mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-09-10 18:34:18 +08:00
274 lines
92 KiB
JavaScript
274 lines
92 KiB
JavaScript
|
|
'use strict';
|
|
'require form';
|
|
'require fs';
|
|
'require poll';
|
|
'require rpc';
|
|
'require uci';
|
|
'require ui';
|
|
'require view';
|
|
|
|
var LuciView=(()=>{var ie=Object.defineProperty;var Sr=Object.getOwnPropertyDescriptor;var vr=Object.getOwnPropertyNames;var Er=Object.prototype.hasOwnProperty;var Tr=(e,t)=>{for(var r in t)ie(e,r,{get:t[r],enumerable:!0})},Or=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of vr(t))!Er.call(e,o)&&o!==r&&ie(e,o,{get:()=>t[o],enumerable:!(n=Sr(t,o))||n.enumerable});return e};var wr=e=>Or(ie({},"__esModule",{value:!0}),e);var po={};Tr(po,{default:()=>uo});var S={CUSTOM:"custom",LOAD_BALANCE:"load_balance",HYSTERIA2:"hysteria2",SHADOWSOCKS:"shadowsocks",TUIC:"tuic",SHADOWTLS:"shadowtls",VLESS:"vless"},N={XRAY:"xray",SING_BOX:"sing-box",CUSTOM:"custom"},Q={NONE:"none",PRE_ROUTING:"pre-routing",ROUTING:"routing"};function q(e){let t=(e||"").trim();return t==="singbox"?N.SING_BOX:t}var _o={[N.XRAY]:[S.SHADOWSOCKS,S.HYSTERIA2,S.VLESS],[N.SING_BOX]:[S.SHADOWSOCKS,S.HYSTERIA2,S.VLESS,S.TUIC,S.SHADOWTLS]},dt={DNS_STRATEGY_VALUES:[{label:"Prefer IPv6 (sing-box only, xray uses dual stack by default)",value:"64"},{label:"Prefer IPv4 (sing-box only, xray uses dual stack by default)",value:"46"},{label:"IPv6 only",value:"6"},{label:"IPv4 only",value:"4"}],SHUNT_LOG_LEVELS:["info","warn","error","debug"],PROXY_LOG_LEVELS:["info","warn","error","debug"],SHUNT_CONF_TYPE:[N.XRAY,N.SING_BOX],PROXY_TYPES:[{label:"Load Balancing",value:"load_balance"},{label:"Shadowsocks",value:"shadowsocks"},{label:"Hysteria2",value:"hysteria2"},{label:"VLESS",value:"vless"},{label:"TUIC",value:"tuic"},{label:"ShadowTLS",value:"shadowtls"}],SHADOWSOCKS_METHODS:[{label:"2022-blake3-aes-128-gcm",value:"2022-blake3-aes-128-gcm"},{label:"2022-blake3-aes-256-gcm",value:"2022-blake3-aes-256-gcm"},{label:"2022-blake3-chacha20-poly1305",value:"2022-blake3-chacha20-poly1305"},{label:"aes-128-gcm",value:"aes-128-gcm"},{label:"aes-192-gcm",value:"aes-192-gcm"},{label:"aes-256-gcm",value:"aes-256-gcm"},{label:"chacha20-ietf-poly1305",value:"chacha20-ietf-poly1305"},{label:"xchacha20-ietf-poly1305",value:"xchacha20-ietf-poly1305"}],MULTIPLEX_PROTOCOLS:[{label:"smux",value:"smux"},{label:"yamux",value:"yamux"},{label:"h2mux",value:"h2mux"}],TUIC_CONGESTION_CONTROLS:[{label:"cubic",value:"cubic"},{label:"new_reno",value:"new_reno"},{label:"bbr",value:"bbr"}],TUIC_UDP_RELAY_MODES:[{label:"Native UDP",value:"native"},{label:"QUIC Stream",value:"quic"}],SHADOWTLS_VERSIONS:[{label:"v1",value:"1"},{label:"v2",value:"2"},{label:"v3",value:"3"}],VLESS_FLOWS:[{label:"None",value:""},{label:"xtls-rprx-vision",value:"xtls-rprx-vision"},{label:"xtls-rprx-vision-udp443",value:"xtls-rprx-vision-udp443"}],VLESS_PACKET_ENCODINGS:[{label:"Disabled",value:""},{label:"packetaddr",value:"packetaddr"},{label:"xudp",value:"xudp"}],V2RAY_TRANSPORT_TYPES_XRAY:[{label:"None",value:""},{label:"HTTP",value:"http"},{label:"WebSocket",value:"ws"},{label:"gRPC",value:"grpc"},{label:"HTTPUpgrade",value:"httpupgrade"},{label:"XHTTP",value:"xhttp"}],HYSTERIA2_OBFS_TYPES:[{label:"Disabled",value:""},{label:"Salamander",value:"salamander"}],DUAL_CORES:[{label:"sing-box",value:N.SING_BOX},{label:"xray",value:N.XRAY},{label:"Custom",value:N.CUSTOM}]};var O=fs;var a=uci;var M=ui;var et=class{disabled;level;timestamp;constructor(t){this.disabled=!1,this.level=t||"info",this.timestamp=!0}},gt=class{type;tag;server;server_port;detour;constructor(t,r,n,o,s){this.type=t,this.tag=r,this.server=n,this.server_port=Number.isFinite(o)&&o>0?o:void 0,this.detour=s==="direct-out"?void 0:s}},St=class{servers;rules;strategy;disable_cache;disable_expire;final;constructor(t,r,n){this.servers=[],this.rules=[],this.strategy=r||"prefer_ipv6",this.disable_cache=!n,this.disable_expire=!n,this.final=t}},vt=class{action;outbound;constructor(t,r){this.action=t,this.outbound=r}},rt=class extends vt{ip_version;protocol;port;port_range;domain;domain_suffix;domain_keyword;domain_regex;rule_set;ip_cidr;network;constructor(t,r){super(t,r)}initRule(t){return this.ip_version=t.ipVersion,this.network=t.network,this.protocol=t.protocol,this.port=t.port,this.port_range=t.portRange.map(r=>r.replace("-",":")),this.domain=t.domain,this.domain_suffix=t.domainSuffix,this.domain_keyword=t.domainKeyword,this.domain_regex=t.domainRegex,this.rule_set=t.ruleSet.map(r=>r.tag),this.ip_cidr=t.ipCidr,this}},Et=class extends vt{domain;domain_keyword;domain_regex;domain_suffix;rule_set;server;strategy;disable_cache;disable_expire;constructor(t,r,n){super(t,void 0),this.action=t,this.server=r,this.strategy=n,this.disable_cache=!0}initRule(t){return this.domain=t.domain,this.domain_suffix=t.domainSuffix,this.domain_keyword=t.domainKeyword,this.domain_regex=t.domainRegex,this.rule_set=t.ruleSet.map(r=>r.tag),this}},ae=class extends rt{constructor(){super("sniff",void 0)}},le=class extends rt{constructor(){super("hijack-dns",void 0),this.protocol=["dns"]}},Tt=class{type;tag;format;constructor(t,r,n){this.type=r,this.tag=t,this.format=n}},Ot=class extends Tt{url;http_client;update_interval;constructor(t,r,n,o,s){super(t,"remote",r),this.url=n,o&&(this.http_client=new ue(o)),this.update_interval=s}},ue=class{detour;constructor(t){this.detour=t}},wt=class extends Tt{path;constructor(t,r,n){super(t,"local",r),this.path=n}},Ct=class{rules;rule_set;default_domain_resolver;final;constructor(t,r){this.rules=[new ae,new le],this.rule_set=[],this.default_domain_resolver=r,this.final=t}},nt=class{type="tproxy";tag;listen;listen_port;constructor(t,r,n){this.tag=r,this.listen=n??"::",this.listen_port=t}},Pt=class{type="direct";tag;listen;listen_port;constructor(t,r){this.tag=r,this.listen="::",this.listen_port=t}},_t=class{type="socks";tag;listen;listen_port;users;constructor(t,r,n){this.tag=r,this.listen=n??"::",this.listen_port=t}},Rt=class{type="block";tag;constructor(t){this.tag=t}},Dt=class{type="direct";tag;domain_resolver;constructor(t){this.tag=t}},At=class{type="urltest";tag;url;interval;tolerance;idle_timeout;interrupt_exist_connections;outbounds;constructor(t,r,n,o,s,i){this.tag=t,this.outbounds=[],this.url=r,this.interval=n,this.tolerance=o,this.idle_timeout=s,this.interrupt_exist_connections=i}},ot=class{type="socks";tag;server;server_port;version="5";domain_resolver;constructor(t,r,n){this.tag=n,this.server=t,this.server_port=r,this.version="5"}},H=class{enabled;server_name;insecure;reality;constructor(t){this.enabled=!0,this.server_name=t}},st=class{enabled;up_mbps;down_mbps;constructor(){this.enabled=!0}},it=class{enabled;protocol;max_connections;min_streams;max_streams;brutal;constructor(){this.enabled=!0}};var pe=class{protocols=new Map;register(t){this.protocols.set(t.type,t)}build(t,r){let n=this.protocols.get(t);if(!n)throw new Error(`Unsupported sing-box protocol: ${t}`);return n.build(r)}},Y=new pe;var ce=class{type;password;constructor(t){this.type="salamander",this.password=t}},de=class{type="hysteria2";tag;server;server_port;password;obfs;up_mbps;down_mbps;server_ports;hop_interval;network;tls;constructor(t,r,n,o){this.tag=t,this.server=r,this.server_port=n,this.tls=new H(o)}},Pr={type:"hysteria2",build(e){let t=e,r=new de(t.name,t.server,parseInt(t.server_port),t.tls_server_name||t.server);return t.password&&(r.password=t.password),t.up_mbps&&(r.up_mbps=Number(t.up_mbps)),t.down_mbps&&(r.down_mbps=Number(t.down_mbps)),t.server_ports&&t.server_ports.length>0&&(r.server_ports=t.server_ports.map(n=>n.replace("-",":")).filter(n=>n.length>0)),t.hop_interval&&(r.hop_interval=t.hop_interval),t.network&&(r.network=t.network),t.obfs_type==="salamander"&&t.obfs_password&&(r.obfs=new ce(t.obfs_password)),r.tls.insecure=t.tls_insecure==="1",r}};Y.register(Pr);var ge=class{type="shadowsocks";tag;server;server_port;method;password;network;udp_over_tcp;plugin;plugin_opts;multiplex;constructor(t,r,n,o,s){this.tag=t,this.server=r,this.server_port=n,this.method=o,this.password=s}};function Rr(e){let t=new it;if(e.multiplex_protocol&&(t.protocol=e.multiplex_protocol),e.multiplex_max_connections&&(t.max_connections=parseInt(e.multiplex_max_connections)),e.multiplex_min_streams&&(t.min_streams=parseInt(e.multiplex_min_streams)),e.multiplex_max_streams&&(t.max_streams=parseInt(e.multiplex_max_streams)),e.multiplex_brutal_enabled==="1"){let r=new st;e.multiplex_brutal_up_mbps&&(r.up_mbps=parseInt(e.multiplex_brutal_up_mbps)),e.multiplex_brutal_down_mbps&&(r.down_mbps=parseInt(e.multiplex_brutal_down_mbps)),t.brutal=r}return t}var Dr={type:"shadowsocks",build(e){let t=e,r=new ge(t.name,t.server,parseInt(t.server_port),t.method,t.password);return t.network&&(r.network=t.network),t.udp_over_tcp==="1"&&(r.udp_over_tcp=!0),t.plugin&&(r.plugin=t.plugin),t.plugin_opts&&(r.plugin_opts=t.plugin_opts),t.multiplex_enabled==="1"&&(r.multiplex=Rr(t)),r}};Y.register(Dr);var _e=class{type="vless";tag;server;server_port;uuid;flow;network;packet_encoding;tls;transport;multiplex;constructor(t,r,n,o,s){this.tag=t,this.server=r,this.server_port=n,this.uuid=o,this.tls=new H(s)}};function Ar(e){switch(e.transport_type){case"http":{let t={type:"http"};return e.transport_http_host&&(t.host=e.transport_http_host),e.transport_http_path&&(t.path=e.transport_http_path),e.transport_http_method&&(t.method=e.transport_http_method),e.transport_http_idle_timeout&&(t.idle_timeout=e.transport_http_idle_timeout),e.transport_http_ping_timeout&&(t.ping_timeout=e.transport_http_ping_timeout),t}case"ws":{let t={type:"ws"};return e.transport_ws_path&&(t.path=e.transport_ws_path),e.transport_ws_host&&(t.headers={Host:e.transport_ws_host}),e.transport_ws_max_early_data&&(t.max_early_data=parseInt(e.transport_ws_max_early_data)),e.transport_ws_early_data_header_name&&(t.early_data_header_name=e.transport_ws_early_data_header_name),t}case"grpc":{let t={type:"grpc"};return e.transport_grpc_service_name&&(t.service_name=e.transport_grpc_service_name),e.transport_grpc_idle_timeout&&(t.idle_timeout=e.transport_grpc_idle_timeout),e.transport_grpc_ping_timeout&&(t.ping_timeout=e.transport_grpc_ping_timeout),e.transport_grpc_permit_without_stream==="1"&&(t.permit_without_stream=!0),t}case"httpupgrade":{let t={type:"httpupgrade"};return e.transport_httpupgrade_host&&(t.host=e.transport_httpupgrade_host),e.transport_httpupgrade_path&&(t.path=e.transport_httpupgrade_path),t}default:return}}function Lr(e){let t=new it;if(e.multiplex_protocol&&(t.protocol=e.multiplex_protocol),e.multiplex_max_connections&&(t.max_connections=parseInt(e.multiplex_max_connections)),e.multiplex_min_streams&&(t.min_streams=parseInt(e.multiplex_min_streams)),e.multiplex_max_streams&&(t.max_streams=parseInt(e.multiplex_max_streams)),e.multiplex_brutal_enabled==="1"){let r=new st;e.multiplex_brutal_up_mbps&&(r.up_mbps=parseInt(e.multiplex_brutal_up_mbps)),e.multiplex_brutal_down_mbps&&(r.down_mbps=parseInt(e.multiplex_brutal_down_mbps)),t.brutal=r}return t}var Ur={type:"vless",build(e){let t=e,r=new _e(t.name,t.server,parseInt(t.server_port),t.uuid,t.tls_server_name||t.server);return t.flow&&(r.flow=t.flow),t.network&&(r.network=t.network),t.packet_encoding&&(r.packet_encoding=t.packet_encoding),r.tls.insecure=t.tls_insecure==="1",t.tls_reality_enabled==="1"&&t.tls_reality_public_key&&(r.tls.reality={enabled:!0,public_key:t.tls_reality_public_key,short_id:t.tls_reality_short_id||""}),t.transport_type&&(r.transport=Ar(t)),t.multiplex_enabled==="1"&&(r.multiplex=Lr(t)),r}};Y.register(Ur);var fe=class{type="tuic";tag;server;server_port;uuid;password;congestion_control;udp_relay_mode;udp_over_stream;zero_rtt_handshake;heartbeat;network;tls;constructor(t,r,n,o,s,i){this.tag=t,this.server=r,this.server_port=n,this.uuid=o,this.password=s,this.tls=new H(i)}},kr={type:"tuic",build(e){let t=e,r=new fe(t.name,t.server,parseInt(t.server_port),t.uuid,t.password,t.tls_server_name||t.server);return t.congestion_control&&(r.congestion_control=t.congestion_control),t.udp_relay_mode&&(r.udp_relay_mode=t.udp_relay_mode),t.udp_over_stream==="1"&&(r.udp_over_stream=!0),t.zero_rtt_handshake==="1"&&(r.zero_rtt_handshake=!0),t.heartbeat&&(r.heartbeat=t.heartbeat),t.network&&(r.network=t.network),r.tls.insecure=t.tls_insecure==="1",r}};Y.register(kr);var me=class{type="shadowtls";tag;server;server_port;version;password;tls;constructor(t,r,n,o,s){this.tag=t,this.server=r,this.server_port=n,this.version=o,this.tls=new H(s)}},Ir={type:"shadowtls",build(e){let t=e,r=new me(t.name,t.server,parseInt(t.server_port),parseInt(t.version),t.tls_server_name||t.server);return t.password&&(r.password=t.password),r.tls.insecure=t.tls_insecure==="1",r}};Y.register(Ir);var Lt=class{tag;type;server;port},Ut=class{defaultDnsNode;defaultStrategy;rulesetDnsNode;useCache;nodes;constructor(){this.nodes=[]}},at=class{enabled;name;proxyNode;ipVersionSplit;proxyNodeV4;proxyNodeV6;protocol;network;port;portRange;domainList;ipList;dnsNode;dnsProxyNode;dnsStrategy;constructor(){this.port=[],this.portRange=[],this.network=[],this.protocol=[],this.ipVersionSplit="0"}},kt=class{defaultProxyNode;rulesetOutNode;rulesetConvert;rules;constructor(){this.rules=[]}},It=class{type;configType;shuntListenPort;dnsListenPort;logLevel;logPath;route;dns},Ft=class{domain;domainRegex;domainKeyword;domainSuffix;ipCidr;network;protocol;port;portRange;ipVersion;ruleSet;geoIp;geoSite;constructor(){this.domain=[],this.domainRegex=[],this.domainKeyword=[],this.domainSuffix=[],this.ruleSet=[],this.ipCidr=[],this.geoIp=[],this.geoSite=[],this.network=[],this.protocol=[],this.port=[],this.portRange=[]}containDomain(){return this.domain.length>0||this.domainRegex.length>0||this.domainSuffix.length>0||this.domainKeyword.length>0}containGeo(){return this.geoSite.length>0||this.geoIp.length>0}containRuleSet(){return this.ruleSet.length>0}containIp(){return this.ipCidr.length>0||this.geoIp.length>0}isEmpty(t){return!(this.containDomain()||this.containIp()||t==="geo"&&this.containGeo()||t==="set"&&this.containRuleSet()||this.network.length>0||this.port.length>0||this.portRange.length>0||this.protocol.length>0)}},Mt=class{name;type="load_balance";core=N.SING_BOX;enabled="1";listen_port;socks_port;member_node;procd_env;log_level;log_path;url;interval;tolerance;idle_timeout;interrupt_exist_connections;strategy;strategy_expected;strategy_max_rtt;strategy_tolerance;fallback_tag;probe_url;probe_connectivity;probe_interval;probe_timeout;probe_sampling;probe_http_method;constructor(){this.member_node=[],this.procd_env=[]}},Yt=class{name;type="custom";enabled="1";command;listen_port;socks_port;procd_env;log_enabled;log_path;constructor(){this.type="custom",this.enabled="1",this.procd_env=[]}},Bt=class{name;type="hysteria2";enabled="1";core;server;server_port;server_ports;hop_interval;obfs_type;obfs_password;brutal_debug;udp_idle_timeout;up_mbps;down_mbps;password;network;tls_server_name;tls_insecure;listen_port;socks_port;procd_env;log_path;constructor(){this.type="hysteria2",this.enabled="1",this.core=N.SING_BOX,this.server_ports=[],this.network="",this.brutal_debug="0",this.tls_insecure="0"}},Vt=class{name;type="shadowsocks";enabled="1";core;server;server_port;method;password;plugin;plugin_opts;network;udp_over_tcp;listen_port;socks_port;multiplex_enabled;multiplex_protocol;multiplex_max_connections;multiplex_min_streams;multiplex_max_streams;multiplex_brutal_enabled;multiplex_brutal_up_mbps;multiplex_brutal_down_mbps;procd_env;log_path;constructor(){this.type="shadowsocks",this.enabled="1",this.core=N.SING_BOX,this.network="",this.udp_over_tcp="0",this.multiplex_enabled="0",this.multiplex_protocol="h2mux",this.multiplex_brutal_enabled="0"}},Gt=class{name;type="tuic";enabled="1";core;server;server_port;uuid;password;congestion_control;udp_relay_mode;udp_over_stream;zero_rtt_handshake;heartbeat;network;tls_server_name;tls_insecure;listen_port;socks_port;procd_env;log_path;constructor(){this.type="tuic",this.enabled="1",this.core=N.SING_BOX,this.congestion_control="cubic",this.udp_relay_mode="",this.udp_over_stream="0",this.zero_rtt_handshake="0",this.heartbeat="10s",this.network="",this.tls_insecure="0"}},Ht=class{name;type="shadowtls";enabled="1";core;server;server_port;version;password;tls_server_name;tls_insecure;listen_port;socks_port;procd_env;log_path;constructor(){this.type="shadowtls",this.enabled="1",this.core=N.SING_BOX,this.version="1",this.tls_insecure="0"}},jt=class{name;type="vless";enabled="1";core;server;server_port;uuid;flow;network;packet_encoding;tls_server_name;tls_insecure;tls_reality_enabled;tls_reality_public_key;tls_reality_short_id;listen_port;socks_port;multiplex_enabled;multiplex_protocol;multiplex_max_connections;multiplex_min_streams;multiplex_max_streams;multiplex_brutal_enabled;multiplex_brutal_up_mbps;multiplex_brutal_down_mbps;transport_type;transport_http_host;transport_http_path;transport_http_method;transport_http_idle_timeout;transport_http_ping_timeout;transport_ws_host;transport_ws_path;transport_ws_max_early_data;transport_ws_early_data_header_name;transport_grpc_service_name;transport_grpc_idle_timeout;transport_grpc_ping_timeout;transport_grpc_permit_without_stream;transport_httpupgrade_host;transport_httpupgrade_path;transport_xhttp_host;transport_xhttp_path;transport_xhttp_mode;procd_env;log_path;constructor(){this.type="vless",this.enabled="1",this.core=N.XRAY,this.network="tcp",this.packet_encoding="",this.tls_insecure="0",this.tls_reality_enabled="0",this.multiplex_enabled="0",this.multiplex_protocol="h2mux",this.multiplex_brutal_enabled="0",this.transport_type="",this.transport_http_idle_timeout="15s",this.transport_http_ping_timeout="15s",this.transport_grpc_idle_timeout="15s",this.transport_grpc_ping_timeout="15s",this.transport_grpc_permit_without_stream="0",this.transport_xhttp_path="/",this.transport_xhttp_mode="auto"}};var $={camelToSnake:function(e){return e.replace(/([A-Z])/g,function(t){return"_"+t.toLowerCase()})},transFromUci:function(e,t){Object.keys(e).forEach(r=>{let n=$.camelToSnake(r);t[n]&&(e[r]=t[n])})},generateUniqueSectionId:function(e="hijpass"){let t="abcdefghijklmnopqrstuvwxyz0123456789",r="";for(;;){r="";for(let n=0;n<8;n++)r+=t.charAt(Math.floor(Math.random()*t.length));if(!a.get(e,r))break}return r}};function Me(e,t){let r=e.substring(t==="remote"?16:15),n=r.split("/").pop(),o=n.substring(0,n.lastIndexOf("."))||n,s=(t==="remote"?r:n).endsWith("srs")?"binary":"source";return{tag:o,type:t,format:s,pathOrUrl:r}}var w={getShuntSection:function(){let e=new It,t=a.get_first("hijpass","shunt");return $.transFromUci(e,t),e.dns=w.getDnsSection(),e.route=w.getRouteSection(),e},getRouteSection:function(){let e=a.get_first("hijpass","shunt"),t=new kt;return $.transFromUci(t,e),a.sections("hijpass","shunt_route_rule",function(r){let n=new at;$.transFromUci(n,r),t.rules.push(n)}),t},getRouteRuleVariants:function(e){if(e.ipVersionSplit!=="1")return[{rule:e,proxyNode:e.proxyNode}];let t=[];if(e.proxyNodeV4){let r=Object.assign(new at,e);r.name=e.name?e.name+"-ipv4":e.name,r.proxyNode=e.proxyNodeV4,t.push({rule:r,proxyNode:e.proxyNodeV4,ipVersion:4})}if(e.proxyNodeV6){let r=Object.assign(new at,e);r.name=e.name?e.name+"-ipv6":e.name,r.proxyNode=e.proxyNodeV6,t.push({rule:r,proxyNode:e.proxyNodeV6,ipVersion:6})}return t},getDnsSection:function(){let e=a.get_first("hijpass","shunt"),t=new Ut;return t.nodes=[],$.transFromUci(t,e),a.sections("hijpass","shunt_dns_node",function(r){if(r.enabled==="0")return;let n=new Lt;$.transFromUci(n,r),t.nodes.push(n)}),t},parseRuleList:function(e){let t=new Ft,r=e.domainList,n=e.ipList;if(t.network=e.network?e.network:[],t.protocol=e.protocol?e.protocol:[],e.port&&(t.port=e.port.map(o=>parseInt(o,10)).filter(o=>!isNaN(o))),e.portRange&&(t.portRange=e.portRange.map(o=>o.replace("-",":")).filter(o=>o.length>0)),r&&r.trim()!==""){let o=r.split(`
|
|
`);for(let s of o)if(s=s.trim(),!(s===""||s.startsWith("#"))){if(s.startsWith("rule-set:")){let i=s.startsWith("rule-set:remote:")?"remote":"local",l=Me(s,i);t.ruleSet.push(l);continue}s.startsWith("regexp:")?t.domainRegex.push(s.substring(7)):s.startsWith("domain:")?t.domainSuffix.push(s.substring(7)):s.startsWith("full:")?t.domain.push(s.substring(5)):s.startsWith("geosite:")?t.geoSite.push(s):t.domainKeyword.push(s)}}if(n&&n.trim()!==""){let o=n.split(`
|
|
`);for(let s of o)if(s=s.trim(),!(s===""||s.startsWith("#"))){if(s.startsWith("rule-set:")){let i=s.startsWith("rule-set:remote:")?"remote":"local",l=Me(s,i);t.ruleSet.push(l);continue}s.startsWith("geoip:")?t.geoIp.push(s):t.ipCidr.push(s)}}return t}};var he=3,Xt="lb-member-";function Ye(e){return e?.name||e?.[".name"]||""}function ye(e){return q(e?.core||N.SING_BOX)}function be(e){if(!e)return!1;let t=Number(e);return Number.isInteger(t)&&t>0&&t<=65535}function Be(){let e=[];return a.sections("hijpass","proxy_node",function(t){e.push(t)}),e}function xe(){let e=new Map;return Be().forEach(t=>{let r=Ye(t);r&&e.set(r,t)}),e}function Ve(e){return"upstream-"+e}function Ne(e){return e?(Array.isArray(e)?e:[e]).filter(t=>!!t):[]}function Ge(e){return Xt+e}function Fr(e,t=xe()){let r=Ne(e.member_node);if(r.length===0)throw new Error("Load balancing node has no members: "+e.name);return r.map((n,o)=>{if(n===e.name)throw new Error("Load balancing node cannot include itself: "+n);let s=t.get(n);if(!s)throw new Error("Load balancing member node not found: "+n);if(s.type===S.LOAD_BALANCE)throw new Error("Nested load balancing members are not supported: "+n);if(s.enabled!=="1")throw new Error("Load balancing member node disabled: "+n);if(!be(s.socks_port))throw new Error("Load balancing member node SOCKS port invalid: "+n);return{name:n,socksPort:Number(s.socks_port),tag:Ge(o),core:ye(s),section:s}})}function Mr(e,t=xe()){let r=e.upstream_proxy_node;if(!r)return;if(r===e.name)throw new Error("Upstream proxy node cannot be itself: "+r);let n=t.get(r);if(!n)throw new Error("Upstream proxy node not found: "+r);if(n.enabled!=="1")throw new Error("Upstream proxy node disabled: "+r);if(!be(n.socks_port))throw new Error("Upstream proxy node SOCKS port invalid: "+r);return{name:r,socksPort:Number(n.socks_port),tag:Ve(r),core:ye(n),section:n}}function Yr(e,t){let r=[],n=new Set,o=e;for(;o;){if(n.has(o))return r.push(o),{chain:r,cycle:!0};n.add(o),r.push(o);let s=t.get(o);if(!s||!s.upstream_proxy_node)break;o=s.upstream_proxy_node}return{chain:r,cycle:!1}}function He(e){let t=[];return e?.type===S.LOAD_BALANCE?t.push(...Ne(e.member_node)):e?.upstream_proxy_node&&t.push(e.upstream_proxy_node),t}function Br(e){let t=new Set,r=new Set,n=[];function o(s){if(r.has(s)){let l=n.indexOf(s);return n.slice(l).concat(s)}if(t.has(s))return;let i=e.get(s);if(!(!i||i.enabled!=="1")){r.add(s),n.push(s);for(let l of He(i)){let p=o(l);if(p)return p}n.pop(),r.delete(s),t.add(s)}}for(let s of e.keys()){let i=o(s);if(i)return i}}var R={getProxyName:Ye,getProxyCore:ye,getProxySections:Be,getProxySectionMap:xe,isPort:be,getUpstreamProxyOutboundTag:Ve,normalizeProxyNodeList:Ne,getLoadBalanceMemberOutboundTag:Ge,resolveUpstreamProxy:Mr,resolveLoadBalanceMembers:Fr,collectProxyChain:Yr,getProxyDependencies:He,findProxyDependencyCycle:Br};var mt={genShuntConf:Vr,genProxyConf:Gr,writeGeoRule:Xr};function Vr(){let e=w.getShuntSection();if(!e)return;let t=new Map,r=new Map,n=e.dns,o=e.route,s=new Ct(ft(o.defaultProxyNode),n.defaultDnsNode),i=new St(n.defaultDnsNode,qe(n.defaultStrategy),n.useCache==="1");n.nodes.forEach(function(u){let g=new gt(u.type,u.tag,u.server,parseInt(u.port,10),void 0);t.set(u.tag,g)});let l=[new Dt("direct-out"),new Rt("block")];a.sections("hijpass","proxy_node",function(u){u.enabled==="1"&&l.push(new ot("127.0.0.1",Number(u.socks_port),u.name))});let p=[new nt(parseInt(e.shuntListenPort,10),"tproxy-in"),new Pt(parseInt(e.dnsListenPort,10),"dns-in")];if(s.default_domain_resolver&&s.final){let u=t.get(s.default_domain_resolver);if(!u)throw new Error(_('Default global DNS "%s" does not exist').format(s.default_domain_resolver));i.servers.push(Se(u.tag,s.final,u))}if(o.rulesetOutNode){let u=ft(o.rulesetOutNode),g=l.find(b=>b.tag===u);if(g){let b=structuredClone(g);if(b.tag="ruleset-out",n.rulesetDnsNode){b.domain_resolver="ruleset-dns-resolver";let f=t.get(n.rulesetDnsNode);if(!f)throw new Error(_('%s "%s" does not exist').format(_("Rule-set DNS"),n.rulesetDnsNode));i.servers.push(Se("ruleset-dns-resolver","ruleset-out",f))}l.push(b)}}return o.rules.forEach(function(u){if(u.enabled!=="1")return;let g=u.ipVersionSplit==="1",b,f=!1;if(w.getRouteRuleVariants(u).forEach(function(m){let c=w.parseRuleList(m.rule),h=Qr(c,o.rulesetConvert);if(c.ipVersion=m.ipVersion,o.rulesetConvert==="1")qr(c);else if(c.containGeo()&&(Kr(c),!zr(c)))return;if(c.isEmpty("set"))return;for(let T of c.ruleSet)r.set(T.tag,Wr(T,o.rulesetOutNode?"ruleset-out":void 0));let v="route",F=ft(m.proxyNode);if(m.proxyNode==="hijpass-block"&&(v="reject",F=void 0),s.rules.push(new rt(v,F).initRule(c)),v!=="reject"){if(g){h&&(b=b||c,f=!0);return}(c.containDomain()||c.containIp()||c.containRuleSet())&&je(u,m.rule.name,c,ft(u.dnsProxyNode)||F,t,s,i)}}),g&&f&&b){let m=ft(u.dnsProxyNode);if(!m)throw new Error(_('Route rule "%s" uses IPv4/IPv6 split and must specify a DNS exit node').format(u.name));je(u,u.name,b,m,t,s,i)}}),r.forEach(u=>s.rule_set.push(u)),{log:new et(e.logLevel),inbounds:p,outbounds:l,dns:i,route:s}}function Gr(e){if(e.type===S.LOAD_BALANCE)return Hr(e);let t=Y.build(e.type,e),r=[t];return jr(e,t,r),{log:new et(e.log_level),dns:{servers:[{type:"local",tag:"local"}]},inbounds:[new nt(Number(e.listen_port),"tproxy-in","127.0.0.1"),new _t(Number(e.socks_port),"socks-in","127.0.0.1")],outbounds:r}}function Hr(e){let t=R.resolveLoadBalanceMembers(e),r=new At("slb",e.url||void 0,e.interval||void 0,e.tolerance?parseInt(e.tolerance,10):void 0,e.idle_timeout||void 0,e.interrupt_exist_connections==="1"?!0:void 0);return r.outbounds=t.map(n=>n.tag),{log:new et(e.log_level),dns:{servers:[{type:"local",tag:"local"}]},inbounds:[new nt(Number(e.listen_port),"tproxy-in","127.0.0.1"),new _t(Number(e.socks_port),"socks-in","127.0.0.1")],outbounds:[r,...t.map(n=>new ot("127.0.0.1",n.socksPort,n.tag))],route:{final:"slb"}}}function jr(e,t,r){let n=R.resolveUpstreamProxy(e);n&&(t.detour=n.tag,r.push(new ot("127.0.0.1",n.socksPort,n.tag)))}function Xr(){let e=w.getRouteSection(),t=new Set,r=new Set;for(let l of e.rules){if(l.enabled!=="1")continue;let p=w.parseRuleList(l);for(let u of p.geoSite)t.add(u.replace("geosite:",""));for(let u of p.geoIp)r.add(u.replace("geoip:",""))}let n=[...t],o=[...r],s=a.get_first("hijpass","shunt","geoip_ruleset")??[],i=a.get_first("hijpass","shunt","geosite_ruleset")??[];o.length>0?We(s,o)||a.set_first("hijpass","shunt","geoip_ruleset",o):a.set_first("hijpass","shunt","geoip_ruleset",void 0),n.length>0?We(i,n)||a.set_first("hijpass","shunt","geosite_ruleset",n):a.set_first("hijpass","shunt","geosite_ruleset",void 0)}function Se(e,t,r){return new gt(r.type,e,r.server,r.server_port,t)}function Wr(e,t){return e.type==="remote"?new Ot(e.tag,e.format,e.pathOrUrl,t,void 0):new wt(e.tag,e.format,e.pathOrUrl)}function qe(e){switch(e){case"4":return"ipv4_only";case"6":return"ipv6_only";case"64":return"prefer_ipv6";case"46":return"prefer_ipv4";default:return}}function je(e,t,r,n,o,s,i){let l=e.dnsNode,p=l?o.get(l):o.get(s.default_domain_resolver);if(!p)throw new Error(_('Route rule "%s" DNS node "%s" does not exist').format(e.name||t,e.dnsNode||s.default_domain_resolver||""));i.servers.push(Se(Xe(t),n,p)),i.rules.push(new Et("route",Xe(t),qe(e.dnsStrategy)).initRule(r))}function ft(e){return e==="hijpass-block"?"block":e==="hijpass-direct"?"direct-out":e}function Xe(e){return e+"-dns"}function qr(e){e.ruleSet=[];for(let t of e.geoSite){let r=t.replace("geosite:","geosite-");e.ruleSet.push({tag:r,type:"local",format:"binary",pathOrUrl:"/etc/hijpass/ruleset/"+r+".srs"})}for(let t of e.geoIp){let r=t.replace("geoip:","geoip-");e.ruleSet.push({tag:r,type:"local",format:"binary",pathOrUrl:"/etc/hijpass/ruleset/"+r+".srs"})}}function Kr(e){e.geoSite=[],e.geoIp=[]}function zr(e){return e.containDomain()||e.containIp()||e.containRuleSet()}function Qr(e,t){return e.containDomain()||e.containRuleSet()||t==="1"&&e.geoSite.length>0}function We(e,t){return!e||!t?!1:e.length===t.length&&e.every((r,n)=>r===t[n])}var ve=class{protocols=new Map;register(t){this.protocols.set(t.type,t)}build(t,r){let n=this.protocols.get(t);if(!n)throw new Error(`Unsupported xray protocol: ${t}`);return n.build(r)}},K=new ve;var Ee=class{settings;protocol;tag;streamSettings;constructor(t,r,n,o,s,i,l,p){this.protocol="hysteria",this.tag=n,this.settings={version:2,address:t,port:r},this.streamSettings={network:"hysteria",security:"tls",tlsSettings:{serverName:s,alpn:["h3"]},hysteriaSettings:{version:2,auth:o,...i!==void 0?{udpIdleTimeout:i}:{}},...l||p?{finalmask:{quicParams:{...l?{brutalUp:l}:{},...p?{brutalDown:p}:{}}}}:{}}}};function Ke(e){let t=(e||"").trim();if(t)return t==="0"?"0":t+" mbps"}var $r={type:"hysteria2",build(e){let t=e,r=t.udp_idle_timeout?Number(t.udp_idle_timeout):void 0,n=Ke(t.up_mbps),o=Ke(t.down_mbps);return new Ee(t.server,Number(t.server_port),t.name,t.password||"",t.tls_server_name||t.server,r,n,o)}};K.register($r);var Te=class{settings;protocol;tag;constructor(t,r,n,o,s,i){this.protocol="shadowsocks",this.tag=n,this.settings={address:t,port:r,method:o,password:s,uot:i||void 0,level:0}}},Jr={type:"shadowsocks",build(e){let t=e;return new Te(t.server,Number(t.server_port),t.name,t.method,t.password,t.udp_over_tcp==="1"?!0:void 0)}};K.register(Jr);var Oe=class{settings;protocol;tag;streamSettings;constructor(t,r,n,o,s="none",i,l=0){this.protocol="vless",this.tag=o,this.settings={address:t,port:r,id:n,encryption:s,level:l},i&&(this.settings.flow=i)}};function qt(e){let t=(e||"").trim();if(!t)return;let r=t.match(/^(\d+)(?:s)?$/);if(!r)return;let n=Number(r[1]);return Number.isFinite(n)&&n>0?n:void 0}function Zr(e,t){let r=(t||"").trim();if(!r)return e;let n=e||"/",o=n.indexOf("#"),s=o>=0?n.slice(0,o):n,i=o>=0?n.slice(o):"",l=s.indexOf("?")>=0?"&":"?";return s+l+"ed="+encodeURIComponent(r)+i}var tn={type:"vless",build(e){let t=e,r=new Oe(t.server,Number(t.server_port),t.uuid,t.name,"none",t.flow||void 0,0),n=t.tls_reality_enabled==="1",o=n?{fingerprint:"chrome",serverName:t.tls_server_name||t.server,password:t.tls_reality_public_key||"",shortId:t.tls_reality_short_id||""}:void 0,s=n?void 0:{alpn:["h2","http/1.1"],serverName:t.tls_server_name||t.server},i=n?"reality":t.tls_server_name?"tls":"none",l={network:"raw",security:i};switch(o&&(l.realitySettings=o),s&&i==="tls"&&(l.tlsSettings=s),t.transport_type||""){case"xhttp":l.network="xhttp",l.xhttpSettings={host:t.transport_xhttp_host||void 0,path:t.transport_xhttp_path||"/",mode:t.transport_xhttp_mode||"auto"};break;case"ws":l.network="websocket",l.wsSettings={host:t.transport_ws_host||void 0,path:Zr(t.transport_ws_path||"/",t.transport_ws_max_early_data)};break;case"grpc":l.network="grpc",l.grpcSettings={serviceName:t.transport_grpc_service_name||"TunService",...qt(t.transport_grpc_idle_timeout)?{idle_timeout:qt(t.transport_grpc_idle_timeout)}:{},...qt(t.transport_grpc_ping_timeout)?{health_check_timeout:qt(t.transport_grpc_ping_timeout)}:{},...t.transport_grpc_permit_without_stream==="1"?{permit_without_stream:!0}:{}};break;case"http":l.network="xhttp",l.xhttpSettings={...t.transport_http_host?{host:t.transport_http_host}:{},path:t.transport_http_path||"/",mode:"stream-one",...t.transport_http_method?{uplinkHTTPMethod:t.transport_http_method}:{}};break;case"httpupgrade":l.network="httpupgrade",l.httpupgradeSettings={host:t.transport_httpupgrade_host||void 0,path:t.transport_httpupgrade_path||"/"};break}return r.streamSettings=l,r}};K.register(tn);var lt=class{loglevel;dnsLog;constructor(t){this.loglevel=t||"info",this.dnsLog=!1}},Kt=class{tag;address;port;queryStrategy;domains;skipFallback;disableCache;constructor(t,r,n,o){switch(t){case"tcp":this.address="tcp://"+n,this.port=o;break;case"https":this.address="https://"+n,o&&(this.address+=":"+o),this.address+="/dns-query";break;case"quic":this.address="quic://"+n,this.port=o;break;case"udp":this.address=n,this.port=o;break;default:throw new Error("Invalid xray DNS server type: "+t)}this.tag=r,this.domains=[],this.skipFallback=!0}},zt=class{servers;rules;queryStrategy;disableCache;serveStale;serveExpiredTTL;disableFallback;disableFallbackIfMatch;constructor(t,r){this.servers=[],this.rules=[],this.queryStrategy=t||"UseIP",this.disableCache=!r,this.serveStale=!r,this.serveExpiredTTL=3600,this.disableFallback=!1,this.disableFallbackIfMatch=!0}},ut=class{ruleTag;inboundTag;outboundTag;balancerTag;constructor(t,r,n){this.ruleTag=t,this.inboundTag=r,n==="slb"?this.balancerTag=n:this.outboundTag=n}},Qt=class extends ut{domain;network;ip;protocol;port;constructor(t,r){super(t,void 0,r),this.inboundTag=["tproxy-in"],this.domain=[],this.network=[],this.ip=[],this.protocol=[]}},ht=class extends ut{constructor(t,r){super(void 0,t,r)}},yt=class{rules;domainStrategy;balancers;constructor(){this.rules=[],this.domainStrategy="AsIs",this.balancers=[]}},$t=class{settings;protocol;tag;streamSettings;constructor(t){this.protocol="blackhole",this.tag=t}},pt=class{settings;protocol;tag;constructor(t,r,n){this.protocol="socks",this.tag=n,this.settings={address:t,port:r}}},Jt=class{settings;protocol;tag;constructor(t){this.protocol="dns",this.tag=t,this.settings={rules:[{action:"hijack",qType:"1,28"},{action:"return",rCode:5}]}}},bt=class{settings;protocol;tag;constructor(t){this.protocol="freedom",this.tag=t,this.settings={domainStrategy:"UseIP"}}},Zt=class{tag;selector;fallbackTag;strategy;constructor(t){this.tag=t,this.selector=[],this.fallbackTag=void 0,this.strategy={type:"leastLoad",settings:{expected:1,maxRTT:"1s",tolerance:.05}}}},te=class{subjectSelector;pingConfig;constructor(t,r,n,o,s,i){this.subjectSelector=[],this.pingConfig={destination:t||"https://connectivitycheck.gstatic.com/generate_204",connectivity:r||void 0,interval:n||"60s",timeout:o||"2s",sampling:s||3,httpMethod:i||void 0}}},J=class{protocol;tag;listen;port;settings;streamSettings;sniffing;constructor(t,r,n,o){this.protocol="dokodemo-door",this.tag=n,this.listen=o,this.port=r,this.settings={network:"tcp,udp",followRedirect:void 0},t==="tproxy"&&(this.settings.followRedirect=!0,this.streamSettings={sockopt:{tproxy:"tproxy"}},this.sniffing={enabled:!0,destOverride:["http","tls","quic"],routeOnly:!0})}};var Ce={genShuntConf:rn,genProxyConf:nn};function rn(){let e=w.getShuntSection(),t=new Map,r=new yt,n=e.dns,o=new zt(Ze(n.defaultStrategy),n.useCache==="1");n.nodes.forEach(function(c){let h=new Kt(c.type,c.tag,c.server,Number(c.port));t.set(c.tag,h)});let s=e.route,i=[];a.sections("hijpass","proxy_node",function(c){if(c.enabled==="1"){let h=new pt("127.0.0.1",Number(c.socks_port),ee(c.name));c.name===s.defaultProxyNode?i.unshift(h):i.push(h)}}),s.defaultProxyNode==="hijpass-direct"?i.unshift(new bt("direct-out")):i.push(new bt("direct-out")),i.push(new $t("block")),i.push(new Jt("dns-out"));let l=[new J("tproxy",parseInt(e.shuntListenPort,10),"tproxy-in"),new J("direct",parseInt(e.dnsListenPort,10),"dns-in","::")],p=[new ht(["dns-in"],"dns-out")],u=[],g=t.get(n.defaultDnsNode);if(!g)throw new Error(_('Default global DNS "%s" does not exist').format(n.defaultDnsNode||""));let b=new Map;s.rules.forEach(function(c){if(c.enabled!=="1")return;let h=c.ipVersionSplit==="1",v,F=!1;if(w.getRouteRuleVariants(c).forEach(function(T){let X=ee(T.proxyNode)||i[0].tag,G=w.parseRuleList(T.rule),U=pn(G);if(G.ipVersion=T.ipVersion,!un(G)&&(cn(T.rule.name,X,G).forEach(z=>{u.push(z)}),X!=="block")){if(h){U&&(v=v||G,F=!0);return}if(U){let z=ee(c.dnsProxyNode)||X;ze(c,T.rule.name,z,G,t,g,o,b)}}}),h&&F&&v){let T=ee(c.dnsProxyNode);if(!T)throw new Error(_('Route rule "%s" uses IPv4/IPv6 split and must specify a DNS exit node').format(c.name));ze(c,c.name,T,v,t,g,o,b)}});let f=structuredClone(g);return f.tag=$e("default"),f.skipFallback=!1,o.servers.push(f),b.forEach((c,h)=>p.push(new ht(c,h))),r.rules=r.rules.concat(p),r.rules=r.rules.concat(u),{log:new lt(Pe(e.logLevel)),inbounds:l,outbounds:i,dns:o,routing:r}}function nn(e){if(e.type===S.LOAD_BALANCE)return sn(e);let t=K.build(e.type,e);return on(e,t)}function on(e,t){let r=Qe(e),n=[t];return an(e,t,n),{log:new lt(Pe(e.log_level)),inbounds:r,outbounds:n}}function Qe(e){let t=new J("tproxy",Number(e.listen_port),"tproxy-in");t.sniffing=void 0;let r=new J("direct",Number(e.socks_port),"socks-in");return r.settings={udp:!0},r.protocol="socks",[t,r]}function sn(e){let t=R.resolveLoadBalanceMembers(e),r=new yt;r.rules.push(new ut(void 0,["tproxy-in","socks-in"],"slb"));let n=new Zt("slb");n.selector=[Xt];let o=t.find(p=>p.name===e.fallback_tag)||t[0];n.fallbackTag=o.tag;let s=e.strategy||"leastLoad";n.strategy.type=s,s==="leastLoad"?(e.strategy_expected&&(n.strategy.settings.expected=parseInt(e.strategy_expected,10)),e.strategy_max_rtt&&(n.strategy.settings.maxRTT=e.strategy_max_rtt),e.strategy_tolerance&&(n.strategy.settings.tolerance=parseFloat(e.strategy_tolerance))):n.strategy.settings=void 0,r.balancers.push(n);let i=new te(e.probe_url||void 0,e.probe_connectivity||void 0,e.probe_interval||void 0,e.probe_timeout||void 0,e.probe_sampling?parseInt(e.probe_sampling,10):void 0,e.probe_http_method||void 0);i.subjectSelector=[Xt];let l=t.map(p=>new pt("127.0.0.1",p.socksPort,p.tag));return{log:new lt(Pe(e.log_level)),inbounds:Qe(e),outbounds:l,routing:r,burstObservatory:i}}function Pe(e){return e==="warn"?"warning":e}function an(e,t,r){let n=R.resolveUpstreamProxy(e);n&&(ln(t,n.tag),r.push(new pt("127.0.0.1",n.socksPort,n.tag)))}function ln(e,t){e.streamSettings=e.streamSettings||{},e.streamSettings.sockopt=e.streamSettings.sockopt||{},e.streamSettings.sockopt.dialerProxy=t,e.streamSettings.sockopt.domainStrategy="UseIP"}function $e(e){return e+"-dns"}function un(e){return e.isEmpty("geo")?!0:e.containRuleSet()&&!e.containDomain()&&!e.containIp()&&!e.containGeo()}function pn(e){return e.containDomain()||e.geoSite.length>0}function ze(e,t,r,n,o,s,i,l){let p=$e(t);l.has(r)?l.get(r).push(p):l.set(r,[p]);let u=e.dnsNode?o.get(e.dnsNode):s;if(!u)throw new Error(_('Route rule "%s" DNS node "%s" does not exist').format(e.name||t,e.dnsNode||""));let g=structuredClone(u);g.tag=p,g.queryStrategy=Ze(e.dnsStrategy),g.domains=Je(n),i.servers.push(g)}function cn(e,t,r){let n=new Qt(e,t);n.network=r.network,n.protocol=fn(r.protocol);let o=r.port.map(l=>String(l));r.portRange&&r.portRange.length>0&&(o=o.concat(r.portRange)),n.port=o.join(","),n.domain=Je(r),n.domain=n.domain.length>0?n.domain:void 0,n.ip=dn(r),n.ip=n.ip.length>0?n.ip:void 0;let s=[],i=_n(r.ipVersion);if(n.domain){let l=structuredClone(n);i?l.ip=[i]:l.ip=void 0,s.push(l)}if(n.ip){let l=structuredClone(n);l.domain=void 0,s.push(l)}return!n.domain&&!n.ip&&(i&&(n.ip=[i]),s.push(n)),s}function Je(e){let t=[we(e.domain,"full:"),we(e.domainSuffix,"domain:"),e.domainKeyword,we(e.domainRegex,"regexp:"),e.geoSite];return[].concat(...t.filter(r=>Array.isArray(r)&&r.length>0))}function dn(e){let t=[gn(e.ipCidr,e.ipVersion),e.geoIp];return[].concat(...t.filter(r=>Array.isArray(r)&&r.length>0))}function gn(e,t){return!t||!Array.isArray(e)?e||[]:e.filter(r=>{let n=r.replace(/^!/,"");return n.startsWith("geoip:")||n.startsWith("ext:")?!0:n.indexOf(":")>=0?t===6:/^\d{1,3}(\.\d{1,3}){3}(\/\d+)?$/.test(n)?t===4:!0})}function _n(e){if(e===4)return"0.0.0.0/0";if(e===6)return"::/0"}function ee(e){return e==="hijpass-block"?"block":e==="hijpass-direct"?"direct-out":e}function Ze(e){switch(e){case"4":return"UseIPv4";case"6":return"UseIPv6";case"64":case"46":return"UseIP";default:return}}function fn(e){if(!e)return;let t=e.map(r=>{switch(r){case"http":case"tls":case"quic":case"bittorrent":return r;default:throw new Error("Unsupported xray rule protocol: "+r)}}).filter(r=>r!==void 0);return t.length===0?void 0:t}function we(e,t){return Array.isArray(e)?e.map(r=>t+r):[]}var k=N,tr={getCoreAdapter:function(e){switch(q(e)){case k.SING_BOX:return mt;case k.XRAY:return Ce;default:throw new Error("Unsupported core: "+e)}}},Re={genProxyConf:function(e,t){switch(q(e)){case k.SING_BOX:return mt.genProxyConf(t);case k.XRAY:return Ce.genProxyConf(t);default:throw new Error("Unsupported core: "+e)}}};var mn={hijpass:{client_dir:"/etc/hijpass/client",shunt_conf:"/etc/hijpass/shunt.json",ip_direct:"/etc/hijpass/rules/ip-direct.txt",ip_proxy:"/etc/hijpass/rules/ip-proxy.txt",domain_direct:"/etc/hijpass/rules/domain-direct.txt",domain_proxy:"/etc/hijpass/rules/domain-proxy.txt",nft:"/etc/hijpass/fw4-template.nft",nft_hook:"/etc/hijpass/hook/nft-hook.sh",dns_hook:"/etc/hijpass/hook/dns-hook.sh"},hijserver:{server_dir:"/etc/hijpass/server"}};function hn(e){let t=(e||"").trim().replace(/\r\n/g,`
|
|
`);return t?t+`
|
|
`:""}function De(e,t="hijpass"){let r=a.get_first(t,t,e);if(r)return r;let n=mn[t]?.[e];return n||(console.log(e+" path is empty"),"")}function yn(e,t,r,n){if(!t)throw new Error(_("Configuration file directory is empty"));let s=n?.section?.formvalue?.(r,"name")||a.get(e,r,"name")||r;return t+"/"+s+"-"+r+".json"}function bn(e){let t=e.name||e[".name"];return De("client_dir")+"/"+t+"-"+e[".name"]+".json"}function xn(e){let t=e.name||e[".name"];return De("server_dir","hijserver")+"/"+t+"-"+e[".name"]+".json"}var D={normalizeFileContent:hn,getFilePath:De,getNodeConfigFilePath:yn,getProxyConfigFilePath:bn,getServerConfigFilePath:xn};async function Nn(e){async function t(r,n,o){let s=o?[r,n,o]:[r,n];await O.exec("/usr/lib/hijpass/rm.sh",s)}if(e?.hijpass){for(let r of e.hijpass)if(r.length===2&&r[0]==="remove"&&await t("proxy",r[1]),r.length===4&&r[0]==="set"&&r[2]==="name"){let n=a.get("hijpass",r[1]),o=n?D.getProxyConfigFilePath(n):void 0;await t("proxy",r[1],o)}}if(e?.hijserver){for(let r of e.hijserver)if(r.length===2&&r[0]==="remove"&&await t("server",r[1]),r.length===4&&r[0]==="set"&&r[2]==="name"){let n=a.get("hijserver",r[1]),o=n?D.getServerConfigFilePath(n):void 0;await t("server",r[1],o)}}}var er={cleanupChangedNodeFiles:Nn};function Sn(e,t){if(!(Array.isArray(t)&&t.length===0)&&t!==null&&!(typeof t=="number"&&!Number.isFinite(t))&&!(typeof t=="string"&&!t.trim()))return t}var re={omitEmptyReplacer:Sn};var ne={getShuntConfData:function(){if(a.get_first("hijpass","shunt","enabled")==="0"||a.get_first("hijpass","shunt","config_type")!=="tmpl")return"";let r=a.get_first("hijpass","shunt","type");return JSON.stringify(tr.getCoreAdapter(r).genShuntConf(),re.omitEmptyReplacer,2)}};var Ae=class{container=null;notifications=new Map;notificationId=0;autoCloseTimers=new Map;constructor(){this.initContainer()}initContainer(){this.container||(this.container=document.createElement("div"),this.container.id="notification-container",this.container.style.cssText=`
|
|
position: fixed;
|
|
top: 20px;
|
|
right: 20px;
|
|
z-index: 9999;
|
|
pointer-events: none;
|
|
`,document.body.appendChild(this.container))}getTypeConfig(t){let r={success:{bgColor:"#4caf50",borderColor:"#45a049",icon:"\u2713",textColor:"#fff"},error:{bgColor:"#f44336",borderColor:"#da190b",icon:"\u2715",textColor:"#fff"},warning:{bgColor:"#ff9800",borderColor:"#e68900",icon:"\u26A0",textColor:"#fff"},info:{bgColor:"#2196f3",borderColor:"#0b7dda",icon:"\u2139",textColor:"#fff"}};return r[t]||r.info}show(t){let{message:r,title:n,content:o,type:s="info",duration:i=3e3,icon:l=!1}=t;this.initContainer();let p=`notification-${++this.notificationId}`,u=this.getTypeConfig(s),g=n||r,b=o,f=document.createElement("div");if(f.id=p,f.style.cssText=`
|
|
background-color: ${u.bgColor};
|
|
border-left: 4px solid ${u.borderColor};
|
|
color: ${u.textColor};
|
|
padding: 16px 20px;
|
|
margin-bottom: 10px;
|
|
border-radius: 4px;
|
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
display: flex;
|
|
align-items: flex-start;
|
|
gap: 12px;
|
|
min-width: 300px;
|
|
max-width: 400px;
|
|
word-break: break-word;
|
|
animation: slideInRight 0.3s ease-out;
|
|
pointer-events: auto;
|
|
transition: all 0.3s ease;
|
|
font-size: 14px;
|
|
font-weight: 500;
|
|
`,l){let h=document.createElement("span");h.style.cssText=`
|
|
font-size: 20px;
|
|
font-weight: bold;
|
|
flex-shrink: 0;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
width: 24px;
|
|
height: 24px;
|
|
margin-top: 2px;
|
|
`,h.textContent=u.icon,f.appendChild(h)}let m=document.createElement("div");if(m.style.cssText=`
|
|
flex: 1;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 4px;
|
|
`,g){let h=document.createElement("div");h.style.cssText=`
|
|
font-weight: 600;
|
|
font-size: 14px;
|
|
line-height: 1.4;
|
|
`,h.textContent=g,m.appendChild(h)}if(b){let h=document.createElement("div");h.style.cssText=`
|
|
font-weight: 400;
|
|
font-size: 13px;
|
|
line-height: 1.4;
|
|
opacity: 0.9;
|
|
white-space: pre-line;
|
|
`,h.textContent=b,m.appendChild(h)}f.appendChild(m);let c=document.createElement("button");if(c.style.cssText=`
|
|
background: none;
|
|
border: none;
|
|
color: ${u.textColor};
|
|
cursor: pointer;
|
|
font-size: 20px;
|
|
padding: 0;
|
|
width: 24px;
|
|
height: 24px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
flex-shrink: 0;
|
|
opacity: 0.7;
|
|
transition: opacity 0.2s;
|
|
`,c.innerHTML="\xD7",c.onmouseover=()=>c.style.opacity="1",c.onmouseout=()=>c.style.opacity="0.7",c.onclick=h=>{h.stopPropagation(),this.remove(p)},f.appendChild(c),this.container.appendChild(f),this.notifications.set(p,f),i>0){let h=setTimeout(()=>{this.remove(p)},i);this.autoCloseTimers.set(p,h),f.onmouseenter=()=>{let v=this.autoCloseTimers.get(p);v&&(clearTimeout(v),this.autoCloseTimers.delete(p))},f.onmouseleave=()=>{if(this.notifications.has(p)){let v=setTimeout(()=>{this.remove(p)},i);this.autoCloseTimers.set(p,v)}}}return p}remove(t){let r=this.notifications.get(t);if(!r)return;let n=this.autoCloseTimers.get(t);n&&(clearTimeout(n),this.autoCloseTimers.delete(t)),r.style.animation="slideOutRight 0.3s ease-in",r.style.opacity="0",setTimeout(()=>{r.remove(),this.notifications.delete(t)},300)}success(t,r){return this.show({message:t,type:"success",duration:r})}error(t,r){return this.show({message:t,type:"error",duration:r})}warning(t,r){return this.show({message:t,type:"warning",duration:r})}info(t,r){return this.show({message:t,type:"info",duration:r})}clear(){this.notifications.forEach((t,r)=>{this.remove(r)})}},vn=new Ae;function rr(){if(document.getElementById("notification-styles"))return;let e=document.createElement("style");e.id="notification-styles",e.textContent=`
|
|
@keyframes slideInRight {
|
|
from {
|
|
transform: translateX(400px);
|
|
opacity: 0;
|
|
}
|
|
to {
|
|
transform: translateX(0);
|
|
opacity: 1;
|
|
}
|
|
}
|
|
|
|
@keyframes slideOutRight {
|
|
from {
|
|
transform: translateX(0);
|
|
opacity: 1;
|
|
}
|
|
to {
|
|
transform: translateX(400px);
|
|
opacity: 0;
|
|
}
|
|
}
|
|
|
|
@media (max-width: 768px) {
|
|
#notification-container {
|
|
left: 10px !important;
|
|
right: 10px !important;
|
|
top: 10px !important;
|
|
}
|
|
|
|
#notification-container > div {
|
|
min-width: auto !important;
|
|
max-width: 100% !important;
|
|
}
|
|
}
|
|
`,document.head.appendChild(e)}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",rr):rr();var Z=vn;var B={show:function(e){return Z.show(e)},success:function(e,t,r){return Z.show({title:e,content:t,type:"success",duration:r})},error:function(e,t,r){return Z.show({title:e,content:t,type:"error",duration:r})},warning:function(e,t,r){return Z.show({title:e,content:t,type:"warning",duration:r})},info:function(e,t,r){return Z.show({title:e,content:t,type:"info",duration:r})},clear:function(){return Z.clear()}};var Le={createProxyConfigFromSection:function(e){let t=e.type,r;switch(t){case S.LOAD_BALANCE:r=new Mt;break;case S.HYSTERIA2:r=new Bt;break;case S.SHADOWSOCKS:r=new Vt;break;case S.TUIC:r=new Gt;break;case S.SHADOWTLS:r=new Ht;break;case S.VLESS:r=new jt;break;case S.CUSTOM:r=new Yt;break;default:return null}return Object.keys(e).forEach(n=>{n!==".type"&&n!==".name"&&n!==".anonymous"&&Reflect.set(r,n,e[n])}),r.cfgid=e[".name"],r}};function En(e){return/^(\d{1,3}\.){3}\d{1,3}$/.test(e)||/^[0-9a-fA-F:]+$/.test(e)}function Tn(e){return Array.isArray(e?.outbounds)?e.outbounds[0]:void 0}function On(e,t){let r=Tn(e);return r?r.server?(r.server=t,!0):r.settings?.address?(r.settings.address=t,!0):r.settings?.servers?.[0]?.address?(r.settings.servers[0].address=t,!0):r.settings?.vnext?.[0]?.address?(r.settings.vnext[0].address=t,!0):!1:!1}async function wn(e,t){if(!e.upstream_proxy_node||!e.server||En(e.server))return;let r=await O.exec_direct("/usr/lib/hijpass/net.sh",["resolve",e.server],"json");if(!r?.address)throw new Error(_("Resolve proxy server failed: %s").format(e.server));if(!On(t,r.address))throw new Error(_("Unsupported proxy config server field: %s").format(e.name||e.server))}async function Cn(){let e=[];if(a.sections("hijpass","proxy_node",r=>{let n=Le.createProxyConfigFromSection(r);if(r.enabled!=="1"||!n||n.type===S.CUSTOM||n.core===k.CUSTOM)return;let o=Re.genProxyConf(n.core,n);e.push(wn(n,o).then(()=>{let s=typeof o=="string"?o:JSON.stringify(o,re.omitEmptyReplacer,2);return O.write(D.getProxyConfigFilePath(r),s)}))}),e.length===0)return;(await Promise.allSettled(e)).forEach(r=>{if(r.status==="rejected")throw new Error(r.reason?.message||String(r.reason))})}function Pn(e){let t=Le.createProxyConfigFromSection(e);if(t)return Re.genProxyConf(t.core,t)}var nr={writeGeneratedProxyConfigs:Cn,generateProxyConfigFromSection:Pn};var d=form;var I={setAnonymousGridSectionMembers:function(e){I.setGridSectionMembers(e),e.anonymous=!0,e.sectiontitle=function(t){return a.get("hijpass",t,"name")||a.get("hijpass",t,"tag")||t}},setGridSectionMembers:function(e){e.anonymous=!1,e.addremove=!0,e.sortable=!0,e.nodescriptions=!0,e.rowcolors=!0},setAnonymousSection:function(e){e.anonymous=!0,e.addremove=!1},simpleHash:function(e){let t=0;e=e||"";for(let r=0;r<e.length;r++)t=(t<<5)-t+e.charCodeAt(r),t|=0;return t},setEditorOptionMembers:function(e,t,r){e.rows=30,e.load=function(o){return O.trimmed(t)};async function n(o,s){let i=String(I.simpleHash(s)),l=a.get("hijpass",o,r);i!==l&&(a.set("hijpass",o,r,i),await O.write(t,(s||"").trim().replace(/\r\n/g,`
|
|
`)+`
|
|
`))}return e.write=n,e.remove=n,e.monospace=!0,e},setConfContentOptionMembers:function(e,t,r){e.monospace=!0,e.rows=20,e.load=async function(n){return L.resolveDefault(O.read(D.getNodeConfigFilePath(t,r,n)),"")},e.write=async function(n,o){let s=D.normalizeFileContent(o);await O.write(D.getNodeConfigFilePath(t,r,n,this),s),a.set(t,n,"custom_conf_hash",String(I.simpleHash(s)))},e.remove=async function(n){await O.write(D.getNodeConfigFilePath(t,r,n,this),""),a.set(t,n,"custom_conf_hash","")}},createTextOption:function(e,t,r,n,o,s){let i=e.taboption(t,d.TextValue,r,n,o);return I.setEditorOptionMembers(i,s,r),i},createLogFlagOption:function(e,t,r){let n=a.get_first(t,t,"log_dir"),o=r?e.taboption(r,d.Flag,"log_enabled",_("Record Logs")):e.option(d.Flag,"log_enabled",_("Record Logs"));return o.modalonly=!0,o.write=function(s,i){let l="shunt.log",p=a.get(t,s,"name");p&&(l=p+"-"+s+".log"),a.set(t,s,"log_path",n+"/"+l)},o.remove=function(s){a.unset(t,s,"log_path")},o.load=function(s){return a.get(t,s,"log_path")?"1":"0"},o.rmempty=!0,o},appendEnabledNodeListenPorts:function(e){a.sections("hijpass","proxy_node",t=>{if(t.listen_port&&t.enabled==="1"){let r=_("Proxy node %s: %s").format(t.name,t.listen_port);e.value(t.listen_port,r)}})},loadProxyNodeOptions:function(e,t=!0){e.load=function(r){return delete this.keylist,delete this.vallist,this.value("hijpass-direct",_("Direct")),t&&this.value("hijpass-block",_("Block")),a.sections("hijpass","proxy_node",function(n){if(n.name&&n.enabled==="1"){let o=n.name;n.socks_port&&(o+=" ("+n.socks_port+")"),this.value(n.name,o)}}.bind(this)),d.ListValue.prototype.load.apply(this,[r])}},getEnabledProxyNodeOptions:function(e=!0){let t=[];return e&&(t.push({value:"hijpass-direct",label:_("Direct")}),t.push({value:"hijpass-block",label:_("Block")})),a.sections("hijpass","proxy_node",r=>{if(r.name&&r.enabled==="1"){let n=r.name;r.socks_port&&(n+=" ("+r.socks_port+")"),t.push({value:r.name,label:n})}}),t}};function ir(e){let t=Number(e);return Number.isInteger(t)&&t>0&&t<=65535}function or(){let e=a.get_first("hijpass","dns"),t=e?.cdg_port||"";return{available:e?.dns_service==="chinadns-ng"&&ir(t),port:t}}function sr(){let e=a.get_first("hijpass","shunt"),t=e?.dns_listen_port||"";return{available:e?.enabled!=="0"&&ir(t),port:t}}function Rn(e,t){let r=e;return t.port&&(r+=": "+t.port),t.available||(r+=" - "+_("Not available")),r}var ct={getSource:function(){return a.get_first("hijpass","firewall","dns_forward")||Q.NONE},getPreRoutingTarget:or,getRoutingTarget:sr,getTargetLabel:Rn,validateSource:function(e){return!e||e===Q.NONE?!0:e===Q.PRE_ROUTING?or().available?!0:_("Independent DNS is unavailable or has no valid listen port"):e===Q.ROUTING?sr().available?!0:_("Core DNS is disabled or has no valid listen port"):_("Unknown DNS forwarding source: %s").format(e)}};var ar=["http","tls","quic","bittorrent"],Dn=["hysteria2","vless"];function An(e){return e?Array.isArray(e)?e.filter(t=>t):[e]:[]}function Ln(e){return e==="hijpass-direct"||e==="hijpass-block"}function V(e,t){return t.length===0?!0:(B.warning(e,t.join(`
|
|
`),8e3),!1)}function Un(){return a.get_first("hijpass","shunt","enabled")!=="0"&&a.get_first("hijpass","shunt","config_type")==="tmpl"}function kn(){let e=new Set;a.sections("hijpass","proxy_node",function(s){s.name&&e.add(s.name)});let t=[];function r(s,i){s&&!Ln(s)&&!e.has(s)&&t.push(i)}let n=a.get_first("hijpass","shunt","default_proxy_node");n?r(n,_('Default global exit "%s" does not exist').format(n)):t.push(_("Default global exit is not configured"));let o=a.get_first("hijpass","shunt","ruleset_out_node");return r(o,_('Rule-set exit "%s" does not exist').format(o)),a.sections("hijpass","shunt_route_rule",function(s){if(s.enabled!=="1")return;let i=s.name||s[".name"];if(s.ip_version_split==="1"){s.proxy_node_v4?r(s.proxy_node_v4,_('Route rule "%s" IPv4 proxy node "%s" does not exist').format(i,s.proxy_node_v4)):t.push(_('Route rule "%s" IPv4 proxy node is not configured').format(i)),s.proxy_node_v6?r(s.proxy_node_v6,_('Route rule "%s" IPv6 proxy node "%s" does not exist').format(i,s.proxy_node_v6)):t.push(_('Route rule "%s" IPv6 proxy node is not configured').format(i));return}s.proxy_node?r(s.proxy_node,_('Route rule "%s" proxy node "%s" does not exist').format(i,s.proxy_node)):t.push(_('Route rule "%s" proxy node is not configured').format(i))}),V(_("Configuration contains missing proxy nodes"),t)}function In(){let e=new Set;if(a.sections("hijpass","proxy_node",function(o){o.enabled!=="1"&&o.name&&e.add(o.name)}),e.size===0)return!0;let t=[],r=a.get_first("hijpass","shunt","default_proxy_node");r&&e.has(r)&&t.push(_('Default global exit "%s" is not enabled').format(r));let n=a.get_first("hijpass","shunt","ruleset_out_node");return n&&e.has(n)&&t.push(_('Rule-set exit "%s" is not enabled').format(n)),a.sections("hijpass","shunt_route_rule",function(o){if(o.enabled!=="1")return;let s=o.name||o[".name"];o.ip_version_split==="1"?(o.proxy_node_v4&&e.has(o.proxy_node_v4)&&t.push(_('Route rule "%s" IPv4 proxy node "%s" is not enabled').format(s,o.proxy_node_v4)),o.proxy_node_v6&&e.has(o.proxy_node_v6)&&t.push(_('Route rule "%s" IPv6 proxy node "%s" is not enabled').format(s,o.proxy_node_v6))):o.proxy_node&&e.has(o.proxy_node)&&t.push(_('Route rule "%s" proxy node "%s" is not enabled').format(s,o.proxy_node)),o.dns_proxy_node&&e.has(o.dns_proxy_node)&&t.push(_('Route rule "%s" DNS exit node "%s" is not enabled').format(s,o.dns_proxy_node))}),V(_("Configuration contains disabled nodes"),t)}function Fn(){let e=R.getProxySectionMap(),t=[];return e.forEach(r=>{if(r.enabled!=="1"||r.type!==S.LOAD_BALANCE)return;let n=R.getProxyName(r),o=q(r.core);o!==N.SING_BOX&&o!==N.XRAY&&t.push(_('Load balancing node "%s" has an unsupported backend core').format(n));let s=R.normalizeProxyNodeList(r.member_node);if(s.length===0){t.push(_('Load balancing node "%s" has no member nodes').format(n));return}let i=s.filter((l,p)=>s.indexOf(l)!==p);i.length>0&&t.push(_('Load balancing node "%s" contains duplicate member nodes: %s').format(n,Array.from(new Set(i)).join(", "))),s.forEach(l=>{if(l===n){t.push(_('Load balancing node "%s" cannot include itself').format(n));return}let p=e.get(l);if(!p){t.push(_('Load balancing node "%s" member node "%s" does not exist').format(n,l));return}p.type===S.LOAD_BALANCE&&t.push(_('Load balancing node "%s" cannot contain load balancing member "%s"').format(n,l)),p.enabled!=="1"&&t.push(_('Load balancing node "%s" member node "%s" is not enabled').format(n,l)),R.isPort(p.socks_port)||t.push(_('Load balancing node "%s" member node "%s" has no valid SOCKS port configured').format(n,l))}),r.fallback_tag&&s.indexOf(r.fallback_tag)<0&&t.push(_('Load balancing node "%s" fallback node "%s" is not a member').format(n,r.fallback_tag))}),V(_("Configuration contains invalid load balancing nodes"),t)}function Mn(){let e=R.getProxySectionMap(),t=[];e.forEach(n=>{if(n.enabled!=="1"||n.type===S.LOAD_BALANCE||!n.upstream_proxy_node)return;let o=R.getProxyName(n),s=n.upstream_proxy_node,i=e.get(s);if(!i){t.push(_('Proxy node "%s" upstream proxy node "%s" does not exist').format(o,s));return}i.enabled!=="1"&&t.push(_('Proxy node "%s" upstream proxy node "%s" is not enabled').format(o,s)),R.isPort(i.socks_port)||t.push(_('Proxy node "%s" upstream proxy node "%s" has no valid SOCKS port configured').format(o,s));let l=R.collectProxyChain(o,e);!l.cycle&&l.chain.length>he&&t.push(_('Proxy node "%s" nesting chain exceeds %d nodes: %s').format(o,he,l.chain.join(" -> ")))});let r=R.findProxyDependencyCycle(e);return r&&t.push(_("Proxy node dependency chain has a cycle: %s").format(r.join(" -> "))),V(_("Configuration contains invalid upstream proxy nodes"),t)}function Yn(){let e=new Set,t=new Set;a.sections("hijpass","shunt_dns_node",function(i){i.tag&&(e.add(i.tag),i.enabled==="0"&&t.add(i.tag))});let r=[],n=[];function o(i,l){if(i){if(!e.has(i)){r.push(_('%s "%s" does not exist').format(l,i));return}t.has(i)&&n.push(_('%s "%s" is not enabled').format(l,i))}}let s=a.get_first("hijpass","shunt","default_dns_node");return s?o(s,_("Default global DNS")):r.push(_("Default global DNS is not configured")),o(a.get_first("hijpass","shunt","ruleset_dns_node"),_("Rule-set DNS")),a.sections("hijpass","shunt_route_rule",function(i){i.enabled==="1"&&o(i.dns_node,_('Route rule "%s" DNS node').format(i.name||i[".name"]))}),V(_("Configuration contains missing DNS nodes"),r)&&V(_("Configuration contains disabled DNS nodes"),n)}function Bn(){let e=new Set;a.sections("hijpass","proxy_node",function(o){o.name&&e.add(o.name)});let t=a.get_first("hijpass","shunt","type"),r=a.get_first("hijpass","shunt","ruleset_convert"),n=[];return w.getRouteSection().rules.forEach(function(o){if(o.enabled!=="1")return;let s=o.dnsProxyNode,i=o.name||_("Unnamed Rule");if(Vn(o,t,r)&&!s){n.push(_('Route rule "%s" uses IPv4/IPv6 split and must specify a DNS exit node').format(i));return}s&&s!=="hijpass-direct"&&!e.has(s)&&n.push(_('Route rule "%s" DNS exit node "%s" does not exist').format(i,s))}),V(_("Configuration contains invalid DNS exit nodes"),n)}function Vn(e,t,r){if(e.ipVersionSplit!=="1")return!1;let n=w.parseRuleList(e);return t===k.XRAY?n.containDomain()||n.geoSite.length>0:n.containDomain()||n.containRuleSet()||r==="1"&&n.geoSite.length>0}function Gn(){let e=new Set;a.sections("hijpass","proxy_node",function(i){i.enabled==="1"&&i.listen_port&&e.add(i.listen_port)});let t=a.get_first("hijpass","firewall","proxy_port"),r=a.get_first("hijpass","firewall","shunt_port"),n=a.get_first("hijpass","shunt","enabled")!=="0",o=a.get_first("hijpass","shunt","shunt_listen_port"),s=[];return t&&!e.has(t)&&s.push(_("Firewall proxy port %s does not reference an enabled proxy node").format(t)),r&&!e.has(r)&&!(n&&o===r)&&s.push(_("Firewall shunt port %s does not reference an enabled proxy node or shunt service").format(r)),V(_("Configuration conflict"),s)}function Hn(){let e=ct.validateSource(ct.getSource());return e===!0||V(_("Configuration conflict"),[e])}function jn(){if(a.get_first("hijpass","dns","dns_service")!=="chinadns-ng")return!0;let t=ct.getRoutingTarget(),r=t.port?"127.0.0.1#"+t.port:"",n=[];return[["direct_dns",_("Direct Domain DNS")],["proxy_dns",_("Proxy Domain DNS")]].forEach(([o,s])=>{let i=a.get_first("hijpass","dns",o);!i||i==="dnsmasq"||i==="system"||i==="custom"||(!t.available||i!==r)&&n.push(_("%s references an unavailable Core DNS port").format(s))}),V(_("Configuration conflict"),n)}function Xn(){if(a.get_first("hijpass","shunt","type")!==k.XRAY)return!0;let t=[];return a.sections("hijpass","shunt_route_rule",function(r){if(r.enabled!=="1")return;let n=An(r.protocol).filter(o=>ar.indexOf(o)===-1);n.length>0&&t.push(_('Route rule "%s" contains protocols unsupported by Xray: %s').format(r.name||r[".name"],n.join(", ")))}),t.length>0?(B.warning(_("Unsupported Xray protocol configuration"),t.join(`
|
|
`)+`
|
|
`+_("Xray route protocol only supports: %s").format(ar.join(", ")),8e3),!1):!0}function Wn(){if(a.get_first("hijpass","shunt","type")!==k.XRAY)return!0;let t=[];return a.sections("hijpass","shunt_dns_node",function(r){r.enabled!=="0"&&r.type==="tls"&&t.push(_('DNS node "%s" uses TLS, which is only supported by sing-box').format(r.tag||r[".name"]))}),V(_("Unsupported Xray DNS configuration"),t)}function qn(){let e=[];return a.sections("hijpass","proxy_node",function(t){t.enabled!=="1"||q(t.core)!==k.XRAY||t.tls_insecure!=="1"||Dn.indexOf(t.type)!==-1&&e.push(_('Proxy node "%s" enables insecure TLS, which is not supported by current Xray').format(t.name||t[".name"]))}),V(_("Unsupported Xray TLS configuration"),e)}function Kn(e,t,r){return new Promise(n=>{M.showModal(e,[E("div",{style:["box-sizing:border-box","width:100%","margin:0 0 14px 0","padding:14px 16px","border-radius:4px","background:rgba(127,127,127,0.08)","line-height:1.55"].join(";")},[E("div",{style:"margin:0 0 12px 0"},t),E("div",{style:"display:flex;flex-direction:column;gap:6px;margin:0"},r.map(o=>E("div",{style:"margin:0;word-break:break-word"},o)))]),E("div",{style:"display:flex;justify-content:flex-end;gap:10px;margin:0"},[E("button",{class:"btn cbi-button",click:function(o){o.preventDefault(),M.hideModal(),n(!1)}},_("Cancel")),E("button",{class:"btn cbi-button-action",click:function(o){o.preventDefault(),M.hideModal(),n(!0)}},_("Continue Apply"))])])})}function zn(e,t,r){let n=w.parseRuleList(e),o=e.name||e[".name"]||_("Unnamed Rule"),s=r==="1";if(t===k.XRAY)return n.isEmpty("geo")?_('Route rule "%s" has no valid match conditions for Xray').format(o):n.containRuleSet()&&!n.containDomain()&&!n.containIp()&&!n.containGeo()?_('Route rule "%s" only contains rule-set target conditions unsupported by Xray').format(o):null;if(t===k.SING_BOX){if(!s&&n.containGeo()&&(n.geoSite=[],n.geoIp=[],!n.containDomain()&&!n.containIp()&&!n.containRuleSet()))return _('Route rule "%s" has no target conditions for sing-box after removing unconverted geosite/geoip').format(o);if(n.isEmpty("set")&&!(s&&n.containGeo()))return _('Route rule "%s" has no valid match conditions for sing-box').format(o)}return null}function Qn(){let e=a.get_first("hijpass","shunt","type"),t=a.get_first("hijpass","shunt","ruleset_convert"),r=[];return w.getRouteSection().rules.forEach(n=>{if(n.enabled!=="1")return;let o=zn(n,e,t);o&&r.push(o)}),r.length>0?Kn(_("Some route rules will be skipped"),_("The following rules have no valid configuration for the current core and options, so they will not be written to the final configuration. Continue applying the configuration?"),r):!0}var lr={runSaveApplyPrechecks:async function(){return!Mn()||!Fn()||!qn()||!Gn()||!Hn()||!jn()?!1:Un()?kn()&&In()&&Yn()&&Bn()&&await Qn()&&Xn()&&Wn():!0}};function $n(){return a.get_first("hijpass","hijpass","enabled")==="0"}var ur={genHandleSaveApply:function(){return async function(e,t){try{if(await this.handleSave(e),$n()){await a.save(),await M.changes.apply(t=="0");return}if(!await lr.runSaveApplyPrechecks())return;if(a.get_first("hijpass","shunt","type")===k.SING_BOX&&a.get_first("hijpass","shunt","ruleset_convert")==="1"&&mt.writeGeoRule(),a.get_first("hijpass","shunt","config_type")==="tmpl"){let s=ne.getShuntConfData();await O.write(D.getFilePath("shunt_conf"),s),a.set_first("hijpass","shunt","shunt_hash",s?String(I.simpleHash(s)):"-1")}await a.save();let o=await a.changes();await er.cleanupChangedNodeFiles(o),await nr.writeGeneratedProxyConfigs(),await M.changes.apply(t=="0")}catch(r){console.log(r),B.error(_("Configuration Apply Failed"),_(r.message),5e3)}}}};var pr=poll;var cr=rpc;var Ue=cr.declare({object:"service",method:"list",params:["name"],expect:{"":{}}}),ke={};function gr(e){return e||"all"}function dr(e){return"service_status_"+gr(e)}var j={getServiceInstances:async function(e){return(await Ue(e))?.[e]?.instances??{}},getServiceInfo:async function(){let e=await Ue("hijpass"),r=(await Ue("hijserver"))?.hijserver?.instances??{},n=e?.hijpass?.instances??{};return{proxyInfos:j.getInstanceName("hijpass","proxy_node").map(o=>n?.[o]??void 0).filter(o=>o),shuntInfo:n?.[j.getInstanceName("hijpass","shunt")[0]]??void 0,dnsInfo:n?.[j.getInstanceName("hijpass","dns")[0]]??void 0,serverInfos:j.getInstanceName("hijserver","server_node").map(o=>r?.[o]??void 0).filter(o=>o)}},getInstanceName:function(e,t){return a.sections(e,t).map(r=>{let n=r[".name"],o=r.name??r.tag??r.dns_service;return o||(o=t),n+"-"+o})},renderServiceStatusText:function(e,t){let r="",n='<em><span style="color:%s"><strong>%s %s</strong></span></em>',o=(e?.proxyInfos??[]).filter(u=>u?.running).length>0,s=(e?.serverInfos??[]).filter(u=>u?.running).length>0,i=e?.shuntInfo?.running??!1,l=e?.dnsInfo?.running??!1,p=function(u,g){return g?n.format("green",u,_("Running")):n.format("red",u,_("Not Running"))};switch(t){case"dns":r+=p(_("Independent DNS"),l);break;case"shunt":r+=p(_("Proxy Routing"),i);break;case"server":r+=p(_("Local Server"),s);break;case"proxy":r+=p(_("Proxy Node"),o);break;default:r+=p(_("Proxy Node"),o),r+=p(_("Proxy Routing"),i),r+=p(_("Independent DNS"),l),r+=p(_("Local Server"),s)}return r},refreshServiceStatus:function(e){let t=gr(e);if(!ke[t]){let r=dr(e);ke[t]=async function(){let n=await L.resolveDefault(j.getServiceInfo()),o=document.getElementById(r);o&&(o.innerHTML=j.renderServiceStatusText(n,e))}}return ke[t]},renderServiceStatus:function(e){return function(){let t=j.refreshServiceStatus(e);return pr.add(t),window.setTimeout(t,0),E("div",{class:"hijpass-service-status"},E("fieldset",{class:"cbi-section"},[E("p",{id:dr(e),style:"display: flex; gap: 1rem;"},_("Fetching Status..."))]))}},createStatusSection:function(e,t){let r=e.section(d.TypedSection);return r.anonymous=!0,r.render=j.renderServiceStatus(t),r}};var tt={createTagValidator:function(e,t,r){return function(n,o){let s=tt.validateNameFormat(n,o);if(s!==!0)return s;let i=!1;return a.sections(e,t,function(l){l[".name"]!==n&&l[r]===o&&(i=!0)}),i?_("%s already exists, use another %s").format(r==="tag"?_("Tag"):_("Name"),r==="tag"?_("Tag"):_("Name")):!0}},getUsedPorts:function(){let e=[];a.sections("hijpass","proxy_node",n=>{n.listen_port&&e.push(Number(n.listen_port)),n.socks_port&&e.push(Number(n.socks_port))}),a.sections("hijserver","server_node",n=>{n.listen_port&&e.push(Number(n.listen_port))});let t=a.get_first("hijpass","shunt");t?.shunt_listen_port&&e.push(Number(t.shunt_listen_port)),t?.dns_listen_port&&e.push(Number(t.dns_listen_port));let r=a.get_first("hijpass","dns");return r?.cdg_port&&e.push(Number(r.cdg_port)),e},getUsedPortsExcluding:function(e){let t=[];a.sections("hijpass","proxy_node",o=>{o[".name"]!==e&&(o.listen_port&&t.push(Number(o.listen_port)),o.socks_port&&t.push(Number(o.socks_port)))}),a.sections("hijserver","server_node",o=>{o.listen_port&&t.push(Number(o.listen_port))});let r=a.get_first("hijpass","shunt");r?.shunt_listen_port&&t.push(Number(r.shunt_listen_port)),r?.dns_listen_port&&t.push(Number(r.dns_listen_port));let n=a.get_first("hijpass","dns");return n?.cdg_port&&t.push(Number(n.cdg_port)),t},findAvailablePort:function(e,t=[]){let r=[...tt.getUsedPorts(),...t],n=e;for(let o=0;o<1e3;o++,n++)if(!r.includes(n))return n;return e},validatePortConflict:function(e,t){let r=a.get_first("hijpass","shunt");if(r&&r[".name"]!==e&&(r.dns_listen_port===t||r.shunt_listen_port===t))return _("Port %s is used by shunt configuration").format(t);let n=a.get_first("hijpass","dns");if(n&&n[".name"]!==e&&n.cdg_port===t)return _("Port %s is used by DNS configuration").format(t);let o=a.sections("hijpass","proxy_node");for(let i=0;i<o.length;i++){let l=o[i];if(l[".name"]!==e&&(l.listen_port===t||l.socks_port===t))return _('Port %s is used by proxy node "%s"').format(t,l.name)}let s=a.sections("hijserver","server_node");for(let i=0;i<s.length;i++){let l=s[i];if(l[".name"]!==e&&l.listen_port===t)return _('Port %s is used by server node "%s"').format(t,l.name)}return!0},validateNameFormat:function(e,t){return!t||t===""?_("Node name cannot be empty"):/^[a-zA-Z0-9_-]+$/.test(t)?!0:_("Node name can only contain letters, numbers, underscores, and hyphens")}};function _r(e,t){let r=E("select",{id:e,class:"cbi-input-select",style:"width:100%"});return t.forEach(({value:n,label:o})=>{let s=document.createElement("option");s.value=n,s.textContent=o,r.appendChild(s)}),r}function fr(e){return[...e.ip_version_split==="1"?["proxy_node_v4","proxy_node_v6"]:["proxy_node"],"dns_proxy_node"]}function Jn(e){return e!=="hijpass-block"}var A={configureConfigEditor:function(e){e.rows=30,e.monospace=!0,e.load=async function(t){return L.resolveDefault(O.read(D.getFilePath("shunt_conf")),"")},e.write=async function(t,r){let n=(r||"").trim().replace(/\r\n/g,`
|
|
`);await O.write(D.getFilePath("shunt_conf"),n?n+`
|
|
`:""),a.set("hijpass",t,"shunt_hash",String(I.simpleHash(n)))},e.remove=async function(t){a.get_first("hijpass","shunt","config_type")!=="tmpl"&&(await O.write(D.getFilePath("shunt_conf"),""),a.set("hijpass",t,"shunt_hash","-1"))},e.rmempty=!1},showPreview:function(){try{let e=ne.getShuntConfData(),t=a.get_first("hijpass","shunt","type")||N.XRAY;M.showModal(_("Preview Configuration"),[E("div",{class:"cbi-section"},[E("div",{class:"cbi-section-descr"},_("Generated %s JSON Configuration").format(t)),E("pre",{style:"max-height: 500px; overflow: auto; padding: 10px; border-radius: 4px;",id:"config-preview-content"},e)]),E("div",{class:"right",style:"display: flex; justify-content: flex-end; align-items: center; gap: 10px;"},[E("button",{class:"btn cbi-button",click:M.hideModal},_("Close")),E("button",{class:"btn cbi-button-action",click:function(r){r.preventDefault(),r.stopPropagation();let n=document.getElementById("config-preview-content").textContent;navigator.clipboard.writeText(n).then(function(){B.success(_("Success"),_("Configuration copied to clipboard"),3e3)})}},_("Copy Configuration"))])])}catch(e){console.log(e),B.error(_("Configuration Generation Failed"),_(e.message),5e3)}},showBulkReplaceModal:function(){let e=new Set,t=a.sections("hijpass","shunt_route_rule");t.forEach(function(i){fr(i).forEach(l=>{i[l]&&e.add(i[l])})});let r=I.getEnabledProxyNodeOptions(!0),n=r.filter(i=>e.has(i.value)),o=_r("replace-from",n),s=_r("replace-to",r);M.showModal(_("Bulk Replace Nodes"),[E("div",{class:"cbi-section"},[E("div",{style:"display:grid;grid-template-columns:1fr 1fr;gap:16px;align-items:center"},[E("div",{},[E("label",{},_("From Node")),o]),E("div",{},[E("label",{},_("Replace With")),s])])]),E("div",{class:"right",style:"display:flex;justify-content:flex-end;gap:10px"},[E("button",{class:"btn cbi-button",click:M.hideModal},_("Cancel")),E("button",{class:"btn cbi-button-action",click:async function(){let i=o.value,l=s.value;if(i===l){M.hideModal();return}if(t.some(u=>u.dns_proxy_node===i)&&!Jn(l)){B.warning(_("Configuration conflict"),_("DNS exit cannot use Block"),5e3);return}t.forEach(function(u){fr(u).forEach(g=>{u[g]===i&&a.set("hijpass",u[".name"],g,l)})}),await a.save(),M.hideModal(),location.reload()}},_("Confirm Replace"))])])},loadProxyNodeOptions:function(e,t){I.loadProxyNodeOptions(e,t)},loadDNSServerOptions:function(e,t){e.load=function(r){return delete this.keylist,delete this.vallist,t&&this.value("",_("Use Global Default DNS")),a.sections("hijpass","shunt_dns_node",function(n){if(n.tag&&n.enabled!=="0"){let o=n.tag;n.server&&(o+=" ("+n.server+")"),this.value(n.tag,o)}}.bind(this)),d.ListValue.prototype.load.apply(this,[r])}},createSectionContainer:function(e,t,r,n,o,s){let i=e.taboption(t,d.SectionValue,r,n,o,s);return i.depends({config_type:"tmpl"}),i},createRequiredListValue:function(e,t,r,n,o){let s=e.option(d.ListValue,t,r,n);return s.rmempty=!1,o&&(s.validate=o),s},createValidatedDynamicList:function(e,t,r,n,o,s){let i=e.option(d.DynamicList,t,r,n);return i.load=function(l){return delete this.keylist,delete this.vallist,a.sections("hijpass",o,function(p){let u=s(p);u&&this.value(u.value,u.display)}.bind(this)),d.DynamicList.prototype.load.apply(this,[l])},i.validate=function(l,p){if(!p||p==="")return!0;let u=[];return a.sections("hijpass",o,function(g){let b=s(g);b&&u.push(b.value)}),u.indexOf(p)===-1?_("Item Not Found").format(r,p):!0},i}};var Ie=view;var mr=["http","tls","quic","bittorrent"];function Zn(){if(document.getElementById("hijpass-inline-rule-query-styles"))return;let e=document.createElement("style");e.id="hijpass-inline-rule-query-styles",e.textContent=`
|
|
.hijpass-rule-editor-query-layout {
|
|
display: grid;
|
|
grid-template-columns: auto minmax(14rem, 18rem);
|
|
gap: 1rem;
|
|
align-items: start;
|
|
width: fit-content;
|
|
max-width: 100%;
|
|
}
|
|
|
|
.cbi-value[data-name="domain_list"],
|
|
.cbi-value[data-name="ip_list"] {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
align-items: flex-start;
|
|
}
|
|
|
|
.cbi-value[data-name="domain_list"] > .cbi-value-field,
|
|
.cbi-value[data-name="ip_list"] > .cbi-value-field {
|
|
display: block;
|
|
flex: 1 1 0;
|
|
min-width: 0;
|
|
}
|
|
|
|
.hijpass-rule-editor-query-layout > .hijpass-rule-editor,
|
|
.hijpass-rule-editor-query-layout > .hijpass-inline-rule-query {
|
|
min-width: 0;
|
|
}
|
|
|
|
.hijpass-rule-editor-query-layout > .hijpass-rule-editor {
|
|
width: 370px;
|
|
max-width: 100%;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.hijpass-rule-editor-query-layout .hijpass-rule-editor textarea.cbi-input-textarea {
|
|
box-sizing: border-box;
|
|
display: block;
|
|
width: 100%;
|
|
min-width: 0;
|
|
max-width: none;
|
|
max-height: 50vh;
|
|
resize: both;
|
|
}
|
|
|
|
.hijpass-inline-rule-query {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: .375rem;
|
|
box-sizing: border-box;
|
|
width: 100%;
|
|
padding: .5rem;
|
|
border: 1px solid rgba(127, 127, 127, .35);
|
|
border-radius: 4px;
|
|
background: rgba(127, 127, 127, .05);
|
|
}
|
|
|
|
.hijpass-inline-rule-query > .cbi-section-descr {
|
|
margin: 0;
|
|
}
|
|
|
|
.hijpass-inline-rule-query-header {
|
|
display: flex;
|
|
align-items: baseline;
|
|
justify-content: space-between;
|
|
gap: .5rem;
|
|
min-width: 0;
|
|
}
|
|
|
|
.hijpass-inline-rule-query-controls {
|
|
display: grid;
|
|
grid-template-columns: minmax(0, 1fr) auto;
|
|
gap: .5rem;
|
|
align-self: stretch;
|
|
min-width: 0;
|
|
}
|
|
|
|
.hijpass-rule-editor-query-layout .hijpass-inline-rule-query-controls > input.cbi-input-text {
|
|
box-sizing: border-box;
|
|
min-width: 0;
|
|
width: auto;
|
|
max-width: none;
|
|
}
|
|
|
|
.hijpass-inline-rule-query-controls > .cbi-button {
|
|
margin: 0;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.hijpass-inline-rule-query-status {
|
|
flex: 0 0 auto;
|
|
min-height: 0;
|
|
text-align: right;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.hijpass-inline-rule-query-status[data-state="success"] {
|
|
color: var(--success-color, #2e7d32);
|
|
}
|
|
|
|
.hijpass-inline-rule-query-status[data-state="error"] {
|
|
color: var(--danger-color, #c62828);
|
|
}
|
|
|
|
.hijpass-rule-editor-query-layout textarea.hijpass-inline-rule-query-result {
|
|
box-sizing: border-box;
|
|
align-self: stretch;
|
|
width: auto;
|
|
min-width: 0;
|
|
max-width: none;
|
|
height: 5rem;
|
|
min-height: 4rem;
|
|
max-height: 50vh;
|
|
resize: vertical;
|
|
}
|
|
|
|
@media (max-width: 900px) {
|
|
.cbi-value[data-name="domain_list"],
|
|
.cbi-value[data-name="ip_list"] {
|
|
display: block;
|
|
}
|
|
|
|
.cbi-value[data-name="domain_list"] > .cbi-value-title,
|
|
.cbi-value[data-name="ip_list"] > .cbi-value-title,
|
|
.cbi-value[data-name="domain_list"] > .cbi-value-field,
|
|
.cbi-value[data-name="ip_list"] > .cbi-value-field {
|
|
box-sizing: border-box;
|
|
display: block;
|
|
float: none;
|
|
width: 100%;
|
|
margin-left: 0;
|
|
text-align: left;
|
|
}
|
|
|
|
.hijpass-rule-editor-query-layout {
|
|
grid-template-columns: minmax(0, 1fr);
|
|
width: 100%;
|
|
}
|
|
|
|
.hijpass-rule-editor-query-layout > .hijpass-rule-editor,
|
|
.hijpass-rule-editor-query-layout .hijpass-rule-editor textarea.cbi-input-textarea {
|
|
width: 100%;
|
|
max-width: 100%;
|
|
}
|
|
}
|
|
`,document.head.appendChild(e)}function to(e,t){let r=t+"-query-title",n=t+"-query-keyword",o=e+":",s=E("div",{class:"hijpass-inline-rule-query-status",role:"status","aria-live":"polite"}),i=E("textarea",{class:"cbi-input-textarea hijpass-inline-rule-query-result",readonly:"readonly",placeholder:_("Query results will appear here"),"aria-label":_("Query Results")}),l=E("input",{id:n,class:"cbi-input-text",type:"text",placeholder:e==="geosite"?"www.example.com / geosite:cn":"1.1.1.1 / geoip:cn","aria-label":_("Query Keyword")}),p=E("button",{class:"cbi-button cbi-button-action",type:"button"},_("Query")),u=E("div",{class:"hijpass-inline-rule-query",role:"group","aria-labelledby":r},[E("div",{class:"hijpass-inline-rule-query-header"},[E("strong",{id:r},_("Geo Database Query")),s]),E("div",{class:"cbi-section-descr"},e==="geosite"?[E("div",{},_("Domain \u2192 GeoSite tags")),E("div",{},_("geosite:tag \u2192 domains in tag"))]:[E("div",{},_("IP address \u2192 GeoIP tags")),E("div",{},_("geoip:tag \u2192 networks in tag"))]),E("div",{class:"hijpass-inline-rule-query-controls"},[l,p]),i]),g=function(f,m){s.textContent=f,m?s.dataset.state=m:delete s.dataset.state},b=async function(){if(p.disabled)return;let f=l.value.trim();if(!f){g(_("Enter Query Keyword"),"error"),l.focus();return}i.value="",p.disabled=!0,u.setAttribute("aria-busy","true"),g(_("Querying"));try{let m=f.toLowerCase().startsWith(o),c=m?f.slice(o.length).trim():f;if(!c){g(_("Enter Query Keyword"),"error"),l.focus();return}let h=await O.exec("/usr/lib/hijpass/geoview.sh",[m?"-e":"-l",e,c]);if(h.code!==0)throw new Error(h.stderr||_("Query Failed"));let v=(h.stdout||"").trim();v?(m||(v=v.split(/\r?\n/).filter(Boolean).map(F=>o+F).join(`
|
|
`)),i.value=v,g(_("Query Complete"),"success")):g(_("No Matching Results"))}catch(m){console.log(m),g(_("Query Failed"),"error")}finally{p.disabled=!1,u.removeAttribute("aria-busy")}};return p.addEventListener("click",function(f){f.preventDefault(),b()}),l.addEventListener("keydown",function(f){f.key==="Enter"&&(f.preventDefault(),b())}),u}function eo(e,t,r,n){if(typeof ResizeObserver>"u")return;let o=window.matchMedia("(max-width: 900px)"),s=n.style.width,i=null,l=370,p=0,u=!1,g=null,b=function(){if(e.isConnected)u=!0;else if(u){f.disconnect();return}if(o.matches){i!==!0&&(t.style.removeProperty("width"),n.style.width=s),i=!0,p=0;return}i===!0&&(t.style.removeProperty("width"),n.style.width=s,l=370),i=!1;let m=e.parentElement;if(!m||m.clientWidth===0)return;m!==g&&(f.observe(m),g=m);let c=n.offsetWidth;c>0&&Math.abs(c-p)>1&&(l=c);let h=parseFloat(window.getComputedStyle(e).columnGap)||0,v=m.clientWidth-r.offsetWidth-h;if(v<=0)return;let F=Math.min(l,v),T=F+"px";p=F,n.style.width!==T&&(n.style.width=T),t.style.width!==T&&(t.style.width=T)},f=new ResizeObserver(b);f.observe(n),f.observe(r),window.requestAnimationFrame(function(){b()})}function hr(e,t){e.renderWidget=function(r,n,o){let s=d.TextValue.prototype.renderWidget.call(this,r,n,o),i=E("div",{class:"hijpass-rule-editor"},[s]),l=to(t,this.cbid(r)),p=E("div",{class:"hijpass-rule-editor-query-layout"},[i,l]),u=s.querySelector("textarea.cbi-input-textarea");return u&&eo(p,i,l,u),p}}function oe(e,t){let r=a.get_first("hijpass","shunt"),n=r?.[".name"],o=n?e.map.lookupOption(t,n):null;return o?o[0].formvalue(o[1]):r?.[t]}function ro(e,t){let r=w.parseRuleList({domainList:e.formvalue(t,"domain_list")||"",ipList:e.formvalue(t,"ip_list")||"",network:[],protocol:[],port:[],portRange:[]}),n=oe(e,"type"),o=oe(e,"ruleset_convert");return n===N.XRAY?r.containDomain()||r.geoSite.length>0:r.containDomain()||r.containRuleSet()||o==="1"&&r.geoSite.length>0}function yr(e,t){if(ct.getSource()===Q.ROUTING)return _("Firewall DNS forwarding is using Core DNS. Select another forwarding source in Firewall before disabling proxy routing.");let r=a.get_first("hijpass","dns","dns_service"),n=a.get_first("hijpass","dns","direct_dns"),o=a.get_first("hijpass","dns","proxy_dns"),s=e.formvalue(t,"dns_listen_port");return r==="chinadns-ng"&&s&&(n==="127.0.0.1#"+s||o==="127.0.0.1#"+s)?_("Independent DNS is using this Core DNS port. Change it in the Independent DNS module before disabling proxy routing."):null}var no=Ie.extend({load:function(){return Promise.all([a.load("hijpass")])},handleSave:async function(e){try{await Ie.prototype.handleSave(e)}catch(t){console.log(t),B.error(_("Configuration Save Failed"),_(t.message),5e3)}},handleSaveApply:ur.genHandleSaveApply(),render:function(){Zn();let e=new d.Map("hijpass",_("Proxy Routing"),_("Configure proxy core routing, DNS, and rule-set settings"));j.createStatusSection(e,"shunt");let t=e.section(d.TypedSection,"shunt");return t.anonymous=!0,t.addremove=!1,lo(t),oo(t),so(t),io(t),ao(t),e.render()}});function oo(e){let t=e.taboption("basic",d.Flag,"enabled",_("Enable Shunt"),"");t.default="1",t.rmempty=!1,t.validate=function(p,u){return u!=="0"?!0:yr(this.section,p)||!0},t.renderWidget=function(p,u,g){let b=d.Flag.prototype.renderWidget.call(this,p,u,g),f=b.querySelector('input[type="checkbox"]');return f?.addEventListener("change",m=>{if(f.checked)return;let c=yr(this.section,p);c&&(f.checked=!0,m.stopImmediatePropagation(),this.triggerValidation(p),B.warning(_("Configuration conflict"),c,8e3))},!0),b};let r=e.taboption("basic",d.ListValue,"type",_("Shunt Type"),_("Select Shunt Type"));dt.SHUNT_CONF_TYPE.forEach(function(p){r.value(p)}),r.default=N.XRAY,r.rmempty=!1;let n=e.taboption("basic",d.ListValue,"config_type",_("Configuration Type"),_("Select Configuration Type"));n.value("tmpl",_("Template Configuration")),n.value("custom",_("Custom Edit")),n.default="tmpl",n.rmempty=!1;let o=e.taboption("basic",d.Value,"shunt_listen_port",_("Shunt Listen Port"),_("Shunt Listen Port"));o.default="1041",o.datatype="port",o.rmempty=!1,o.validate=function(p,u){return this.section.formvalue(p,"dns_listen_port")===u?_("Conflicts with DNS Port"):tt.validatePortConflict.call(this,p,u)};let s=e.taboption("basic",d.Value,"dns_listen_port",_("DNS Listen Port"),_("DNS Listen Port"));s.default="10153",s.datatype="port",s.rmempty=!1,s.validate=function(p,u){return this.section.formvalue(p,"shunt_listen_port")===u?_("Conflicts with Shunt Port"):tt.validatePortConflict.call(this,p,u)},I.createLogFlagOption(e,"hijpass","basic");let i=e.taboption("basic",d.ListValue,"log_level",_("Log Level"),_("Logging Level"));dt.SHUNT_LOG_LEVELS.forEach(function(p){i.value(p)}),i.default="warn",i.rmempty=!1,i.depends("log_enabled","1");let l=e.taboption("basic",d.Button,"_preview_config",_("Preview Configuration"),_("Click to Preview"));l.depends("config_type","tmpl"),l.inputtitle=_("Preview Configuration"),l.inputstyle="apply",l.onclick=A.showPreview}function so(e){let t=e.taboption("config",d.TextValue,"shunt_conf_data",null,_("Edit Shunt Configuration File"));t.depends("config_type","custom"),A.configureConfigEditor(t)}function io(e){let r=A.createSectionContainer(e,"route","_route_global",d.TypedSection,"shunt","").subsection;I.setAnonymousSection(r);let n=A.createRequiredListValue(r,"default_proxy_node",_("Default Global Exit"),_("Select Default Exit Node"),function(y,x){return x?!0:_("Configure Global Exit First")});A.loadProxyNodeOptions(n,!0);let o=r.option(d.ListValue,"ruleset_out_node",_("Rule-set Exit"),_("Rule-set Download Exit"));A.loadProxyNodeOptions(o,!1);let s=r.option(d.Flag,"ruleset_convert",_("Use GeoSite Rule-set"),_("Convert Geo Rules"));s.rmempty=!1,s.depends("type",N.SING_BOX);let i=r.option(d.Button,"_route_diagnostics",_("Shunt Troubleshooting"),_("Trace router or client traffic and inspect routing failures in Diagnostics."));i.inputtitle=_("Open Diagnostics"),i.inputstyle="action",i.onclick=function(){window.location.href=L.url("admin/services/hijpass/log")+"?tab=trace"};let l=r.option(d.Button,"_replace_node",_("Bulk Replace Nodes"));l.depends({config_type:"tmpl"}),l.inputtitle=_("Bulk Replace Nodes"),l.inputstyle="apply",l.onclick=A.showBulkReplaceModal;let p=e.taboption("route",d.SectionValue,"_route_rule",d.GridSection,"shunt_route_rule",_("Routing Rule Configuration"));p.depends({config_type:"tmpl"});let u=p.subsection;u.rowcolors=!0,I.setAnonymousGridSectionMembers(u),u.modaltitle=_("Edit Routing Rule"),u.sectiontitle=function(y){return a.get("hijpass",y,"name")||_("Unnamed Rule")},u.rowcolors=!0,u.tab("_rule",_("Rule")),u.tab("_dns",_("DNS Configuration"));let g=u.taboption("_rule",d.Value,"name",_("Rule Name"));g.validate=tt.createTagValidator("hijpass","shunt_route_rule","name"),g.rmempty=!1,g.modalonly=!0;let b=u.taboption("_rule",d.Flag,"enabled",_("Enable"));b.default="1",b.rmempty=!1,b.editable=!0;let f=u.option(d.DummyValue,"_proxy_node_view",_("Proxy Node"));f.textvalue=function(y){return a.get("hijpass",y,"ip_version_split")==="1"?_("IPv4: %s / IPv6: %s").format(a.get("hijpass",y,"proxy_node_v4")||"-",a.get("hijpass",y,"proxy_node_v6")||"-"):a.get("hijpass",y,"proxy_node")||"-"};let m=u.taboption("_rule",d.ListValue,"proxy_node",_("Proxy Node"));m.rmempty=!0,m.modalonly=!0,m.depends({ip_version_split:"1","!reverse":!0}),m.validate=function(y,x){return this.section.formvalue(y,"ip_version_split")!=="1"&&!x?_("Configure Proxy Node First"):!0},A.loadProxyNodeOptions(m,!0);let c=u.taboption("_rule",d.Flag,"ip_version_split",_("Split IPv4/IPv6 Exit"),_("Use separate proxy nodes for IPv4 and IPv6 while sharing the same rule conditions"));c.default="0",c.rmempty=!1,c.modalonly=!0;let h=u.taboption("_rule",d.ListValue,"proxy_node_v4",_("IPv4 Proxy Node"),_("IPv4 traffic exit node"));h.depends("ip_version_split","1"),h.modalonly=!0,h.validate=function(y,x){return this.section.formvalue(y,"ip_version_split")==="1"&&!x?_("Configure IPv4 Proxy Node First"):!0},A.loadProxyNodeOptions(h,!0);let v=u.taboption("_rule",d.ListValue,"proxy_node_v6",_("IPv6 Proxy Node"),_("IPv6 traffic exit node"));v.depends("ip_version_split","1"),v.modalonly=!0,v.validate=function(y,x){return this.section.formvalue(y,"ip_version_split")==="1"&&!x?_("Configure IPv6 Proxy Node First"):!0},A.loadProxyNodeOptions(v,!0);let F=u.taboption("_dns",d.ListValue,"dns_node",_("DNS Server"),_("Only Effective with Domain/GeoSite/Rule-set"));A.loadDNSServerOptions(F,!0),F.textvalue=function(y){let x=a.get("hijpass",y,"dns_node");if(!x)return _("-");let C=a.get("hijpass",y,"dns_proxy_node"),W;return C?(C=C==="hijpass-direct"?_("Direct"):C,W=x+" -> "+C):W=x,W};let T=u.taboption("_dns",d.ListValue,"dns_strategy",_("DNS Resolution Strategy"));T.value("",_("Use Global Default Resolution Strategy")),dt.DNS_STRATEGY_VALUES.forEach(function(y){T.value(y.value,_(y.label))}),T.modalonly=!0;let X=u.taboption("_dns",d.ListValue,"dns_proxy_node",_("DNS Exit Node"));X.value("",_("Use Routing Proxy Node")),X.value("hijpass-direct",_("Direct")),a.sections("hijpass","proxy_node",function(y){if(y.name&&y.enabled==="1"){let x=y.name;y.socks_port&&(x+=" ("+y.socks_port+")"),X.value(y.name,x)}}),X.modalonly=!0,X.validate=function(y,x){let C=this.section;return C.formvalue(y,"ip_version_split")==="1"&&!x&&ro(C,y)?_("Configure DNS Exit Node when splitting IPv4/IPv6 exit"):!0};let G=u.taboption("_rule",d.MultiValue,"network",_("Network"));G.value("tcp"),G.value("udp"),G.cfgvalue=function(y){let x=a.get("hijpass",y,"network");return x?x.join(","):"-"};let U=u.taboption("_rule",d.MultiValue,"protocol",_("Protocol"),_("Current Xray only supports http, tls, quic, and bittorrent"));U.value("tls"),U.value("http"),U.value("quic"),U.value("stun"),U.value("dns"),U.value("bittorrent"),U.value("dtls"),U.value("ssh"),U.value("rdp"),U.value("ntp"),U.validate=function(y,x){return oe(this.section,"type")!==N.XRAY?!0:(Array.isArray(x)?x:x?[x]:[]).filter(Nr=>mr.indexOf(Nr)===-1).length>0?_("Xray only supports route protocol filters: %s").format(mr.join(", ")):!0},U.cfgvalue=function(y){let x=a.get("hijpass",y,"protocol");return x?x.join(","):"-"};let z=u.taboption("_rule",d.DynamicList,"port",_("Port"));z.datatype="port",z.placeholder="80",z.modalonly=!0;let se=u.taboption("_rule",d.DynamicList,"port_range",_("Port Range"));se.datatype="portrange",se.placeholder="1000-2000",se.modalonly=!0;let Fe=u.option(d.TextValue,"_port_view",_("Port Range"));Fe.textvalue=function(y){let x=a.get("hijpass",y,"port"),C=a.get("hijpass",y,"port_range"),W=[];return x&&W.push(...x),C&&W.push(...C),W.join(",")||"-"},Fe.modalonly=!1;let xt=u.taboption("_rule",d.TextValue,"domain_list",_("Domain Rule List"),_("Plain string: When this string matches any part of the target domain, the rule takes effect.<br>Regular expression: Starts with 'regexp:', followed by a regular expression.<br>Subdomain (recommended): Starts with 'domain:', followed by a domain. The rule takes effect when this domain is the target domain or one of its subdomains.<br>Full match: Starts with 'full:', followed by a domain. The rule takes effect when the target domain exactly matches this domain.<br>geosite: e.g. 'geosite:cn'.<br>rule-set: e.g. 'rule-set:local:/path/rulefile' or 'rule-set:remote:https://file'.<br>Comment: starts with #"));xt.rows=4,xt.monospace=!0,xt.modalonly=!0,hr(xt,"geosite");let br=u.option(d.TextValue,"_domain_list_view",_("Domain Rule Count"));br.textvalue=function(y){let x=a.get("hijpass",y,"domain_list");return x?x.split(`
|
|
`).filter(C=>!C.startsWith("#")).length:"-"};let Nt=u.taboption("_rule",d.TextValue,"ip_list",_("IP Rule List"),_("IP: e.g. '127.0.0.1'.<br>CIDR: e.g. '10.0.0.0/8'.<br>geoip: e.g. 'geoip:cn'.<br>rule-set: e.g. 'rule-set:local:/path/rulefile' or 'rule-set:remote:https://file'.<br>Comment: starts with #"));Nt.rows=4,Nt.monospace=!0,Nt.modalonly=!0,hr(Nt,"geoip");let xr=u.option(d.TextValue,"_ip_list_view",_("IP Rule Count"));xr.textvalue=function(y){let x=a.get("hijpass",y,"ip_list");return x?x.split(`
|
|
`).filter(C=>!C.startsWith("#")).length:"-"}}function ao(e){let r=A.createSectionContainer(e,"dns","_dns_global",d.TypedSection,"shunt","").subsection;I.setAnonymousSection(r);let n=A.createRequiredListValue(r,"default_dns_node",_("Default Global DNS"),_("Select Default DNS"),function(c,h){return h?!0:_("Please configure the global DNS server first")});A.loadDNSServerOptions(n,!1);let o=r.option(d.ListValue,"ruleset_dns_node",_("Rule-set DNS"),_("Select Rule-set DNS"));A.loadDNSServerOptions(o,!0);let s=r.option(d.ListValue,"default_strategy",_("Internal DNS Resolution Strategy"),_("Select DNS Resolution Strategy"));dt.DNS_STRATEGY_VALUES.forEach(function(c){s.value(c.value,_(c.label))}),s.rmempty=!1;let i=r.option(d.Flag,"use_cache",_("DNS Cache"));i.rmempty=!1;let l=e.taboption("dns",d.SectionValue,"_dns_servers",d.GridSection,"shunt_dns_node",_("DNS Node Configuration"));l.depends({config_type:"tmpl"});let p=l.subsection;p.rowcolors=!0,p.anonymous=!0,p.addremove=!0,p.sortable=!0,p.nodescriptions=!0,p.modaltitle=_("Edit DNS Server"),p.sectiontitle=function(c){return a.get("hijpass",c,"tag")||_("Unnamed")};let u=p.option(d.Flag,"enabled",_("Enable"));u.default="1",u.rmempty=!1,u.editable=!0;let g=p.option(d.ListValue,"type",_("Type"),_("DNS Server Type"));g.value("tcp","TCP"),g.value("udp","UDP"),g.value("tls",_("TLS (sing-box only)")),g.value("https","HTTPS"),g.value("quic","QUIC"),g.default="tcp",g.rmempty=!1,g.validate=function(c,h){return h==="tls"&&oe(this.section,"type")===N.XRAY?_("TLS (sing-box only)"):!0};let b=p.option(d.Value,"tag",_("Tag"),_("DNS Server Tag"));b.placeholder="dns-local",b.rmempty=!1,b.validate=tt.createTagValidator("hijpass","shunt_dns_node","tag"),b.modalonly=!0;let f=p.option(d.Value,"server",_("DNS Server"),_("DNS Server Address"));f.placeholder="8.8.8.8",f.datatype="ipaddr",f.rmempty=!1;let m=p.option(d.Value,"port",_("Port"),_("DNS Server Port"));m.placeholder="53",m.datatype="port",m.rmempty=!0}function lo(e){e.tab("basic",_("Basic Configuration")),e.tab("config",_("Shunt Configuration Editor")),e.tab("route",_("Routing Rules")),e.tab("dns",_("Core DNS")),e.tab("ruleset",_("Rule-set"))}var uo=no;return wr(po);})();
|
|
|
|
|
|
return LuciView.default;
|