mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-08 12:36:50 +03:00
feat: add getDNSCheck & getNftRulesCheck js methods
This commit is contained in:
24
fe-app-podkop/src/podkop/methods/getDNSCheck.ts
Normal file
24
fe-app-podkop/src/podkop/methods/getDNSCheck.ts
Normal 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: '',
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -10,7 +10,6 @@ interface IGetDashboardSectionsResponse {
|
|||||||
|
|
||||||
export async function getDashboardSections(): Promise<IGetDashboardSectionsResponse> {
|
export async function getDashboardSections(): Promise<IGetDashboardSectionsResponse> {
|
||||||
const configSections = await getConfigSections();
|
const configSections = await getConfigSections();
|
||||||
console.log('configSections', configSections)
|
|
||||||
const clashProxies = await getClashProxies();
|
const clashProxies = await getClashProxies();
|
||||||
|
|
||||||
if (!clashProxies.success) {
|
if (!clashProxies.success) {
|
||||||
@@ -28,7 +27,10 @@ export async function getDashboardSections(): Promise<IGetDashboardSectionsRespo
|
|||||||
);
|
);
|
||||||
|
|
||||||
const data = configSections
|
const data = configSections
|
||||||
.filter((section) => section.connection_type !== 'block' && section[".type"] !== 'settings')
|
.filter(
|
||||||
|
(section) =>
|
||||||
|
section.connection_type !== 'block' && section['.type'] !== 'settings',
|
||||||
|
)
|
||||||
.map((section) => {
|
.map((section) => {
|
||||||
if (section.connection_type === 'proxy') {
|
if (section.connection_type === 'proxy') {
|
||||||
if (section.proxy_config_type === 'url') {
|
if (section.proxy_config_type === 'url') {
|
||||||
|
|||||||
24
fe-app-podkop/src/podkop/methods/getNftRulesCheck.ts
Normal file
24
fe-app-podkop/src/podkop/methods/getNftRulesCheck.ts
Normal 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: '',
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -2,3 +2,5 @@ export * from './getConfigSections';
|
|||||||
export * from './getDashboardSections';
|
export * from './getDashboardSections';
|
||||||
export * from './getPodkopStatus';
|
export * from './getPodkopStatus';
|
||||||
export * from './getSingboxStatus';
|
export * from './getSingboxStatus';
|
||||||
|
export * from './getDNSCheck';
|
||||||
|
export * from './getNftRulesCheck';
|
||||||
|
|||||||
@@ -53,4 +53,39 @@ export namespace Podkop {
|
|||||||
'.name': string;
|
'.name': string;
|
||||||
'.type': 'settings' | 'section';
|
'.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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -943,7 +943,6 @@ async function getConfigSections() {
|
|||||||
// src/podkop/methods/getDashboardSections.ts
|
// src/podkop/methods/getDashboardSections.ts
|
||||||
async function getDashboardSections() {
|
async function getDashboardSections() {
|
||||||
const configSections = await getConfigSections();
|
const configSections = await getConfigSections();
|
||||||
console.log("configSections", configSections);
|
|
||||||
const clashProxies = await getClashProxies();
|
const clashProxies = await getClashProxies();
|
||||||
if (!clashProxies.success) {
|
if (!clashProxies.success) {
|
||||||
return {
|
return {
|
||||||
@@ -957,7 +956,9 @@ async function getDashboardSections() {
|
|||||||
value
|
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.connection_type === "proxy") {
|
||||||
if (section.proxy_config_type === "url") {
|
if (section.proxy_config_type === "url") {
|
||||||
const outbound = proxies.find(
|
const outbound = proxies.find(
|
||||||
@@ -1091,6 +1092,44 @@ async function getSingboxStatus() {
|
|||||||
return { running: 0, enabled: 0, status: "unknown" };
|
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
|
// src/podkop/services/tab.service.ts
|
||||||
var TabService = class _TabService {
|
var TabService = class _TabService {
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -2026,7 +2065,9 @@ return baseclass.extend({
|
|||||||
getClashVersion,
|
getClashVersion,
|
||||||
getClashWsUrl,
|
getClashWsUrl,
|
||||||
getConfigSections,
|
getConfigSections,
|
||||||
|
getDNSCheck,
|
||||||
getDashboardSections,
|
getDashboardSections,
|
||||||
|
getNftRulesCheck,
|
||||||
getPodkopStatus,
|
getPodkopStatus,
|
||||||
getProxyUrlName,
|
getProxyUrlName,
|
||||||
getSingboxStatus,
|
getSingboxStatus,
|
||||||
|
|||||||
Reference in New Issue
Block a user