Compare commits
5 Commits
82378e0bd7
...
ee5bc790ea
Author | SHA1 | Date | |
---|---|---|---|
ee5bc790ea | |||
f8c215d380 | |||
0df5286c0e | |||
000a00fec8 | |||
405f71f621 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
__pycache__
|
__pycache__
|
||||||
|
dist/
|
||||||
docs/_build
|
docs/_build
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import base64
|
||||||
|
try:
|
||||||
|
# This is is only dependency not from the modules inlcuded in python by default, so we make it optional
|
||||||
|
import rsa
|
||||||
|
except ImportError:
|
||||||
|
rsa = None
|
||||||
|
|
||||||
from .connection import Connection
|
from .connection import Connection
|
||||||
from . import exceptions
|
from . import exceptions
|
||||||
from . import messages
|
from . import messages
|
||||||
@ -147,6 +154,53 @@ class OMMClient2:
|
|||||||
d = self.get_device(ppn)
|
d = self.get_device(ppn)
|
||||||
return self.detach_user_device(d.uid, ppn)
|
return self.detach_user_device(d.uid, ppn)
|
||||||
|
|
||||||
|
def encrypt(self, secret):
|
||||||
|
"""
|
||||||
|
Encrypt secret for OMM
|
||||||
|
|
||||||
|
Required rsa module to be installed
|
||||||
|
|
||||||
|
:param secret: String to encrypt
|
||||||
|
"""
|
||||||
|
|
||||||
|
if rsa is None:
|
||||||
|
raise Exception("rsa module is required for excryption")
|
||||||
|
publickey = self.get_publickey()
|
||||||
|
pubkey = rsa.PublicKey(*publickey)
|
||||||
|
byte_secret = secret.encode('utf8')
|
||||||
|
byte_encrypt = rsa.encrypt(byte_secret, pubkey)
|
||||||
|
encrypt = base64.b64encode(byte_encrypt).decode("utf8")
|
||||||
|
return encrypt
|
||||||
|
|
||||||
|
def find_devices(self, filter):
|
||||||
|
"""
|
||||||
|
Get all devices matching a filter
|
||||||
|
|
||||||
|
:param filter: function taking one parameter which is a device, returns True to keep, False to discard
|
||||||
|
|
||||||
|
Usage::
|
||||||
|
|
||||||
|
>>> c.find_devices(lambda d: d.relType == mitel_ommclient2.types.PPRelTypeType("Unbound"))
|
||||||
|
"""
|
||||||
|
|
||||||
|
for d in self.get_devices():
|
||||||
|
if filter(d):
|
||||||
|
yield d
|
||||||
|
|
||||||
|
def find_users(self, filter):
|
||||||
|
"""
|
||||||
|
Get all users matching a filter
|
||||||
|
|
||||||
|
:param filter: function taking one parameter which is a user, returns True to keep, False to discard
|
||||||
|
|
||||||
|
Usage::
|
||||||
|
|
||||||
|
>>> c.find_users(lambda u: u.num.startswith("9998"))
|
||||||
|
"""
|
||||||
|
|
||||||
|
for u in self.get_users():
|
||||||
|
if filter(u):
|
||||||
|
yield u
|
||||||
|
|
||||||
def get_account(self, id):
|
def get_account(self, id):
|
||||||
"""
|
"""
|
||||||
@ -325,12 +379,12 @@ class OMMClient2:
|
|||||||
|
|
||||||
:param uid: User id
|
:param uid: User id
|
||||||
:param sipAuthId: SIP user name
|
:param sipAuthId: SIP user name
|
||||||
:param sipPw: Encrypted sip password
|
:param sipPw: Plain text password
|
||||||
"""
|
"""
|
||||||
t = types.PPUserType()
|
t = types.PPUserType()
|
||||||
t.uid = uid
|
t.uid = uid
|
||||||
t.sipAuthId = sipAuthId
|
t.sipAuthId = sipAuthId
|
||||||
t.sipPw = sipPw
|
t.sipPw = self.encrypt(sipPw)
|
||||||
m = messages.SetPPUser()
|
m = messages.SetPPUser()
|
||||||
m.childs.user = [t]
|
m.childs.user = [t]
|
||||||
r = self.connection.request(m)
|
r = self.connection.request(m)
|
||||||
|
@ -55,8 +55,11 @@ class Connection:
|
|||||||
if select.select([self._socket], [], []) != ([], [], []):
|
if select.select([self._socket], [], []) != ([], [], []):
|
||||||
# wait for data availiable
|
# wait for data availiable
|
||||||
while True:
|
while True:
|
||||||
|
try:
|
||||||
# fill buffer with one message
|
# fill buffer with one message
|
||||||
data = self._socket.recv(1024)
|
data = self._socket.recv(1024)
|
||||||
|
except BlockingIOError:
|
||||||
|
continue
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
# buffer is empty
|
# buffer is empty
|
||||||
|
@ -72,6 +72,9 @@ class EnumType:
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "{}({})".format(self.__class__.__name__, repr(self.value))
|
return "{}({})".format(self.__class__.__name__, repr(self.value))
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
return isinstance(other, type(self)) and self.value == other.value
|
||||||
|
|
||||||
|
|
||||||
class CallForwardStateType(EnumType):
|
class CallForwardStateType(EnumType):
|
||||||
VALUES = [
|
VALUES = [
|
||||||
|
25
ommcli
25
ommcli
@ -6,16 +6,9 @@ from mitel_ommclient2.messages import GetAccount, Ping
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import base64
|
|
||||||
import getpass
|
import getpass
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
try:
|
|
||||||
# This is is only dependency not from the modules inlcuded in python by default, so we make it optional
|
|
||||||
import rsa
|
|
||||||
except ImportError:
|
|
||||||
rsa = None
|
|
||||||
|
|
||||||
# exit handling with argparse is a bit broken even with exit_on_error=False, so we hack this
|
# exit handling with argparse is a bit broken even with exit_on_error=False, so we hack this
|
||||||
def error_instead_exit(self, message):
|
def error_instead_exit(self, message):
|
||||||
raise argparse.ArgumentError(None, message)
|
raise argparse.ArgumentError(None, message)
|
||||||
@ -50,16 +43,6 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
c = OMMClient2(hostname, username, password, ommsync=ommsync)
|
c = OMMClient2(hostname, username, password, ommsync=ommsync)
|
||||||
|
|
||||||
def encrypt(secret):
|
|
||||||
if rsa is None:
|
|
||||||
raise Exception("rsa module is required for excryption")
|
|
||||||
publickey = c.get_publickey()
|
|
||||||
pubkey = rsa.PublicKey(*publickey)
|
|
||||||
byte_secret = secret.encode('utf8')
|
|
||||||
byte_encrypt = rsa.encrypt(byte_secret, pubkey)
|
|
||||||
encrypt = base64.b64encode(byte_encrypt).decode("utf8")
|
|
||||||
return encrypt
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(prog="ommclient2", add_help=False, exit_on_error=False)
|
parser = argparse.ArgumentParser(prog="ommclient2", add_help=False, exit_on_error=False)
|
||||||
subparsers = parser.add_subparsers()
|
subparsers = parser.add_subparsers()
|
||||||
|
|
||||||
@ -75,10 +58,6 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
return subp
|
return subp
|
||||||
|
|
||||||
parser_get_account = subparsers.add_parser("encrypt")
|
|
||||||
parser_get_account.add_argument("secret")
|
|
||||||
parser_get_account.set_defaults(func=encrypt)
|
|
||||||
|
|
||||||
parser_exit = subparsers.add_parser("exit")
|
parser_exit = subparsers.add_parser("exit")
|
||||||
parser_exit.set_defaults(func=exit)
|
parser_exit.set_defaults(func=exit)
|
||||||
|
|
||||||
@ -104,6 +83,10 @@ if __name__ == "__main__":
|
|||||||
"uid": int,
|
"uid": int,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
parser_get_account = add_parser("encrypt", func=c.encrypt, args={
|
||||||
|
"secret": str,
|
||||||
|
})
|
||||||
|
|
||||||
parser_get_account = add_parser("get_account", func=c.get_account, format=format_child_type, args={
|
parser_get_account = add_parser("get_account", func=c.get_account, format=format_child_type, args={
|
||||||
"id": int,
|
"id": int,
|
||||||
})
|
})
|
||||||
|
27
pyproject.toml
Normal file
27
pyproject.toml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
[build-system]
|
||||||
|
requires = ["hatchling"]
|
||||||
|
build-backend = "hatchling.build"
|
||||||
|
|
||||||
|
[project]
|
||||||
|
name = "mitel_ommclient2"
|
||||||
|
version = "0.0.1"
|
||||||
|
authors = [
|
||||||
|
{ name="clerie", email="hallo@clerie.de" },
|
||||||
|
]
|
||||||
|
description = "Another attempt for a modern client library to the Mitel OM Application XML Interface."
|
||||||
|
readme = "README.md"
|
||||||
|
license = { file="LICENSE" }
|
||||||
|
requires-python = ">=3.7"
|
||||||
|
classifiers = [
|
||||||
|
"Programming Language :: Python :: 3",
|
||||||
|
"License :: OSI Approved :: MIT License",
|
||||||
|
"Operating System :: OS Independent",
|
||||||
|
]
|
||||||
|
|
||||||
|
[project.optional-dependencies]
|
||||||
|
crypt = [
|
||||||
|
"rsa",
|
||||||
|
]
|
||||||
|
|
||||||
|
[project.urls]
|
||||||
|
"Source" = "https://git.clerie.de/clerie/mitel_ommclient2"
|
Loading…
Reference in New Issue
Block a user