The entire script uses the control flow loop statement) to achieve an interactive effect, and then uses judgment and read to achieve configuration.
Although there are more than 200 lines of code, the structure is clear and clear at a glance!
However, in order to take the table and add a lot of font colors, not only for interactive experience, but also to make the keywords or prompts more eye-catching.
You can also use this structure to configure other services. I personally feel that the interactive configuration is more intuitive and concise. I have written several similar interactive configuration scripts that are often used at work.
Code,AppendixRun:
#! /Bin/bashwhile truedoclearecho "-------- menu --------" echo-e "\ 033 [49; 32; 1 m (1) Restart \ 033 [49; 35; 1miptables \ 033 [0 m "echo-e" \ 033 [49; 32; 1 m (2) Add \ 033 [49; 35; 1miptables \ 033 [49; 32; 1 m RULE \ 033 [0 m "echo-e" \ 033 [49; 32; 1 m (3) Delete \ 033 [49; 35; 1miptables \ 033 [49; 32; 1 m RULE \ 033 [0 m "echo-e" \ 033 [49; 32; 1 m (4) Close \ 033 [49; 35; 1miptables \ 033 [0 m "echo-e" \ 033 [49; 32; 1 m (5) Save \ 033 [49; 35; 1miptables \ 033 [49; 32; 1 m rule (remember to save and view the ACL after the ACL is entered) \ 033 [0 M "echo-e" \ 033 [49; 32; 1 m (6) view \ 033 [49; 35; 1miptables \ 033 [49; 32; 1 m status \ 033 [0 m "echo-e" \ 033 [49; 32; 1 m (7) add \ 033 [49; 35; 1miptables \ 033 [49; 32; 1 m Control List \ 033 [0 m "echo-e" \ 033 [49; 32; 1 m (0) exit script \ 033 [0 m "echo" ------------------ "echo-en" \ 033 [49; 31; 1 m enter the number 0-7: \ 033 [0 m "read numif [[" $ {num} "= ~ "^ $"]; Thenecho-e "\ 033 [49; 31; 5 m. Enter a number from 0 to 7! Or press Ctrl + C to exit! \ 033 [0 m "elseif [[" $ {num} "= ~ "^ [A-zA-Z] + $"]; thenecho-e "\ 033 [49; 31; 5 m. Enter a number from 0 to 7! Or press Ctrl + C to exit! \ 033 [0 m "else # if [$ {num}-lt 0-o $ {num}-gt 7] if [" $ {num} "= ~ "[8-9]"]; thenecho-e "\ 033 [49; 31; 5 m, enter a number from 0 to 7! Or press Ctrl + C to exit! \ 033 [0 m "elseif [" $ {num} "=" 1 "] thenservice iptables restart & elseif [" $ {num} "=" 2 "] # ######################################## ############ thenwhile truedoclearecho "-------- add ACL -------" echo-e "\ 033 [49; 32; 1 m (1) for source \ 033 [49; 35; 1mIP \ 033 [49; 32; 1 m allow add \ 033 [0 m "echo-e" \ 033 [49; 32; 1 m (2) for servers \ 033 [49; 35; 1 m port \ 033 [49; 32; 1 m allow add \ 033 [0 m "echo-e" \ 033 [49; 32; 1 m (3) for rules with \ 033 [49; 35; 1mIP and port \ 033 [49; 32; 1 MB Add \ 033 [49; 35; 1 m here the parameter IP address and port such as 1.1.1.1/255.255.0.0 80) \ 033 [0 m "echo-e" \ 033 [49; 32; 1 m (4) complete custom statement add \ 033 [0 m "echo-e" \ 033 [49; 32; 1 m (0) back to level 1 \ 033 [0 m "echo" -------------------- "echo-en" \ 033 [49; 31; 1 m, enter the number 0-4: \ 033 [0 m "read aclnumif [[" $ {aclnum} "= ~ "^ $"]; Thenecho-e "\ 033 [49; 31; 5 m, enter a number in 0-4! Or press Ctrl + C to exit! \ 033 [0 m "elseif [[" $ {aclnum} "= ~ "^ [A-zA-Z] + $"]; thenecho-e "\ 033 [49; 31; 5 m, enter a number in 0-4! Or press Ctrl + C to exit! \ 033 [0 m "elseif [[" $ {aclnum} "= ~ "[5-9]"]; thenecho-e "\ 033 [49; 31; 5 m, enter a number in 0-4! Or press Ctrl + C to exit! \ 033 [0 m "elif [" $ {aclnum} "=" 1 "] thenread ipiptables-a input-s $ {ip}-p tcp-j ACCEPTservice iptables saveelif ["$ {aclnum}" = "2"] thenread portiptables-a input-p tcp-s 0/0 -- dport $ {port}-j ACCEPTservice iptables saveelif ["$ {aclnum} "=" 3 "] thenread ip portiptables-a input-p tcp-s $ {ip} -- dport $ {port}-j ACCEPTservice iptables saveelif [" $ {aclnum }" = "4"] thenread addacl '$ {adda Cl} 'service iptables saveelsebreak1_ifiecho-n ": Do you want to add more? Press ENTER or Y to continue. Press N to return to the upper level!: [Y/n]: "read contineif [" $ {contine} "=" n "-o" $ {contine} "=" N "] thenbreakfidone ########## ######################################## ##### elseif ["$ {num}" = "3"] thenwhile truedoclearecho "------- delete ACL --------" echo-e "\ 033 [49; 32; 1 m (1) for source \ 033 [49; 35; 1mIP \ 033 [49; 32; 1 m Delete \ 033 [0 m "echo-e" \ 033 [49; 32; 1 m (2) for servers \ 033 [49; 35; 1 m port \ 033 [49; 32; 1 m Delete \ 033 [0 m "echo-e" \ 033 [49; 32; 1 m (3) for \ 033 [49; 35; 1mI P and port \ 033 [49; 32; 1 m RULE deletion \ 033 [49; 35; 1 m here the parameter IP address and port such as 1.1.1.1/255.255.0.0 80) \ 033 [0 m "echo-e" \ 033 [49; 32; 1 m (4) delete the complete custom statement \ 033 [0 m "echo-e" \ 033 [49; 32; 1 m (0) back to level 1 \ 033 [0 m "echo" ----------------- "echo-en" \ 033 [49; 31; 1 m, enter the number 0-4: \ 033 [0 m "read aclnumif [[" $ {aclnum} "= ~ "^ $"]; Thenecho-e "\ 033 [49; 31; 5 m, enter a number in 0-4! Or press Ctrl + C to exit! \ 033 [0 m "elseif [[" $ {aclnum} "= ~ "^ [A-zA-Z] + $"]; thenecho-e "\ 033 [49; 31; 5 m, enter a number in 0-4! Or press Ctrl + C to exit! \ 033 [0 m "elseif [[" $ {aclnum} "= ~ "[5-9]"]; thenecho-e "\ 033 [49; 31; 5 m, enter a number in 0-4! Or press Ctrl + C to exit! \ 033 [0 m "elif [" $ {aclnum} "=" 1 "] thenread ipiptables-d input-s $ {ip}-p tcp-j ACCEPTservice iptables saveelif ["$ {aclnum}" = "2"] thenread portiptables-d input-p tcp-s 0/0 -- dport $ {port}-j ACCEPTservice iptables saveelif ["$ {aclnum} "=" 3 "] thenread ip portiptables-d input-p tcp-s $ {ip} -- dport $ {port}-j ACCEPTservice iptables saveelif [" $ {aclnum }" = "4"] thenread deleteacl '$ {d Eleteacl} 'service iptables saveelsebreakincluifiecho-n ": whether to delete the table. Press ENTER or Y to continue. Press N to return to the upper level!: [Y/n]: "read contineif [" $ {contine} "=" n "-o" $ {contine} "=" N "] thenbreakfidone ########## ######################################## ################ elseif ["$ {num}" = "4"] thenecho-e "'service iptables stop & '"elseif [" $ {num} "=" 5 "] thenecho-e" 'service iptables save &' "elseif [" $ {num} "=" 6"] thenecho-e "'service iptables status & '" else ########################### ####################### ############### If ["$ {num}" = "7"] thenwhile truedoclearecho "------- list ACL --------" echo- e "\ 033 [49; 32; 1 m (1) view the currently used rule set \ 033 [0 m "echo-e" \ 033 [49; 32; 1 m (2) view simple traffic statistics for each policy or rule and chain \ 033 [0 m "echo-e" \ 033 [49; 32; 1 m (3) view NAT table \ 033 [0 m "echo-e" \ 033 [49; 32; 1 m (4) custom view \ 033 [0 m "echo-e" \ 033 [49; 32; 1 m (0) return to level 1 \ 033 [0 m "echo" ----------------- "echo-en" \ 033 [49; 31; 1 m. Enter the number 0-4: \ 033 [0 m "read aclnumif [[" $ {Aclnum} "= ~ "^ $"]; Thenecho-e "\ 033 [49; 31; 5 m, enter a number in 0-4! Or press Ctrl + C to exit! \ 033 [0 m "elseif [[" $ {aclnum} "= ~ "^ [A-zA-Z] + $"]; thenecho-e "\ 033 [49; 31; 5 m, enter a number in 0-4! Or press Ctrl + C to exit! \ 033 [0 m "elseif [[" $ {aclnum} "= ~ "[5-9]"]; thenecho-e "\ 033 [49; 31; 5 m, enter a number in 0-4! Or press Ctrl + C to exit! \ 033 [0 m "elif [" $ {aclnum} "=" 1 "] theniptables-Lelif [" $ {aclnum} "=" 2 "] theniptables-L- n-velif ["$ {aclnum}" = "3"] theniptables-L-t natelif ["$ {aclnum}" = "4"] thenread listacl '$ {listacl} 'elsebreakpolicifiecho-n ": Do you want to continue viewing, press ENTER or Y to continue. Press N to return to the upper level!: [Y/n]: "read contineif [" $ {contine} "=" n "-o" $ {contine} "=" N "] thenbreakfidone ########## ###################################### elseexit#ifififififififiecho- n "Press ENTER or Y to return the upper level, press N to exit the program! [Y/n]: "read contineif [" $ {contine} "=" n "-o" $ {contine} "=" N "] thenexitfidone
650) this. width = 650; "style =" float: none; "title =" 1.jpg" alt = "wKiom1LFIJHyOSmXAABrF6VLgyg131.jpg" src = "http://www.bkjia.com/uploads/allimg/140112/20594322U-0.jpg"/>
650) this. width = 650; "style =" float: none; "title =" 2.jpg" alt = "wKioL1LFIITi4GW_AABUcUDaypo463.jpg" src = "http://www.bkjia.com/uploads/allimg/140112/2059435S0-1.jpg"/>
650) this. width = 650; "title =" 3.jpg" src = "http://www.bkjia.com/uploads/allimg/140112/2059436414-2.jpg" alt = "wKioL1LFIXXzoaiuAAFtgmU98Is086.jpg"/>
650) this. width = 650; "style =" float: none; "title =" 4.jpg" alt = "wKioL1LFIIXxXgHNAABIa8CNqzM466.jpg" src = "http://www.bkjia.com/uploads/allimg/140112/205943K60-3.jpg"/>
This article is from the Tuesday blog, please be sure to keep this source http://cuimk.blog.51cto.com/6649029/1347743