mirror of
https://github.com/itdoginfo/podkop.git
synced 2026-02-01 15:20:55 +03:00
refactor: reorganize all methods
This commit is contained in:
@@ -1,2 +0,0 @@
|
|||||||
export * from './types';
|
|
||||||
export * from './createBaseApiRequest';
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
export type IBaseApiResponse<T> =
|
|
||||||
| {
|
|
||||||
success: true;
|
|
||||||
data: T;
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
success: false;
|
|
||||||
message: string;
|
|
||||||
};
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
export * from './types';
|
|
||||||
export * from './methods';
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
import { ClashAPI } from '../types';
|
|
||||||
import { getClashApiUrl } from '../../helpers';
|
|
||||||
import { createBaseApiRequest, IBaseApiResponse } from '../../api';
|
|
||||||
|
|
||||||
export async function getClashConfig(): Promise<
|
|
||||||
IBaseApiResponse<ClashAPI.Config>
|
|
||||||
> {
|
|
||||||
return createBaseApiRequest<ClashAPI.Config>(() =>
|
|
||||||
fetch(`${getClashApiUrl()}/configs`, {
|
|
||||||
method: 'GET',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
import { ClashAPI } from '../types';
|
|
||||||
import { getClashApiUrl } from '../../helpers';
|
|
||||||
import { createBaseApiRequest, IBaseApiResponse } from '../../api';
|
|
||||||
|
|
||||||
export async function getClashGroupDelay(
|
|
||||||
group: string,
|
|
||||||
url = 'https://www.gstatic.com/generate_204',
|
|
||||||
timeout = 2000,
|
|
||||||
): Promise<IBaseApiResponse<ClashAPI.Delays>> {
|
|
||||||
const endpoint = `${getClashApiUrl()}/group/${group}/delay?url=${encodeURIComponent(
|
|
||||||
url,
|
|
||||||
)}&timeout=${timeout}`;
|
|
||||||
|
|
||||||
return createBaseApiRequest<ClashAPI.Delays>(() =>
|
|
||||||
fetch(endpoint, {
|
|
||||||
method: 'GET',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
import { ClashAPI } from '../types';
|
|
||||||
import { getClashApiUrl } from '../../helpers';
|
|
||||||
import { createBaseApiRequest, IBaseApiResponse } from '../../api';
|
|
||||||
|
|
||||||
export async function getClashVersion(): Promise<
|
|
||||||
IBaseApiResponse<ClashAPI.Version>
|
|
||||||
> {
|
|
||||||
return createBaseApiRequest<ClashAPI.Version>(() =>
|
|
||||||
fetch(`${getClashApiUrl()}/version`, {
|
|
||||||
method: 'GET',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
export * from './getConfig';
|
|
||||||
export * from './getGroupDelay';
|
|
||||||
export * from './getProxies';
|
|
||||||
export * from './getVersion';
|
|
||||||
export * from './triggerProxySelector';
|
|
||||||
export * from './triggerLatencyTest';
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
import { getClashApiUrl } from '../../helpers';
|
|
||||||
import { createBaseApiRequest, IBaseApiResponse } from '../../api';
|
|
||||||
|
|
||||||
export async function triggerLatencyGroupTest(
|
|
||||||
tag: string,
|
|
||||||
timeout: number = 5000,
|
|
||||||
url: string = 'https://www.gstatic.com/generate_204',
|
|
||||||
): Promise<IBaseApiResponse<void>> {
|
|
||||||
return createBaseApiRequest<void>(() =>
|
|
||||||
fetch(
|
|
||||||
`${getClashApiUrl()}/group/${tag}/delay?url=${encodeURIComponent(url)}&timeout=${timeout}`,
|
|
||||||
{
|
|
||||||
method: 'GET',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function triggerLatencyProxyTest(
|
|
||||||
tag: string,
|
|
||||||
timeout: number = 2000,
|
|
||||||
url: string = 'https://www.gstatic.com/generate_204',
|
|
||||||
): Promise<IBaseApiResponse<void>> {
|
|
||||||
return createBaseApiRequest<void>(() =>
|
|
||||||
fetch(
|
|
||||||
`${getClashApiUrl()}/proxies/${tag}/delay?url=${encodeURIComponent(url)}&timeout=${timeout}`,
|
|
||||||
{
|
|
||||||
method: 'GET',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
||||||
export namespace ClashAPI {
|
|
||||||
export interface Version {
|
|
||||||
meta: boolean;
|
|
||||||
premium: boolean;
|
|
||||||
version: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Config {
|
|
||||||
port: number;
|
|
||||||
'socks-port': number;
|
|
||||||
'redir-port': number;
|
|
||||||
'tproxy-port': number;
|
|
||||||
'mixed-port': number;
|
|
||||||
'allow-lan': boolean;
|
|
||||||
'bind-address': string;
|
|
||||||
mode: 'Rule' | 'Global' | 'Direct';
|
|
||||||
'mode-list': string[];
|
|
||||||
'log-level': 'debug' | 'info' | 'warn' | 'error';
|
|
||||||
ipv6: boolean;
|
|
||||||
tun: null | Record<string, unknown>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ProxyHistoryEntry {
|
|
||||||
time: string;
|
|
||||||
delay: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ProxyBase {
|
|
||||||
type: string;
|
|
||||||
name: string;
|
|
||||||
udp: boolean;
|
|
||||||
history: ProxyHistoryEntry[];
|
|
||||||
now?: string;
|
|
||||||
all?: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Proxies {
|
|
||||||
proxies: Record<string, ProxyBase>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type Delays = Record<string, number>;
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export * from './methods';
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
export * from './getIpCheck';
|
|
||||||
export * from './getFakeIpCheck';
|
|
||||||
@@ -5,6 +5,5 @@
|
|||||||
|
|
||||||
export * from './validators';
|
export * from './validators';
|
||||||
export * from './helpers';
|
export * from './helpers';
|
||||||
export * from './clash';
|
|
||||||
export * from './podkop';
|
export * from './podkop';
|
||||||
export * from './constants';
|
export * from './constants';
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { IBaseApiResponse } from './types';
|
|
||||||
import { withTimeout } from '../helpers';
|
import { withTimeout } from '../helpers';
|
||||||
|
|
||||||
export async function createBaseApiRequest<T>(
|
export async function createBaseApiRequest<T>(
|
||||||
@@ -42,3 +41,13 @@ export async function createBaseApiRequest<T>(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type IBaseApiResponse<T> =
|
||||||
|
| {
|
||||||
|
success: true;
|
||||||
|
data: T;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
success: false;
|
||||||
|
message: string;
|
||||||
|
};
|
||||||
18
fe-app-podkop/src/podkop/methods/clash/getGroupLatency.ts
Normal file
18
fe-app-podkop/src/podkop/methods/clash/getGroupLatency.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { getClashApiUrl } from '../../../helpers';
|
||||||
|
import { createBaseApiRequest, IBaseApiResponse } from '../../api';
|
||||||
|
|
||||||
|
export async function getGroupLatency(
|
||||||
|
tag: string,
|
||||||
|
timeout: number = 5000,
|
||||||
|
url: string = 'https://www.gstatic.com/generate_204',
|
||||||
|
): Promise<IBaseApiResponse<void>> {
|
||||||
|
return createBaseApiRequest<void>(() =>
|
||||||
|
fetch(
|
||||||
|
`${getClashApiUrl()}/group/${tag}/delay?url=${encodeURIComponent(url)}&timeout=${timeout}`,
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import { ClashAPI } from '../types';
|
import { ClashAPI } from '../../types';
|
||||||
import { getClashApiUrl } from '../../helpers';
|
import { getClashApiUrl } from '../../../helpers';
|
||||||
import { createBaseApiRequest, IBaseApiResponse } from '../../api';
|
import { createBaseApiRequest, IBaseApiResponse } from '../../api';
|
||||||
|
|
||||||
export async function getClashProxies(): Promise<
|
export async function getProxies(): Promise<
|
||||||
IBaseApiResponse<ClashAPI.Proxies>
|
IBaseApiResponse<ClashAPI.Proxies>
|
||||||
> {
|
> {
|
||||||
return createBaseApiRequest<ClashAPI.Proxies>(() =>
|
return createBaseApiRequest<ClashAPI.Proxies>(() =>
|
||||||
18
fe-app-podkop/src/podkop/methods/clash/getProxyLatency.ts
Normal file
18
fe-app-podkop/src/podkop/methods/clash/getProxyLatency.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { getClashApiUrl } from '../../../helpers';
|
||||||
|
import { createBaseApiRequest, IBaseApiResponse } from '../../api';
|
||||||
|
|
||||||
|
export async function getProxyLatency(
|
||||||
|
tag: string,
|
||||||
|
timeout: number = 2000,
|
||||||
|
url: string = 'https://www.gstatic.com/generate_204',
|
||||||
|
): Promise<IBaseApiResponse<void>> {
|
||||||
|
return createBaseApiRequest<void>(() =>
|
||||||
|
fetch(
|
||||||
|
`${getClashApiUrl()}/proxies/${tag}/delay?url=${encodeURIComponent(url)}&timeout=${timeout}`,
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
11
fe-app-podkop/src/podkop/methods/clash/index.ts
Normal file
11
fe-app-podkop/src/podkop/methods/clash/index.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { getGroupLatency } from './getGroupLatency';
|
||||||
|
import { getProxies } from './getProxies';
|
||||||
|
import { getProxyLatency } from './getProxyLatency';
|
||||||
|
import { setProxy } from './setProxy';
|
||||||
|
|
||||||
|
export const ClashMethods = {
|
||||||
|
getGroupLatency,
|
||||||
|
getProxies,
|
||||||
|
getProxyLatency,
|
||||||
|
setProxy,
|
||||||
|
};
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { getClashApiUrl } from '../../helpers';
|
import { getClashApiUrl } from '../../../helpers';
|
||||||
import { createBaseApiRequest, IBaseApiResponse } from '../../api';
|
import { createBaseApiRequest, IBaseApiResponse } from '../../api';
|
||||||
|
|
||||||
export async function triggerProxySelector(
|
export async function setProxy(
|
||||||
selector: string,
|
selector: string,
|
||||||
outbound: string,
|
outbound: string,
|
||||||
): Promise<IBaseApiResponse<void>> {
|
): Promise<IBaseApiResponse<void>> {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Podkop } from '../types';
|
import { Podkop } from '../../types';
|
||||||
|
|
||||||
export async function getConfigSections(): Promise<Podkop.ConfigSection[]> {
|
export async function getConfigSections(): Promise<Podkop.ConfigSection[]> {
|
||||||
return uci.load('podkop').then(() => uci.sections('podkop'));
|
return uci.load('podkop').then(() => uci.sections('podkop'));
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Podkop } from '../types';
|
|
||||||
import { getConfigSections } from './getConfigSections';
|
import { getConfigSections } from './getConfigSections';
|
||||||
import { getClashProxies } from '../../clash';
|
import { Podkop } from '../../types';
|
||||||
import { getProxyUrlName, splitProxyString } from '../../helpers';
|
import { ClashMethods } from '../clash';
|
||||||
|
import { getProxyUrlName, splitProxyString } from '../../../helpers';
|
||||||
|
|
||||||
interface IGetDashboardSectionsResponse {
|
interface IGetDashboardSectionsResponse {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
@@ -10,7 +10,7 @@ interface IGetDashboardSectionsResponse {
|
|||||||
|
|
||||||
export async function getDashboardSections(): Promise<IGetDashboardSectionsResponse> {
|
export async function getDashboardSections(): Promise<IGetDashboardSectionsResponse> {
|
||||||
const configSections = await getConfigSections();
|
const configSections = await getConfigSections();
|
||||||
const clashProxies = await getClashProxies();
|
const clashProxies = await ClashMethods.getProxies();
|
||||||
|
|
||||||
if (!clashProxies.success) {
|
if (!clashProxies.success) {
|
||||||
return {
|
return {
|
||||||
7
fe-app-podkop/src/podkop/methods/custom/index.ts
Normal file
7
fe-app-podkop/src/podkop/methods/custom/index.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { getConfigSections } from './getConfigSections';
|
||||||
|
import { getDashboardSections } from './getDashboardSections';
|
||||||
|
|
||||||
|
export const CustomPodkopMethods = {
|
||||||
|
getConfigSections,
|
||||||
|
getDashboardSections,
|
||||||
|
};
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
|
import { FAKEIP_CHECK_DOMAIN } from '../../../constants';
|
||||||
import { createBaseApiRequest, IBaseApiResponse } from '../../api';
|
import { createBaseApiRequest, IBaseApiResponse } from '../../api';
|
||||||
import { FAKEIP_CHECK_DOMAIN } from '../../constants';
|
|
||||||
|
|
||||||
interface IGetFakeIpCheckResponse {
|
interface IGetFakeIpCheckResponse {
|
||||||
fakeip: boolean;
|
fakeip: boolean;
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
|
import { IP_CHECK_DOMAIN } from '../../../constants';
|
||||||
import { createBaseApiRequest, IBaseApiResponse } from '../../api';
|
import { createBaseApiRequest, IBaseApiResponse } from '../../api';
|
||||||
import { IP_CHECK_DOMAIN } from '../../constants';
|
|
||||||
|
|
||||||
interface IGetIpCheckResponse {
|
interface IGetIpCheckResponse {
|
||||||
fakeip: boolean;
|
fakeip: boolean;
|
||||||
7
fe-app-podkop/src/podkop/methods/fakeip/index.ts
Normal file
7
fe-app-podkop/src/podkop/methods/fakeip/index.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { getFakeIpCheck } from './getFakeIpCheck';
|
||||||
|
import { getIpCheck } from './getIpCheck';
|
||||||
|
|
||||||
|
export const RemoteFakeIPMethods = {
|
||||||
|
getFakeIpCheck,
|
||||||
|
getIpCheck,
|
||||||
|
};
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
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: '',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
import { executeShellCommand } from '../../helpers';
|
|
||||||
import { Podkop } from '../types';
|
|
||||||
|
|
||||||
export async function getFakeIPCheck(): Promise<
|
|
||||||
Podkop.MethodResponse<Podkop.FakeIPCheckResult>
|
|
||||||
> {
|
|
||||||
const response = await executeShellCommand({
|
|
||||||
command: '/usr/bin/podkop',
|
|
||||||
args: ['check_fakeip'],
|
|
||||||
timeout: 10000,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.stdout) {
|
|
||||||
return {
|
|
||||||
success: true,
|
|
||||||
data: JSON.parse(response.stdout) as Podkop.FakeIPCheckResult,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
success: false,
|
|
||||||
error: '',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
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: '',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
import { executeShellCommand } from '../../helpers';
|
|
||||||
|
|
||||||
export async function getPodkopStatus(): Promise<{
|
|
||||||
enabled: number;
|
|
||||||
status: string;
|
|
||||||
}> {
|
|
||||||
const response = await executeShellCommand({
|
|
||||||
command: '/usr/bin/podkop',
|
|
||||||
args: ['get_status'],
|
|
||||||
timeout: 10000,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.stdout) {
|
|
||||||
return JSON.parse(response.stdout.replace(/\n/g, '')) as {
|
|
||||||
enabled: number;
|
|
||||||
status: string;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return { enabled: 0, status: 'unknown' };
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
import { executeShellCommand } from '../../helpers';
|
|
||||||
import { Podkop } from '../types';
|
|
||||||
|
|
||||||
export async function getSingBoxCheck(): Promise<
|
|
||||||
Podkop.MethodResponse<Podkop.SingBoxCheckResult>
|
|
||||||
> {
|
|
||||||
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: '',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
import { executeShellCommand } from '../../helpers';
|
|
||||||
|
|
||||||
export async function getSingBoxStatus(): Promise<{
|
|
||||||
running: number;
|
|
||||||
enabled: number;
|
|
||||||
status: string;
|
|
||||||
}> {
|
|
||||||
const response = await executeShellCommand({
|
|
||||||
command: '/usr/bin/podkop',
|
|
||||||
args: ['get_sing_box_status'],
|
|
||||||
timeout: 10000,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.stdout) {
|
|
||||||
return JSON.parse(response.stdout.replace(/\n/g, '')) as {
|
|
||||||
running: number;
|
|
||||||
enabled: number;
|
|
||||||
status: string;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return { running: 0, enabled: 0, status: 'unknown' };
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,4 @@
|
|||||||
export * from './getConfigSections';
|
export * from './clash';
|
||||||
export * from './getDashboardSections';
|
export * from './custom';
|
||||||
export * from './getPodkopStatus';
|
export * from './fakeip';
|
||||||
export * from './getSingBoxStatus';
|
export * from './shell';
|
||||||
export * from './getDNSCheck';
|
|
||||||
export * from './getNftRulesCheck';
|
|
||||||
export * from './getSingBoxCheck';
|
|
||||||
export * from './getFakeIPCheck';
|
|
||||||
|
|||||||
24
fe-app-podkop/src/podkop/methods/shell/callBaseMethod.ts
Normal file
24
fe-app-podkop/src/podkop/methods/shell/callBaseMethod.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { executeShellCommand } from '../../../helpers';
|
||||||
|
import { Podkop } from '../../types';
|
||||||
|
|
||||||
|
export async function callBaseMethod<T>(
|
||||||
|
method: Podkop.AvailableMethods,
|
||||||
|
): Promise<Podkop.MethodResponse<T>> {
|
||||||
|
const response = await executeShellCommand({
|
||||||
|
command: '/usr/bin/podkop',
|
||||||
|
args: [method],
|
||||||
|
timeout: 10000,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.stdout) {
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
data: JSON.parse(response.stdout) as T,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: '',
|
||||||
|
};
|
||||||
|
}
|
||||||
27
fe-app-podkop/src/podkop/methods/shell/index.ts
Normal file
27
fe-app-podkop/src/podkop/methods/shell/index.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { callBaseMethod } from './callBaseMethod';
|
||||||
|
import { Podkop } from '../../types';
|
||||||
|
|
||||||
|
export const PodkopShellMethods = {
|
||||||
|
checkDNSAvailable: async () =>
|
||||||
|
callBaseMethod<Podkop.DnsCheckResult>(
|
||||||
|
Podkop.AvailableMethods.CHECK_DNS_AVAILABLE,
|
||||||
|
),
|
||||||
|
checkFakeIP: async () =>
|
||||||
|
callBaseMethod<Podkop.FakeIPCheckResult>(
|
||||||
|
Podkop.AvailableMethods.CHECK_FAKEIP,
|
||||||
|
),
|
||||||
|
checkNftRules: async () =>
|
||||||
|
callBaseMethod<Podkop.NftRulesCheckResult>(
|
||||||
|
Podkop.AvailableMethods.CHECK_NFT_RULES,
|
||||||
|
),
|
||||||
|
getStatus: async () =>
|
||||||
|
callBaseMethod<Podkop.GetStatus>(Podkop.AvailableMethods.GET_STATUS),
|
||||||
|
checkSingBox: async () =>
|
||||||
|
callBaseMethod<Podkop.SingBoxCheckResult>(
|
||||||
|
Podkop.AvailableMethods.CHECK_SING_BOX,
|
||||||
|
),
|
||||||
|
getSingBoxStatus: async () =>
|
||||||
|
callBaseMethod<Podkop.GetSingBoxStatus>(
|
||||||
|
Podkop.AvailableMethods.GET_SING_BOX_STATUS,
|
||||||
|
),
|
||||||
|
};
|
||||||
@@ -1,24 +1,19 @@
|
|||||||
import {
|
|
||||||
getDashboardSections,
|
|
||||||
getPodkopStatus,
|
|
||||||
getSingBoxStatus,
|
|
||||||
} from '../../methods';
|
|
||||||
import {
|
import {
|
||||||
getClashApiUrl,
|
getClashApiUrl,
|
||||||
getClashWsUrl,
|
getClashWsUrl,
|
||||||
onMount,
|
onMount,
|
||||||
preserveScrollForPage,
|
preserveScrollForPage,
|
||||||
} from '../../../helpers';
|
} from '../../../helpers';
|
||||||
import {
|
|
||||||
triggerLatencyGroupTest,
|
|
||||||
triggerLatencyProxyTest,
|
|
||||||
triggerProxySelector,
|
|
||||||
} from '../../../clash';
|
|
||||||
import { store, StoreType } from '../../../store';
|
import { store, StoreType } from '../../../store';
|
||||||
import { socket } from '../../../socket';
|
import { socket } from '../../../socket';
|
||||||
import { prettyBytes } from '../../../helpers/prettyBytes';
|
import { prettyBytes } from '../../../helpers/prettyBytes';
|
||||||
import { renderSections } from './renderSections';
|
import { renderSections } from './renderSections';
|
||||||
import { renderWidget } from './renderWidget';
|
import { renderWidget } from './renderWidget';
|
||||||
|
import {
|
||||||
|
ClashMethods,
|
||||||
|
CustomPodkopMethods,
|
||||||
|
PodkopShellMethods,
|
||||||
|
} from '../../methods';
|
||||||
|
|
||||||
// Fetchers
|
// Fetchers
|
||||||
|
|
||||||
@@ -32,7 +27,7 @@ async function fetchDashboardSections() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const { data, success } = await getDashboardSections();
|
const { data, success } = await CustomPodkopMethods.getDashboardSections();
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
console.log('[fetchDashboardSections]: failed to fetch', getClashApiUrl());
|
console.log('[fetchDashboardSections]: failed to fetch', getClashApiUrl());
|
||||||
@@ -49,22 +44,12 @@ async function fetchDashboardSections() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function fetchServicesInfo() {
|
async function fetchServicesInfo() {
|
||||||
try {
|
|
||||||
const [podkop, singbox] = await Promise.all([
|
const [podkop, singbox] = await Promise.all([
|
||||||
getPodkopStatus(),
|
PodkopShellMethods.getStatus(),
|
||||||
getSingBoxStatus(),
|
PodkopShellMethods.getSingBoxStatus(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
store.set({
|
if (!podkop.success || !singbox.success) {
|
||||||
servicesInfoWidget: {
|
|
||||||
loading: false,
|
|
||||||
failed: false,
|
|
||||||
data: { singbox: singbox.running, podkop: podkop.enabled },
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} catch (err) {
|
|
||||||
console.log('[fetchServicesInfo]: failed to fetchServices', err);
|
|
||||||
|
|
||||||
store.set({
|
store.set({
|
||||||
servicesInfoWidget: {
|
servicesInfoWidget: {
|
||||||
loading: false,
|
loading: false,
|
||||||
@@ -73,6 +58,16 @@ async function fetchServicesInfo() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (podkop.success && singbox.success) {
|
||||||
|
store.set({
|
||||||
|
servicesInfoWidget: {
|
||||||
|
loading: false,
|
||||||
|
failed: false,
|
||||||
|
data: { singbox: singbox.data.running, podkop: podkop.data.enabled },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function connectToClashSockets() {
|
async function connectToClashSockets() {
|
||||||
@@ -155,7 +150,7 @@ async function connectToClashSockets() {
|
|||||||
// Handlers
|
// Handlers
|
||||||
|
|
||||||
async function handleChooseOutbound(selector: string, tag: string) {
|
async function handleChooseOutbound(selector: string, tag: string) {
|
||||||
await triggerProxySelector(selector, tag);
|
await ClashMethods.setProxy(selector, tag);
|
||||||
await fetchDashboardSections();
|
await fetchDashboardSections();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,7 +162,7 @@ async function handleTestGroupLatency(tag: string) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await triggerLatencyGroupTest(tag);
|
await ClashMethods.getGroupLatency(tag);
|
||||||
await fetchDashboardSections();
|
await fetchDashboardSections();
|
||||||
|
|
||||||
store.set({
|
store.set({
|
||||||
@@ -186,7 +181,7 @@ async function handleTestProxyLatency(tag: string) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await triggerLatencyProxyTest(tag);
|
await ClashMethods.getProxyLatency(tag);
|
||||||
await fetchDashboardSections();
|
await fetchDashboardSections();
|
||||||
|
|
||||||
store.set({
|
store.set({
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { getDNSCheck } from '../../../methods';
|
|
||||||
import { updateDiagnosticsCheck } from '../updateDiagnosticsCheck';
|
import { updateDiagnosticsCheck } from '../updateDiagnosticsCheck';
|
||||||
import { insertIf } from '../../../../helpers';
|
import { insertIf } from '../../../../helpers';
|
||||||
import { IDiagnosticsChecksItem } from '../../../../store';
|
import { IDiagnosticsChecksItem } from '../../../../store';
|
||||||
import { DIAGNOSTICS_CHECKS_MAP } from './contstants';
|
import { DIAGNOSTICS_CHECKS_MAP } from './contstants';
|
||||||
|
import { PodkopShellMethods } from '../../../methods';
|
||||||
|
|
||||||
export async function runDnsCheck() {
|
export async function runDnsCheck() {
|
||||||
const { order, title, code } = DIAGNOSTICS_CHECKS_MAP.DNS;
|
const { order, title, code } = DIAGNOSTICS_CHECKS_MAP.DNS;
|
||||||
@@ -16,7 +16,7 @@ export async function runDnsCheck() {
|
|||||||
items: [],
|
items: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
const dnsChecks = await getDNSCheck();
|
const dnsChecks = await PodkopShellMethods.checkDNSAvailable();
|
||||||
|
|
||||||
if (!dnsChecks.success) {
|
if (!dnsChecks.success) {
|
||||||
updateDiagnosticsCheck({
|
updateDiagnosticsCheck({
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import * as podkopMethods from '../../../methods';
|
|
||||||
import * as fakeIPMethods from '../../../../fakeip/methods';
|
|
||||||
import { updateDiagnosticsCheck } from '../updateDiagnosticsCheck';
|
import { updateDiagnosticsCheck } from '../updateDiagnosticsCheck';
|
||||||
import { insertIf } from '../../../../helpers';
|
import { insertIf } from '../../../../helpers';
|
||||||
import { IDiagnosticsChecksItem } from '../../../../store';
|
import { IDiagnosticsChecksItem } from '../../../../store';
|
||||||
import { DIAGNOSTICS_CHECKS_MAP } from './contstants';
|
import { DIAGNOSTICS_CHECKS_MAP } from './contstants';
|
||||||
|
import { PodkopShellMethods, RemoteFakeIPMethods } from '../../../methods';
|
||||||
|
|
||||||
export async function runFakeIPCheck() {
|
export async function runFakeIPCheck() {
|
||||||
const { order, title, code } = DIAGNOSTICS_CHECKS_MAP.FAKEIP;
|
const { order, title, code } = DIAGNOSTICS_CHECKS_MAP.FAKEIP;
|
||||||
@@ -17,9 +16,9 @@ export async function runFakeIPCheck() {
|
|||||||
items: [],
|
items: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
const routerFakeIPResponse = await podkopMethods.getFakeIPCheck();
|
const routerFakeIPResponse = await PodkopShellMethods.checkFakeIP();
|
||||||
const checkFakeIPResponse = await fakeIPMethods.getFakeIpCheck();
|
const checkFakeIPResponse = await RemoteFakeIPMethods.getFakeIpCheck();
|
||||||
const checkIPResponse = await fakeIPMethods.getIpCheck();
|
const checkIPResponse = await RemoteFakeIPMethods.getIpCheck();
|
||||||
|
|
||||||
console.log('runFakeIPCheck', {
|
console.log('runFakeIPCheck', {
|
||||||
routerFakeIPResponse,
|
routerFakeIPResponse,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { getNftRulesCheck } from '../../../methods';
|
|
||||||
import { updateDiagnosticsCheck } from '../updateDiagnosticsCheck';
|
import { updateDiagnosticsCheck } from '../updateDiagnosticsCheck';
|
||||||
import { getFakeIpCheck, getIpCheck } from '../../../../fakeip';
|
|
||||||
import { DIAGNOSTICS_CHECKS_MAP } from './contstants';
|
import { DIAGNOSTICS_CHECKS_MAP } from './contstants';
|
||||||
|
import { RemoteFakeIPMethods } from '../../../methods/fakeip';
|
||||||
|
import { PodkopShellMethods } from '../../../methods';
|
||||||
|
|
||||||
export async function runNftCheck() {
|
export async function runNftCheck() {
|
||||||
const { order, title, code } = DIAGNOSTICS_CHECKS_MAP.NFT;
|
const { order, title, code } = DIAGNOSTICS_CHECKS_MAP.NFT;
|
||||||
@@ -15,10 +15,10 @@ export async function runNftCheck() {
|
|||||||
items: [],
|
items: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
await getFakeIpCheck();
|
await RemoteFakeIPMethods.getFakeIpCheck();
|
||||||
await getIpCheck();
|
await RemoteFakeIPMethods.getIpCheck();
|
||||||
|
|
||||||
const nftablesChecks = await getNftRulesCheck();
|
const nftablesChecks = await PodkopShellMethods.checkNftRules();
|
||||||
|
|
||||||
if (!nftablesChecks.success) {
|
if (!nftablesChecks.success) {
|
||||||
updateDiagnosticsCheck({
|
updateDiagnosticsCheck({
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { getSingBoxCheck } from '../../../methods';
|
|
||||||
import { updateDiagnosticsCheck } from '../updateDiagnosticsCheck';
|
import { updateDiagnosticsCheck } from '../updateDiagnosticsCheck';
|
||||||
import { DIAGNOSTICS_CHECKS_MAP } from './contstants';
|
import { DIAGNOSTICS_CHECKS_MAP } from './contstants';
|
||||||
|
import { PodkopShellMethods } from '../../../methods';
|
||||||
|
|
||||||
export async function runSingBoxCheck() {
|
export async function runSingBoxCheck() {
|
||||||
const { order, title, code } = DIAGNOSTICS_CHECKS_MAP.SINGBOX;
|
const { order, title, code } = DIAGNOSTICS_CHECKS_MAP.SINGBOX;
|
||||||
@@ -14,7 +14,7 @@ export async function runSingBoxCheck() {
|
|||||||
items: [],
|
items: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
const singBoxChecks = await getSingBoxCheck();
|
const singBoxChecks = await PodkopShellMethods.checkSingBox();
|
||||||
|
|
||||||
if (!singBoxChecks.success) {
|
if (!singBoxChecks.success) {
|
||||||
updateDiagnosticsCheck({
|
updateDiagnosticsCheck({
|
||||||
|
|||||||
@@ -1,5 +1,35 @@
|
|||||||
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||||
|
export namespace ClashAPI {
|
||||||
|
export interface ProxyHistoryEntry {
|
||||||
|
time: string;
|
||||||
|
delay: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ProxyBase {
|
||||||
|
type: string;
|
||||||
|
name: string;
|
||||||
|
udp: boolean;
|
||||||
|
history: ProxyHistoryEntry[];
|
||||||
|
now?: string;
|
||||||
|
all?: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Proxies {
|
||||||
|
proxies: Record<string, ProxyBase>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||||
export namespace Podkop {
|
export namespace Podkop {
|
||||||
|
export enum AvailableMethods {
|
||||||
|
CHECK_DNS_AVAILABLE = 'check_dns_available',
|
||||||
|
CHECK_FAKEIP = 'check_fakeip',
|
||||||
|
CHECK_NFT_RULES = 'check_nft_rules',
|
||||||
|
GET_STATUS = 'get_status',
|
||||||
|
CHECK_SING_BOX = 'check_sing_box',
|
||||||
|
GET_SING_BOX_STATUS = 'get_sing_box_status',
|
||||||
|
}
|
||||||
|
|
||||||
export interface Outbound {
|
export interface Outbound {
|
||||||
code: string;
|
code: string;
|
||||||
displayName: string;
|
displayName: string;
|
||||||
@@ -102,4 +132,15 @@ export namespace Podkop {
|
|||||||
fakeip: boolean;
|
fakeip: boolean;
|
||||||
IP: string;
|
IP: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface GetStatus {
|
||||||
|
enabled: number;
|
||||||
|
status: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GetSingBoxStatus {
|
||||||
|
running: number;
|
||||||
|
enabled: number;
|
||||||
|
status: string;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1003,7 +1003,7 @@ function validateProxyUrl(url) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// src/api/createBaseApiRequest.ts
|
// src/podkop/api.ts
|
||||||
async function createBaseApiRequest(fetchFn, options) {
|
async function createBaseApiRequest(fetchFn, options) {
|
||||||
const wrappedFn = () => options?.timeoutMs && options?.operationName ? withTimeout(
|
const wrappedFn = () => options?.timeoutMs && options?.operationName ? withTimeout(
|
||||||
fetchFn(),
|
fetchFn(),
|
||||||
@@ -1032,62 +1032,8 @@ async function createBaseApiRequest(fetchFn, options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// src/clash/methods/getConfig.ts
|
// src/podkop/methods/clash/getGroupLatency.ts
|
||||||
async function getClashConfig() {
|
async function getGroupLatency(tag, timeout = 5e3, url = "https://www.gstatic.com/generate_204") {
|
||||||
return createBaseApiRequest(
|
|
||||||
() => fetch(`${getClashApiUrl()}/configs`, {
|
|
||||||
method: "GET",
|
|
||||||
headers: { "Content-Type": "application/json" }
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// src/clash/methods/getGroupDelay.ts
|
|
||||||
async function getClashGroupDelay(group, url = "https://www.gstatic.com/generate_204", timeout = 2e3) {
|
|
||||||
const endpoint = `${getClashApiUrl()}/group/${group}/delay?url=${encodeURIComponent(
|
|
||||||
url
|
|
||||||
)}&timeout=${timeout}`;
|
|
||||||
return createBaseApiRequest(
|
|
||||||
() => fetch(endpoint, {
|
|
||||||
method: "GET",
|
|
||||||
headers: { "Content-Type": "application/json" }
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// src/clash/methods/getProxies.ts
|
|
||||||
async function getClashProxies() {
|
|
||||||
return createBaseApiRequest(
|
|
||||||
() => fetch(`${getClashApiUrl()}/proxies`, {
|
|
||||||
method: "GET",
|
|
||||||
headers: { "Content-Type": "application/json" }
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// src/clash/methods/getVersion.ts
|
|
||||||
async function getClashVersion() {
|
|
||||||
return createBaseApiRequest(
|
|
||||||
() => fetch(`${getClashApiUrl()}/version`, {
|
|
||||||
method: "GET",
|
|
||||||
headers: { "Content-Type": "application/json" }
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// src/clash/methods/triggerProxySelector.ts
|
|
||||||
async function triggerProxySelector(selector, outbound) {
|
|
||||||
return createBaseApiRequest(
|
|
||||||
() => fetch(`${getClashApiUrl()}/proxies/${selector}`, {
|
|
||||||
method: "PUT",
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify({ name: outbound })
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// src/clash/methods/triggerLatencyTest.ts
|
|
||||||
async function triggerLatencyGroupTest(tag, timeout = 5e3, url = "https://www.gstatic.com/generate_204") {
|
|
||||||
return createBaseApiRequest(
|
return createBaseApiRequest(
|
||||||
() => fetch(
|
() => fetch(
|
||||||
`${getClashApiUrl()}/group/${tag}/delay?url=${encodeURIComponent(url)}&timeout=${timeout}`,
|
`${getClashApiUrl()}/group/${tag}/delay?url=${encodeURIComponent(url)}&timeout=${timeout}`,
|
||||||
@@ -1098,7 +1044,19 @@ async function triggerLatencyGroupTest(tag, timeout = 5e3, url = "https://www.gs
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
async function triggerLatencyProxyTest(tag, timeout = 2e3, url = "https://www.gstatic.com/generate_204") {
|
|
||||||
|
// src/podkop/methods/clash/getProxies.ts
|
||||||
|
async function getProxies() {
|
||||||
|
return createBaseApiRequest(
|
||||||
|
() => fetch(`${getClashApiUrl()}/proxies`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: { "Content-Type": "application/json" }
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// src/podkop/methods/clash/getProxyLatency.ts
|
||||||
|
async function getProxyLatency(tag, timeout = 2e3, url = "https://www.gstatic.com/generate_204") {
|
||||||
return createBaseApiRequest(
|
return createBaseApiRequest(
|
||||||
() => fetch(
|
() => fetch(
|
||||||
`${getClashApiUrl()}/proxies/${tag}/delay?url=${encodeURIComponent(url)}&timeout=${timeout}`,
|
`${getClashApiUrl()}/proxies/${tag}/delay?url=${encodeURIComponent(url)}&timeout=${timeout}`,
|
||||||
@@ -1110,15 +1068,34 @@ async function triggerLatencyProxyTest(tag, timeout = 2e3, url = "https://www.gs
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// src/podkop/methods/getConfigSections.ts
|
// src/podkop/methods/clash/setProxy.ts
|
||||||
|
async function setProxy(selector, outbound) {
|
||||||
|
return createBaseApiRequest(
|
||||||
|
() => fetch(`${getClashApiUrl()}/proxies/${selector}`, {
|
||||||
|
method: "PUT",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ name: outbound })
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// src/podkop/methods/clash/index.ts
|
||||||
|
var ClashMethods = {
|
||||||
|
getGroupLatency,
|
||||||
|
getProxies,
|
||||||
|
getProxyLatency,
|
||||||
|
setProxy
|
||||||
|
};
|
||||||
|
|
||||||
|
// src/podkop/methods/custom/getConfigSections.ts
|
||||||
async function getConfigSections() {
|
async function getConfigSections() {
|
||||||
return uci.load("podkop").then(() => uci.sections("podkop"));
|
return uci.load("podkop").then(() => uci.sections("podkop"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// src/podkop/methods/getDashboardSections.ts
|
// src/podkop/methods/custom/getDashboardSections.ts
|
||||||
async function getDashboardSections() {
|
async function getDashboardSections() {
|
||||||
const configSections = await getConfigSections();
|
const configSections = await getConfigSections();
|
||||||
const clashProxies = await getClashProxies();
|
const clashProxies = await ClashMethods.getProxies();
|
||||||
if (!clashProxies.success) {
|
if (!clashProxies.success) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
@@ -1241,37 +1218,51 @@ async function getDashboardSections() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// src/podkop/methods/getPodkopStatus.ts
|
// src/podkop/methods/custom/index.ts
|
||||||
async function getPodkopStatus() {
|
var CustomPodkopMethods = {
|
||||||
const response = await executeShellCommand({
|
getConfigSections,
|
||||||
command: "/usr/bin/podkop",
|
getDashboardSections
|
||||||
args: ["get_status"],
|
};
|
||||||
timeout: 1e4
|
|
||||||
});
|
// src/podkop/methods/fakeip/getFakeIpCheck.ts
|
||||||
if (response.stdout) {
|
async function getFakeIpCheck() {
|
||||||
return JSON.parse(response.stdout.replace(/\n/g, ""));
|
return createBaseApiRequest(
|
||||||
|
() => fetch(`https://${FAKEIP_CHECK_DOMAIN}/check`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: { "Content-Type": "application/json" }
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
operationName: "getFakeIpCheck",
|
||||||
|
timeoutMs: 5e3
|
||||||
}
|
}
|
||||||
return { enabled: 0, status: "unknown" };
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// src/podkop/methods/getSingBoxStatus.ts
|
// src/podkop/methods/fakeip/getIpCheck.ts
|
||||||
async function getSingBoxStatus() {
|
async function getIpCheck() {
|
||||||
const response = await executeShellCommand({
|
return createBaseApiRequest(
|
||||||
command: "/usr/bin/podkop",
|
() => fetch(`https://${IP_CHECK_DOMAIN}/check`, {
|
||||||
args: ["get_sing_box_status"],
|
method: "GET",
|
||||||
timeout: 1e4
|
headers: { "Content-Type": "application/json" }
|
||||||
});
|
}),
|
||||||
if (response.stdout) {
|
{
|
||||||
return JSON.parse(response.stdout.replace(/\n/g, ""));
|
operationName: "getIpCheck",
|
||||||
|
timeoutMs: 5e3
|
||||||
}
|
}
|
||||||
return { running: 0, enabled: 0, status: "unknown" };
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// src/podkop/methods/getDNSCheck.ts
|
// src/podkop/methods/fakeip/index.ts
|
||||||
async function getDNSCheck() {
|
var RemoteFakeIPMethods = {
|
||||||
|
getFakeIpCheck,
|
||||||
|
getIpCheck
|
||||||
|
};
|
||||||
|
|
||||||
|
// src/podkop/methods/shell/callBaseMethod.ts
|
||||||
|
async function callBaseMethod(method) {
|
||||||
const response = await executeShellCommand({
|
const response = await executeShellCommand({
|
||||||
command: "/usr/bin/podkop",
|
command: "/usr/bin/podkop",
|
||||||
args: ["check_dns_available"],
|
args: [method],
|
||||||
timeout: 1e4
|
timeout: 1e4
|
||||||
});
|
});
|
||||||
if (response.stdout) {
|
if (response.stdout) {
|
||||||
@@ -1286,62 +1277,39 @@ async function getDNSCheck() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// src/podkop/methods/getNftRulesCheck.ts
|
// src/podkop/types.ts
|
||||||
async function getNftRulesCheck() {
|
var Podkop;
|
||||||
const response = await executeShellCommand({
|
((Podkop2) => {
|
||||||
command: "/usr/bin/podkop",
|
let AvailableMethods;
|
||||||
args: ["check_nft_rules"],
|
((AvailableMethods2) => {
|
||||||
timeout: 1e4
|
AvailableMethods2["CHECK_DNS_AVAILABLE"] = "check_dns_available";
|
||||||
});
|
AvailableMethods2["CHECK_FAKEIP"] = "check_fakeip";
|
||||||
if (response.stdout) {
|
AvailableMethods2["CHECK_NFT_RULES"] = "check_nft_rules";
|
||||||
return {
|
AvailableMethods2["GET_STATUS"] = "get_status";
|
||||||
success: true,
|
AvailableMethods2["CHECK_SING_BOX"] = "check_sing_box";
|
||||||
data: JSON.parse(response.stdout)
|
AvailableMethods2["GET_SING_BOX_STATUS"] = "get_sing_box_status";
|
||||||
};
|
})(AvailableMethods = Podkop2.AvailableMethods || (Podkop2.AvailableMethods = {}));
|
||||||
}
|
})(Podkop || (Podkop = {}));
|
||||||
return {
|
|
||||||
success: false,
|
|
||||||
error: ""
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// src/podkop/methods/getSingBoxCheck.ts
|
// src/podkop/methods/shell/index.ts
|
||||||
async function getSingBoxCheck() {
|
var PodkopShellMethods = {
|
||||||
const response = await executeShellCommand({
|
checkDNSAvailable: async () => callBaseMethod(
|
||||||
command: "/usr/bin/podkop",
|
Podkop.AvailableMethods.CHECK_DNS_AVAILABLE
|
||||||
args: ["check_sing_box"],
|
),
|
||||||
timeout: 1e4
|
checkFakeIP: async () => callBaseMethod(
|
||||||
});
|
Podkop.AvailableMethods.CHECK_FAKEIP
|
||||||
if (response.stdout) {
|
),
|
||||||
return {
|
checkNftRules: async () => callBaseMethod(
|
||||||
success: true,
|
Podkop.AvailableMethods.CHECK_NFT_RULES
|
||||||
data: JSON.parse(response.stdout)
|
),
|
||||||
};
|
getStatus: async () => callBaseMethod(Podkop.AvailableMethods.GET_STATUS),
|
||||||
}
|
checkSingBox: async () => callBaseMethod(
|
||||||
return {
|
Podkop.AvailableMethods.CHECK_SING_BOX
|
||||||
success: false,
|
),
|
||||||
error: ""
|
getSingBoxStatus: async () => callBaseMethod(
|
||||||
};
|
Podkop.AvailableMethods.GET_SING_BOX_STATUS
|
||||||
}
|
)
|
||||||
|
};
|
||||||
// src/podkop/methods/getFakeIPCheck.ts
|
|
||||||
async function getFakeIPCheck() {
|
|
||||||
const response = await executeShellCommand({
|
|
||||||
command: "/usr/bin/podkop",
|
|
||||||
args: ["check_fakeip"],
|
|
||||||
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 {
|
||||||
@@ -1994,7 +1962,7 @@ async function fetchDashboardSections() {
|
|||||||
failed: false
|
failed: false
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const { data, success } = await getDashboardSections();
|
const { data, success } = await CustomPodkopMethods.getDashboardSections();
|
||||||
if (!success) {
|
if (!success) {
|
||||||
console.log("[fetchDashboardSections]: failed to fetch", getClashApiUrl());
|
console.log("[fetchDashboardSections]: failed to fetch", getClashApiUrl());
|
||||||
}
|
}
|
||||||
@@ -2008,20 +1976,11 @@ async function fetchDashboardSections() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
async function fetchServicesInfo() {
|
async function fetchServicesInfo() {
|
||||||
try {
|
|
||||||
const [podkop, singbox] = await Promise.all([
|
const [podkop, singbox] = await Promise.all([
|
||||||
getPodkopStatus(),
|
PodkopShellMethods.getStatus(),
|
||||||
getSingBoxStatus()
|
PodkopShellMethods.getSingBoxStatus()
|
||||||
]);
|
]);
|
||||||
store.set({
|
if (!podkop.success || !singbox.success) {
|
||||||
servicesInfoWidget: {
|
|
||||||
loading: false,
|
|
||||||
failed: false,
|
|
||||||
data: { singbox: singbox.running, podkop: podkop.enabled }
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (err) {
|
|
||||||
console.log("[fetchServicesInfo]: failed to fetchServices", err);
|
|
||||||
store.set({
|
store.set({
|
||||||
servicesInfoWidget: {
|
servicesInfoWidget: {
|
||||||
loading: false,
|
loading: false,
|
||||||
@@ -2030,6 +1989,15 @@ async function fetchServicesInfo() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (podkop.success && singbox.success) {
|
||||||
|
store.set({
|
||||||
|
servicesInfoWidget: {
|
||||||
|
loading: false,
|
||||||
|
failed: false,
|
||||||
|
data: { singbox: singbox.data.running, podkop: podkop.data.enabled }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
async function connectToClashSockets() {
|
async function connectToClashSockets() {
|
||||||
socket.subscribe(
|
socket.subscribe(
|
||||||
@@ -2105,7 +2073,7 @@ async function connectToClashSockets() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
async function handleChooseOutbound(selector, tag) {
|
async function handleChooseOutbound(selector, tag) {
|
||||||
await triggerProxySelector(selector, tag);
|
await ClashMethods.setProxy(selector, tag);
|
||||||
await fetchDashboardSections();
|
await fetchDashboardSections();
|
||||||
}
|
}
|
||||||
async function handleTestGroupLatency(tag) {
|
async function handleTestGroupLatency(tag) {
|
||||||
@@ -2115,7 +2083,7 @@ async function handleTestGroupLatency(tag) {
|
|||||||
latencyFetching: true
|
latencyFetching: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
await triggerLatencyGroupTest(tag);
|
await ClashMethods.getGroupLatency(tag);
|
||||||
await fetchDashboardSections();
|
await fetchDashboardSections();
|
||||||
store.set({
|
store.set({
|
||||||
sectionsWidget: {
|
sectionsWidget: {
|
||||||
@@ -2131,7 +2099,7 @@ async function handleTestProxyLatency(tag) {
|
|||||||
latencyFetching: true
|
latencyFetching: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
await triggerLatencyProxyTest(tag);
|
await ClashMethods.getProxyLatency(tag);
|
||||||
await fetchDashboardSections();
|
await fetchDashboardSections();
|
||||||
store.set({
|
store.set({
|
||||||
sectionsWidget: {
|
sectionsWidget: {
|
||||||
@@ -2772,7 +2740,7 @@ async function runDnsCheck() {
|
|||||||
state: "loading",
|
state: "loading",
|
||||||
items: []
|
items: []
|
||||||
});
|
});
|
||||||
const dnsChecks = await getDNSCheck();
|
const dnsChecks = await PodkopShellMethods.checkDNSAvailable();
|
||||||
if (!dnsChecks.success) {
|
if (!dnsChecks.success) {
|
||||||
updateDiagnosticsCheck({
|
updateDiagnosticsCheck({
|
||||||
order,
|
order,
|
||||||
@@ -2842,7 +2810,7 @@ async function runSingBoxCheck() {
|
|||||||
state: "loading",
|
state: "loading",
|
||||||
items: []
|
items: []
|
||||||
});
|
});
|
||||||
const singBoxChecks = await getSingBoxCheck();
|
const singBoxChecks = await PodkopShellMethods.checkSingBox();
|
||||||
if (!singBoxChecks.success) {
|
if (!singBoxChecks.success) {
|
||||||
updateDiagnosticsCheck({
|
updateDiagnosticsCheck({
|
||||||
order,
|
order,
|
||||||
@@ -2911,34 +2879,6 @@ async function runSingBoxCheck() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// src/fakeip/methods/getIpCheck.ts
|
|
||||||
async function getIpCheck() {
|
|
||||||
return createBaseApiRequest(
|
|
||||||
() => fetch(`https://${IP_CHECK_DOMAIN}/check`, {
|
|
||||||
method: "GET",
|
|
||||||
headers: { "Content-Type": "application/json" }
|
|
||||||
}),
|
|
||||||
{
|
|
||||||
operationName: "getIpCheck",
|
|
||||||
timeoutMs: 5e3
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// src/fakeip/methods/getFakeIpCheck.ts
|
|
||||||
async function getFakeIpCheck() {
|
|
||||||
return createBaseApiRequest(
|
|
||||||
() => fetch(`https://${FAKEIP_CHECK_DOMAIN}/check`, {
|
|
||||||
method: "GET",
|
|
||||||
headers: { "Content-Type": "application/json" }
|
|
||||||
}),
|
|
||||||
{
|
|
||||||
operationName: "getFakeIpCheck",
|
|
||||||
timeoutMs: 5e3
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// src/podkop/tabs/diagnostic/checks/runNftCheck.ts
|
// src/podkop/tabs/diagnostic/checks/runNftCheck.ts
|
||||||
async function runNftCheck() {
|
async function runNftCheck() {
|
||||||
const { order, title, code } = DIAGNOSTICS_CHECKS_MAP.NFT;
|
const { order, title, code } = DIAGNOSTICS_CHECKS_MAP.NFT;
|
||||||
@@ -2950,9 +2890,9 @@ async function runNftCheck() {
|
|||||||
state: "loading",
|
state: "loading",
|
||||||
items: []
|
items: []
|
||||||
});
|
});
|
||||||
await getFakeIpCheck();
|
await RemoteFakeIPMethods.getFakeIpCheck();
|
||||||
await getIpCheck();
|
await RemoteFakeIPMethods.getIpCheck();
|
||||||
const nftablesChecks = await getNftRulesCheck();
|
const nftablesChecks = await PodkopShellMethods.checkNftRules();
|
||||||
if (!nftablesChecks.success) {
|
if (!nftablesChecks.success) {
|
||||||
updateDiagnosticsCheck({
|
updateDiagnosticsCheck({
|
||||||
order,
|
order,
|
||||||
@@ -3042,9 +2982,9 @@ async function runFakeIPCheck() {
|
|||||||
state: "loading",
|
state: "loading",
|
||||||
items: []
|
items: []
|
||||||
});
|
});
|
||||||
const routerFakeIPResponse = await getFakeIPCheck();
|
const routerFakeIPResponse = await PodkopShellMethods.checkFakeIP();
|
||||||
const checkFakeIPResponse = await getFakeIpCheck();
|
const checkFakeIPResponse = await RemoteFakeIPMethods.getFakeIpCheck();
|
||||||
const checkIPResponse = await getIpCheck();
|
const checkIPResponse = await RemoteFakeIPMethods.getIpCheck();
|
||||||
console.log("runFakeIPCheck", {
|
console.log("runFakeIPCheck", {
|
||||||
routerFakeIPResponse,
|
routerFakeIPResponse,
|
||||||
checkFakeIPResponse,
|
checkFakeIPResponse,
|
||||||
@@ -3254,6 +3194,8 @@ return baseclass.extend({
|
|||||||
CACHE_TIMEOUT,
|
CACHE_TIMEOUT,
|
||||||
COMMAND_SCHEDULING,
|
COMMAND_SCHEDULING,
|
||||||
COMMAND_TIMEOUT,
|
COMMAND_TIMEOUT,
|
||||||
|
ClashMethods,
|
||||||
|
CustomPodkopMethods,
|
||||||
DIAGNOSTICS_INITIAL_DELAY,
|
DIAGNOSTICS_INITIAL_DELAY,
|
||||||
DIAGNOSTICS_UPDATE_INTERVAL,
|
DIAGNOSTICS_UPDATE_INTERVAL,
|
||||||
DNS_SERVER_OPTIONS,
|
DNS_SERVER_OPTIONS,
|
||||||
@@ -3263,7 +3205,9 @@ return baseclass.extend({
|
|||||||
FETCH_TIMEOUT,
|
FETCH_TIMEOUT,
|
||||||
IP_CHECK_DOMAIN,
|
IP_CHECK_DOMAIN,
|
||||||
PODKOP_LUCI_APP_VERSION,
|
PODKOP_LUCI_APP_VERSION,
|
||||||
|
PodkopShellMethods,
|
||||||
REGIONAL_OPTIONS,
|
REGIONAL_OPTIONS,
|
||||||
|
RemoteFakeIPMethods,
|
||||||
STATUS_COLORS,
|
STATUS_COLORS,
|
||||||
TabService,
|
TabService,
|
||||||
TabServiceInstance,
|
TabServiceInstance,
|
||||||
@@ -3273,21 +3217,9 @@ return baseclass.extend({
|
|||||||
executeShellCommand,
|
executeShellCommand,
|
||||||
getBaseUrl,
|
getBaseUrl,
|
||||||
getClashApiUrl,
|
getClashApiUrl,
|
||||||
getClashConfig,
|
|
||||||
getClashGroupDelay,
|
|
||||||
getClashProxies,
|
|
||||||
getClashUIUrl,
|
getClashUIUrl,
|
||||||
getClashVersion,
|
|
||||||
getClashWsUrl,
|
getClashWsUrl,
|
||||||
getConfigSections,
|
|
||||||
getDNSCheck,
|
|
||||||
getDashboardSections,
|
|
||||||
getFakeIPCheck,
|
|
||||||
getNftRulesCheck,
|
|
||||||
getPodkopStatus,
|
|
||||||
getProxyUrlName,
|
getProxyUrlName,
|
||||||
getSingBoxCheck,
|
|
||||||
getSingBoxStatus,
|
|
||||||
initDashboardController,
|
initDashboardController,
|
||||||
initDiagnosticController,
|
initDiagnosticController,
|
||||||
injectGlobalStyles,
|
injectGlobalStyles,
|
||||||
@@ -3302,9 +3234,6 @@ return baseclass.extend({
|
|||||||
renderDiagnostic,
|
renderDiagnostic,
|
||||||
splitProxyString,
|
splitProxyString,
|
||||||
svgEl,
|
svgEl,
|
||||||
triggerLatencyGroupTest,
|
|
||||||
triggerLatencyProxyTest,
|
|
||||||
triggerProxySelector,
|
|
||||||
validateDNS,
|
validateDNS,
|
||||||
validateDomain,
|
validateDomain,
|
||||||
validateIPV4,
|
validateIPV4,
|
||||||
|
|||||||
Reference in New Issue
Block a user