feat: add getDNSCheck & getNftRulesCheck js methods

This commit is contained in:
divocat
2025-10-11 17:48:53 +03:00
parent 791cc1c945
commit d041334d88
6 changed files with 132 additions and 4 deletions

View File

@@ -0,0 +1,24 @@
import { executeShellCommand } from '../../helpers';
import { Podkop } from '../types';
export async function getDNSCheck(): Promise<
Podkop.MethodResponse<Podkop.DnsCheckResult>
> {
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: '',
};
}

View File

@@ -10,7 +10,6 @@ interface IGetDashboardSectionsResponse {
export async function getDashboardSections(): Promise<IGetDashboardSectionsResponse> {
const configSections = await getConfigSections();
console.log('configSections', configSections)
const clashProxies = await getClashProxies();
if (!clashProxies.success) {
@@ -28,7 +27,10 @@ export async function getDashboardSections(): Promise<IGetDashboardSectionsRespo
);
const data = configSections
.filter((section) => 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') {

View File

@@ -0,0 +1,24 @@
import { executeShellCommand } from '../../helpers';
import { Podkop } from '../types';
export async function getNftRulesCheck(): Promise<
Podkop.MethodResponse<Podkop.NftRulesCheckResult>
> {
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: '',
};
}

View File

@@ -2,3 +2,5 @@ export * from './getConfigSections';
export * from './getDashboardSections';
export * from './getPodkopStatus';
export * from './getSingboxStatus';
export * from './getDNSCheck';
export * from './getNftRulesCheck';

View File

@@ -53,4 +53,39 @@ export namespace Podkop {
'.name': string;
'.type': 'settings' | 'section';
};
export interface MethodSuccessResponse<T> {
success: true;
data: T;
}
export interface MethodFailureResponse {
success: false;
error: string;
}
export type MethodResponse<T> =
| MethodSuccessResponse<T>
| 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;
}
}

View File

@@ -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,