FirewallD bash script project

General support questions
Post Reply
ally_uk
Posts: 24
Joined: 2012/06/08 15:17:52

FirewallD bash script project

Post by ally_uk » 2015/03/30 00:24:14

Hi Guys I recently have made the transition to Centos 7 and have been playing with firewalld I wanted to create a basic bash script
to automate the configuration process and would gradually like to add more and more advanced concepts to it with the input of you guys.
I am a noob when it comes to scripting and figured this project could benefit a few people and speed up the config process. I wish to
document the process so that others can add and gain knowledge.

The initial layout / process of the script I have in mind is the following please feel free to add / input and aid me on my quest

Since this forum is full of Linux Gods on a different level of knowledge to myself.If you have some free time please feel free input my goal is to document everything so others can gain something from this project.

-------------------------------------------------------------------------------------------------------------------------------------------

(Rough layout of Firewalld Configuration Script Version 1.0 )


1) Script loads and checks if user is running as root if not script exits:
2) User is presented with a menu with the following options: - Start firewalld, Stop, Status, disable iptables,
add service - user presented with a menu of popular services to allow through firewall i.e ssh, http, samba ( all services are added permanent )
remove service does the same as above but removes services.
add ports, remove ports ( user specifies a port range and wheter it's UDP / TCP options are made permanent)

menu options for the following? : List rules, get services, reload firewall, enable at boot?


3) Advanced configuration options - takes user to another menu with the following options:


: get default zone information
: get active zones
: get zones - show all available zones
: set default zone to : home, public,
:assign ip address to a zone:


restart: system

------------------------------------------------------------------------------------------------------------------------------------------------

I found a old script that was geared towards Iptables that is kind of similar to what I wanted to achieve I was thinking of modifying it for firewalld. I have posted a portion of the script below.

###############################IPTABLE SERVICES PROGRAM BEGINS HERE###############################
checkstatus()
{
opt_checkstatus=1
while [ $opt_checkstatus != 7 ]
do
clear
#echo -e "\nChoose the Option Bellow!!!\n
echo -e "\n\t*****Note: Save your Iptables before stop/Restart the iptables Services*****\n"
echo -e " 1. Save the iptables\n
2. Status of Iptables\n
3. Start iptables Services\n
4. Stop iptables Services\n
5. Restart iptable Services\n
6. Flush iptables (**Use Carefully_it will remove all the rules from iptables**)\n
7. Go back to Main Menu"
read opt_checkstatus
case $opt_checkstatus in

-------------------------------------------------------------------------------------------------------------------------------------------------

Being a bash scripting noob and analyzing the iptables script above mainly this section:

checkstatus()
{
opt_checkstatus=1
while [ $opt_checkstatus != 7 ]
do

I know that a function checkstatus is being declared but what does the opt_checkstatus=1 mean is that a variable?
also the while [ $opt_checkstatus != 7 ] line is confusing me aswell can somebody explain what that does?

Many Thanks :)

User avatar
AlanBartlett
Forum Moderator
Posts: 9345
Joined: 2007/10/22 11:30:09
Location: ~/Earth/UK/England/Suffolk
Contact:

Re: FirewallD bash script project

Post by AlanBartlett » 2015/03/30 14:04:38

Being a bash scripting noob and analyzing the iptables script above mainly this section:

checkstatus()
{
opt_checkstatus=1
while [ $opt_checkstatus != 7 ]
do

I know that a function checkstatus is being declared but what does the opt_checkstatus=1 mean is that a variable?
also the while [ $opt_checkstatus != 7 ] line is confusing me aswell can somebody explain what that does?
opt_checkstatus is a variable within that bash script.

opt_checkstatus=1 is assigning the integer value 1 to the variable opt_checkstatus.

while [ $opt_checkstatus != 7 ] is the starting line of a do . . . done loop. Specifically a while some condition is true do . . . done loop. The [ and ] delimit a test that controls the do . . . done loop. $opt_checkstatus is the value assigned to the opt_checkstatus variable. != means not equal to. Putting all of that together, it means that the do . . . done loop is repeated while the variable opt_checkstatus does not equal the interger 7.
Image 100% Linux and, previously, Unix. Co-founder of the ELRepo Project.

Post Reply