mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-14 23:46:50 +03:00
feat: add trojan link support to Proxy Configuration URL validation
This commit is contained in:
@@ -8,3 +8,4 @@ export * from './bulkValidate';
|
||||
export * from './validateShadowsocksUrl';
|
||||
export * from './validateVlessUrl';
|
||||
export * from './validateOutboundJson';
|
||||
export * from './validateTrojanUrl';
|
||||
|
||||
26
fe-app-podkop/src/validators/validateTrojanUrl.ts
Normal file
26
fe-app-podkop/src/validators/validateTrojanUrl.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { ValidationResult } from './types';
|
||||
|
||||
// TODO refactor current validation and add tests
|
||||
export function validateTrojanUrl(url: string): ValidationResult {
|
||||
if (!url.startsWith('trojan://')) {
|
||||
return {
|
||||
valid: false,
|
||||
message: 'Invalid Trojan URL: must start with trojan://',
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const parsedUrl = new URL(url);
|
||||
|
||||
if (!parsedUrl.username || !parsedUrl.hostname || !parsedUrl.port) {
|
||||
return {
|
||||
valid: false,
|
||||
message: 'Invalid Trojan URL: must contain username, hostname and port',
|
||||
};
|
||||
}
|
||||
} catch (e) {
|
||||
return { valid: false, message: 'Invalid Trojan URL: parsing failed' };
|
||||
}
|
||||
|
||||
return { valid: true, message: 'Valid' };
|
||||
}
|
||||
@@ -34,7 +34,7 @@ function createConfigSection(section) {
|
||||
o.rmempty = false;
|
||||
o.ucisection = s.section;
|
||||
o.sectionDescriptions = new Map();
|
||||
o.placeholder = 'vless://uuid@server:port?type=tcp&security=tls#main\n// backup ss://method:pass@server:port\n// backup2 vless://uuid@server:port?type=grpc&security=reality#alt';
|
||||
o.placeholder = 'vless://uuid@server:port?type=tcp&security=tls#main\n// backup ss://method:pass@server:port\n// backup2 vless://uuid@server:port?type=grpc&security=reality#alt\n// backup3 trojan://04agAQapcl@127.0.0.1:33641?type=tcp&security=none#trojan-tcp-none';
|
||||
|
||||
o.renderWidget = function (section_id, option_index, cfgvalue) {
|
||||
const original = form.TextValue.prototype.renderWidget.apply(this, [section_id, option_index, cfgvalue]);
|
||||
@@ -112,7 +112,17 @@ function createConfigSection(section) {
|
||||
return _(validation.message)
|
||||
}
|
||||
|
||||
return _('URL must start with vless:// or ss://')
|
||||
if (activeConfig.startsWith('trojan://')) {
|
||||
const validation = main.validateTrojanUrl(activeConfig);
|
||||
|
||||
if (validation.valid) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return _(validation.message)
|
||||
}
|
||||
|
||||
return _('URL must start with vless:// or ss:// or trojan://')
|
||||
|
||||
} catch (e) {
|
||||
return `${_('Invalid URL format:')} ${e?.message}`;
|
||||
|
||||
@@ -277,6 +277,28 @@ function validateOutboundJson(value) {
|
||||
}
|
||||
}
|
||||
|
||||
// src/validators/validateTrojanUrl.ts
|
||||
function validateTrojanUrl(url) {
|
||||
if (!url.startsWith("trojan://")) {
|
||||
return {
|
||||
valid: false,
|
||||
message: "Invalid Trojan URL: must start with trojan://"
|
||||
};
|
||||
}
|
||||
try {
|
||||
const parsedUrl = new URL(url);
|
||||
if (!parsedUrl.username || !parsedUrl.hostname || !parsedUrl.port) {
|
||||
return {
|
||||
valid: false,
|
||||
message: "Invalid Trojan URL: must contain username, hostname and port"
|
||||
};
|
||||
}
|
||||
} catch (e) {
|
||||
return { valid: false, message: "Invalid Trojan URL: parsing failed" };
|
||||
}
|
||||
return { valid: true, message: "Valid" };
|
||||
}
|
||||
|
||||
// src/helpers/getBaseUrl.ts
|
||||
function getBaseUrl() {
|
||||
const { protocol, hostname } = window.location;
|
||||
@@ -465,6 +487,7 @@ return baseclass.extend({
|
||||
validatePath,
|
||||
validateShadowsocksUrl,
|
||||
validateSubnet,
|
||||
validateTrojanUrl,
|
||||
validateUrl,
|
||||
validateVlessUrl
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user