Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
	import mailbox

	import univention.admin.modules
	univention.admin.modules.init(lo, extenPhone.position, user)

	phoneUser = user.lookup(co, lo, "(ast4ucsUserPhone=%s)"%(
		univention.admin.filter.escapeForLdapFilter(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)
		if phone.get("forwarding"):
			channels.append("Local/%s" % phone["forwarding"])
		else:
			channels.append("SIP/%s" % phone["extension"])
			hints.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