From d467e9c538ff29fac3dd429eb1b63a14e6080197 Mon Sep 17 00:00:00 2001 From: Nova Date: Fri, 13 Aug 2021 10:50:39 -0300 Subject: [PATCH] See the changelog for changes --- ChangeLog | 5 + Makefile | 14 +- setnet.8.gz | Bin 3219 -> 3219 bytes setnet.8.html | 343 ++++++++ setnet.sh | 2076 ++++++++++++++++++++----------------------------- 5 files changed, 1225 insertions(+), 1213 deletions(-) create mode 100644 setnet.8.html diff --git a/ChangeLog b/ChangeLog index a298e90..6d161f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2021-08-13 Nova + * Massive code cleanup and reformatting (let me know if it breaks) + * Implemented an experimental pastebin function (needs further testing) using 'minpb' + * Modified the Makefile adding install and uninstall rules along with environment variables used on these + 2018-05-03 KatolaZ * setnet.sh: fixed a bug in essid management diff --git a/Makefile b/Makefile index b616fde..ea163bf 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,19 @@ - +DESTDIR ?= +PREFIX ?= /usr +SYSCONFDIR ?= /etc +MANDIR ?= $(PREFIX)/share/man all: doc doc: setnet.8 gzip -c setnet.8 > setnet.8.gz groff -m mdoc -T html setnet.8 > setnet.8.html + +install: + install -m0644 setnetrc $(SYSCONFDIR)/setnetrc + install -m0755 setnet.sh $(DESTDIR)$(PREFIX)/bin/setnet + install -m0644 setnet.8.gz $(DESTDIR)$(MANDIR)/man8/setnet.8.gz +uninstall: + rm -v $(SYSCONFDIR)/setnetrc + rm -v $(DESTDIR)$(PREFIX)/bin/setnet + rm -v $(DESTDIR)$(MANDIR)/man8/setnet.8.gz diff --git a/setnet.8.gz b/setnet.8.gz index f1aea9e1297f9ed9dc290371bb3b7780839225f1..1de533b261b98f60b9cb2cf3d19c53a8a3b00f72 100644 GIT binary patch delta 17 YcmbO%Ia!iJzMF&NyQy&EMviVC04+=f3jhEB delta 17 YcmbO%Ia!iJzMF&N*Vk838#%gp05^*Uo&W#< diff --git a/setnet.8.html b/setnet.8.html new file mode 100644 index 0000000..c419f96 --- /dev/null +++ b/setnet.8.html @@ -0,0 +1,343 @@ + + + + + + + + + + + + + +
+ + +

SETNET(8) System Manager’s Manual SETNET(8)

+ +

NAME

+ +

setnet.sh — +minimalist shell script for network configuration with +dialog interface

+ +

SYNOPSIS

+ +

setnet.sh +[−c config_file] +[−d trace_file] [−h] +[−v]

+ +

DESCRIPTION

+ +

setnet.sh is a shell script for +network management, with a terminal user interface based on +dialog(1). It works as a wrapper around the basic tools for +the configuration of Ethernet and Wi-Fi interfaces, +including ip(8), dhclient(8), and wpa_cli(8).

+ +

setnet.sh allows +to configure static and/or DHCP-based connections to a +LAN/WLAN, and to manage the authentication to a Wi-Fi +network. At present, open (no key), WPA-Personal (WPA-PSK +and WPA2-PSK), and WPA-Enterprise (EAP/PEAP or EAP/TLS) are +supported.

+ +

setnet.sh can be +also used as a minimal interface to basic network +diagnostics tools, including ping(8), host(1), +traceroute(1), and netstat(8). It allows to show some +information about network status, including the routing +table, content of resolv.conf and nsswitch.conf, active +TCP/IP connections, running daemons, etc., and to dump those +information to a file. Support for posting a dump of network +status to websites like pastebin.com is under +development.

+ +

setnet.sh uses +/bin/sh by default. It has been tested with several +standard shells, including bash, busybox, dash, ksh, mksh, +posh, sh, yash, and zsh but it should work correctly with +any POSIX-compliant shell.

+ +

setnet.sh +recognises the following options:

+ +

−c +config_file

+ +

specify a configuration +file

+ +

−d +trace_file

+ +

enable dialog debug, and write +the trace to the provided trace_file

+ +

−h

+ +

print a minimal +help and exit

+ +

−v

+ +

show version +and exit

+ +

The main +setnet.sh menu allows to choose from five sections, as +described below:

+ +

Setup

+ +

This section +allows to configure a network interface, selected from the +list of available network devices (as returned by "ip +-o link"). Once a device has been selected, it is +possible to choose on of the following functions

+ +

View

+ +

View current device +configuration, i.e., MAC address, link status, IP address, +etc.

+ +

WiFi

+ +

(available only for wi-fi +devices) Manage the association to a Wi-Fi network. This +allows to restart wpa_supplicant, to manage the currently +configured networks, to add a new network, and to show (and +modify) the configuration file used by wpa_supplicant.

+ +

Conf

+ +

Configure the IP address of the +device. It is possible to choose between DHCP-based +and Static IP configuration.

+ +

Start

+ +

Bring the interface up (using +"ip link set <DEVNAME> up").

+ +

Stop

+ +

Bring the interface down (using +"ip link set <DEVNAME> down").

+ +

Restart

+ +

Restart the interface by +putting it first down and then up again.

+ +

Info

+ +

This section +provides information about the current network status and +allows to perform basic diagnostic tasks. The following +functions are available:

+ +

ARP

+ +

Show the current ARP table

+ +

Connections

+ +

List active network connections +by running "netstat -tnp"

+ +

DNS

+ +

List the configured DNS, by +showing the "nameserver" entries in +/etc/resolv.conf.

+ +

Lookup

+ +

Perform a DNS lookup through +"host <HOST>". If <HOST> is a FQDN, +the result will be the IP address(es) associated to that +domain name. If <HOST> is an IP address, the result is +the list of FQDNs associated to that address.

+ +

Ping

+ +

Ping a host, using its IP of +FQDN (Fully-Qualified Domain Name) by running "ping -c +5 <HOST>".

+ +

Resolver

+ +

Show the system resolver +configuration, i.e. the content of the file +/etc/nsswitch.conf

+ +

Routes

+ +

Show the current routing +table

+ +

Services

+ +

Show a list of processes +(daemons) listening on TCP ports, by running "netstat +-ltnp".

+ +

Traceroute

+ +

Show the route to a given host, +as obtained by running the command "traceroute +<HOST>".

+ +

Dump

+ +

Dump +information about current network status to a file. The user +can choose which information to include from a checklist. +The support for dumping network information to web +applications like pastebin is currently under +development.

+ +

Log

+ +

Show the +logfile written by setnet.sh

+ +

About

+ +

Provide +information about copyright, contributors, and license.

+ +

ENVIRONMENT

+ +

setnet.sh uses the following +environment variables:

+ +

WPA_FILE

+ +

The configuration file for +wpa_supplicant(1) (default to +/etc/wpa_supplicant/wpa_setnet.conf ).

+ +

LOGFILE

+ +

The file used by setnet.sh for +logging (default to /var/log/setnet.log ).

+ +

TRUNCATE_LOG

+ +

If it is set to "yes" +or "YES", the log file is truncated when setnet.sh +starts.

+ +

WIFI_DEVICES

+ +

List of wifi devices. This list +is used only when automatic detection of wifi devices +fails.

+ +

SUPPRESS_INFO

+ +

If set to "yes" or +"YES", setnet will suppress verbose +notifications.

+ +

SHOW_LO

+ +

If set to "yes" or +"YES" setnet will include the loopback device in +the list of available network devices.

+ +

These variables +are normally set in the setnetrc configuration file (see +FILES below). setnet.sh will exit if either WPA_FILE +or LOGFILE are undefined.

+ +

FILES

+ +

setnet.sh uses a configuration +file which defines the environment variables described in +ENVIRONMENT above. setnet.sh looks for the following +files:

+ +

+ +

the config_file provided +through the option -c (if any).

+ +

+ +

the file /etc/setnetrc +(if it exists)

+ +

+ +

the file ~/.setnetrc (if +it exists)

+ +

in that order. +If a config_file is provided, the other files are +ignored. Otherwise, if ~/.setnetrc exists, it takes +precedence over /etc/setnetrc.

+ +

SEE ALSO

+ +

ip(8), iw(8), dhclient(8), +wpa_supplicant(8), wpa_cli(8), netstat(8).

+ +

AUTHORS

+ +

setnet.sh is Free Software, +distributed under the terms of the GNU General Public +License (GPL), version 3 of the License.

+ +

setnet.sh is +copyleft (c) 2016-2018 by Vincenzo (KatolaZ) Nicosia +<katolaz@freaknet.org>

+ +

BUGS

+ +

At present, setnet.sh can +reliably manage no more than one Wi-Fi device at a time. +This is due to the fact that the configuration file for +wpa_supplicant is defined in the environment variable +WPA_FILE. There is no limitation on the number of Ethernet +devices that setnet.sh can manage, but you should be careful +with having more than one dhclient processes running, +since each of them will try to add a default gateway to the +kernel routing table.

+ +

SECURITY +CONSIDERATIONS

+ +

Configuring networking is an +administration task, and setnet.sh requires root privileges +to work properly. It is possible to allow a regular user to +run setnet.sh, e.g. by using sudo(8) or sup(1) (see +https://sup.dyne.org/ for more information about sup).

+ +

setnet.sh can +recognise if it is running under sudo(8) or sup(1), by +looking at the content of the environment variables +SUDO_UID/SUP_UID, SUDO_GID/SUP_GID, and SUDO_USER/SUP_USER. +When setnet.sh is run under sudo(8) or sup(1), some +functionalities are disabled. In particular, loading and +editing an alternate wpa_supplicant configuration file is +forbidden (and for obvious reasons, since this would in +principle allow the sudoer to edit *any* file in your +system).

+ +

Linux +May 03, 2018 Linux

+
+ + diff --git a/setnet.sh b/setnet.sh index d6fc086..449221a 100755 --- a/setnet.sh +++ b/setnet.sh @@ -19,9 +19,8 @@ # # ---------------------------------------------------------------------- # -# Copyleft (C) Vincenzo "KatolaZ" Nicosia (katolaz@freaknet.org) -- -# (2016-2018) -# +# Copyleft (C) Vincenzo "KatolaZ" Nicosia (katolaz@freaknet.org) -- (2016-2018) +# Copyleft (C) Nova (novaburst@tilde.team) -- 2021 # @@ -29,7 +28,7 @@ ## Initialisation ## -VERSION=0.4 +VERSION=0.5 TOPSTR="setnet-${VERSION} [user: $(id -run)]" @@ -65,7 +64,7 @@ SOFT_DEPS="wpa_cli wpa_supplicant" ## the names of the commands actually found ## -OPT_DEPS="host ping traceroute netstat pastebinit" +OPT_DEPS="host ping traceroute netstat minpb" ################################# @@ -119,8 +118,7 @@ NET_FAMILIES="inet inet6" ## Load the configuration file "setnetrc" ## -##function -load_setnetrc(){ +load_setnetrc() { WPA_FILE="" LOGFILE="" @@ -140,7 +138,7 @@ load_setnetrc(){ ## if [ -f /etc/setnetrc ]; then - SETNETRC=/etc/setnetrc + SETNETRC=/etc/setnetrc fi ## @@ -148,12 +146,12 @@ load_setnetrc(){ ## if [ -f ~/.setnetrc ]; then - SETNETRC=~/.setnetrc + SETNETRC=~/.setnetrc fi if [ -n "${SETNETRC}" ] && - [ -f "${SETNETRC}" ]; then - . ${SETNETRC} + [ -f "${SETNETRC}" ]; then + . ${SETNETRC} fi if [ -z ${WPA_FILE} ]; then @@ -172,8 +170,8 @@ load_setnetrc(){ ## handler called upon exit/signal (NONE HUP INT TRAP TERM QUIT) ## -##function -cleanup(){ + +cleanup() { rm -f ${TMPFILE} rm -f ${WPA_PIDFILE} } @@ -189,15 +187,12 @@ cleanup(){ ## log() takes two arguments, namely the label and the message ## ## -##function -log(){ + +log() { + LABEL=$1 + MSG=$2 - ##local - LABEL=$1 - ##local - MSG=$2 - - echo "${LABEL}:" "${MSG}" >> "${LOGFILE}" + echo "${LABEL}:" "${MSG}" >> "${LOGFILE}" } @@ -215,27 +210,24 @@ log(){ ## - yash ## -##function -check_shell(){ - - ## - ## FIXME!!! THIS TEST DOES NOT WORK yet... - ## - +check_shell() { + ## + ## FIXME!!! THIS TEST DOES NOT WORK yet... + ## SCRIPT_CMD=$(ps $$ | tail -1 | sed -r -e 's/\ +/\ /g;s/^\ +//g' | cut -d " " -f 5) CUR_SH=$(basename ${SCRIPT_CMD}) - case ${CUR_SH} in - ash|bash|busybox|dash|ksh|mksh|posh|sh|yash|zsh) - log "check_shell" "The current shell (${CUR_SH}) is supported" - return - ;; - *) - log "check_shell" "The current shell (${CUR_SH}) is not supported" - echo "The current shell (${CUR_SH}) is not supported. Exiting..." - exit 1 - ;; - esac + case ${CUR_SH} in + ash|bash|busybox|dash|ksh|mksh|posh|sh|yash|zsh) + log "check_shell" "The current shell (${CUR_SH}) is supported" + return + ;; + *) + log "check_shell" "The current shell (${CUR_SH}) is not supported" + echo "The current shell (${CUR_SH}) is not supported. Exiting..." + exit 1 + ;; + esac } @@ -254,9 +246,7 @@ check_shell(){ ## included in the variable "HAS_OPTS" ## -##function -check_deps(){ - +check_deps() { check_shell ## Workaround for zsh @@ -264,34 +254,35 @@ check_deps(){ setopt shwordsplit fi - for h in $(echo ${HARD_DEPS}); do - _W=$(which ${h}) - if [ -z "${_W}" ]; then - echo "Error: required command \"${h}\" not found. Exiting..." - exit 1 - fi - log "check_deps" "NOTICE: required command '${h}'...found" - done - - for s in $(echo ${SOFT_DEPS}); do - _S=$(which ${s}) - if [ -z "${_S}" ]; then - log "check_deps" "WARNING: suggested command '${s}' not found! Some functions might not work properly" - fi - done + for h in $(echo ${HARD_DEPS}); do + _W=$(which ${h}) + if [ -z "${_W}" ]; then + echo "Error: required command \"${h}\" not found. Exiting..." + exit 1 + fi + log "check_deps" "NOTICE: required command '${h}'...found" + done - HAS_OPTS="" - for o in $(echo ${OPT_DEPS}); do - _O=$(which ${o}) - if [ -n "${_O}" ]; then - HAS_OPTS=" ${HAS_OPTS} ${o} " - log "check_deps" "NOTICE: optional command '${o}'...found" - else - log "check_deps" "NOTICE: optional command '${o}' not found!" - fi - done + for s in $(echo ${SOFT_DEPS}); do + _S=$(which ${s}) + if [ -z "${_S}" ]; then + log "check_deps" "WARNING: suggested command '${s}' not found! Some functions might not work properly" + fi + done - log "check_deps" "HAS_OPTS: \"${HAS_OPTS}\"" + HAS_OPTS="" + + for o in $(echo ${OPT_DEPS}); do + _O=$(which ${o}) + if [ -n "${_O}" ]; then + HAS_OPTS=" ${HAS_OPTS} ${o} " + log "check_deps" "NOTICE: optional command '${o}'...found" + else + log "check_deps" "NOTICE: optional command '${o}' not found!" + fi + done + + log "check_deps" "HAS_OPTS: \"${HAS_OPTS}\"" } @@ -301,9 +292,7 @@ check_deps(){ ## TRACE_FILE provided by the user ## -##function -set_debug(){ - +set_debug() { TRACE_FILE=$1 DEBUG_MODE="DEBUG" DIALOG="${DIALOG} --trace ${TRACE_FILE}" @@ -316,19 +305,17 @@ set_debug(){ ## message-box and returns ## -##function -unimplemented(){ - - LABEL=$1 +unimplemented() { + LABEL=$1 - eval "${DIALOG} --msgbox 'Sorry! '$LABEL' not implemented, yet!' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" 2>${TMPFILE} + eval "${DIALOG} --msgbox 'Sorry! '$LABEL' not implemented, yet!' \ + ${INFO_HEIGHT} ${INFO_WIDTH}" 2>${TMPFILE} } - -##function -check_sudo(){ - +## +## Check whether doas/su/sudo/sup is used or not +## +check_sudo() { LABEL="$1" if [ "${USING_SUDO}" = "1" ]; then @@ -344,8 +331,7 @@ check_sudo(){ ## Check the output of a command provided as argument against an ## expected output. Return 1 if the check fails, otherwise return 0 ## -##function -chk_out(){ +chk_out() { EXP_OUT=$1 shift @@ -353,9 +339,8 @@ chk_out(){ ACT_OUT=$($@) [ "${ACT_OUT}" = "${EXP_OUT}" ] || \ log "chk_out" "Error: got '${ACT_OUT}' when expecting '${EXP_OUT}'" && \ - return 1 - return 0 - + return 1 + return 0 } @@ -363,9 +348,8 @@ chk_out(){ ## Check the exit value of a command provided as argument against an ## expected output -- return 1 if the check fails, otherwise return 0 ## -##function -chk_exit(){ - +chk_exit() { + EXP_EXIT=$1 shift log "chk_exit" "check exit value of: $(echo $@)" @@ -373,38 +357,33 @@ chk_exit(){ ACT_EXIT=$? [ "${ACT_EXIT}" = "${EXP_EXIT}" ] || \ log "chk_exit" "Error: got '${ACT_EXIT}' when expecting '${EXP_EXIT}'" && \ - return 1 - return 0 + return 1 + return 0 } - - ########################################## -##function -edit_file(){ +edit_file() { + FILEIN=$1 - ##local - FILEIN=$1 - log "edit_file" "editing file ${FILEIN}" - eval "${DIALOG} --title 'Editing file: ${FILEIN}' \ - --editbox ${FILEIN} ${WINDOW_HEIGHT} ${WINDOW_WIDTH}" 2> ${TMPFILE} - - if [ $? -eq 0 ]; then - log "edit_file" "Copying ${TMPFILE} into ${FILEIN}" - if cp "${TMPFILE}" "${FILEIN}" - then - eval "${DIALOG} --msgbox 'File ${FILEIN} saved successfully' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" - else - eval "${DIALOG} --msgbox 'Error saving file ${FILEIN}' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" - fi - else - log "edit_file" "Editing of ${FILEIN} aborted..." - eval "${DIALOG} --msgbox 'File ${FILEIN} not saved' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" - fi + log "edit_file" "editing file ${FILEIN}" + eval "${DIALOG} --title 'Editing file: ${FILEIN}' \ + --editbox ${FILEIN} ${WINDOW_HEIGHT} ${WINDOW_WIDTH}" 2> ${TMPFILE} + + if [ $? -eq 0 ]; then + log "edit_file" "Copying ${TMPFILE} into ${FILEIN}" + if cp "${TMPFILE}" "${FILEIN}";then + eval "${DIALOG} --msgbox 'File ${FILEIN} saved successfully' \ + ${INFO_HEIGHT} ${INFO_WIDTH}" + else + eval "${DIALOG} --msgbox 'Error saving file ${FILEIN}' \ + ${INFO_HEIGHT} ${INFO_WIDTH}" + fi + else + log "edit_file" "Editing of ${FILEIN} aborted..." + eval "${DIALOG} --msgbox 'File ${FILEIN} not saved' \ + ${INFO_HEIGHT} ${INFO_WIDTH}" + fi } @@ -413,33 +392,28 @@ edit_file(){ ## ## Read all the configured addresses for a given inet family ## -##function -get_addr_family(){ - -##local - DEVNAME=$1 - ##local - DEVFAMILY=$2 - - NUMADDR=$(ip -f "${DEVFAMILY}" addr show "${DEVNAME}" | grep -c "${DEVFAMILY}") - ADDR_STR="" - for i in $(seq ${NUMADDR}); do - ADDR=$(ip -f "${DEVFAMILY}" addr show "${DEVNAME}" | grep "${DEVFAMILY}" | \ - tail -n +$i | head -1 | sed -r -e "s:^\ +::g" | cut -d " " -f 2,4,6 |\ - sed -r -e "s:\ : -- :g") - ADDR_STR="${ADDR_STR}\n${DEVFAMILY}: ${ADDR}\n" - done + +get_addr_family() { + DEVNAME=$1 + DEVFAMILY=$2 + + NUMADDR=$(ip -f "${DEVFAMILY}" addr show "${DEVNAME}" | grep -c "${DEVFAMILY}") + ADDR_STR="" + for i in $(seq ${NUMADDR}); do + ADDR=$(ip -f "${DEVFAMILY}" addr show "${DEVNAME}" | grep "${DEVFAMILY}" | \ + tail -n +$i | head -1 | sed -r -e "s:^\ +::g" | cut -d " " -f 2,4,6 | + sed -r -e "s:\ : -- :g") + ADDR_STR="${ADDR_STR}\n${DEVFAMILY}: ${ADDR}\n" + done } ## ## Show the current configuration of a given device ## -##function -show_device_conf(){ - -##local -DEVNAME=$1 + +show_device_conf() { + DEVNAME=$1 if [ -z "${DEVNAME}" ]; then return -1 fi @@ -452,9 +426,9 @@ DEVNAME=$1 log "show_device_conf" "NET_FAMILIES: \"${NET_FAMILIES}\"" for f in ${NET_FAMILIES}; do - get_addr_family ${DEVNAME} ${f} - log "show_device_conf" "family: ${f} ADDR_STR: \"${ADDR_STR}\"" - + get_addr_family ${DEVNAME} ${f} + log "show_device_conf" "family: ${f} ADDR_STR: \"${ADDR_STR}\"" + if [ -z "${ADDR_STR}" ]; then DEVCONF="${DEVCONF}${f}: Unconfigured\n" else @@ -471,50 +445,37 @@ DEVNAME=$1 } - - -##function -config_ip_static(){ - - ##local +config_ip_static() { DEV_IP="192.168.1.2" - ##local - DEV_NET="192.168.1.0" - ##local + DEV_NET="192.168.1.0" DEV_NETMASK="255.255.255.0" - ##local DEV_GW="192.168.1.1" - ##local DEV_DNS1="208.67.222.222" - ##local DEV_DNS2="208.67.220.220" - - ##local DEVNAME=$1 - eval "${DIALOG} --form 'Set network for device: ${DEVNAME}' \ - ${FORM_HEIGHT} ${FORM_WIDTH} 6 \ - 'IP' 1 1 '${DEV_IP}' 1 16 16 16 \ - 'Network' 2 1 '${DEV_NET}' 2 16 16 16 \ - 'Netmask' 3 1 '${DEV_NETMASK}' 3 16 16 16 \ - 'Gateway' 4 1 '${DEV_GW}' 4 16 16 16 \ - 'Primary DNS' 5 1 '${DEV_DNS1}' 5 16 16 16 \ - 'Secondary DNS' 6 1 '${DEV_DNS2}' 6 16 16 16 " \ - 2> ${TMPFILE} + ${FORM_HEIGHT} ${FORM_WIDTH} 6 \ + 'IP' 1 1 '${DEV_IP}' 1 16 16 16 \ + 'Network' 2 1 '${DEV_NET}' 2 16 16 16 \ + 'Netmask' 3 1 '${DEV_NETMASK}' 3 16 16 16 \ + 'Gateway' 4 1 '${DEV_GW}' 4 16 16 16 \ + 'Primary DNS' 5 1 '${DEV_DNS1}' 5 16 16 16 \ + 'Secondary DNS' 6 1 '${DEV_DNS2}' 6 16 16 16 " \ + 2> ${TMPFILE} if [ $? -eq 1 ]; then eval "${DIALOG} --infobox 'Configuration of ${DEVNAME} aborted' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" - return + ${INFO_HEIGHT} ${INFO_WIDTH}" + return fi cat ${TMPFILE} | tr '\n' ' ' >${TMPFILE}_2 - + read DEV_IP DEV_NET DEV_NETMASK DEV_GW DEV_DNS1 DEV_DNS2 <${TMPFILE}_2 eval "${DIALOG} --msgbox 'Proposed configuration of ${DEVNAME}:\n \ -IP: ${DEV_IP}\nNetwork: ${DEV_NET}\nNetmask: ${DEV_NETMASK}\nGateway: \ -${DEV_GW}\nDNS1: ${DEV_DNS1}\nDNS2: ${DEV_DNS2}'\ + IP: ${DEV_IP}\nNetwork: ${DEV_NET}\nNetmask: ${DEV_NETMASK}\nGateway: \ + ${DEV_GW}\nDNS1: ${DEV_DNS1}\nDNS2: ${DEV_DNS2}'\ ${WINDOW_HEIGHT} ${WINDOW_WIDTH}" rm -f ${TMPFILE}_2 @@ -526,138 +487,101 @@ ${DEV_GW}\nDNS1: ${DEV_DNS1}\nDNS2: ${DEV_DNS2}'\ chk_exit 0 ip address add "${DEV_IP}/${DEV_NETMASK}" dev "${DEVNAME}" ## Configure GW - #if [ -n "${DEV_GW}" ]; then chk_exit 0 ip route flush dev "${DEVNAME}" chk_exit 0 ip route add "${DEV_NET}/${DEV_NETMASK}" dev "${DEVNAME}" chk_exit 0 ip route add default via "${DEV_GW}" - #fi + ## Configure DNS - #if [ -n "${DEV_DNS1}" ] || - # [ -n "${DEV_DNS1}" ]; then - mv /etc/resolv.conf /etc/resolv.conf.bak - if [ -n "${DEV_DNS1}" ]; then - echo "nameserver ${DEV_DNS1}" >> /etc/resolv.conf - fi - if [ -n "${DEV_DNS2}" ]; then - echo "nameserver ${DEV_DNS2}" >> /etc/resolv.conf - fi - [ -z "${SUPPRESS}" ] && show_device_conf "${DEVNAME}" - #fi + mv /etc/resolv.conf /etc/resolv.conf.bak + if [ -n "${DEV_DNS1}" ]; then + echo "nameserver ${DEV_DNS1}" >> /etc/resolv.conf + fi + if [ -n "${DEV_DNS2}" ]; then + echo "nameserver ${DEV_DNS2}" >> /etc/resolv.conf + fi + [ -z "${SUPPRESS}" ] && show_device_conf "${DEVNAME}" } -##function -config_ip_dhcp(){ - -##local + +config_ip_dhcp() { DEVNAME=$1 - - ##eval "${DIALOG} --msgbox 'Running \"dhclient ${DEVNAME}\"' ${INFO_HEIGHT} ${INFO_WIDTH}" dhclient -r ${DEVNAME} 2>/dev/null dhclient -v ${DEVNAME} 2>&1 | eval "${DIALOG} --title 'Running dhclient ${DEVNAME}' \ - --programbox ${WINDOW_HEIGHT} ${WINDOW_WIDTH}" 2>${TMPFILE} - if [ $! -ne 0 ];then + --programbox ${WINDOW_HEIGHT} ${WINDOW_WIDTH}" 2>${TMPFILE} + + if [ $! -ne 0 ];then log "config_ip_dhcp" "dhclient aborted" fi [ -z "${SUPPRESS}" ] && show_device_conf ${DEVNAME} } -##function -configure_ip_address(){ - -##local + +configure_ip_address() { DEVNAME=$1 - - eval "${DIALOG} --cancel-label 'Up' \ - --menu 'Configuring ${DEVNAME}' ${INFO_HEIGHT} ${INFO_WIDTH} 4 \ - 'DHCP' ''\ - 'Static' ''" 2>${TMPFILE} - if [ $? -eq 1 ]; then - return - fi - ACTION=$(cat ${TMPFILE}) - case ${ACTION} in - "Static") - config_ip_static ${DEVNAME} - ;; - "DHCP") - config_ip_dhcp ${DEVNAME} - ;; - esac -} - -##function -wifi_essid_from_mac(){ - - ##local - DEVNAME=$1 - ##local - W_MAC=$2 - - W_ESSID="$(wpa_cli -i "${DEVNAME}" scan_results | grep -E "^${W_MAC}" | \ - sed -r -e 's/\t/\|/g' | cut -d "|" -f 5)" - - log "wifi_essid_from_mac" "Recovered ESSID: ${W_ESSID}" -} - -##function -wifi_flags_from_mac(){ -##local - DEVNAME=$1 -##local - W_MAC=$2 - - W_FLAGS=$(wpa_cli -i "${DEVNAME}" scan_results | grep -E "^${W_MAC}" | \ - sed -r -e 's/\t/\|/g' | cut -d "|" -f 4) - log "wifi_essid_from_mac" "Recovered W_FLAGS: ${W_FLAGS}" - -} - - -##function -wifi_network_list(){ - -##local - DEVNAME=$1 - wpa_cli -i ${DEVNAME} list_networks | tail -n +2 | sed -r -e 's/\t/\|/g' > ${TMPFILE} - - NETLIST="" - LAST_IFS=$IFS - IFS="|" - while read NETNUM NETESSID NETBSSID NETFLAGS; do - IS_DIS=$(echo ${NETFLAGS} | sed -r -e 's/\[//g;s/\]//g' | grep -c -i disabled ) - if [ ${IS_DIS} -eq 1 ]; then - STATUS="(DIS)" - else - STATUS="(ENAB)" - fi - IS_CUR=$(echo ${NETFLAGS} | sed -r -e 's/\[//g;s/\]//g' | grep -c -i current ) - if [ ${IS_CUR} -eq 1 ]; then - STATUS="${STATUS}(CUR)" - fi - - - NETLIST="${NETLIST} ${NETNUM} \"${NETESSID}-${STATUS}\"" - done < ${TMPFILE} - IFS=${LAST_IFS} - - log "wifi_network_list" "NETLIST: ${NETLIST}" -} - -##function -wpa_authenticate_EAP_TLS(){ - - ##unimplemented "wpa_authenticate_EAP_TLS" - ##return 1 - + eval "${DIALOG} --cancel-label 'Up' \ + --menu 'Configuring ${DEVNAME}' ${INFO_HEIGHT} ${INFO_WIDTH} 4 \ + 'DHCP' ''\ + 'Static' ''" 2>${TMPFILE} + if [ $? -eq 1 ]; then + return + fi + ACTION=$(cat ${TMPFILE}) + case ${ACTION} in + "Static") + config_ip_static ${DEVNAME} + ;; + "DHCP") + config_ip_dhcp ${DEVNAME} + ;; + esac +} +wifi_essid_from_mac() { + DEVNAME=$1 + W_MAC=$2 + W_ESSID="$(wpa_cli -i "${DEVNAME}" scan_results | grep -E "^${W_MAC}" | \ + sed -r -e 's/\t/\|/g' | cut -d "|" -f 5)" + log "wifi_essid_from_mac" "Recovered ESSID: ${W_ESSID}" +} +wifi_flags_from_mac() { + DEVNAME=$1 + W_MAC=$2 + W_FLAGS=$(wpa_cli -i "${DEVNAME}" scan_results | grep -E "^${W_MAC}" | \ + sed -r -e 's/\t/\|/g' | cut -d "|" -f 4) + log "wifi_essid_from_mac" "Recovered W_FLAGS: ${W_FLAGS}" +} +wifi_network_list() { + DEVNAME=$1 + wpa_cli -i ${DEVNAME} list_networks | tail -n +2 | sed -r -e 's/\t/\|/g' > ${TMPFILE} + NETLIST="" + LAST_IFS=$IFS + IFS="|" + while read NETNUM NETESSID NETBSSID NETFLAGS; do + IS_DIS=$(echo ${NETFLAGS} | sed -r -e 's/\[//g;s/\]//g' | grep -c -i disabled ) + if [ ${IS_DIS} -eq 1 ]; then + STATUS="(DIS)" + else + STATUS="(ENAB)" + fi + IS_CUR=$(echo ${NETFLAGS} | sed -r -e 's/\[//g;s/\]//g' | grep -c -i current ) + if [ ${IS_CUR} -eq 1 ]; then + STATUS="${STATUS}(CUR)" + fi + NETLIST="${NETLIST} ${NETNUM} \"${NETESSID}-${STATUS}\"" + done < ${TMPFILE} + IFS=${LAST_IFS} + + log "wifi_network_list" "NETLIST: ${NETLIST}" +} +wpa_authenticate_EAP_TLS() { DEVNAME=$1 W_ESSID="$2" ## We first add the new network NET_NUM=$(wpa_cli -i ${DEVNAME} add_network | tail -1) - + log "wifi_authenticate_EAP_PEAP" "NET_NUM: ${NET_NUM}" chk_out "OK" wpa_cli -i ${DEVNAME} set_network ${NET_NUM} ssid "\"${W_ESSID}\"" @@ -669,15 +593,14 @@ wpa_authenticate_EAP_TLS(){ ## - client certificate ## - ## - eval "${DIALOG} --form 'PEAP parameters:' \ - ${FORM_HEIGHT} ${FORM_WIDTH} 3 \ - 'identity' 1 1 '' 1 20 30 80 \ - 'CA certificate' 2 1 '' 2 20 30 200 \ - 'client certificate' 3 1 '' 3 20 30 200 \ - 'private key' 4 1 '' 4 20 30 200 \ - 'private key password' 5 1 '' 5 30 30 80 \ - " 2>${TMPFILE} + ${FORM_HEIGHT} ${FORM_WIDTH} 3 \ + 'identity' 1 1 '' 1 20 30 80 \ + 'CA certificate' 2 1 '' 2 20 30 200 \ + 'client certificate' 3 1 '' 3 20 30 200 \ + 'private key' 4 1 '' 4 20 30 200 \ + 'private key password' 5 1 '' 5 30 30 80 \ + " 2>${TMPFILE} if [ $? != "0" ]; then log "wifi_authenticate_EAP_TLS" "Aborting EAP/TLS authentication" @@ -695,7 +618,6 @@ wpa_authenticate_EAP_TLS(){ ## Remove everything from the temp file echo "" > ${TMPFILE} - chk_out "OK" wpa_cli -i ${DEVNAME} set_network ${NET_NUM} key_mgmt WPA-EAP ## Set eap to PEAP @@ -709,8 +631,8 @@ wpa_authenticate_EAP_TLS(){ chk_out "OK" wpa_cli -i ${DEVNAME} set_network ${NET_NUM} private_key_passwd "\"${EAP_PRIV_KEY_PWD}\"" eval "${DIALOG} --defaultno --yesno \ - 'Network \"${W_ESSID}\" configured\nSave configuration file?' \ - ${INFO_HEIGHT} ${INFO_WIDTH} " 2> ${TMPFILE} + 'Network \"${W_ESSID}\" configured\nSave configuration file?' \ + ${INFO_HEIGHT} ${INFO_WIDTH} " 2> ${TMPFILE} if [ $? -eq 0 ]; then ## Save the config file wifi_save_file ${DEVNAME} @@ -720,38 +642,28 @@ wpa_authenticate_EAP_TLS(){ chk_out "OK" wpa_cli -i ${DEVNAME} enable_network ${NET_NUM} return 0 - -} - - -##function -wpa_authenticate_EAP_PEAP(){ - - ##unimplemented "wpa_authenticate_EAP_PEAP" - +} +wpa_authenticate_EAP_PEAP() { DEVNAME=$1 W_ESSID="$2" ## We first add the new network NET_NUM=$(wpa_cli -i ${DEVNAME} add_network | tail -1) - log "wifi_authenticate_EAP_PEAP" "NET_NUM: ${NET_NUM}" chk_out "OK" wpa_cli -i ${DEVNAME} set_network ${NET_NUM} ssid "\"${W_ESSID}\"" - ## we get the needed information, namely: ## ## - identity ## - password ## - server certificate (ca_cert) ## - eval "${DIALOG} --form 'PEAP parameters:' \ - ${FORM_HEIGHT} ${FORM_WIDTH} 3 \ - 'identity' 1 1 '' 1 20 30 80 \ - 'password' 2 1 '' 2 20 30 80 \ - 'CA certificate' 3 1 '' 3 20 30 80 \ - " 2>${TMPFILE} + ${FORM_HEIGHT} ${FORM_WIDTH} 3 \ + 'identity' 1 1 '' 1 20 30 80 \ + 'password' 2 1 '' 2 20 30 80 \ + 'CA certificate' 3 1 '' 3 20 30 80 \ + " 2>${TMPFILE} if [ $? != "0" ]; then log "wifi_authenticate_EAP_PEAP" "Aborting EAP/PEAP authentication" @@ -785,8 +697,9 @@ wpa_authenticate_EAP_PEAP(){ fi eval "${DIALOG} --defaultno --yesno \ - 'Network \"${W_ESSID}\" configured\nSave configuration file?' \ - ${INFO_HEIGHT} ${INFO_WIDTH} " 2> ${TMPFILE} + 'Network \"${W_ESSID}\" configured\nSave configuration file?' \ + ${INFO_HEIGHT} ${INFO_WIDTH} " 2> ${TMPFILE} + if [ $? -eq 0 ]; then ## Save the config file wifi_save_file ${DEVNAME} @@ -796,28 +709,20 @@ wpa_authenticate_EAP_PEAP(){ ## We can now enable the network chk_out "OK" wpa_cli -i ${DEVNAME} enable_network ${NET_NUM} - return 0 - + return 0 } - - -## -## Open access point -- no WPA -## -##function -wifi_authenticate_NONE(){ - +wifi_authenticate_NONE() { DEVNAME="$1" W_ESSID="$2" - NET_NUM=$(wpa_cli -i ${DEVNAME} add_network | tail -1) - + log "wifi_authenticate" "NET_NUM: ${NET_NUM}" chk_out "OK" wpa_cli -i ${DEVNAME} set_network ${NET_NUM} ssid "\"${W_ESSID}\"" chk_out "OK" wpa_cli -i ${DEVNAME} set_network ${NET_NUM} key_mgmt NONE eval "${DIALOG} --defaultno --yesno \ - 'Network \"${W_ESSID}\" added\nSave configuration file?' \ - ${INFO_HEIGHT} ${INFO_WIDTH} " 2> ${TMPFILE} + 'Network \"${W_ESSID}\" added\nSave configuration file?' \ + ${INFO_HEIGHT} ${INFO_WIDTH} " 2> ${TMPFILE} + if [ $? -eq 0 ]; then ## Save the config file wifi_save_file ${DEVNAME} @@ -829,29 +734,25 @@ wifi_authenticate_NONE(){ return 0 } - - -##function -wpa_authenticate_PSK(){ - +wpa_authenticate_PSK() { DEVNAME=$1 W_ESSID="$2" - + PSK="" PSK_LENGTH=${#PSK} while [ ${PSK_LENGTH} -le 7 ]; do eval "${DIALOG} --insecure --inputbox 'Please insert WPA PSK\n(min 8 characters)' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" 2> ${TMPFILE} + ${INFO_HEIGHT} ${INFO_WIDTH}" 2> ${TMPFILE} + if [ $? -eq 1 ]; then eval "${DIALOG} --msgbox 'Network configuration aborted!!!' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" - return 1 + ${INFO_HEIGHT} ${INFO_WIDTH}" + return 1 fi PSK=$(cat ${TMPFILE}) PSK_LENGTH=${#PSK} done - NET_NUM=$(wpa_cli -i ${DEVNAME} add_network | tail -1) log "wifi_authenticate_PSK" "NET_NUM: ${NET_NUM}" @@ -864,8 +765,9 @@ wpa_authenticate_PSK(){ ## remove the password from tmpfile echo "" > ${TMPFILE} eval "${DIALOG} --defaultno --yesno \ - 'Network \"${W_ESSID}\" added\nSave configuration file?' \ - ${INFO_HEIGHT} ${INFO_WIDTH} " 2> ${TMPFILE} + 'Network \"${W_ESSID}\" added\nSave configuration file?' \ + ${INFO_HEIGHT} ${INFO_WIDTH} " 2> ${TMPFILE} + if [ $? -eq 0 ]; then ## Save the config file wifi_save_file ${DEVNAME} @@ -876,22 +778,8 @@ wpa_authenticate_PSK(){ eval "${DIALOG} --msgbox 'Network added successfully' ${INFO_HEIGHT} ${INFO_WIDTH}" return 0 - - } - -## -## Manage WPA authentication. Choose among the available -## authentication systems currently supported: -## -## - PSK -## - EAP/PEAP -## - EAP/TLS -## - -##function -wifi_authenticate_WPA(){ - +wifi_authenticate_WPA() { DEVNAME=$1 W_ESSID="$2" @@ -921,84 +809,66 @@ wifi_authenticate_WPA(){ eval "${DIALOG} --menu 'Select authentication' ${WINDOW_HEIGHT} ${WINDOW_WIDTH} 10 \ - ${MENU_ITEMS} " 2> ${TMPFILE} + ${MENU_ITEMS} " 2> ${TMPFILE} if [ $? != "0" ]; then ## conf aborted log "wifi_authenticate_WPA" "configuration aborted" return 1; - fi - + fi SEL_MODE=$(cat ${TMPFILE}) log "wifi_authenticate_WPA" "SEL_MODE: ${SEL_MODE}" case ${SEL_MODE} in "WPA+EAP/PEAP"|"WPA2+EAP/PEAP") - wpa_authenticate_EAP_PEAP ${DEVNAME} "${W_ESSID}" - ;; + wpa_authenticate_EAP_PEAP ${DEVNAME} "${W_ESSID}" + ;; "WPA+EAP/TLS"|"WPA2+EAP/TLS") wpa_authenticate_EAP_TLS ${DEVNAME} "${W_ESSID}" - ;; + ;; "WPA+PSK"|"WPA2+PSK") wpa_authenticate_PSK ${DEVNAME} "${W_ESSID}" ;; *) log "wifi_authenticate_WPA" "Error. SEL_MODE '${SEL_MODE}' unsupported" - esac - - } - - - ## ## Manage the authentication for a given wifi ESSID ## ## We use wpa_cli to check the type of authentication supported by the ## network, and then we call the corresponding function -## - -##function -wifi_authenticate(){ - -##local +## +wifi_authenticate() { DEVNAME=$1 - ##local W_MAC=$2 - - + log "wifi_authenticate" "configuring ${DEVNAME} on ${W_MAC}" - ## This will set the variable W_ESSID appropriately - wifi_essid_from_mac ${DEVNAME} ${W_MAC} - - ## This will set the variable W_FLAGS appropriately - wifi_flags_from_mac ${DEVNAME} ${W_MAC} + ## This will set the variable W_ESSID appropriately + wifi_essid_from_mac ${DEVNAME} ${W_MAC} + ## This will set the variable W_FLAGS appropriately + wifi_flags_from_mac ${DEVNAME} ${W_MAC} - log "wifi_authenticate" "configuring essid: ${W_ESSID} on device: ${DEVNAME}" - log "wifi_authenticate" "W_FLAGS: ${W_FLAGS}" + log "wifi_authenticate" "configuring essid: ${W_ESSID} on device: ${DEVNAME}" + log "wifi_authenticate" "W_FLAGS: ${W_FLAGS}" - - ## If the network exists already, we first remove it... - - NET_EXISTS=$(wpa_cli -i ${DEVNAME} list_networks | tail -n +2 | sed -r -e 's/\t/\|/g' \ - | cut -d "|" -f 2 | grep -c "${W_ESSID}$" ) - if [ ${NET_EXISTS} != 0 ]; then - NET_NUM=$(wpa_cli -i ${DEVNAME} list_networks | tail -n +2 | sed -r -e 's/\t/\|/g' \ - | cut -d "|" -f 1,2 | grep "${W_ESSID}$" | cut -d "|" -f 1) - STATUS=$(wpa_cli -i ${DEVNAME} remove_network ${NET_NUM}) - if [ "${STATUS}" != "OK" ]; then - eval "${DIALOG} --msgbox 'Error while removing existing \ - network:\n$essid: {W_ESSID}'" ${INFO_HEIGHT} ${INFO_WIDTH} - return + ## If the network exists already, we first remove it... + NET_EXISTS=$(wpa_cli -i ${DEVNAME} list_networks | tail -n +2 | sed -r -e 's/\t/\|/g' \ + | cut -d "|" -f 2 | grep -c "${W_ESSID}$" ) + if [ ${NET_EXISTS} != 0 ]; then + NET_NUM=$(wpa_cli -i ${DEVNAME} list_networks | tail -n +2 | sed -r -e 's/\t/\|/g' \ + | cut -d "|" -f 1,2 | grep "${W_ESSID}$" | cut -d "|" -f 1) + STATUS=$(wpa_cli -i ${DEVNAME} remove_network ${NET_NUM}) + if [ "${STATUS}" != "OK" ]; then + eval "${DIALOG} --msgbox 'Error while removing existing \ + network:\n$essid: {W_ESSID}'" ${INFO_HEIGHT} ${INFO_WIDTH} + return + fi fi - fi - ## Check whether WPA is available - HAS_WPA=$(echo "${W_FLAGS}" | grep -E -c "WPA" ) - + log "wifi_authenticate" "HAS_WPA: \"${HAS_WPA}\"" ### This will configure WPA @@ -1029,286 +899,234 @@ wifi_authenticate(){ eval "${DIALOG} --msgbox 'No supported authentication method for ${W_ESSID}'" return 1 } - - - - ## ## Configure a new connection from a list of available wi-fi networks -## - -##function -wifi_add(){ - -##local -DEVNAME=$1 +## +wifi_add() { + DEVNAME=$1 wpa_cli -i ${DEVNAME} scan eval "${DIALOG} --timeout 4 --msgbox 'Scanning for networks...' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" - wpa_cli -i ${DEVNAME} scan_results | grep -E "^[0-9a-f][0-9a-f]:" | \ - sed -r -e 's/\t/|/g' |\ - sort -t "|" -r -n -k 3 > ${TMPFILE} + ${INFO_HEIGHT} ${INFO_WIDTH}" + wpa_cli -i ${DEVNAME} scan_results | grep -E "^[0-9a-f][0-9a-f]:" | \ + sed -r -e 's/\t/|/g' |\ + sort -t "|" -r -n -k 3 > ${TMPFILE} - wifinets="" - LAST_IFS=$IFS - IFS="|" - while read W_MAC W_FREQ W_STRNGT W_FLAGS W_ESSID; do + wifinets="" + LAST_IFS=$IFS + IFS="|" + while read W_MAC W_FREQ W_STRNGT W_FLAGS W_ESSID; do + log "wifi_add" "W_ESSID: \"${W_ESSID}\"" + wifinets="${wifinets} ${W_MAC} \"${W_ESSID} -- ${W_FLAGS}\"" + done < ${TMPFILE} + IFS=${LAST_IFS} + + log "wifi_add" "Wifi nets: \n${wifinets}\n===" + eval "dialog --menu 'Select a network' ${WINDOW_HEIGHT} ${WINDOW_WIDTH} 10 \ + ${wifinets} " 2> ${TMPFILE} - log "wifi_add" "W_ESSID: \"${W_ESSID}\"" - wifinets="${wifinets} ${W_MAC} \"${W_ESSID} -- ${W_FLAGS}\"" - done < ${TMPFILE} - IFS=${LAST_IFS} - - - log "wifi_add" "Wifi nets: \n${wifinets}\n===" - eval "dialog --menu 'Select a network' ${WINDOW_HEIGHT} ${WINDOW_WIDTH} 10 \ - ${wifinets} " 2> ${TMPFILE} - if [ $? -eq 1 ]; then - return - fi - - W_MAC=$(cat ${TMPFILE}) - - - wifi_authenticate ${DEVNAME} ${W_MAC} - if [ $? != "0" ]; then - eval "${DIALOG} --msgbox 'Error while configuring ${DEVNAME}' " - fi - return $? + if [ $? -eq 1 ]; then + return + fi + W_MAC=$(cat ${TMPFILE}) + wifi_authenticate ${DEVNAME} ${W_MAC} + if [ $? != "0" ]; then + eval "${DIALOG} --msgbox 'Error while configuring ${DEVNAME}' " + fi + return $? } - - -##function -wifi_save_file(){ - -##local +wifi_save_file() { DEVNAME=$1 - - SAVE_STATUS=$(wpa_cli -i ${DEVNAME} save_config | tail -1 ) - if [ "${SAVE_STATUS}" = "OK" ]; then - eval "${DIALOG} --msgbox 'Current configuration dumped to file ${WPA_FILE}' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" +SAVE_STATUS=$(wpa_cli -i ${DEVNAME} save_config | tail -1 ) +if [ "${SAVE_STATUS}" = "OK" ]; then + eval "${DIALOG} --msgbox 'Current configuration dumped to file ${WPA_FILE}' \ + ${INFO_HEIGHT} ${INFO_WIDTH}" + else + eval "${DIALOG} --msgbox 'Error while saving configuration to file ${WPA_FILE}' \ + ${INFO_HEIGHT} ${INFO_WIDTH}" +fi +} +wifi_remove() { + DEVNAME=$1 + wifi_network_list ${DEVNAME} + + eval "${DIALOG} --menu 'Select network to remove' \ + ${WINDOW_HEIGHT} ${WINDOW_WIDTH} 10 ${NETLIST}" \ + 2> ${TMPFILE} + + if [ $? -eq 0 ]; then + ## a network has been selected + NETNUM=$(cat ${TMPFILE}) + WPA_STATUS=$(wpa_cli -i ${DEVNAME} remove_network ${NETNUM} | tail -1 ) + if [ "${WPA_STATUS}" = "OK" ]; then + eval "${DIALOG} --defaultno --yesno \ + 'Network ${NETNUM} removed\nSave configuration file?' \ + ${INFO_HEIGHT} ${INFO_WIDTH}" 2> ${TMPFILE} + + if [ $? -eq 0 ]; then + ## Save the config file + wifi_save_file ${DEVNAME} + fi + return + else + eval "${DIALOG} --msgbox 'Network ${NETNUM} NOT removed' \ + ${INFO_HEIGHT} ${INFO_WIDTH}" + + return + fi else - eval "${DIALOG} --msgbox 'Error while saving configuration to file ${WPA_FILE}' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" - fi + eval "${DIALOG} --msgbox 'No network removed!!!' \ + ${INFO_HEIGHT} ${INFO_WIDTH}" + + return + fi } +wifi_restart_wpa() { + DEVNAME=$1 + WPA_FILE=$2 + WPA_PID=$(ps ax | grep wpa_supplicant | grep " -i ${DEVNAME} " | sed -r -e 's/^\ +//g' | cut -d " " -f 1) + WPA_CLI_PID=$(ps ax | grep wpa_cli | grep "-a /etc/wpa_supplicant/wpa_cli.sh " | sed -r -e 's/^\ +//g' | cut -d " " -f 1) -##function -wifi_remove(){ - -##local - DEVNAME=$1 - - wifi_network_list ${DEVNAME} - - eval "${DIALOG} --menu 'Select network to remove' \ - ${WINDOW_HEIGHT} ${WINDOW_WIDTH} 10 ${NETLIST}" \ - 2> ${TMPFILE} - - if [ $? -eq 0 ]; then - ## a network has been selected - NETNUM=$(cat ${TMPFILE}) - WPA_STATUS=$(wpa_cli -i ${DEVNAME} remove_network ${NETNUM} | tail -1 ) - if [ "${WPA_STATUS}" = "OK" ]; then - eval "${DIALOG} --defaultno --yesno \ - 'Network ${NETNUM} removed\nSave configuration file?' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" 2> ${TMPFILE} - if [ $? -eq 0 ]; then - ## Save the config file - wifi_save_file ${DEVNAME} - fi - - return - else - eval "${DIALOG} --msgbox 'Network ${NETNUM} NOT removed' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" - return - fi - else - eval "${DIALOG} --msgbox 'No network removed!!!' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" - return - fi - -} - - -##function -wifi_restart_wpa(){ - -##local - DEVNAME=$1 -##local - WPA_FILE=$2 - - WPA_PID=$(ps ax | grep wpa_supplicant | grep " -i ${DEVNAME} " | -sed -r -e 's/^\ +//g' | cut -d " " -f 1) - - if [ -n "${WPA_PID}" ]; then + if [ -n "wpa_supplicant" ]; then log "wifi_restart_wpa" "WPA_PID: ${WPA_PID}" kill -9 ${WPA_PID} + kill -9 ${WPA_CLI_PID} else log "wifi_restart_wpa" "no wpa_supplicant is running!!!" - fi + fi + wpa_supplicant -B -i ${DEVNAME} -c ${WPA_FILE} -P${WPA_PIDFILE} 2>&1 >/dev/null - WPA_PID=$(ps ax | grep wpa_supplicant | grep " -i ${DEVNAME}" | \ - sed -r -e 's/^\ +//g' | cut -d " " -f 1 ) + wpa_cli -a /etc/wpa_supplicant/wpa_cli.sh + + WPA_PID=$(ps ax | grep wpa_supplicant | grep " -i ${DEVNAME}" | sed -r -e 's/^\ +//g' | cut -d " " -f 1 ) WPA_PID_SAVED=$(cat ${WPA_PIDFILE}) - log "wifi_restart_wpa" "WPA_PID: ${WPA_PID} WPA_PID_SAVED: ${WPA_PID_SAVED}" - if [ -n "${WPA_PID}" ] && [ "${WPA_PID}" != "${WPA_PID_SAVED}" ]; then - eval "${DIALOG} --msgbox 'Error restarting wpa_supplicant' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" - else - eval "${DIALOG} --msgbox 'wpa_supplicant restarted successfully' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" - fi - + log "wifi_restart_wpa" "WPA_PID: ${WPA_PID} WPA_PID_SAVED: ${WPA_PID_SAVED}" + if [ -n "${WPA_PID}" ] && [ "${WPA_PID}" != "${WPA_PID_SAVED}" ]; then + eval "${DIALOG} --msgbox 'Error restarting wpa_supplicant' \ + ${INFO_HEIGHT} ${INFO_WIDTH}" + + else + eval "${DIALOG} --msgbox 'wpa_supplicant restarted successfully' \ + ${INFO_HEIGHT} ${INFO_WIDTH}" + fi } - - - ## ## wifi_enable: show the list of configured networks, and enable the ## one the used has clicked on -## - -##function -wifi_enable(){ - -##local +## +wifi_enable() { DEVNAME=$1 - - wifi_network_list ${DEVNAME} - - eval "${DIALOG} --menu 'Select configured network' \ - ${WINDOW_HEIGHT} ${WINDOW_WIDTH} 10 ${NETLIST}" \ - 2> ${TMPFILE} - - if [ $? -eq 0 ]; then - ## a network has been selected - NETNUM=$(cat ${TMPFILE}) - WPA_STATUS=$(wpa_cli -i ${DEVNAME} enable ${NETNUM} | tail -1 ) - if [ "${WPA_STATUS}" = "OK" ]; then - eval "${DIALOG} --msgbox 'Network ${NETNUM} enabled' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" - #config_ethernet ${DEVNAME} - return - else - eval "${DIALOG} --msgbox 'Network ${NETNUM} NOT enabled' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" - return - fi - else - eval "${DIALOG} --msgbox 'No network enabled!!!' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" + wifi_network_list ${DEVNAME} + eval "${DIALOG} --menu 'Select configured network' \ + ${WINDOW_HEIGHT} ${WINDOW_WIDTH} 10 ${NETLIST}" \ + 2> ${TMPFILE} + + if [ $? -eq 0 ]; then + ## a network has been selected + NETNUM=$(cat ${TMPFILE}) + WPA_STATUS=$(wpa_cli -i ${DEVNAME} enable ${NETNUM} | tail -1 ) + if [ "${WPA_STATUS}" = "OK" ]; then + eval "${DIALOG} --msgbox 'Network ${NETNUM} enabled' \ + ${INFO_HEIGHT} ${INFO_WIDTH}" + return - fi -} - - -##function -wifi_disable(){ - -##local - DEVNAME=$1 - wifi_network_list ${DEVNAME} - eval "${DIALOG} --menu 'Select configured network' \ - ${WINDOW_HEIGHT} ${WINDOW_WIDTH} 10 ${NETLIST}" \ - 2> ${TMPFILE} - - if [ $? -eq 0 ]; then - ## a network has been selected - NETNUM=$(cat ${TMPFILE}) - WPA_STATUS=$(wpa_cli -i ${DEVNAME} disable ${NETNUM} | tail -1 ) - if [ "${WPA_STATUS}" = "OK" ]; then - eval "${DIALOG} --msgbox 'Network ${NETNUM} disabled' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" - return - else - eval "${DIALOG} --msgbox 'Network ${NETNUM} NOT disabled' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" - return - fi - else - eval "${DIALOG} --msgbox 'No network disabled!!!' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" + else + eval "${DIALOG} --msgbox 'Network ${NETNUM} NOT enabled' \ + ${INFO_HEIGHT} ${INFO_WIDTH}" + return - fi + fi + else + eval "${DIALOG} --msgbox 'No network enabled!!!' \ + ${INFO_HEIGHT} ${INFO_WIDTH}" + + return + fi } - - - - -##function -config_wifi(){ - -##local +wifi_disable() { DEVNAME=$1 + wifi_network_list ${DEVNAME} + eval "${DIALOG} --menu 'Select configured network' \ + ${WINDOW_HEIGHT} ${WINDOW_WIDTH} 10 ${NETLIST}" \ + 2> ${TMPFILE} - while true; do + if [ $? -eq 0 ]; then + ## a network has been selected + NETNUM=$(cat ${TMPFILE}) + WPA_STATUS=$(wpa_cli -i ${DEVNAME} disable ${NETNUM} | tail -1 ) + if [ "${WPA_STATUS}" = "OK" ]; then + eval "${DIALOG} --msgbox 'Network ${NETNUM} disabled' \ + ${INFO_HEIGHT} ${INFO_WIDTH}" + return + else + eval "${DIALOG} --msgbox 'Network ${NETNUM} NOT disabled' \ + ${INFO_HEIGHT} ${INFO_WIDTH}" + return + fi + else + eval "${DIALOG} --msgbox 'No network disabled!!!' \ + ${INFO_HEIGHT} ${INFO_WIDTH}" + return + fi +} +config_wifi() { + DEVNAME=$1 + + while true; do CUR_NET=$(wpa_cli -i ${DEVNAME} status | grep "^ssid" | cut -d "=" -f 2) eval "${DIALOG} --cancel-label 'Up' \ - --menu 'Configuring ${DEVNAME}\nCurrent network: ${CUR_NET}\n(Current file: ${WPA_FILE})' \ - ${WINDOW_HEIGHT} ${WINDOW_WIDTH} 12 \ - 'Restart' 'Restart wpa_supplicant' \ - 'Enable' 'Enable a configured network' \ - 'Disable' 'Disable a configured network' \ - 'Add' 'Configure a new network' \ - 'Remove' 'Delete an existing network' \ - 'Show' 'Show current configuration file' \ - 'Edit' 'Edit current configuration file' \ - 'Save' 'Save configuration to file' "\ - 2>${TMPFILE} - - if [ $? = "1" ]; then - return - fi - ACTION=$(cat ${TMPFILE}) - case ${ACTION} in - "Restart") - ## Restart wpa_supplicant - wifi_restart_wpa ${DEVNAME} ${WPA_FILE} - ;; - "Enable") - wifi_enable ${DEVNAME} - ;; - "Disable") - wifi_disable ${DEVNAME} - ;; - "Add") - wifi_add ${DEVNAME} - ;; - "Remove") - wifi_remove ${DEVNAME} - ;; - "Show") - eval "${DIALOG} --title 'Current file: ${WPA_FILE}' \ - --textbox ${WPA_FILE} ${WINDOW_HEIGHT} ${WINDOW_WIDTH}" - ;; - "Edit") - edit_file ${WPA_FILE} - ;; - "Save") - wifi_save_file ${DEVNAME} - ;; - esac - done - + --menu 'Configuring ${DEVNAME}\nCurrent network: ${CUR_NET}\n(Current file: ${WPA_FILE})' \ + ${WINDOW_HEIGHT} ${WINDOW_WIDTH} 12 \ + 'Restart' 'Restart wpa_supplicant' \ + 'Enable' 'Enable a configured network' \ + 'Disable' 'Disable a configured network' \ + 'Add' 'Configure a new network' \ + 'Remove' 'Delete an existing network' \ + 'Show' 'Show current configuration file' \ + 'Edit' 'Edit current configuration file' \ + 'Save' 'Save configuration to file' "\ + 2>${TMPFILE} + + if [ $? = "1" ]; then + return + fi + ACTION=$(cat ${TMPFILE}) + case ${ACTION} in + "Restart") + ## Restart wpa_supplicant + wifi_restart_wpa ${DEVNAME} ${WPA_FILE} + ;; + "Enable") + wifi_enable ${DEVNAME} + ;; + "Disable") + wifi_disable ${DEVNAME} + ;; + "Add") + wifi_add ${DEVNAME} + ;; + "Remove") + wifi_remove ${DEVNAME} + ;; + "Show") + eval "${DIALOG} --title 'Current file: ${WPA_FILE}' \ + --textbox ${WPA_FILE} ${WINDOW_HEIGHT} ${WINDOW_WIDTH}" + + ;; + "Edit") + edit_file ${WPA_FILE} + ;; + "Save") + wifi_save_file ${DEVNAME} + ;; + esac + done } - - - ## ## (Re)-Configure -## - -##function -configure_wifi(){ - -##local - DEVNAME=$1 +## +configure_wifi() { + DEVNAME=$1 ## Automatically Check if the network device is a wifi -- this ## should be robust... @@ -1316,14 +1134,12 @@ configure_wifi(){ IS_WIFI=$? log "configure_device" "Device ${DEVNAME} -- IS_WIFI: ${IS_WIFI} (automatic)" if [ "${IS_WIFI}" = "0" ] && \ - [ -n "${WIFI_DEVICES}" ]; then - ## WIFI_DEVICES is set, hence we check whether the current - ## device is in the list - IS_WIFI=$(echo " ${WIFI_DEVICES} " | grep -E -c "(\ ${DEVNAME}\ )") - log "configure_device" "Device ${DEVNAME} -- IS_WIFI: ${IS_WIFI} (config file)" + [ -n "${WIFI_DEVICES}" ]; then + ## WIFI_DEVICES is set, hence we check whether the current + ## device is in the list + IS_WIFI=$(echo " ${WIFI_DEVICES} " | grep -E -c "(\ ${DEVNAME}\ )") + log "configure_device" "Device ${DEVNAME} -- IS_WIFI: ${IS_WIFI} (config file)" fi - - case ${IS_WIFI} in 1) config_wifi ${DEVNAME} @@ -1331,112 +1147,84 @@ configure_wifi(){ *) ## Show a message here eval "${DIALOG} --msgbox '${DEVNAME} is not a WiFi device... ' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" + ${INFO_HEIGHT} ${INFO_WIDTH}" ;; esac - -} - - -##function -set_device_up(){ - - ##local +} +set_device_up() { DEVNAME=$1 - chk_exit 0 ip link set ${DEVNAME} up - -} - -##function -set_device_down(){ - - ##local +} +set_device_down() { DEVNAME=$1 chk_exit 0 ip link set ${DEVNAME} down - -} - -##function -show_device_menu(){ - -##local +} +show_device_menu() { DEVNAME=$1 - while true; do - DEV_STATUS=$(ip -o link | cut -d " " -f 2,9 | grep -E "^${DEVNAME}: " | cut -d " " -f 2) - log "show_device_menu" "DEVNAME: ${DEVNAME} DEV_STATUS: ${DEV_STATUS}" - eval "${DIALOG_EXTRA} --cancel-label 'Up' --menu\ - 'Device: ${DEVNAME}\nStatus: ${DEV_STATUS}' \ - ${WINDOW_HEIGHT} ${WINDOW_WIDTH} 8 \ - 'View' 'View current configuration' \ - 'Conf' 'Configure IP Address' \ - 'WiFi' 'Manage WiFi networking' \ - 'Start' 'Bring interface up' \ - 'Stop' 'Put interface down' \ - 'Restart' 'Restart interface'" 2> ${TMPFILE} - ext=$? - if [ $ext -eq 1 ]; then - return - elif [ $ext -eq 3 ]; then - exit 0 - fi + DEV_STATUS=$(ip -o link | cut -d " " -f 2,9 | grep -E "^${DEVNAME}: " | cut -d " " -f 2) + log "show_device_menu" "DEVNAME: ${DEVNAME} DEV_STATUS: ${DEV_STATUS}" + eval "${DIALOG_EXTRA} --cancel-label 'Up' --menu\ + 'Device: ${DEVNAME}\nStatus: ${DEV_STATUS}' \ + ${WINDOW_HEIGHT} ${WINDOW_WIDTH} 8 \ + 'View' 'View current configuration' \ + 'Conf' 'Configure IP Address' \ + 'WiFi' 'Manage WiFi networking' \ + 'Start' 'Bring interface up' \ + 'Stop' 'Put interface down' \ + 'Restart' 'Restart interface'" 2> ${TMPFILE} - DEV_ACTION=$(cat ${TMPFILE}) - case ${DEV_ACTION} in - "View") - show_device_conf ${DEVNAME} - ;; - "Conf") - configure_ip_address ${DEVNAME} - ;; - "WiFi") - configure_wifi ${DEVNAME} - ;; - "Start") - set_device_up ${DEVNAME} - ;; - "Stop") - set_device_down ${DEVNAME} - ;; - "Restart") - set_device_down ${DEVNAME} - set_device_up ${DEVNAME} - ;; - *) - ;; - - esac - done + ext=$? + if [ $ext -eq 1 ]; then + return + elif [ $ext -eq 3 ]; then + exit 0 + fi + DEV_ACTION=$(cat ${TMPFILE}) + case ${DEV_ACTION} in + "View") + show_device_conf ${DEVNAME} + ;; + "Conf") + configure_ip_address ${DEVNAME} + ;; + "WiFi") + configure_wifi ${DEVNAME} + ;; + "Start") + set_device_up ${DEVNAME} + ;; + "Stop") + set_device_down ${DEVNAME} + ;; + "Restart") + set_device_down ${DEVNAME} + set_device_up ${DEVNAME} + ;; + *) + ;; + esac + done } - ## ## Show all the available network devices -## - -##function +## show_devs() { + DEVICES=$(ip link show | awk 'NR % 2 == 1' | cut -d ":" -f 2) + DEVICE_TAGS="" - DEVICES=$(ip link show | awk 'NR % 2 == 1' | cut -d ":" -f 2) - - DEVICE_TAGS="" - - for i in $DEVICES; do - if [ "$i" != "lo" -o -n "${SHOW_LO}" ]; then - DEVICE_TAGS="${DEVICE_TAGS} $i $i" - fi - done - - eval "${DIALOG_EXTRA} --cancel-label 'Up' \ - --menu 'Select Interface to configure' ${WINDOW_HEIGHT} ${WINDOW_WIDTH} 4 \ - ${DEVICE_TAGS}" 2> ${TMPFILE} - return $? + for i in $DEVICES; do + if [ "$i" != "lo" -o -n "${SHOW_LO}" ]; then + DEVICE_TAGS="${DEVICE_TAGS} $i $i" + fi + done + eval "${DIALOG_EXTRA} --cancel-label 'Up' \ + --menu 'Select Interface to configure' ${WINDOW_HEIGHT} ${WINDOW_WIDTH} 4 \ + ${DEVICE_TAGS}" 2> ${TMPFILE} + + return $? } - - -##function -dev_config_menu(){ - +dev_config_menu() { while true; do show_devs ext=$? @@ -1449,13 +1237,10 @@ dev_config_menu(){ show_device_menu ${DEVNAME} done } +show_info() { +cat < ${TMPFILE} -##function -show_info(){ - - cat < ${TMPFILE} - - -+- setnet.sh ${VERSION} -+- +-+- setnet.sh ${VERSION} -+- setnet.sh is a simple state-less tool to manage and configure network interfaces. It is a shell wrapper around the functionalities of @@ -1483,18 +1268,15 @@ EOF eval "${DIALOG} --cr-wrap --textbox ${TMPFILE} ${WINDOW_HEIGHT} ${WINDOW_WIDTH}" return } +show_copyright() { +cat < ${TMPFILE} -##function -show_copyright(){ - - cat < ${TMPFILE} - - -+- setnet.sh ${VERSION} -+- +-+- setnet.sh ${VERSION} -+- -------------------------------------------------------------------- - Copyleft (C) Vincenzo "KatolaZ" Nicosia - 2016-2018 + Copyleft (C) Vincenzo "KatolaZ" Nicosia 2016-2018 + Copyleft (C) Nova 2021 -------------------------------------------------------------------- @@ -1503,14 +1285,10 @@ EOF eval "${DIALOG} --cr-wrap --textbox ${TMPFILE} ${WINDOW_HEIGHT} ${WINDOW_WIDTH}" return } +show_license() { +cat < ${TMPFILE} - -##function -show_license(){ - - cat < ${TMPFILE} - - -+- setnet.sh ${VERSION} -+- +-+- setnet.sh ${VERSION} -+- This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1527,21 +1305,16 @@ along with this program. If not, see . -------------------------------------------------------------------- - Copyleft (C) Vincenzo "KatolaZ" Nicosia - 2016-2018 + Copyleft (C) Vincenzo "KatolaZ" Nicosia 2016-2018 + Copyleft (C) Nova 2021 -------------------------------------------------------------------- EOF - eval "${DIALOG} --cr-wrap --textbox ${TMPFILE} ${WINDOW_HEIGHT} ${WINDOW_WIDTH}" - return +eval "${DIALOG} --cr-wrap --textbox ${TMPFILE} ${WINDOW_HEIGHT} ${WINDOW_WIDTH}" +return } - - - -##function -about_menu(){ - +about_menu() { while true; do eval "${DIALOG} --cancel-label 'Up' --menu 'setnet ${VERSION} -- About' \ ${WINDOW_HEIGHT} ${WINDOW_WIDTH} 6 \ @@ -1567,24 +1340,14 @@ about_menu(){ esac done } - -##function -notfound(){ - +notfound() { CMDNAME=$1 - - eval "${DIALOG} --msgbox 'Sorry! Commmand ${CMDNAME} not found!'" \ - ${INFO_HEIGHT} ${INFO_WIDTH} + ${INFO_HEIGHT} ${INFO_WIDTH} } - - -##function -netdiag_DNS(){ - +netdiag_DNS() { DUMPFILE=$1 - if [ -n "${DUMPFILE}" ]; then ## Dump to file printf "\n=====\n== DNS Configuration (/etc/resolv.conf)\n=====\n\n" >> ${DUMPFILE} @@ -1599,14 +1362,9 @@ netdiag_DNS(){ eval "${DIALOG} --title 'DNS servers' --msgbox '${MSG_STR}' "\ ${WINDOW_HEIGHT} ${WINDOW_WIDTH} - } - -##function -netdiag_resolver(){ - +netdiag_resolver() { DUMPFILE=$1 - if [ -n "${DUMPFILE}" ]; then ## Dump to file printf "\n=====\n== Resolver Configuration (/etc/nsswitch.conf)\n=====\n\n" >> ${DUMPFILE} @@ -1623,13 +1381,8 @@ netdiag_resolver(){ ${WINDOW_HEIGHT} ${WINDOW_WIDTH} } - - -##function -netdiag_routes(){ - +netdiag_routes() { DUMPFILE=$1 - HAS_NETSTAT=$(echo "${HAS_OPTS}" | grep -c "\ netstat\ ") if [ ${HAS_NETSTAT} -ne 1 ]; then notfound "netstat" @@ -1650,10 +1403,7 @@ netdiag_routes(){ "--tab-correct --tab-len 4 --textbox ${TMPFILE} "\ ${LARGE_HEIGHT} ${LARGE_WIDTH} } - -##function -netdiag_ARP(){ - +netdiag_ARP() { DUMPFILE=$1 log "netdiag_ARP" "DUMPFILE: '${DUMPFILE}'" if [ -n "${DUMPFILE}" ]; then @@ -1671,27 +1421,20 @@ netdiag_ARP(){ "--tab-correct --tab-len 4 --textbox ${TMPFILE} "\ ${LARGE_HEIGHT} ${LARGE_WIDTH} } - -##function -netdiag_connections(){ - +netdiag_connections() { DUMPFILE=$1 - - HAS_NETSTAT=$(echo "${HAS_OPTS}" | grep -c "\ netstat\ ") if [ ${HAS_NETSTAT} -ne 1 ]; then - notfound "netstat" - return + notfound "netstat" + return fi - if [ -n "${DUMPFILE}" ]; then - ## Dump to file - printf "\n=====\n== Active Network Connections\n=====\n\n" >> ${DUMPFILE} - netstat -tnp | sed -r -e 's/$/\n/g' >> ${DUMPFILE} - echo "==================================" >> ${DUMPFILE} - return 0 + ## Dump to file + printf "\n=====\n== Active Network Connections\n=====\n\n" >> ${DUMPFILE} + netstat -tnp | sed -r -e 's/$/\n/g' >> ${DUMPFILE} + echo "==================================" >> ${DUMPFILE} + return 0 fi - ## Dump to dialog SERV=$(netstat -tnp | sed -r -e 's/$/\n/g' > ${TMPFILE}) @@ -1700,320 +1443,270 @@ netdiag_connections(){ "--tab-correct --tab-len 4 --textbox ${TMPFILE} "\ ${LARGE_HEIGHT} ${LARGE_WIDTH} } +netdiag_services() { + DUMPFILE=$1 + HAS_NETSTAT=$(echo "${HAS_OPTS}" | grep -c "\ netstat\ ") + if [ ${HAS_NETSTAT} -ne 1 ]; then + notfound "netstat" + return + fi + if [ -n "${DUMPFILE}" ]; then + ## Dump to file + printf "\n=====\n== Active network services\n=====\n\n" >> ${DUMPFILE} + netstat -ltnp | sed -r -e 's/$/\n/g' >> ${DUMPFILE} + echo "==================================" >> ${DUMPFILE} + return 0 + fi + SERV=$(netstat -ltnp | sed -r -e 's/$/\n/g' > ${TMPFILE}) + eval "${DIALOG} --no-collapse "\ + " --title 'Active network services (netstat -ltnp) [arrows to scroll]'" \ + "--tab-correct --tab-len 4 --textbox ${TMPFILE} "\ + ${LARGE_HEIGHT} ${LARGE_WIDTH} - -##function -netdiag_services(){ - - DUMPFILE=$1 - - HAS_NETSTAT=$(echo "${HAS_OPTS}" | grep -c "\ netstat\ ") - if [ ${HAS_NETSTAT} -ne 1 ]; then - notfound "netstat" - return - fi - - if [ -n "${DUMPFILE}" ]; then - ## Dump to file - printf "\n=====\n== Active network services\n=====\n\n" >> ${DUMPFILE} - netstat -ltnp | sed -r -e 's/$/\n/g' >> ${DUMPFILE} - echo "==================================" >> ${DUMPFILE} - return 0 - fi - - - SERV=$(netstat -ltnp | sed -r -e 's/$/\n/g' > ${TMPFILE}) - - eval "${DIALOG} --no-collapse "\ - " --title 'Active network services (netstat -ltnp) [arrows to scroll]'" \ - "--tab-correct --tab-len 4 --textbox ${TMPFILE} "\ - ${LARGE_HEIGHT} ${LARGE_WIDTH} } +netdiag_ping() { + HAS_PING=$(echo "${HAS_OPTS}" | grep -E -c "\ ping\ ") + if [ ${HAS_PING} -ne 1 ]; then + notfound "ping" + return + fi + eval "${DIALOG} --insecure --inputbox 'Host or IP to ping:' \ + ${INFO_HEIGHT} ${INFO_WIDTH}" 2> ${TMPFILE} + if [ $? -ne 0 ]; then + eval "${DIALOG} --msgbox 'Ping Aborted' \ + ${INFO_HEIGHT} ${INFO_WIDTH}" -##function -netdiag_ping(){ - - HAS_PING=$(echo "${HAS_OPTS}" | grep -E -c "\ ping\ ") - if [ ${HAS_PING} -ne 1 ]; then - notfound "ping" - return - fi - eval "${DIALOG} --insecure --inputbox 'Host or IP to ping:' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" 2> ${TMPFILE} - - if [ $? -ne 0 ]; then - eval "${DIALOG} --msgbox 'Ping Aborted' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" - return - else - PINGIP=$(cat ${TMPFILE}) - ping -c 5 ${PINGIP} 2>&1 |\ + return + else + PINGIP=$(cat ${TMPFILE}) + ping -c 5 ${PINGIP} 2>&1 |\ eval "${DIALOG} --title 'Ping ${PINGIP}' \ - --programbox ${LARGE_HEIGHT} ${LARGE_WIDTH}" 2>${TMPFILE} - if [ $! -ne 0 ];then - log "netdiag_ping" "ping aborted" + --programbox ${LARGE_HEIGHT} ${LARGE_WIDTH}" 2>${TMPFILE} + + if [ $! -ne 0 ];then + log "netdiag_ping" "ping aborted" fi - fi - + fi } +netdiag_traceroute() { + HAS_TRACERT=$(echo "${HAS_OPTS}" | grep -c "\ traceroute\ ") + if [ ${HAS_TRACERT} -ne 1 ]; then + notfound "traceroute" + return + fi + eval "${DIALOG} --insecure --inputbox 'Host or IP to trace:' \ + ${INFO_HEIGHT} ${INFO_WIDTH}" 2> ${TMPFILE} -##function -netdiag_traceroute(){ - - HAS_TRACERT=$(echo "${HAS_OPTS}" | grep -c "\ traceroute\ ") - if [ ${HAS_TRACERT} -ne 1 ]; then - notfound "traceroute" - return - fi - eval "${DIALOG} --insecure --inputbox 'Host or IP to trace:' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" 2> ${TMPFILE} + if [ $? -ne 0 ]; then + eval "${DIALOG} --msgbox 'Traceroute Aborted' \ + ${INFO_HEIGHT} ${INFO_WIDTH}" - if [ $? -ne 0 ]; then - eval "${DIALOG} --msgbox 'Traceroute Aborted' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" - return - else - TRACEIP=$(cat ${TMPFILE}) - traceroute ${TRACEIP} 2>&1 | \ - eval "${DIALOG} --title 'Traceroute ${TRACEIP}' \ - --programbox ${LARGE_HEIGHT} ${LARGE_WIDTH}" 2>${TMPFILE} - if [ $! -ne 0 ];then - log "netdiag_traceroute" "traceroute aborted" + return + else + TRACEIP=$(cat ${TMPFILE}) + traceroute ${TRACEIP} 2>&1 | eval "${DIALOG} --title 'Traceroute ${TRACEIP}' \ + --programbox ${LARGE_HEIGHT} ${LARGE_WIDTH}" 2>${TMPFILE} + + if [ $! -ne 0 ];then + log "netdiag_traceroute" "traceroute aborted" fi - fi + fi } +netdiag_lookup() { + HAS_HOST=$(echo "${HAS_OPTS}" | grep -c "\ host\ ") + if [ ${HAS_HOST} -ne 1 ]; then + notfound "host" + return + fi + eval "${DIALOG} --insecure --inputbox 'Hostname or IP to lookup:' \ + ${INFO_HEIGHT} ${INFO_WIDTH}" 2> ${TMPFILE} + if [ $? -ne 0 ]; then + eval "${DIALOG} --msgbox 'DNS lookup aborted' \ + ${INFO_HEIGHT} ${INFO_WIDTH}" -##function -netdiag_lookup(){ - - HAS_HOST=$(echo "${HAS_OPTS}" | grep -c "\ host\ ") - if [ ${HAS_HOST} -ne 1 ]; then - notfound "host" - return - fi - - eval "${DIALOG} --insecure --inputbox 'Hostname or IP to lookup:' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" 2> ${TMPFILE} - - if [ $? -ne 0 ]; then - eval "${DIALOG} --msgbox 'DNS lookup aborted' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" - return - else - QUERYIP=$(cat ${TMPFILE}) - host ${QUERYIP} 2>&1 |\ + return + else + QUERYIP=$(cat ${TMPFILE}) + host ${QUERYIP} 2>&1 |\ eval "${DIALOG} --title 'host ${QUERYIP}' \ - --programbox ${LARGE_HEIGHT} ${LARGE_WIDTH}" 2>${TMPFILE} - if [ $! -ne 0 ];then - log "netdiag_ping" "host lookup aborted" + --programbox ${LARGE_HEIGHT} ${LARGE_WIDTH}" 2>${TMPFILE} + + if [ $! -ne 0 ];then + log "netdiag_ping" "host lookup aborted" fi - - fi + fi } - -##function -netdiag_devices(){ - - DUMPFILE=$1 - - if [ -n "${DUMPFILE}" ]; then - printf "\n=====\n== Network Devices\n=====\n\n" >> ${DUMPFILE} - ip addr >> ${DUMPFILE} - echo "==================================" >> ${DUMPFILE} - return 0 - fi +netdiag_devices() { + DUMPFILE=$1 + if [ -n "${DUMPFILE}" ]; then + printf "\n=====\n== Network Devices\n=====\n\n" >> ${DUMPFILE} + ip addr >> ${DUMPFILE} + echo "==================================" >> ${DUMPFILE} + return 0 + fi } - - - ## ## Main menu for network diagnostics ## - -##function -netdiag_menu(){ - - while true; do - eval "${DIALOG} --cancel-label 'Up' --menu 'Network diagnostics' \ - ${WINDOW_HEIGHT} ${WINDOW_WIDTH} 10 \ - 'ARP' 'Show ARP table' \ - 'Connections' 'List active network connections' \ - 'DNS' 'List DNS servers' \ - 'Lookup' 'DNS Lookup' \ - 'Ping' 'Ping a host' \ - 'Resolver' 'Show resolver configuration' \ - 'Routes' 'Show routing table' \ - 'Services' 'List active network daemons' \ - 'Traceroute' 'Show the route to a host' " \ - 2> ${TMPFILE} - if [ $? -eq 1 ];then - return; - fi +netdiag_menu() { + while true; do + eval "${DIALOG} --cancel-label 'Up' --menu 'Network diagnostics' \ + ${WINDOW_HEIGHT} ${WINDOW_WIDTH} 10 \ + 'ARP' 'Show ARP table' \ + 'Connections' 'List active network connections' \ + 'DNS' 'List DNS servers' \ + 'Lookup' 'DNS Lookup' \ + 'Ping' 'Ping a host' \ + 'Resolver' 'Show resolver configuration' \ + 'Routes' 'Show routing table' \ + 'Services' 'List active network daemons' \ + 'Traceroute' 'Show the route to a host' " \ + 2> ${TMPFILE} - ACTION=$(cat ${TMPFILE}) - case ${ACTION} in - "ARP") - netdiag_ARP - ;; - "Connections") - netdiag_connections - ;; - "DNS") - netdiag_DNS - ;; - "Ping") - netdiag_ping - ;; - "Lookup") - netdiag_lookup - ;; - "Resolver") - netdiag_resolver - ;; - "Routes") - netdiag_routes - ;; - "Services") - netdiag_services - ;; - "Traceroute") - netdiag_traceroute - ;; - esac - done - - + if [ $? -eq 1 ];then + return; + fi + + ACTION=$(cat ${TMPFILE}) + case ${ACTION} in + "ARP") + netdiag_ARP + ;; + "Connections") + netdiag_connections + ;; + "DNS") + netdiag_DNS + ;; + "Ping") + netdiag_ping + ;; + "Lookup") + netdiag_lookup + ;; + "Resolver") + netdiag_resolver + ;; + "Routes") + netdiag_routes + ;; + "Services") + netdiag_services + ;; + "Traceroute") + netdiag_traceroute + ;; + esac + done } +dump_file() { + CONF=$1 + log "dump_file" "CONF: ${CONF}" -##function -dump_file(){ - - CONF=$1 - - log "dump_file" "CONF: ${CONF}" - - DUMPFILE="/tmp/network_dump.txt" - - eval "${DIALOG} --fselect ${DUMPFILE} ${WINDOW_HEIGHT} ${WINDOW_WIDTH}" \ - 2>${TMPFILE} + DUMPFILE="/tmp/network_dump.txt" + eval "${DIALOG} --fselect ${DUMPFILE} ${WINDOW_HEIGHT} ${WINDOW_WIDTH}" \ + 2>${TMPFILE} - if [ $? -eq 0 ]; then - SEL_FILE=$(cat ${TMPFILE}) - while [ -d "${SEL_FILE}" ]; do - eval "${DIALOG} --fselect ${SEL_FILE} ${WINDOW_HEIGHT} ${WINDOW_WIDTH}" \ - 2>${TMPFILE} - if [ $? -eq 0 ]; then - SEL_FILE=$(cat ${TMPFILE}) - else - eval "${DIALOG} --msgbox 'Dump aborted' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" - return - fi - done - + if [ $? -eq 0 ]; then + SEL_FILE=$(cat ${TMPFILE}) + while [ -d "${SEL_FILE}" ]; do + eval "${DIALOG} --fselect ${SEL_FILE} ${WINDOW_HEIGHT} ${WINDOW_WIDTH}" \ + 2>${TMPFILE} + + if [ $? -eq 0 ]; then + SEL_FILE=$(cat ${TMPFILE}) + else + eval "${DIALOG} --msgbox 'Dump aborted' \ + ${INFO_HEIGHT} ${INFO_WIDTH}" + + return + fi + done ## The dump starts here.... - DUMPFILE=${SEL_FILE} - truncate -s 0 ${DUMPFILE} - echo "===== setnet ${VERSION}" >> ${DUMPFILE} + DUMPFILE=${SEL_FILE} + truncate -s 0 ${DUMPFILE} + echo "===== setnet ${VERSION}" >> ${DUMPFILE} echo "===== Date: $(date)" >> ${DUMPFILE} echo "===== Network configuration dump: ${CONF} " >> ${DUMPFILE} for c in ${CONF}; do - eval "netdiag_${c} \"${DUMPFILE}\"" - done - else - eval "${DIALOG} --msgbox 'Dump aborted' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" - return - fi - eval "${DIALOG} --msgbox 'Status dumped to ${DUMPFILE}' \ - ${INFO_HEIGHT} ${INFO_WIDTH}" + eval "netdiag_${c} \"${DUMPFILE}\"" + done +else + eval "${DIALOG} --msgbox 'Dump aborted' \ + ${INFO_HEIGHT} ${INFO_WIDTH}" + + return + fi + eval "${DIALOG} --msgbox 'Status dumped to ${DUMPFILE}' \ + ${INFO_HEIGHT} ${INFO_WIDTH}" } - - -##function -dump_pastebin(){ - - unimplemented "pastebin" +dump_pastebin() { + DUMP_CONF=$1 + minpb -p ${DUMP_CONF} https://ttm.sh } - -##function -dump_menu(){ - - eval "${DIALOG} --checklist 'Select conf to dump' \ - ${WINDOW_HEIGHT} ${WINDOW_WIDTH} 10 \ - 'ARP' 'ARP table' on \ - 'devices' 'Device configuration' on \ - 'DNS' 'DNS configuration' on \ - 'resolver' 'System resolver configuration' on \ - 'routes' 'Routing table' on \ - 'connections' 'Active network connections' on \ - 'services' 'Active network services' on " 2> ${TMPFILE} - if [ $? -ne 0 ]; then - return - fi +dump_menu() { + eval "${DIALOG} --checklist 'Select conf to dump' \ + ${WINDOW_HEIGHT} ${WINDOW_WIDTH} 10 \ + 'ARP' 'ARP table' on \ + 'devices' 'Device configuration' on \ + 'DNS' 'DNS configuration' on \ + 'resolver' 'System resolver configuration' on \ + 'routes' 'Routing table' on \ + 'connections' 'Active network connections' on \ + 'services' 'Active network services' on " 2> ${TMPFILE} - DUMP_CONF=$(cat ${TMPFILE}) + if [ $? -ne 0 ]; then + return + fi + DUMP_CONF=$(cat ${TMPFILE}) + eval "${DIALOG} --cancel-label 'Up' \ + --menu 'Dump configuration to:' \ + ${INFO_HEIGHT} ${INFO_WIDTH} 6 \ + 'File' 'Dump to file' \ + 'Pastebin' 'Dump to pastebin'" \ + 2> ${TMPFILE} - eval "${DIALOG} --cancel-label 'Up' \ - --menu 'Dump configuration to:' \ - ${INFO_HEIGHT} ${INFO_WIDTH} 6 \ - 'File' 'Dump to file' \ - 'Pastebin' 'Dump to pastebin'" \ - 2> ${TMPFILE} - if [ $? -eq 1 ];then - return; - fi - - ACTION=$(cat ${TMPFILE}) - case ${ACTION} in - "File") - dump_file "${DUMP_CONF}" - ;; - "Pastebin") - dump_pastebin "${DUMP_CONF}" - ;; - esac + if [ $? -eq 1 ];then + return; + fi + ACTION=$(cat ${TMPFILE}) + case ${ACTION} in + "File") + dump_file "${DUMP_CONF}" + ;; + "Pastebin") + dump_pastebin "${DUMP_CONF}" + ;; + esac } +show_toplevel() { + log "show_toplevel" "TMPFILE: ${TMPFILE}" + eval "${DIALOG} --cancel-label 'Quit' --menu 'Main Menu' \ + ${WINDOW_HEIGHT} ${WINDOW_WIDTH} 6 \ + 'Setup' 'Setup interfaces' \ + 'Info' 'Network diagnostics' \ + 'Dump' 'Dump current network status' \ + 'Log' 'View setnet log' \ + 'About' 'License & Copyleft'" 2> ${TMPFILE} - -##function -show_toplevel(){ - - log "show_toplevel" "TMPFILE: ${TMPFILE}" - eval "${DIALOG} --cancel-label 'Quit' --menu 'Main Menu' \ - ${WINDOW_HEIGHT} ${WINDOW_WIDTH} 6 \ - 'Setup' 'Setup interfaces' \ - 'Info' 'Network diagnostics' \ - 'Dump' 'Dump current network status' \ - 'Log' 'View setnet log' \ - 'About' 'License & Copyleft'" 2> ${TMPFILE} - - return $? + return $? } - -##function -show_help(){ - -##local -SCRIPTNAME=$1 +show_help() { + SCRIPTNAME=$1 echo "Usage: ${SCRIPTNAME} [OPTION]" echo "Options:" printf "\t -c cfg_file\tLoad configuration from cfg_file.\n" printf "\t -c trace_file\tDump dialog debug trace to trace_file.\n" printf "\t -v\t\tPrint version number and exit.\n" printf "\t -h\t\tShow this help.\n" - } - -##function -show_version(){ - -##local -SCRIPTNAME=$1 +show_version() { + SCRIPTNAME=$1 echo "${SCRIPTNAME} -- version ${VERSION}" echo "Copyleft (C) Vincenzo \"KatolaZ\" Nicosia (katolaz@freaknet.org) -- 2016-2018" + echo "Copyleft (C) Nova (novaburst@tilde.team) -- 2021" echo "This is free software. You can use and redistribute it under the " echo "terms of the GNU General Public Licence version 3 or (at your option)" echo "any later version." @@ -2022,50 +1715,42 @@ SCRIPTNAME=$1 echo "There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or" echo "FITNESS FOR A PARTICULAR PURPOSE." } +show_disclaimer() { +cat < ${TMPFILE} +-+- setnet.sh ${VERSION} -+- -##function -show_disclaimer(){ +Copyleft (C) KatolaZ (katolaz@freaknet.org) 2016-2018 +Copyleft (C) Nova (novaburst@tilde.team) - 2021 - cat < ${TMPFILE} +-+- This is a beta release of setnet.sh -+- + +THIS IS FREE SOFTWARE +YOU CAN USE AND DISTRIBUTE IT UNDER THE +TERMS OF THE GNU GENERAL PUBLIC LICENSE + +USE THIS SOFTWARE AT YOUR OWN RISK - -+- setnet.sh ${VERSION} -+- +There is ABSOLUTELY NO WARRANTY; not even for +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE - Copyleft (C) KatolaZ (katolaz@freaknet.org) - 2016-2018 - - -+- This is a beta release of setnet.sh -+- - - THIS IS FREE SOFTWARE - YOU CAN USE AND DISTRIBUTE IT UNDER THE - TERMS OF THE GNU GENERAL PUBLIC LICENSE - - USE THIS SOFTWARE AT YOUR OWN RISK - - There is ABSOLUTELY NO WARRANTY; not even for - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE - - See "About" for more information about - your right and distribution terms +See "About" for more information about +your right and distribution terms EOF - eval "${DIALOG} --cr-wrap --textbox ${TMPFILE} 23 60" - return +eval "${DIALOG} --cr-wrap --textbox ${TMPFILE} 23 60" +return } +initialise() { + TMPFILE=$( (tempfile) 2>/dev/null) || TMPFILE=/tmp/setnet_$$ + WPA_PIDFILE=$( (tempfile) 2>/dev/null) || WPA_PIDFILE=/tmp/setnet_wpapid_$$ -##function -initialise(){ - - - TMPFILE=$( (tempfile) 2>/dev/null) || TMPFILE=/tmp/setnet_$$ - WPA_PIDFILE=$( (tempfile) 2>/dev/null) || WPA_PIDFILE=/tmp/setnet_wpapid_$$ - trap cleanup 0 HUP INT TRAP TERM QUIT - if [ -z ${TRUNCATE_LOG} ] || \ - [ ${TRUNCATE_LOG} = "yes" ] || \ - [ ${TRUNCATE_LOG} = "YES" ]; then - truncate -s 0 ${LOGFILE} - fi + if [ -z ${TRUNCATE_LOG} ] || \ + [ ${TRUNCATE_LOG} = "yes" ] || \ + [ ${TRUNCATE_LOG} = "YES" ]; then + truncate -s 0 ${LOGFILE} + fi chmod 600 ${LOGFILE} @@ -2079,12 +1764,9 @@ initialise(){ EUID=$(id -ru) if [ "${EUID}" = "0" ] && - [ -n "${SUDO_UID}" ] && - [ "${EUID}" != "${SUDO_UID}" ]; then - USING_SUDO="1" - elif [ "${EUID}" = "0" ] && - [ -n "${SUP_UID}" ] && - [ "${EUID}" != "${SUP_UID}" ]; then + [ -n "${SUDO_UID}" ] && [ "${EUID}" != "${SUDO_UID}" ]; then + USING_SUDO="1" + elif [ "${EUID}" = "0" ] && [ -n "${SUP_UID}" ] && [ "${EUID}" != "${SUP_UID}" ]; then USING_SUDO="1" else USING_SUDO="0" @@ -2097,36 +1779,24 @@ initialise(){ SUPPRESS="" if [ -n "${SUPPRESS_INFO}" ] && - [ "${SUPPRESS_INFO}" != "no" ] && - [ "${SUPPRESS_INFO}" != "NO" ]; then - SUPPRESS="1" + [ "${SUPPRESS_INFO}" != "no" ] && [ "${SUPPRESS_INFO}" != "NO" ]; then + SUPPRESS="1" fi - if [ -n "${SHOW_LO}" ] && - [ "${SHOW_LO}" != "no" ] && - [ "${SHOW_LO}" != "NO" ]; then + if [ -n "${SHOW_LO}" ] && [ "${SHOW_LO}" != "no" ] && [ "${SHOW_LO}" != "NO" ]; then SHOW_LO="1" else SHOW_LO="" fi log "initialise" "SUPPRESS: ${SUPPRESS}" - } - - -##function -log_show(){ - - eval "${DIALOG} --cr-wrap --title 'setnet log file (${LOGFILE})'\ - --textbox ${LOGFILE} \ - ${WINDOW_HEIGHT} ${WINDOW_WIDTH}" - +log_show() { + eval "${DIALOG} --cr-wrap --title 'setnet log file (${LOGFILE})'\ + --textbox ${LOGFILE} \ + ${WINDOW_HEIGHT} ${WINDOW_WIDTH}" } - -##function -main(){ - +main() { log "main" "SUPPRESS: ${SUPPRESS}" [ -z "${SUPPRESS}" ] && show_disclaimer @@ -2137,43 +1807,39 @@ main(){ log "main" "Using WPA config file \"${WPA_FILE}\"" LOFGILE=$(realpath ${LOGFILE}) log "main" "Using log file \"${LOGFILE}\"" - - while true; do - show_toplevel - if [ $? -eq 1 ]; then - cleanup - exit 1 - fi - log "main" "${TMPFILE}" - ACTION=$(cat ${TMPFILE}) - log "main" "ACTION: ${ACTION}" - case ${ACTION} in - "Setup") - dev_config_menu - ;; - "Info") - netdiag_menu - ;; - "Dump") - dump_menu - ;; - "Log") - log_show - ;; - "About") - about_menu - ;; - esac + while true; do + show_toplevel + if [ $? -eq 1 ]; then + cleanup + exit 1 + fi + log "main" "${TMPFILE}" + ACTION=$(cat ${TMPFILE}) + log "main" "ACTION: ${ACTION}" + case ${ACTION} in + "Setup") + dev_config_menu + ;; + "Info") + netdiag_menu + ;; + "Dump") + dump_menu + ;; + "Log") + log_show + ;; + "About") + about_menu + ;; + esac done } - - ## ## The script starts here ## - ## ## Get command-line arguments ## @@ -2181,59 +1847,45 @@ main(){ SETNETRC="" while getopts ":c:d:hv" opt; do - - case $opt in - c) - #echo "Got option -c ${OPTARG}" - SETNETRC=$(realpath ${OPTARG}) - #echo "SETNETRC: ${SETNETRC}" - ;; - h) - show_help $(basename $0) - exit 1 - ;; - v) - show_version $(basename $0) - exit 1 - ;; - d) - TRACE_FILE=$(realpath ${OPTARG}) - set_debug ${TRACE_FILE} - ;; - \?) - echo "Invalid option: -${OPTARG}" - exit 1 - ;; - :) - echo "Option -${OPTARG} requires an argument" - exit 1 - ;; - esac + case $opt in + c) + SETNETRC=$(realpath ${OPTARG}) + ;; + h) + show_help $(basename $0) + exit 1 + ;; + v) + show_version $(basename $0) + exit 1 + ;; + d) + TRACE_FILE=$(realpath ${OPTARG}) + set_debug ${TRACE_FILE} + ;; + \?) + echo "Invalid option: -${OPTARG}" + exit 1 + ;; + :) + echo "Option -${OPTARG} requires an argument" + exit 1 + ;; + esac done - - ## ## Load the configuration file ## - load_setnetrc ${SETNETRC} - ## ## Init stuff ## - initialise - - ## ## Check dependencies. If we are missing someting essential, then exit. ## - check_deps - ## ## This is the main loop ## - main -