Guest User

Untitled

a guest
Jun 15th, 2025
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.61 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. KEY="<Redacted>"
  4. SECRET="<Redacted>"
  5. RULE_ID="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
  6. SOURCE_NET="fdxx:xxxx:xxxx::/64" # This is the Wiregaurd ULA prefix
  7. WAN_INTERFACE="igc0"
  8. HOST=localhost
  9.  
  10. # Get current WAN IPv6 prefix
  11. WAN_PREFIX=$(curl -sk -u "$KEY:$SECRET" "https://$HOST/api/interfaces/overview/get_interface/$WAN_INTERFACE" \
  12.   | jq -r '.message["ifctl.prefix"].value[0]')
  13.  
  14. echo "Detected WAN prefix: $WAN_PREFIX"
  15.  
  16. # Exit if WAN prefix is empty
  17. if [ -z "$WAN_PREFIX" ]; then
  18.   echo "WAN prefix is empty. Exiting."
  19.   exit 1
  20. fi
  21.  
  22. # Get current NPT rule details
  23. CURRENT_DEST_NET=$(curl -sk -u "$KEY:$SECRET" "https://$HOST/api/firewall/npt/get_rule/$RULE_ID" \
  24.   | jq -r '.rule.destination_net')
  25.  
  26. echo "Current NPT destination_net: $CURRENT_DEST_NET"
  27.  
  28. # Compare current vs new prefix
  29. if [ "$CURRENT_DEST_NET" = "$WAN_PREFIX" ]; then
  30.   # Prefix has not changed. No update needed.
  31.   exit 0
  32. fi
  33.  
  34. # Prepare JSON body
  35. JSON_BODY=$(cat <<EOF
  36. {
  37.   "rule": {
  38.     "enabled": "1",
  39.     "sequence": "1",
  40.     "log": "1",
  41.     "interface": "wan",
  42.     "source_net": "$SOURCE_NET",
  43.     "destination_net": "$WAN_PREFIX",
  44.     "trackif": "",
  45.     "categories": "",
  46.     "description": "NPTv6 - WGG"
  47.   }
  48. }
  49. EOF
  50. )
  51.  
  52. # Perform the update
  53. API_RESPONSE=$(curl -sS -k -u "$KEY:$SECRET" \
  54.   -X POST "https://$HOST/api/firewall/npt/set_rule/$RULE_ID" \
  55.   -H "Content-Type: application/json" \
  56.   -d "$JSON_BODY")
  57.  
  58.  
  59. # Check for success
  60. echo "$API_RESPONSE" | grep -q '"result":"saved"' || {
  61.   echo "Error: Failed to update rule"
  62.   exit 1
  63. }
  64.  
  65. # Restart filter upon successful
  66. /usr/local/etc/rc.filter_configure
Add Comment
Please, Sign In to add comment