Elfinder 2.0 decode filename - javascript

$("#elfinder").elfinder({
url: 'https://localhost/elfinder',
handlers: {
dblclick: function(event, elfinderInstance) {
var file = event.data.file; //l1_dGVzdC9iYW5uZXJfYmdfaG9yaXpvbnRhbC5qcGc
}
}
});
How to decrypt l1_dGVzdC9iYW5uZXJfYmdfaG9yaXpvbnRhbC5qcGc into banner_bg_horizontal.jpg (real filename) ?

For elFinder you'll need to modify the base64 keyStr values + / = to - _ .
var keyStr = "ABCDEFGHIJKLMNOP" +
"QRSTUVWXYZabcdef" +
"ghijklmnopqrstuv" +
"wxyz0123456789+/" +
"=";
change to...
var keyStr = "ABCDEFGHIJKLMNOP" +
"QRSTUVWXYZabcdef" +
"ghijklmnopqrstuv" +
"wxyz0123456789-_" +
".";
then strip the prefix "l1_" before decoding

because you do not use Base64
I use it and it works well
example Base64

Related

Regex to replace only some / characters inside strings

How to get regex with replace method? In my case I've got string which uses char / between.
input:
var string = "cn/" + companyName + "/st/" + state + "/ic/" + incCi + "/pr/" + priority + "/es/" + emplSystem + "/mc/" + mainCategory + "/sc/" + subCategory + "/ty/" + type;
output:
"cn/Nemesis Group/st/2/ic/null/pr/1 - High/es/null/mc/Add/Button/sc/Core/Label/ty/str"
variable mainCategory and subCategory returns string 'Add/Button' and 'Core/Label'
How to replace 'Add/Button' to 'Add%2FButton' and 'Core/Label' to 'Core%2FLabel' without changing any other char?
string.replace("\/", "%2F")
will change all char / to %2F
You can use encodeURIComponent() and decodeURIComponent() to transform this String
Example:
const companyName = "Company",
state = "State",
incCi = "IncCi",
priority = "Priority",
emplSystem = "EmplSystem",
mainCategory = 'Add/Button',
subCategory = 'Core/Label',
type = "Type";
var string = "cn/" + companyName + "/st/" + state + "/ic/" + incCi + "/pr/" + priority + "/es/" + emplSystem +
"/mc/" + encodeURIComponent(mainCategory) +
"/sc/" + encodeURIComponent(subCategory) + "/ty/" + type;
console.log(string)
It sounds to me like you are looking to encode the url. You can use encodeURI in JS to encode a url.
let encodedURL = encodeURI(url);
You can read more about it here.
If you want to encode the string altogether without ignoring any domain related parts, you can us encodeURIComponent()
let encodedURL = encodeURIComponent(url);
You can read more about their differences here.
EDIT:
If you are not encoding a url and you just want to repalce / with %2F only in mainCategory and subCategory then you need to run the regex on the string itself before joining them.
var string = "cn/" + companyName +
"/st/" + state +
"/ic/" + incCi +
"/pr/" + priority +
"/es/" + emplSystem +
"/mc/" + mainCategory.replace("\/", "%2F") +
"/sc/" + subCategory.replace("\/", "%2F") +
"/ty/" + type;

Twitter in_reply_to_status_id signature

I am working on twitter integration. I am using CryptoJs to create a signature. Here is the code.
The issue is, following code is working without "in_reply_to_status_id" parameter, but with that parameter it is giving "could not authenticate issue".
var autSign =
'oauth_consumer_key=' + percentEncode(consumer_key) + '&' +
'oauth_nonce=' + percentEncode(nonce) + '&' +
'oauth_signature_method=HMAC-SHA1&' +
'oauth_timestamp=' + timeStamp + '&' +
'oauth_token=' + percentEncode(access_token) + '&' +
'oauth_version=1.0&status=test3&in_reply_to_status_id=1217119832744898564';
var baseString =
"POST&" +
percentEncode(endpoint) + "&" + percentEncode(autSign);
var signingKey = this.percentEncode(consumer_secret) +
"&" + this.percentEncode(access_token_secret);
var encrypted = CryptoJS.HmacSHA1(baseString, signingKey);
var signature = CryptoJS.enc.Base64.stringify(encrypted);

Select local files with input type:file (pdf) and convert them to base64 string

how to get base64 string from selected files with input type: file (multiple .pdf) in javascript.
I need a base64 string in a variable.
function handleFileSelect(e) {
console.dir(e);
if (!e.target.files) return;
selDiv.innerHTML = "";
var files = e.target.files;
for (var i = 0; i < files.length; i++) {
var base64;
var fileToLoad = document.getElementById("files").files[i]
var fileReader = new FileReader();
fileReader.onload = function (fileLoadedEvent) {
base64 = fileLoadedEvent.target.result;
console.log(base64);
};
fileReader.readAsDataURL(fileToLoad);
var f = files[i];
var TmpPath = URL.createObjectURL(e.target.files[i]);
var name = f.name;
var extencion = f.name.split('.')[1];
selDiv.innerHTML += f.name + " <a href='#' onclick=verdetalle(" + i + ",'" + extencion + "','" + name + "','" + base64 + "','" + TmpPath + "')>Ver Detalle</a>" + "<br/>";
}
}
but I do not respect the value for my base64 variable, only if I debuge it from the browser.
in this line of my code I create a link for each selected file, where I assign an onchange and pass the variables i, extension, name, base64, TmpPath, but I am missing the base64 variable
selDiv.innerHTML += f.name + " <a href='#' onclick=verdetalle(" + i + ",'" + extencion + "','" + name + "','" + base64 + "','" + TmpPath + "')>Ver Detalle</a>" + "<br/>";
Try below code snippet,
var base64String;
function handleFileSelect(callback) {
var file = document.getElementById('filePicker').files[0];
var reader = new FileReader();
reader.onload = function(readerEvt) {
var binaryString = readerEvt.target.result;
base64String = btoa(binaryString);
// alert(base64String);
// Do additional stuff
callback(base64String);
};
reader.readAsBinaryString(file);
};
<div>
<div>
<label for="filePicker">Choose file:</label><br>
<input type="file" id="filePicker" onchange="handleFileSelect(function(base64String){alert(base64String)})">
</div>
<br>
</div>
You need to put the functionality that depends on base64 inside the filereader.onload callback. Also, make sure to always use const or let when dealing with asynchronous loops. var gets hoisted and has function scope, not block scope, so it's easy to run into problems if you use it. Or, even better, use forEach, which gives you better abstraction, doesn't require manual iteration, and has function scope:
function handleFileSelect(e) {
console.dir(e);
const files = e.target.files;
if (!files) return;
selDiv.innerHTML = "";
files.forEach((file, i) => {
const { name } = file;
const extencion = f.name.split('.')[1];
const fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent) {
const base64 = fileLoadedEvent.target.result;
console.log(base64);
const TmpPath = URL.createObjectURL(file);
selDiv.innerHTML += f.name + " <a href='#' onclick=verdetalle(" + i + ",'" + extencion + "','" + name + "','" + base64 + "','" + TmpPath + "')>Ver Detalle</a>" + "<br/>";
};
fileReader.readAsDataURL(file);
});
}

html2 canvas unable to click button

I am unable to click the approve button to save the signature into database. .Please help! I have refer to this link to do but they are not working.
https://www.aspsnippets.com/Articles/Convert-Export-HTML-DIV-or-Table-to-Image-using-HTML-Canvas-in-ASPNet-using-C-and-VBNet.aspx
Code under approve button
<asp:Button ID="ProcesssOwner1" Visible="true" data-action="save" Text="Approve" CssClass="btn btn-success btn-sm" UseSubmitBehavior="false" OnClientClick="return ConvertToImage(this)" runat="server" OnClick="ProcesssOwner1_Click" />
Javascript
<script type="text/javascript">
function ConvertToImage(ProcesssOwner1) {
if (signaturePad.isEmpty()) {
alert("Please provide signature first.");
return false;
} else {
//document.getElementById("hfSign").value = signaturePad.toDataURL();
html2canvas($("#drawing")[0]).then(function (canvas) {
var base64 = canvas.toDataURL();
$("[id*=hfImageData]").val(base64);
__doPostBack(ProcesssOwner1.name, "");
});
return false;
}
}
</script>
Code under button click
Here I tried to save the signature in the path and folder.
protected void ProcesssOwner1_Click(object sender, EventArgs e)
{
if (Session["loggedUserID"] == null && Session["loggedRoleID"] == null)
{
Response.Redirect("Login.aspx");
}
else
{
int loggedUserID = Convert.ToInt32(Session["loggedUserID"]);
List<BOL.UserInfo> userslist = new UserInfos().List();
BOL.UserInfo loggeduser = userslist.Where(x => x.UserID == loggedUserID).FirstOrDefault();
string app_type = "";
string dcr = Request.QueryString["r_id"].Replace("/", "_") + DateTime.Now.ToString("yyyy-MM-dd HHmmtt");
string myID = loggeduser.EmployeeNo;
string path1 = "/Web/";
//System.Diagnostics.Debugger.Launch();
if (Request.QueryString["STAT"] == "S_7")
{
app_type = "A";
string base64 = Request.Form[hfImageData.UniqueID].Split(',')[1];
byte[] bytes = Convert.FromBase64String(base64);
//write the bytes to file:
File.WriteAllBytes(path1 + dcr + "_" + myID + app_type + ".jpg", bytes); //write to a temp location.
File.Copy(path1 + dcr + "_" + myID + app_type + ".jpg", #"D:\IntranetPortal\IntranetPortal\Web\signature\" + dcr + "_" + myID + app_type + ".jpg");//here we grab the file and copy it. //EDIT: based on permissions you might be able to write directly to the share instead of a temp folder first.
}
else if (Request.QueryString["STAT"] == "S_9")
{
app_type = "C";
string base64 = Request.Form[hfImageData.UniqueID].Split(',')[1];
byte[] bytes = Convert.FromBase64String(base64);
//write the bytes to file:
File.WriteAllBytes(path1 + dcr + "_" + myID + app_type + ".jpg", bytes); //write to a temp location.
File.Copy(path1 + dcr + "_" + myID + app_type + ".jpg", #"D:\IntranetPortal\IntranetPortal\Web\signature\" + dcr + "_" + myID + app_type + ".jpg");//here we grab the file and copy it.
}
DAL.DMSS insertdata = new DMSS();
insertdata.APP_PROCESS(Request.QueryString["r_id"], app_type, chatt.Text, path1 + "signature" + "/" + dcr + "_" + myID + app_type + ".jpg", dcr + "_" + myID + app_type + ".jpg", loggeduser.EmployeeNo, DATEE.Text);
ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Approved.Thank you.');window.location ='Dms_app.aspx';", true);
}
}

Using http.send() ajax

if(document.getElementById(callerName).checked) {
//alert(callerName);
var poststr = "field=" + escape(encodeURI(callerName)) +
"&op=add" + "&nocache=" + nocache;
}
else {
//alert(callerName);
var poststr = "field=" + escape(encodeURI(callerName)) +
"&op=del" + "&nocache=" + nocache;
}
http.send(poststr);
When I recieve the $_POST['field'] i get '%20' where there are spaces..any solution to get exact the string?
PHP:
$field = urldecode($_POST['field']);
You are double-escaping your data by using both escape and encodeURI. Also, I'd recommend you use encodeURIComponent instead. Try changing to this:
var poststr = "field=" + encodeURIComponent(callerName) +
"&op=add&nocache=" + nocache;

Categories