Guest User

Untitled

a guest
Oct 15th, 2018
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.65 KB | None | 0 0
  1. #!/bin/bash
  2. # dig.sh
  3. # automated VPN tunnel management script
  4.  
  5. set -x
  6.  
  7. # global variable declaration
  8.  
  9. # Network Variables
  10. sVPN_Server="wedontdoresi.com"
  11. sIP_wlan0=$(ip a s wlan0 | grep 'inet ' | awk '{print $2}' | sed 's/\/.*//g')
  12. sIP_eth0=$(ip a s eth0 | grep 'inet ' | awk '{print $2}' | sed 's/\/.*//g')
  13. saIPs=( "$sIP_wlan0" "$sIP_eth0" )
  14. # gather interfaces with default routes
  15. while read -r line; do
  16. dvaIFs_Routed+=( "$line" )
  17. done <<< "$(ip r s | grep default | awk '{print $5}')"
  18.  
  19. # File and path variables
  20. sPath="$(cd "$(dirname $0)" && pwd)"
  21. if [ -z "$sPath" ]; then
  22. echo "ERROR: Cannot derive path."
  23. exit 1
  24. fi
  25. sLogfile="connection.log"
  26. sConfig="hostus-embed-meerkat1.ovpn"
  27. sVPN_Logfile="vpn.log"
  28. #sPidfile_fullpath="/var/run/openvpn.pid"
  29.  
  30. # Logging and debugging verbosity
  31. nVerbosity=1 # default to 1
  32. function fnLog()
  33. {
  34. # eventually we want optional 3rd parameter to have bit flags
  35. # 1 bit should force the log entry even if it's repeating
  36. # 1 bit should suppress log echoes for this call
  37. if [ -n "$3" ];then
  38. echo "Forced log entry:" >> "$sPath"/"$sLogfile"
  39. fi
  40.  
  41. if ! tail -3 "$sPath"/"$sLogfile" | grep "$2"; then
  42. if [ "$1" -le $nVerbosity ]; then
  43. case $nVerbosity in
  44. 1) # default logging
  45. echo "$(date) | $2" >> "$sPath"/"$sLogfile"
  46. ;;
  47. 2) # noisy logging
  48. echo "$(date) | $2" | tee -a "$sPath"/"$sLogfile"
  49. ;;
  50. 3) # noisy debugging
  51. echo "$(date) | Debug msg--- $2" | tee -a "$sPath"/"$sLogfile"
  52. ;;
  53. 4) # "up to 11" (but really it's 4)
  54. echo "$(date) | $2" >> "$sPath"/"$sLogfile"
  55. sudo wall -n "$2"
  56. ;;
  57. esac
  58. fi
  59. fi
  60. }
  61. ##################################
  62. ## network related functions ##
  63. ##################################
  64.  
  65. # takes two parameters, the first is mandatory [start|stop]
  66. # the second is a local ip to bind to the VPN tunnel and is only used in conjuction with start
  67. function fnVPN_Control()
  68. {
  69. case "$1" in
  70. start)
  71. # a few notes on starting the VPN:
  72. #+ we can't depend on the exit status of the openvpn command, because apparently it exits ok even if it doesn't start successfully
  73. # also, it doesn't like unset variables in the command path. so that precludes an entire approach to modular triggering
  74. if [ -z "$2" ]; then
  75. fnLog 3 "Executing: sudo -b openvpn --config $sPath/$sConfig --log $sPath/vpn.log --writepid /var/run/openvpn.pid"
  76. if sudo -b openvpn --config "$sPath"/"$sConfig" --log "$sPath"/"$sVPN_Logfile" --writepid /var/run/openvpn.pid; then
  77. sudo wall -n "Tunneling to Burrow ..."
  78. fi
  79. else
  80. fnLog 3 "Executing: sudo -b openvpn --config $sPath/$sConfig --log $sPath/vpn.log --writepid /var/run/openvpn.pid --local $2"
  81. if sudo -b openvpn --config "$sPath"/"$sConfig" --log "$sPath"/"$sVPN_Logfile" --writepid /var/run/openvpn.pid --local "$2"; then
  82. sudo wall -n "Tunneling to Burrow ..."
  83. fi
  84. fi
  85.  
  86.  
  87. # at this point, we should find a dependable way to check if the vpn was established sucessfully
  88. # sleep 5
  89. # if [ $(tail -1 vpn.log | grep 'Initialization Sequence Completed') ]; then
  90. # fnLog 1 "Connection to Burrow successful."
  91. # fi
  92. ;;
  93. stop)
  94. if pgrep vpn &> /dev/null; then
  95. sudo wall -n "Tunnel aborted."
  96. fnLog 1 "VPN tunnel closed."
  97. sudo killall openvpn
  98. else
  99. fnLog 1 "No VPN to kill."
  100. fi
  101. ;;
  102. esac
  103. }
  104. function fnNIC_to_IP()
  105. {
  106. local sIP
  107. sIP="$(ip a s "$1" 2> /dev/null | grep 'inet ' | awk '{print $2}' | sed 's/\/.*//g' | grep -v -e "[a-zA-Z]")"
  108. if [ -n "$sIP" ]; then
  109. echo "$sIP"
  110. else
  111. return 1
  112. fi
  113. }
  114. # takes two parameters, first is the interface name, the second is the output notation flag
  115. # output notation flag: 1 (default) CIDR notation (ex- 192.168.1.0/24) as used with iptables
  116. #+ 2 full notation (ex- 192.168.1.0 255.255.255.0) as used with openvpn configs
  117. # right now it's a crude, but functional version that makes a lot of assumptions and only really works for
  118. # networks we're likely to come across. later I can expand it to be more comprehensive and flexible
  119. function fnNIC_to_NET()
  120. {
  121. local nType
  122. local sResult
  123. local sNIC
  124.  
  125. sNIC="$1"
  126. if [ -z "$2" ]; then
  127. nType=1
  128. else
  129. nType="$2"
  130. fi
  131.  
  132. case "$nType" in
  133. 1) sResult="$(ip a s $sNIC | grep 'inet ' | awk '{print $2}' | sed 's/\.[0-9]\{1,3\}\//\.0\//')" ;; # pulls the ip address reported by "ip address show" (which reports CIDR notation) and replaces the last octet with 0
  134. 2) sResult="$(ifconfig $sNIC | grep 'inet ' | sed 's/.*inet //' | sed 's/\.[0-9]\{1,3\}\ \ netmask/\.0/' | sed 's/ destination.*//' | sed 's/\ \{0,\}broadcast.*//')";; # ifconfig conveniently reports netmasks in
  135. esac
  136.  
  137. echo "$sResult"
  138. }
  139. # takes three parameters, first is a directive [add|remove|check]
  140. # second parameter is a NIC to SNAT/MASQUERADE (typically eth0)
  141. # third parameter is an optional type (selects SNAT/MASQUERADE with 1/2), defaults to 1 (2 for now because troubleshooting fewer variables in the command is easier)
  142. function fnIPtables() # (char [add|remove|check], char [<interface name>] [, integer <type flag, 1=SNAT, 2=MASQUERADE>])
  143. {
  144. local saNATs=()
  145. local nType
  146. local sTun_Net
  147. local sLocalIP
  148.  
  149. # set default type
  150. if [ -z "$3" ]; then
  151. nType=2 # change to 1 once I get this to behave
  152. else
  153. nType="$3"
  154. fi
  155.  
  156. sTun_Net="$(fnNIC_to_NET tun0 1)"
  157. sLocalIP="$(fnNIC_to_IP $2)"
  158.  
  159. ((nType--)) # adjust flag to array index
  160.  
  161. saNATs[0]="POSTROUTING -s $sTun_Net -o $2 -j SNAT --to-source $sLocalIP"
  162. saNATs[1]="POSTROUTING -s $sTun_Net -o $2 -j MASQUERADE"
  163.  
  164. fnLog 3 "IP Table NAT entry type 1: ${saNATs[0]}"
  165. fnLog 3 "IP Table NAT entry type 2: ${saNATs[1]}"
  166.  
  167.  
  168. case "$1" in
  169. add)
  170. fnLog 1 "Appending the NAT table with the following rule: \"${saNATs[$nType]}\""
  171. #if sudo iptables -t nat -A "${saNATs[$nType]}" &>> "$sPath"/"$sLogfile"; then
  172. if sudo iptables -t nat -A POSTROUTING -s "$sTun_Net" -o "$2" -j MASQUERADE &>> "$sPath"/"$sLogfile"; then
  173. fnLog 1 "Append successful."
  174. echo 0
  175. else
  176. fnLog 1 "Append unsuccessful."
  177. echo 1
  178. fi
  179. ;;
  180. remove)
  181. fnLog 1 "Removing the following rule: \"${saNATs[$nType]}\" from the NAT table."
  182. if sudo iptables -t nat -D ${saNATs[$nType]} &>> "$sPath"/"$sLogfile"; then
  183. fnLog 1 "Remove successful."
  184. echo 0
  185. else
  186. fnLog 1 "Remove unsuccessful."
  187. echo 1
  188. fi
  189. ;;
  190. check)
  191. fnLog 1 "Querying the NAT table for either a SNAT or MASQUERADE route on interface $2"
  192. # note: if the full append command is contained in the array, the array must be preceded with a double backslash to properly escape the initial dash so grep doesn't process it
  193. if sudo iptables -t nat -S | grep -q "${saNATs[$nType]}";then
  194. #if sudo iptables -t nat -S | grep -q "${saNATs[0]}" || sudo iptables -t nat -S | grep -q "${saNATs[1]}";then
  195. fnLog 3 "NAT Table entry found."
  196. echo 0
  197. else
  198. fnLog 3 "NAT Table entry not found."
  199. echo 1
  200. fi
  201. ;;
  202. esac
  203. }
  204.  
  205. # takes an interface name as a parameter and attempts to start a vpn connection
  206. # this can be thought of as a "careful start" to the VPN, with more debugging info
  207. function fnInitiate_Session()
  208. {
  209. #sScanCmd="sudo nmap -n -e $1 -sU -p1194 $sVPN_Server | grep 1194 | grep 'open '"
  210. fnLog 1 "Attempting fnInitiate_Session on $1"
  211. if sudo nmap -n -e $1 -sU -p1194 $sVPN_Server | grep 1194 | grep 'open ' &> /dev/null; then
  212. fnLog 1 "Burrow visible via source interface $1. Starting VPN Connection"
  213. fnVPN_Control "start" $(ip a s wlan0 | grep 'inet ' | awk '{print $2}' | sed 's/\/.*//g') #derive source ip and pass it for binding
  214. return 0
  215. elif nc -zv -s "$1" www.google.com 80 &> /dev/null; then
  216. fnLog 1 "Interface ($1) can see the internet, but we cannot see the VPN server ($sVPN_Server)."
  217. return 1
  218. else
  219. fnLog 1 "Interface ($1) cannot reach the internet."
  220. return 2
  221. fi
  222. }
  223.  
  224. # This function takes an interface name as its only parameter and checks the status of its connection.
  225. function fnTestComms()
  226. {
  227. fnLog 1 "Checking the connection on NIC $1"
  228. if [ -n "$1" ]; then
  229. if sudo nmap -n -e $1 -sU -p1194 $sVPN_Server | grep 1194 | grep 'open ' &> /dev/null; then
  230. fnLog 1 "Burrow visible via interface $1."
  231. echo 0
  232. elif nc -zv -s "$1" www.google.com 80 &> /dev/null; then
  233. fnLog 1 "Interface ($1) can see the internet, but we cannot see the VPN server ($sVPN_Server)."
  234. echo 1
  235. else
  236. fnLog 1 "Interface ($1) cannot reach the internet."
  237. echo 2
  238. fi
  239. else
  240. fnLog 1 "Testing connection without NIC specification."
  241. if sudo nmap -n -sU -p1194 $sVPN_Server | grep 1194 | grep 'open ' &> /dev/null; then
  242. echo 0
  243. else
  244. echo 1
  245. fi
  246. fi
  247. }
  248.  
  249. # takes an interface name and removes any default routes associated with it
  250. # if called without a parameter, it removes the first route, if there is more than one unless an
  251. #+ a force flag is passed in the form of a second parameter
  252. function fnRemDefRoute()
  253. {
  254. # store route before deleting
  255. local sIF
  256. local route
  257.  
  258. # if called without a parameter, we will assume we're getting rid of the first default route
  259. if [ -z "$1" ]; then
  260. sIF=${dvaIFs_Routed[0]}
  261. else
  262. sIF="$1"
  263. fi
  264.  
  265. if [[ (${#dvaIFs_Routed[@]} -gt 1) || ( -n "$2") ]]; then
  266. route=$(ip r s | grep default | grep "$sIF")
  267. fnLog 1 "Removing Default route <$route> and storing in file $sPath/route-$sIF.tmp"
  268. fnLog 3 "sIF is $sIF"
  269. echo "$route" > "$sPath"/route-"$sIF".tmp
  270. if sudo ip r d $(cat "$sPath"/route-"$sIF".tmp) &>> "$sPath"/"$sLogfile"; then
  271. fnLog 3 "Route delete result: $?"
  272. else
  273. fnLog 1 "Route delete unsuccessful."
  274. fi
  275.  
  276. fi
  277. # god knows why this was so hard, but delete commands that threw errors are the following:
  278. #sudo ip r d $(ip r s | grep default | grep "$1")
  279. #sudo ip r d "$route"
  280. #sudo ip r d dev "$sIF"
  281. }
  282. function fnRestoreDefRoute()
  283. {
  284. fnLog 1 "Restoring route for interface $1, and removing temp file <$sPath/route-$1.tmp>."
  285. if [ -f "$sPath"/route-"$1".tmp ]; then
  286. local route
  287. route=$(cat "$sPath"/route-"$1".tmp)
  288. fnLog 3 "exact command used: \"sudo ip r a $route\""
  289. #if sudo ip r a "$route"; then
  290. fnLog 1 "Route file located. Attempting restore now."
  291. if sudo ip r a $(cat "$sPath"/route-"$1".tmp) &>> "$sPath"/"$sLogfile"; then
  292. fnLog 3 "Restore route result: $?"
  293. rm "$sPath"/route-"$1".tmp
  294. fnLog 1 "Route restored, $sPath/route-$1.tmp deleted."
  295. else
  296. fnLog 1 "Error restoring route. Result: $?"
  297. fi
  298. fi
  299. }
  300.  
  301. ######################################
  302. ## command line option functions ##
  303. ######################################
  304. function fnInvalidSwitch()
  305. {
  306. echo "Invalid parameter: $1"
  307. echo "Try [ -h | --help ]"
  308. echo "Exiting."
  309. exit 1
  310. }
  311. function fnUsage()
  312. {
  313. cat <<USAGE
  314.  
  315. Usage: `basename $0` [Options ...]
  316. If called with no options, it will simply attempt to establish or maintain a connection to the VPN server.
  317. Options:
  318. --start Removes the noconnect lock file, and then starts the VPN.
  319. Takes an optional parameter of a bind address
  320. --stop Stops the VPN and locks it by creating the noconnect lock file.
  321. --status Reports the status of the VPN process.
  322. [vars|connetion]
  323. --remove Removes the default route associated with the specified NIC from the routing table.
  324. If no NIC is specified, it removes the first route in the table as long as it's not the only default route.
  325. -v [n] Sets the verbosity to n, or if n is not specified, sets it to 2.
  326. 0 = silent, or no logging
  327. 1 = logging enabled \(default\)
  328. 2 = noisy logging, or echoed logging
  329. 3 = noisy debug logging
  330. 4 = as loud as it gets. debug logging with broadcast to all users
  331. -h, --help Displays this help message.
  332.  
  333. USAGE
  334. exit 1
  335. }
  336.  
  337.  
  338. # needs to be expanded
  339. function fnStatus()
  340. {
  341. if [ -z "$1" ]; then
  342. # Is the
  343. if pgrep vpn &> /dev/null; then #ps aux | grep -q $(cat /var/run/openvpn.pid)
  344. echo "Open VPN client is running."
  345. local sVPN_Rtr_IP
  346. sVPN_Rtr_IP=$(ip a s tun0 | grep 'inet ' | sed 's/.*inet //' | sed 's/\.[0-9]\{1,3\}\/.*/\.1/')
  347. if ping -c1 -W3 "$sVPN_Rtr_IP" &> /dev/null; then
  348. echo "Tunnel is up."
  349. else
  350. echo "Tunnel is down."
  351. if nc -zv google.com 80 &> /dev/null; then
  352. if sudo nmap -n -sU -p1194 $sVPN_Server | grep 1194 | grep 'open ' &> /dev/null; then
  353. echo "We can see the Burrow." # how did we get here?
  354. else
  355. echo "Internet is up."
  356. fi
  357. else
  358. echo "Check internet connection."
  359. fi
  360. fi
  361. else
  362. echo "VPN is stopped."
  363. fi
  364. if [ -f "$sPath"/noconnect ]; then
  365. echo "\"noconnect\" file is present"
  366. else
  367. echo "\"noconnect\" file not found; gate is open"
  368. fi
  369. echo "Cronstatus for $USER: \"$(sudo cat /var/spool/cron/crontabs/$USER | grep $0)\""
  370. echo "Postrouting chain:"
  371. sudo iptables -t nat -S | grep '\-A POSTROUTING'
  372. else
  373. nVerbosity=3
  374. case "$1" in
  375. vars)
  376. fnLog 3 "Variable status Requested."
  377. fnLog 3 "Path set to $sPath"
  378. fnLog 3 "Primary local bind address set to ${saIPs[0]}"
  379. fnLog 3 "Secondary local bind address set to ${saIPs[1]}"
  380. fnLog 3 "Server set to $sVPN_Server"
  381. fnLog 3 "Config set to $sConfig"
  382. ;;
  383. connection)
  384.  
  385. ;;
  386. esac
  387. fi
  388. }
  389.  
  390. ######################################
  391. ## main program, VPN management ##
  392. ######################################
  393.  
  394. function fnMain()
  395. {
  396. # If there are no objections, let's get this VPN started.
  397. # Potential objections include, the VPN is already running,
  398. #+ as well as the presence of 'noconnect' file in the working directory.
  399.  
  400. if pgrep vpn &> /dev/null; then
  401. if ping -c1 -W3 -4 10.8.0.1 &> /dev/null; then
  402. fnLog 3 "VPN is running and the tunnel router is visible."
  403.  
  404. # first we figure out which IF we're using for internet, and check if the other one has the appropriate SNAT/MASQUERADE rule in the nat table
  405. # this check should only be performed after we have successfully connected to the VPN
  406. if [ ! -f "$sPath"/noconnect ]; then
  407. fnLog 3 "Checking the NAT's postrouting chain."
  408. local sAV_IF
  409. case "${dvaIFs_Routed[0]}" in
  410. wlan0) sAV_IF="eth0";;
  411. eth0) sAV_IF="wlan0";;
  412. esac
  413.  
  414. case "$(fnIPtables "check" "$sAV_IF")" in
  415. 0) fnLog 3 "POSTROUTING chain looks good." ;;
  416. 1) fnIPtables "add" "$sAV_IF" ;;
  417. esac
  418. fi
  419. else
  420. fnLog 1 "VPN is running, but the tunnel router is not visible. Either the VPN server is restarting, or there is a connection issue."
  421. if [ $(fnTestComms ${dvaIFs_Routed[0]}) -ne 0 ]; then
  422. fnRemDefRoute
  423. fi
  424. fi
  425. elif [ -f "$sPath"/noconnect ]; then
  426. # don't connect if we find the noconnect file in the working directory
  427. fnLog 1 "Connection prevented by noconnect file"
  428. else
  429. fnLog 1 "VPN is not running, and 'noconnect' file is not preset. Attempting to establish connection."
  430.  
  431. # if we can see the server with our primary default route, just connect
  432. if [ $(fnTestComms) -eq 0 ]; then
  433. fnLog 3 "UDP Port 1194 is visible on $sVPN_Server"
  434. fnVPN_Control "start"
  435. else
  436. fnLog 1 "Dealing with connectivity issues."
  437. # how many default routes do we have right now?
  438. case "${#dvaIFs_Routed[@]}" in
  439. 0) fnLog 1 "No default routes found. We need internet in order to proceed.";;
  440. 1)
  441. case "$(fnTestComms ${dvaIFs_Routed[0]})" in
  442. 0) fnVPN_Control "start" "$(fnNIC_to_IP ${dvaIFs_Routed[0]})" ;; # how did we get here? this should have been sorted out at the beginning of this if conditional
  443. 1) fnLog 1 "Our lone default route can see the internet, but cannot see our server $sVPN_Server";;
  444. 2) fnLog 1 "Our lone default route cannot see the internet.";;
  445. esac
  446. ;;
  447. 2)
  448. # this is where the two main interfaces eth0 and wlan0 are hard-coded in
  449. # we may want to abstract this out if we want to make this script useful for secondary wireless/wired NICs
  450. # so the first default route doesn't work for us, if the second does, our work is simple
  451.  
  452. # if we can see out on route #2, delete route #1
  453. case "$(fnTestComms ${dvaIFs_Routed[1]})" in
  454. 0) fnRemDefRoute; fnVPN_Control "start" ;; # if the second nic can see the VPN server, that's good enough
  455. 1) fnLog 1 "Is the $sVPN_Server online?";; ## this is where internet management gets tricky
  456. 2) ;;
  457. esac
  458. ;;
  459. *) # this should never trigger
  460. for i in "${!dvaIFs_Routed[@]}"; do
  461. fnTestComms "${dvaIFs_Routed[$i]}"
  462. if [ "$?" -eq 0 ]; then
  463. fnLog 1 "Looks like we should be able to get out. However more logic may be necessary if there's a potential issue we haven't accounted for yet."
  464. exit 0
  465. fi
  466. done
  467. fnLog 1 "All available NICs failed to reach the internet. Exiting. "
  468. exit 1
  469. ;;
  470. esac
  471. fi
  472. fi
  473. }
  474.  
  475.  
  476.  
  477. ##############################
  478. ## command line parsing ##
  479. ##############################
  480.  
  481. # !!! add the ability to pass multi argument command line switches
  482.  
  483. # parse command line
  484. POSITIONAL=()
  485. while [ "$#" -gt 0 ]; do
  486.  
  487. # command switches without parameters
  488. if [[ $(echo "$2" | grep '\-') || ( -z "$2") ]]; then # if the command switch is bare, use default value and shift 1
  489. POSITIONAL+=("$1")
  490. case "$1" in
  491. # check for help first, as this will trigger an exit
  492. -h|--help)
  493. fnUsage
  494. ;;
  495. -v)
  496. nVerbosity=2
  497. echo "verbosity set to $nVerbosity"
  498. ;;
  499. # list of valid commands that trigger functions
  500. --start\
  501. |--stop\
  502. |--status\
  503. |--showlogs\
  504. |--clearlogs\
  505. |--remove\
  506. |--test)
  507. saCMDs+=("$1")
  508. saParams+=("") # iterate the parameter array to keep the indices congruent
  509. ;;
  510. *)
  511. if [ -n "$1" ]; then
  512. fnInvalidSwitch "$1"
  513. fi
  514. ;;
  515. esac
  516. shift
  517.  
  518. # command switches with single parameters
  519. else # otherwise set parameter and shift 2
  520. POSITIONAL+=("$1")
  521. POSITIONAL+=("$2")
  522. case "$1" in
  523. -v)
  524. nVerbosity="$2"
  525. echo "verbosity set to $nVerbosity"
  526. ;;
  527. # valid commands that take parameters
  528. --start\
  529. |--status\
  530. |--remove\
  531. |--restore\
  532. |--test)
  533. saCMDs+=("$1")
  534. saParams+=("$2")
  535. ;;
  536. *)
  537. if [ -n "$1" ]; then
  538. fnInvalidSwitch "$1"
  539. fi
  540. ;;
  541. esac
  542. shift 2
  543. fi
  544. done
  545.  
  546. set -- "${POSITIONAL[@]}" # restore position parameters, just because
  547. #echo "Positional == ${POSITIONAL[@]}"
  548.  
  549. # process command line parameters
  550.  
  551. for i in "${!saCMDs[@]}"; do
  552. case "${saCMDs[$i]}" in
  553. --start)
  554. if [ -f "$sPath"/noconnect ]; then
  555. fnLog 1 "Removing \"noconnect\" file."
  556. rm "$sPath"/noconnect
  557. fi
  558. fnVPN_Control "start" "${saParams[$i]}"
  559. ;;
  560. --stop)
  561. fnVPN_Control "stop"
  562. fnLog 1 "Creating \"noconnect\" file."
  563. touch "$sPath"/noconnect
  564. ;;
  565. --status)
  566. fnStatus "${saParams[$i]}"
  567. ;;
  568. --showlogs)
  569. echo "*** connection.log ***"
  570. cat "$sPath"/"$sLogfile"
  571. echo "*** vpn.log ***"
  572. sudo cat "$sPath"/vpn.log
  573. ;;
  574. --clearlogs)
  575. echo -n > "$sPath"/"$sLogfile"
  576. echo -n | sudo tee "$sPath"/vpn.log
  577. echo "Logs cleared."
  578. ;;
  579. --remove) # !!! need to add input sanitization for parameters on remove/restore
  580. fnRemDefRoute "${saParams[$i]}"
  581. ;;
  582. --restore)
  583. fnRestoreDefRoute "${saParams[$i]}"
  584. ;;
  585. --test) ## this is just for some debugging, disregard
  586. #fnIPtables "add" ${saParams[$i]}
  587. fnIPtables "remove" ${saParams[$i]}
  588.  
  589. ;;
  590. esac
  591. done
  592.  
  593. # if no long commands were specified, run mainline
  594. if [ "${#saCMDs[@]}" -eq 0 ]; then
  595. fnMain
  596. fi
  597.  
  598. #fnLog 3 "Script done."
  599.  
  600. #############
  601. # End #
  602. #############
Add Comment
Please, Sign In to add comment