Browse Source

Update to version 2.1.13

Safer than ever!
It starts the captive portal when tomcat is ready!
Deben Oldert 11 years ago
parent
commit
bf558ac479
1 changed files with 54 additions and 12 deletions
  1. 54 12
      captiveportal/firewall/rules.sh

+ 54 - 12
captiveportal/firewall/rules.sh

@@ -4,42 +4,85 @@
 #It is multifuncional
 #It is multifuncional
 #Initialize the new rules (startup)
 #Initialize the new rules (startup)
 #Delete a rule for an ip to grand internet access
 #Delete a rule for an ip to grand internet access
-#Display statusses
 
 
 #define version of the script
 #define version of the script
-version="V1.3.78"
+version="V2.1.13"
 #load IPTables
 #load IPTables
 IPTABLES=/sbin/iptables
 IPTABLES=/sbin/iptables
 #When it needs to initialize the rules, do this
 #When it needs to initialize the rules, do this
 if [ "$1" == "initialize" ]
 if [ "$1" == "initialize" ]
 then
 then
-#Display startup message
-echo $version
-echo "Copy right: Deben Oldert"
+#First stop host apd so people can't connect
+sudo service hostapd stop
 #Flush all existing rules
 #Flush all existing rules
 $IPTABLES -F
 $IPTABLES -F
 $IPTABLES -X
 $IPTABLES -X
 #Allow forwarding
 #Allow forwarding
 echo 1 > /proc/sys/net/ipv4/ip_forward
 echo 1 > /proc/sys/net/ipv4/ip_forward
-#Read all ips from ip file and make rule per ip
+#Boot up Wifi adapter
+echo "Booting up WiFi adapter..."
+sudo ifup wlan0
+#Add some basic rules to iptables
+while read rule
+do
+        #Execute each rule in the file
+        $($rule)
+done < /portal/firewall_Rules
 #Each ip from the list will be redirected to the captive portal
 #Each ip from the list will be redirected to the captive portal
 echo "These IP's will be redirected to the Captive Portal"
 echo "These IP's will be redirected to the Captive Portal"
 #define 1 (ip counter) and set it to zero
 #define 1 (ip counter) and set it to zero
 i=0
 i=0
+#Read all ips from ip file and make rule per ip
 #Read each line as $ip
 #Read each line as $ip
 while read ip
 while read ip
 do
 do
         #Shits getting serious now
         #Shits getting serious now
-        sudo $IPTABLES -t nat -A PREROUTING -s "$ip" -p tcp -j DNAT --to-destination 10.111.11.5:8080
+        sudo $IPTABLES -t nat -A PREROUTING -s "$ip" -p tcp -j DNAT --to-destination 10.111.11.5:80
         #Print the ip
         #Print the ip
         echo $ip
         echo $ip
         #Increment 1 on i so we can see how many ip where added
         #Increment 1 on i so we can see how many ip where added
         ((i++))
         ((i++))
-#Not the last line in file? Lets do is again!
-done < /users
+#Not the last line in file? Lets do it again!
+done < /portal/users
 #Show the amount of ip's
 #Show the amount of ip's
 echo "Added $i IP's to rule list"
 echo "Added $i IP's to rule list"
-echo "Done"
+echo "Checking if site is up (might take a while)"
+#Set 1 to one, for another counter
+i=1
+        #Lets check if our portal is online
+        #The 3 here is for the amount of times you want to check (default is 3)
+        while [ $i -le 3 ]
+        do
+                #Check if the site is online 
+                if curl -s --head http://localhost/Portal/ | head -n 1 | grep "200" >/dev/null 2>&1;
+                then
+                        #If the site is up, do this:
+                        echo "Site is up!"
+                        echo "Starting hostapd"
+                        #Start hostapd so people can connect
+                        sudo service hostapd start
+                        #Set i to 4 to break the loop
+                        i=4
+                        echo "Everything is up and running!"
+                else
+                        #If site is still down do this
+                        echo "Still checking if site is up ($i/3)"
+                        #Give Tomcat some time to think
+                        sleep 30s
+                        #Increment i with 1
+                        ((i++))
+                        #If i = 4, The site is still not up, Tell whats wrong!
+                        if [ "$i" == "4" ]
+                        then
+                                echo "Site is still not online!"
+                                echo "Exiting the program (maybe reboot)"
+                        fi
+                fi
+        done
+#Show some information
+echo "Captive Portal rule script"
+echo $version
+echo "Copy right: Deben Oldert"
 fi
 fi
 #If action is permitting acces to internet, delete rule to portal
 #If action is permitting acces to internet, delete rule to portal
 if [ "$1" == "grand" ]
 if [ "$1" == "grand" ]
@@ -48,7 +91,7 @@ then
         if [[ ! -z "$2" ]]
         if [[ ! -z "$2" ]]
         then
         then
                 #Delete the rule
                 #Delete the rule
-                sudo $IPTABLES -t nat -D PREROUTING -s $2 -p tcp -j DNAT --to-destination 10.111.11.5:8080
+                sudo -u root $IPTABLES -t nat -D PREROUTING -s $2 -p tcp -j DNAT --to-destination 10.11$
                 #Tell the system its fine
                 #Tell the system its fine
                 echo "SUCCES"
                 echo "SUCCES"
         else
         else
@@ -56,6 +99,5 @@ then
                 echo "FAIL"
                 echo "FAIL"
         fi
         fi
 fi
 fi
-
 #Uncomment for debugging
 #Uncomment for debugging
 #$IPTABLES -t nat -L PREROUTING
 #$IPTABLES -t nat -L PREROUTING