somestuff-ucmstuff 0.1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- somestuff_ucmstuff-0.1.3/.gitignore +180 -0
- somestuff_ucmstuff-0.1.3/LICENSE.md +163 -0
- somestuff_ucmstuff-0.1.3/PKG-INFO +240 -0
- somestuff_ucmstuff-0.1.3/README.md +210 -0
- somestuff_ucmstuff-0.1.3/pyproject.toml +53 -0
- somestuff_ucmstuff-0.1.3/somestuff/ucmstuff/README.md +210 -0
- somestuff_ucmstuff-0.1.3/somestuff/ucmstuff/__init__.py +112 -0
- somestuff_ucmstuff-0.1.3/somestuff/ucmstuff/example_router.py +110 -0
- somestuff_ucmstuff-0.1.3/somestuff/ucmstuff/mqtt_bridge.py +327 -0
- somestuff_ucmstuff-0.1.3/somestuff/ucmstuff/py.typed +0 -0
- somestuff_ucmstuff-0.1.3/somestuff/ucmstuff/somestuff-ucm6204-secret.example.yaml +17 -0
- somestuff_ucmstuff-0.1.3/somestuff/ucmstuff/somestuff_ucm6204_deployment.yml +90 -0
- somestuff_ucmstuff-0.1.3/somestuff/ucmstuff/ucm.env.example +59 -0
- somestuff_ucmstuff-0.1.3/somestuff/ucmstuff/ucm6204_api.py +1505 -0
- somestuff_ucmstuff-0.1.3/somestuff/ucmstuff/ucm6204_api_rest.py +428 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**/.gtfs_cache
|
|
2
|
+
/*.local
|
|
3
|
+
.claude
|
|
4
|
+
|
|
5
|
+
/*gguf*
|
|
6
|
+
|
|
7
|
+
/docker-config
|
|
8
|
+
/docker_build_local.log
|
|
9
|
+
|
|
10
|
+
/ms?hit
|
|
11
|
+
*mstest*py
|
|
12
|
+
*_test.py
|
|
13
|
+
/umqtt
|
|
14
|
+
.idea/
|
|
15
|
+
/upydev_.config
|
|
16
|
+
*.local.*
|
|
17
|
+
/scripts/logdir/
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# Byte-compiled / optimized / DLL files
|
|
21
|
+
__pycache__/
|
|
22
|
+
*.py[cod]
|
|
23
|
+
*$py.class
|
|
24
|
+
|
|
25
|
+
# C extensions
|
|
26
|
+
*.so
|
|
27
|
+
|
|
28
|
+
# Distribution / packaging
|
|
29
|
+
.Python
|
|
30
|
+
build/
|
|
31
|
+
develop-eggs/
|
|
32
|
+
dist/
|
|
33
|
+
downloads/
|
|
34
|
+
eggs/
|
|
35
|
+
.eggs/
|
|
36
|
+
lib/
|
|
37
|
+
lib64/
|
|
38
|
+
parts/
|
|
39
|
+
sdist/
|
|
40
|
+
var/
|
|
41
|
+
wheels/
|
|
42
|
+
share/python-wheels/
|
|
43
|
+
*.egg-info/
|
|
44
|
+
.installed.cfg
|
|
45
|
+
*.egg
|
|
46
|
+
MANIFEST
|
|
47
|
+
|
|
48
|
+
# PyInstaller
|
|
49
|
+
# Usually these files are written by a python script from a template
|
|
50
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
51
|
+
*.manifest
|
|
52
|
+
*.spec
|
|
53
|
+
|
|
54
|
+
# Installer logs
|
|
55
|
+
pip-log.txt
|
|
56
|
+
pip-delete-this-directory.txt
|
|
57
|
+
|
|
58
|
+
# Unit test / coverage reports
|
|
59
|
+
htmlcov/
|
|
60
|
+
.tox/
|
|
61
|
+
.nox/
|
|
62
|
+
.coverage
|
|
63
|
+
.coverage.*
|
|
64
|
+
.cache
|
|
65
|
+
nosetests.xml
|
|
66
|
+
coverage.xml
|
|
67
|
+
*.cover
|
|
68
|
+
*.py,cover
|
|
69
|
+
.hypothesis/
|
|
70
|
+
.pytest_cache/
|
|
71
|
+
cover/
|
|
72
|
+
|
|
73
|
+
# Translations
|
|
74
|
+
*.mo
|
|
75
|
+
*.pot
|
|
76
|
+
|
|
77
|
+
# Django stuff:
|
|
78
|
+
*.log
|
|
79
|
+
local_settings.py
|
|
80
|
+
db.sqlite3
|
|
81
|
+
db.sqlite3-journal
|
|
82
|
+
|
|
83
|
+
# Flask stuff:
|
|
84
|
+
instance/
|
|
85
|
+
.webassets-cache
|
|
86
|
+
|
|
87
|
+
# Scrapy stuff:
|
|
88
|
+
.scrapy
|
|
89
|
+
|
|
90
|
+
# Sphinx documentation
|
|
91
|
+
docs/_build/
|
|
92
|
+
|
|
93
|
+
# PyBuilder
|
|
94
|
+
.pybuilder/
|
|
95
|
+
target/
|
|
96
|
+
|
|
97
|
+
# Jupyter Notebook
|
|
98
|
+
.ipynb_checkpoints
|
|
99
|
+
|
|
100
|
+
# IPython
|
|
101
|
+
profile_default/
|
|
102
|
+
ipython_config.py
|
|
103
|
+
|
|
104
|
+
# pyenv
|
|
105
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
106
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
107
|
+
# .python-version
|
|
108
|
+
|
|
109
|
+
# pipenv
|
|
110
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
111
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
112
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
113
|
+
# install all needed dependencies.
|
|
114
|
+
#Pipfile.lock
|
|
115
|
+
|
|
116
|
+
# poetry
|
|
117
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
118
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
119
|
+
# commonly ignored for libraries.
|
|
120
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
121
|
+
#poetry.lock
|
|
122
|
+
|
|
123
|
+
# pdm
|
|
124
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
125
|
+
#pdm.lock
|
|
126
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
127
|
+
# in version control.
|
|
128
|
+
# https://pdm.fming.dev/#use-with-ide
|
|
129
|
+
.pdm.toml
|
|
130
|
+
|
|
131
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
132
|
+
__pypackages__/
|
|
133
|
+
|
|
134
|
+
# Celery stuff
|
|
135
|
+
celerybeat-schedule
|
|
136
|
+
celerybeat.pid
|
|
137
|
+
|
|
138
|
+
# SageMath parsed files
|
|
139
|
+
*.sage.py
|
|
140
|
+
|
|
141
|
+
# Environments
|
|
142
|
+
.env
|
|
143
|
+
.venv
|
|
144
|
+
env/
|
|
145
|
+
venv/
|
|
146
|
+
ENV/
|
|
147
|
+
env.bak/
|
|
148
|
+
venv.bak/
|
|
149
|
+
|
|
150
|
+
# Spyder project settings
|
|
151
|
+
.spyderproject
|
|
152
|
+
.spyproject
|
|
153
|
+
|
|
154
|
+
# Rope project settings
|
|
155
|
+
.ropeproject
|
|
156
|
+
|
|
157
|
+
# mkdocs documentation
|
|
158
|
+
/site
|
|
159
|
+
|
|
160
|
+
# mypy
|
|
161
|
+
.mypy_cache/
|
|
162
|
+
.dmypy.json
|
|
163
|
+
dmypy.json
|
|
164
|
+
|
|
165
|
+
# Pyre type checker
|
|
166
|
+
.pyre/
|
|
167
|
+
|
|
168
|
+
# pytype static type analyzer
|
|
169
|
+
.pytype/
|
|
170
|
+
|
|
171
|
+
# Cython debug symbols
|
|
172
|
+
cython_debug/
|
|
173
|
+
|
|
174
|
+
# PyCharm
|
|
175
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
176
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
177
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
178
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
179
|
+
#.idea/
|
|
180
|
+
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
GNU Lesser General Public License
|
|
2
|
+
=================================
|
|
3
|
+
|
|
4
|
+
_Version 3, 29 June 2007_
|
|
5
|
+
_Copyright © 2007 Free Software Foundation, Inc. <<http://fsf.org/>>_
|
|
6
|
+
|
|
7
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
8
|
+
of this license document, but changing it is not allowed.
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
This version of the GNU Lesser General Public License incorporates
|
|
12
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
13
|
+
License, supplemented by the additional permissions listed below.
|
|
14
|
+
|
|
15
|
+
### 0. Additional Definitions
|
|
16
|
+
|
|
17
|
+
As used herein, “this License” refers to version 3 of the GNU Lesser
|
|
18
|
+
General Public License, and the “GNU GPL” refers to version 3 of the GNU
|
|
19
|
+
General Public License.
|
|
20
|
+
|
|
21
|
+
“The Library” refers to a covered work governed by this License,
|
|
22
|
+
other than an Application or a Combined Work as defined below.
|
|
23
|
+
|
|
24
|
+
An “Application” is any work that makes use of an interface provided
|
|
25
|
+
by the Library, but which is not otherwise based on the Library.
|
|
26
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
27
|
+
of using an interface provided by the Library.
|
|
28
|
+
|
|
29
|
+
A “Combined Work” is a work produced by combining or linking an
|
|
30
|
+
Application with the Library. The particular version of the Library
|
|
31
|
+
with which the Combined Work was made is also called the “Linked
|
|
32
|
+
Version”.
|
|
33
|
+
|
|
34
|
+
The “Minimal Corresponding Source” for a Combined Work means the
|
|
35
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
36
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
37
|
+
based on the Application, and not on the Linked Version.
|
|
38
|
+
|
|
39
|
+
The “Corresponding Application Code” for a Combined Work means the
|
|
40
|
+
object code and/or source code for the Application, including any data
|
|
41
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
42
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
43
|
+
|
|
44
|
+
### 1. Exception to Section 3 of the GNU GPL
|
|
45
|
+
|
|
46
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
47
|
+
without being bound by section 3 of the GNU GPL.
|
|
48
|
+
|
|
49
|
+
### 2. Conveying Modified Versions
|
|
50
|
+
|
|
51
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
52
|
+
facility refers to a function or data to be supplied by an Application
|
|
53
|
+
that uses the facility (other than as an argument passed when the
|
|
54
|
+
facility is invoked), then you may convey a copy of the modified
|
|
55
|
+
version:
|
|
56
|
+
|
|
57
|
+
* **a)** under this License, provided that you make a good faith effort to
|
|
58
|
+
ensure that, in the event an Application does not supply the
|
|
59
|
+
function or data, the facility still operates, and performs
|
|
60
|
+
whatever part of its purpose remains meaningful, or
|
|
61
|
+
|
|
62
|
+
* **b)** under the GNU GPL, with none of the additional permissions of
|
|
63
|
+
this License applicable to that copy.
|
|
64
|
+
|
|
65
|
+
### 3. Object Code Incorporating Material from Library Header Files
|
|
66
|
+
|
|
67
|
+
The object code form of an Application may incorporate material from
|
|
68
|
+
a header file that is part of the Library. You may convey such object
|
|
69
|
+
code under terms of your choice, provided that, if the incorporated
|
|
70
|
+
material is not limited to numerical parameters, data structure
|
|
71
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
72
|
+
(ten or fewer lines in length), you do both of the following:
|
|
73
|
+
|
|
74
|
+
* **a)** Give prominent notice with each copy of the object code that the
|
|
75
|
+
Library is used in it and that the Library and its use are
|
|
76
|
+
covered by this License.
|
|
77
|
+
* **b)** Accompany the object code with a copy of the GNU GPL and this license
|
|
78
|
+
document.
|
|
79
|
+
|
|
80
|
+
### 4. Combined Works
|
|
81
|
+
|
|
82
|
+
You may convey a Combined Work under terms of your choice that,
|
|
83
|
+
taken together, effectively do not restrict modification of the
|
|
84
|
+
portions of the Library contained in the Combined Work and reverse
|
|
85
|
+
engineering for debugging such modifications, if you also do each of
|
|
86
|
+
the following:
|
|
87
|
+
|
|
88
|
+
* **a)** Give prominent notice with each copy of the Combined Work that
|
|
89
|
+
the Library is used in it and that the Library and its use are
|
|
90
|
+
covered by this License.
|
|
91
|
+
|
|
92
|
+
* **b)** Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
93
|
+
document.
|
|
94
|
+
|
|
95
|
+
* **c)** For a Combined Work that displays copyright notices during
|
|
96
|
+
execution, include the copyright notice for the Library among
|
|
97
|
+
these notices, as well as a reference directing the user to the
|
|
98
|
+
copies of the GNU GPL and this license document.
|
|
99
|
+
|
|
100
|
+
* **d)** Do one of the following:
|
|
101
|
+
- **0)** Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
- **1)** Use a suitable shared library mechanism for linking with the
|
|
109
|
+
Library. A suitable mechanism is one that **(a)** uses at run time
|
|
110
|
+
a copy of the Library already present on the user's computer
|
|
111
|
+
system, and **(b)** will operate properly with a modified version
|
|
112
|
+
of the Library that is interface-compatible with the Linked
|
|
113
|
+
Version.
|
|
114
|
+
|
|
115
|
+
* **e)** Provide Installation Information, but only if you would otherwise
|
|
116
|
+
be required to provide such information under section 6 of the
|
|
117
|
+
GNU GPL, and only to the extent that such information is
|
|
118
|
+
necessary to install and execute a modified version of the
|
|
119
|
+
Combined Work produced by recombining or relinking the
|
|
120
|
+
Application with a modified version of the Linked Version. (If
|
|
121
|
+
you use option **4d0**, the Installation Information must accompany
|
|
122
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
123
|
+
Code. If you use option **4d1**, you must provide the Installation
|
|
124
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
125
|
+
for conveying Corresponding Source.)
|
|
126
|
+
|
|
127
|
+
### 5. Combined Libraries
|
|
128
|
+
|
|
129
|
+
You may place library facilities that are a work based on the
|
|
130
|
+
Library side by side in a single library together with other library
|
|
131
|
+
facilities that are not Applications and are not covered by this
|
|
132
|
+
License, and convey such a combined library under terms of your
|
|
133
|
+
choice, if you do both of the following:
|
|
134
|
+
|
|
135
|
+
* **a)** Accompany the combined library with a copy of the same work based
|
|
136
|
+
on the Library, uncombined with any other library facilities,
|
|
137
|
+
conveyed under the terms of this License.
|
|
138
|
+
* **b)** Give prominent notice with the combined library that part of it
|
|
139
|
+
is a work based on the Library, and explaining where to find the
|
|
140
|
+
accompanying uncombined form of the same work.
|
|
141
|
+
|
|
142
|
+
### 6. Revised Versions of the GNU Lesser General Public License
|
|
143
|
+
|
|
144
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
145
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
146
|
+
versions will be similar in spirit to the present version, but may
|
|
147
|
+
differ in detail to address new problems or concerns.
|
|
148
|
+
|
|
149
|
+
Each version is given a distinguishing version number. If the
|
|
150
|
+
Library as you received it specifies that a certain numbered version
|
|
151
|
+
of the GNU Lesser General Public License “or any later version”
|
|
152
|
+
applies to it, you have the option of following the terms and
|
|
153
|
+
conditions either of that published version or of any later version
|
|
154
|
+
published by the Free Software Foundation. If the Library as you
|
|
155
|
+
received it does not specify a version number of the GNU Lesser
|
|
156
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
157
|
+
General Public License ever published by the Free Software Foundation.
|
|
158
|
+
|
|
159
|
+
If the Library as you received it specifies that a proxy can decide
|
|
160
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
161
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
162
|
+
permanent authorization for you to choose that version for the
|
|
163
|
+
Library.
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: somestuff-ucmstuff
|
|
3
|
+
Version: 0.1.3
|
|
4
|
+
Summary: Grandstream UCM6204 IP-PBX monitor/control: WebSocket call events, HTTPS API client, trunk call router, MQTT bridge
|
|
5
|
+
Project-URL: Homepage, https://github.com/vroomfondel/somestuff
|
|
6
|
+
Project-URL: Repository, https://github.com/vroomfondel/somestuff
|
|
7
|
+
Project-URL: Issues, https://github.com/vroomfondel/somestuff/issues
|
|
8
|
+
Author-email: Henning Thieß <ht@xomox.cc>
|
|
9
|
+
License-File: LICENSE.md
|
|
10
|
+
Keywords: call-routing,grandstream,mqtt,pbx,sip,ucm6204,voip,websocket
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: System Administrators
|
|
13
|
+
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
|
|
14
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Topic :: Communications :: Telephony
|
|
19
|
+
Classifier: Topic :: System :: Monitoring
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Python: >=3.13
|
|
22
|
+
Requires-Dist: loguru>=0.7.3
|
|
23
|
+
Requires-Dist: mqttstuff>=0.0.7
|
|
24
|
+
Requires-Dist: requests>=2.34
|
|
25
|
+
Requires-Dist: tabulate>=0.10
|
|
26
|
+
Requires-Dist: typer>=0.27
|
|
27
|
+
Requires-Dist: urllib3>=2.8
|
|
28
|
+
Requires-Dist: websocket-client>=1.9
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# ucmstuff
|
|
32
|
+
|
|
33
|
+
Monitor and control a **Grandstream UCM6204** IP-PBX from Python: receive real-time
|
|
34
|
+
call events over WebSocket, act on them via the HTTPS API, route incoming trunk
|
|
35
|
+
calls by caller, and optionally bridge everything onto MQTT.
|
|
36
|
+
|
|
37
|
+
The UCM6204 exposes **two separate** interfaces with different session models:
|
|
38
|
+
|
|
39
|
+
| Interface | Purpose | Auth | Client |
|
|
40
|
+
|-------------------------------|--------------------------------------------------------------------------------------------------------|-------------------------------------|------------------|
|
|
41
|
+
| **WebSocket** (`/websockify`) | UCM *pushes* real-time events (`ActiveCallStatus`, `ExtensionStatus`, `PbxStatus`, ...) | **web** user (e.g. `administrator`) | `UCMEventClient` |
|
|
42
|
+
| **HTTPS API** (`/api`) | request/response *control* + queries (`acceptCall`, `refuseCall`, `Hangup`, `dialExtension`, CDR, ...) | **API** user (e.g. `cdrapi`) | `UCM6204` |
|
|
43
|
+
|
|
44
|
+
They are genuinely independent: the API user does **not** work on the WebSocket,
|
|
45
|
+
and the WebSocket does **not** accept HTTPS-API query actions. To both *monitor*
|
|
46
|
+
and *control* calls you run both clients together.
|
|
47
|
+
|
|
48
|
+
## Modules
|
|
49
|
+
|
|
50
|
+
- **`ucm6204_api`** — the core: `UCMEventClient` (WebSocket events, auto-reconnect
|
|
51
|
+
and heartbeat), `UCM6204` (HTTPS-API control), `TrunkCallRouter` / `IncomingCall`
|
|
52
|
+
(route incoming calls on a trunk to a caller-based branch), a `/healthz` server
|
|
53
|
+
for Kubernetes probes, and the Typer CLI (`ucm6204`).
|
|
54
|
+
- **`ucm6204_api_rest`** — `UCM6204Rest`, a subclass adding a named, typed,
|
|
55
|
+
documented method for **every** HTTPS-API action (trunks, routes, IVRs, queues,
|
|
56
|
+
paging, accounts, users, dialing/transfer, ...) on top of the generic `api_call`.
|
|
57
|
+
- **`mqtt_bridge`** — `MqttEventBridge` publishes events and parsed incoming calls
|
|
58
|
+
to MQTT and, optionally, accepts `accept` / `refuse` / `hangup` commands. It is the
|
|
59
|
+
only module that imports `mqttstuff`. Topics (base topic defaults to `ucm6204`),
|
|
60
|
+
all published with `retain=False`:
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
ucm6204/events/<eventname> full notify event as JSON
|
|
64
|
+
ucm6204/calls/<trunk>/incoming parsed IncomingCall as JSON
|
|
65
|
+
ucm6204/calls/<trunk>/ended same call once its leg terminates
|
|
66
|
+
ucm6204/cmd/{accept,refuse,hangup} inbound, payload {"channel": "PJSIP/..."}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`<trunk>` is the call's `inbound_trunk_name`, sanitized for use as a topic segment.
|
|
70
|
+
- **`example_router`** — runnable example wiring `UCMEventClient`, `UCM6204` and
|
|
71
|
+
`TrunkCallRouter` together from environment variables (see Library).
|
|
72
|
+
- **`/healthz`** — served by the CLI on `--health-host` / `--health-port`
|
|
73
|
+
(default `0.0.0.0:8070`); returns `200` with `{"connected": true}` once the
|
|
74
|
+
WebSocket is connected and subscribed, otherwise `503`. The process only makes
|
|
75
|
+
**outbound** connections to the UCM, so no service or ingress is needed.
|
|
76
|
+
|
|
77
|
+
Logging (loguru, with an intercept for stdlib `logging`) and the startup banner are
|
|
78
|
+
shared via `somestuff.ucmstuff`.
|
|
79
|
+
|
|
80
|
+
## Installation
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pip install somestuff-ucmstuff
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`somestuff` is a PEP 420 namespace; the package is imported as
|
|
87
|
+
`somestuff.ucmstuff` and shares the namespace with the other `somestuff-*`
|
|
88
|
+
distributions.
|
|
89
|
+
|
|
90
|
+
### Setup on the UCM
|
|
91
|
+
|
|
92
|
+
1. **API Configuration -> HTTPS API Settings (New)**: enable it, set the API
|
|
93
|
+
username/password, and tick **Call Control** (required for accept/refuse).
|
|
94
|
+
2. Create a **web user** for the WebSocket (a limited one is fine; the API user
|
|
95
|
+
does not work there).
|
|
96
|
+
|
|
97
|
+
Both interfaces negotiate a weak Diffie-Hellman group; the clients lower the
|
|
98
|
+
OpenSSL security level (`@SECLEVEL=1`) automatically so the handshake succeeds.
|
|
99
|
+
|
|
100
|
+
## Usage
|
|
101
|
+
|
|
102
|
+
The console script and module invocation are equivalent:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
ucm6204 \
|
|
106
|
+
--host ucm.example.lan --port 8089 \
|
|
107
|
+
--web-user webuser --web-password '...' \
|
|
108
|
+
--api-user cdrapi --api-password '...' \
|
|
109
|
+
--trunk MyTrunk --trunk AnotherTrunk # repeatable; omit for monitor-only
|
|
110
|
+
|
|
111
|
+
python3 -m somestuff.ucmstuff.ucm6204_api --host ucm.example.lan --web-user webuser --web-password '...' -v
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Every event is logged; `--trunk` attaches a `TrunkCallRouter` and logs incoming
|
|
115
|
+
calls on those trunks. Add your own branching in code (see Library).
|
|
116
|
+
|
|
117
|
+
Options:
|
|
118
|
+
|
|
119
|
+
| Option | Default | Meaning |
|
|
120
|
+
|-------------------------------------------------------------------------------------------|----------------------------------------------|-----------------------------------------------------------------|
|
|
121
|
+
| `--host`, `--web-user`, `--web-password` | required | UCM address and web-user credentials for the WebSocket |
|
|
122
|
+
| `--api-user`, `--api-password` | empty | API-user credentials; empty disables control actions |
|
|
123
|
+
| `--port` | `8089` | HTTPS-API / WebSocket port |
|
|
124
|
+
| `--events` | `ActiveCallStatus,ExtensionStatus,PbxStatus` | comma-separated event names to subscribe to |
|
|
125
|
+
| `--trunk` | none | inbound trunk to route calls for; repeatable |
|
|
126
|
+
| `--health-host`, `--health-port` | `0.0.0.0`, `8070` | bind address and port of the `/healthz` server |
|
|
127
|
+
| `--mqtt` / `--no-mqtt` | off | enable the MQTT bridge |
|
|
128
|
+
| `--mqtt-host`, `--mqtt-port` | empty, `1883` | broker (host required with `--mqtt`) |
|
|
129
|
+
| `--mqtt-user`, `--mqtt-password` | empty | broker credentials; empty user = anonymous |
|
|
130
|
+
| `--mqtt-base-topic` | `ucm6204` | root of the topic tree |
|
|
131
|
+
| `--mqtt-commands` | off | accept commands on `<base>/cmd/#` (requires `--api-user`) |
|
|
132
|
+
| `--mqtt-tls`, `--mqtt-tls-ca`, `--mqtt-tls-cert`, `--mqtt-tls-key`, `--mqtt-tls-insecure` | off, empty | broker TLS, CA, mutual-TLS client cert/key, skip hostname check |
|
|
133
|
+
| `-v`, `--verbose` | off | debug logging |
|
|
134
|
+
|
|
135
|
+
`ucm6204 --help` shows the exact flag forms.
|
|
136
|
+
|
|
137
|
+
## Configuration
|
|
138
|
+
|
|
139
|
+
The CLI takes UCM connection settings only as flags; the `--mqtt*` options also
|
|
140
|
+
read environment variables. `example_router` reads the connection settings from
|
|
141
|
+
the environment. Boolean variables accept `true|false` (`1|0` works as well).
|
|
142
|
+
|
|
143
|
+
| Variable | Read by | Meaning |
|
|
144
|
+
|-----------------------------------------|------------------|------------------------------------------------------------------------------------------------------|
|
|
145
|
+
| `UCM_HOST` | `example_router` | UCM address (required) |
|
|
146
|
+
| `UCM_PORT` | `example_router` | HTTPS-API / WebSocket port, default `8089` |
|
|
147
|
+
| `UCM_API_USER`, `UCM_API_PASSWORD` | `example_router` | API user for control actions (needs "HTTPS API" + "Call Control") |
|
|
148
|
+
| `UCM_WEB_USER`, `UCM_WEB_PASSWORD` | `example_router` | web user for the WebSocket event stream |
|
|
149
|
+
| `UCM_TRUNKS` | `example_router` | space-separated inbound trunk names; empty = monitor only |
|
|
150
|
+
| `UCM_MQTT_ENABLE` | CLI (`--mqtt`) | enable the MQTT bridge, default off |
|
|
151
|
+
| `UCM_MQTT_HOST`, `UCM_MQTT_PORT` | CLI | broker, default port `1883` |
|
|
152
|
+
| `UCM_MQTT_USER`, `UCM_MQTT_PASSWORD` | CLI | broker credentials |
|
|
153
|
+
| `UCM_MQTT_BASE_TOPIC` | CLI | topic root, default `ucm6204` |
|
|
154
|
+
| `UCM_MQTT_COMMANDS` | CLI | accept accept/refuse/hangup on `<base>/cmd/#` (needs an API user) |
|
|
155
|
+
| `UCM_MQTT_TLS` | CLI | TLS to the broker; the port is not switched, set `UCM_MQTT_PORT` (usually `8883`) |
|
|
156
|
+
| `UCM_MQTT_TLS_CA` | CLI | CA certificate path; empty = system CA store |
|
|
157
|
+
| `UCM_MQTT_TLS_CERT`, `UCM_MQTT_TLS_KEY` | CLI | client certificate and key for mutual TLS (both or neither) |
|
|
158
|
+
| `UCM_MQTT_TLS_INSECURE` | CLI | skip hostname verification (self-signed); still encrypted but MITM-able, chain verification stays on |
|
|
159
|
+
|
|
160
|
+
There is no env-file loader: put the variables in a file of your own, for example
|
|
161
|
+
`ucm.local.env`, and export them into the shell before starting:
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
set -a; . ./ucm.local.env; set +a
|
|
165
|
+
python3 -m somestuff.ucmstuff.example_router
|
|
166
|
+
ucm6204 --host "$UCM_HOST" --port "$UCM_PORT" --web-user "$UCM_WEB_USER" --web-password "$UCM_WEB_PASSWORD" \
|
|
167
|
+
--api-user "$UCM_API_USER" --api-password "$UCM_API_PASSWORD"
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
The repository additionally contains `ucm.env.example`, a Kubernetes secret example
|
|
171
|
+
and `somestuff_ucm6204_deployment.yml` (one pod = events + control, `/healthz`
|
|
172
|
+
backing the liveness/readiness probes); they are not part of the installed package:
|
|
173
|
+
https://github.com/vroomfondel/somestuff/tree/main/somestuff/ucmstuff/
|
|
174
|
+
|
|
175
|
+
Keep real credentials in `*.local.*` files that are not committed.
|
|
176
|
+
|
|
177
|
+
## Library
|
|
178
|
+
|
|
179
|
+
Coordinated monitor + control, as in `example_router`:
|
|
180
|
+
|
|
181
|
+
```python
|
|
182
|
+
from somestuff.ucmstuff.ucm6204_api import UCM6204, UCMEventClient, TrunkCallRouter, IncomingCall
|
|
183
|
+
|
|
184
|
+
api = UCM6204(host="ucm.example.lan", api_user="cdrapi", api_password="...")
|
|
185
|
+
api.connect()
|
|
186
|
+
|
|
187
|
+
events = UCMEventClient(host="ucm.example.lan", web_user="webuser", web_password="...")
|
|
188
|
+
|
|
189
|
+
def route(call: IncomingCall) -> None:
|
|
190
|
+
if call.number == "+491234567":
|
|
191
|
+
api.accept_call(call.channel)
|
|
192
|
+
elif call.name.upper().startswith("SPAM"):
|
|
193
|
+
api.refuse_call(call.channel)
|
|
194
|
+
|
|
195
|
+
events.add_event_handler(TrunkCallRouter("MyTrunk", on_call=route).handle)
|
|
196
|
+
events.run(block=True)
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Full API access:
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
from somestuff.ucmstuff.ucm6204_api_rest import UCM6204Rest
|
|
203
|
+
|
|
204
|
+
ucm = UCM6204Rest(host="ucm.example.lan", api_user="cdrapi", api_password="...")
|
|
205
|
+
ucm.connect()
|
|
206
|
+
for t in ucm.list_voip_trunks():
|
|
207
|
+
print(t["trunk_name"], ucm.get_sip_trunk(trunk=str(t["trunk_index"]))["status"])
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## Grandstream documentation (and what is outdated)
|
|
211
|
+
|
|
212
|
+
Grandstream's UCM API docs are inconsistent across firmware generations, and the
|
|
213
|
+
widely-linked PDF describes an event mechanism this firmware no longer uses:
|
|
214
|
+
|
|
215
|
+
- **Outdated: the `url` report-push model.** The UCM6xxx HTTPS API Guide (PDF)
|
|
216
|
+
documents a `url` parameter on the `login` action: the UCM is supposed to *POST*
|
|
217
|
+
"system reports and call reports" to that HTTP URL. On current UCM6204 firmware
|
|
218
|
+
the `url` is still **accepted and stored**, but **nothing is POSTed to it** for
|
|
219
|
+
call events; it is a dead legacy field.
|
|
220
|
+
- **Actual: the WebSocket model.** Real-time events arrive over a **WebSocket**
|
|
221
|
+
(`wss://<host>:<port>/websockify`): the client connects and performs a JSON
|
|
222
|
+
`challenge` -> `login` -> `subscribe` handshake, then receives `notify` frames.
|
|
223
|
+
This is a *separate* session from the HTTPS API, and it authenticates with a
|
|
224
|
+
**web** user, not the API user.
|
|
225
|
+
|
|
226
|
+
`UCMEventClient` implements the WebSocket model; the `url`-POST model is
|
|
227
|
+
intentionally not used. `UCM6204` / `UCM6204Rest` implement the request/response
|
|
228
|
+
HTTPS API from the same guide, which is still current.
|
|
229
|
+
|
|
230
|
+
- HTTPS API knowledge base: https://documentation.grandstream.com/knowledge-base/https-api
|
|
231
|
+
- UCM6xxx HTTPS API Guide (PDF): https://www.grandstream.com/hubfs/Product_Documentation/UCM_API_Guide.pdf
|
|
232
|
+
|
|
233
|
+
## Notes
|
|
234
|
+
|
|
235
|
+
- **`inbound_trunk_name` is not `trunk_name`**: the trunk name in an `ActiveCallStatus`
|
|
236
|
+
event can differ from the configured name in `listVoIPTrunk`. Verify against a
|
|
237
|
+
real call (every event is logged) and set `UCM_TRUNKS` / `--trunk` accordingly.
|
|
238
|
+
- Requires: `loguru`, `typer`, `requests`, `urllib3`, `websocket-client`, `tabulate`,
|
|
239
|
+
`mqttstuff`. Linux only.
|
|
240
|
+
- Licensed under the LGPL, see `LICENSE.md` in the repository root.
|