gologin-commonjs 1.2.6 → 1.2.7
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.
|
@@ -236,17 +236,23 @@ class BrowserChecker {
|
|
|
236
236
|
}
|
|
237
237
|
return;
|
|
238
238
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
239
|
+
return Promise.resolve();
|
|
240
|
+
|
|
241
|
+
// const hashFileContent = await exec(`cat ${join(this.#browserPath, DEB_HASH_FILE)}`);
|
|
242
|
+
// let serverRes = (hashFileContent.stdout || '').toString().trim();
|
|
243
|
+
// serverRes = serverRes.split(' ')[0];
|
|
244
|
+
|
|
245
|
+
// const calculateLocalBrowserHash = await exec(
|
|
246
|
+
// `cd ${join(this.#browserPath, EXTRACTED_FOLDER)} && find orbita-browser -type f -print0 | sort -z | \
|
|
247
|
+
// xargs -0 sha256sum > ${this.#browserPath}/calculatedFolderSha.txt`,
|
|
248
|
+
// );
|
|
249
|
+
|
|
250
|
+
// const localHashContent = await exec(`cd ${this.#browserPath} && sha256sum calculatedFolderSha.txt`);
|
|
251
|
+
// let userRes = (localHashContent.stdout || '').toString().trim();
|
|
252
|
+
// userRes = userRes.split(' ')[0];
|
|
253
|
+
// if (userRes !== serverRes) {
|
|
254
|
+
// throw new Error('Error in sum matching. Please run script again.');
|
|
255
|
+
// }
|
|
250
256
|
}
|
|
251
257
|
async replaceBrowser() {
|
|
252
258
|
console.log('Copy Orbita to target path');
|
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
4
|
+
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.uploadCookies =
|
|
7
|
-
exports.setOriginalExtPaths =
|
|
8
|
-
exports.setExtPathsAndRemoveDeleted =
|
|
9
|
-
exports.recalculateId =
|
|
10
|
-
exports.downloadFonts =
|
|
11
|
-
exports.downloadCookies =
|
|
12
|
-
exports.copyFontsConfigFile =
|
|
13
|
-
exports.composeFonts =
|
|
14
|
-
void 0;
|
|
6
|
+
exports.uploadCookies = exports.setOriginalExtPaths = exports.setExtPathsAndRemoveDeleted = exports.recalculateId = exports.downloadFonts = exports.downloadCookies = exports.copyFontsConfigFile = exports.composeFonts = void 0;
|
|
15
7
|
var _crypto = require("crypto");
|
|
16
8
|
var _fs = require("fs");
|
|
17
9
|
var _os = require("os");
|
|
@@ -19,69 +11,65 @@ var _path = require("path");
|
|
|
19
11
|
var _requestretry = _interopRequireDefault(require("requestretry"));
|
|
20
12
|
var _url = require("url");
|
|
21
13
|
var _fonts = require("../../fonts.js");
|
|
22
|
-
function _interopRequireDefault(e) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
14
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
+
const {
|
|
16
|
+
access,
|
|
17
|
+
readFile,
|
|
18
|
+
writeFile,
|
|
19
|
+
mkdir,
|
|
20
|
+
readdir,
|
|
21
|
+
copyFile,
|
|
22
|
+
rename
|
|
23
|
+
} = _fs.promises;
|
|
24
|
+
const _filename = (0, _url.fileURLToPath)(require('url').pathToFileURL(_filename).toString());
|
|
30
25
|
const _dirname = (0, _path.dirname)(_filename);
|
|
31
|
-
const FONTS_URL =
|
|
32
|
-
const FONTS_DIR_NAME =
|
|
26
|
+
const FONTS_URL = 'https://fonts.gologin.com/';
|
|
27
|
+
const FONTS_DIR_NAME = 'fonts';
|
|
33
28
|
const HOMEDIR = (0, _os.homedir)();
|
|
34
|
-
const BROWSER_PATH = (0, _path.join)(HOMEDIR,
|
|
29
|
+
const BROWSER_PATH = (0, _path.join)(HOMEDIR, '.gologin', 'browser');
|
|
35
30
|
const OS_PLATFORM = process.platform;
|
|
36
|
-
const DEFAULT_ORBITA_EXTENSIONS_NAMES = [
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"CryptoTokenExtension",
|
|
40
|
-
"Web Store",
|
|
41
|
-
];
|
|
42
|
-
const GOLOGIN_BASE_FOLDER_NAME = ".gologin";
|
|
43
|
-
const GOLOGIN_TEST_FOLDER_NAME = ".gologin_test";
|
|
31
|
+
const DEFAULT_ORBITA_EXTENSIONS_NAMES = ['Google Hangouts', 'Chromium PDF Viewer', 'CryptoTokenExtension', 'Web Store'];
|
|
32
|
+
const GOLOGIN_BASE_FOLDER_NAME = '.gologin';
|
|
33
|
+
const GOLOGIN_TEST_FOLDER_NAME = '.gologin_test';
|
|
44
34
|
const osPlatform = process.platform;
|
|
45
|
-
const downloadCookies = ({
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
35
|
+
const downloadCookies = ({
|
|
36
|
+
profileId,
|
|
37
|
+
ACCESS_TOKEN,
|
|
38
|
+
API_BASE_URL
|
|
39
|
+
}) => _requestretry.default.get(`${API_BASE_URL}/browser/${profileId}/cookies`, {
|
|
40
|
+
headers: {
|
|
41
|
+
Authorization: `Bearer ${ACCESS_TOKEN}`,
|
|
42
|
+
'user-agent': 'gologin-api'
|
|
43
|
+
},
|
|
44
|
+
json: true,
|
|
45
|
+
maxAttempts: 3,
|
|
46
|
+
retryDelay: 2000,
|
|
47
|
+
timeout: 10 * 1000
|
|
48
|
+
}).catch(e => {
|
|
49
|
+
console.log(e);
|
|
50
|
+
return {
|
|
51
|
+
body: []
|
|
52
|
+
};
|
|
53
|
+
});
|
|
63
54
|
exports.downloadCookies = downloadCookies;
|
|
64
55
|
const uploadCookies = ({
|
|
65
56
|
cookies = [],
|
|
66
57
|
profileId,
|
|
67
58
|
ACCESS_TOKEN,
|
|
68
|
-
API_BASE_URL
|
|
69
|
-
}) =>
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
console.log(e);
|
|
83
|
-
return e;
|
|
84
|
-
});
|
|
59
|
+
API_BASE_URL
|
|
60
|
+
}) => _requestretry.default.post(`${API_BASE_URL}/browser/${profileId}/cookies?encrypted=true`, {
|
|
61
|
+
headers: {
|
|
62
|
+
Authorization: `Bearer ${ACCESS_TOKEN}`,
|
|
63
|
+
'User-Agent': 'gologin-api'
|
|
64
|
+
},
|
|
65
|
+
json: cookies,
|
|
66
|
+
maxAttempts: 3,
|
|
67
|
+
retryDelay: 2000,
|
|
68
|
+
timeout: 20 * 1000
|
|
69
|
+
}).catch(e => {
|
|
70
|
+
console.log(e);
|
|
71
|
+
return e;
|
|
72
|
+
});
|
|
85
73
|
exports.uploadCookies = uploadCookies;
|
|
86
74
|
const downloadFonts = async (fontsList = [], profilePath) => {
|
|
87
75
|
if (!fontsList.length) {
|
|
@@ -89,159 +77,107 @@ const downloadFonts = async (fontsList = [], profilePath) => {
|
|
|
89
77
|
}
|
|
90
78
|
const browserFontsPath = (0, _path.join)(BROWSER_PATH, FONTS_DIR_NAME);
|
|
91
79
|
await mkdir(browserFontsPath, {
|
|
92
|
-
recursive: true
|
|
80
|
+
recursive: true
|
|
93
81
|
});
|
|
94
82
|
const files = await readdir(browserFontsPath);
|
|
95
|
-
const fontsToDownload = fontsList.filter(
|
|
96
|
-
let promises = fontsToDownload.map((font
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
timeout: 30 * 1000,
|
|
102
|
-
})
|
|
103
|
-
.pipe((0, _fs.createWriteStream)((0, _path.join)(browserFontsPath, font)))
|
|
104
|
-
);
|
|
83
|
+
const fontsToDownload = fontsList.filter(font => !files.includes(font));
|
|
84
|
+
let promises = fontsToDownload.map(font => _requestretry.default.get(FONTS_URL + font, {
|
|
85
|
+
maxAttempts: 5,
|
|
86
|
+
retryDelay: 2000,
|
|
87
|
+
timeout: 30 * 1000
|
|
88
|
+
}).pipe((0, _fs.createWriteStream)((0, _path.join)(browserFontsPath, font))));
|
|
105
89
|
if (promises.length) {
|
|
106
90
|
await Promise.all(promises);
|
|
107
91
|
}
|
|
108
|
-
promises = fontsList.map((font)
|
|
109
|
-
copyFile(
|
|
110
|
-
(0, _path.join)(browserFontsPath, font),
|
|
111
|
-
(0, _path.join)(profilePath, FONTS_DIR_NAME, font)
|
|
112
|
-
)
|
|
113
|
-
);
|
|
92
|
+
promises = fontsList.map(font => copyFile((0, _path.join)(browserFontsPath, font), (0, _path.join)(profilePath, FONTS_DIR_NAME, font)));
|
|
114
93
|
await Promise.all(promises);
|
|
115
94
|
};
|
|
116
95
|
exports.downloadFonts = downloadFonts;
|
|
117
|
-
const composeFonts = async (
|
|
118
|
-
fontsList = [],
|
|
119
|
-
profilePath,
|
|
120
|
-
differentOs = false
|
|
121
|
-
) => {
|
|
96
|
+
const composeFonts = async (fontsList = [], profilePath, differentOs = false) => {
|
|
122
97
|
if (!(fontsList.length && profilePath)) {
|
|
123
98
|
return;
|
|
124
99
|
}
|
|
125
|
-
const fontsToDownload = _fonts.fontsCollection
|
|
126
|
-
.filter((elem) => fontsList.includes(elem.value))
|
|
127
|
-
.reduce((res, elem) => res.concat(elem.fileNames || []), []);
|
|
100
|
+
const fontsToDownload = _fonts.fontsCollection.filter(elem => fontsList.includes(elem.value)).reduce((res, elem) => res.concat(elem.fileNames || []), []);
|
|
128
101
|
if (differentOs && !fontsToDownload.length) {
|
|
129
|
-
throw new Error(
|
|
130
|
-
"No fonts to download found. Use getAvailableFonts() method and set some fonts from this list"
|
|
131
|
-
);
|
|
102
|
+
throw new Error('No fonts to download found. Use getAvailableFonts() method and set some fonts from this list');
|
|
132
103
|
}
|
|
133
|
-
fontsToDownload.push(
|
|
134
|
-
fontsToDownload.push(
|
|
104
|
+
fontsToDownload.push('LICENSE.txt');
|
|
105
|
+
fontsToDownload.push('OFL.txt');
|
|
135
106
|
const pathToFontsDir = (0, _path.join)(profilePath, FONTS_DIR_NAME);
|
|
136
|
-
const fontsDirExists = await access(pathToFontsDir).then(
|
|
137
|
-
() => true,
|
|
138
|
-
() => false
|
|
139
|
-
);
|
|
107
|
+
const fontsDirExists = await access(pathToFontsDir).then(() => true, () => false);
|
|
140
108
|
if (fontsDirExists) {
|
|
141
109
|
(0, _fs.rmdirSync)(pathToFontsDir, {
|
|
142
|
-
recursive: true
|
|
110
|
+
recursive: true
|
|
143
111
|
});
|
|
144
112
|
}
|
|
145
113
|
await mkdir(pathToFontsDir, {
|
|
146
|
-
recursive: true
|
|
114
|
+
recursive: true
|
|
147
115
|
});
|
|
148
116
|
await downloadFonts(fontsToDownload, profilePath);
|
|
149
|
-
if (OS_PLATFORM ===
|
|
117
|
+
if (OS_PLATFORM === 'linux') {
|
|
150
118
|
await copyFontsConfigFile(profilePath);
|
|
151
119
|
}
|
|
152
120
|
};
|
|
153
121
|
exports.composeFonts = composeFonts;
|
|
154
|
-
const copyFontsConfigFile = async
|
|
122
|
+
const copyFontsConfigFile = async profilePath => {
|
|
155
123
|
if (!profilePath) {
|
|
156
124
|
return;
|
|
157
125
|
}
|
|
158
|
-
const fileContent = await readFile(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
);
|
|
162
|
-
const result = fileContent.replace(
|
|
163
|
-
/\$\$GOLOGIN_FONTS\$\$/g,
|
|
164
|
-
(0, _path.join)(profilePath, FONTS_DIR_NAME)
|
|
165
|
-
);
|
|
166
|
-
const defaultFolderPath = (0, _path.join)(profilePath, "Default");
|
|
126
|
+
const fileContent = await readFile((0, _path.resolve)(_dirname, '..', '..', 'fonts_config'), 'utf-8');
|
|
127
|
+
const result = fileContent.replace(/\$\$GOLOGIN_FONTS\$\$/g, (0, _path.join)(profilePath, FONTS_DIR_NAME));
|
|
128
|
+
const defaultFolderPath = (0, _path.join)(profilePath, 'Default');
|
|
167
129
|
await mkdir(defaultFolderPath, {
|
|
168
|
-
recursive: true
|
|
130
|
+
recursive: true
|
|
169
131
|
});
|
|
170
|
-
await writeFile((0, _path.join)(defaultFolderPath,
|
|
132
|
+
await writeFile((0, _path.join)(defaultFolderPath, 'fonts_config'), result);
|
|
171
133
|
};
|
|
172
134
|
exports.copyFontsConfigFile = copyFontsConfigFile;
|
|
173
|
-
const setExtPathsAndRemoveDeleted = (
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
)
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
return {
|
|
186
|
-
path: el,
|
|
187
|
-
originalId,
|
|
188
|
-
};
|
|
189
|
-
})
|
|
190
|
-
.filter(Boolean);
|
|
135
|
+
const setExtPathsAndRemoveDeleted = (settings = {}, profileExtensionsCheckRes = [], profileId = '') => {
|
|
136
|
+
const formattedLocalExtArray = profileExtensionsCheckRes.map(el => {
|
|
137
|
+
const [extFolderName = ''] = el.split(_path.sep).reverse();
|
|
138
|
+
const [originalId] = extFolderName.split('@');
|
|
139
|
+
if (!originalId) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
path: el,
|
|
144
|
+
originalId
|
|
145
|
+
};
|
|
146
|
+
}).filter(Boolean);
|
|
191
147
|
const extensionsSettings = settings.extensions?.settings || {};
|
|
192
148
|
const extensionsEntries = Object.entries(extensionsSettings);
|
|
193
|
-
const promises = extensionsEntries.map(async
|
|
149
|
+
const promises = extensionsEntries.map(async extensionObj => {
|
|
194
150
|
let [extensionId, currentExtSettings = {}] = extensionObj;
|
|
195
|
-
const extName = currentExtSettings.manifest?.name ||
|
|
196
|
-
let extPath = currentExtSettings.path ||
|
|
197
|
-
let originalId =
|
|
198
|
-
const isExtensionToBeDeleted =
|
|
199
|
-
(["resources", "passwords-ext", "cookies-ext"].some((substring) =>
|
|
200
|
-
extPath.includes(substring)
|
|
201
|
-
) &&
|
|
202
|
-
[GOLOGIN_BASE_FOLDER_NAME, GOLOGIN_TEST_FOLDER_NAME].some((substring) =>
|
|
203
|
-
extPath.includes(substring)
|
|
204
|
-
)) ||
|
|
205
|
-
(DEFAULT_ORBITA_EXTENSIONS_NAMES.includes(extName) &&
|
|
206
|
-
[GOLOGIN_BASE_FOLDER_NAME, GOLOGIN_TEST_FOLDER_NAME].some((substring) =>
|
|
207
|
-
extPath.includes(substring)
|
|
208
|
-
));
|
|
151
|
+
const extName = currentExtSettings.manifest?.name || '';
|
|
152
|
+
let extPath = currentExtSettings.path || '';
|
|
153
|
+
let originalId = '';
|
|
154
|
+
const isExtensionToBeDeleted = ['resources', 'passwords-ext', 'cookies-ext'].some(substring => extPath.includes(substring)) && [GOLOGIN_BASE_FOLDER_NAME, GOLOGIN_TEST_FOLDER_NAME].some(substring => extPath.includes(substring)) || DEFAULT_ORBITA_EXTENSIONS_NAMES.includes(extName) && [GOLOGIN_BASE_FOLDER_NAME, GOLOGIN_TEST_FOLDER_NAME].some(substring => extPath.includes(substring));
|
|
209
155
|
if (isExtensionToBeDeleted) {
|
|
210
156
|
delete extensionsSettings[extensionId];
|
|
211
157
|
return;
|
|
212
158
|
}
|
|
213
|
-
if (osPlatform ===
|
|
214
|
-
extPath = extPath.replace(/\//g,
|
|
159
|
+
if (osPlatform === 'win32') {
|
|
160
|
+
extPath = extPath.replace(/\//g, '\\');
|
|
215
161
|
} else {
|
|
216
|
-
extPath = extPath.replace(/\\/g,
|
|
162
|
+
extPath = extPath.replace(/\\/g, '/');
|
|
217
163
|
}
|
|
218
164
|
extensionsSettings[extensionId].path = extPath;
|
|
219
165
|
const splittedPath = extPath.split(_path.sep);
|
|
220
|
-
const isExtensionManageable =
|
|
221
|
-
["chrome-extensions", "user-extensions"].some((substring) =>
|
|
222
|
-
extPath.includes(substring)
|
|
223
|
-
) &&
|
|
224
|
-
[GOLOGIN_BASE_FOLDER_NAME, GOLOGIN_TEST_FOLDER_NAME].some((substring) =>
|
|
225
|
-
extPath.includes(substring)
|
|
226
|
-
);
|
|
166
|
+
const isExtensionManageable = ['chrome-extensions', 'user-extensions'].some(substring => extPath.includes(substring)) && [GOLOGIN_BASE_FOLDER_NAME, GOLOGIN_TEST_FOLDER_NAME].some(substring => extPath.includes(substring));
|
|
227
167
|
if (isExtensionManageable) {
|
|
228
168
|
const [extFolderName] = extPath.split(_path.sep).reverse();
|
|
229
|
-
[originalId] = extFolderName.split(
|
|
169
|
+
[originalId] = extFolderName.split('@');
|
|
230
170
|
} else if (splittedPath.length === 2) {
|
|
231
171
|
[originalId] = splittedPath;
|
|
232
172
|
}
|
|
233
173
|
if (isExtensionManageable || splittedPath.length === 2) {
|
|
234
|
-
const isExtensionInProfileSettings = formattedLocalExtArray.find(
|
|
235
|
-
el.path.includes(originalId)
|
|
236
|
-
);
|
|
174
|
+
const isExtensionInProfileSettings = formattedLocalExtArray.find(el => el.path.includes(originalId));
|
|
237
175
|
if (!isExtensionInProfileSettings) {
|
|
238
176
|
delete extensionsSettings[extensionId];
|
|
239
177
|
return;
|
|
240
178
|
}
|
|
241
179
|
}
|
|
242
|
-
const localExtObj =
|
|
243
|
-
originalId &&
|
|
244
|
-
formattedLocalExtArray.find((el) => el.path.includes(originalId));
|
|
180
|
+
const localExtObj = originalId && formattedLocalExtArray.find(el => el.path.includes(originalId));
|
|
245
181
|
if (!localExtObj) {
|
|
246
182
|
return;
|
|
247
183
|
}
|
|
@@ -250,82 +186,62 @@ const setExtPathsAndRemoveDeleted = (
|
|
|
250
186
|
localExtObj,
|
|
251
187
|
extensionId,
|
|
252
188
|
extensionsSettings,
|
|
253
|
-
currentExtSettings
|
|
189
|
+
currentExtSettings
|
|
254
190
|
});
|
|
255
191
|
if (initialExtName !== extensionId) {
|
|
256
|
-
const profilePath = (0, _path.join)(
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
);
|
|
260
|
-
const extSyncFolder = (0, _path.join)(
|
|
261
|
-
profilePath,
|
|
262
|
-
"Default",
|
|
263
|
-
"Sync Extension Settings",
|
|
264
|
-
initialExtName
|
|
265
|
-
);
|
|
266
|
-
const newSyncFolder = (0, _path.join)(
|
|
267
|
-
profilePath,
|
|
268
|
-
"Default",
|
|
269
|
-
"Sync Extension Settings",
|
|
270
|
-
extensionId
|
|
271
|
-
);
|
|
192
|
+
const profilePath = (0, _path.join)((0, _os.tmpdir)(), `gologin_profile_${profileId}`);
|
|
193
|
+
const extSyncFolder = (0, _path.join)(profilePath, 'Default', 'Sync Extension Settings', initialExtName);
|
|
194
|
+
const newSyncFolder = (0, _path.join)(profilePath, 'Default', 'Sync Extension Settings', extensionId);
|
|
272
195
|
await rename(extSyncFolder, newSyncFolder).catch(() => null);
|
|
273
196
|
}
|
|
274
|
-
if (localExtObj.path.endsWith(
|
|
275
|
-
localExtObj.path = localExtObj.path.replace(
|
|
197
|
+
if (localExtObj.path.endsWith('.zip')) {
|
|
198
|
+
localExtObj.path = localExtObj.path.replace('.zip', '');
|
|
276
199
|
}
|
|
277
|
-
extensionsSettings[extensionId].path = localExtObj.path ||
|
|
200
|
+
extensionsSettings[extensionId].path = localExtObj.path || '';
|
|
278
201
|
});
|
|
279
202
|
return Promise.all(promises).then(() => extensionsSettings);
|
|
280
203
|
};
|
|
281
204
|
exports.setExtPathsAndRemoveDeleted = setExtPathsAndRemoveDeleted;
|
|
282
|
-
const setOriginalExtPaths = async (
|
|
283
|
-
settings = {},
|
|
284
|
-
originalExtensionsFolder = ""
|
|
285
|
-
) => {
|
|
205
|
+
const setOriginalExtPaths = async (settings = {}, originalExtensionsFolder = '') => {
|
|
286
206
|
if (!originalExtensionsFolder) {
|
|
287
207
|
return null;
|
|
288
208
|
}
|
|
289
209
|
const extensionsSettings = settings.extensions?.settings || {};
|
|
290
210
|
const extensionsEntries = Object.entries(extensionsSettings);
|
|
291
|
-
const originalExtensionsList = await readdir(originalExtensionsFolder).catch(
|
|
292
|
-
() => []
|
|
293
|
-
);
|
|
211
|
+
const originalExtensionsList = await readdir(originalExtensionsFolder).catch(() => []);
|
|
294
212
|
if (!originalExtensionsList.length) {
|
|
295
213
|
return null;
|
|
296
214
|
}
|
|
297
|
-
const promises = originalExtensionsList.map(async
|
|
215
|
+
const promises = originalExtensionsList.map(async originalId => {
|
|
298
216
|
const extFolderPath = (0, _path.join)(originalExtensionsFolder, originalId);
|
|
299
217
|
const extFolderContent = await readdir(extFolderPath);
|
|
300
218
|
if (!extFolderPath.length) {
|
|
301
219
|
return {};
|
|
302
220
|
}
|
|
303
|
-
if (extFolderContent.includes(
|
|
221
|
+
if (extFolderContent.includes('manifest.json')) {
|
|
304
222
|
return {
|
|
305
223
|
originalId,
|
|
306
|
-
path: (0, _path.join)(originalExtensionsFolder, originalId)
|
|
224
|
+
path: (0, _path.join)(originalExtensionsFolder, originalId)
|
|
307
225
|
};
|
|
308
226
|
}
|
|
309
227
|
const [version] = extFolderContent;
|
|
310
228
|
return {
|
|
311
229
|
originalId,
|
|
312
|
-
path: (0, _path.join)(originalExtensionsFolder, originalId, version)
|
|
230
|
+
path: (0, _path.join)(originalExtensionsFolder, originalId, version)
|
|
313
231
|
};
|
|
314
232
|
});
|
|
315
233
|
const originalExtPaths = await Promise.all(promises);
|
|
316
|
-
extensionsEntries.forEach(
|
|
234
|
+
extensionsEntries.forEach(extensionObj => {
|
|
317
235
|
const [extensionsId] = extensionObj;
|
|
318
236
|
const extPath = extensionsSettings[extensionsId].path;
|
|
319
237
|
if (!/chrome-extensions/.test(extPath)) {
|
|
320
238
|
return;
|
|
321
239
|
}
|
|
322
|
-
const originalExtPath = originalExtPaths.find(
|
|
323
|
-
(el) => el.originalId === extensionsId
|
|
324
|
-
);
|
|
240
|
+
const originalExtPath = originalExtPaths.find(el => el.originalId === extensionsId);
|
|
325
241
|
if (!originalExtPath) {
|
|
326
242
|
return;
|
|
327
243
|
}
|
|
328
|
-
extensionsSettings[extensionsId].path = originalExtPath.path ||
|
|
244
|
+
extensionsSettings[extensionsId].path = originalExtPath.path || '';
|
|
329
245
|
});
|
|
330
246
|
return extensionsSettings;
|
|
331
247
|
};
|
|
@@ -334,14 +250,14 @@ const recalculateId = async ({
|
|
|
334
250
|
localExtObj,
|
|
335
251
|
extensionId,
|
|
336
252
|
extensionsSettings,
|
|
337
|
-
currentExtSettings
|
|
253
|
+
currentExtSettings
|
|
338
254
|
}) => {
|
|
339
255
|
if (currentExtSettings.manifest?.key) {
|
|
340
256
|
return extensionId;
|
|
341
257
|
}
|
|
342
|
-
const manifestFilePath = (0, _path.join)(localExtObj.path,
|
|
258
|
+
const manifestFilePath = (0, _path.join)(localExtObj.path, 'manifest.json');
|
|
343
259
|
const manifestString = await readFile(manifestFilePath, {
|
|
344
|
-
encoding:
|
|
260
|
+
encoding: 'utf8'
|
|
345
261
|
}).catch(() => ({}));
|
|
346
262
|
if (!manifestString) {
|
|
347
263
|
return extensionId;
|
|
@@ -355,19 +271,13 @@ const recalculateId = async ({
|
|
|
355
271
|
if (manifestObject.key) {
|
|
356
272
|
return extensionId;
|
|
357
273
|
}
|
|
358
|
-
let encoding =
|
|
359
|
-
if (osPlatform ===
|
|
360
|
-
encoding =
|
|
274
|
+
let encoding = 'utf8';
|
|
275
|
+
if (osPlatform === 'win32') {
|
|
276
|
+
encoding = 'utf16le';
|
|
361
277
|
}
|
|
362
278
|
const extPathToEncode = Buffer.from(localExtObj.path, encoding);
|
|
363
|
-
const hexEncodedPath = (0, _crypto.createHash)(
|
|
364
|
-
|
|
365
|
-
.digest("hex");
|
|
366
|
-
const newId = hexEncodedPath
|
|
367
|
-
.split("")
|
|
368
|
-
.slice(0, 32)
|
|
369
|
-
.map((symbol) => extIdEncoding[symbol])
|
|
370
|
-
.join("");
|
|
279
|
+
const hexEncodedPath = (0, _crypto.createHash)('sha256').update(extPathToEncode).digest('hex');
|
|
280
|
+
const newId = hexEncodedPath.split('').slice(0, 32).map(symbol => extIdEncoding[symbol]).join('');
|
|
371
281
|
if (extensionId !== newId) {
|
|
372
282
|
delete extensionsSettings[extensionId];
|
|
373
283
|
extensionsSettings[newId] = currentExtSettings;
|
|
@@ -377,20 +287,20 @@ const recalculateId = async ({
|
|
|
377
287
|
};
|
|
378
288
|
exports.recalculateId = recalculateId;
|
|
379
289
|
const extIdEncoding = {
|
|
380
|
-
0:
|
|
381
|
-
1:
|
|
382
|
-
2:
|
|
383
|
-
3:
|
|
384
|
-
4:
|
|
385
|
-
5:
|
|
386
|
-
6:
|
|
387
|
-
7:
|
|
388
|
-
8:
|
|
389
|
-
9:
|
|
390
|
-
a:
|
|
391
|
-
b:
|
|
392
|
-
c:
|
|
393
|
-
d:
|
|
394
|
-
e:
|
|
395
|
-
f:
|
|
396
|
-
};
|
|
290
|
+
0: 'a',
|
|
291
|
+
1: 'b',
|
|
292
|
+
2: 'c',
|
|
293
|
+
3: 'd',
|
|
294
|
+
4: 'e',
|
|
295
|
+
5: 'f',
|
|
296
|
+
6: 'g',
|
|
297
|
+
7: 'h',
|
|
298
|
+
8: 'i',
|
|
299
|
+
9: 'j',
|
|
300
|
+
a: 'k',
|
|
301
|
+
b: 'l',
|
|
302
|
+
c: 'm',
|
|
303
|
+
d: 'n',
|
|
304
|
+
e: 'o',
|
|
305
|
+
f: 'p'
|
|
306
|
+
};
|
package/dist/src/gologin.js
CHANGED
|
@@ -470,7 +470,10 @@ class GoLogin {
|
|
|
470
470
|
proxy = null;
|
|
471
471
|
}
|
|
472
472
|
this.proxy = proxy;
|
|
473
|
-
this.getTimeZone(proxy)
|
|
473
|
+
await this.getTimeZone(proxy).catch(e => {
|
|
474
|
+
console.error("Proxy Error. Check it and try again.");
|
|
475
|
+
throw new Error(`Proxy Error. ${e.message}`);
|
|
476
|
+
});
|
|
474
477
|
const [latitude, longitude] = this._tz.ll;
|
|
475
478
|
const {
|
|
476
479
|
accuracy
|
|
@@ -618,7 +621,7 @@ class GoLogin {
|
|
|
618
621
|
}
|
|
619
622
|
return port;
|
|
620
623
|
}
|
|
621
|
-
getTimeZone(proxy) {
|
|
624
|
+
async getTimeZone(proxy) {
|
|
622
625
|
debug("getting timeZone proxy=", proxy);
|
|
623
626
|
if (this.timezone) {
|
|
624
627
|
debug("getTimeZone from options", this.timezone);
|
|
@@ -626,25 +629,27 @@ class GoLogin {
|
|
|
626
629
|
return this._tz.timezone;
|
|
627
630
|
}
|
|
628
631
|
let data = null;
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
632
|
+
if (proxy && proxy.mode !== PROXY_NONE) {
|
|
633
|
+
if (proxy.mode.includes("socks")) {
|
|
634
|
+
for (let i = 0; i < 5; i++) {
|
|
635
|
+
try {
|
|
636
|
+
debug("getting timeZone socks try", i + 1);
|
|
637
|
+
return this.getTimezoneWithSocks(proxy);
|
|
638
|
+
} catch (e) {
|
|
639
|
+
console.log(e.message);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
throw new Error("Socks proxy connection timed out");
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
// const proxyUrl = `${proxy.mode}://${proxy.username}:${proxy.password}@${proxy.host}:${proxy.port}`;
|
|
646
|
+
// debug(`getTimeZone start ${TIMEZONE_URL}`, proxyUrl);
|
|
647
|
+
// const response = await requests.get(TIMEZONE_URL, {
|
|
648
|
+
// proxy: proxyUrl,
|
|
649
|
+
// timeout: 20 * 1000,
|
|
650
|
+
// maxAttempts: 5,
|
|
651
|
+
// });
|
|
652
|
+
// const result = JSON.parse(response.body);
|
|
648
653
|
const result = {
|
|
649
654
|
country: "ID",
|
|
650
655
|
stateProv: "Jakarta",
|
|
@@ -652,7 +657,7 @@ class GoLogin {
|
|
|
652
657
|
timezone: "Asia/Jakarta",
|
|
653
658
|
ll: ["-6.21462", "106.84513"],
|
|
654
659
|
languages: "id",
|
|
655
|
-
accuracy: 100
|
|
660
|
+
accuracy: 100
|
|
656
661
|
};
|
|
657
662
|
data = {
|
|
658
663
|
body: {
|
|
@@ -665,24 +670,24 @@ class GoLogin {
|
|
|
665
670
|
accuracy: 100
|
|
666
671
|
}
|
|
667
672
|
};
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
673
|
+
} else {
|
|
674
|
+
const response = await _requestretry.default.get(TIMEZONE_URL, {
|
|
675
|
+
timeout: 20 * 1000,
|
|
676
|
+
maxAttempts: 5
|
|
677
|
+
});
|
|
678
|
+
const result = JSON.parse(response.body);
|
|
679
|
+
data = {
|
|
680
|
+
body: {
|
|
681
|
+
country: result.country_code,
|
|
682
|
+
stateProv: result.city,
|
|
683
|
+
city: result.city,
|
|
684
|
+
timezone: (0, _timezone.tzlookup)(result.latitude, result.longitude),
|
|
685
|
+
ll: [result.latitude, result.longitude],
|
|
686
|
+
languages: "en",
|
|
687
|
+
accuracy: 100
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
}
|
|
686
691
|
debug("getTimeZone finish", data.body);
|
|
687
692
|
this._tz = data.body;
|
|
688
693
|
return this._tz.timezone;
|
|
@@ -741,7 +746,10 @@ class GoLogin {
|
|
|
741
746
|
Object.keys(process.env).forEach(key => {
|
|
742
747
|
env[key] = process.env[key];
|
|
743
748
|
});
|
|
744
|
-
const tz = this.getTimeZone(this.proxy)
|
|
749
|
+
const tz = await this.getTimeZone(this.proxy).catch(e => {
|
|
750
|
+
console.error("Proxy Error. Check it and try again.");
|
|
751
|
+
throw e;
|
|
752
|
+
});
|
|
745
753
|
env.TZ = tz;
|
|
746
754
|
let params = [`--proxy-server=${proxy}`, `--user-data-dir=${profile_path}`, "--password-store=basic", `--tz=${tz}`, "--lang=en"];
|
|
747
755
|
if (Array.isArray(this.extra_params) && this.extra_params.length) {
|
|
@@ -776,7 +784,10 @@ class GoLogin {
|
|
|
776
784
|
Object.keys(process.env).forEach(key => {
|
|
777
785
|
env[key] = process.env[key];
|
|
778
786
|
});
|
|
779
|
-
const tz = this.getTimeZone(this.proxy)
|
|
787
|
+
const tz = await this.getTimeZone(this.proxy).catch(e => {
|
|
788
|
+
console.error("Proxy Error. Check it and try again.");
|
|
789
|
+
throw e;
|
|
790
|
+
});
|
|
780
791
|
env.TZ = tz;
|
|
781
792
|
if (this.vnc_port) {
|
|
782
793
|
const script_path = (0, _path.resolve)(__dirname, "./run.sh");
|
|
@@ -265,21 +265,23 @@ export class BrowserChecker {
|
|
|
265
265
|
return;
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
)
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
268
|
+
return Promise.resolve();
|
|
269
|
+
|
|
270
|
+
// const hashFileContent = await exec(`cat ${join(this.#browserPath, DEB_HASH_FILE)}`);
|
|
271
|
+
// let serverRes = (hashFileContent.stdout || '').toString().trim();
|
|
272
|
+
// serverRes = serverRes.split(' ')[0];
|
|
273
|
+
|
|
274
|
+
// const calculateLocalBrowserHash = await exec(
|
|
275
|
+
// `cd ${join(this.#browserPath, EXTRACTED_FOLDER)} && find orbita-browser -type f -print0 | sort -z | \
|
|
276
|
+
// xargs -0 sha256sum > ${this.#browserPath}/calculatedFolderSha.txt`,
|
|
277
|
+
// );
|
|
278
|
+
|
|
279
|
+
// const localHashContent = await exec(`cd ${this.#browserPath} && sha256sum calculatedFolderSha.txt`);
|
|
280
|
+
// let userRes = (localHashContent.stdout || '').toString().trim();
|
|
281
|
+
// userRes = userRes.split(' ')[0];
|
|
282
|
+
// if (userRes !== serverRes) {
|
|
283
|
+
// throw new Error('Error in sum matching. Please run script again.');
|
|
284
|
+
// }
|
|
283
285
|
}
|
|
284
286
|
|
|
285
287
|
async replaceBrowser() {
|