def writeSipConf(self): """Writes the sip.conf file""" content = self.configContent['sip'] % { 'codec': str.join("\n ", self.colapseData(self.codecs)), 'domain': config.Domain, 'context': 'default' } self.writeFile('/etc/asterisk/sip.conf', content, ';') # Create sip peers for handsets phones = config.PBX.get('phones', {}) for exten, conf in phones.items(): phDevString = "Phone/" + conf['username'] conf['context'] = "" conf['voicemail'] = '' conf['append'] = '' ext = PBXUtils.getDeviceExtension(phDevString) if ext: if ext[1]['enabled']: conf['extname'] = ext[0] conf[ 'context'] = "context = " + PBXUtils.getExtensionContext( ext[1]) if 'fullcallerID' in ext[1]: conf['callerid'] = ext[1]['fullcallerID'] if ext[1].get('voiceMail', False): conf['voicemail'] = 'mailbox=' + str( ext[1]['extensions'][0]) conf['append'] = """callgroup=0 accountcode=%(extname)s pickupgroup=0 vmexten=*96 %(voicemail)s """ % conf block = """[%(username)s] type=peer %(context)s callerid=%(callerid)s username=%(username)s host=dynamic notifyringing=yes nat=yes notifyhold=yes limitonpeers=yes call-limit=99 canreinvite=no qualify=5000 dtmfmode=rfc2833 %(append)s """ % conf if conf.get('call-limit', 0): block += "call-limit=%s\n" % conf['call-limit'] ph = open('/etc/asterisk/peers/sip/%s.conf' % exten, 'wt') ph.write(self.stripBlock(block)) ph.close()
def generateHandsetConfig(self, macAddr): """Generates the handset config from the mac address""" #snomMAC = self.sysconf.PBX.get('snomMAC', []) #if macAddr not in snomMAC: # snomMAC.append(macAddr) #So it shows in the interface # PBX = self.sysconf.PBX # PBX['snomMAC'] = snomMAC # self.sysconf.PBX = PBX phoneEnt = self.getPhoneEntry(macAddr) d = None data = {} def returnEntry(ret=None): print data if data: return stan.raw(snomDevConf % data) return "" if not phoneEnt: #Generate a blank Phone entry PBX = self.sysconf.PBX phones = PBX.get('phones', {}) cblock = { 'callerid': macAddr, 'username': macAddr, 'fullcallerid': macAddr, 'phone': { 'type': 'Snom ' + self.phoneVer[0], 'fkeys': [], 'mac': macAddr, 'autogen': True, #This was autogenerated }, 'secret': GenPasswd2(), 'outgoinglimit': 1 } phones[macAddr] = cblock PBX['phones'] = phones self.sysconf.PBX = PBX d = Asterisk.restartAsterisk() phoneEnt = self.getPhoneEntry(macAddr) print phoneEnt if phoneEnt: type = phoneEnt['phone']['type'].lower().split()[1] ptype = phoneEnt['phone']['type'].lower().split()[0] if self.phoneVer[0]: type = self.phoneVer[0].lower() if ptype == 'snom': ext = PBXUtils.getDeviceExtension('Phone/' + phoneEnt['username']) callerid = phoneEnt['username'] displayName = phoneEnt['username'] fkeys = self.genSnomFkeys([], type, self.phoneVer[1][0] == 7) if type == '300': displayName = displayName[ 2:] #Strip out the first two '0' chars if ext: #If there is a user extension bound to this phone then we need to work out a few things if ext[1]['enabled']: callerid = ext[1].get( 'fullcallerID', ext[1].get('callerID', 'Unknown')) displayName = "%s-%s" % (ext[1].get( 'callerID', 'Unknown'), ext[0]) if 'fkeys' in ext[1]: #Resolve Function Keys fkeys = self.genSnomFkeys(ext[1]['fkeys'], type) fwurl = 'firmware_status: http://%s:9682/snom/snom-firmware.htm' % self.lanIP if self.phoneVer[0] not in self.firmware.keys(): autoVer = "v%s" % self.phoneVer[1][0] print "Snom of type %s requested firmware for version %s, I don't know this type sending it to snom url(%s)" % ( self.phoneVer[0], str.join('.', self.phoneVer[1]), self.firmware[autoVer], ) if autoVer in self.firmware: fwurl = "firmware_status: %s%s" % ( self.firmware[autoVer], str(time.time())) data = { 'fkeys': fkeys, 'user': phoneEnt['username'], 'user_realname': callerid, 'user_idletext': displayName, 'password': phoneEnt['secret'], 'firmwareurl': fwurl, } if d: #If there is a defer then lets wait for it to end return d.addBoth(returnEntry) else: return returnEntry()