feat: import Sea vHost single-server testing release
This commit is contained in:
commit
248badd33e
441 files changed
+63221
No files matched your search
@@ -0,0 +1,44 @@
|
||||
import crypto from 'node:crypto';
|
||||
import http from 'node:http';
|
||||
import https from 'node:https';
|
||||
|
||||
const panelURL = process.env.SEA_PANEL_URL?.trim();
|
||||
const panelAPIKey = process.env.SEA_PANEL_API_KEY?.trim();
|
||||
const prefix = process.env.SEA_PANEL_TASK_PREFIX?.trim();
|
||||
const insecureTLS = process.env.SEA_PANEL_TLS_INSECURE === 'true';
|
||||
if (!panelURL || !panelAPIKey || !prefix || prefix.length < 12 || prefix.length > 80 || /[\r\n]/.test(prefix)) process.exit(2);
|
||||
const base = new URL(panelURL);
|
||||
const client = base.protocol === 'https:' ? https : http;
|
||||
const agent = base.protocol === 'https:' ? new https.Agent({ rejectUnauthorized: !insecureTLS }) : undefined;
|
||||
const md5 = (value) => crypto.createHash('md5').update(value).digest('hex');
|
||||
function panelForm(pathname, values) {
|
||||
const requestTime = Math.floor(Date.now() / 1000).toString();
|
||||
const body = Buffer.from(new URLSearchParams({ ...values, request_time: requestTime, request_token: md5(requestTime + md5(panelAPIKey)) }).toString());
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = client.request(new URL(pathname, base), { method: 'POST', agent, timeout: 30_000, headers: { 'content-type': 'application/x-www-form-urlencoded', 'content-length': body.length } }, (response) => {
|
||||
let data = '';
|
||||
response.setEncoding('utf8');
|
||||
response.on('data', (chunk) => { data += chunk; });
|
||||
response.on('end', () => {
|
||||
if (response.statusCode < 200 || response.statusCode > 299) return reject(new Error(`aaPanel returned HTTP ${response.statusCode}`));
|
||||
try { resolve(JSON.parse(data)); } catch { reject(new Error('aaPanel returned non-JSON data')); }
|
||||
});
|
||||
});
|
||||
request.on('timeout', () => request.destroy(new Error('aaPanel request timed out')));
|
||||
request.on('error', reject);
|
||||
request.end(body);
|
||||
});
|
||||
}
|
||||
function rows(payload) {
|
||||
if (Array.isArray(payload)) return payload;
|
||||
if (Array.isArray(payload?.data)) return payload.data;
|
||||
if (Array.isArray(payload?.data?.data)) return payload.data.data;
|
||||
return [];
|
||||
}
|
||||
const listing = await panelForm('/crontab', { action: 'GetCrontab' });
|
||||
const matches = rows(listing).filter((item) => String(item.name ?? item.sName ?? '').startsWith(prefix));
|
||||
for (const item of matches) {
|
||||
const id = Number(item.id);
|
||||
if (Number.isSafeInteger(id) && id > 0) await panelForm('/crontab', { action: 'DelCrontab', id: String(id) });
|
||||
}
|
||||
console.log(JSON.stringify({ removed: matches.length, prefix }));
|
||||
Reference in new issue
Block a user