mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-07-12 07:36:07 +00:00
feat: add manual and automatic WARP IP rotation (#5099)
* feat: add manual and automatic WARP IP rotation * fix: update generated api and frontend schemas * fix(warp): validate rotation interval, fix auto-update timing, sync editor - Validate the auto-update interval as an integer and store it via setInt; a non-integer value previously broke GetAllSetting for the whole panel. - Seed warpLastUpdate when the interval is saved and when changing IP manually, so auto-update counts from "now" instead of epoch 0 and a manual rotation doesn't trigger an immediate scheduled one. - Guard WarpIpJob: when lastUpdate is unset, establish a baseline and skip instead of rotating on the next tick. - Log WARP license re-apply failures instead of swallowing them. - After a manual "Change IP", sync the in-memory Xray editor with the keys the backend persisted so a later template save can't revert them; only toast success when the interval save actually succeeds. - Add the WARP rotation UI strings to all 13 locales. - Drop trailing whitespace introduced in entity.go and xray_setting.go. --------- Co-authored-by: Rqzbeh <Rqzbeh@example.com> Co-authored-by: Sanaei <ho3ein.sanaei@gmail.com>
This commit is contained in:
@@ -75,6 +75,7 @@ export const EXAMPLES: Record<string, unknown> = {
|
||||
"trustedProxyCIDRs": "",
|
||||
"twoFactorEnable": false,
|
||||
"twoFactorToken": "",
|
||||
"warpUpdateInterval": 0,
|
||||
"webBasePath": "",
|
||||
"webCertFile": "",
|
||||
"webDomain": "",
|
||||
@@ -163,6 +164,7 @@ export const EXAMPLES: Record<string, unknown> = {
|
||||
"trustedProxyCIDRs": "",
|
||||
"twoFactorEnable": false,
|
||||
"twoFactorToken": "",
|
||||
"warpUpdateInterval": 0,
|
||||
"webBasePath": "",
|
||||
"webCertFile": "",
|
||||
"webDomain": "",
|
||||
|
||||
@@ -299,6 +299,11 @@ export const SCHEMAS: Record<string, unknown> = {
|
||||
"description": "Two-factor authentication token",
|
||||
"type": "string"
|
||||
},
|
||||
"warpUpdateInterval": {
|
||||
"description": "WARP",
|
||||
"minimum": 0,
|
||||
"type": "integer"
|
||||
},
|
||||
"webBasePath": {
|
||||
"description": "Base path for web panel URLs",
|
||||
"type": "string"
|
||||
@@ -401,6 +406,7 @@ export const SCHEMAS: Record<string, unknown> = {
|
||||
"trustedProxyCIDRs",
|
||||
"twoFactorEnable",
|
||||
"twoFactorToken",
|
||||
"warpUpdateInterval",
|
||||
"webBasePath",
|
||||
"webCertFile",
|
||||
"webDomain",
|
||||
@@ -727,6 +733,11 @@ export const SCHEMAS: Record<string, unknown> = {
|
||||
"description": "Two-factor authentication token",
|
||||
"type": "string"
|
||||
},
|
||||
"warpUpdateInterval": {
|
||||
"description": "WARP",
|
||||
"minimum": 0,
|
||||
"type": "integer"
|
||||
},
|
||||
"webBasePath": {
|
||||
"description": "Base path for web panel URLs",
|
||||
"type": "string"
|
||||
@@ -835,6 +846,7 @@ export const SCHEMAS: Record<string, unknown> = {
|
||||
"trustedProxyCIDRs",
|
||||
"twoFactorEnable",
|
||||
"twoFactorToken",
|
||||
"warpUpdateInterval",
|
||||
"webBasePath",
|
||||
"webCertFile",
|
||||
"webDomain",
|
||||
|
||||
@@ -80,6 +80,7 @@ export interface AllSetting {
|
||||
trustedProxyCIDRs: string;
|
||||
twoFactorEnable: boolean;
|
||||
twoFactorToken: string;
|
||||
warpUpdateInterval: number;
|
||||
webBasePath: string;
|
||||
webCertFile: string;
|
||||
webDomain: string;
|
||||
@@ -169,6 +170,7 @@ export interface AllSettingView {
|
||||
trustedProxyCIDRs: string;
|
||||
twoFactorEnable: boolean;
|
||||
twoFactorToken: string;
|
||||
warpUpdateInterval: number;
|
||||
webBasePath: string;
|
||||
webCertFile: string;
|
||||
webDomain: string;
|
||||
|
||||
@@ -90,6 +90,7 @@ export const AllSettingSchema = z.object({
|
||||
trustedProxyCIDRs: z.string(),
|
||||
twoFactorEnable: z.boolean(),
|
||||
twoFactorToken: z.string(),
|
||||
warpUpdateInterval: z.number().int().min(0),
|
||||
webBasePath: z.string(),
|
||||
webCertFile: z.string(),
|
||||
webDomain: z.string(),
|
||||
@@ -180,6 +181,7 @@ export const AllSettingViewSchema = z.object({
|
||||
trustedProxyCIDRs: z.string(),
|
||||
twoFactorEnable: z.boolean(),
|
||||
twoFactorToken: z.string(),
|
||||
warpUpdateInterval: z.number().int().min(0),
|
||||
webBasePath: z.string(),
|
||||
webCertFile: z.string(),
|
||||
webDomain: z.string(),
|
||||
|
||||
@@ -80,6 +80,7 @@ export default function WarpModal({
|
||||
const [warpData, setWarpData] = useState<WarpData | null>(null);
|
||||
const [warpConfig, setWarpConfig] = useState<WarpConfig | null>(null);
|
||||
const [warpPlus, setWarpPlus] = useState('');
|
||||
const [updateInterval, setUpdateInterval] = useState<number>(0);
|
||||
const [licenseError, setLicenseError] = useState('');
|
||||
const [stagedOutbound, setStagedOutbound] = useState<Record<string, unknown> | null>(null);
|
||||
|
||||
@@ -89,24 +90,29 @@ export default function WarpModal({
|
||||
return list.findIndex((o) => o?.tag === 'warp');
|
||||
}, [templateSettings?.outbounds]);
|
||||
|
||||
const collectConfig = useCallback((data: WarpData | null, config: WarpConfig | null) => {
|
||||
const cfg = config?.config;
|
||||
if (!cfg?.peers?.length) return;
|
||||
const peer = cfg.peers[0];
|
||||
setStagedOutbound({
|
||||
tag: 'warp',
|
||||
protocol: 'wireguard',
|
||||
settings: {
|
||||
mtu: 1420,
|
||||
secretKey: data?.private_key,
|
||||
address: addressesFor(cfg.interface?.addresses || {}),
|
||||
reserved: reservedFor(cfg.client_id ?? data?.client_id),
|
||||
domainStrategy: 'ForceIP',
|
||||
peers: [{ publicKey: peer.public_key, endpoint: peer.endpoint?.host }],
|
||||
noKernelTun: false,
|
||||
},
|
||||
});
|
||||
}, []);
|
||||
const collectConfig = useCallback(
|
||||
(data: WarpData | null, config: WarpConfig | null): Record<string, unknown> | null => {
|
||||
const cfg = config?.config;
|
||||
if (!cfg?.peers?.length) return null;
|
||||
const peer = cfg.peers[0];
|
||||
const outbound: Record<string, unknown> = {
|
||||
tag: 'warp',
|
||||
protocol: 'wireguard',
|
||||
settings: {
|
||||
mtu: 1420,
|
||||
secretKey: data?.private_key,
|
||||
address: addressesFor(cfg.interface?.addresses || {}),
|
||||
reserved: reservedFor(cfg.client_id ?? data?.client_id),
|
||||
domainStrategy: 'ForceIP',
|
||||
peers: [{ publicKey: peer.public_key, endpoint: peer.endpoint?.host }],
|
||||
noKernelTun: false,
|
||||
},
|
||||
};
|
||||
setStagedOutbound(outbound);
|
||||
return outbound;
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
const fetchData = useCallback(async () => {
|
||||
setLoading(true);
|
||||
@@ -116,6 +122,10 @@ export default function WarpModal({
|
||||
const raw = msg.obj;
|
||||
setWarpData(raw && raw.length > 0 ? JSON.parse(raw) : null);
|
||||
}
|
||||
const settingMsg = await HttpUtil.post<Record<string, unknown>>('/panel/api/setting/all');
|
||||
if (settingMsg?.success && settingMsg.obj) {
|
||||
setUpdateInterval(Number(settingMsg.obj.warpUpdateInterval) || 0);
|
||||
}
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -159,6 +169,40 @@ export default function WarpModal({
|
||||
}
|
||||
}
|
||||
|
||||
async function changeIp() {
|
||||
setLoading(true);
|
||||
try {
|
||||
const msg = await HttpUtil.post<string>('/panel/api/xray/warp/changeIp');
|
||||
if (msg?.success && msg.obj) {
|
||||
const parsed = JSON.parse(msg.obj);
|
||||
setWarpData(parsed.data);
|
||||
setWarpConfig(parsed.config);
|
||||
const built = collectConfig(parsed.data, parsed.config);
|
||||
// The backend already persisted the new keys into the saved Xray
|
||||
// template; keep the in-memory editor in sync so a later template
|
||||
// save doesn't revert them to the old keys.
|
||||
if (built && warpOutboundIndex >= 0) {
|
||||
onResetOutbound({ index: warpOutboundIndex, outbound: built });
|
||||
}
|
||||
messageApi.success(t('pages.xray.warp.changeIpSuccess', 'WARP IP changed successfully!'));
|
||||
}
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function saveInterval() {
|
||||
setLoading(true);
|
||||
try {
|
||||
const msg = await HttpUtil.post('/panel/api/xray/warp/interval', { interval: updateInterval });
|
||||
if (msg?.success) {
|
||||
messageApi.success(t('pages.setting.toasts.saveSuccess', 'Settings saved successfully'));
|
||||
}
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function updateLicense() {
|
||||
if (warpPlus.length < 26) return;
|
||||
setLoading(true);
|
||||
@@ -281,13 +325,37 @@ export default function WarpModal({
|
||||
</Form>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: '2',
|
||||
label: t('pages.xray.warp.autoUpdateIp', 'Auto Update IP Address'),
|
||||
children: (
|
||||
<Form colon={false} labelCol={{ md: { span: 8 } }} wrapperCol={{ md: { span: 12 } }}>
|
||||
<Form.Item label={t('pages.xray.warp.intervalDays', 'Interval (Days)')} extra={t('pages.xray.warp.intervalDesc', '0 to disable. Changes IP address automatically.')}>
|
||||
<Input
|
||||
type="number"
|
||||
min={0}
|
||||
value={updateInterval}
|
||||
onChange={(e) => setUpdateInterval(Number(e.target.value))}
|
||||
/>
|
||||
<Button className="mt-8" type="primary" loading={loading} onClick={saveInterval}>
|
||||
{t('save', 'Save')}
|
||||
</Button>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
|
||||
<Divider className="zero-margin">{t('pages.xray.warp.accountInfo')}</Divider>
|
||||
<Button className="my-8" loading={loading} type="primary" icon={<SyncOutlined />} onClick={getConfig}>
|
||||
{t('refresh')}
|
||||
</Button>
|
||||
<div className="my-8">
|
||||
<Button loading={loading} type="primary" icon={<SyncOutlined />} onClick={getConfig}>
|
||||
{t('refresh')}
|
||||
</Button>
|
||||
<Button loading={loading} type="primary" className="ml-8" icon={<SyncOutlined />} onClick={changeIp}>
|
||||
{t('pages.xray.warp.changeIp', 'Change IP')}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{hasConfig && (
|
||||
<>
|
||||
|
||||
Reference in New Issue
Block a user