orbita-downloader 1.0.0 → 1.0.1
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/browser-checker.js +383 -0
- package/browser-user-data-manager.js +333 -0
- package/common.js +23 -0
- package/cookies-manager.js +165 -0
- package/example.js +30 -0
- package/extensions-extractor.js +55 -0
- package/extensions-manager.js +364 -0
- package/fonts.js +4295 -0
- package/fonts_config +104 -0
- package/gologin-browser-ext.zip +0 -0
- package/gologin.js +1356 -0
- package/gologin_zeroprofile.b64 +1 -0
- package/index.mjs +1 -1
- package/package copy.json +43 -0
- package/package.json +1 -1
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const util = require('util');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const https = require('https');
|
|
6
|
+
const { access, mkdir, readdir, rmdir, unlink, copyFile, readlink, symlink, lstat } = require('fs').promises;
|
|
7
|
+
const exec = util.promisify(require('child_process').exec);
|
|
8
|
+
const decompress = require('decompress');
|
|
9
|
+
const decompressUnzip = require('decompress-unzip');
|
|
10
|
+
const ProgressBar = require('progress');
|
|
11
|
+
const readline = require('readline');
|
|
12
|
+
|
|
13
|
+
const PLATFORM = process.platform;
|
|
14
|
+
|
|
15
|
+
const VERSION_FILE = 'latest-version.txt';
|
|
16
|
+
const MAC_VERSION_FILE_URL = `https://orbita-browser-mac-wc.gologin.com/${VERSION_FILE}`;
|
|
17
|
+
const DEB_VERSION_FILE_URL = `https://orbita-browser-linux-wc.gologin.com/${VERSION_FILE}`;
|
|
18
|
+
const WIN_VERSION_FILE_URL = `https://orbita-browser-windows-wc.gologin.com/${VERSION_FILE}`;
|
|
19
|
+
|
|
20
|
+
const WIN_FOLDERSIZE_FILE = 'foldersize.txt';
|
|
21
|
+
const WIN_FOLDERSIZE_FILE_LINK = `https://orbita-browser-windows.gologin.com/${WIN_FOLDERSIZE_FILE}`;
|
|
22
|
+
|
|
23
|
+
const BROWSER_ARCHIVE_NAME = `orbita-browser-latest.${PLATFORM === 'win32' ? 'zip' : 'tar.gz'}`;
|
|
24
|
+
const MAC_BROWSER_LINK = `https://orbita-browser-mac-wc.gologin.com/${BROWSER_ARCHIVE_NAME}`;
|
|
25
|
+
const DEB_BROWSER_LINK = `https://orbita-browser-linux-wc.gologin.com/${BROWSER_ARCHIVE_NAME}`;
|
|
26
|
+
const WIN_BROWSER_LINK = `https://orbita-browser-windows-wc.gologin.com/${BROWSER_ARCHIVE_NAME}`;
|
|
27
|
+
|
|
28
|
+
const MAC_HASH_FILE = 'hashfile.mtree';
|
|
29
|
+
const DEB_HASH_FILE = 'hashfile.txt';
|
|
30
|
+
const WIN_HASH_FILE = DEB_HASH_FILE;
|
|
31
|
+
const MAC_HASHFILE_LINK = `https://orbita-browser-mac-wc.gologin.com/${MAC_HASH_FILE}`;
|
|
32
|
+
const DEB_HASHFILE_LINK = `https://orbita-browser-linux-wc.gologin.com/${DEB_HASH_FILE}`;
|
|
33
|
+
const WIN_HASHFILE_LINK = `https://orbita-browser-windows-wc.gologin.com/${WIN_HASH_FILE}`;
|
|
34
|
+
|
|
35
|
+
const FAIL_SUM_MATCH_MESSAGE = 'hash_sum_not_matched';
|
|
36
|
+
const EXTRACTED_FOLDER = 'extracted-browser';
|
|
37
|
+
|
|
38
|
+
class BrowserChecker {
|
|
39
|
+
#homedir;
|
|
40
|
+
#browserPath;
|
|
41
|
+
#executableFilePath;
|
|
42
|
+
#skipOrbitaHashChecking = false;
|
|
43
|
+
|
|
44
|
+
constructor(skipOrbitaHashChecking) {
|
|
45
|
+
this.#skipOrbitaHashChecking = skipOrbitaHashChecking;
|
|
46
|
+
this.#homedir = os.homedir();
|
|
47
|
+
this.#browserPath = path.join(this.#homedir, '.gologin', 'browser');
|
|
48
|
+
|
|
49
|
+
let executableFilePath = path.join(this.#browserPath, 'orbita-browser', 'chrome');
|
|
50
|
+
if (PLATFORM === 'darwin') {
|
|
51
|
+
executableFilePath = path.join(this.#browserPath, 'Orbita-Browser.app', 'Contents', 'MacOS', 'Orbita');
|
|
52
|
+
} else if (PLATFORM === 'win32') {
|
|
53
|
+
executableFilePath = path.join(this.#browserPath, 'orbita-browser', 'chrome.exe');
|
|
54
|
+
}
|
|
55
|
+
this.#executableFilePath = executableFilePath;
|
|
56
|
+
// console.log('executableFilePath:', executableFilePath);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async checkBrowser(autoUpdateBrowser = false) {
|
|
60
|
+
const browserFolderExists = await access(this.#executableFilePath).then(() => true).catch(() => false);
|
|
61
|
+
|
|
62
|
+
if (!browserFolderExists) {
|
|
63
|
+
return this.downloadBrowser();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const browserLatestVersion = await this.getLatestBrowserVersion();
|
|
67
|
+
const currentVersionReq = await this.getCurrentVersion();
|
|
68
|
+
const currentVersion = (currentVersionReq?.stdout || '').replace(/(\r\n|\n|\r)/gm, '');
|
|
69
|
+
|
|
70
|
+
if (browserLatestVersion === currentVersion) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (autoUpdateBrowser) {
|
|
75
|
+
return this.downloadBrowser();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return new Promise(resolve => {
|
|
79
|
+
const rl = readline.createInterface(process.stdin, process.stdout);
|
|
80
|
+
const timeout = setTimeout(() => {
|
|
81
|
+
console.log(`\nContinue with current ${currentVersion} version.`);
|
|
82
|
+
resolve();
|
|
83
|
+
}, 10000);
|
|
84
|
+
|
|
85
|
+
rl.question(`New Orbita ${browserLatestVersion} is available. Update? [y/n] `, (answer) => {
|
|
86
|
+
clearTimeout(timeout);
|
|
87
|
+
rl.close();
|
|
88
|
+
if (answer && answer[0].toString().toLowerCase() === 'y') {
|
|
89
|
+
return this.downloadBrowser().then(() => resolve());
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
console.log(`Continue with current ${currentVersion} version.`);
|
|
93
|
+
resolve();
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async downloadBrowser() {
|
|
99
|
+
await this.deleteOldArchives(true);
|
|
100
|
+
await mkdir(this.#browserPath, { recursive: true });
|
|
101
|
+
|
|
102
|
+
const pathStr = path.join(this.#browserPath, BROWSER_ARCHIVE_NAME);
|
|
103
|
+
let link = DEB_BROWSER_LINK;
|
|
104
|
+
if (PLATFORM === 'win32') {
|
|
105
|
+
link = WIN_BROWSER_LINK;
|
|
106
|
+
} else if (PLATFORM === 'darwin') {
|
|
107
|
+
link = MAC_BROWSER_LINK;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
await this.downloadBrowserArchive(link, pathStr);
|
|
111
|
+
await this.checkBrowserArchive(pathStr);
|
|
112
|
+
await this.extractBrowser();
|
|
113
|
+
await this.checkBrowserSum();
|
|
114
|
+
console.log('Orbita hash checked successfully');
|
|
115
|
+
await this.replaceBrowser();
|
|
116
|
+
await this.deleteOldArchives();
|
|
117
|
+
console.log('Orbita updated successfully');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
downloadBrowserArchive(link, pathStr) {
|
|
121
|
+
return new Promise((resolve, reject) => {
|
|
122
|
+
const writableStream = fs.createWriteStream(pathStr);
|
|
123
|
+
writableStream.on('error', async err => {
|
|
124
|
+
await unlink(pathStr);
|
|
125
|
+
reject(err);
|
|
126
|
+
});
|
|
127
|
+
writableStream.on('finish', () => resolve());
|
|
128
|
+
|
|
129
|
+
const req = https.get(link, {
|
|
130
|
+
timeout: 15 * 1000,
|
|
131
|
+
}, (res) => {
|
|
132
|
+
const len = parseInt(res.headers['content-length'], 10);
|
|
133
|
+
const formattedLen = len / 1024 / 1024;
|
|
134
|
+
const bar = new ProgressBar('Orbita downloading [:bar] :rate/mps :downloadedMb/:fullMbMB :percent :etas', {
|
|
135
|
+
complete: '=',
|
|
136
|
+
incomplete: ' ',
|
|
137
|
+
width: 30,
|
|
138
|
+
total: Math.round(formattedLen),
|
|
139
|
+
});
|
|
140
|
+
let downloadedMb = 0;
|
|
141
|
+
|
|
142
|
+
res.on('data', (chunk) => {
|
|
143
|
+
const formattedChunckLenght = chunk.length / 1024 / 1024;
|
|
144
|
+
downloadedMb += formattedChunckLenght;
|
|
145
|
+
bar.tick(formattedChunckLenght, {
|
|
146
|
+
fullMb: formattedLen.toFixed(2),
|
|
147
|
+
downloadedMb: downloadedMb.toFixed(2),
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
res.on('end', function () {
|
|
152
|
+
bar.tick(bar.total, {
|
|
153
|
+
fullMb: formattedLen.toFixed(2),
|
|
154
|
+
downloadedMb: formattedLen.toFixed(2),
|
|
155
|
+
});
|
|
156
|
+
console.log('\nDownload completed');
|
|
157
|
+
writableStream.end();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
res.pipe(writableStream);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
req.on('error', (err) => writableStream.destroy(err));
|
|
164
|
+
req.end();
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async checkBrowserArchive(pathStr) {
|
|
169
|
+
console.log('Checking Orbita archive');
|
|
170
|
+
try {
|
|
171
|
+
await access(pathStr);
|
|
172
|
+
} catch (e) {
|
|
173
|
+
throw new Error('Archive has not been found. Please run script again.')
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
async extractBrowser() {
|
|
178
|
+
console.log('Extracting Orbita');
|
|
179
|
+
await mkdir(path.join(this.#browserPath, EXTRACTED_FOLDER), { recursive: true });
|
|
180
|
+
if (PLATFORM === 'win32') {
|
|
181
|
+
return decompress(path.join(this.#browserPath, BROWSER_ARCHIVE_NAME), path.join(this.#browserPath, EXTRACTED_FOLDER),
|
|
182
|
+
{
|
|
183
|
+
plugins: [decompressUnzip()],
|
|
184
|
+
filter: file => !file.path.endsWith('/'),
|
|
185
|
+
}
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return exec(
|
|
190
|
+
`tar xzf ${path.join(this.#browserPath, BROWSER_ARCHIVE_NAME)} --directory ${path.join(this.#browserPath, EXTRACTED_FOLDER)}`
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
async downloadHashFile() {
|
|
195
|
+
let hashLink = DEB_HASHFILE_LINK;
|
|
196
|
+
let resultPath = path.join(this.#browserPath, DEB_HASH_FILE);
|
|
197
|
+
if (PLATFORM === 'darwin') {
|
|
198
|
+
hashLink = MAC_HASHFILE_LINK;
|
|
199
|
+
resultPath = path.join(this.#browserPath, MAC_HASH_FILE);
|
|
200
|
+
}
|
|
201
|
+
const writableStream = fs.createWriteStream(resultPath);
|
|
202
|
+
writableStream.on('error', async (err) => {
|
|
203
|
+
await unlink(resultPath);
|
|
204
|
+
throw err;
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
await new Promise(resolve => https.get(hashLink,
|
|
208
|
+
{
|
|
209
|
+
timeout: 10 * 1000,
|
|
210
|
+
}, (res) => {
|
|
211
|
+
res.on('end', function () {
|
|
212
|
+
console.log('Hashfile downloading completed');
|
|
213
|
+
writableStream.end();
|
|
214
|
+
resolve();
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
res.pipe(writableStream);
|
|
218
|
+
}).on('error', (err) => writableStream.destroy(err)));
|
|
219
|
+
|
|
220
|
+
const hashFile = PLATFORM === 'darwin' ? MAC_HASH_FILE : DEB_HASH_FILE;
|
|
221
|
+
const hashFilePath = path.join(this.#browserPath, hashFile);
|
|
222
|
+
return access(hashFilePath);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async checkBrowserSum() {
|
|
226
|
+
if (this.#skipOrbitaHashChecking) {
|
|
227
|
+
return Promise.resolve();
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
console.log('Orbita hash checking');
|
|
231
|
+
if (PLATFORM === 'win32') {
|
|
232
|
+
return Promise.resolve();
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
await this.downloadHashFile();
|
|
236
|
+
if (PLATFORM === 'darwin') {
|
|
237
|
+
const calculatedHash = await exec(
|
|
238
|
+
`mtree -p ${path.join(this.#browserPath, EXTRACTED_FOLDER, 'Orbita-Browser.app')} < ${path.join(this.#browserPath, MAC_HASH_FILE)} || echo ${FAIL_SUM_MATCH_MESSAGE}`
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
const checkedRes = (calculatedHash || '').toString().trim();
|
|
242
|
+
if (checkedRes.includes(FAIL_SUM_MATCH_MESSAGE)) {
|
|
243
|
+
throw new Error('Error in sum matching. Please run script again.');
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const hashFileContent = await exec(`cat ${path.join(this.#browserPath, DEB_HASH_FILE)}`);
|
|
250
|
+
let serverRes = (hashFileContent.stdout || '').toString().trim();
|
|
251
|
+
serverRes = serverRes.split(' ')[0];
|
|
252
|
+
|
|
253
|
+
const calculateLocalBrowserHash = await exec(
|
|
254
|
+
`cd ${path.join(this.#browserPath, EXTRACTED_FOLDER)} && find orbita-browser -type f -print0 | sort -z | \
|
|
255
|
+
xargs -0 sha256sum > ${this.#browserPath}/calculatedFolderSha.txt`
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
const localHashContent = await exec(`cd ${this.#browserPath} && sha256sum calculatedFolderSha.txt`);
|
|
259
|
+
let userRes = (localHashContent.stdout || '').toString().trim();
|
|
260
|
+
userRes = userRes.split(' ')[0];
|
|
261
|
+
if (userRes !== serverRes) {
|
|
262
|
+
throw new Error('Error in sum matching. Please run script again.');
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
async replaceBrowser() {
|
|
267
|
+
console.log('Copy Orbita to target path');
|
|
268
|
+
if (PLATFORM === 'darwin') {
|
|
269
|
+
await this.deleteDir(path.join(this.#browserPath, 'Orbita-Browser.app'));
|
|
270
|
+
|
|
271
|
+
const files = await readdir(path.join(this.#browserPath, EXTRACTED_FOLDER));
|
|
272
|
+
const promises = [];
|
|
273
|
+
files.forEach((filename) => {
|
|
274
|
+
if (filename.match(/.*\.dylib$/)) {
|
|
275
|
+
promises.push(copyFile(path.join(this.#browserPath, EXTRACTED_FOLDER, filename), path.join(this.#browserPath, filename)));
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
return Promise.all(promises);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const targetBrowserPath = path.join(this.#browserPath, 'orbita-browser');
|
|
283
|
+
await this.deleteDir(targetBrowserPath);
|
|
284
|
+
|
|
285
|
+
await this.copyDir(
|
|
286
|
+
path.join(this.#browserPath, EXTRACTED_FOLDER, 'orbita-browser'),
|
|
287
|
+
targetBrowserPath
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
async deleteOldArchives(deleteCurrentBrowser = false) {
|
|
292
|
+
if (deleteCurrentBrowser) {
|
|
293
|
+
return this.deleteDir(path.join(this.#browserPath));
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
await this.deleteDir(path.join(this.#browserPath, EXTRACTED_FOLDER));
|
|
297
|
+
return readdir(this.#browserPath)
|
|
298
|
+
.then((files) => {
|
|
299
|
+
const promises = [];
|
|
300
|
+
files.forEach((filename) => {
|
|
301
|
+
if (filename.match(/(txt|dylib|mtree)/)) {
|
|
302
|
+
promises.push(unlink(path.join(this.#browserPath, filename)));
|
|
303
|
+
}
|
|
304
|
+
})
|
|
305
|
+
return Promise.all(promises);
|
|
306
|
+
})
|
|
307
|
+
.catch(e => {
|
|
308
|
+
console.log(`Error in deleting old archives. ${e.message}`);
|
|
309
|
+
return Promise.resolve();
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
async copyDir(src, dest) {
|
|
314
|
+
await mkdir(dest);
|
|
315
|
+
const files = await readdir(src);
|
|
316
|
+
for (let i = 0; i < files.length; i++) {
|
|
317
|
+
const current = await lstat(path.join(src, files[i]));
|
|
318
|
+
if (current.isDirectory()) {
|
|
319
|
+
await this.copyDir(path.join(src, files[i]), path.join(dest, files[i]));
|
|
320
|
+
} else if(current.isSymbolicLink()) {
|
|
321
|
+
const symlinkObj = await readlink(path.join(src, files[i]));
|
|
322
|
+
await symlink(symlinkObj, path.join(dest, files[i]));
|
|
323
|
+
} else {
|
|
324
|
+
await copyFile(path.join(src, files[i]), path.join(dest, files[i]));
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
getCurrentVersion() {
|
|
330
|
+
let command = `if [ -f ${path.join(this.#browserPath, 'orbita-browser', 'version')} ]; then cat ${path.join(this.#browserPath, 'orbita-browser', 'version')}; else echo 0.0.0; fi`;
|
|
331
|
+
if (PLATFORM === 'win32') {
|
|
332
|
+
command = `if exist "${path.join(this.#browserPath, 'orbita-browser', 'version')}" (type "${path.join(this.#browserPath, 'orbita-browser', 'version')}") else (echo 0.0.0)`;
|
|
333
|
+
} else if (PLATFORM === 'darwin') {
|
|
334
|
+
command = `if [ -f ${path.join(this.#browserPath, 'version', VERSION_FILE)} ]; then cat ${path.join(this.#browserPath, 'version', VERSION_FILE)}; else echo 0.0.0; fi`;
|
|
335
|
+
}
|
|
336
|
+
return exec(command);
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
getLatestBrowserVersion() {
|
|
340
|
+
let url = DEB_VERSION_FILE_URL;
|
|
341
|
+
if (PLATFORM === 'win32') {
|
|
342
|
+
url = WIN_VERSION_FILE_URL;
|
|
343
|
+
} else if (PLATFORM === 'darwin') {
|
|
344
|
+
url = MAC_VERSION_FILE_URL;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return new Promise(resolve => https.get(url,
|
|
348
|
+
{
|
|
349
|
+
timeout: 15 * 1000,
|
|
350
|
+
headers: {
|
|
351
|
+
'Content-Type': 'text/plain',
|
|
352
|
+
},
|
|
353
|
+
}, (res) => {
|
|
354
|
+
res.setEncoding('utf8');
|
|
355
|
+
|
|
356
|
+
let resultResponse = '';
|
|
357
|
+
res.on('data', (data) => resultResponse += data);
|
|
358
|
+
|
|
359
|
+
res.on('end', () => {
|
|
360
|
+
resolve(resultResponse.trim());
|
|
361
|
+
});
|
|
362
|
+
}).on('error', (err) => resolve('')));
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
get getOrbitaPath() {
|
|
366
|
+
return this.#executableFilePath;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
async deleteDir(path = '') {
|
|
370
|
+
if (!path) {
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const directoryExists = await access(path).then(() => true).catch(() => false);
|
|
375
|
+
if (!directoryExists) {
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
return rmdir(path, { recursive: true });
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
module.exports = BrowserChecker;
|