Guest User

Untitled

a guest
Apr 2nd, 2014
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # Simple script to manage iptables
  3.  
  4. function AppMenu () {
  5. # Display menu and interact based on the user's input
  6.  
  7. ### --------- ACCEPT OPTION    
  8. varmenu="$(kdialog --menu "Choose from one of the options below:" 1 'See current rules' 2 'Edit iptables_script' 3 'Launch iptables_script' 4 'Save curren rules' 5 'Enabl iptables.service')"
  9.    
  10. if [[ $? -eq 0 ]]; then
  11.   # If the user did not cancel, find out what s/he chosed
  12.   case $varmenu in
  13.    
  14.     1)
  15.       # see current rules
  16.       sudo iptables -nvL > see_rules.txt
  17.       kdialog --textbox see_rules.txt 700 400
  18.       ;;
  19.    
  20.     2)
  21.       # edit iptables_script
  22.       kdesu kate /etc/iptables/iptables_script.sh
  23.       ;;
  24.    
  25.     3)
  26.       # launch iptables_script
  27.       sudo sh /etc/iptables/iptables_script.sh
  28.       ;;
  29.      
  30.      4)
  31.      kdialog --dontagain kortafuegos:save_ktf_wng --title "Save current rules?" --warningyesno "Are you sure you want to save this rules?"
  32.      if [[ $? -eq 0 ]]; then
  33.      sudo iptables-save > /etc/iptables/iptables.rules
  34.      #notification
  35.      kdialog --title "Rules saved notification" --passivepopup \
  36.      "Current rules was saved successfully" 10
  37.      fi
  38.       ;;
  39.      
  40.      5)
  41.      # Enabling iptables.service
  42.      kdialog --dontagain kortafuegos:enable_service_wng --title "Enable iptables.service?" --warningyesno "Are you sure you want to enable iptables.service? This is only needed once"
  43.      if [[ $? -eq 0 ]]; then
  44.      sudo systemctl enable iptables && sudo systemctl start iptables
  45.      #notification
  46.      kdialog --title "Service enabled notification" --passivepopup \
  47.      "Iptables.service was enabled succesfully" 10
  48.     fi
  49.      ;;
  50.   esac
  51.  
  52. ### --------- CANCEL OPTION
  53. else
  54.   # Show the text message for CANCEL option in file 'text_message.txt'
  55.   # Note that text_message.txt should be under the same location as the script!
  56.   kdialog --textbox text_message.txt
  57. fi
  58.  
  59. return;
  60. }
  61.  
  62. # Main Program
  63. # Welcome the user, allow for early exit if not interested
  64. kdialog --dontagain kortafuegos:welcome_ktf_msg --title "Welcome to Kortafuegos" --yesno "Welcome to Kortafuegos, this script will let you manage easily a firewall based on iptables.  \nPlease, click OK to Continue or CANCEL to exit"
  65.  
  66. # If the user decided to continue, present a menu
  67. if [[ $? -ne 1 ]]; then
  68. AppMenu
  69. fi
Advertisement
Add Comment
Please, Sign In to add comment