Aggiunto support per il proxy su poisson.
Leonardo Robol [2010-10-12 09:31]
Aggiunto support per il proxy su poisson.
diff --git a/99_poisson_vpn.py b/99_poisson_vpn.py
index c736e29..66ae999 100755
--- a/99_poisson_vpn.py
+++ b/99_poisson_vpn.py
@@ -22,8 +22,11 @@
__author__ = "Leonardo Robol <robol@poisson.phc.unipi.it>"
+# Defaults
+apt_proxy_file = "/etc/apt/apt.conf.d/99poisson_proxy"
-import dbus, sys
+
+import dbus, sys, os
from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)
@@ -156,6 +159,20 @@ def activate_connection(connection):
connection,
dbus.ObjectPath("/"),
base_connection)
+ setup_apt_proxy ()
+ else:
+ reset_apt_proxy ()
+
+def reset_apt_proxy():
+ if os.path.exists(apt_proxy_file):
+ os.path.remove(apt_proxy_file)
+
+def setup_apt_proxy():
+ if not os.path.exists(apt_proxy_file):
+ with open(apt_proxy_file, "w") as handle:
+ handle.write("""Acquire::http { Proxy "http://poisson:3142"; };""")
+ handle.write("\n")
+
if __name__ == "__main__":
@@ -163,6 +180,7 @@ if __name__ == "__main__":
# che ti riattivi quella per poisson (anche perché potresti stare
# cercando di liberartente).
if sys.argv[2] == "vpn-down":
+ delete_apt_proxy()
sys.exit (0)
# Se è appena stata attivata una VPN non ha senso cercare di
@@ -174,6 +192,7 @@ if __name__ == "__main__":
# Se hai appena deconfigurato un'interfaccia probabilmente non
# desideri attivare la VPN
if sys.argv[2] == "down":
+ delete_apt_proxy()
sys.exit (0)
# Otteniamo il bus
@@ -189,7 +208,7 @@ if __name__ == "__main__":
# Altrimenti la attiviamo, e poi usciamo :)
activate_connection (poisson_vpn)
-
+
sys.exit (0)