mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-06 03:26:51 +03:00
feat: implement fakeip checks step
This commit is contained in:
24
fe-app-podkop/src/podkop/methods/getFakeIPCheck.ts
Normal file
24
fe-app-podkop/src/podkop/methods/getFakeIPCheck.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
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: '',
|
||||
};
|
||||
}
|
||||
@@ -5,3 +5,4 @@ export * from './getSingBoxStatus';
|
||||
export * from './getDNSCheck';
|
||||
export * from './getNftRulesCheck';
|
||||
export * from './getSingBoxCheck';
|
||||
export * from './getFakeIPCheck';
|
||||
|
||||
@@ -1,29 +1,101 @@
|
||||
import * as podkopMethods from '../../../methods';
|
||||
import * as fakeIPMethods from '../../../../fakeip/methods';
|
||||
import { updateDiagnosticsCheck } from '../updateDiagnosticsCheck';
|
||||
import { insertIf } from '../../../../helpers';
|
||||
import { IDiagnosticsChecksItem } from '../../../../store';
|
||||
|
||||
export async function runFakeIPCheck() {
|
||||
const code = 'fake_ip_check';
|
||||
|
||||
updateDiagnosticsCheck({
|
||||
code,
|
||||
title: _('Fake IP checks'),
|
||||
description: _('Not implemented yet'),
|
||||
state: 'skipped',
|
||||
title: _('FakeIP checks'),
|
||||
description: _('Checking FakeIP, please wait'),
|
||||
state: 'loading',
|
||||
items: [],
|
||||
});
|
||||
|
||||
const routerFakeIPResponse = await podkopMethods.getFakeIPCheck();
|
||||
const checkFakeIPResponse = await fakeIPMethods.getFakeIpCheck();
|
||||
const checkIPResponse = await fakeIPMethods.getIpCheck();
|
||||
|
||||
console.log('runFakeIPCheck', {
|
||||
routerFakeIPResponse,
|
||||
checkFakeIPResponse,
|
||||
checkIPResponse,
|
||||
});
|
||||
|
||||
const checks = {
|
||||
router: routerFakeIPResponse.success && routerFakeIPResponse.data.fakeip,
|
||||
browserFakeIP:
|
||||
checkFakeIPResponse.success && checkFakeIPResponse.data.fakeip,
|
||||
differentIP:
|
||||
checkFakeIPResponse.success &&
|
||||
checkIPResponse.success &&
|
||||
checkFakeIPResponse.data.IP !== checkIPResponse.data.IP,
|
||||
};
|
||||
|
||||
console.log('checks', checks);
|
||||
|
||||
const allGood = checks.router || checks.browserFakeIP || checks.differentIP;
|
||||
const atLeastOneGood =
|
||||
checks.router && checks.browserFakeIP && checks.differentIP;
|
||||
|
||||
function getMeta(): {
|
||||
description: string;
|
||||
state: 'loading' | 'warning' | 'success' | 'error' | 'skipped';
|
||||
} {
|
||||
if (allGood) {
|
||||
return {
|
||||
state: 'success',
|
||||
description: _('FakeIP checks passed'),
|
||||
};
|
||||
}
|
||||
|
||||
if (atLeastOneGood) {
|
||||
return {
|
||||
state: 'warning',
|
||||
description: _('FakeIP checks partially passed'),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
state: 'error',
|
||||
description: _('FakeIP checks failed'),
|
||||
};
|
||||
}
|
||||
|
||||
const { state, description } = getMeta();
|
||||
|
||||
updateDiagnosticsCheck({
|
||||
code,
|
||||
title: _('FakeIP checks'),
|
||||
description,
|
||||
state,
|
||||
items: [
|
||||
{
|
||||
state: 'success',
|
||||
key: 'success',
|
||||
state: checks.router ? 'success' : 'warning',
|
||||
key: checks.router
|
||||
? _('Router DNS is routed through sing-box')
|
||||
: _('Router DNS is not routed through sing-box'),
|
||||
value: '',
|
||||
},
|
||||
{
|
||||
state: 'warning',
|
||||
key: 'warning',
|
||||
value: '',
|
||||
},
|
||||
{
|
||||
state: 'error',
|
||||
key: 'error',
|
||||
state: checks.browserFakeIP ? 'success' : 'error',
|
||||
key: checks.browserFakeIP
|
||||
? _('Browser is using FakeIP correctly')
|
||||
: _('Browser is not using FakeIP'),
|
||||
value: '',
|
||||
},
|
||||
...insertIf<IDiagnosticsChecksItem>(checks.browserFakeIP, [
|
||||
{
|
||||
state: checks.differentIP ? 'success' : 'error',
|
||||
key: checks.differentIP
|
||||
? _('Proxy traffic is routed via FakeIP')
|
||||
: _('Proxy traffic is not routed via FakeIP'),
|
||||
value: '',
|
||||
},
|
||||
]),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5,9 +5,6 @@ import { getFakeIpCheck, getIpCheck } from '../../../../fakeip';
|
||||
export async function runNftCheck() {
|
||||
const code = 'nft_check';
|
||||
|
||||
await getFakeIpCheck();
|
||||
await getIpCheck();
|
||||
|
||||
updateDiagnosticsCheck({
|
||||
code,
|
||||
title: _('Nftables checks'),
|
||||
@@ -16,6 +13,9 @@ export async function runNftCheck() {
|
||||
items: [],
|
||||
});
|
||||
|
||||
await getFakeIpCheck();
|
||||
await getIpCheck();
|
||||
|
||||
const nftablesChecks = await getNftRulesCheck();
|
||||
|
||||
if (!nftablesChecks.success) {
|
||||
|
||||
@@ -97,4 +97,9 @@ export namespace Podkop {
|
||||
sing_box_process_running: 0 | 1;
|
||||
sing_box_ports_listening: 0 | 1;
|
||||
}
|
||||
|
||||
export interface FakeIPCheckResult {
|
||||
fakeip: boolean;
|
||||
IP: string;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1268,6 +1268,25 @@ async function getSingBoxCheck() {
|
||||
};
|
||||
}
|
||||
|
||||
// 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
|
||||
var TabService = class _TabService {
|
||||
constructor() {
|
||||
@@ -2774,8 +2793,6 @@ async function getFakeIpCheck() {
|
||||
// src/podkop/tabs/diagnostic/checks/runNftCheck.ts
|
||||
async function runNftCheck() {
|
||||
const code = "nft_check";
|
||||
await getFakeIpCheck();
|
||||
await getIpCheck();
|
||||
updateDiagnosticsCheck({
|
||||
code,
|
||||
title: _("Nftables checks"),
|
||||
@@ -2783,6 +2800,8 @@ async function runNftCheck() {
|
||||
state: "loading",
|
||||
items: []
|
||||
});
|
||||
await getFakeIpCheck();
|
||||
await getIpCheck();
|
||||
const nftablesChecks = await getNftRulesCheck();
|
||||
if (!nftablesChecks.success) {
|
||||
updateDiagnosticsCheck({
|
||||
@@ -2865,25 +2884,69 @@ async function runFakeIPCheck() {
|
||||
const code = "fake_ip_check";
|
||||
updateDiagnosticsCheck({
|
||||
code,
|
||||
title: _("Fake IP checks"),
|
||||
description: _("Not implemented yet"),
|
||||
state: "skipped",
|
||||
title: _("FakeIP checks"),
|
||||
description: _("Checking FakeIP, please wait"),
|
||||
state: "loading",
|
||||
items: []
|
||||
});
|
||||
const routerFakeIPResponse = await getFakeIPCheck();
|
||||
const checkFakeIPResponse = await getFakeIpCheck();
|
||||
const checkIPResponse = await getIpCheck();
|
||||
console.log("runFakeIPCheck", {
|
||||
routerFakeIPResponse,
|
||||
checkFakeIPResponse,
|
||||
checkIPResponse
|
||||
});
|
||||
const checks = {
|
||||
router: routerFakeIPResponse.success && routerFakeIPResponse.data.fakeip,
|
||||
browserFakeIP: checkFakeIPResponse.success && checkFakeIPResponse.data.fakeip,
|
||||
differentIP: checkFakeIPResponse.success && checkIPResponse.success && checkFakeIPResponse.data.IP !== checkIPResponse.data.IP
|
||||
};
|
||||
console.log("checks", checks);
|
||||
const allGood = checks.router || checks.browserFakeIP || checks.differentIP;
|
||||
const atLeastOneGood = checks.router && checks.browserFakeIP && checks.differentIP;
|
||||
function getMeta() {
|
||||
if (allGood) {
|
||||
return {
|
||||
state: "success",
|
||||
description: _("FakeIP checks passed")
|
||||
};
|
||||
}
|
||||
if (atLeastOneGood) {
|
||||
return {
|
||||
state: "warning",
|
||||
description: _("FakeIP checks partially passed")
|
||||
};
|
||||
}
|
||||
return {
|
||||
state: "error",
|
||||
description: _("FakeIP checks failed")
|
||||
};
|
||||
}
|
||||
const { state, description } = getMeta();
|
||||
updateDiagnosticsCheck({
|
||||
code,
|
||||
title: _("FakeIP checks"),
|
||||
description,
|
||||
state,
|
||||
items: [
|
||||
{
|
||||
state: "success",
|
||||
key: "success",
|
||||
state: checks.router ? "success" : "warning",
|
||||
key: checks.router ? _("Router DNS is routed through sing-box") : _("Router DNS is not routed through sing-box"),
|
||||
value: ""
|
||||
},
|
||||
{
|
||||
state: "warning",
|
||||
key: "warning",
|
||||
state: checks.browserFakeIP ? "success" : "error",
|
||||
key: checks.browserFakeIP ? _("Browser is using FakeIP correctly") : _("Browser is not using FakeIP"),
|
||||
value: ""
|
||||
},
|
||||
{
|
||||
state: "error",
|
||||
key: "error",
|
||||
value: ""
|
||||
}
|
||||
...insertIf(checks.browserFakeIP, [
|
||||
{
|
||||
state: checks.differentIP ? "success" : "error",
|
||||
key: checks.differentIP ? _("Proxy traffic is routed via FakeIP") : _("Proxy traffic is not routed via FakeIP"),
|
||||
value: ""
|
||||
}
|
||||
])
|
||||
]
|
||||
});
|
||||
}
|
||||
@@ -2955,6 +3018,7 @@ return baseclass.extend({
|
||||
getConfigSections,
|
||||
getDNSCheck,
|
||||
getDashboardSections,
|
||||
getFakeIPCheck,
|
||||
getNftRulesCheck,
|
||||
getPodkopStatus,
|
||||
getProxyUrlName,
|
||||
|
||||
Reference in New Issue
Block a user