Esempio n. 1
0
 def annotate_profiles(self, profiles):
     for k,v in profiles.iteritems():
         matches = core.find_matching_available_nets(v["ssid"], v["bssid"])
         if len(matches) > 0:
             v["available"] = True
         else:
             v["available"] = False
         v["available_nets"] = matches
     return profiles
Esempio n. 2
0
 def annotate_profiles(self, profiles):
     for k, v in profiles.iteritems():
         matches = core.find_matching_available_nets(v["ssid"], v["bssid"])
         if len(matches) > 0:
             v["available"] = True
         else:
             v["available"] = False
         v["available_nets"] = matches
     return profiles
Esempio n. 3
0
 def readProfile(self, profname):
     f = os.path.join(self.profiledir, profname + '.profile')
     p = pyjavaproperties.Properties()
     p.load(open(f))
     profile = dict()
     profile['filename'] = f
     profile['mtime'] = os.path.getmtime(f)
     for k,v in p.items():
         profile[k] = v
     for param in ('ssid', 'channel', 'ip', 'netmask', 'dns', 'ipgenerate'):
         ##Also validate ip, dns, bssid, channel?
         if param not in profile:
             self.log('Error in ' + f + ': missing or malformed ' +
                     param + ' option') ## And raise some sort of error?
     if profile['ipgenerate'] in ('True', 'true', 'Yes', 'yes', '1'):
         # and not profile['randomip']
         self.log('Generating static ip with base ' +
                 profile['ip'] + ' and subnet ' + profile['netmask'])
         # If this profile is detected on an interface, use that interface;
         #   otherwise use the default.
         # FIXME we should try to not mix network code into the file loader code
         matched_nets = core.find_matching_available_nets(profile["ssid"],
                                                             profile["bssid"])
         if len(matched_nets) > 0:
             #FIXME: This is a bug in a multi-interface environment
             mac = core.nets_dict[matched_nets[0]]["interface"].MAC
         else:
             mac = self.selectInterface().MAC
         profile['ip'] = self._generate_ip(profile['ip'],
                                           profile['netmask'],
                                           mac)
     if not 'bssid' in profile:
         # Include note in default config file that bssid parameter is allowed,
         #   but should almost never be used
         self.log('Generating BSSID from hash of ssid and channel')
         bssid = hashlib.new('md4', ssid).hexdigest()[-8:].upper() \
                 + '%02X' %int(profile['channel']) #or 'md5', [:8]
         profile['bssid'] = ':'.join(a+b for a,b in zip(bssid[::2], bssid[1::2]))
     conf = re.sub('(.*)\.profile', r'\1.conf', f) #TODO: this is now wrong
     if os.path.exists(conf):
         self.log('profile has custom olsrd.conf: "' + conf + '"')
         profile['conf'] = conf
     else:
         self.log('using built in olsrd.conf: "' + self.olsrdconf + '"')
         profile['conf'] = self.olsrdconf
     return profile