diff --git a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/section.js b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/section.js index 8d41053..b338a5a 100644 --- a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/section.js +++ b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/section.js @@ -42,8 +42,7 @@ function createSectionContent(section) { o.textarea = true; o.rmempty = false; o.sectionDescriptions = new Map(); - o.placeholder = - 'vless://uuid@server:port?type=tcp&security=tls#main\n// backup ss://method:pass@server:port\n// backup2 vless://uuid@server:port?type=grpc&security=reality#alt\n// backup3 trojan://04agAQapcl@127.0.0.1:33641?type=tcp&security=none#trojan-tcp-none'; + o.placeholder = 'vless://uuid@server:port?type=tcp&security=tls#main\n// backup ss://method:pass@server:port\n// backup2 vless://uuid@server:port?type=grpc&security=reality#alt\n// backup3 trojan://04agAQapcl@127.0.0.1:33641?type=tcp&security=none#trojan-tcp-none'; o.validate = function (section_id, value) { // Optional if (!value || value.length === 0) { @@ -54,15 +53,11 @@ function createSectionContent(section) { const activeConfigs = main.splitProxyString(value); if (!activeConfigs.length) { - return _( - 'No active configuration found. One configuration is required.', - ); + return _('No active configuration found. One configuration is required.'); } if (activeConfigs.length > 1) { - return _( - 'Multiply active configurations found. Please leave one configuration.', - ); + return _('Multiply active configurations found. Please leave one configuration.'); } const validation = main.validateProxyUrl(activeConfigs[0]); @@ -224,33 +219,24 @@ function createSectionContent(section) { return validation.message; }; - o = section.option( - form.Flag, - 'community_lists_enabled', - _('Community Lists'), - ); - o.default = '0'; - o.rmempty = false; - o = section.option( form.DynamicList, 'community_lists', - _('Service List'), - _('Select predefined service for routing') + + _('Community Lists'), + _('Select a predefined list for routing') + ' github.com/itdoginfo/allow-domains', ); o.placeholder = 'Service list'; Object.entries(main.DOMAIN_LIST_OPTIONS).forEach(([key, label]) => { o.value(key, _(label)); }); - o.depends('community_lists_enabled', '1'); - o.rmempty = false; + o.rmempty = true; o = section.option( form.ListValue, 'user_domain_list_type', _('User Domain List Type'), - _('Select how to add your custom domains'), + _('Select the list type for adding custom domains'), ); o.value('disabled', _('Disabled')); o.value('dynamic', _('Dynamic List')); @@ -262,9 +248,7 @@ function createSectionContent(section) { form.DynamicList, 'user_domains', _('User Domains'), - _( - 'Enter domain names without protocols (example: sub.example.com or example.com)', - ), + _('Enter domain names without protocols, e.g. example.com or sub.example.com'), ); o.placeholder = 'Domains list'; o.depends('user_domain_list_type', 'dynamic'); @@ -288,12 +272,9 @@ function createSectionContent(section) { form.TextValue, 'user_domains_text', _('User Domains List'), - _( - 'Enter domain names separated by comma, space or newline. You can add comments after //', - ), + _('Enter domain names separated by commas, spaces, or newlines. You can add comments using //'), ); - o.placeholder = - 'example.com, sub.example.com\n// Social networks\ndomain.com test.com // personal domains'; + o.placeholder = 'example.com, sub.example.com\n// Social networks\ndomain.com test.com // personal domains'; o.depends('user_domain_list_type', 'text'); o.rows = 8; o.rmempty = false; @@ -306,9 +287,7 @@ function createSectionContent(section) { const domains = main.parseValueList(value); if (!domains.length) { - return _( - 'At least one valid domain must be specified. Comments-only content is not allowed.', - ); + return _('At least one valid domain must be specified. Comments-only content is not allowed.'); } const {valid, results} = main.bulkValidate(domains, row => main.validateDomain(row, true)); @@ -324,110 +303,11 @@ function createSectionContent(section) { return true; }; - o = section.option( - form.Flag, - 'local_domain_lists_enabled', - _('Local Domain Lists'), - _('Use the list from the router filesystem'), - ); - o.default = '0'; - o.rmempty = false; - - o = section.option( - form.DynamicList, - 'local_domain_lists', - _('Local Domain List Paths'), - _('Enter the list file path'), - ); - o.placeholder = '/path/file.lst'; - o.depends('local_domain_lists_enabled', '1'); - o.rmempty = false; - o.validate = function (section_id, value) { - // Optional - if (!value || value.length === 0) { - return true; - } - - const validation = main.validatePath(value); - - if (validation.valid) { - return true; - } - - return validation.message; - }; - - o = section.option( - form.Flag, - 'remote_domain_lists_enabled', - _('Remote Domain Lists'), - _('Download and use domain lists from remote URLs'), - ); - o.default = '0'; - o.rmempty = false; - - o = section.option( - form.DynamicList, - 'remote_domain_lists', - _('Remote Domain URLs'), - _('Enter full URLs starting with http:// or https://'), - ); - o.placeholder = 'URL'; - o.depends('remote_domain_lists_enabled', '1'); - o.rmempty = false; - o.validate = function (section_id, value) { - // Optional - if (!value || value.length === 0) { - return true; - } - - const validation = main.validateUrl(value); - - if (validation.valid) { - return true; - } - - return validation.message; - }; - - o = section.option( - form.Flag, - 'local_subnet_lists_enabled', - _('Local Subnet Lists'), - _('Use the list from the router filesystem'), - ); - o.default = '0'; - o.rmempty = false; - - o = section.option( - form.DynamicList, - 'local_subnet_lists', - _('Local Subnet List Paths'), - _('Enter the list file path'), - ); - o.placeholder = '/path/file.lst'; - o.depends('local_subnet_lists_enabled', '1'); - o.rmempty = false; - o.validate = function (section_id, value) { - // Optional - if (!value || value.length === 0) { - return true; - } - - const validation = main.validatePath(value); - - if (validation.valid) { - return true; - } - - return validation.message; - }; - o = section.option( form.ListValue, 'user_subnet_list_type', _('User Subnet List Type'), - _('Select how to add your custom subnets'), + _('Select the list type for adding custom subnets'), ); o.value('disabled', _('Disabled')); o.value('dynamic', _('Dynamic List')); @@ -439,9 +319,7 @@ function createSectionContent(section) { form.DynamicList, 'user_subnets', _('User Subnets'), - _( - 'Enter subnets in CIDR notation (example: 103.21.244.0/22) or single IP addresses', - ), + _('Enter subnets in CIDR notation (e.g. 103.21.244.0/22) or single IP addresses'), ); o.placeholder = 'IP or subnet'; o.depends('user_subnet_list_type', 'dynamic'); @@ -466,7 +344,8 @@ function createSectionContent(section) { 'user_subnets_text', _('User Subnets List'), _( - 'Enter subnets in CIDR notation or single IP addresses, separated by comma, space or newline. You can add comments after //', + 'Enter subnets in CIDR notation or single IP addresses, separated by commas, spaces, or newlines. ' + + 'You can add comments using //' ), ); o.placeholder = @@ -483,9 +362,7 @@ function createSectionContent(section) { const subnets = main.parseValueList(value); if (!subnets.length) { - return _( - 'At least one valid subnet or IP must be specified. Comments-only content is not allowed.', - ); + return _('At least one valid subnet or IP must be specified. Comments-only content is not allowed.'); } const {valid, results} = main.bulkValidate(subnets, main.validateSubnet); @@ -502,23 +379,82 @@ function createSectionContent(section) { }; o = section.option( - form.Flag, - 'remote_subnet_lists_enabled', - _('Remote Subnet Lists'), - _('Download and use subnet lists from remote URLs'), + form.DynamicList, + 'local_domain_lists', + _('Local Domain Lists'), + _('Specify the path to the list file located on the router filesystem'), ); - o.default = '0'; - o.rmempty = false; + o.placeholder = '/path/file.lst'; + o.rmempty = true; + o.validate = function (section_id, value) { + // Optional + if (!value || value.length === 0) { + return true; + } + + const validation = main.validatePath(value); + + if (validation.valid) { + return true; + } + + return validation.message; + }; + + o = section.option( + form.DynamicList, + 'local_subnet_lists', + _('Local Subnet Lists'), + _('Specify the path to the list file located on the router filesystem'), + ); + o.placeholder = '/path/file.lst'; + o.rmempty = true; + o.validate = function (section_id, value) { + // Optional + if (!value || value.length === 0) { + return true; + } + + const validation = main.validatePath(value); + + if (validation.valid) { + return true; + } + + return validation.message; + }; + + o = section.option( + form.DynamicList, + 'remote_domain_lists', + _('Remote Domain Lists'), + _('Specify remote URLs to download and use domain lists'), + ); + o.placeholder = 'https://example.com/domains.srs'; + o.rmempty = true; + o.validate = function (section_id, value) { + // Optional + if (!value || value.length === 0) { + return true; + } + + const validation = main.validateUrl(value); + + if (validation.valid) { + return true; + } + + return validation.message; + }; o = section.option( form.DynamicList, 'remote_subnet_lists', - _('Remote Subnet URLs'), - _('Enter full URLs starting with http:// or https://'), + _('Remote Subnet Lists'), + _('Specify remote URLs to download and use subnet lists'), ); - o.placeholder = 'URL'; - o.depends('remote_subnet_lists_enabled', '1'); - o.rmempty = false; + o.placeholder = 'https://example.com/subnets.srs'; + o.rmempty = true; o.validate = function (section_id, value) { // Optional if (!value || value.length === 0) { @@ -538,10 +474,10 @@ function createSectionContent(section) { form.DynamicList, 'fully_routed_ips', _('Fully Routed IPs'), - _('Specify local IP addresses whose traffic will always be routed through the configured route'), + _('Specify local IP addresses or subnets whose traffic will always be routed through the configured route'), ); - o.placeholder = 'IP'; - o.rmempty = false; + o.placeholder = '192.168.1.2 or 192.168.1.0/24'; + o.rmempty = true; o.validate = function (section_id, value) { // Optional if (!value || value.length === 0) { diff --git a/podkop/files/usr/bin/podkop b/podkop/files/usr/bin/podkop index 91ce5f1..0aab46e 100755 --- a/podkop/files/usr/bin/podkop +++ b/podkop/files/usr/bin/podkop @@ -211,9 +211,10 @@ validate_service() { } process_validate_service() { - local community_lists_enabled - config_get_bool community_lists_enabled "$section" "community_lists_enabled" 0 - if [ "$community_lists_enabled" -eq 1 ]; then + local section="$1" + local community_lists + config_get community_lists "$section" "community_lists" + if [ -n "$community_lists" ]; then config_list_foreach "$section" "community_lists" validate_service fi } @@ -404,10 +405,10 @@ dnsmasq_restore() { add_cron_job() { ## Future: make a check so that it doesn't recreate many times - local community_lists_enabled remote_domain_lists_enabled remote_subnet_lists_enabled update_interval - config_get community_lists_enabled "$section" "community_lists_enabled" - config_get remote_domain_lists_enabled "$section" "remote_domain_lists_enabled" - config_get remote_subnet_lists_enabled "$section" "remote_subnet_lists_enabled" + local community_lists remote_domain_lists remote_subnet_lists update_interval + config_get community_lists "$section" "community_lists" + config_get remote_domain_lists "$section" "remote_domain_lists" + config_get remote_subnet_lists "$section" "remote_subnet_lists" config_get update_interval "settings" "update_interval" case "$update_interval" in @@ -432,9 +433,9 @@ add_cron_job() { ;; esac - if [ "$community_lists_enabled" -eq 1 ] || - [ "$remote_domain_lists_enabled" -eq 1 ] || - [ "$remote_subnet_lists_enabled" -eq 1 ]; then + if [ -n "$community_lists" ] || + [ -n "$remote_domain_lists" ] || + [ -n "$remote_subnet_lists" ]; then remove_cron_job crontab -l | { cat @@ -720,7 +721,7 @@ sing_box_configure_route() { config=$(sing_box_cm_configure_route "$config" "$SB_DIRECT_OUTBOUND_TAG" true "$SB_DNS_SERVER_TAG") local sniff_inbounds - sniff_inbounds=$(comma_string_to_json_array "$SB_TPROXY_INBOUND_TAG,$SB_DNS_INBOUND_TAG,$SB_MIXED_INBOUND_TAG") + sniff_inbounds=$(comma_string_to_json_array "$SB_TPROXY_INBOUND_TAG,$SB_DNS_INBOUND_TAG") config=$(sing_box_cm_sniff_route_rule "$config" "inbound" "$sniff_inbounds") config=$(sing_box_cm_add_hijack_dns_route_rule "$config" "protocol" "dns") @@ -803,20 +804,21 @@ exclude_source_ip_from_routing_handler() { configure_routing_for_section_lists() { local section="$1" + log "Configuring routing for '$section' section" if ! section_has_enabled_lists "$section"; then log "Section '$section' does not have any enabled list, skipping..." "warn" return 0 fi - local community_lists_enabled user_domain_list_type local_domain_lists_enabled remote_domain_lists_enabled \ - user_subnet_list_type local_subnet_lists_enabled remote_subnet_lists_enabled section_mode_type route_rule_tag - config_get_bool community_lists_enabled "$section" "community_lists_enabled" 0 + local community_lists user_domain_list_type user_subnet_list_type local_domain_lists local_subnet_lists \ + remote_domain_lists remote_subnet_lists section_mode_type route_rule_tag + config_get_bool community_lists "$section" "community_lists" config_get user_domain_list_type "$section" "user_domain_list_type" "disabled" - config_get_bool local_domain_lists_enabled "$section" "local_domain_lists_enabled" 0 - config_get_bool remote_domain_lists_enabled "$section" "remote_domain_lists_enabled" 0 config_get user_subnet_list_type "$section" "user_subnet_list_type" "disabled" - config_get_bool local_subnet_lists_enabled "$section" "local_subnet_lists_enabled" 0 - config_get_bool remote_subnet_lists_enabled "$section" "remote_subnet_lists_enabled" 0 + config_get_bool local_domain_lists "$section" "local_domain_lists" + config_get_bool local_subnet_lists "$section" "local_subnet_lists" + config_get_bool remote_domain_lists "$section" "remote_domain_lists" + config_get_bool remote_subnet_lists "$section" "remote_subnet_lists" config_get section_mode_type "$section" "mode" if [ "$section_mode_type" = "block" ]; then @@ -827,7 +829,7 @@ configure_routing_for_section_lists() { config=$(sing_box_cm_add_route_rule "$config" "$route_rule_tag" "$SB_TPROXY_INBOUND_TAG" "$outbound_tag") fi - if [ "$community_lists_enabled" -eq 1 ]; then + if [ -n "$community_lists" ]; then log "Processing community list routing rules for '$section' section" config_list_foreach "$section" "community_lists" configure_community_list_handler "$section" "$route_rule_tag" fi @@ -838,30 +840,30 @@ configure_routing_for_section_lists() { configure_user_domain_or_subnets_list "$section" "domains" "$route_rule_tag" fi - if [ "$local_domain_lists_enabled" -eq 1 ]; then - log "Processing local domains routing rules for '$section' section" - configure_local_domain_or_subnet_lists "$section" "domains" "$route_rule_tag" - fi - - if [ "$remote_domain_lists_enabled" -eq 1 ]; then - log "Processing remote domains routing rules for '$section' section" - prepare_common_ruleset "$section" "domains" "$route_rule_tag" - config_list_foreach "$section" "remote_domain_lists" configure_remote_domain_or_subnet_list_handler \ - "domains" "$section" "$route_rule_tag" - fi - if [ "$user_subnet_list_type" != "disabled" ]; then log "Processing user subnets routing rules for '$section' section" prepare_common_ruleset "$section" "subnets" "$route_rule_tag" configure_user_domain_or_subnets_list "$section" "subnets" "$route_rule_tag" fi - if [ "$local_subnet_lists_enabled" -eq 1 ]; then + if [ -n "$local_domain_lists" ]; then + log "Processing local domains routing rules for '$section' section" + configure_local_domain_or_subnet_lists "$section" "domains" "$route_rule_tag" + fi + + if [ -n "$local_subnet_lists" ]; then log "Processing local subnets routing rules for '$section' section" configure_local_domain_or_subnet_lists "$section" "subnets" "$route_rule_tag" fi - if [ "$remote_subnet_lists_enabled" -eq 1 ]; then + if [ -n "$remote_domain_lists" ]; then + log "Processing remote domains routing rules for '$section' section" + prepare_common_ruleset "$section" "domains" "$route_rule_tag" + config_list_foreach "$section" "remote_domain_lists" configure_remote_domain_or_subnet_list_handler \ + "domains" "$section" "$route_rule_tag" + fi + + if [ -n "$remote_subnet_lists" ]; then log "Processing remote subnets routing rules for '$section' section" prepare_common_ruleset "$section" "subnets" "$route_rule_tag" config_list_foreach "$section" "remote_subnet_lists" configure_remote_domain_or_subnet_list_handler \ @@ -1130,9 +1132,9 @@ sing_box_config_check() { import_community_subnet_lists() { local section="$1" - local community_lists_enabled - config_get_bool community_lists_enabled "$section" "community_lists_enabled" 0 - if [ "$community_lists_enabled" -eq 1 ]; then + local community_lists + config_get community_lists "$section" "community_lists" + if [ -n "$community_lists" ]; then log "Importing community subnet lists for '$section' section" config_list_foreach "$section" "community_lists" import_community_service_subnet_list_handler fi @@ -1198,9 +1200,9 @@ import_community_service_subnet_list_handler() { import_domains_from_remote_domain_lists() { local section="$1" - local remote_domain_lists_enabled - config_get remote_domain_lists_enabled "$section" "remote_domain_lists_enabled" - if [ "$remote_domain_lists_enabled" -eq 1 ]; then + local remote_domain_lists + config_get remote_domain_lists "$section" "remote_domain_lists" + if [ -n "$remote_domain_lists" ]; then log "Importing domains from remote domain lists for '$section' section" config_list_foreach "$section" "remote_domain_lists" import_domains_from_remote_domain_list_handler "$section" fi @@ -1227,9 +1229,9 @@ import_domains_from_remote_domain_list_handler() { import_subnets_from_remote_subnet_lists() { local section="$1" - - config_get remote_subnet_lists_enabled "$section" "remote_subnet_lists_enabled" - if [ "$remote_subnet_lists_enabled" -eq 1 ]; then + local remote_subnet_lists + config_get remote_subnet_lists "$section" "remote_subnet_lists" + if [ -n "$remote_subnet_lists" ]; then log "Importing subnets from remote subnet lists for '$section' section" config_list_foreach "$section" "remote_subnet_lists" import_subnets_from_remote_subnet_list_handler "$section" fi @@ -1375,24 +1377,24 @@ block_section_exists() { section_has_enabled_lists() { local section="$1" - local community_lists_enabled user_domain_list_type local_domain_lists_enabled remote_domain_lists_enabled \ - user_subnet_list_type local_subnet_lists_enabled remote_subnet_lists_enabled + local community_lists user_domain_list_type user_subnet_list_type local_domain_lists local_subnet_lists \ + remote_domain_lists remote_subnet_lists - config_get_bool community_lists_enabled "$section" "community_lists_enabled" 0 + config_get_bool community_lists "$section" "community_lists" config_get user_domain_list_type "$section" "user_domain_list_type" "disabled" - config_get_bool local_domain_lists_enabled "$section" "local_domain_lists_enabled" 0 - config_get_bool remote_domain_lists_enabled "$section" "remote_domain_lists_enabled" 0 config_get user_subnet_list_type "$section" "user_subnet_list_type" "disabled" - config_get_bool local_subnet_lists_enabled "$section" "local_subnet_lists_enabled" 0 - config_get_bool remote_subnet_lists_enabled "$section" "remote_subnet_lists_enabled" 0 + config_get_bool local_domain_lists "$section" "local_domain_lists" + config_get_bool local_subnet_lists "$section" "local_subnet_lists" + config_get_bool remote_domain_lists "$section" "remote_domain_lists" + config_get_bool remote_subnet_lists "$section" "remote_subnet_lists" - if [ "$community_lists_enabled" -ne 0 ] || + if [ -n "$community_lists" ] || [ "$user_domain_list_type" != "disabled" ] || - [ "$local_domain_lists_enabled" -ne 0 ] || - [ "$remote_domain_lists_enabled" -ne 0 ] || [ "$user_subnet_list_type" != "disabled" ] || - [ "$local_subnet_lists_enabled" -ne 0 ] || - [ "$remote_subnet_lists_enabled" -ne 0 ]; then + [ -n "$local_domain_lists" ] || + [ -n "$local_subnet_lists" ] || + [ -n "$remote_domain_lists" ] || + [ -n "$remote_subnet_lists" ]; then return 0 else return 1 diff --git a/podkop/files/usr/lib/constants.sh b/podkop/files/usr/lib/constants.sh index 42e4156..621ffe9 100644 --- a/podkop/files/usr/lib/constants.sh +++ b/podkop/files/usr/lib/constants.sh @@ -38,9 +38,7 @@ SB_TPROXY_INBOUND_PORT=1602 SB_DNS_INBOUND_TAG="dns-in" SB_DNS_INBOUND_ADDRESS="127.0.0.42" SB_DNS_INBOUND_PORT=53 -SB_MIXED_INBOUND_TAG="mixed-in" SB_MIXED_INBOUND_ADDRESS="0.0.0.0" # TODO(ampetelin): maybe to determine address? -SB_MIXED_INBOUND_PORT=2080 SB_SERVICE_MIXED_INBOUND_TAG="service-mixed-in" SB_SERVICE_MIXED_INBOUND_ADDRESS="127.0.0.1" SB_SERVICE_MIXED_INBOUND_PORT=4534