Compare commits
No commits in common. "ee5bc790ead40c2c0a1547035f520ffa9d660706" and "82378e0bd72b207d219208ed7025cd8350ac2abf" have entirely different histories.
ee5bc790ea
...
82378e0bd7
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,2 @@
|
||||
__pycache__
|
||||
dist/
|
||||
docs/_build
|
||||
|
@ -1,12 +1,5 @@
|
||||
#!/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 . import exceptions
|
||||
from . import messages
|
||||
@ -154,53 +147,6 @@ class OMMClient2:
|
||||
d = self.get_device(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):
|
||||
"""
|
||||
@ -379,12 +325,12 @@ class OMMClient2:
|
||||
|
||||
:param uid: User id
|
||||
:param sipAuthId: SIP user name
|
||||
:param sipPw: Plain text password
|
||||
:param sipPw: Encrypted sip password
|
||||
"""
|
||||
t = types.PPUserType()
|
||||
t.uid = uid
|
||||
t.sipAuthId = sipAuthId
|
||||
t.sipPw = self.encrypt(sipPw)
|
||||
t.sipPw = sipPw
|
||||
m = messages.SetPPUser()
|
||||
m.childs.user = [t]
|
||||
r = self.connection.request(m)
|
||||
|
@ -55,11 +55,8 @@ class Connection:
|
||||
if select.select([self._socket], [], []) != ([], [], []):
|
||||
# wait for data availiable
|
||||
while True:
|
||||
try:
|
||||
# fill buffer with one message
|
||||
data = self._socket.recv(1024)
|
||||
except BlockingIOError:
|
||||
continue
|
||||
# fill buffer with one message
|
||||
data = self._socket.recv(1024)
|
||||
|
||||
if not data:
|
||||
# buffer is empty
|
||||
|
@ -72,9 +72,6 @@ class EnumType:
|
||||
def __repr__(self):
|
||||
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):
|
||||
VALUES = [
|
||||
|
25
ommcli
25
ommcli
@ -6,9 +6,16 @@ from mitel_ommclient2.messages import GetAccount, Ping
|
||||
import time
|
||||
|
||||
import argparse
|
||||
import base64
|
||||
import getpass
|
||||
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
|
||||
def error_instead_exit(self, message):
|
||||
raise argparse.ArgumentError(None, message)
|
||||
@ -43,6 +50,16 @@ if __name__ == "__main__":
|
||||
|
||||
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)
|
||||
subparsers = parser.add_subparsers()
|
||||
|
||||
@ -58,6 +75,10 @@ if __name__ == "__main__":
|
||||
|
||||
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.set_defaults(func=exit)
|
||||
|
||||
@ -83,10 +104,6 @@ if __name__ == "__main__":
|
||||
"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={
|
||||
"id": int,
|
||||
})
|
||||
|
@ -1,27 +0,0 @@
|
||||
[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