hedgequantx 2.6.161 → 2.6.162
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/package.json +1 -1
- package/src/menus/ai-agent-connect.js +181 -0
- package/src/menus/ai-agent-models.js +219 -0
- package/src/menus/ai-agent-oauth.js +292 -0
- package/src/menus/ai-agent-ui.js +141 -0
- package/src/menus/ai-agent.js +88 -1489
- package/src/pages/algo/copy-engine.js +449 -0
- package/src/pages/algo/copy-trading.js +11 -543
- package/src/pages/algo/smart-logs-data.js +218 -0
- package/src/pages/algo/smart-logs.js +9 -214
- package/src/pages/algo/ui-constants.js +144 -0
- package/src/pages/algo/ui-summary.js +184 -0
- package/src/pages/algo/ui.js +42 -526
- package/src/pages/stats-calculations.js +191 -0
- package/src/pages/stats-ui.js +381 -0
- package/src/pages/stats.js +14 -507
- package/src/services/ai/client-analysis.js +194 -0
- package/src/services/ai/client-models.js +333 -0
- package/src/services/ai/client.js +6 -489
- package/src/services/ai/index.js +2 -257
- package/src/services/ai/proxy-install.js +249 -0
- package/src/services/ai/proxy-manager.js +29 -411
- package/src/services/ai/proxy-remote.js +161 -0
- package/src/services/ai/supervisor-optimize.js +215 -0
- package/src/services/ai/supervisor-sync.js +178 -0
- package/src/services/ai/supervisor.js +50 -515
- package/src/services/ai/validation.js +250 -0
- package/src/services/hqx-server-events.js +110 -0
- package/src/services/hqx-server-handlers.js +217 -0
- package/src/services/hqx-server-latency.js +136 -0
- package/src/services/hqx-server.js +51 -403
- package/src/services/position-constants.js +28 -0
- package/src/services/position-manager.js +105 -554
- package/src/services/position-momentum.js +206 -0
- package/src/services/projectx/accounts.js +142 -0
- package/src/services/projectx/index.js +40 -289
- package/src/services/projectx/trading.js +180 -0
- package/src/services/rithmic/handlers.js +2 -208
- package/src/services/rithmic/index.js +32 -542
- package/src/services/rithmic/latency-tracker.js +182 -0
- package/src/services/rithmic/specs.js +146 -0
- package/src/services/rithmic/trade-history.js +254 -0
package/src/services/ai/index.js
CHANGED
|
@@ -7,6 +7,7 @@ const { getProviders, getProvider } = require('./providers');
|
|
|
7
7
|
const { storage } = require('../session');
|
|
8
8
|
const AISupervisor = require('./supervisor');
|
|
9
9
|
const StrategySupervisor = require('./strategy-supervisor');
|
|
10
|
+
const { validateConnection } = require('./validation');
|
|
10
11
|
|
|
11
12
|
// In-memory cache of connections
|
|
12
13
|
let connectionsCache = null;
|
|
@@ -348,263 +349,7 @@ const getCredentials = () => {
|
|
|
348
349
|
return agent?.credentials || null;
|
|
349
350
|
};
|
|
350
351
|
|
|
351
|
-
|
|
352
|
-
* Validate API key with provider
|
|
353
|
-
*/
|
|
354
|
-
const validateConnection = async (providerId, optionId, credentials) => {
|
|
355
|
-
const provider = getProvider(providerId);
|
|
356
|
-
if (!provider) return { valid: false, error: 'Invalid provider' };
|
|
357
|
-
|
|
358
|
-
try {
|
|
359
|
-
switch (providerId) {
|
|
360
|
-
case 'anthropic':
|
|
361
|
-
return await validateAnthropic(credentials);
|
|
362
|
-
case 'openai':
|
|
363
|
-
return await validateOpenAI(credentials);
|
|
364
|
-
case 'gemini':
|
|
365
|
-
return await validateGemini(credentials);
|
|
366
|
-
case 'deepseek':
|
|
367
|
-
return await validateDeepSeek(credentials);
|
|
368
|
-
case 'groq':
|
|
369
|
-
return await validateGroq(credentials);
|
|
370
|
-
case 'ollama':
|
|
371
|
-
return await validateOllama(credentials);
|
|
372
|
-
case 'lmstudio':
|
|
373
|
-
return await validateLMStudio(credentials);
|
|
374
|
-
case 'custom':
|
|
375
|
-
return await validateCustom(credentials);
|
|
376
|
-
// OpenAI-compatible providers (use same validation)
|
|
377
|
-
case 'openrouter':
|
|
378
|
-
return await validateOpenRouter(credentials);
|
|
379
|
-
case 'xai':
|
|
380
|
-
case 'mistral':
|
|
381
|
-
case 'perplexity':
|
|
382
|
-
case 'together':
|
|
383
|
-
case 'qwen':
|
|
384
|
-
case 'moonshot':
|
|
385
|
-
case 'yi':
|
|
386
|
-
case 'zhipu':
|
|
387
|
-
case 'baichuan':
|
|
388
|
-
return await validateOpenAICompatible(provider, credentials);
|
|
389
|
-
default:
|
|
390
|
-
return { valid: false, error: 'Unknown provider' };
|
|
391
|
-
}
|
|
392
|
-
} catch (error) {
|
|
393
|
-
return { valid: false, error: error.message };
|
|
394
|
-
}
|
|
395
|
-
};
|
|
396
|
-
|
|
397
|
-
// Validation functions for each provider
|
|
398
|
-
const validateAnthropic = async (credentials) => {
|
|
399
|
-
try {
|
|
400
|
-
const token = credentials.apiKey || credentials.sessionKey || credentials.accessToken;
|
|
401
|
-
if (!token) return { valid: false, error: 'No API key provided' };
|
|
402
|
-
|
|
403
|
-
// Validate by fetching models from API - this proves the token works
|
|
404
|
-
const response = await fetch('https://api.anthropic.com/v1/models', {
|
|
405
|
-
method: 'GET',
|
|
406
|
-
headers: {
|
|
407
|
-
'x-api-key': token,
|
|
408
|
-
'anthropic-version': '2023-06-01'
|
|
409
|
-
}
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
if (response.ok) {
|
|
413
|
-
const data = await response.json();
|
|
414
|
-
if (data.data && Array.isArray(data.data) && data.data.length > 0) {
|
|
415
|
-
return { valid: true, tokenType: 'api_key' };
|
|
416
|
-
}
|
|
417
|
-
return { valid: false, error: 'API returned no models' };
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
const error = await response.json();
|
|
421
|
-
return { valid: false, error: error.error?.message || 'Invalid API key' };
|
|
422
|
-
} catch (e) {
|
|
423
|
-
return { valid: false, error: e.message };
|
|
424
|
-
}
|
|
425
|
-
};
|
|
426
|
-
|
|
427
|
-
const validateOpenAI = async (credentials) => {
|
|
428
|
-
try {
|
|
429
|
-
const response = await fetch('https://api.openai.com/v1/models', {
|
|
430
|
-
headers: {
|
|
431
|
-
'Authorization': `Bearer ${credentials.apiKey || credentials.accessToken}`
|
|
432
|
-
}
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
if (response.ok) {
|
|
436
|
-
return { valid: true };
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
return { valid: false, error: 'Invalid API key' };
|
|
440
|
-
} catch (e) {
|
|
441
|
-
return { valid: false, error: e.message };
|
|
442
|
-
}
|
|
443
|
-
};
|
|
444
|
-
|
|
445
|
-
const validateGemini = async (credentials) => {
|
|
446
|
-
try {
|
|
447
|
-
const response = await fetch(
|
|
448
|
-
`https://generativelanguage.googleapis.com/v1/models?key=${credentials.apiKey}`
|
|
449
|
-
);
|
|
450
|
-
|
|
451
|
-
if (response.ok) {
|
|
452
|
-
return { valid: true };
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
return { valid: false, error: 'Invalid API key' };
|
|
456
|
-
} catch (e) {
|
|
457
|
-
return { valid: false, error: e.message };
|
|
458
|
-
}
|
|
459
|
-
};
|
|
460
|
-
|
|
461
|
-
const validateDeepSeek = async (credentials) => {
|
|
462
|
-
try {
|
|
463
|
-
const response = await fetch('https://api.deepseek.com/v1/models', {
|
|
464
|
-
headers: {
|
|
465
|
-
'Authorization': `Bearer ${credentials.apiKey}`
|
|
466
|
-
}
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
if (response.ok) {
|
|
470
|
-
return { valid: true };
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
return { valid: false, error: 'Invalid API key' };
|
|
474
|
-
} catch (e) {
|
|
475
|
-
return { valid: false, error: e.message };
|
|
476
|
-
}
|
|
477
|
-
};
|
|
478
|
-
|
|
479
|
-
const validateGroq = async (credentials) => {
|
|
480
|
-
try {
|
|
481
|
-
const response = await fetch('https://api.groq.com/openai/v1/models', {
|
|
482
|
-
headers: {
|
|
483
|
-
'Authorization': `Bearer ${credentials.apiKey}`
|
|
484
|
-
}
|
|
485
|
-
});
|
|
486
|
-
|
|
487
|
-
if (response.ok) {
|
|
488
|
-
return { valid: true };
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
return { valid: false, error: 'Invalid API key' };
|
|
492
|
-
} catch (e) {
|
|
493
|
-
return { valid: false, error: e.message };
|
|
494
|
-
}
|
|
495
|
-
};
|
|
496
|
-
|
|
497
|
-
const validateOllama = async (credentials) => {
|
|
498
|
-
try {
|
|
499
|
-
const endpoint = credentials.endpoint || 'http://localhost:11434';
|
|
500
|
-
const response = await fetch(`${endpoint}/api/tags`);
|
|
501
|
-
|
|
502
|
-
if (response.ok) {
|
|
503
|
-
const data = await response.json();
|
|
504
|
-
return {
|
|
505
|
-
valid: true,
|
|
506
|
-
models: data.models?.map(m => m.name) || []
|
|
507
|
-
};
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
return { valid: false, error: 'Cannot connect to Ollama' };
|
|
511
|
-
} catch (e) {
|
|
512
|
-
return { valid: false, error: 'Ollama not running. Start with: ollama serve' };
|
|
513
|
-
}
|
|
514
|
-
};
|
|
515
|
-
|
|
516
|
-
const validateCustom = async (credentials) => {
|
|
517
|
-
try {
|
|
518
|
-
const response = await fetch(`${credentials.endpoint}/models`, {
|
|
519
|
-
headers: credentials.apiKey ? {
|
|
520
|
-
'Authorization': `Bearer ${credentials.apiKey}`
|
|
521
|
-
} : {}
|
|
522
|
-
});
|
|
523
|
-
|
|
524
|
-
if (response.ok) {
|
|
525
|
-
return { valid: true };
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
return { valid: false, error: 'Cannot connect to endpoint' };
|
|
529
|
-
} catch (e) {
|
|
530
|
-
return { valid: false, error: e.message };
|
|
531
|
-
}
|
|
532
|
-
};
|
|
533
|
-
|
|
534
|
-
const validateOpenRouter = async (credentials) => {
|
|
535
|
-
try {
|
|
536
|
-
const response = await fetch('https://openrouter.ai/api/v1/models', {
|
|
537
|
-
headers: {
|
|
538
|
-
'Authorization': `Bearer ${credentials.apiKey}`
|
|
539
|
-
}
|
|
540
|
-
});
|
|
541
|
-
|
|
542
|
-
if (response.ok) {
|
|
543
|
-
return { valid: true };
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
return { valid: false, error: 'Invalid API key' };
|
|
547
|
-
} catch (e) {
|
|
548
|
-
return { valid: false, error: e.message };
|
|
549
|
-
}
|
|
550
|
-
};
|
|
551
|
-
|
|
552
|
-
const validateLMStudio = async (credentials) => {
|
|
553
|
-
try {
|
|
554
|
-
const endpoint = credentials.endpoint || 'http://localhost:1234/v1';
|
|
555
|
-
const response = await fetch(`${endpoint}/models`);
|
|
556
|
-
|
|
557
|
-
if (response.ok) {
|
|
558
|
-
const data = await response.json();
|
|
559
|
-
return {
|
|
560
|
-
valid: true,
|
|
561
|
-
models: data.data?.map(m => m.id) || []
|
|
562
|
-
};
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
return { valid: false, error: 'Cannot connect to LM Studio' };
|
|
566
|
-
} catch (e) {
|
|
567
|
-
return { valid: false, error: 'LM Studio not running. Start local server first.' };
|
|
568
|
-
}
|
|
569
|
-
};
|
|
570
|
-
|
|
571
|
-
const validateOpenAICompatible = async (provider, credentials) => {
|
|
572
|
-
try {
|
|
573
|
-
const endpoint = provider.endpoint;
|
|
574
|
-
const response = await fetch(`${endpoint}/models`, {
|
|
575
|
-
headers: {
|
|
576
|
-
'Authorization': `Bearer ${credentials.apiKey}`,
|
|
577
|
-
'Content-Type': 'application/json'
|
|
578
|
-
}
|
|
579
|
-
});
|
|
580
|
-
|
|
581
|
-
if (response.ok) {
|
|
582
|
-
return { valid: true };
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
// Some providers don't have /models endpoint, try a simple chat
|
|
586
|
-
const chatResponse = await fetch(`${endpoint}/chat/completions`, {
|
|
587
|
-
method: 'POST',
|
|
588
|
-
headers: {
|
|
589
|
-
'Authorization': `Bearer ${credentials.apiKey}`,
|
|
590
|
-
'Content-Type': 'application/json'
|
|
591
|
-
},
|
|
592
|
-
body: JSON.stringify({
|
|
593
|
-
model: provider.defaultModel,
|
|
594
|
-
messages: [{ role: 'user', content: 'hi' }],
|
|
595
|
-
max_tokens: 5
|
|
596
|
-
})
|
|
597
|
-
});
|
|
598
|
-
|
|
599
|
-
if (chatResponse.ok) {
|
|
600
|
-
return { valid: true };
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
return { valid: false, error: 'Invalid API key or endpoint' };
|
|
604
|
-
} catch (e) {
|
|
605
|
-
return { valid: false, error: e.message };
|
|
606
|
-
}
|
|
607
|
-
};
|
|
352
|
+
// validateConnection imported from ./validation
|
|
608
353
|
|
|
609
354
|
module.exports = {
|
|
610
355
|
// Provider info
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview CLIProxyAPI Installation
|
|
3
|
+
*
|
|
4
|
+
* Downloads, extracts, and configures CLIProxyAPI binary
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const https = require('https');
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const os = require('os');
|
|
11
|
+
const { exec } = require('child_process');
|
|
12
|
+
|
|
13
|
+
// Configuration
|
|
14
|
+
const PROXY_VERSION = 'v6.6.84';
|
|
15
|
+
const PROXY_PORT = 8317;
|
|
16
|
+
const PROXY_DIR = path.join(os.homedir(), '.hqx', 'proxy');
|
|
17
|
+
const PROXY_BIN = path.join(PROXY_DIR, process.platform === 'win32' ? 'cli-proxy-api.exe' : 'cli-proxy-api');
|
|
18
|
+
const PROXY_CONFIG = path.join(PROXY_DIR, 'config.yaml');
|
|
19
|
+
const PROXY_AUTH_DIR = path.join(PROXY_DIR, 'auths');
|
|
20
|
+
const API_KEY = 'hqx-local-key';
|
|
21
|
+
const MANAGEMENT_KEY = 'hqx-mgmt-key';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Get download URL for current platform
|
|
25
|
+
*/
|
|
26
|
+
const getDownloadUrl = () => {
|
|
27
|
+
const platform = process.platform;
|
|
28
|
+
const arch = process.arch;
|
|
29
|
+
|
|
30
|
+
let osName, archName, ext;
|
|
31
|
+
|
|
32
|
+
if (platform === 'darwin') {
|
|
33
|
+
osName = 'darwin';
|
|
34
|
+
archName = arch === 'arm64' ? 'arm64' : 'amd64';
|
|
35
|
+
ext = 'tar.gz';
|
|
36
|
+
} else if (platform === 'win32') {
|
|
37
|
+
osName = 'windows';
|
|
38
|
+
archName = arch === 'arm64' ? 'arm64' : 'amd64';
|
|
39
|
+
ext = 'zip';
|
|
40
|
+
} else {
|
|
41
|
+
osName = 'linux';
|
|
42
|
+
archName = arch === 'arm64' ? 'arm64' : 'amd64';
|
|
43
|
+
ext = 'tar.gz';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const version = PROXY_VERSION.replace('v', '');
|
|
47
|
+
return `https://github.com/router-for-me/CLIProxyAPI/releases/download/${PROXY_VERSION}/CLIProxyAPI_${version}_${osName}_${archName}.${ext}`;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Check if CLIProxyAPI binary exists
|
|
52
|
+
*/
|
|
53
|
+
const isInstalled = () => {
|
|
54
|
+
return fs.existsSync(PROXY_BIN);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Download file from URL
|
|
59
|
+
*/
|
|
60
|
+
const downloadFile = (url, dest) => {
|
|
61
|
+
return new Promise((resolve, reject) => {
|
|
62
|
+
const file = fs.createWriteStream(dest);
|
|
63
|
+
|
|
64
|
+
const request = (url) => {
|
|
65
|
+
https.get(url, (res) => {
|
|
66
|
+
if (res.statusCode === 302 || res.statusCode === 301) {
|
|
67
|
+
request(res.headers.location);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (res.statusCode !== 200) {
|
|
72
|
+
reject(new Error(`HTTP ${res.statusCode}`));
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
res.pipe(file);
|
|
77
|
+
file.on('finish', () => {
|
|
78
|
+
file.close();
|
|
79
|
+
resolve();
|
|
80
|
+
});
|
|
81
|
+
}).on('error', (err) => {
|
|
82
|
+
fs.unlink(dest, () => {});
|
|
83
|
+
reject(err);
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
request(url);
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Extract tar.gz archive
|
|
93
|
+
*/
|
|
94
|
+
const extractTarGz = (archive, dest) => {
|
|
95
|
+
return new Promise((resolve, reject) => {
|
|
96
|
+
exec(`tar -xzf "${archive}" -C "${dest}"`, (err) => {
|
|
97
|
+
if (err) reject(err);
|
|
98
|
+
else resolve();
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Extract zip archive (Windows)
|
|
105
|
+
*/
|
|
106
|
+
const extractZip = (archive, dest) => {
|
|
107
|
+
return new Promise((resolve, reject) => {
|
|
108
|
+
exec(`powershell -command "Expand-Archive -Path '${archive}' -DestinationPath '${dest}' -Force"`, (err) => {
|
|
109
|
+
if (err) reject(err);
|
|
110
|
+
else resolve();
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Generate config file content
|
|
117
|
+
*/
|
|
118
|
+
const getConfigContent = () => {
|
|
119
|
+
return `port: ${PROXY_PORT}
|
|
120
|
+
auth-dir: "${PROXY_AUTH_DIR}"
|
|
121
|
+
api-keys:
|
|
122
|
+
- "${API_KEY}"
|
|
123
|
+
remote-management:
|
|
124
|
+
secret-key: "${MANAGEMENT_KEY}"
|
|
125
|
+
allow-remote-management: false
|
|
126
|
+
request-retry: 3
|
|
127
|
+
quota-exceeded:
|
|
128
|
+
switch-project: true
|
|
129
|
+
switch-preview-model: true
|
|
130
|
+
`;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Download and install CLIProxyAPI
|
|
135
|
+
* @param {Function} onProgress - Progress callback (message)
|
|
136
|
+
*/
|
|
137
|
+
const install = async (onProgress = () => {}) => {
|
|
138
|
+
// Create directories
|
|
139
|
+
if (!fs.existsSync(PROXY_DIR)) {
|
|
140
|
+
fs.mkdirSync(PROXY_DIR, { recursive: true });
|
|
141
|
+
}
|
|
142
|
+
if (!fs.existsSync(PROXY_AUTH_DIR)) {
|
|
143
|
+
fs.mkdirSync(PROXY_AUTH_DIR, { recursive: true });
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
onProgress('Downloading CLIProxyAPI...');
|
|
147
|
+
|
|
148
|
+
const downloadUrl = getDownloadUrl();
|
|
149
|
+
const ext = process.platform === 'win32' ? 'zip' : 'tar.gz';
|
|
150
|
+
const archivePath = path.join(PROXY_DIR, `cliproxyapi.${ext}`);
|
|
151
|
+
|
|
152
|
+
// Download
|
|
153
|
+
await downloadFile(downloadUrl, archivePath);
|
|
154
|
+
|
|
155
|
+
onProgress('Extracting...');
|
|
156
|
+
|
|
157
|
+
// Extract
|
|
158
|
+
if (ext === 'zip') {
|
|
159
|
+
await extractZip(archivePath, PROXY_DIR);
|
|
160
|
+
} else {
|
|
161
|
+
await extractTarGz(archivePath, PROXY_DIR);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Find the binary (it might be in a subdirectory)
|
|
165
|
+
const possibleBins = [
|
|
166
|
+
path.join(PROXY_DIR, 'cli-proxy-api'),
|
|
167
|
+
path.join(PROXY_DIR, 'cli-proxy-api.exe'),
|
|
168
|
+
path.join(PROXY_DIR, 'CLIProxyAPI', 'cli-proxy-api'),
|
|
169
|
+
path.join(PROXY_DIR, 'CLIProxyAPI', 'cli-proxy-api.exe')
|
|
170
|
+
];
|
|
171
|
+
|
|
172
|
+
for (const bin of possibleBins) {
|
|
173
|
+
if (fs.existsSync(bin) && bin !== PROXY_BIN) {
|
|
174
|
+
fs.renameSync(bin, PROXY_BIN);
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Make executable (Unix)
|
|
180
|
+
if (process.platform !== 'win32') {
|
|
181
|
+
fs.chmodSync(PROXY_BIN, 0o755);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Create config file
|
|
185
|
+
fs.writeFileSync(PROXY_CONFIG, getConfigContent());
|
|
186
|
+
|
|
187
|
+
// Cleanup archive
|
|
188
|
+
fs.unlinkSync(archivePath);
|
|
189
|
+
|
|
190
|
+
onProgress('Installation complete');
|
|
191
|
+
|
|
192
|
+
return true;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Check if config has correct management key (plain text, not hashed)
|
|
197
|
+
* @returns {boolean}
|
|
198
|
+
*/
|
|
199
|
+
const isConfigValid = () => {
|
|
200
|
+
if (!fs.existsSync(PROXY_CONFIG)) return false;
|
|
201
|
+
|
|
202
|
+
try {
|
|
203
|
+
const config = fs.readFileSync(PROXY_CONFIG, 'utf8');
|
|
204
|
+
|
|
205
|
+
if (!config.includes('remote-management:') || !config.includes('secret-key:')) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Check if key is hashed (bcrypt hashes start with $2a$, $2b$, or $2y$)
|
|
210
|
+
if (config.includes('$2a$') || config.includes('$2b$') || config.includes('$2y$')) {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (!config.includes(MANAGEMENT_KEY)) {
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return true;
|
|
219
|
+
} catch (e) {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Rewrite config file with correct settings
|
|
226
|
+
*/
|
|
227
|
+
const rewriteConfig = () => {
|
|
228
|
+
if (!fs.existsSync(PROXY_DIR)) {
|
|
229
|
+
fs.mkdirSync(PROXY_DIR, { recursive: true });
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
fs.writeFileSync(PROXY_CONFIG, getConfigContent());
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
module.exports = {
|
|
236
|
+
PROXY_VERSION,
|
|
237
|
+
PROXY_PORT,
|
|
238
|
+
PROXY_DIR,
|
|
239
|
+
PROXY_BIN,
|
|
240
|
+
PROXY_CONFIG,
|
|
241
|
+
PROXY_AUTH_DIR,
|
|
242
|
+
API_KEY,
|
|
243
|
+
MANAGEMENT_KEY,
|
|
244
|
+
getDownloadUrl,
|
|
245
|
+
isInstalled,
|
|
246
|
+
install,
|
|
247
|
+
isConfigValid,
|
|
248
|
+
rewriteConfig,
|
|
249
|
+
};
|