Skip to content

Instantly share code, notes, and snippets.

@teawithfruit
Last active January 10, 2022 14:15
Show Gist options
  • Save teawithfruit/2dcfbf204702c056e6280d70afe2d889 to your computer and use it in GitHub Desktop.
Save teawithfruit/2dcfbf204702c056e6280d70afe2d889 to your computer and use it in GitHub Desktop.
Synology Task / AVM Fritzbox port mapping / Let's Encrypt renew

Put the fritzbox_port.sh file somewhere to your Synology system. Create a custom task entry in your Synology system options with the following code. Update the PATH_TO_SCRIPT part and run the task as root.

bash /volume1/PATH_TO_SCRIPT/fritzbox_port.sh 1
/usr/syno/sbin/syno-letsencrypt renew-all -v
bash /volume1/PATH_TO_SCRIPT/fritzbox_port.sh 0
#!/bin/bash
# VARIABLES TO UPDATE
FBIP="192.168.0.1"
FBUSER="USERNAME"
FBPASS="PASSWORD"
SYNOIP="NAS_IP"
################################################################################
# DO NOT EDIT FROM HERE
if [ "$1" == "0" ]
then
STATUS="DEACTIVATED!"
elif [ "$1" == "1" ]
then
STATUS="ACTIVATED!"
fi
location="/upnp/control/wanpppconn1"
uri="urn:dslforum-org:service:WANPPPConnection:1"
action='AddPortMapping'
SoapParamString="<NewRemoteHost>0.0.0.0</NewRemoteHost>
<NewExternalPort>80</NewExternalPort>
<NewProtocol>TCP</NewProtocol>
<NewInternalPort>80</NewInternalPort>
<NewInternalClient>$SYNOIP</NewInternalClient>
<NewEnabled>$1</NewEnabled>
<NewPortMappingDescription>Lets Encrypt</NewPortMappingDescription>
<NewLeaseDuration>0</NewLeaseDuration>"
if [ "$1" == "0" ] || [ "$1" == "1" ]
then
curl -k -m 5 --anyauth -u "$FBUSER:$FBPASS" https://$FBIP:49443$location -H 'Content-Type: text/xml; charset="utf-8"' -H "SoapAction:$uri#$action" -d "<?xml version='1.0' encoding='utf-8'?><s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><u:$action xmlns:u='$uri'>$SoapParamString</u:$action></s:Body></s:Envelope>" -s
printf "Port sharing: $STATUS"
else
printf "No expected parameter (0|1) given. Port sharing not activated."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment