2016-04-01 04:59:50 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								#!/bin/bash
 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								###################################################################### 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-03 05:27:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								#                      STRATUX HOSTAPD MANAGER                      # 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								###################################################################### 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								#Set Script Name variable 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								SCRIPT = ` basename ${ BASH_SOURCE [0] } ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								#Initialize variables to default values. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								OPT_S = false 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								OPT_C = false 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								OPT_E = false 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								OPT_O = false 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 14:15:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								OPT_P = false 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								OPT_Q = false 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 19:20:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								defaultPass = "SquawkDirtyToMe!" 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								parm = "*" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								err = "####" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								att = "+++" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								#Set fonts for Help. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								BOLD = $( tput bold) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								STOT = $( tput smso) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								UNDR = $( tput smul) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								REV = $( tput rev) 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 04:59:50 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								RED = $( tput setaf 1) 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								GREEN = $( tput setaf 2) 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 04:59:50 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								YELLOW = $( tput setaf 3) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								MAGENTA = $( tput setaf 5) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								WHITE = $( tput setaf 7) 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								NORM = $( tput sgr0) 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 04:59:50 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								NORMAL = $( tput sgr0) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								#Help function 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  HELP { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  echo  -e \\ n" Help documentation for  ${ BOLD } ${ SCRIPT } . ${ NORM } " \\ n
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 14:28:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  echo  -e " ${ REV } Basic usage: ${ NORM }   ${ BOLD } $SCRIPT  -s ssid -c chan -p pass  ${ NORM } " \\ n
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  echo  "The following command line switches are recognized." 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  echo  " ${ REV } -s ${ NORM }   --Sets the SSID to  ${ BOLD } ssid ${ NORM } . \"-s stratux\" " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  echo  " ${ REV } -c ${ NORM }   --Sets the channel to  ${ BOLD } chan ${ NORM } . \"-c 1\" " 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 14:15:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  echo  " ${ REV } -o ${ NORM }   --Turns off encryption and sets network to open. Cannot be used with -e or -p. " 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 14:28:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  echo  " ${ REV } -e ${ NORM }   --Turns on encryption with passphrase  ${ BOLD } $defaultPass {NORM}. Cannot be used with -o or -p " 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 14:15:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  echo  " ${ REV } -p ${ NORM }   --Turns on encryption with your chosen passphrase  ${ BOLD } pass ${ NORM } . 8-63 Printable Characters(ascii 32-126). Cannot be used with -o or -e. \"-p password!\" " 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 14:28:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  echo  " ${ REV } -q ${ NORM }   --Run silently. Still a work in progress, but quieter. " 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  echo  -e " ${ REV } -h ${ NORM }   --Displays this help message. No further functions are performed. " \\ n
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 14:28:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  echo  -e " Example:  ${ BOLD } $SCRIPT  -s Stratux-N3558D -c 5 -p SquawkDirty! ${ NORM } " \\ n
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  exit  1 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 04:59:50 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 14:15:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								confirm( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									# call with a prompt string or use a default 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									read  -r -p " $1   "  response
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									case  " $response "  in
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										[ yY] [ eE] [ sS] | [ yY] )  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										true 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									; ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										*) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										exit  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									; ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									esac 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								#apply settings and restart all processes 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  APPLYSETTINGSLOUD { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									echo  " ${ RED } ${ BOLD }   $att  At this time the script will restart your WiFi services. ${ WHITE } ${ NORMAL } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									echo  " If you are connected to Stratux through the  ${ BOLD } 192.168.10.1 ${ NORMAL }  interface then you will be disconnected " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									echo  "Please wait 1 min and look for the new SSID on your wireless device." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									sleep 3 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									echo  " ${ YELLOW } $att  Restarting Stratux WiFi Services...  $att   ${ WHITE } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									echo  " ${ YELLOW } $att  SSH will now  disconnect if connected to http://192.168.1.10 ...  $att   ${ WHITE } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									echo  "Killing hostapd..." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									sleep 2 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									/usr/bin/killall -9 hostapd hostapd-edimax
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									echo  "Killed..." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									echo  "" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									echo  "Killing DHCP Server..." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									echo  "" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									/usr/sbin/service isc-dhcp-server stop
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									sleep 0.5
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									echo  "Killed..." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									echo  "" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									echo  "ifdown wlan0..." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ifdown wlan0
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									sleep 0.5
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									echo  "ifup wlan0..." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									echo  "Calling Stratux WiFI Start Script(stratux-wifi.sh)..." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ifup wlan0
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									sleep 0.5
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									echo  "" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									echo  "" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									echo  "All systems should be up and running and you should see your new SSID!" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								function  APPLYSETTINGSQUIET { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									sleep 2 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									/usr/bin/killall -9 hostapd hostapd-edimax
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									sleep 1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									/usr/sbin/service isc-dhcp-server stop
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									sleep 0.5
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ifdown wlan0
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									sleep 0.5
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ifup wlan0
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									sleep 0.5
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								clear
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 14:15:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								echo  "" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								echo  "#### Stratux HOSTAPD Settings ####" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								echo  "" 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 04:59:50 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								if  [  $( whoami)  !=  'root'  ] ;  then 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									echo  " ${ BOLD } ${ RED } This script must be executed as root, exiting... ${ WHITE } ${ NORMAL } " 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 14:15:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									echo  " ${ BOLD } ${ RED } USAGE ${ WHITE } ${ NORMAL } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									exit  1 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 04:59:50 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								fi 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								#Check the number of arguments. If none are passed, print help and exit. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								NUMARGS = $# 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								if  [  $NUMARGS  -eq 0  ] ;  then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  HELP
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 04:59:50 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								fi 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								### Start getopts code ### 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 04:59:50 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								#Parse command line flags 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								#If an option should be followed by an argument, it should be followed by a ":". 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 14:15:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								#Notice there is no ":" after "eoqh". The leading ":" suppresses error messages from 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								#getopts. This is required to get my unrecognized option code to work. 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 14:15:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								options = ':s:c:p:eoqh' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								#options=':s:c:h' 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								while  getopts  $options  option;  do 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  case  $option  in
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    s)   #set option "s" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      if  [ [  -z " ${ OPTARG } "  ||  " ${ OPTARG } "  = =  *[ [ :space:] ] * ||  " ${ OPTARG } "  = =  -* ] ] ;  then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          echo  " ${ BOLD } ${ RED } $err  No SSID for -s, exiting... ${ WHITE } ${ NORMAL } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          exit  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          OPT_S = $OPTARG 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          echo  " $parm  SSID Option -s used:  $OPT_S " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          echo  " ${ GREEN }     SSID will now be  ${ BOLD } ${ UNDR } $OPT_S ${ NORMAL } . ${ WHITE } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      fi 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      ; ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    c)   #set option "c" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      if  [ [  -z " ${ OPTARG } "  ||  " ${ OPTARG } "  = =  *[ [ :space:] ] * ||  " ${ OPTARG } "  = =  -* ] ] ;  then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          echo  " ${ BOLD } ${ RED } $err  Channel option(-c) used without value, exiting...  ${ WHITE } ${ NORMAL } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          exit  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          OPT_C = $OPTARG 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          echo  " $parm  Channel option -c used:  $OPT_C " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          if  [ [  " $OPT_C "  = ~ ^[ 0-9] +$ ] ]  &&  [  " $OPT_C "  -ge 1  -a " $OPT_C "  -le 13   ] ;  then 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-24 17:00:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								          	echo  " ${ GREEN }     Channel will now be set to  ${ BOLD } ${ UNDR } $OPT_C ${ WHITE } ${ NORMAL } . " 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								          else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            echo  " ${ BOLD } ${ RED } $err  Channel is not within acceptable values, exiting... ${ WHITE } ${ NORMAL } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            exit  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          fi 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      fi 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      ; ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 14:15:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    e)   #set option "e" with default passphrase 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  [ [  -z " ${ OPTARG } "  ||  " ${ OPTARG } "  = =  *[ [ :space:] ] * ||  " ${ OPTARG } "  = =  -* ] ] ;  then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          echo  " $parm  Encrypted WiFI Option -e used. " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          OPT_E = $defaultPass 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										  echo  " ${ GREEN }      WiFi will be encrypted using  ${ BOLD } ${ UNDR } $OPT_E ${ NORMAL } ${ GREEN }  as the passphrase! ${ WHITE } ${ NORMAL } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          echo  " ${ BOLD } ${ RED } $err  Option -e does not require arguement. ${ WHITE } ${ NORMAL } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          exit  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      fi 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      ; ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									p)  #set encryption with user specified passphrase 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  [ [  -z " ${ OPTARG } "  ||  " ${ OPTARG } "  = ~ ^[ [ :space:] ] *$ ||  " ${ OPTARG } "  = =  -* ] ] ;  then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											echo  " ${ BOLD } ${ RED } $err  Encryption option(-p) used without passphrase! ${ WHITE } ${ NORMAL } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											echo  " ${ BOLD } ${ RED } $err  Encryption option(-p) required an arguement \"-p passphrase\"  ${ WHITE } ${ NORMAL } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											OPT_P = $OPTARG 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										fi 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										echo  " $parm  Encryption option -p used: " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  [  -z ` echo  $OPT_P  |  tr -d "[:print:]" `  ]  &&  [  ${# OPT_P }  -ge 8  ]   &&  [  ${# OPT_P }  -le 63  ] ;  then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											echo  " ${ GREEN }      WiFi will be encrypted using  ${ BOLD } ${ UNDR } $OPT_P ${ NORMAL } ${ GREEN }  as the passphrase! ${ WHITE } ${ NORMAL } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											echo   " ${ BOLD } ${ RED } $err  Invalid PASSWORD: 8 - 63 printable characters, exiting... ${ WHITE } ${ NORMAL } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										exit  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										fi 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ; ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    o)   #set option "o" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      if  [ [  -z " ${ OPTARG } "  ||  " ${ OPTARG } "  = =  *[ [ :space:] ] * ||  " ${ OPTARG } "  = =  -* ] ] ;  then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          echo  " $parm  Open WiFI Option -o used. " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          echo  " ${ GREEN }     WiFi will be set to  ${ BOLD } ${ UNDR } OPEN ${ NORMAL } ${ GREEN }  or  ${ BOLD } ${ UNDR } UNSECURE ${ WHITE } ${ NORMAL } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          OPT_O = true 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          echo  " ${ BOLD } ${ RED } $err  Option -o does not require arguement. ${ WHITE } ${ NORMAL } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          exit  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      fi 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      ; ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 14:15:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    q) 	 #set Quiet mode 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										OPT_Q = true 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      ; ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    h)   #show help 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      HELP
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      ; ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								   \? )  # invalid option 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-24 17:00:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     echo  " ${ BOLD } ${ RED } $err  Invalid option - $OPTARG   ${ WHITE } ${ NORMAL } "  >& 2 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 14:15:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     HELP
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     exit  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     ; ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								   :)  # Missing Arg  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     echo  " ${ BOLD } ${ RED } $err  Missing option for argument - $OPTARG   ${ WHITE } ${ NORMAL } "  >& 2 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 14:15:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     HELP
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     exit  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     ; ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								   *)  # Invalid 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     echo  " ${ BOLD } ${ RED } $err  Unimplemented option - $OPTARG   ${ WHITE } ${ NORMAL } "  >& 2 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 14:15:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     HELP
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     exit  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								     ; ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  esac 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								done 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 04:59:50 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								shift  $(( OPTIND-1))   #This tells getopts to move on to the next argument. 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 04:59:50 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								### End getopts code ### 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 04:59:50 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								### Main loop to process files ### 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 04:59:50 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								#This is where your main file processing will take place. This example is just 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								#printing the files and extensions to the terminal. You should place any other 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								#file processing tasks within the while-do loop. 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 04:59:50 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 14:15:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								if  [ [  $OPT_O  = =  true   &&  (   $OPT_E  !=  false  ||  $OPT_P  !=  false  )  ] ] ;  then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  echo  " ${ BOLD } ${ RED } $err  Option -e , -p and -o cannot be used simultaneously  ${ WHITE } ${ NORMAL } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  exit  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								fi 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								if  [  $OPT_P  !=  false  ]  &&  [  $OPT_E  !=  false  ] ;  then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  echo  " ${ BOLD } ${ RED } $err  Option -e and -p cannot be used simultaneously  ${ WHITE } ${ NORMAL } " 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  exit  1 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 04:59:50 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								fi 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								echo  "" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								echo  " ${ BOLD } No errors found. Continuning... ${ NORMAL } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								echo  "" 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 04:59:50 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 14:15:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								if  [  $OPT_Q  = =  false  ] ;  then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									confirm "Are you ready to apply these settings? [y/n]" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								fi 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# files to edit 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-23 20:54:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								HOSTAPD = ( '/etc/hostapd/hostapd.user' ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 04:59:50 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								#### 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								#### File modification loop 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								#### 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								for  i in " ${ HOSTAPD [@] } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								do 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  if  [  -f ${ i }  ] ;  then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    echo  " Working on  $i ... " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  [  $OPT_S  !=  false  ] ;  then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    	echo  " ${ MAGENTA } Setting  ${ YELLOW } SSID ${ MAGENTA }  to  ${ YELLOW } $OPT_S   ${ MAGENTA } in  $i ... ${ WHITE } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  grep -q "^ssid="  ${ HOSTAPD [ $x ] } ;  then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        sed -i " s/^ssid=.*/ssid= ${ OPT_S } / "  ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        echo  ${ OPT_S }  >> ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      fi 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 04:59:50 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    fi 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 14:15:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  [  $OPT_C  !=  false  ] ;  then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    	echo  " ${ MAGENTA } Setting  ${ YELLOW } Channel ${ MAGENTA }  to  ${ YELLOW } $OPT_C   ${ MAGENTA } in  $i ... ${ WHITE } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  grep -q "^channel="  ${ i } ;  then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            sed -i " s/^channel=.*/channel= ${ OPT_C } / "  ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            echo  ${ OPT_C }  >> ${ i } 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 05:44:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        fi 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    fi 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 14:15:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  [  $OPT_E  !=  false  ] ;  then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    	echo  " ${ MAGENTA } Adding WPA encryption with passphrase:  ${ YELLOW } $OPT_E   ${ MAGENTA } to  $i ... ${ WHITE } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  grep -q "^#auth_algs="  ${ i } ;  then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        	#echo "uncomenting wpa" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            sed -i "s/^#auth_algs=.*/auth_algs=1/"  ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            sed -i "s/^#wpa=.*/wpa=3/"  ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            sed -i " s/^#wpa_passphrase=.*/wpa_passphrase= $OPT_E / "  ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            sed -i "s/^#wpa_key_mgmt=.*/wpa_key_mgmt=WPA-PSK/"  ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            sed -i "s/^#wpa_pairwise=.*/wpa_pairwise=TKIP/"  ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            sed -i "s/^#rsn_pairwise=.*/rsn_pairwise=CCMP/"  ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								       elif  grep -q "^auth_algs="  ${ i } ;  then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        	#echo "rewriting existing wpa" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            sed -i "s/^auth_algs=.*/auth_algs=1/"  ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            sed -i "s/^wpa=.*/wpa=3/"  ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            sed -i " s/^wpa_passphrase=.*/wpa_passphrase= $OPT_E / "  ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            sed -i "s/^wpa_key_mgmt=.*/wpa_key_mgmt=WPA-PSK/"  ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            sed -i "s/^wpa_pairwise=.*/wpa_pairwise=TKIP/"  ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            sed -i "s/^rsn_pairwise=.*/rsn_pairwise=CCMP/"  ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								       else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								#      		#echo "adding wpa" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										echo  ""  >> ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									        echo  "auth_algs=1"  >> ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										echo  "wpa=3"  >> ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										echo  " wpa_passphrase= $OPT_E "  >> ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										echo  "wpa_key_mgmt=WPA-PSK"  >> ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									        echo  "wpa_pairwise=TKIP"  >> ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										echo  "rsn_pairwise=CCMP"  >> ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        fi 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    fi 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  [  $OPT_O  !=  false  ] ;  then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								       	echo  " ${ MAGENTA } Removing WPA encryption in  $i ... ${ WHITE } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  grep -q "^auth_algs="  ${ i } ;  then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        	#echo "comenting out wpa" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            sed -i "s/^auth_algs=.*/#auth_algs=1/"  ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            sed -i "s/^wpa=.*/#wpa=3/"  ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            sed -i " s/^wpa_passphrase=.*/#wpa_passphrase= $defaultPass / "  ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            sed -i "s/^wpa_key_mgmt=.*/#wpa_key_mgmt=WPA-PSK/"  ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            sed -i "s/^wpa_pairwise=.*/#wpa_pairwise=TKIP/"  ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            sed -i "s/^rsn_pairwise=.*/#rsn_pairwise=CCMP/"  ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        elif  grep -q "^#auth_algs="  ${ i } ;  then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        	#echo "rewriting comentied out wpa" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            sed -i "s/^#auth_algs=.*/#auth_algs=1/"  ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            sed -i "s/^#wpa=.*/#wpa=3/"  ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            sed -i " s/^#wpa_passphrase=.*/#wpa_passphrase= $defaultPass / "  ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            sed -i "s/^#wpa_key_mgmt=.*/#wpa_key_mgmt=WPA-PSK/"  ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            sed -i "s/^#wpa_pairwise=.*/#wpa_pairwise=TKIP/"  ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            sed -i "s/^#rsn_pairwise=.*/#rsn_pairwise=CCMP/"  ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        	#echo "adding commented out WPA" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        	echo  ""  >> ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        	echo  "#auth_algs=1"  >> ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											echo  "#wpa=3"  >> ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											echo  " #wpa_passphrase= $defaultPass "  >> ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											echo  "#wpa_key_mgmt=WPA-PSK"  >> ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            echo  "#wpa_pairwise=TKIP"  >> ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											echo  "#rsn_pairwise=CCMP"  >> ${ i } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        fi 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    fi 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-22 03:45:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									echo  " ${ GREEN } Modified  ${ i } ...done ${ WHITE } " 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 14:15:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									echo  "" 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								   	echo  " ${ MAGENTA } No  ${ i }  file found... ${ WHITE } ${ NORMAL } " 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 14:15:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									echo  "" 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  fi 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								done 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 14:15:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 04:59:50 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								### End main loop ### 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 04:59:50 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-06-01 14:15:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								### Apply Settings and restart all services 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								if  [  $OPT_Q  = =  false  ] ;  then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									APPLYSETTINGSLOUD
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									APPLYSETTINGSQUIET
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								fi 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-04-01 19:00:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								exit  0