|
|
@ -18,15 +18,31 @@ class Dect:
|
|
|
|
ommsync=True,
|
|
|
|
ommsync=True,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
|
|
|
def temp_num_prefix(self):
|
|
|
|
|
|
|
|
return next(self.fp.extensions.extensions_by_type("temp")).num
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def load_temp_extensions(self):
|
|
|
|
|
|
|
|
current_temp_extension = 0
|
|
|
|
|
|
|
|
used_temp_extensions = self.c.find_users(lambda u: u.num.startswith(self.temp_num_prefix))
|
|
|
|
|
|
|
|
for u in used_temp_extensions:
|
|
|
|
|
|
|
|
temp_num = u.num
|
|
|
|
|
|
|
|
self.fp.temp_extensions[temp_num] = {
|
|
|
|
|
|
|
|
"name": f"Temp {temp_num[4:]}",
|
|
|
|
|
|
|
|
"type": "dect",
|
|
|
|
|
|
|
|
"trunk": False,
|
|
|
|
|
|
|
|
"dialout_allowed": False,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_temp_number(self):
|
|
|
|
def get_temp_number(self):
|
|
|
|
temp_num_prefix = next(self.fp.extensions.extensions_by_type("temp")).num
|
|
|
|
|
|
|
|
current_temp_extension = 0
|
|
|
|
current_temp_extension = 0
|
|
|
|
used_temp_extensions = [u.num[len(temp_num_prefix):] for u in self.c.find_users(lambda u: u.num.startswith(temp_num_prefix))]
|
|
|
|
used_temp_extensions = [num[len(self.temp_num_prefix):] for num, ext in self.fp.temp_extensions.items()]
|
|
|
|
|
|
|
|
|
|
|
|
while "{:0>4}".format(current_temp_extension) in used_temp_extensions:
|
|
|
|
while "{:0>4}".format(current_temp_extension) in used_temp_extensions:
|
|
|
|
current_temp_extension += 1
|
|
|
|
current_temp_extension += 1
|
|
|
|
|
|
|
|
|
|
|
|
return "{}{:0>4}".format(temp_num_prefix, current_temp_extension)
|
|
|
|
return "{}{:0>4}".format(self.temp_num_prefix, current_temp_extension)
|
|
|
|
|
|
|
|
|
|
|
|
def get_sip_password_for_number(self, num):
|
|
|
|
def get_sip_password_for_number(self, num):
|
|
|
|
return num
|
|
|
|
return num
|
|
|
@ -36,10 +52,12 @@ class Dect:
|
|
|
|
self.c.attach_user_device(u.uid, d.ppn)
|
|
|
|
self.c.attach_user_device(u.uid, d.ppn)
|
|
|
|
self.c.set_user_relation_fixed(u.uid)
|
|
|
|
self.c.set_user_relation_fixed(u.uid)
|
|
|
|
self.c.set_user_sipauth(u.uid, num, self.get_sip_password_for_number(num))
|
|
|
|
self.c.set_user_sipauth(u.uid, num, self.get_sip_password_for_number(num))
|
|
|
|
|
|
|
|
return u
|
|
|
|
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
def run(self):
|
|
|
|
logger.info("initialising connection to OMM")
|
|
|
|
logger.info("initialising connection to OMM")
|
|
|
|
self._init_client()
|
|
|
|
self._init_client()
|
|
|
|
|
|
|
|
self.load_temp_extensions()
|
|
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
while True:
|
|
|
|
msg = self.fp.queues["dect"].get()
|
|
|
|
msg = self.fp.queues["dect"].get()
|
|
|
@ -53,6 +71,7 @@ class Dect:
|
|
|
|
extensions = self.fp.extensions.extensions_by_type("dect")
|
|
|
|
extensions = self.fp.extensions.extensions_by_type("dect")
|
|
|
|
extensions_by_num = {e.num: e for e in extensions}
|
|
|
|
extensions_by_num = {e.num: e for e in extensions}
|
|
|
|
extensions_by_ipei = {e._c['dect_ipei']: e for _, e in extensions_by_num.items() if e._c.get('dect_ipei')}
|
|
|
|
extensions_by_ipei = {e._c['dect_ipei']: e for _, e in extensions_by_num.items() if e._c.get('dect_ipei')}
|
|
|
|
|
|
|
|
created_tmp_ext = False
|
|
|
|
|
|
|
|
|
|
|
|
users_by_ext = {}
|
|
|
|
users_by_ext = {}
|
|
|
|
users_by_uid = {}
|
|
|
|
users_by_uid = {}
|
|
|
@ -90,15 +109,30 @@ class Dect:
|
|
|
|
ui = users_by_uid.get(d.uid)
|
|
|
|
ui = users_by_uid.get(d.uid)
|
|
|
|
if ui.num != e.num:
|
|
|
|
if ui.num != e.num:
|
|
|
|
logger.debug(f'User for {d} has wrong number')
|
|
|
|
logger.debug(f'User for {d} has wrong number')
|
|
|
|
|
|
|
|
if self.fp.temp_extensions.get(ui.num):
|
|
|
|
|
|
|
|
self.fp.temp_extensions.pop(ui.num)
|
|
|
|
self.c.set_user_num(d.uid, e.num)
|
|
|
|
self.c.set_user_num(d.uid, e.num)
|
|
|
|
self.c.set_user_sipauth(d.uid, e.num, self.get_sip_password_for_number(e.num))
|
|
|
|
self.c.set_user_sipauth(d.uid, e.num, self.get_sip_password_for_number(e.num))
|
|
|
|
|
|
|
|
self.c.set_user_name(user.uid, e._c['name'])
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
logger.debug(f'Creating and binding user for {d}')
|
|
|
|
logger.debug(f'Creating and binding user for {d}')
|
|
|
|
self.create_and_bind_user(d, e.num)
|
|
|
|
user = self.create_and_bind_user(d, e.num)
|
|
|
|
|
|
|
|
self.c.set_user_name(user.uid, e._c['name'])
|
|
|
|
|
|
|
|
|
|
|
|
elif d.relType == mitel_ommclient2.types.PPRelTypeType("Unbound"):
|
|
|
|
elif d.relType == mitel_ommclient2.types.PPRelTypeType("Unbound"):
|
|
|
|
temp_num = self.get_temp_number()
|
|
|
|
temp_num = self.get_temp_number()
|
|
|
|
logger.debug(f'Creating and binding tmp-user for {d}: {temp_num}')
|
|
|
|
logger.debug(f'Creating and binding tmp-user for {d}: {temp_num}')
|
|
|
|
self.create_and_bind_user(d, temp_num)
|
|
|
|
user = self.create_and_bind_user(d, temp_num)
|
|
|
|
|
|
|
|
self.c.set_user_name(user.uid, f"Temp {temp_num[4:]}")
|
|
|
|
|
|
|
|
self.fp.temp_extensions[temp_num] = {
|
|
|
|
|
|
|
|
"name": f"Temp {temp_num[4:]}",
|
|
|
|
|
|
|
|
"type": "dect",
|
|
|
|
|
|
|
|
"trunk": False,
|
|
|
|
|
|
|
|
"dialout_allowed": False,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
created_tmp_ext = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if created_tmp_ext:
|
|
|
|
|
|
|
|
self.fp.queues['routing'].put({"type": "sync"})
|
|
|
|
|
|
|
|
|
|
|
|
self.c.connection.close()
|
|
|
|
self.c.connection.close()
|
|
|
|