@medicus.ai/medicus-report-pdf-generator 1.0.229 → 1.0.230
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/xorcrypt12.js +217 -0
- package/index.js +16 -19
- package/lib/encrypt_decrypt.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/*
|
|
2
|
+
This Javascript will en/decrypt a string using the HTML XOR algorithim
|
|
3
|
+
XORCRYPT Version 1.2
|
|
4
|
+
|
|
5
|
+
This version is much faster because it does not use Base64 encoding.
|
|
6
|
+
It is also more difficult to crack, because the key is as long as the
|
|
7
|
+
password, and the only way to hack it is to try every possible password.
|
|
8
|
+
|
|
9
|
+
The latest version has some small bugs cleaned up, reorganized decrypt
|
|
10
|
+
sequence and is now crossplatform, crossbrowser compatible, with the
|
|
11
|
+
exception of Netscape 2.X. It would be possible to make it compatible
|
|
12
|
+
with Netscape 2.X, but I see no point.
|
|
13
|
+
|
|
14
|
+
For more information on this very simple algorithim email me.
|
|
15
|
+
|
|
16
|
+
This script was written by:
|
|
17
|
+
Evan Jones, 1997
|
|
18
|
+
jonesev@home.com
|
|
19
|
+
You may use this script any way you wish as long as you email me and let me know.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/* Create the encrypt table */
|
|
23
|
+
// The last char in the table is always the escape code
|
|
24
|
+
// The table is not quite 128 chars, it is 95 (minus the escape char)
|
|
25
|
+
// Values 93-127 must be escaped
|
|
26
|
+
|
|
27
|
+
var cryptTable=new String(" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 !@#$%^&*()`'-=[];,./?_+{}|:<>~");
|
|
28
|
+
var cryptLength=new Number(cryptTable.length-1) //93 Chars
|
|
29
|
+
var escapeChar=cryptTable.charAt(cryptLength); // The escape code is ~
|
|
30
|
+
|
|
31
|
+
var lineFeed="\n"; //The linefeed char - escaped to double escapeChar
|
|
32
|
+
var doubleQuote='"'; //Double quotes are escaped to ~'
|
|
33
|
+
var clearMessage=new Number(5000); //The number of ms to wait to clear the status bar message
|
|
34
|
+
|
|
35
|
+
/* This function uses the key and encrypts a string with the password */
|
|
36
|
+
// Encryption strips all linefeeds - but they are replaced upon decrypt
|
|
37
|
+
function encrypt(input, password)
|
|
38
|
+
{
|
|
39
|
+
var inChar, inValue, outValue;
|
|
40
|
+
|
|
41
|
+
var output="";
|
|
42
|
+
var arNumberPw = new Array();
|
|
43
|
+
|
|
44
|
+
var pwLength=password.length;
|
|
45
|
+
var inLength=input.length;
|
|
46
|
+
|
|
47
|
+
var stopStatus=Math.round(inLength/10);
|
|
48
|
+
var statusBar=0;
|
|
49
|
+
|
|
50
|
+
for (var pwIndex=0; pwIndex<pwLength; pwIndex++)
|
|
51
|
+
{
|
|
52
|
+
arNumberPw[pwIndex]=cryptTable.indexOf(password.charAt(pwIndex));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/* XOR all the chars */
|
|
56
|
+
for (var inIndex=0, pwIndex=0; inIndex<inLength; inIndex++, pwIndex++)
|
|
57
|
+
{
|
|
58
|
+
if (pwIndex==pwLength) //Make sure the password index is in range
|
|
59
|
+
{
|
|
60
|
+
pwIndex=0;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/* Get the input */
|
|
64
|
+
|
|
65
|
+
inChar=input.charAt(inIndex)
|
|
66
|
+
inValue=cryptTable.indexOf(inChar);
|
|
67
|
+
|
|
68
|
+
/* Conversion/Escaping Sequence */
|
|
69
|
+
// If the outValue is in the character map, encode it
|
|
70
|
+
// If the encoded value is outside the character map, escape it
|
|
71
|
+
// Else convert it to a char
|
|
72
|
+
// If the input char is a linefeed, escape it
|
|
73
|
+
// If the input char is a double quote, escape it
|
|
74
|
+
// If the input char wasn't found, pass it through
|
|
75
|
+
|
|
76
|
+
if (inValue!=-1)
|
|
77
|
+
{
|
|
78
|
+
outValue=arNumberPw[pwIndex] ^ inValue;
|
|
79
|
+
if (outValue>=cryptLength)
|
|
80
|
+
{
|
|
81
|
+
outValue=escapeChar+cryptTable.charAt(outValue-cryptLength);
|
|
82
|
+
}
|
|
83
|
+
else outValue=cryptTable.charAt(outValue);
|
|
84
|
+
}
|
|
85
|
+
else if (inChar=="\r")
|
|
86
|
+
{
|
|
87
|
+
outValue=escapeChar+escapeChar;
|
|
88
|
+
if (input.charAt(inIndex+1)=="\n") inIndex++; //If it is a 2 char linefeed skip next one
|
|
89
|
+
}
|
|
90
|
+
else if (inChar=="\n")
|
|
91
|
+
{
|
|
92
|
+
outValue=escapeChar+escapeChar;
|
|
93
|
+
}
|
|
94
|
+
else if (inChar==doubleQuote)
|
|
95
|
+
{
|
|
96
|
+
outValue=escapeChar+"'";
|
|
97
|
+
}
|
|
98
|
+
else
|
|
99
|
+
{
|
|
100
|
+
outValue=inChar;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
output+=outValue; //Output the char
|
|
104
|
+
|
|
105
|
+
/* Status bar progress indicator */
|
|
106
|
+
|
|
107
|
+
if (inIndex>=statusBar)
|
|
108
|
+
{
|
|
109
|
+
window.status=inIndex+"/"+inLength+" characters decrypted ("+Math.round(inIndex/inLength*100)+"%)";
|
|
110
|
+
statusBar+=stopStatus;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
window.status=inLength+"/"+inLength+" characters encrypted (100%)";
|
|
115
|
+
setTimeout("window.status=''", clearMessage);
|
|
116
|
+
|
|
117
|
+
return output;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
/* This function uses the key and encrypts a string with the password */
|
|
122
|
+
|
|
123
|
+
function decrypt(input, password)
|
|
124
|
+
{
|
|
125
|
+
var inChar, inValue, outValue, escape=false;
|
|
126
|
+
|
|
127
|
+
var output="";
|
|
128
|
+
var arNumberPw = new Array();
|
|
129
|
+
|
|
130
|
+
var pwLength=password.length;
|
|
131
|
+
var inLength=input.length;
|
|
132
|
+
|
|
133
|
+
var stopStatus=Math.round(inLength/10);
|
|
134
|
+
var statusBar=0;
|
|
135
|
+
|
|
136
|
+
for (var pwIndex=0; pwIndex<pwLength; pwIndex++)
|
|
137
|
+
{
|
|
138
|
+
arNumberPw[pwIndex]=cryptTable.indexOf(password.charAt(pwIndex));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/* XOR all the chars */
|
|
142
|
+
for (var inIndex=0, pwIndex=0; inIndex<inLength; inIndex++, pwIndex++)
|
|
143
|
+
{
|
|
144
|
+
if (pwIndex>=pwLength) //Make sure the password index is in range
|
|
145
|
+
{
|
|
146
|
+
pwIndex=0;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/* Get the input */
|
|
150
|
+
inChar=input.charAt(inIndex);
|
|
151
|
+
inValue=cryptTable.indexOf(inChar);
|
|
152
|
+
|
|
153
|
+
/* Decrypting/Unescaping Sequence */
|
|
154
|
+
// If the input char wasn't found, pass it through (error checking)
|
|
155
|
+
// If the last char was an escapeChar
|
|
156
|
+
//And the input is an escapeChar, output a linefeed
|
|
157
|
+
//Or the input is a single quote, output a double quote
|
|
158
|
+
//Otherwise just add the cryptLength to the inValue
|
|
159
|
+
//Turn escape off
|
|
160
|
+
// If the inValue hasn't been coverted to an outValue yet
|
|
161
|
+
// If the inChar is an escapeChar, turn escape on
|
|
162
|
+
// Otherwise decrypt the encrypted character
|
|
163
|
+
|
|
164
|
+
if (inValue==-1)
|
|
165
|
+
{
|
|
166
|
+
outValue=inChar;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
else if (escape)
|
|
170
|
+
{
|
|
171
|
+
if (inValue==cryptLength)
|
|
172
|
+
{
|
|
173
|
+
outValue=lineFeed;
|
|
174
|
+
inValue=-1;
|
|
175
|
+
}
|
|
176
|
+
else if (inChar=="'")
|
|
177
|
+
{
|
|
178
|
+
outValue=doubleQuote;
|
|
179
|
+
inValue=-1;
|
|
180
|
+
}
|
|
181
|
+
else
|
|
182
|
+
{
|
|
183
|
+
inValue+=cryptLength;
|
|
184
|
+
}
|
|
185
|
+
escape=false;
|
|
186
|
+
}
|
|
187
|
+
else if (inValue==cryptLength)
|
|
188
|
+
{
|
|
189
|
+
escape=true;
|
|
190
|
+
pwIndex--; //Stop the password from incrementing
|
|
191
|
+
outValue="";
|
|
192
|
+
inValue=-1;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (inValue!=-1)
|
|
196
|
+
{
|
|
197
|
+
outValue=cryptTable.charAt(arNumberPw[pwIndex] ^ inValue);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/* Output */
|
|
201
|
+
|
|
202
|
+
output+=outValue;
|
|
203
|
+
|
|
204
|
+
/* Status bar progress indicator */
|
|
205
|
+
|
|
206
|
+
if (inIndex>=statusBar)
|
|
207
|
+
{
|
|
208
|
+
window.status=inIndex+"/"+inLength+" characters decrypted ("+Math.round(inIndex/inLength*100)+"%)";
|
|
209
|
+
statusBar+=stopStatus;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
window.status=inLength+"/"+inLength+" characters decrypted (100%)";
|
|
214
|
+
setTimeout("window.status=''", clearMessage);
|
|
215
|
+
|
|
216
|
+
return output;
|
|
217
|
+
}
|
package/index.js
CHANGED
|
@@ -91,28 +91,25 @@ module.exports = {
|
|
|
91
91
|
generateNascoPDF: async (data, isDebugging, isDownloadable, shouldSendEmail) => {
|
|
92
92
|
|
|
93
93
|
let reportData = JSON.parse(data)
|
|
94
|
-
let encryptionKey
|
|
95
|
-
let sentData
|
|
94
|
+
let encryptionKey=reportData.encryptionKey
|
|
95
|
+
let sentData=reportData.data
|
|
96
96
|
let ecbDecrypted = encryptDecrypt.ecbDecrypt(sentData, encryptionKey)
|
|
97
97
|
|
|
98
98
|
let xorDecrypted = encryptDecrypt.XORDecrypt(ecbDecrypted, encryptionKey)
|
|
99
|
-
|
|
100
|
-
ecbDecrypted: ecbDecrypted,
|
|
101
|
-
xorDecrypted: xorDecrypted
|
|
102
|
-
}
|
|
99
|
+
|
|
103
100
|
|
|
104
101
|
let base64Object = Buffer.from(xorDecrypted, 'utf8').toString('base64');
|
|
105
|
-
console.log("base64Object",
|
|
102
|
+
console.log("base64Object",base64Object)
|
|
106
103
|
let LOGS = '';
|
|
107
104
|
let LOGS_FILE_PATH = __dirname + '/output/LOGS.txt';
|
|
108
105
|
let PDF_FILE_PATH = __dirname + '/output/nasco-sample.pdf';
|
|
109
106
|
let mailConfig = {
|
|
110
|
-
host:
|
|
111
|
-
port:
|
|
112
|
-
authUser:
|
|
113
|
-
authPass:
|
|
114
|
-
sendFromEmail:
|
|
115
|
-
secure:
|
|
107
|
+
host:reportData.host,
|
|
108
|
+
port:reportData.port,
|
|
109
|
+
authUser:reportData.authUser,
|
|
110
|
+
authPass:reportData.authPass,
|
|
111
|
+
sendFromEmail:reportData.sendFromEmail,
|
|
112
|
+
secure:reportData.secure
|
|
116
113
|
}
|
|
117
114
|
if (isDebugging) {
|
|
118
115
|
if (fs.existsSync(LOGS_FILE_PATH)) {
|
|
@@ -132,7 +129,7 @@ module.exports = {
|
|
|
132
129
|
}
|
|
133
130
|
// 2: save decoded json string
|
|
134
131
|
const json = Buffer.from(base64Object, 'base64').toString('utf8');
|
|
135
|
-
console.log("json",
|
|
132
|
+
console.log("json",json)
|
|
136
133
|
if (isDebugging) {
|
|
137
134
|
console.log('2: save decoded json string');
|
|
138
135
|
LOGS += '2: save decoded json string' + '\n' + '=============' + '\n';
|
|
@@ -147,9 +144,9 @@ module.exports = {
|
|
|
147
144
|
LOGS += decodedJSON + '\n\n\n';
|
|
148
145
|
}
|
|
149
146
|
|
|
150
|
-
let html = await generateHTMLWellbeingReport(decodedJSON, isDebugging,
|
|
147
|
+
let html = await generateHTMLWellbeingReport(decodedJSON, isDebugging,reportData.client,reportData.language);
|
|
151
148
|
|
|
152
|
-
console.log("shouldSendEmail",
|
|
149
|
+
console.log("shouldSendEmail",shouldSendEmail)
|
|
153
150
|
// 3: save PDF buffer
|
|
154
151
|
let fileBuffer = await generatePDFWellbeingReport(html);
|
|
155
152
|
if (isDebugging) {
|
|
@@ -158,7 +155,7 @@ module.exports = {
|
|
|
158
155
|
LOGS += fileBuffer + '\n\n\n';
|
|
159
156
|
}
|
|
160
157
|
|
|
161
|
-
console.log("PDF_FILE_PATH",
|
|
158
|
+
console.log("PDF_FILE_PATH",PDF_FILE_PATH)
|
|
162
159
|
fs.writeFileSync(PDF_FILE_PATH, fileBuffer, 'utf8');
|
|
163
160
|
|
|
164
161
|
// 4: save encoded base64
|
|
@@ -180,8 +177,8 @@ module.exports = {
|
|
|
180
177
|
return fileBuffer;
|
|
181
178
|
} else {
|
|
182
179
|
if (shouldSendEmail)
|
|
183
|
-
return await sendNascoEmail(decodedJSON, PDF_FILE_PATH, mailConfig,
|
|
184
|
-
else
|
|
180
|
+
return await sendNascoEmail(decodedJSON, PDF_FILE_PATH, mailConfig,reportData.client)
|
|
181
|
+
else{
|
|
185
182
|
let xorEncrypted = encryptDecrypt.XOREncrypt(base64data, encryptionKey)
|
|
186
183
|
let ecbEncrypted = encryptDecrypt.ecbEncrypt(xorEncrypted.toString(), encryptionKey)
|
|
187
184
|
return ecbEncrypted;
|
package/lib/encrypt_decrypt.js
CHANGED
package/package.json
CHANGED