-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDontpadJS.js
More file actions
152 lines (145 loc) · 5.5 KB
/
Copy pathDontpadJS.js
File metadata and controls
152 lines (145 loc) · 5.5 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Post
var postText = async (key, text, encrypt = false, keyEncrypt = 'dontpadJs') => {
const urlRequest = location.protocol;
let url;
if (encrypt == true) {
text = encryptString({
"data": EncryptAES(text,keyEncrypt)
}, keyEncrypt)
}
if (urlRequest == 'https:')
url = 'https://cors-anywhere.herokuapp.com/http://dontpad.com/' + key;
else
url = 'http://dontpad.com/' + key;
const rawResponse = await fetch(url, {
method: 'POST',
mode: 'no-cors',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Access-Control-Allow-Headers': '*',
'Access-Control-Allow-Origin': '*',
'Access-Control-Request-Method': 'POST',
'Access-Control-Allow-Headers': 'Content-Type'
},
body: `text=${text}`,
});
await rawResponse
};
// Get
var getText = (key, encrypt = false, validate = false, keyValidate = 'dontpadJs') => {
const proxy = 'https://cors-anywhere.herokuapp.com/http://dontpad.com/';
let url = proxy + key + '.txt';
let signature = false;
return fetch(url,
{
method: "GET",
headers: {
'Content-Type': 'text/html; charset=utf-8',
},
})
.then((response) => response.text())
.then((responseData) => {
try {
if (validate == true) {
if (validateJwt(responseData, keyValidate))
signature = true;
else
signature = false;
let dataReturn = (encrypt == true ? DecryptAES(decryptString(responseData).data,keyValidate) : responseData);
return {
"Signature": signature,
"data": dataReturn
}
} else {
if (encrypt == true)
return DecryptAES(decryptString(responseData).data,keyValidate)
else
return responseData
}
} catch (e) {
console.log('Error: ' + e);
signature = false;
return null;
}
})
.catch(error => console.error(error));
}
//Get SubPaths from Key
var getSubPath = (key) =>{
const proxy = 'https://cors-anywhere.herokuapp.com/http://dontpad.com/';
let url = proxy + key + '.menu.json';
return fetch(url,
{
method: "GET",
headers: {
'Content-Type': 'text/html; charset=utf-8',
},
}).then((response) => response.text()).then((responseData) => JSON.parse(responseData));
}
//Clear Path
var clearPath = (key) => postText(key, '')
//Doc load and start
document.addEventListener("DOMContentLoaded", (event) => {
try {
encryptString({"Load": "Load"}, 'Load');
} catch (e) {
if (e instanceof ReferenceError)
setTimeout(console.log.bind(console, "%cwarn%c Error to load Encryptation Lib, Follow Link to use references > https://pastebin.com/PJpYmNXw", "background: #e3ce10;color:#FFF;padding:5px;border-radius: 3px;line-height: 5px;user-select: none;", ""));
}
setTimeout(console.log.bind(console, "%cinfo%c DontpadJS is loaded! https://github.com/GabrielDuarteMG/DontpadJs", "background: #00b84c;color:#FFF;padding:5px;border-radius: 3px;line-height: 5px;user-select: none;", ""));
});
/*
JWT - Encrypt method Using Alg HS256 - Type: DPJs
Default password: dontpadJs
*/
var validateJwt = (token, pass) => {
let defaultHeader = {
"alg": "HS256",
"typ": "DPJs"
};
let header = JSON.parse(atob(token.split('.')[0]))
let tokenSignature = token.split('.')[2];
if (defaultHeader.alg != header.alg || defaultHeader.typ != header.typ)
return false;
else {
let signature = token.split('.')[0] + "." + token.split('.')[1];
signature = CryptoJS.HmacSHA256(signature, pass);
signature = base64url(signature);
if (signature != tokenSignature)
return false;
else
return true;
}
}
var encryptString = (content, secretKey) => {
let header = {
"alg": "HS256",
"typ": "DPJs"
};
let stringifiedHeader = CryptoJS.enc.Utf8.parse(JSON.stringify(header));
let encodedHeader = base64url(stringifiedHeader);
let stringifiedData = CryptoJS.enc.Utf8.parse(JSON.stringify(content));
let encodedData = base64url(stringifiedData);
let signature = encodedHeader + "." + encodedData;
signature = CryptoJS.HmacSHA256(signature, secretKey);
signature = base64url(signature);
return encodedHeader + '.' + encodedData + '.' + signature;
}
var decryptString = (token) => {
let playload = JSON.parse(atob(token.split('.')[1]));
return playload;
};
const base64url = (source) => {
let encodedSource = CryptoJS.enc.Base64.stringify(source);
encodedSource = encodedSource.replace(/=+$/, '');
encodedSource = encodedSource.replace(/\+/g, '-');
encodedSource = encodedSource.replace(/\//g, '_')
return encodedSource;
}
var EncryptAES = (text, key) => {
return CryptoJS.AES.encrypt(text, key).toString();
}
var DecryptAES = (text, key) => {
return CryptoJS.AES.decrypt(text, key).toString(CryptoJS.enc.Utf8);
}