def checkFields(self, module): def nameFromDn(dn): return dn.split(",")[0].split("=", 1)[1] for phonedn in module.info.get("phones", []): if not phonedn: continue phoneUsers = user.lookup(module.co, module.lo, "(&(ast4ucsUserPhone=%s)(!(uid=%s)))" % ( escapeForLdapFilter(phonedn), escapeForLdapFilter(module.info["username"]))) if phoneUsers: raise self.phoneError( nameFromDn(phonedn), nameFromDn(phoneUsers[0].dn)) mailboxdn = module.info.get("mailbox") if mailboxdn: mailboxUsers = user.lookup(module.co, module.lo, "(&(ast4ucsUserMailbox=%s)(!(uid=%s)))" % ( escapeForLdapFilter(mailboxdn), escapeForLdapFilter(module.info["username"]))) if mailboxUsers: raise self.mailboxError( nameFromDn(mailboxdn), nameFromDn(mailboxUsers[0].dn))
def genVoicemailconfEntry(co, lo, box): from univention.admin.handlers.users import user boxUser = user.lookup(co, lo, filter_format("(ast4ucsUserMailbox=%s)", (box.dn,))) if len(boxUser) == 0: return ";; Mailbox %s has no user.\n" % box["id"] if len(boxUser) > 1: msg = ";; Mailbox %s has multiple users:\n" % box["id"] for userObj in boxUser: msg += ";; * %s\n" % userObj["username"] boxUser = boxUser[0].info box = box.info if box.get("email") == "1" and boxUser.get("mailPrimaryAddress"): return "%s => %s,%s,%s\n" % ( box["id"], box["password"], getNameFromUser(boxUser), llist(boxUser["mailPrimaryAddress"])[0], ) else: return "%s => %s,%s\n" % ( box["id"], box["password"], getNameFromUser(boxUser), )
def genVoicemailconfEntry(co, lo, box): from univention.admin.handlers.users import user boxUser = user.lookup(co, lo, filter_format("(ast4ucsUserMailbox=%s)", (box.dn, ))) if len(boxUser) == 0: return ";; Mailbox %s has no user.\n" % box["id"] if len(boxUser) > 1: msg = ";; Mailbox %s has multiple users:\n" % box["id"] for userObj in boxUser: msg += ";; * %s\n" % userObj["username"] boxUser = boxUser[0].info box = box.info if box.get("email") == "1" and boxUser.get("mailPrimaryAddress"): return "%s => %s,%s,%s\n" % ( box["id"], box["password"], getNameFromUser(boxUser), llist(boxUser["mailPrimaryAddress"])[0], ) else: return "%s => %s,%s\n" % ( box["id"], box["password"], getNameFromUser(boxUser), )
def genSipconfEntry(co, lo, phone): from univention.admin.handlers.users import user from univention.admin.handlers.asterisk import sipPhone, mailbox, phoneGroup import univention.admin.modules univention.admin.modules.init(lo, phone.position, user) phoneUser = user.lookup(co, lo, filter_format("(ast4ucsUserPhone=%s)", (phone.dn,))) if len(phoneUser) == 0: return ";; Phone %s has no user.\n" % phone["extension"] if len(phoneUser) > 1: msg = ";; Phone %s has multiple users:\n" % phone["extension"] for userObj in phoneUser: msg += ";; * %s\n" % userObj["username"] phoneUser = phoneUser[0].info phone = phone.info if phoneUser.get("mailbox"): phoneMailbox = mailbox.object(co, lo, None, phoneUser["mailbox"]).info callgroups = [] for group in phone.get("callgroups", []): group = phoneGroup.object(co, lo, None, group).info callgroups.append(group["id"]) pickupgroups = [] for group in phone.get("pickupgroups", []): group = phoneGroup.object(co, lo, None, group).info pickupgroups.append(group["id"]) res = "[%s](template-%s)\n" % ( phone["extension"], phone.get("profile", "default")) res += "secret=%s\n" % (phone["password"]) if phoneUser.get("extmode") == "normal": res += "callerid=\"%s\" <%s>\n" % ( getNameFromUser(phoneUser), phone["extension"]) elif phoneUser.get("extmode") == "first": firstPhone = sipPhone.object(co, lo, None, llist(phoneUser["phones"])[0]).info res += "callerid=\"%s\" <%s>\n" % ( getNameFromUser(phoneUser), firstPhone["extension"]) if phoneUser.get("mailbox"): res += "mailbox=%s\n" % (phoneMailbox["id"]) if callgroups: res += "callgroup=%s\n" % (','.join(callgroups)) if pickupgroups: res += "pickupgroup=%s\n" % (','.join(pickupgroups)) return res
def genSipconfEntry(co, lo, phone): from univention.admin.handlers.users import user from univention.admin.handlers.asterisk import sipPhone, mailbox, phoneGroup import univention.admin.modules univention.admin.modules.init(lo, phone.position, user) phoneUser = user.lookup( co, lo, filter_format("(ast4ucsUserPhone=%s)", (phone.dn, ))) if len(phoneUser) == 0: return ";; Phone %s has no user.\n" % phone["extension"] if len(phoneUser) > 1: msg = ";; Phone %s has multiple users:\n" % phone["extension"] for userObj in phoneUser: msg += ";; * %s\n" % userObj["username"] phoneUser = phoneUser[0].info phone = phone.info if phoneUser.get("mailbox"): phoneMailbox = mailbox.object(co, lo, None, phoneUser["mailbox"]).info callgroups = [] for group in phone.get("callgroups", []): group = phoneGroup.object(co, lo, None, group).info callgroups.append(group["id"]) pickupgroups = [] for group in phone.get("pickupgroups", []): group = phoneGroup.object(co, lo, None, group).info pickupgroups.append(group["id"]) res = "[%s](template-%s)\n" % (phone["extension"], phone.get("profile", "default")) res += "secret=%s\n" % (phone["password"]) if phoneUser.get("extmode") == "normal": res += "callerid=\"%s\" <%s>\n" % (getNameFromUser(phoneUser), phone["extension"]) elif phoneUser.get("extmode") == "first": firstPhone = sipPhone.object(co, lo, None, llist(phoneUser["phones"])[0]).info res += "callerid=\"%s\" <%s>\n" % (getNameFromUser(phoneUser), firstPhone["extension"]) if phoneUser.get("mailbox"): res += "mailbox=%s\n" % (phoneMailbox["id"]) if callgroups: res += "callgroup=%s\n" % (','.join(callgroups)) if pickupgroups: res += "pickupgroup=%s\n" % (','.join(pickupgroups)) return res
def lookup(co, lo, filter_s, base='', superordinate=None, scope='sub', unique=False, required=False, timeout=-1, sizelimit=0): dn = lo.whoami() return [ user for user in udm_user.lookup(co, lo, filter_s, base, superordinate, scope=scope, unique=unique, required=required, timeout=timeout, sizelimit=sizelimit) if lo.compare_dn(dn, user.dn) ]
def genExtSIPPhoneEntry(co, lo, agis, extenPhone): extension = extenPhone.info["extension"] # check if this phone is managed manually (not by ast4ucs) if extenPhone.get("skipExtension") == "1": return ";; Extension %s is managed manually.\n" % ( extenPhone["extension"]) from univention.admin.handlers.users import user from univention.admin.handlers.asterisk import sipPhone, mailbox import univention.admin.modules univention.admin.modules.init(lo, extenPhone.position, user) phoneUser = user.lookup(co, lo, filter_format("(ast4ucsUserPhone=%s)", (extenPhone.dn,))) if len(phoneUser) == 0: return ";; Phone %s has no user.\n" % extenPhone["extension"] if len(phoneUser) > 1: msg = ";; Phone %s has multiple users:\n" % extenPhone["extension"] for userObj in phoneUser: msg += ";; * %s\n" % userObj["username"] phoneUser = phoneUser[0].info try: timeout = int(phoneUser["timeout"]) if timeout < 1 or timeout > 120: raise Exception except: timeout = 10 try: ringdelay = int(phoneUser["ringdelay"]) if ringdelay < 1 or ringdelay > 120: raise Exception except: ringdelay = 0 channels = [] hints = [] for dn in phoneUser.get("phones", []): phone = sipPhone.object(co, lo, extenPhone.position, dn, extenPhone.superordinate) hints.append("SIP/%s" % phone["extension"]) if phone.get("forwarding"): channels.append("Local/%s" % phone["forwarding"]) else: channels.append("SIP/%s" % phone["extension"]) res = [] # copy agis into res for agi in agis: res.append(agi) if channels: if ringdelay: for channel in channels[:-1]: res.append("Dial(%s,%i,tT)" % (channel, ringdelay)) res.append("Wait(0.5)") res.append("Dial(%s,%i,tT)" % (channels[-1], timeout)) else: res.append("Dial(%s,%i,tT)" % ( '&'.join(channels), timeout)) if phoneUser.get("mailbox"): phoneMailbox = mailbox.object( co, lo, None, phoneUser["mailbox"]).info res.append("Voicemail(%s,u)" % phoneMailbox["id"]) if phoneUser.get("forwarding"): res = ["Dial(Local/%s,,tT)" % phoneUser["forwarding"]] resStr = "" if hints: resStr += "exten => %s,hint,%s\n" % (extension, '&'.join(hints)) for i, data in enumerate(res): resStr += "exten => %s,%i,%s\n" % (extension, i+1, data) return resStr
def genExtSIPPhoneEntry(co, lo, agis, extenPhone): extension = extenPhone.info["extension"] # check if this phone is managed manually (not by ast4ucs) if extenPhone.get("skipExtension") == "1": return ";; Extension %s is managed manually.\n" % ( extenPhone["extension"]) from univention.admin.handlers.users import user from univention.admin.handlers.asterisk import sipPhone, mailbox import univention.admin.modules univention.admin.modules.init(lo, extenPhone.position, user) phoneUser = user.lookup( co, lo, filter_format("(ast4ucsUserPhone=%s)", (extenPhone.dn, ))) if len(phoneUser) == 0: return ";; Phone %s has no user.\n" % extenPhone["extension"] if len(phoneUser) > 1: msg = ";; Phone %s has multiple users:\n" % extenPhone["extension"] for userObj in phoneUser: msg += ";; * %s\n" % userObj["username"] phoneUser = phoneUser[0].info try: timeout = int(phoneUser["timeout"]) if timeout < 1 or timeout > 120: raise Exception except: timeout = 10 try: ringdelay = int(phoneUser["ringdelay"]) if ringdelay < 1 or ringdelay > 120: raise Exception except: ringdelay = 0 channels = [] hints = [] for dn in phoneUser.get("phones", []): phone = sipPhone.object(co, lo, extenPhone.position, dn, extenPhone.superordinate) hints.append("SIP/%s" % phone["extension"]) if phone.get("forwarding"): channels.append("Local/%s" % phone["forwarding"]) else: channels.append("SIP/%s" % phone["extension"]) res = [] # copy agis into res for agi in agis: res.append(agi) if channels: if ringdelay: for channel in channels[:-1]: res.append("Dial(%s,%i,tT)" % (channel, ringdelay)) res.append("Wait(0.5)") res.append("Dial(%s,%i,tT)" % (channels[-1], timeout)) else: res.append("Dial(%s,%i,tT)" % ('&'.join(channels), timeout)) if phoneUser.get("mailbox"): phoneMailbox = mailbox.object(co, lo, None, phoneUser["mailbox"]).info res.append("Voicemail(%s,u)" % phoneMailbox["id"]) if phoneUser.get("forwarding"): res = ["Dial(Local/%s,,tT)" % phoneUser["forwarding"]] resStr = "" if hints: resStr += "exten => %s,hint,%s\n" % (extension, '&'.join(hints)) for i, data in enumerate(res): resStr += "exten => %s,%i,%s\n" % (extension, i + 1, data) return resStr
def genSipconfEntry(co, lo, phone): from univention.admin.handlers.users import user import mailbox, phoneGroup import univention.admin.modules univention.admin.modules.init(lo, phone.position, user) phoneUser = user.lookup(co, lo, "(ast4ucsUserPhone=%s)" % ( univention.admin.filter.escapeForLdapFilter(phone.dn))) if len(phoneUser) == 0: return ";; Phone %s has no user.\n" % phone["extension"] if len(phoneUser) > 1: msg = ";; Phone %s has multiple users:\n" % phone["extension"] for userObj in phoneUser: msg += ";; * %s\n" % userObj["username"] phoneUser = phoneUser[0].info phone = phone.info if phoneUser.get("mailbox"): phoneMailbox = mailbox.object(co, lo, None, phoneUser["mailbox"]).info callgroups = [] for group in phone.get("callgroups", []): group = phoneGroup.object(co, lo, None, group).info callgroups.append(group["id"]) pickupgroups = [] for group in phone.get("pickupgroups", []): group = phoneGroup.object(co, lo, None, group).info pickupgroups.append(group["id"]) res = "[%s]\n" % (phone["extension"]) res += "type=friend\n" res += "host=dynamic\n" res += "subscribecontext=default\n" res += "call-limit=10\n" res += "secret=%s\n" % (phone["password"]) if phoneUser.get("extmode") == "normal": res += "callerid=\"%s\" <%s>\n" % ( getNameFromUser(phoneUser), phone["extension"] ) elif phoneUser.get("extmode") == "first": firstPhone = sipPhone.object(co, lo, None, llist(phoneUser["phones"])[0]).info res += "callerid=\"%s\" <%s>\n" % ( getNameFromUser(phoneUser), firstPhone["extension"] ) if phoneUser.get("mailbox"): res += "mailbox=%s\n" % (phoneMailbox["id"]) if callgroups: res += "callgroup=%s\n" % (','.join(callgroups)) if pickupgroups: res += "pickupgroup=%s\n" % (','.join(pickupgroups)) return res