aboutsummaryrefslogtreecommitdiffstats
path: root/jsaccess/jsa/jsa.js
diff options
context:
space:
mode:
Diffstat (limited to 'jsaccess/jsa/jsa.js')
-rw-r--r--jsaccess/jsa/jsa.js72
1 files changed, 63 insertions, 9 deletions
diff --git a/jsaccess/jsa/jsa.js b/jsaccess/jsa/jsa.js
index 45030f8..91d5ac6 100644
--- a/jsaccess/jsa/jsa.js
+++ b/jsaccess/jsa/jsa.js
@@ -4,33 +4,86 @@
/* Reference code */
//console.log(JSON.stringify(xhr));
+/* ===== PUBLIC - called by html ===== */
+
/* Called on "body" load */
function jsainit() {
- /* XXX get content of jsa/files/ directory to present
- a list to the user */
+
+}
+
+/* Called on "Get files list" click */
+
+function jsagetlist() {
+ var pass = document.getElementById('password').value;
+ var RMD160 = new Hashes.RMD160;
+ var hash = RMD160.hex(pass);
+
+ _status("Getting file list ...");
+ listreq = $.ajax({
+ url: 'files/' + hash + '/index.txt',
+ beforeSend: function ( xhr ) {
+ xhr.overrideMimeType("application/base64");
+ },
+ success: function ( data ) {
+ _status("We have file list");
+ _showfiles(data, pass, hash);
+ },
+ error: function (xhr, opts, err) {
+ _status("Bad password");
+ throw(err);
+ }
+ });
}
/* Called on "Download" click */
function jsadl() {
- document.getElementById('status').innerHTML = "";
var pass = document.getElementById('password').value;
- var file = $('input[name=files]:checked').val();
+ var file = $('input[name=file]:checked').val();
obj = _dl(file, pass);
}
+/* ===== PRIVATE - called within this javascript file ===== */
+
+function _showfiles(data, pass, hash) {
+ try {
+ var decrypted = GibberishAES.dec(data, pass);
+ } catch(err) {
+ _status(err.toString());
+ throw err;
+ }
+
+ document.getElementById('files').innerHTML = "";
+ lines = decrypted.split("\n").filter(function(n){return n});
+ $.each(lines,
+ function( idx, obj ){
+ obj = obj.trim();
+ _status("XXX LINE "+obj);
+ var btn = $('<input type="radio" name="file" value="'+obj+'"/>'+obj+'<br/>');
+ btn.appendTo('#files');
+ });
+}
+
function _dl(file, pass) {
- window.URL = window.URL || window.webkitURL;
+ var RMD160 = new Hashes.RMD160;
+
+ var dirhash = RMD160.hex(pass);
+ var path = 'files/' + dirhash + '/' + RMD160.hex(dirhash + file);
_status("Downloading \""+file+"\" ...");
dlreq = $.ajax({
- url: 'files/' + file,
+ url: path,
beforeSend: function ( xhr ) {
xhr.overrideMimeType("application/base64");
+ },
+ success: function ( data ) {
+ _status("Download complete, decrypting ...");
+ _decrypt(data, pass, file);
+ },
+ error: function (xhr, opts, err) {
+ _status("Dowload failed (status="+xhr.status+")");
+ throw(err);
}
- }).done(function ( data ) {
- _status("Download complete, decrypting ...");
- _decrypt(data, pass, file);
});
}
@@ -39,6 +92,7 @@ function _decrypt(obj, pass, name) {
var decrypted = GibberishAES.dec(obj, pass);
} catch(err) {
_status(err.toString());
+ throw err;
}
out = $.base64.decode(decrypted.toString());
_status("Decrypted successfuly, saving ...");