-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdemo.js
More file actions
99 lines (96 loc) · 4.3 KB
/
demo.js
File metadata and controls
99 lines (96 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
(function() {
function randomWords(n) {
return Array.apply(null, new Array(n)).map(function() { return Math.floor(Math.random() * 0xFFFFFFFF); });
}
var password = sjcl.codec.hex.fromBits(randomWords(8));
var salt = randomWords(2);
var files_key = window.files_key = randomWords(8);
var hmac_bits = randomWords(4);
var key = sjcl.misc.pbkdf2(password, salt, 10);
var private_key = window.private_key = key.slice(128/32); // Second half
var shared_key = key.slice(0, 128/32); // First half
var private_hmac = window.private_hmac = new sjcl.misc.hmac(private_key);
var files_hmac = window.files_hmac = new sjcl.misc.hmac(hmac_bits);
var authkey = sjcl.codec.hex.fromBits(shared_key).toUpperCase();
var account_info = window.account_info = {tier: 10, S3Prefix: sjcl.codec.hex.fromBits(sjcl.random.randomWords(2,0)).toUpperCase()};
var S3Prefix = window.S3Prefix = account_info.S3Prefix;
var XMLHttpRequest_open = window.XMLHttpRequest.prototype.open;
window.XMLHttpRequest.prototype.open = function(method, url) {
var hash = url.substr(url.indexOf('#') + 1);
if(hash.substr(0, hash.indexOf('.')) !== '1') { // Not a request to a real shared document
if(url.substr(0, 8) === '/object/' && method === 'GET') {
url = '/v2/live' + hash.substr(hash.indexOf('.') + 1);
this.responseType = 'arraybuffer';
} else if(url.substr(0, 8) === '/object/' || url.substr(0, 13) === '/transaction/') {
Object.defineProperty(this, 'setRequestHeader', {value: function() {}});
Object.defineProperty(this, 'send', {value: function() {
Object.defineProperty(this, 'airborn_readyState', {get: function() { return 4; }});
Object.defineProperty(this, 'airborn_status', {get: function() { return 200; }});
this.dispatchEvent(new Event('readystatechange'));
this.dispatchEvent(new Event('load'));
}});
return;
}
}
Object.defineProperty(this, 'airborn_readyState', {get: function() { return this.readyState; }});
Object.defineProperty(this, 'airborn_status', {get: function() { return this.status; }});
Object.defineProperty(this, 'airborn_statusText', {get: function() { return this.statusText; }});
Object.defineProperty(this, 'airborn_response', {get: function() { return this.response; }});
Object.defineProperty(this, 'airborn_responseText', {get: function() { return this.response; }}); // Not responseText
XMLHttpRequest_open.apply(this, arguments);
};
var req = new XMLHttpRequest();
req.open('GET', '/v2/live/Core/modules/core/core.js');
req.addEventListener('readystatechange', function() {
if(this.readyState === 4 && this.status === 200) {
eval(this.responseText.replace(/\b((?:this|req)\.)((?:readyState|status|response)(?:Text)?)\b/g, '$1airborn_$2')); // renameGlobalVariables light
var _decrypt = decrypt;
decrypt = function(key, contents, outparams, callback) {
_decrypt(key, contents, outparams, function(decrypted, err) {
if(err) {
callback(contents);
} else {
callback(decrypted);
}
});
};
[
'/',
'/Documents/',
'/Documents/.history/',
'/Documents/Documents/.history/',
'/AppData/',
'/AppData/firetext/',
'/AppData/firetext/localStorage',
'/CoreData/',
'/CoreData/localStorage',
'/settings',
].forEach(function(path) {
// We write directly to cache instead of using putFile to avoid the
// cyclic dependency between /Documents/ and /Documents/.history/.
window.getFileCache[path] = {codec: 'utf8String', contents: '', ts: Date.now()};
});
if(!location.hash.includes('firetext:s=')) {
putFile('/Documents/Documents/', 'Welcome.html: {type: text/html}');
putFile('/AppData/firetext/localStorage', '{"firetext.recents":"[[\\"/sdcard/Documents/\\",\\"Welcome\\",\\".html\\",\\"\\",\\"internal\\"]]"}');
}
getFile('/Core/modules/startup/startup.js', function(contents) {
eval(contents);
});
window.logout = function() {
window.location = '/';
};
window.showNotice('demo', 'In this demo version, your files are not saved. <a href="' + location.origin + '/register" target="_blank">Register now!</a>', true);
}
});
req.send(null);
[
'/Apps/firetext/index.html',
'/Apps/firetext/styles.css',
].forEach(function(url) {
var link = document.createElement('link');
link.rel = 'prefetch';
link.href= '/v2/live' + url;
document.body.appendChild(link);
});
})();