Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Simple script to manage iptables
- function AppMenu () {
- # Display menu and interact based on the user's input
- ### --------- ACCEPT OPTION
- 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')"
- if [[ $? -eq 0 ]]; then
- # If the user did not cancel, find out what s/he chosed
- case $varmenu in
- 1)
- # see current rules
- sudo iptables -nvL > see_rules.txt
- kdialog --textbox see_rules.txt 700 400
- ;;
- 2)
- # edit iptables_script
- kdesu kate /etc/iptables/iptables_script.sh
- ;;
- 3)
- # launch iptables_script
- sudo sh /etc/iptables/iptables_script.sh
- ;;
- 4)
- kdialog --dontagain kortafuegos:save_ktf_wng --title "Save current rules?" --warningyesno "Are you sure you want to save this rules?"
- if [[ $? -eq 0 ]]; then
- sudo iptables-save > /etc/iptables/iptables.rules
- #notification
- kdialog --title "Rules saved notification" --passivepopup \
- "Current rules was saved successfully" 10
- fi
- ;;
- 5)
- # Enabling iptables.service
- 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"
- if [[ $? -eq 0 ]]; then
- sudo systemctl enable iptables && sudo systemctl start iptables
- #notification
- kdialog --title "Service enabled notification" --passivepopup \
- "Iptables.service was enabled succesfully" 10
- fi
- ;;
- esac
- ### --------- CANCEL OPTION
- else
- # Show the text message for CANCEL option in file 'text_message.txt'
- # Note that text_message.txt should be under the same location as the script!
- kdialog --textbox text_message.txt
- fi
- return;
- }
- # Main Program
- # Welcome the user, allow for early exit if not interested
- 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"
- # If the user decided to continue, present a menu
- if [[ $? -ne 1 ]]; then
- AppMenu
- fi
Advertisement
Add Comment
Please, Sign In to add comment