letasset_file_status=_('WARNING: at least one of asset files (geoip.dat, geosite.dat) is not found under /usr/share/xray. Xray may not work properly. See <a href="https://github.com/yichya/luci-app-xray">here</a> for help.')
if(geoip_existence){
if(geosite_existence){
asset_file_status=_('Asset files check: ')+`geoip.dat ${geoip_size}; geosite.dat ${geosite_size}. `+_('Report issues or request for features <a href="https://github.com/yichya/luci-app-xray">here</a>.')
o=s.taboption('general',form.Flag,'transparent_proxy_enable',_('Enable Transparent Proxy'),_('This enables DNS query forwarding and TProxy for both TCP and UDP connections.'))
o=s.taboption('general',form.Flag,'tproxy_sniffing',_('Enable Sniffing'),_('If sniffing is enabled, requests will be routed according to domain settings in "DNS Settings" tab.'))
o.depends("transparent_proxy_enable","1")
o=s.taboption('general',form.Flag,'route_only',_('Route Only'),_('Use sniffed domain for routing only but still access through IP. Reduces unnecessary DNS requests. See <a href="https://github.com/XTLS/Xray-core/commit/a3023e43ef55d4498b1afbc9a7fe7b385138bb1a">here</a> for help.'))
o=s.taboption('general',form.SectionValue,"xray_servers",form.GridSection,'servers',_('Xray Servers'),_("Servers are referenced by index (order in the following list). Deleting servers may result in changes of upstream servers actually used by proxy and bridge."))
o=ss.taboption('protocol',form.Flag,'shadowsocks_udp_over_tcp',_('[shadowsocks] UDP over TCP'),_('Only available for shadowsocks-2022 ciphers (2022-*)'))
o=ss.taboption('transport',form.Value,"grpc_initial_windows_size",_("[grpc] Initial Windows Size"),_("Set to 524288 to avoid Cloudflare sending ENHANCE_YOUR_CALM."))
o=s.taboption('proxy',form.Value,'dns_port',_('Xray DNS Server Port'),_("Do not use port 53 (dnsmasq), port 5353 (mDNS) or other common ports"))
o.datatype='port'
o.default=5300
o=s.taboption('proxy',form.Value,'dns_count',_('Extra DNS Server Ports'),_('Listen for DNS Requests on multiple ports (all of which serves as dnsmasq upstream servers).<br/>For example if Xray DNS Server Port is 5300 and use 3 extra ports, 5300 - 5303 will be used for DNS requests.<br/>Increasing this value may help reduce the possibility of temporary DNS lookup failures.'))
o.datatype='range(0, 50)'
o.default=0
o=s.taboption('proxy',form.Value,'mark',_('Socket Mark Number'),_('Avoid proxy loopback problems with local (gateway) traffic'))
o=s.taboption('proxy',form.SectionValue,"access_control_lan_hosts",form.TableSection,'lan_hosts',_('LAN Hosts Access Control'),_("Will not enable transparent proxy for these MAC addresses."))
o=ss.option(form.ListValue,"bypassed",_("Access Control Strategy"))
o.value("0","Always forwarded")
o.value("1","Always bypassed")
o.rmempty=false
s.tab('dns',_('DNS Settings'));
o=s.taboption('dns',form.Value,'fast_dns',_('Fast DNS'),_("DNS for resolving outbound domains and following bypassed domains"))
o.datatype='or(ip4addr, ip4addrport)'
o.placeholder="114.114.114.114"
if(geosite_existence){
o=s.taboption('dns',form.DynamicList,"bypassed_domain_rules",_('Bypassed domain rules'),_('Specify rules like <code>geosite:cn</code> or <code>domain:bilibili.com</code>. See <a href="https://xtls.github.io/config/dns.html#dnsobject">documentation</a> for details.'))
}else{
o=s.taboption('dns',form.DynamicList,'bypassed_domain_rules',_('Bypassed domain rules'),_('Specify rules like <code>domain:bilibili.com</code> or see <a href="https://xtls.github.io/config/dns.html#dnsobject">documentation</a> for details.<br/> In order to use Geosite rules you need a valid resource file /usr/share/xray/geosite.dat.<br/>Compile your firmware again with data files to use Geosite rules, or <a href="https://github.com/v2fly/domain-list-community">download one</a> and upload it to your router.'))
}
o.rmempty=true
o=s.taboption('dns',form.Value,'secure_dns',_('Secure DNS'),_("DNS for resolving known polluted domains (specify forwarded domain rules here)"))
o.datatype='or(ip4addr, ip4addrport)'
o.placeholder="1.1.1.1"
if(geosite_existence){
o=s.taboption('dns',form.DynamicList,"forwarded_domain_rules",_('Forwarded domain rules'),_('Specify rules like <code>geosite:geolocation-!cn</code> or <code>domain:youtube.com</code>. See <a href="https://xtls.github.io/config/dns.html#dnsobject">documentation</a> for details.'))
}else{
o=s.taboption('dns',form.DynamicList,'forwarded_domain_rules',_('Forwarded domain rules'),_('Specify rules like <code>domain:youtube.com</code> or see <a href="https://xtls.github.io/config/dns.html#dnsobject">documentation</a> for details.<br/> In order to use Geosite rules you need a valid resource file /usr/share/xray/geosite.dat.<br/>Compile your firmware again with data files to use Geosite rules, or <a href="https://github.com/v2fly/domain-list-community">download one</a> and upload it to your router.'))
}
o.rmempty=true
o=s.taboption('dns',form.Value,'default_dns',_('Default DNS'),_("DNS for resolving other sites (not in the rules above) and DNS records other than A or AAAA (TXT and MX for example)"))
o.datatype='or(ip4addr, ip4addrport)'
o.placeholder="8.8.8.8"
if(geosite_existence){
o=s.taboption('dns',form.DynamicList,"blocked_domain_rules",_('Blocked domain rules'),_('Specify rules like <code>geosite:category-ads</code> or <code>domain:baidu.com</code>. See <a href="https://xtls.github.io/config/dns.html#dnsobject">documentation</a> for details.'))
}else{
o=s.taboption('dns',form.DynamicList,'blocked_domain_rules',_('Blocked domain rules'),_('Specify rules like <code>domain:baidu.com</code> or see <a href="https://xtls.github.io/config/dns.html#dnsobject">documentation</a> for details.<br/> In order to use Geosite rules you need a valid resource file /usr/share/xray/geosite.dat.<br/>Compile your firmware again with data files to use Geosite rules, or <a href="https://github.com/v2fly/domain-list-community">download one</a> and upload it to your router.'))
o=s.taboption('access_control',form.Value,'geoip_direct_code',_('GeoIP Direct Code'),_("Hosts in this GeoIP set will not be forwarded through Xray. Set to unspecified to forward all non-private hosts."))
}else{
o=s.taboption('access_control',form.Value,'geoip_direct_code',_('GeoIP Direct Code'),_("Resource file /usr/share/xray/geoip.dat not exist. All network traffic will be forwarded. <br/> Compile your firmware again with data files to use this feature, or<br/><a href=\"https://github.com/v2fly/geoip\">download one</a> (maybe disable transparent proxy first) and upload it to your router."))
o.readonly=true
}
o.value("cn","cn")
o.value("telegram","telegram")
o.datatype="string"
o=s.taboption('access_control',form.ListValue,'routing_domain_strategy',_('Routing Domain Strategy'),_("Domain resolution strategy when matching domain against rules."))
o.value("AsIs","AsIs")
o.value("IPIfNonMatch","IPIfNonMatch")
o.value("IPOnDemand","IPOnDemand")
o.default="AsIs"
o.rmempty=false
o=s.taboption('access_control',form.DynamicList,"wan_bp_ips",_("Bypassed IP"),_("Requests to these IPs won't be forwarded through Xray."))
o=s.taboption('access_control',form.SectionValue,"access_control_manual_tproxy",form.GridSection,'manual_tproxy',_('Manual Transparent Proxy'),_('Compared to iptables REDIRECT, Xray could do NAT46 / NAT64 (for example accessing IPv6 only sites). See <a href="https://github.com/v2ray/v2ray-core/issues/2233">FakeDNS</a> for details.'))
o=ss.option(form.Flag,'force_forward',_('Force Forward'),_('This destination must be forwarded through Xray. (This option might be removed later.)'))
o.modalonly=true
s.tab('xray_server',_('HTTPS Server'));
o=s.taboption('xray_server',form.Flag,'web_server_enable',_('Enable Xray HTTPS Server'),_("This will start a HTTPS server at port 443 which serves both as an inbound for Xray and a reverse proxy web server."));
o=s.taboption('extra_options',form.ListValue,'loglevel',_('Log Level'),_('Read Xray log in "System Log" or use <code>logread</code> command.'))
o.value("debug")
o.value("info")
o.value("warning")
o.value("error")
o.value("none")
o.default="warning"
o=s.taboption('extra_options',form.Flag,'access_log',_('Enable Access Log'),_('Access log will also be written to System Log.'))
o=s.taboption('extra_options',form.Flag,'dns_log',_('Enable DNS Log'),_('DNS log will also be written to System Log.'))
o=s.taboption('extra_options',form.Flag,'xray_api',_('Enable Xray API Service'),_('Xray API Service uses port 8080 and GRPC protocol. Also callable via <code>xray api</code> or <code>ubus call xray</code>. See <a href="https://xtls.github.io/document/command.html#xray-api">here</a> for help.'))
o=s.taboption('extra_options',form.Flag,'stats',_('Enable Statistics'),_('Enable statistics of inbounds / outbounds data. Use Xray API to query values.'))
o=s.taboption('extra_options',form.Flag,'observatory',_('Enable Observatory'),_('Enable latency measurement for TCP and UDP outbounds. Support for balancers and strategy will be added later.'))
o=s.taboption('extra_options',form.Flag,'metrics_server_enable',_('Enable Xray Metrics Server'),_("Enable built-in metrics server for pprof and expvar. See <a href='https://github.com/XTLS/Xray-core/pull/1000'>here</a> for details."));
o=s.taboption('extra_options',form.Value,'metrics_server_port',_('Xray Metrics Server Port'),_("Metrics may be sensitive so think twice before setting it as Default Fallback HTTP Server."))
o=s.taboption('extra_options',form.Value,'handshake',_('Handshake Timeout'),_('Policy: Handshake timeout when connecting to upstream. See <a href="https://xtls.github.io/config/policy.html#levelpolicyobject">here</a> for help.'))
o.datatype='uinteger'
o.placeholder=4
o.default=4
o=s.taboption('extra_options',form.Value,'conn_idle',_('Connection Idle Timeout'),_('Policy: Close connection if no data is transferred within given timeout. See <a href="https://xtls.github.io/config/policy.html#levelpolicyobject">here</a> for help.'))
o.datatype='uinteger'
o.placeholder=300
o.default=300
o=s.taboption('extra_options',form.Value,'uplink_only',_('Uplink Only Timeout'),_('Policy: How long to wait before closing connection after server closed connection. See <a href="https://xtls.github.io/config/policy.html#levelpolicyobject">here</a> for help.'))
o.datatype='uinteger'
o.placeholder=2
o.default=2
o=s.taboption('extra_options',form.Value,'downlink_only',_('Downlink Only Timeout'),_('Policy: How long to wait before closing connection after client closed connection. See <a href="https://xtls.github.io/config/policy.html#levelpolicyobject">here</a> for help.'))
o.datatype='uinteger'
o.placeholder=5
o.default=5
o=s.taboption('extra_options',form.Value,'buffer_size',_('Buffer Size'),_('Policy: Internal cache size per connection. See <a href="https://xtls.github.io/config/policy.html#levelpolicyobject">here</a> for help.'))
o.datatype='uinteger'
o.placeholder=512
o.default=512
o=s.taboption('extra_options',form.SectionValue,"xray_bridge",form.TableSection,'bridge',_('Bridge'),_('Reverse proxy tool. Currently only client role (bridge) is supported. See <a href="https://xtls.github.io/config/reverse.html#bridgeobject">here</a> for help.'))
// if (Object.keys(optional_features).length > 0) {
// s.tab('optional_features', _('Optional Features'), _("Warning: all settings on this page are experimental, not guaranteed to be stable, and quite likely to be changed very frequently. Use at your own risk."))
o=s.taboption('custom_options',form.TextValue,'custom_config',_('Custom Configurations'),_('Check <code>/var/etc/xray/config.json</code> for tags of generated inbounds and outbounds. See <a href="https://xtls.github.io/config/features/multiple.html">here</a> for help'))