diff --git a/luci-app-zapret2/htdocs/luci-static/resources/view/zapret2/diagnost.js b/luci-app-zapret2/htdocs/luci-static/resources/view/zapret2/diagnost.js new file mode 100644 index 0000000..41f4553 --- /dev/null +++ b/luci-app-zapret2/htdocs/luci-static/resources/view/zapret2/diagnost.js @@ -0,0 +1,97 @@ +'use strict'; +'require baseclass'; +'require fs'; +'require poll'; +'require uci'; +'require ui'; +'require view'; +'require view.zapret2.tools as tools'; + +const btn_style_neutral = 'btn'; +const btn_style_action = 'btn cbi-button-action'; +const btn_style_positive = 'btn cbi-button-save important'; +const btn_style_negative = 'btn cbi-button-reset important'; +const btn_style_warning = 'btn cbi-button-negative'; +const btn_style_success = 'btn cbi-button-success important'; + +const fn_dwc_sh = '/opt/'+tools.appName+'/dwc.sh'; + +return baseclass.extend({ + appendLog: function(msg, end = '\n') + { + this.logArea.value += msg + end; + this.logArea.scrollTop = this.logArea.scrollHeight; + }, + + dpiCheck: async function() + { + this._action = 'dpiCheck'; + this.appendLog('DPI check [tcp 16-20]...'); + this.appendLog('Original sources: https://github.com/hyperion-cs/dpi-checkers'); + this.appendLog('WEB-version: https://hyperion-cs.github.io/dpi-checkers/ru/tcp-16-20/'); + let cmd = [ fn_dwc_sh ]; + let log = '/tmp/'+tools.appName+'_dwc.log'; + let callback = this.execAndReadCallback; + let wnd = this; + return tools.execAndRead({ cmd: cmd, log: log, logArea: this.logArea, callback: callback, cbarg: wnd }); + }, + + execAndReadCallback: function(wnd, rc, txt = '') + { + if (rc == 0 && txt) { + if (wnd._action == 'dpiCheck') { + wnd.appendLog('========================================================='); + return; + } + } + if (rc >= 500) { + if (txt) { + wnd.appendLog(txt.startsWith('ERROR') ? txt : 'ERROR: ' + txt); + } else { + wnd.appendLog('ERROR: ' + wnd._action + ': Terminated with error code = ' + rc); + } + } else { + wnd.appendLog('ERROR: Process finished with retcode = ' + rc); + } + wnd.setStage(999); + wnd.appendLog('========================================================='); + }, + + openDiagnostDialog: function(pkg_arch) + { + this.pkg_arch = pkg_arch; + + this.logArea = E('textarea', { + 'id': 'widget.modal_content', + 'readonly': true, + 'style': 'width:100% !important; font-family: monospace;', + 'rows': 26, + 'wrap': 'off', + }); + + this.btn_cancel = E('button', { + 'id': 'btn_cancel', + 'name': 'btn_cancel', + 'class': btn_style_warning, + }, _('Cancel')); + this.btn_cancel.onclick = ui.hideModal; + + this.btn_dpicheck = E('button', { + 'id': 'btn_dpicheck', + 'name': 'btn_dpicheck', + 'class': btn_style_action, + }, _('DPI check [tcp 16-20]')); + this.btn_dpicheck.onclick = ui.createHandlerFn(this, () => { this.dpiCheck() }); + + ui.showModal(_('Diagnostics'), [ + E('div', { 'class': 'cbi-section' }, [ + this.logArea, + ]), + E('div', { 'class': 'right' }, [ + this.btn_dpicheck, + ' ', + this.btn_cancel, + ]) + ]); + } +}); diff --git a/luci-app-zapret2/htdocs/luci-static/resources/view/zapret2/service.js b/luci-app-zapret2/htdocs/luci-static/resources/view/zapret2/service.js index 97f2125..25e4b4a 100644 --- a/luci-app-zapret2/htdocs/luci-static/resources/view/zapret2/service.js +++ b/luci-app-zapret2/htdocs/luci-static/resources/view/zapret2/service.js @@ -5,6 +5,7 @@ 'require ui'; 'require view'; 'require view.zapret2.tools as tools'; +'require view.zapret2.diagnost as diagnost'; 'require view.zapret2.updater as updater'; const btn_style_neutral = 'btn'; @@ -23,6 +24,7 @@ return view.extend({ restart : elems.btn_restart || document.getElementById('btn_restart'), stop : elems.btn_stop || document.getElementById('btn_stop'), reset : elems.btn_reset || document.getElementById('btn_reset'), + diag : elems.btn_diag || document.getElementById('btn_diag'), update : elems.btn_update || document.getElementById('btn_update'), }; }, @@ -382,6 +384,10 @@ return view.extend({ btn_reset.onclick = L.bind(this.dialogResetCfg, this); layout_append(_('Reset settings to default'), null, [ btn_reset ] ); + let btn_diag = create_btn('btn_diag', btn_style_action, _('Diagnostics')); + btn_diag.onclick = ui.createHandlerFn(this, () => { diagnost.openDiagnostDialog(this.pkg_arch) }); + layout_append('', null, [ btn_diag ] ); + let btn_update = create_btn('btn_update', btn_style_action, _('Update')); btn_update.onclick = ui.createHandlerFn(this, () => { updater.openUpdateDialog(this.pkg_arch) }); layout_append(_('Update package'), null, [ btn_update ] ); @@ -394,6 +400,7 @@ return view.extend({ "btn_restart": btn_restart, "btn_stop": btn_stop, "btn_reset": btn_reset, + "btn_diag": btn_diag, "btn_update": btn_update, }; this.setAppStatus(status_array, elems); diff --git a/zapret2/dwc.sh b/zapret2/dwc.sh new file mode 100644 index 0000000..65195d8 --- /dev/null +++ b/zapret2/dwc.sh @@ -0,0 +1,118 @@ +#!/bin/sh +# Copyright (c) 2026 remittor + +. /opt/zapret/comfunc.sh + +ZAP_TMP_DIR=/tmp/zapret_dwc + +rm -rf $ZAP_TMP_DIR + +CURL_TIMEOUT=5 +CURL_RANGETO=65535 + +if ! command -v curl >/dev/null 2>&1; then + echo "ERROR: package \"curl\" not installed!" + return 10 +fi +CURL_INFO=$( curl -V ) +if ! echo "$CURL_INFO" | grep -q 'https'; then + echo "------- package curl" + echo "$CURL_INFO" + echo "-------" + echo "ERROR: package \"curl\" not supported HTTPS protocol!" + echo "NOTE: Please install package \"curl-ssl\"" + return 11 +fi + +#echo 'Original sources: https://github.com/hyperion-cs/dpi-checkers' +#echo 'WEB-version: https://hyperion-cs.github.io/dpi-checkers/ru/tcp-16-20/' + +TEST_SUITE='[ + { id: "US.CF-01", provider: "🇺🇸 Cloudflare", times: 1, url: "https://img.wzstats.gg/cleaver/gunFullDisplay" }, + { id: "US.CF-02", provider: "🇺🇸 Cloudflare", times: 1, url: "https://genshin.jmp.blue/characters/all#" }, + { id: "US.CF-03", provider: "🇺🇸 Cloudflare", times: 1, url: "https://api.frankfurter.dev/v1/2000-01-01..2002-12-31" }, + { id: "US.CF-04", provider: "🇨🇦 Cloudflare", times: 1, url: "https://www.bigcartel.com/" }, + { id: "US.DO-01", provider: "🇺🇸 DigitalOcean", times: 2, url: "https://genderize.io/" }, + { id: "DE.HE-01", provider: "🇩🇪 Hetzner", times: 1, url: "https://j.dejure.org/jcg/doctrine/doctrine_banner.webp" }, + { id: "DE.HE-02", provider: "🇩🇪 Hetzner", times: 1, url: "https://maps.gnosis.earth/ogcapi/api/swagger-ui/swagger-ui-standalone-preset.js#" }, + { id: "FI.HE-01", provider: "🇫🇮 Hetzner", times: 1, url: "https://251b5cd9.nip.io/1MB.bin" }, + { id: "FI.HE-02", provider: "🇫🇮 Hetzner", times: 1, url: "https://5fd8c176.nip.io/1MB.bin" }, + { id: "FI.HE-03", provider: "🇫🇮 Hetzner", times: 1, url: "https://5fd8bdae.nip.io/1MB.bin" }, + { id: "FI.HE-04", provider: "🇫🇮 Hetzner", times: 1, url: "https://5fd8bca5.nip.io/1MB.bin" }, + { id: "FR.OVH-01", provider: "🇫🇷 OVH", times: 1, url: "https://eu.api.ovh.com/console/rapidoc-min.js" }, + { id: "FR.OVH-02", provider: "🇫🇷 OVH", times: 1, url: "https://ovh.sfx.ovh/10M.bin" }, + { id: "SE.OR-01", provider: "🇸🇪 Oracle", times: 1, url: "https://oracle.sfx.ovh/10M.bin" }, + { id: "DE.AWS-01", provider: "🇩🇪 AWS", times: 1, url: "https://www.getscope.com/assets/fonts/fa-solid-900.woff2" }, + { id: "US.AWS-01", provider: "🇺🇸 AWS", times: 1, url: "https://corp.kaltura.com/wp-content/cache/min/1/wp-content/themes/airfleet/dist/styles/theme.css" }, + { id: "US.GC-01", provider: "🇺🇸 Google Cloud", times: 1, url: "https://api.usercentrics.eu/gvl/v3/en.json" }, + { id: "US.FST-01", provider: "🇺🇸 Fastly", times: 1, url: "https://www.jetblue.com/main.c7b61d59416f714f.js" }, + { id: "CA.FST-01", provider: "🇨🇦 Fastly", times: 1, url: "https://www.cnn10.com/" }, + { id: "US.AKM-01", provider: "🇺🇸 Akamai", times: 1, url: "https://www.roxio.com/static/roxio/images/products/creator/nxt9/call-action-footer-bg.jpg" }, + { id: "PL.AKM-01", provider: "🇵🇱 Akamai", times: 1, url: "https://media-assets.stryker.com/is/image/stryker/gateway_1?$max_width_1410$" }, + { id: "US.CDN77-01", provider: "🇺🇸 CDN77", times: 1, url: "https://cdn.eso.org/images/banner1920/eso2520a.jpg" }, + { id: "FR.CNTB-01", provider: "🇫🇷 Contabo", times: 1, url: "https://airsea.no/images/main_logo.png" }, + { id: "NL.SW-01", provider: "🇳🇱 Scaleway", times: 1, url: "https://www.velivole.fr/img/header.jpg" }, + { id: "US.CNST-01", provider: "🇺🇸 Constant", times: 1, url: "https://cdn.xuansiwei.com/common/lib/font-awesome/4.7.0/fontawesome-webfont.woff2?v=4.7.0" } +]' + +function trim +{ + echo "$1" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' +} + +mkdir -p $ZAP_TMP_DIR + +ID=0 +while IFS='|' read -r TAG PROVIDER TIMES URL; do + [ -z "$TAG" ] && continue + ID=$((ID+1)) + ID3=$(printf '%03d' "$ID") + COUNTRY="$(echo "$TAG" | cut -d. -f1)" + CNTFLAG="$(echo "$PROVIDER" | awk '{print $1}')" + PROVIDER="$(echo "$PROVIDER" | cut -d' ' -f2-)" + URL_NO_PROTO="${URL#*://}" + DOMAIN="${URL_NO_PROTO%%/*}" + URLPATH="/${URL_NO_PROTO#*/}" + [ "$URLPATH" = "/$URL_NO_PROTO" ] && URLPATH="/" + #echo "TAG=$TAG , COUNTRY=$COUNTRY , PROVIDER=$PROVIDER , TIMES=$TIMES , URL=$URL" + ( + DST_IP=$( curl -4 -s -o /dev/null -w '%{remote_ip}\n' $DOMAIN ) + if [ -z "$DST_IP" ]; then + DST_IP="$( ping -c1 "$DOMAIN" 2>/dev/null | sed -n '1s/.*(\([0-9.]*\)).*/\1/p')" + fi + curl -k $URL --resolve $DOMAIN:443:$DST_IP -o /dev/null -s -w '%{size_download}\n' --max-time $CURL_TIMEOUT --range 0-$CURL_RANGETO + ) >"$ZAP_TMP_DIR/$ID3.$TAG.txt" 2>&1 & +done <