Example #1
0
 def parse (self) :
     root  = self.tree.getroot ()
     self.ip_dev = {}
     for pre in root.findall (".//%s" % tag ("pre")) :
         state = 0
         for a in pre :
             if a.tag != tag ('a') :
                 continue
             if state == 0 and a.tail and 'scope link' in a.tail :
                 state = 1
                 found = False
                 for w in a.tail.strip ().split () :
                     if found :
                         devname = w
                         break
                     if w == 'dev' :
                         found = True
                 continue
             if state == 1 :
                 if devname :
                     self.ip_dev [a.text.strip ()] = devname
                 devname = None
                 state = 0
     for sm in root.findall (".//%s" % tag ("small")) :
         if sm.text :
             s = sm.text.strip ()
             if s.startswith ('0xffolsr') :
                 self.version = s
                 break
Example #2
0
 def parse (self) :
     wlo = \
         ( 'Wireless Overview'
         , 'Drahtlosübersicht'.decode ('latin1')
         , 'WLAN Übersicht'.decode ('latin1')
         )
     root = self.tree.getroot ()
     self.wlans = []
     for div in root.findall (".//%s" % tag ("div")) :
         if div.get ('class') != 'cbi-map' :
             continue
         if not len (div) or div [0].tag != tag ('h2') :
             continue
         if div [0].text not in wlo :
             continue
         for tr in div.findall (".//%s" % tag ("tr")) :
             cls = tr.get ('class') or ''
             cls = cls.split ()
             if 'cbi-section-table-row' not in cls :
                 continue
             d = WLAN_Config ()
             self.wlans.append (d)
             for td in tr :
                 k = td.get ('id')
                 if k :
                     k = k.split ('-') [-1]
                 else :
                     k = 'name'
                 v = td.text
                 d.set (** {k : v})
         break
Example #3
0
 def parse (self) :
     root = self.tree.getroot ()
     for fs in root.findall (".//%s" % tag ("fieldset")) :
         if fs.get ('class') == 'cbi-section' :
             tbl = fs.find (".//%s" % tag ("table"))
             assert tbl.get ('class') == 'cbi-section-table'
             for tr in tbl :
                 if tr [0].tag == tag ('th') :
                     assert tr [0].text == 'Announced network'
                     continue
                 assert tr [1][0].tag == tag ('a')
                 self.content.add (HNA_Entry (tr [0].text, tr [1][0].text))
Example #4
0
File: parser.py Project: CNDB/CNDB
 def parse (self) :
     self.backend = 'Backfire'
     root  = self.tree.getroot ()
     #print (self.tree_as_string (root))
     for h in root.findall (".//%s" % tag ('div')) :
         if h.get ('id') == 'header' :
             for p in h :
                 if p.tag not in (tag ('p'), tag ('h1')) :
                     break
             else :
                 self.backend = 'OpenWRT'
             break
Example #5
0
 def table_iter (self) :
     root  = self.tree.getroot ()
     for div in root.findall (".//%s" % tag ("div")) :
         if div.get ('id') == 'maincontent' :
             break
     tbl = div.find (".//%s" % tag ("table"))
     if tbl is None :
         return
     for tr in tbl :
         if tr [0].tag == tag ('th') :
             continue
         yield (self.tree.get_text (x) for x in tr)
Example #6
0
 def parse (self) :
     root = self.tree.getroot ()
     for fs in root.findall (".//%s" % tag ("fieldset")) :
         if fs.get ('class') == 'cbi-section' :
             tbl = fs.find (".//%s" % tag ("table"))
             assert tbl.get ('class') == 'cbi-section-table'
             for tr in tbl :
                 if tr [0].tag == tag ('th') :
                     assert tr [0].text == 'OLSR node'
                     continue
                 assert tr [0][0].tag == tag ('a')
                 self.content.add (tr [0][0].text, * tr [1].text.split (';'))
Example #7
0
 def tbl_iter (self, div) :
     tbl = div.find (".//%s" % tag ("table"))
     assert tbl.get ('class') == 'cbi-section-table'
     d = {}
     for tr in tbl :
         if 'cbi-section-table-row' not in tr.get ('class').split () :
             continue
         for input in tr.findall (".//%s" % tag ('input')) :
             name = input.get ('id').split ('.') [-1]
             val  = input.get ('value')
             d [name] = val
         if not d :
             continue
         yield d
Example #8
0
File: parser.py Project: CNDB/CNDB
 def try_freifunk (self, root) :
     for big in root.findall (".//%s" % tag ("big")) :
         if big.get ('class') == 'plugin' :
             self.backend = "Freifunk"
             break
     # Best effort to find status url
     for a in root.findall (".//%s" % tag ("a")) :
         if a.get ('class') == 'plugin' :
             # Allow 'Status klassisch' to override status
             # even if found first
             if a.text == 'Status klassisch' :
                 self.status_url = a.get ('href')
                 self.status_ok = 1
             elif a.text == 'Status' and not self.status_ok :
                 self.status_url = a.get ('href')
     self.params.update (url = self.status_url)
Example #9
0
 def parse (self) :
     wlo = \
         ( 'Wireless Overview'
         , 'Drahtlosübersicht'.decode ('utf-8')
         , 'WLAN Übersicht'.decode ('utf-8')
         )
     root = self.tree.getroot ()
     self.wlans = []
     for div in root.findall (".//%s" % tag ("div")) :
         if div.get ('class') != 'cbi-map' :
             continue
         if not len (div) or div [0].tag != tag ('h2') :
             continue
         if div [0].text not in wlo :
             continue
         for tr in div.findall (".//%s" % tag ("tr")) :
             cls = tr.get ('class') or ''
             cls = cls.split ()
             if 'cbi-section-table-row' not in cls :
                 continue
             d = WLAN_Config ()
             self.wlans.append (d)
             for td in tr :
                 k = td.get ('id')
                 if k :
                     k = k.split ('-') [-1]
                     # special handling of signal picture which has
                     # the necessary info in a title attribute :-(
                     if k == 'signal' and not td.text :
                         if td [0].tag == tag ('img') :
                             title = td [0].get ('title') 
                             m = self.title_re.search (title)
                             if m :
                                 d.set \
                                     ( signal = m.group (1)
                                     , noise  = m.group (2)
                                     )
                                 continue
                 else :
                     k = 'name'
                 v = td.text
                 d.set (** {k : v})
         break
Example #10
0
 def parse (self) :
     root = self.tree.getroot ()
     for fs in root.findall (".//%s" % tag ("fieldset")) :
         if fs.get ('class') == 'cbi-section' :
             tbl = fs.find (".//%s" % tag ("table"))
             assert tbl.get ('class') == 'cbi-section-table'
             for tr in tbl :
                 if tr [0].tag == tag ('th') :
                     assert tr [0].text == 'OLSR node'
                     continue
                 assert tr [0][0].tag == tag ('a')
                 assert tr [1][0].tag == tag ('a')
                 p = [tr [0][0].text, tr [1][0].text]
                 for v in tr [2:] :
                     v = v.text
                     if v == 'INFINITE' : v = 'inf'
                     v = float (v)
                     p.append (v)
                 self.content.add (Topo_Entry (* p))
Example #11
0
File: luci.py Project: mihi-tr/CNDB
 def try_get_version (self, div) :
     if div.get ('class') == 'footer' :
         for p in div.findall (".//%s" % tag ("p")) :
             if  (   p.get ('class') == 'luci'
                 and len (p)
                 and p [0].tag == tag ("a")
                 ) :
                 a = p [0]
                 if a.text.startswith ("Powered by LuCI") :
                     self.luci_version = a.text
     if div.get ('class') == 'header_right' :
         self.bf_version = div.text
     if div.get ('class') == 'hostinfo' :
         assert self.bf_version is None
         self.bf_version = div.text.split ('|') [0].strip ()
     if div.get ('id') == 'header' and not self.bf_version :
         p = div.find (".//%s" % tag ("p"))
         if p is not None :
             v = p.text.split (':', 1) [-1].split ('|', 1) [0]
             self.bf_version = v
Example #12
0
File: parser.py Project: CNDB/CNDB
 def try_luci (self, root) :
     for meta in root.findall (".//%s" % tag ("meta")) :
         if meta.get ('http-equiv') == 'refresh' :
             c = meta.get ('content')
             if c and c.endswith ('cgi-bin/luci') :
                 self.backend = 'Luci'
                 break
             elif c and c.endswith ('URL=/cgi-bin-index.html') :
                 # e.g. Fonera
                 self.backend = 'Freifunk'
                 break
Example #13
0
File: parser.py Project: CNDB/CNDB
 def try_router_os (self, root) :
     score = 0
     for td in root.findall (".//%s" % tag ("td")) :
         if td.text in self.router_os_scores :
             score += self.router_os_scores [td.text]
         if score > 3 :
             self.backend = 'Router_OS'
             break
     else :
         for form in root.findall (".//%s" % tag ("form")) :
             if form.get ('action') == "/login.cgi" :
                 self.backend = 'Router_OS'
                 self.params.update (url = 'cgi-bin/index.sh')
                 break
         else :
             return
     for a in root.findall (".//%s" % tag ("a")) :
         if a.text in ('OLSR-Routen', 'OLSR-Routen (IPv4)') :
             self.params.update (url = a.get ('href').split ('?') [0])
             break
Example #14
0
 def parse (self) :
     root = self.tree.getroot ()
     self.if_by_name = {}
     self.ips        = {}
     for div in root.findall (".//%s" % tag ("div")) :
         self.try_get_version (div)
         if div.get ('id') == 'maincontent' and not self.if_by_name :
             tbl = div.find (".//%s" % tag ("table"))
             for n, tr in enumerate (tbl) :
                 if tr [0].tag == tag ('th') :
                     assert tr [0].text in ('Interface', 'Schnittstelle') \
                         , tr [0].text
                     continue
                 name, status, mtu, wlan, ip, mask, bcast = \
                     (x.text for x in tr)
                 if name in self.if_by_name :
                     iface = self.if_by_name [name]
                 else :
                     iface = Interface (n, name, mtu)
                     iface.is_wlan = self.yesno.get (wlan, False)
                 if status == 'DOWN' :
                     continue
                 # append IP address to interface if there is one
                 if ip is not None :
                     if ':' in ip :
                         i6 = Inet6 (ip, mask, bcast, iface = name)
                         iface.append_inet6 (i6)
                     else :
                         i4 = Inet4 (ip, mask, bcast, iface = name)
                         iface.append_inet4 (i4)
                         if not unroutable (i4.ip) :
                             self.if_by_name [name] = iface
                             self.ips [i4] = True
     self.set_version (root)
     if not self.if_by_name :
         raise ValueError, "No interface config found"
     bfw = Backfire_WLAN_Config (site = self.site)
     for d in bfw.wlans :
         if d.name in self.if_by_name :
             iface = self.if_by_name [d.name]
             iface.wlan_info = d
Example #15
0
File: luci.py Project: mihi-tr/CNDB
 def set_version (self, root) :
     lv = self.luci_version
     if lv is None :
         p = root [-1][-1]
         if p.tag == tag ('p') and p.get ('class') == 'luci' :
             lv = self.luci_version = self.tree.get_text (p)
     # New 2014-Beta (sic) backfire has changed the version info :-(
     if lv is None :
         footer = None
         for a in root.findall (".//%s" % tag ("a")) :
             if a.get ('href') == 'http://luci.subsignal.org/' :
                 break
         if a is not None :
             if a.text.startswith ("Powered by LuCI") :
                 self.luci_version = lv = a.text
                 self.bf_version   = a.tail.strip ()
     if (lv and lv.startswith ('Powered by LuCI')) :
         lv = lv.split ('(', 1) [-1].split (')', 1) [0]
         self.luci_version = lv
     if self.bf_version and self.luci_version :
         self.version = "%s / Luci %s" % (self.bf_version, self.luci_version)
Example #16
0
 def parse(self):
     root = self.tree.getroot()
     self.ip_dev = {}
     self.gw_ip = {}
     self.metric = {}
     for pre in root.findall(".//%s" % tag("pre")):
         state = 0
         assert 'Table: Links' in pre.text
         for a in pre:
             if a.tag != tag('a'):
                 continue
             if state == 0:
                 state = 1
                 ip = a.text
             elif state == 1:
                 state = 0
                 if 'Table:' in a.tail:
                     state = 2
                 assert ip
                 self.gw_ip[a.text] = ip
                 # LQ, NLQ, Cost, 0th parameter varies with version
                 pars = a.tail.strip().split()[1:4]
                 pars = ((x, 'nan')[x == 'INFINITE'] for x in pars)
                 self.metric[ip] = [float(x) for x in pars]
             elif state == 2:
                 if 'Table: Routes' in a.tail:
                     state = 3
             elif state == 3:
                 state = 4
                 dst = a.text
                 if dst in self.gw_ip:
                     ip = self.gw_ip[dst]
                 else:
                     ip = None
             elif state == 4:
                 state = 3
                 if ip:
                     assert dst
                     self.ip_dev[ip] = a.tail.strip().split()[-1]
Example #17
0
 def set_version(self, root):
     lv = self.luci_version
     if lv is None:
         p = root[-1][-1]
         if p.tag == tag('p') and p.get('class') == 'luci':
             lv = self.luci_version = self.tree.get_text(p)
     # New 2014-Beta (sic) backfire has changed the version info :-(
     if lv is None:
         footer = None
         for a in root.findall(".//%s" % tag("a")):
             if a.get('href') == 'http://luci.subsignal.org/':
                 break
         if a is not None:
             if a.text.startswith("Powered by LuCI"):
                 self.luci_version = lv = a.text
                 self.bf_version = a.tail.strip()
     if (lv and lv.startswith('Powered by LuCI')):
         lv = lv.split('(', 1)[-1].split(')', 1)[0]
         self.luci_version = lv
     if self.bf_version and self.luci_version:
         self.version = "%s / Luci %s" % (self.bf_version,
                                          self.luci_version)
Example #18
0
 def parse (self) :
     root  = self.tree.getroot ()
     self.ip_dev = {}
     self.gw_ip  = {}
     self.metric = {}
     for pre in root.findall (".//%s" % tag ("pre")) :
         state = 0
         assert 'Table: Links' in pre.text
         for a in pre :
             if a.tag != tag ('a') :
                 continue
             if state == 0 :
                 state = 1
                 ip = a.text
             elif state == 1 :
                 state = 0
                 if 'Table:' in a.tail :
                     state = 2
                 assert ip
                 self.gw_ip [a.text] = ip
                 # LQ, NLQ, Cost, 0th parameter varies with version
                 pars = a.tail.strip ().split () [1:4]
                 pars = ((x, 'nan')[x == 'INFINITE'] for x in pars)
                 self.metric [ip] = [float (x) for x in pars]
             elif state == 2 :
                 if 'Table: Routes' in a.tail :
                     state = 3
             elif state == 3 :
                 state = 4
                 dst = a.text
                 if dst in self.gw_ip :
                     ip = self.gw_ip [dst]
                 else :
                     ip = None
             elif state == 4 :
                 state = 3
                 if ip :
                     assert dst
                     self.ip_dev [ip] = a.tail.strip ().split () [-1]
Example #19
0
 def parse(self):
     self.backend = None
     root = self.tree.getroot()
     #print self.tree_as_string (root)
     title = root.find(".//%s" % tag("title"))
     t = 'olsr.org httpinfo plugin'
     if title is not None and title.text and title.text.strip() == t:
         self.backend = 'OLSR'
         self.params.update(site=self.url)
     if not self.backend:
         for meta in root.findall(".//%s" % tag("meta")):
             if meta.get('http-equiv') == 'refresh':
                 c = meta.get('content')
                 if c and c.endswith('cgi-bin/luci'):
                     self.backend = 'Luci'
                     break
                 elif c and c.endswith('URL=/cgi-bin-index.html'):
                     # e.g. Fonera
                     self.backend = 'Freifunk'
                     break
         else:  # Freifunk
             for big in root.findall(".//%s" % tag("big")):
                 if big.get('class') == 'plugin':
                     self.backend = "Freifunk"
                     break
             else:
                 raise ValueError("Unknown Web Frontend")
             # Best effort to find status url
             for a in root.findall(".//%s" % tag("a")):
                 if a.get('class') == 'plugin':
                     # Allow 'Status klassisch' to override status
                     # even if found first
                     if a.text == 'Status klassisch':
                         self.status_url = a.get('href')
                         self.status_ok = 1
                     elif a.text == 'Status' and not self.status_ok:
                         self.status_url = a.get('href')
             self.params.update(url=self.status_url)
Example #20
0
 def parse (self) :
     self.if_by_name = {}
     self.ips        = {}
     root = self.tree.getroot ()
     for div in root.findall (".//%s" % tag ('div')) :
         if div.get ('id') == 'maintable' :
             break
     else :
         raise Parse_Error ("Unable to find main table")
     # get version
     vt = div.text
     assert vt.startswith ('Version:')
     self.version = vt.split (' - ') [1].strip ()
     # we search for the first table after the h2 Interfaces element
     found = False
     for e in div :
         if e.tag == tag ('h2') and e.text == 'Interfaces' :
             found = True
         if found and e.tag == tag ('table') :
             tbl  = e
             name = None
             d    = {}
             n    = 0
             for tr in tbl :
                 if tr [0].tag == tag ('th') :
                     if name and d.get ('status') == 'UP' :
                         self.append_iface (n, name, ** d)
                         n += 1
                     name = tr [0].text
                     d    = {}
                 else :
                     for td in tr :
                         k, v = (x.strip () for x in td.text.split (':', 1))
                         d [k.lower ()] = v
             if name and d.get ('status') == 'UP' :
                 self.append_iface (n, name, ** d)
                 n += 1
             break
Example #21
0
 def parse (self) :
     self.backend = None
     root  = self.tree.getroot ()
     #print self.tree_as_string (root)
     title = root.find (".//%s" % tag ("title"))
     t     = 'olsr.org httpinfo plugin'
     if title is not None and title.text and title.text.strip () == t :
         self.backend = 'OLSR'
         self.params.update (site = self.url)
     if not self.backend :
         for meta in root.findall (".//%s" % tag ("meta")) :
             if meta.get ('http-equiv') == 'refresh' :
                 c = meta.get ('content')
                 if c and c.endswith ('cgi-bin/luci') :
                     self.backend = 'Luci'
                     break
                 elif c and c.endswith ('URL=/cgi-bin-index.html') :
                     # e.g. Fonera
                     self.backend = 'Freifunk'
                     break
         else : # Freifunk
             for big in root.findall (".//%s" % tag ("big")) :
                 if big.get ('class') == 'plugin' :
                     self.backend = "Freifunk"
                     break
             else :
                 raise ValueError ("Unknown Web Frontend")
             # Best effort to find status url
             for a in root.findall (".//%s" % tag ("a")) :
                 if a.get ('class') == 'plugin' :
                     # Allow 'Status klassisch' to override status
                     # even if found first
                     if a.text == 'Status klassisch' :
                         self.status_url = a.get ('href')
                         self.status_ok = 1
                     elif a.text == 'Status' and not self.status_ok :
                         self.status_url = a.get ('href')
             self.params.update (url = self.status_url)
Example #22
0
 def parse(self):
     self.if_by_name = {}
     self.ips = {}
     root = self.tree.getroot()
     for div in root.findall(".//%s" % tag("div")):
         if div.get("id") == "maintable":
             break
     else:
         raise Parse_Error("Unable to find main table")
     # get version
     vt = div.text
     assert vt.startswith("Version:")
     self.version = vt.split(" - ")[1].strip()
     # we search for the first table after the h2 Interfaces element
     found = False
     for e in div:
         if e.tag == tag("h2") and e.text == "Interfaces":
             found = True
         if found and e.tag == tag("table"):
             tbl = e
             name = None
             d = {}
             n = 0
             for tr in tbl:
                 if tr[0].tag == tag("th"):
                     if name and d.get("status") == "UP":
                         self.append_iface(n, name, **d)
                         n += 1
                     name = tr[0].text
                     d = {}
                 else:
                     for td in tr:
                         k, v = (x.strip() for x in td.text.split(":", 1))
                         d[k.lower()] = v
             if name and d.get("status") == "UP":
                 self.append_iface(n, name, **d)
                 n += 1
             break
Example #23
0
 def parse(self):
     self.if_by_name = {}
     self.ips = {}
     root = self.tree.getroot()
     for div in root.findall(".//%s" % tag('div')):
         if div.get('id') == 'maintable':
             break
     else:
         raise Parse_Error("Unable to find main table")
     # get version
     vt = div.text
     assert vt.startswith('Version:')
     self.version = vt.split(' - ')[1].strip()
     # we search for the first table after the h2 Interfaces element
     found = False
     for e in div:
         if e.tag == tag('h2') and e.text == 'Interfaces':
             found = True
         if found and e.tag == tag('table'):
             tbl = e
             name = None
             d = {}
             n = 0
             for tr in tbl:
                 if tr[0].tag == tag('th'):
                     if name and d.get('status') == 'UP':
                         self.append_iface(n, name, **d)
                         n += 1
                     name = tr[0].text
                     d = {}
                 else:
                     for td in tr:
                         k, v = (x.strip() for x in td.text.split(':', 1))
                         d[k.lower()] = v
             if name and d.get('status') == 'UP':
                 self.append_iface(n, name, **d)
                 n += 1
             break
Example #24
0
 def parse (self) :
     self.backend = None
     root  = self.tree.getroot ()
     #print (self.tree_as_string (root))
     title = root.find (".//%s" % tag ("title"))
     t     = 'olsr.org httpinfo plugin'
     if title is not None and title.text and title.text.strip () == t :
         self.backend = 'OLSR'
         self.params.update (site = self.url)
     for trial in self.try_luci, self.try_freifunk, self.try_router_os :
         if not self.backend :
             trial (root)
     if not self.backend :
         #print (self.tree_as_string (root))
         raise ValueError ("Unknown Web Frontend")
Example #25
0
 def parse (self) :
     root  = self.tree.getroot ()
     self.wlans  = []
     self.routes = {}
     for div in root.findall (".//%s" % tag ("div")) :
         id = div.get ('id')
         if id == 'cbi-wireless' :
             wlan_div = div
         elif id == 'cbi-routes' :
             route_div = div
         self.try_get_version (div)
     for d in self.tbl_iter (wlan_div) :
         for k, newkey in self.wl_names.iteritems () :
             if k in d :
                 d [newkey] = d [k]
         wl = WLAN_Config (** d)
         self.wlans.append (wl)
     for d in self.tbl_iter (route_div) :
         iface = d.get ('iface')
         gw    = d.get ('gateway')
         if iface and gw :
             self.routes [iface] = gw
     self.set_version (root)
Example #26
0
 def parse(self):
     root = self.tree.getroot()
     self.wlans = []
     self.routes = {}
     for div in root.findall(".//%s" % tag("div")):
         id = div.get('id')
         if id == 'cbi-wireless':
             wlan_div = div
         elif id == 'cbi-routes':
             route_div = div
         self.try_get_version(div)
     for d in self.tbl_iter(wlan_div):
         for k, newkey in self.wl_names.iteritems():
             if k in d:
                 d[newkey] = d[k]
         wl = WLAN_Config(**d)
         self.wlans.append(wl)
     for d in self.tbl_iter(route_div):
         iface = d.get('iface')
         gw = d.get('gateway')
         if iface and gw:
             self.routes[iface] = gw
     self.set_version(root)
Example #27
0
    def parse(self):
        #print self.tree_as_string ()
        root = self.tree.getroot()
        for pre in root.findall(".//%s" % tag("pre")):
            if pre.get('id') == 'ifconfig':
                self.ifconfig = Interface_Config()
                self.ifconfig.parse(pre.text.split('\n'))
                #print pre.text
                self.if_by_name = {}
                self.ips = {}
                for k, v in self.ifconfig.assignments.iteritems():
                    v = v.strip()
                    if not v:
                        continue
                    if k == 'lan_ifname':
                        is_wlan = False
                    elif k == 'wan_ifname':
                        is_wlan = False
                    elif k.startswith('wl') and k.endswith('_ifname'):
                        is_wlan = True
                    elif k == 'wifi_ifname':
                        is_wlan = True
                    else:
                        continue
                    # unused interface name:
                    if v not in self.ifconfig.if_by_name:
                        continue
                    iface = self.ifconfig.if_by_name[v]
                    self._check_interface(iface, is_wlan)
                for iface in self.ifconfig.interfaces:
                    if iface.name not in self.if_by_name:
                        self._check_interface(iface)
                break
        else:
            raise ValueError, "No interface config found"
        for td in root.findall(".//%s" % tag("td")):
            if (not td.text or 'SSID:' not in td.text):
                continue
            self.wlan_info = WLAN_Config_Freifunk()
            self.wlan_info.parse(td.text.split('\n'))
            break
        wl_count = 0
        if self.wlan_info:
            for iface in self.if_by_name.itervalues():
                if iface.is_wlan:
                    iface.wlan_info = self.wlan_info
                    wl_count += 1
        if not wl_count and getattr(self.wlan_info, 'name', None):
            if self.wlan_info.name in self.if_by_name:
                iface = self.if_by_name[self.wlan_info.name]
                iface.is_wlan = True
                iface.wlan_info = self.wlan_info
                wl_count += 1

        assert wl_count <= 1
        for sm in root.findall(".//%s" % tag("small")):
            if sm.text:
                s = sm.text.strip()
                if s.startswith('v1.') or s.startswith('1.'):
                    self.version = sm.text
                    break
        if self.version == 'Unknown':
            for td in root.findall(".//%s" % tag("td")):
                if td.text:
                    s = td.text.strip()
                    if s.startswith('v1.') or s.startswith('Fonera-1'):
                        self.version = td.text.strip()
                        break
Example #28
0
File: freifunk.py Project: FFM/FFM
    def parse (self) :
        #print self.tree_as_string ()
        root = self.tree.getroot ()
        for pre in root.findall (".//%s" % tag ("pre")) :
            if pre.get ('id') == 'ifconfig' :
                self.ifconfig = Interface_Config ()
                self.ifconfig.parse (pre.text.split ('\n'))
                #print pre.text
                self.if_by_name = {}
                self.ips        = {}
                for k, v in self.ifconfig.assignments.iteritems () :
                    v = v.strip ()
                    if not v :
                        continue
                    if k == 'lan_ifname' :
                        is_wlan = False
                    elif k == 'wan_ifname' :
                        is_wlan = False
                    elif k.startswith ('wl') and k.endswith ('_ifname') :
                        is_wlan = True
                    elif k == 'wifi_ifname' :
                        is_wlan = True
                    else :
                        continue
                    # unused interface name:
                    if v not in self.ifconfig.if_by_name :
                        continue
                    iface = self.ifconfig.if_by_name [v]
                    self._check_interface (iface, is_wlan)
                for iface in self.ifconfig.interfaces :
                    if iface.name not in self.if_by_name :
                        self._check_interface (iface)
                break
        else :
            raise ValueError, "No interface config found"
        for td in root.findall (".//%s" % tag ("td")) :
            if (not td.text or 'SSID:' not in td.text) :
                continue
            self.wlan_info = WLAN_Config_Freifunk ()
            self.wlan_info.parse (td.text.split ('\n'))
            break
        wl_count = 0
        if self.wlan_info :
            for iface in self.if_by_name.itervalues () :
                if iface.is_wlan :
                    iface.wlan_info = self.wlan_info
                    wl_count += 1
        if not wl_count and getattr (self.wlan_info, 'name', None) :
            if self.wlan_info.name in self.if_by_name :
                iface = self.if_by_name [self.wlan_info.name]
                iface.is_wlan = True
                iface.wlan_info = self.wlan_info
                wl_count += 1

        assert wl_count <= 1
        for sm in root.findall (".//%s" % tag ("small")) :
            if sm.text :
                s = sm.text.strip ()
                if s.startswith ('v1.') or s.startswith ('1.') :
                    self.version = sm.text
                    break
        if self.version == 'Unknown' :
            for td in root.findall (".//%s" % tag ("td")) :
                if td.text :
                    s = td.text.strip ()
                    if s.startswith ('v1.') or s.startswith ('Fonera-1') :
                        self.version = td.text.strip ()
                        break