wireless-net/trunk/sbin/gen-wlan-files.py

arekm cvs at pld-linux.org
Tue Jul 19 08:13:03 CEST 2005


Author: arekm
Date: Tue Jul 19 08:13:00 2005
New Revision: 6222

Modified:
   wireless-net/trunk/sbin/gen-wlan-files.py
Log:
Check whether interface is wireless one before issuing iw* commands. Print what's happending while running script.

Modified: wireless-net/trunk/sbin/gen-wlan-files.py
==============================================================================
--- wireless-net/trunk/sbin/gen-wlan-files.py	(original)
+++ wireless-net/trunk/sbin/gen-wlan-files.py	Tue Jul 19 08:13:00 2005
@@ -1,9 +1,20 @@
 #!/usr/bin/python
 # Generate all required files (pap-secrets, ipac-ng.conf, oidentd_masq.conf etc)
-# (C) 2002, 2003, 2004 Arkadiusz Miskiewicz <arekm at pld-linux.org>
+# (C) 2002, 2003, 2004, 2005 Arkadiusz Miskiewicz <arekm at pld-linux.org>
 
-import string, os, re, ConfigParser;
+import string, os, re, ConfigParser, socket, fcntl;
 
+SIOCGIWNAME = 0x8B01
+
+def is_wireless(iface):
+    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+    try:
+	fcntl.ioctl(s.fileno(), SIOCGIWNAME, iface.strip()+(32-len(iface.strip()))*'\0')
+    except IOError:
+	s.close()
+	return false
+    s.close()
+    return true
 
 config = ConfigParser.ConfigParser()
 config.read('/etc/wireless-net/wlan.conf')
@@ -41,25 +52,28 @@
 fpmrtg.write("LogFormat:      rrdtool\n")
 
 for elem in ifaces:
+    print "Writting fetchipac config for %s interface." % elem
     if old_ipac:
 	fpipac.write("%s_in_all|in|%s|all||\n" % (elem, elem))
 	fpipac.write("%s_out_all|out|%s|all||\n" % (elem, elem))
     else:
 	fpipac.write("%s_in_all|ipac~o|%s|all|||\n" % (elem, elem))
 	fpipac.write("%s_out_all|ipac~i|%s|all|||\n" % (elem, elem))
-	
 
-    os.system("/sbin/iwspy %s off 2> /dev/null" % elem)
+    if is_wireless(elem):
+	os.system("/sbin/iwspy %s off 2> /dev/null" % elem)
 
 for elem in mrtg_links:
     iface = elem[2]
-    
-    os.system("/sbin/iwspy %s off 2> /dev/null" % iface)
+    if is_wireless(iface):
+	os.system("/sbin/iwspy %s off 2> /dev/null" % iface)
     
 for elem in mrtg_links:
     host = string.strip(elem[0])
     mac = string.strip(elem[1])
     iface = string.strip(elem[2])
+    
+    print "Writting mrtg config for %s link." % host
 
     fpmrtg.write("\n")
     fpmrtg.write("Target[%s.quality]: `/etc/mrtg/scripts/mrtg-wlan-quality.sh \"%s\"`\n" % (host, mac))
@@ -75,9 +89,12 @@
     fpmrtg.write("LegendO[%s.quality]: &nbsp;Sr Iface: \n"% host)
     fpmrtg.write("\n")
 
-    os.system("/sbin/iwspy %s + %s 2> /dev/null" % (iface, mac))
+    if is_wireless(iface):
+	os.system("/sbin/iwspy %s + %s" % (iface, mac))
 
 for iface in ap_iface:
+    print "Preparing root tc queue for %s interface." % iface
+    
     os.system("tc qdisc del root dev %s 2> /dev/null" % iface)
     if use_htb:
 	os.system("tc qdisc add dev %s root handle 1:0 htb r2q 1" % iface)
@@ -106,6 +123,8 @@
     host = string.strip(l[6])
     mac = string.strip(l[7])
 
+    print "Running configuration for %s (%s, down %s, up %s)" % (l, ip, speed_down, speed_up)
+
     if passwd != "apuser":
 	fppap.write("%s\t%s\t%s\t%s\n" % (login, "\"*\"", passwd, ip))
    
@@ -161,7 +180,7 @@
     fpmrtg.write("LegendO[%s.quality]: &nbsp;Sr Iface: \n"% host)
     fpmrtg.write("\n")
 
-    if passwd != "apuser":
+    if passwd != "apuser" and is_wireless(pppoe_iface):
     	    os.system("/sbin/iwspy %s + %s" % (pppoe_iface, mac))
 
 fpmrtg.close()
@@ -172,5 +191,3 @@
 os.system("iptables -A apchain -j RETURN")
 os.system("iptables -t mangle -A apchain -j RETURN")
 os.system("/usr/sbin/fetchipac -S")
-               
-    



More information about the pld-cvs-commit mailing list