Rivisto il codice e aggiunto qualche commento.
Leonardo Robol [2011-02-03 22:05]
Rivisto il codice e aggiunto qualche commento.
diff --git a/99_poisson_vpn.py b/99_poisson_vpn.py
index c15db12..36ef383 100755
--- a/99_poisson_vpn.py
+++ b/99_poisson_vpn.py
@@ -23,16 +23,37 @@
__author__ = "Leonardo Robol <robol@poisson.phc.unipi.it>"
-# Defaults
+# Default values. You can change these to adjust package
+# configuration
+#
+# apt_proxy_file specifies the name of the file that
+# poisson_vpn will use as configuration file for the
+# apt proxy. It will created on connection and deleted
+# on disconnection
apt_proxy_file = "/etc/apt/apt.conf.d/99poisson_proxy"
+# mac_addresses is a list of unicode strings containing the
+# mac addresses of access point that are in the local
+# subnet where the VPN is available
+mac_addresses = [ u"00:0d:54:a9:cf:36",
+ u'00:0f:cb:aa:16:52' ]
-import dbus, sys, os, subprocess, re, time
-from dbus.mainloop.glib import DBusGMainLoop
+# using_notify controls if notifications of
+# a successful conection should be showed to
+# logged user.
+using_notify = True
+# notify_body is the content of the notification that
+# will be displayed in alle the gnome active sessions
+# when the connection is established.
+notify_body = "La connessione VPN a poisson è stata effettuata ed è ora possibile navigare in Internet."
-notify_body = "La connessione VPN a poisson è stata effettuata ed è ora possibile navigare in Internet."
-using_notify = True
+#
+# START OF THE CODE; DON'T MODIFY THE SCRIPT BEYOND THIS LINE
+#
+
+import dbus, sys, os, subprocess, re, time
+from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)
@@ -133,15 +154,16 @@ def get_base_connection():
settings = interface.GetSettings()
if settings.has_key("802-11-wireless"):
-
- # MAC address of CDCWL1 ap
- if settings['802-11-wireless']['seen-bssids'][0] == u'00:12:0e:8c:ae:a0':
- return connection
-
- # MAC address of PHC-wifi ap
- if settings['802-11-wireless']['seen-bssids'][0] == u'00:0f:cb:aa:16:52':
+
+ # Rimuoviamo dalla lista gli access point che non sono
+ # all'interno del Dipartimento di Matematica
+ intersection = filter(lambda x : x in mac_addresses,
+ settings['802-11-wireless']['seen-bssids'])
+
+ # Se ne è rimasto qualcuno ritorniamo la connessione
+ if len(intersection) != 0:
return connection
-
+
# Se siamo arrivati a questo punto significa che la connessione attiva
# non è direttamente connessa a poisson.phc-priv e qunidi possiamo
# anche lasciar perdere