rules.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #Captive portal iptables rule script
  2. #Copyright Deben Oldert
  3. #This script handles the rules for the captive portal
  4. #It is multifuncional
  5. #Initialize the new rules (startup)
  6. #Delete a rule for an ip to grand internet access
  7. #Display statusses
  8. #define version of the script
  9. version="V1.3.78"
  10. #load IPTables
  11. IPTABLES=/sbin/iptables
  12. #When it needs to initialize the rules, do this
  13. if [ "$1" == "initialize" ]
  14. then
  15. #Display startup message
  16. echo $version
  17. echo "Copy right: Deben Oldert"
  18. #Flush all existing rules
  19. $IPTABLES -F
  20. $IPTABLES -X
  21. #Allow forwarding
  22. echo 1 > /proc/sys/net/ipv4/ip_forward
  23. #Read all ips from ip file and make rule per ip
  24. #Each ip from the list will be redirected to the captive portal
  25. echo "These IP's will be redirected to the Captive Portal"
  26. #define 1 (ip counter) and set it to zero
  27. i=0
  28. #Read each line as $ip
  29. while read ip
  30. do
  31. #Shits getting serious now
  32. sudo $IPTABLES -t nat -A PREROUTING -s "$ip" -p tcp -j DNAT --to-destination 10.111.11.5:8080
  33. #Print the ip
  34. echo $ip
  35. #Increment 1 on i so we can see how many ip where added
  36. ((i++))
  37. #Not the last line in file? Lets do is again!
  38. done < /users
  39. #Show the amount of ip's
  40. echo "Added $i IP's to rule list"
  41. echo "Done"
  42. fi
  43. #If action is permitting acces to internet, delete rule to portal
  44. if [ "$1" == "grand" ]
  45. then
  46. #check if $2 (ip adress) not empty
  47. if [[ ! -z "$2" ]]
  48. then
  49. #Delete the rule
  50. sudo $IPTABLES -t nat -D PREROUTING -s $2 -p tcp -j DNAT --to-destination 10.111.11.5:8080
  51. #Tell the system its fine
  52. echo "SUCCES"
  53. else
  54. #Missing the ip parameter
  55. echo "FAIL"
  56. fi
  57. fi
  58. #Uncomment for debugging
  59. #$IPTABLES -t nat -L PREROUTING