Saturday, 26 September 2009

Well that was easy, 0.2.1 (ish)

It turns out that porting the majority of it to bash was much easier than expected
#!/bin/sh
profilemap="/etc/netprofiles/profilemap"
settingsFile="/etc/netprofiles/NMsettings"
executable="/etc/netprofiles/run-netprofile"
log="/var/log/netprofiles.log"
logstr="NM LOG:"

read_settings () {
 declare -i number offlineDelay
 [ -r $settingsFile ] && . $settingsFile
 [ $unknownProfile ] || $unknownProfile = "public"
}

[ -r /var/run/NMnetprofile.pid ] && ( . /var/run/NMnetprofile.pid ; kill $pid )
echo "pid="$$ > /var/run/NMnetprofile.pid

echo $logstr "Called as" $0 $1 $2 "uuid=" $CONNECTION_UUID >> $log
case $2 in
up)
 profile=$(sed -n "s/^$CONNECTION_UUID=//p;q" $profilemap)
 if [ $profile ] ; then 
  echo  $logstr "connected to" $CONNECTION_UUID "switching to" $profile >> $log
  $executable  $profile
 else
  read_settings
  echo  $logstr $CONNECTION_UUID "unknown switching to" $unknownProfile >> $log 
  $executable  $unkownProfile
 fi
;;
down)
 read_settings
 [ -x $offlineCommand ] && $offlineCommand 
 if [ $offlineProfile ] ; then
  [ $offlineDelay ] && sleep $offlineDelay 
  echo $logstr "Switching to" $offlineProfile "on shutdown" >> $log
  $executable  $offlineProfile
 else 
  echo $logstr "No action taken on network shutdown" >> $log
 fi
;;
*)
 echo $logstr "Change to"  $2 "Not coded yet" >> $log
;;
esac
exit 0

It requires changing the config (and I moved it to /etc/netprofile/NMsettings) and replacing any , in the profilemap (also moved to /etc/netprofile/) with =
unknownProfile=public     #if absent defaults to public
offlineDelay=10           #remove if 0 to safe upto 90ms on execution
offlineProfile=public     #remove to take no action on going offline

As it doesn't seam anybody is actually using this yet, I wont bother repackaging it, if for you stumble across this and want to give it a try, email me or install the core and profiles, then put the above as your dispatcher script (and install the uuid-changer as that still requires dbus, its the same as the one i posted but with line 32 edited to filename="/etc/netprofiles/profilemap")

In other news I'm worked on GUI tools to make it easier to setup/maintain the profiles. Unfortunately looking at the current tools is somewhat depressing (other than sysv-rc-conf, props to Joe Oppegaard), so I either have to learn the basics of perl to adapt his code or I have to start from scratch.

Sunday, 20 September 2009

netprofiles0.2 "alpha release"

I'll get straight to the point, here are the tars:
netprofiles0.2 - use this to install the core scripts (it will untar to / unless otherwise told)
netprofiles0.2-NMcaller - This contains the NM caller (no bash script)
MyProfiles - My sample profiles (full,home,public,hidden)
you will also need to add a script to /etc/NetworkManger/dispatcher.d/ such as
#!/bin/sh
pkill chooseprofile.py
/etc/netprofiles/callers/NetworkManager/chooseprofile.py $2
exit 0
or netprofiles0.2-full - Everything including the bash script (it will untar /)

Saturday, 19 September 2009

netprofiles design

what:
A simple framework to switch the services your pc offers depending on what network its connected to.
how:
Using a framework similar to that of runlevels, with additional sections for custom scripts, switching configs, changing firewalls(IPtables).
why:

  • More secure - You can't compromise samba if it doesn't run when I connect to your network, you can't catch me on your wifi if you cant ping me (well you can but most people don't know how)
  • More convenient - I'm to lazy to run "sudo myscript" after every connection
  • Faster boot time - If your not connecting to any networks (about the same if your networking is configured to connect before login)
  • Vista can do it - Vista has similar functionality to protect its users and ill be dammed if I cant have it to