diff --git a/fe-app-podkop/src/podkop/methods/getDNSCheck.ts b/fe-app-podkop/src/podkop/methods/getDNSCheck.ts new file mode 100644 index 0000000..8744230 --- /dev/null +++ b/fe-app-podkop/src/podkop/methods/getDNSCheck.ts @@ -0,0 +1,24 @@ +import { executeShellCommand } from '../../helpers'; +import { Podkop } from '../types'; + +export async function getDNSCheck(): Promise< + Podkop.MethodResponse +> { + const response = await executeShellCommand({ + command: '/usr/bin/podkop', + args: ['check_dns_available'], + timeout: 10000, + }); + + if (response.stdout) { + return { + success: true, + data: JSON.parse(response.stdout) as Podkop.DnsCheckResult, + }; + } + + return { + success: false, + error: '', + }; +} diff --git a/fe-app-podkop/src/podkop/methods/getDashboardSections.ts b/fe-app-podkop/src/podkop/methods/getDashboardSections.ts index 78d5c77..b6619d0 100644 --- a/fe-app-podkop/src/podkop/methods/getDashboardSections.ts +++ b/fe-app-podkop/src/podkop/methods/getDashboardSections.ts @@ -10,7 +10,6 @@ interface IGetDashboardSectionsResponse { export async function getDashboardSections(): Promise { const configSections = await getConfigSections(); - console.log('configSections', configSections) const clashProxies = await getClashProxies(); if (!clashProxies.success) { @@ -28,7 +27,10 @@ export async function getDashboardSections(): Promise section.connection_type !== 'block' && section[".type"] !== 'settings') + .filter( + (section) => + section.connection_type !== 'block' && section['.type'] !== 'settings', + ) .map((section) => { if (section.connection_type === 'proxy') { if (section.proxy_config_type === 'url') { diff --git a/fe-app-podkop/src/podkop/methods/getNftRulesCheck.ts b/fe-app-podkop/src/podkop/methods/getNftRulesCheck.ts new file mode 100644 index 0000000..f5eded4 --- /dev/null +++ b/fe-app-podkop/src/podkop/methods/getNftRulesCheck.ts @@ -0,0 +1,24 @@ +import { executeShellCommand } from '../../helpers'; +import { Podkop } from '../types'; + +export async function getNftRulesCheck(): Promise< + Podkop.MethodResponse +> { + const response = await executeShellCommand({ + command: '/usr/bin/podkop', + args: ['check_nft_rules'], + timeout: 10000, + }); + + if (response.stdout) { + return { + success: true, + data: JSON.parse(response.stdout) as Podkop.NftRulesCheckResult, + }; + } + + return { + success: false, + error: '', + }; +} diff --git a/fe-app-podkop/src/podkop/methods/index.ts b/fe-app-podkop/src/podkop/methods/index.ts index 6b2c1f3..98851a9 100644 --- a/fe-app-podkop/src/podkop/methods/index.ts +++ b/fe-app-podkop/src/podkop/methods/index.ts @@ -2,3 +2,5 @@ export * from './getConfigSections'; export * from './getDashboardSections'; export * from './getPodkopStatus'; export * from './getSingboxStatus'; +export * from './getDNSCheck'; +export * from './getNftRulesCheck'; diff --git a/fe-app-podkop/src/podkop/types.ts b/fe-app-podkop/src/podkop/types.ts index e6203e6..1e51a0f 100644 --- a/fe-app-podkop/src/podkop/types.ts +++ b/fe-app-podkop/src/podkop/types.ts @@ -53,4 +53,39 @@ export namespace Podkop { '.name': string; '.type': 'settings' | 'section'; }; + + export interface MethodSuccessResponse { + success: true; + data: T; + } + + export interface MethodFailureResponse { + success: false; + error: string; + } + + export type MethodResponse = + | MethodSuccessResponse + | MethodFailureResponse; + + export interface DnsCheckResult { + dns_type: 'udp' | 'doh' | 'dot'; + dns_server: string; + dns_status: 0 | 1; + local_dns_status: 0 | 1; + bootstrap_dns_server: string; + bootstrap_dns_status: 0 | 1; + dhcp_has_dns_server: 0 | 1; + } + + export interface NftRulesCheckResult { + table_exist: 0 | 1; + rules_mangle_exist: 0 | 1; + rules_mangle_counters: 0 | 1; + rules_mangle_output_exist: 0 | 1; + rules_mangle_output_counters: 0 | 1; + rules_proxy_exist: 0 | 1; + rules_proxy_counters: 0 | 1; + rules_other_mark_exist: 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 532b06d..06e499f 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 @@ -943,7 +943,6 @@ async function getConfigSections() { // src/podkop/methods/getDashboardSections.ts async function getDashboardSections() { const configSections = await getConfigSections(); - console.log("configSections", configSections); const clashProxies = await getClashProxies(); if (!clashProxies.success) { return { @@ -957,7 +956,9 @@ async function getDashboardSections() { value }) ); - const data = configSections.filter((section) => section.connection_type !== "block" && section[".type"] !== "settings").map((section) => { + const data = configSections.filter( + (section) => section.connection_type !== "block" && section[".type"] !== "settings" + ).map((section) => { if (section.connection_type === "proxy") { if (section.proxy_config_type === "url") { const outbound = proxies.find( @@ -1091,6 +1092,44 @@ async function getSingboxStatus() { return { running: 0, enabled: 0, status: "unknown" }; } +// src/podkop/methods/getDNSCheck.ts +async function getDNSCheck() { + const response = await executeShellCommand({ + command: "/usr/bin/podkop", + args: ["check_dns_available"], + timeout: 1e4 + }); + if (response.stdout) { + return { + success: true, + data: JSON.parse(response.stdout) + }; + } + return { + success: false, + error: "" + }; +} + +// src/podkop/methods/getNftRulesCheck.ts +async function getNftRulesCheck() { + const response = await executeShellCommand({ + command: "/usr/bin/podkop", + args: ["check_nft_rules"], + 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() { @@ -2026,7 +2065,9 @@ return baseclass.extend({ getClashVersion, getClashWsUrl, getConfigSections, + getDNSCheck, getDashboardSections, + getNftRulesCheck, getPodkopStatus, getProxyUrlName, getSingboxStatus,