Browse Source

Updated dropzone and added new encryption functions

tags/2.0.3
Teknikode 4 years ago
parent
commit
21ffabf103

+ 9
- 0
Teknik/Areas/Upload/Controllers/UploadController.cs View File

@@ -30,6 +30,15 @@ namespace Teknik.Areas.Upload.Controllers
[ValidateAntiForgeryToken]
public ActionResult Upload(string uploadID)
{
foreach (string fileName in Request.Files)
{
HttpPostedFileBase file = Request.Files[fileName];
//Save file content goes here
string fName = file.FileName;
if (file != null && file.ContentLength > 0)
{
}
}
return Json(new { result = "tempURL.png" });
}


+ 89
- 13
Teknik/Areas/Upload/Scripts/Upload.js View File

@@ -37,23 +37,27 @@ Dropzone.options.TeknikUpload = {
this.on("addedfile", function(file, responseText) {
$("#upload_message").css('display', 'none', 'important');
});
this.on("sending", function (file, xhrObject, formData) {

// We need to encrypt the file before upload
});
this.on("success", function(file, response) {
var name = response.result;
var short_name = file.name.split(".")[0].hashCode();
$("#upload-links").css('display', 'inline', 'important');
$("#upload-links").prepend(' \
<div class="row link_'+short_name+'"> \
<div class="col-sm-6"> \
'+file.name+' \
</div> \
<div class="col-sm-3"> \
<a href='+uploadURL+'/'+name+'" target="_blank" class="alert-link">'+uploadURL+'/'+name+'</a> \
</div> \
<div class="col-sm-3"> \
<button type="button" class="btn btn-default btn-xs generate-delete-link-'+short_name+'" id="'+name+'">Generate Deletion URL</button> \
</div> \
</div> \
');
<div class="row link_'+short_name+'"> \
<div class="col-sm-6"> \
'+file.name+' \
</div> \
<div class="col-sm-3"> \
<a href='+uploadURL+'/'+name+'" target="_blank" class="alert-link">'+uploadURL+'/'+name+'</a> \
</div> \
<div class="col-sm-3"> \
<button type="button" class="btn btn-default btn-xs generate-delete-link-'+short_name+'" id="'+name+'">Generate Deletion URL</button> \
</div> \
</div> \
');
linkUploadDelete('.generate-delete-link-'+short_name+'');
});
this.on("removedfile", function(file) {
@@ -85,4 +89,76 @@ Dropzone.options.TeknikUpload = {
$(".progress").children('.progress-bar').html('Complete');
});
}
};
};

function encryptFile(file)
{
var key = CryptoJS.enc.Utf8.parse('8080808080808080');
var iv = CryptoJS.enc.Utf8.parse('8080808080808080');
var reader = new FileReader();
reader.onload = function (e) {
var encrypted = CryptoJS.AES.encrypt(e.target.result, key);


}
}

function readBlob(opt_startByte, opt_stopByte) {

var files = document.getElementById('fileinput').files;
if (!files.length) {
alert('Please select a file!');
return;
}

var file = files[0];
var start = parseInt(opt_startByte) || 0;
var stop = parseInt(opt_stopByte) || file.size - 1;

var reader = new FileReader();

// If we use onloadend, we need to check the readyState.
reader.onloadend = function (evt) {
if (evt.target.readyState == FileReader.DONE) { // DONE == 2
window.bits.push(aesEncryptor.process(evt.target.result));
}
};

var blob = file.slice(start, stop + 1);
reader.readAsBinaryString(blob);
}

function handling(evt) {

// INITIALIZE PROGRESSIVE ENCRYPTION
var key = CryptoJS.enc.Hex.parse(document.getElementById('pass').value);
var iv = CryptoJS.lib.WordArray.random(128 / 8);
window.bits = [];
window.aesEncryptor = CryptoJS.algo.AES.createEncryptor(key, { iv: iv });

// LOOP THROUGH BYTES AND PROGRESSIVELY ENCRYPT
var startByte = 0;
var endByte = 0;
while (startByte < document.querySelector('input[type=file]').files[0].size - 1) {
endByte = startByte + 1000000;
readBlob(startByte, endByte);
startByte = endByte;
}

// FINALIZE ENCRYPTION AND UPLOAD
var encrypted = aesEncryptor.finalize();
encrypted = encodeURIComponent(encrypted);
var filename = document.getElementById('fileinput').value;
var file_type = document.getElementById('fileinput').files[0].type;
var url = 'data=' + encrypted + '&filename=' + filename + '&filetype=' + file_type;
$.ajax({
url: 'myphpscript.php',
type: 'POST',
data: url
}).success(function (data) {
// Display encrypted data
document.getElementById('status').innerHTML = 'Upload Complete.';
});
alert(encrypted);

}

+ 1
- 1
Teknik/Areas/Upload/Views/Upload/Index.cshtml View File

@@ -10,7 +10,7 @@

<div class="container">
<div class="row text-center">
<form action="@Url.SubRouteUrl("upload", "Upload.Upload")" class="dropzone" id="TeknikUpload" name="TeknikUpload">
<form action="@Url.SubRouteUrl("upload", "Upload.Upload")" class="dropzone" id="TeknikUpload" name="TeknikUpload" enctype="multipart/form-data">
@Html.AntiForgeryToken()
<div class="dz-message text-center" id="upload_message">
<div class="row">

+ 565
- 732
Teknik/Scripts/Dropzone/dropzone.js
File diff suppressed because it is too large
View File


+ 0
- 22
Teknik/Web.config View File

@@ -28,35 +28,13 @@
<remove name="FormsAuthentication" />
<add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
<add name="PerfModule" type="Teknik.Modules.PerformanceMonitorModule, Teknik" />
</modules>
<staticContent>
<mimeMap fileExtension="woff" mimeType="application/font-woff" />
<mimeMap fileExtension="woff2" mimeType="application/font-woff" />
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" cacheControlCustom="public" />
</staticContent>
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="image/*" enabled="true" />
<add mimeType="video/*" enabled="true" />
<add mimeType="application/javascript" enabled="true" />
<add mimeType="*/*" enabled="false" />
</dynamicTypes>
<staticTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="image/*" enabled="true" />
<add mimeType="video/*" enabled="true" />
<add mimeType="application/javascript" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
</httpCompression>
<urlCompression doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="true" />
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

Loading…
Cancel
Save