From 5486dfb0a4fc78e234f9ed8f904e8aa596947e35 Mon Sep 17 00:00:00 2001 From: divocat Date: Sat, 11 Oct 2025 20:17:24 +0300 Subject: [PATCH] feat: add getSingBoxCheck js method --- .../src/podkop/methods/getSingBoxCheck.ts | 24 ++++++++++++++++ ...etSingboxStatus.ts => getSingBoxStatus.ts} | 2 +- fe-app-podkop/src/podkop/methods/index.ts | 3 +- .../tabs/dashboard/initDashboardController.ts | 4 +-- fe-app-podkop/src/podkop/types.ts | 9 ++++++ .../luci-static/resources/view/podkop/main.js | 28 ++++++++++++++++--- 6 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 fe-app-podkop/src/podkop/methods/getSingBoxCheck.ts rename fe-app-podkop/src/podkop/methods/{getSingboxStatus.ts => getSingBoxStatus.ts} (90%) diff --git a/fe-app-podkop/src/podkop/methods/getSingBoxCheck.ts b/fe-app-podkop/src/podkop/methods/getSingBoxCheck.ts new file mode 100644 index 0000000..6ad35cc --- /dev/null +++ b/fe-app-podkop/src/podkop/methods/getSingBoxCheck.ts @@ -0,0 +1,24 @@ +import { executeShellCommand } from '../../helpers'; +import { Podkop } from '../types'; + +export async function getSingBoxCheck(): Promise< + Podkop.MethodResponse +> { + const response = await executeShellCommand({ + command: '/usr/bin/podkop', + args: ['check_sing_box'], + timeout: 10000, + }); + + if (response.stdout) { + return { + success: true, + data: JSON.parse(response.stdout) as Podkop.SingBoxCheckResult, + }; + } + + return { + success: false, + error: '', + }; +} diff --git a/fe-app-podkop/src/podkop/methods/getSingboxStatus.ts b/fe-app-podkop/src/podkop/methods/getSingBoxStatus.ts similarity index 90% rename from fe-app-podkop/src/podkop/methods/getSingboxStatus.ts rename to fe-app-podkop/src/podkop/methods/getSingBoxStatus.ts index 41735f5..51d2f62 100644 --- a/fe-app-podkop/src/podkop/methods/getSingboxStatus.ts +++ b/fe-app-podkop/src/podkop/methods/getSingBoxStatus.ts @@ -1,6 +1,6 @@ import { executeShellCommand } from '../../helpers'; -export async function getSingboxStatus(): Promise<{ +export async function getSingBoxStatus(): Promise<{ running: number; enabled: number; status: string; diff --git a/fe-app-podkop/src/podkop/methods/index.ts b/fe-app-podkop/src/podkop/methods/index.ts index 98851a9..2577428 100644 --- a/fe-app-podkop/src/podkop/methods/index.ts +++ b/fe-app-podkop/src/podkop/methods/index.ts @@ -1,6 +1,7 @@ export * from './getConfigSections'; export * from './getDashboardSections'; export * from './getPodkopStatus'; -export * from './getSingboxStatus'; +export * from './getSingBoxStatus'; export * from './getDNSCheck'; export * from './getNftRulesCheck'; +export * from './getSingBoxCheck'; diff --git a/fe-app-podkop/src/podkop/tabs/dashboard/initDashboardController.ts b/fe-app-podkop/src/podkop/tabs/dashboard/initDashboardController.ts index d5c9526..fc7b5c9 100644 --- a/fe-app-podkop/src/podkop/tabs/dashboard/initDashboardController.ts +++ b/fe-app-podkop/src/podkop/tabs/dashboard/initDashboardController.ts @@ -1,7 +1,7 @@ import { getDashboardSections, getPodkopStatus, - getSingboxStatus, + getSingBoxStatus, } from '../../methods'; import { getClashApiUrl, @@ -52,7 +52,7 @@ async function fetchServicesInfo() { try { const [podkop, singbox] = await Promise.all([ getPodkopStatus(), - getSingboxStatus(), + getSingBoxStatus(), ]); store.set({ diff --git a/fe-app-podkop/src/podkop/types.ts b/fe-app-podkop/src/podkop/types.ts index 1e51a0f..558f99b 100644 --- a/fe-app-podkop/src/podkop/types.ts +++ b/fe-app-podkop/src/podkop/types.ts @@ -88,4 +88,13 @@ export namespace Podkop { rules_proxy_counters: 0 | 1; rules_other_mark_exist: 0 | 1; } + + export interface SingBoxCheckResult { + sing_box_installed: 0 | 1; + sing_box_version_ok: 0 | 1; + sing_box_service_exist: 0 | 1; + sing_box_autostart_disabled: 0 | 1; + sing_box_process_running: 0 | 1; + sing_box_ports_listening: 0 | 1; + } } diff --git a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/main.js b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/main.js index 06e499f..1ae5e68 100644 --- a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/main.js +++ b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/main.js @@ -1079,8 +1079,8 @@ async function getPodkopStatus() { return { enabled: 0, status: "unknown" }; } -// src/podkop/methods/getSingboxStatus.ts -async function getSingboxStatus() { +// src/podkop/methods/getSingBoxStatus.ts +async function getSingBoxStatus() { const response = await executeShellCommand({ command: "/usr/bin/podkop", args: ["get_sing_box_status"], @@ -1130,6 +1130,25 @@ async function getNftRulesCheck() { }; } +// src/podkop/methods/getSingBoxCheck.ts +async function getSingBoxCheck() { + const response = await executeShellCommand({ + command: "/usr/bin/podkop", + args: ["check_sing_box"], + timeout: 1e4 + }); + if (response.stdout) { + return { + success: true, + data: JSON.parse(response.stdout) + }; + } + return { + success: false, + error: "" + }; +} + // src/podkop/services/tab.service.ts var TabService = class _TabService { constructor() { @@ -1691,7 +1710,7 @@ async function fetchServicesInfo() { try { const [podkop, singbox] = await Promise.all([ getPodkopStatus(), - getSingboxStatus() + getSingBoxStatus() ]); store.set({ servicesInfoWidget: { @@ -2070,7 +2089,8 @@ return baseclass.extend({ getNftRulesCheck, getPodkopStatus, getProxyUrlName, - getSingboxStatus, + getSingBoxCheck, + getSingBoxStatus, initDashboardController, initDiagnosticController, injectGlobalStyles,