networkselect – a KDE network selector

Tuesday, 17/03/2009 ≅19:47 ©brainycat

I've never met a gui network manager that worked for me. Maybe it's because my laptop moves across too many networks each with unique requirements, or perhaps because I use too many interfaces. So I've always used shell scripts to manage my interfaces. I add the scripts to my application menu, and tell KDE that I need the root pword to run them. Works like a charm.

Then I found out that KDE provides shell accessible dialog utilities. Yum! I whipped up this wrapper in a few minutes. You will need to customize it for your installation, but it should be obvious what you need to change and where. This is a version 0.1 release.

TODO: add my Sierra Wireless 875 (ppp0)
Various "FIXME"

 
#!/bin/bash
 
### cat@brainycat.com Tue Mar 17 14:25:42 PDT 2009
### copyrighted under the terms of the GPLv3
### http://www.gnu.org/licenses/gpl-3.0.html
 
### NOTE that this script does not touch the lo interface
 
### to add new networks:
### add to f_drawNetworkRadioList
### add to 'case' in main
### create function
 
### VARIABLES ########################################
 
### FUNCTIONS ########################################
 
# draws the initial radiolist that selects the network
f_drawNetworkRadioList()
{
  kdialog --title "BrainyCat's Network Selector" \
          --radiolist "                     Configured Networks:                     " \
                      1 "wasteland.syn ethernet" off \
                      2 "wasteland.syn wifi" off \
                      10 "SPL Ballard wifi" off \
                      11 "JavaBean 24th Ave wifi" off \
                      99 "ifconfig * down" off \
                      100 "EXIT" on
  return $answer
}; # end f_drawNetworkRadioList
 
f_exit()
{
  # cleanup
  exit
}; #end f_exit
 
f_interfaceUp()
{
  # FIXME make this prettier
  kdialog --title "Network Status:" \
          --passivepopup "$(ifconfig);echo;$(route -n)"
}
 
f_ifdown()
{
  # FIXME should we take down httpd? Different .conf for different networks?
  # FIXME different samba scripts for different networks
  /etc/rc.d/rc.samba stop
  # FIXME kill dhclient should find every process and make sure it killed successfully
  kill 'pidof dhclient'
  echo "" > /etc/resolv.conf
  # FIXME this should be per interface, called by 'case'
  ifconfig eth0 down
  ifconfig eth1 down
  ifconfig ppp0 down
  rmmod orinoco_pci
  rmmod orinoco
  rmmod hermes_dld
  rmmod hermes
  rmmod e100
  modprobe orinoco_pci
  modprobe hermes
  modprobe e100
}; #end f_ifdown
 
f_wasteland.syn.ethernet()
{
  echo "nameserver 192.168.0.205" > /etc/resolv.conf
  echo "search wasteland.syn" >> /etc/resolv.conf
  ifconfig eth1 up
  dhclient eth1
}; #end f_wasteland.syn.ethernet
 
f_wasteland.syn.wifi()
{
  echo "nameserver 192.168.0.205" > /etc/resolv.conf
  echo "search wasteland.syn" >> /etc/resolv.conf
  /sbin/ifconfig eth0 up
  /sbin/iwconfig eth0 essid YOUR_ESSID_HERE
  /sbin/iwconfig eth0 key YOUR_WEP_KEY_HERE
  /sbin/dhclient eth0
  /etc/rc.d/rc.samba start
}; #end f_wasteland.syn.wifi
 
f_seattlepubliclibrary.ballard()
{
  ifconfig eth0 up
  iwconfig eth0 essid any
  iwconfig eth0 essid "spl-public"
  dhclient eth0
}; #end f_seattlepubliclibrary.ballard
 
f_javabean.24thAve()
{
  ipconfig eth0 up
  iwconfig eth0 mode managed key s:wmwn1
  iwconfig eth0 essid wmwn1
  dhclient eth0
}
 
### MAIN ########################################
 
# assigns the option chosen in the radiolist
userChoice=`f_drawNetworkRadioList`
 
# check for errors or cancel button
exitCode=$?
if [ $exitCode -gt 0 ]; then f_exit; fi
 
case $userChoice in
  1)
    f_ifdown
    f_wasteland.syn.ethernet
    f_interfaceUp
    ;;
  2)
    f_ifdown
    f_wasteland.syn.wifi
    f_interfaceUp
    ;;
  10)
    f_ifdown
    f_seattlepubliclibrary.ballard
    f_interfaceUp
    ;;
  11)
    f_ifdown
    f_javabean.24thAve
    f_interfaceUp
    ;;
  99)
    f_ifdown
    f_interfaceUp
    ;;
  100)
    f_exit
    ;;
esac