Browse Source

cron entry to update external IP for vpn

Bob Mottram 7 years ago
parent
commit
d73f5a6785
1 changed files with 18 additions and 0 deletions
  1. 18
    0
      src/freedombone-utils-firewall

+ 18
- 0
src/freedombone-utils-firewall View File

110
     echo 1 > /proc/sys/net/ipv6/conf/all/forwarding
110
     echo 1 > /proc/sys/net/ipv6/conf/all/forwarding
111
 }
111
 }
112
 
112
 
113
+function firewall_update_external_ip {
114
+    ip_update_script=/usr/bin/externalipupdate
115
+    echo '#!/bin/bash' >> $ip_update_script
116
+    echo "existing_ip=\$(cat $CONFIGURATION_FILE | grep \"EXTERNAL_IPV4_ADDRESS=\" | head -n 1 | awk -F '=' '{print \$2}')'" >> $ip_update_script
117
+    echo "curr_ip=\$(nslookup . $EXTERNAL_IP_LOOKUP_URL | grep Address | tail -n 1 | awk -F ' ' '{print \$2}')" >> $ip_update_script
118
+    echo 'if [[ "$curr_ip" != "$existing_ip" ]]; then' >> $ip_update_script
119
+    echo "  sed -i \"s|EXTERNAL_IPV4_ADDRESS=.*|EXTERNAL_IPV4_ADDRESS=\${curr_ip}|g\" $CONFIGURATION_FILE" >> $ip_update_script
120
+    echo "  iptables -t nat -D POSTROUTING -s \${curr_ip}/24 -o ${FIREWALL_EIFACE} -j MASQUERADE" >> $ip_update_script
121
+    echo "  iptables -t nat -A POSTROUTING -s \${curr_ip}/24 -o ${FIREWALL_EIFACE} -j MASQUERADE" >> $ip_update_script
122
+    echo '  iptables-save > /etc/firewall.conf' >> $ip_update_script
123
+    echo 'fi' >> $ip_update_script
124
+
125
+    cron_add_mins 10 $ip_update_script
126
+}
127
+
113
 function firewall_disable_vpn {
128
 function firewall_disable_vpn {
114
     read_config_param EXTERNAL_IPV4_ADDRESS
129
     read_config_param EXTERNAL_IPV4_ADDRESS
115
     if [ ! $EXTERNAL_IPV4_ADDRESS ]; then
130
     if [ ! $EXTERNAL_IPV4_ADDRESS ]; then
116
         return
131
         return
117
     fi
132
     fi
133
+    sed -i '/externalipupdate/d' /etc/crontab
118
     iptables -D INPUT -i ${FIREWALL_EIFACE} -m state --state NEW -p udp --dport 1194 -j ACCEPT
134
     iptables -D INPUT -i ${FIREWALL_EIFACE} -m state --state NEW -p udp --dport 1194 -j ACCEPT
119
     iptables -D INPUT -i tun+ -j ACCEPT
135
     iptables -D INPUT -i tun+ -j ACCEPT
120
     iptables -D FORWARD -i tun+ -j ACCEPT
136
     iptables -D FORWARD -i tun+ -j ACCEPT
136
     iptables -A OUTPUT -o tun+ -j ACCEPT
152
     iptables -A OUTPUT -o tun+ -j ACCEPT
137
     write_config_param EXTERNAL_IPV4_ADDRESS "$curr_external_ipv4_address"
153
     write_config_param EXTERNAL_IPV4_ADDRESS "$curr_external_ipv4_address"
138
     save_firewall_settings
154
     save_firewall_settings
155
+
156
+    firewall_update_external_ip
139
 }
157
 }
140
 
158
 
141
 function configure_firewall {
159
 function configure_firewall {