From f26fb1950791b1d60d618c91dfaeacdce72e80ce Mon Sep 17 00:00:00 2001 From: Santa-Claus_16 Date: Mon, 6 Oct 2025 15:35:49 +0300 Subject: [PATCH] Add warp6.sh --- warp6.sh | 133 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100755 warp6.sh diff --git a/warp6.sh b/warp6.sh new file mode 100755 index 0000000..ec6cbc4 --- /dev/null +++ b/warp6.sh @@ -0,0 +1,133 @@ +#!/bin/sh + +URL='https://generator-warp-config.vercel.app/warp4d?dns=1.1.1.1%2C%201.0.0.1%2C%202606%3A4700%3A4700%3A%3A1111%2C%202606%3A4700%3A4700%3A%3A1001&allowedIPs=0.0.0.0%2F0%2C%20%3A%3A%2F0' +TMP_JSON="/tmp/warp.json" +TMP_CONF="/tmp/warp_decoded.conf" + +fail() { + echo "Error: $*" >&2 + exit 1 +} + +need() { + command -v "$1" >/dev/null 2>&1 || return 1 + return 0 +} + +if ! need curl; then + fail "curl is required. Please install curl (opkg update && opkg install curl)." +fi + +if ! need amneziawg; then + fail "amneziawg is required. Please install amneziawg 1.5+" +fi + +curl -fsSL -A 'curl-openwrt/warp-fetch' "$URL" -o "$TMP_JSON" +if [ $? -ne 0 ]; then + fail "Failed to download $URL" +fi + +CONTENT=$(grep -o '"content":"[^"]*"' "$TMP_JSON" | sed -e 's/^"content":"//' -e 's/"$//' | tr -d '\r\n') +if [ -z "$CONTENT" ]; then + fail "Field 'content' not found in JSON" +fi + +decode_base64_to_file() { + out="$1" + printf '%s' "$CONTENT" | awk ' + BEGIN { + b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + for(i=1;i<=length(b64);i++) map[substr(b64,i,1)] = i-1; + } + { + gsub(/[^A-Za-z0-9+\/=]/,"",$0) + line=line$0 + } + END { + len=length(line) + for(i=1;i<=len;i+=4){ + a_c=substr(line,i,1); b_c=substr(line,i+1,1); c_c=substr(line,i+2,1); d_c=substr(line,i+3,1); + if(a_c==""||b_c=="") break; + a=(a_c in map)?map[a_c]:0; + b=(b_c in map)?map[b_c]:0; + byte1=a*4+int(b/16); printf("%c",byte1); + if(c_c!="="&&c_c!=""){c=(c_c in map)?map[c_c]:0; byte2=(b%16)*16+int(c/4); printf("%c",byte2); + if(d_c!="="&&d_c!=""){d=(d_c in map)?map[d_c]:0; byte3=(c%4)*64+d; printf("%c",byte3)}}} + }' > "$out" +} + +decode_base64_to_file "$TMP_CONF" +if [ $? -ne 0 ]; then + fail "Failed to decode content" +fi + +getval() { + key="$1" + grep -m1 "^$key" "$TMP_CONF" 2>/dev/null | sed -e "s/^$key[[:space:]]*=[[:space:]]*//" +} + +PRIVATE_KEY=$(getval "PrivateKey" || true) +PUBLIC_KEY=$(getval "PublicKey" || true) +ADDR_LINE=$(getval "Address" || true) +ENDPOINT=$(getval "Endpoint" || true) + +ENDPOINT_DOMAIN="${ENDPOINT%%:*}" +ENDPOINT_PORT="${ENDPOINT##*:}" + +IPV6=$(printf '%s' "$ADDR_LINE" | awk -F',' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//') + +[ -n "$IPV6" ] && case "$IPV6" in */*) IPV6_MASK="$IPV6" ;; *) IPV6_MASK="${IPV6}/128" ;; esac + +for var in PRIVATE_KEY IPV6_MASK ENDPOINT_DOMAIN ENDPOINT_PORT PUBLIC_KEY; do + eval val=\$$var + if [ -z "$val" ]; then + echo "Error: variable $var is empty, aborting" >&2 + exit 1 + fi +done + +uci -q del network.wan6 +uci -q del network.@amneziawg_wan6[0] +uci -q commit network + +I1="" + +uci -q set network.wan6=interface +uci -q set network.wan6.proto="amneziawg" +uci -q set network.wan6.nohostroute="1" +uci -q set network.wan6.private_key="$PRIVATE_KEY" +uci -q set network.wan6.addresses="$IPV6_MASK" +uci -q set network.wan6.awg_jc="4" +uci -q set network.wan6.awg_jmin="40" +uci -q set network.wan6.awg_jmax="70" +uci -q set network.wan6.awg_s1="0" +uci -q set network.wan6.awg_s2="0" +uci -q set network.wan6.awg_h1="1" +uci -q set network.wan6.awg_h2="2" +uci -q set network.wan6.awg_h3="3" +uci -q set network.wan6.awg_h4="4" +uci -q set network.wan6.awg_i1="$I1" +uci -q set network.@amneziawg_wan6[0]=amneziawg + +uci -q add network amneziawg_wan6 >/dev/null 2>&1 +uci -q set network.@amneziawg_wan6[0]=amneziawg_wan6 +uci -q set network.@amneziawg_wan6[0].description="wan6" +uci -q set network.@amneziawg_wan6[0].endpoint_host="$ENDPOINT_DOMAIN" +uci -q set network.@amneziawg_wan6[0].endpoint_port="$ENDPOINT_PORT" +uci -q set network.@amneziawg_wan6[0].public_key="$PUBLIC_KEY" +uci -q set network.@amneziawg_wan6[0].persistent_keepalive="25" +uci -q set network.@amneziawg_wan6[0].route_allowed_ips="1" +uci -q set network.@amneziawg_wan6[0].allowed_ips="::/0" +uci -q commit network + +ifup wan6 + +uci -q set dhcp.lan.ra_default="1" +uci -q commit dhcp +service odhcpd restart + +uci -q set firewall.@zone[1].masq6="1" +uci -q commit firewall +service firewall restart + +rm -f "$TMP_JSON" "$TMP_CONF"