ser2netweb 3.0.0__tar.gz → 3.1.0__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.
Files changed (138) hide show
  1. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/PKG-INFO +17 -20
  2. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/THIRD-PARTY-NOTICES.md +8 -0
  3. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/pyproject.toml +38 -28
  4. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/__init__.py +1 -1
  5. ser2netweb-3.1.0/ser2netweb/capture.py +189 -0
  6. ser2netweb-3.1.0/ser2netweb/certwatch.py +259 -0
  7. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/cli.py +19 -10
  8. ser2netweb-3.1.0/ser2netweb/clockwatch.py +158 -0
  9. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/config.py +632 -18
  10. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/console.py +3 -3
  11. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/engine/access.py +34 -9
  12. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/engine/bridge.py +569 -92
  13. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/engine/modbus_gateway.py +357 -11
  14. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/engine/mqtt_pub.py +189 -37
  15. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/engine/netguard.py +1 -1
  16. ser2netweb-3.1.0/ser2netweb/engine/pool.py +217 -0
  17. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/engine/serial_compat.py +53 -7
  18. ser2netweb-3.1.0/ser2netweb/engine/serial_transport.py +527 -0
  19. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/engine/sparkplug_node.py +26 -3
  20. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/engine/supervisor.py +56 -1
  21. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/importer.py +28 -6
  22. ser2netweb-3.1.0/ser2netweb/layout.py +295 -0
  23. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/licences.py +1 -1
  24. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/locale/tr.json +176 -4
  25. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/notify.py +97 -23
  26. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/optional.py +28 -0
  27. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/reload.py +1 -0
  28. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/runtime.py +15 -8
  29. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/ser2net_import.py +364 -41
  30. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/state.py +23 -1
  31. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/api.py +453 -19
  32. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/routes/cluster.py +7 -6
  33. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/routes/forms.py +99 -11
  34. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/routes/login.py +1 -1
  35. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/routes/mappings.py +118 -20
  36. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/routes/ops.py +62 -5
  37. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/routes/settings.py +76 -3
  38. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/routes/system.py +16 -0
  39. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/routes/totp.py +1 -1
  40. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/server.py +5 -3
  41. ser2netweb-3.1.0/ser2netweb/web/starlette_compat.py +210 -0
  42. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/static/app.js +47 -0
  43. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/static/points.js +38 -8
  44. ser2netweb-3.1.0/ser2netweb/web/static/xterm-addon-fit.js +2 -0
  45. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/static/xterm.css +71 -4
  46. ser2netweb-3.1.0/ser2netweb/web/static/xterm.js +2 -0
  47. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/templates/_mapping_form.html +82 -1
  48. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/templates/_mapping_traces.html +14 -0
  49. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/templates/_mappings_body.html +15 -3
  50. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/templates/settings.html +49 -1
  51. ser2netweb-3.1.0/ser2netweb/web/tlsupload.py +250 -0
  52. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb.egg-info/PKG-INFO +17 -20
  53. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb.egg-info/SOURCES.txt +7 -0
  54. ser2netweb-3.1.0/ser2netweb.egg-info/requires.txt +29 -0
  55. ser2netweb-3.0.0/ser2netweb/layout.py +0 -118
  56. ser2netweb-3.0.0/ser2netweb/web/static/xterm-addon-fit.js +0 -2
  57. ser2netweb-3.0.0/ser2netweb/web/static/xterm.js +0 -2
  58. ser2netweb-3.0.0/ser2netweb.egg-info/requires.txt +0 -34
  59. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/COMMERCIAL_LICENSE.md +0 -0
  60. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/LICENSE +0 -0
  61. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/MANIFEST.in +0 -0
  62. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/NOTICE +0 -0
  63. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/packaging/README.pypi.md +0 -0
  64. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/__main__.py +0 -0
  65. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/accounts.py +0 -0
  66. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/clock.py +0 -0
  67. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/datalock.py +0 -0
  68. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/engine/__init__.py +0 -0
  69. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/engine/bindhint.py +0 -0
  70. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/engine/cluster.py +0 -0
  71. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/engine/modbus.py +0 -0
  72. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/engine/netinfo.py +0 -0
  73. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/engine/portdiag.py +0 -0
  74. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/engine/portlist.py +0 -0
  75. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/engine/protocols/__init__.py +0 -0
  76. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/engine/protocols/base.py +0 -0
  77. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/engine/protocols/raw.py +0 -0
  78. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/engine/protocols/rfc2217.py +0 -0
  79. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/engine/protocols/telnet.py +0 -0
  80. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/engine/serial_io.py +0 -0
  81. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/engine/serial_link.py +0 -0
  82. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/engine/sockopts.py +0 -0
  83. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/engine/sparkplug.py +0 -0
  84. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/engine/tls.py +0 -0
  85. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/envvars.py +0 -0
  86. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/explain.py +0 -0
  87. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/healthcheck.py +0 -0
  88. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/i18n.py +0 -0
  89. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/logsetup.py +0 -0
  90. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/logtext.py +0 -0
  91. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/sdnotify.py +0 -0
  92. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/signins.py +0 -0
  93. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/standalone.py +0 -0
  94. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/storage.py +0 -0
  95. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/textfold.py +0 -0
  96. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/tlsreload.py +0 -0
  97. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/watchdog.py +0 -0
  98. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/__init__.py +0 -0
  99. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/auth.py +0 -0
  100. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/certinfo.py +0 -0
  101. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/httpguard.py +0 -0
  102. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/ldap_auth.py +0 -0
  103. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/oidc_auth.py +0 -0
  104. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/proxy.py +0 -0
  105. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/routes/__init__.py +0 -0
  106. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/routes/common.py +0 -0
  107. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/routes/console.py +0 -0
  108. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/selfsigned.py +0 -0
  109. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/static/app.css +0 -0
  110. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/static/htmx.min.js +0 -0
  111. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/static/theme.js +0 -0
  112. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/templates/_cluster_body.html +0 -0
  113. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/templates/_console.html +0 -0
  114. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/templates/_footer.html +0 -0
  115. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/templates/_login_notice.html +0 -0
  116. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/templates/_macros.html +0 -0
  117. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/templates/_mapping_log.html +0 -0
  118. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/templates/_modbus_read.html +0 -0
  119. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/templates/_ports_table.html +0 -0
  120. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/templates/_serial_port_select.html +0 -0
  121. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/templates/_shell.html +0 -0
  122. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/templates/audit.html +0 -0
  123. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/templates/base.html +0 -0
  124. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/templates/dashboard.html +0 -0
  125. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/templates/licenses.html +0 -0
  126. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/templates/login.html +0 -0
  127. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/templates/login_totp.html +0 -0
  128. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/templates/setup.html +0 -0
  129. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/templates/totp.html +0 -0
  130. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/web/totp.py +0 -0
  131. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb/winservice.py +0 -0
  132. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb.egg-info/dependency_links.txt +0 -0
  133. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb.egg-info/entry_points.txt +0 -0
  134. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/ser2netweb.egg-info/top_level.txt +0 -0
  135. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/setup.cfg +0 -0
  136. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/tools/licenses/npm/htmx.org.txt +0 -0
  137. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/tools/licenses/npm/xterm-addon-fit.txt +0 -0
  138. {ser2netweb-3.0.0 → ser2netweb-3.1.0}/tools/licenses/npm/xterm.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ser2netweb
3
- Version: 3.0.0
3
+ Version: 3.1.0
4
4
  Summary: Serial-to-network bridge with a web UI: raw TCP, telnet, RFC 2217, UDP, Modbus gateway, MQTT
5
5
  Author-email: Halis KILIÇ <mail@haliskilic.com.tr>
6
6
  License-Expression: AGPL-3.0-only
@@ -38,29 +38,26 @@ License-File: THIRD-PARTY-NOTICES.md
38
38
  License-File: tools/licenses/npm/htmx.org.txt
39
39
  License-File: tools/licenses/npm/xterm-addon-fit.txt
40
40
  License-File: tools/licenses/npm/xterm.txt
41
- Requires-Dist: pyserial<4,>=3.5
42
- Requires-Dist: pyserial-asyncio-fast<0.17,>=0.16
43
- Requires-Dist: starlette<2,>=1.10.0; python_version >= "3.11"
44
- Requires-Dist: starlette<2,>=1.7.0; python_version < "3.11"
45
- Requires-Dist: uvicorn<0.55,>=0.54.0
46
- Requires-Dist: h11<0.17,>=0.16.0
47
- Requires-Dist: websockets<18,>=17.4; python_version >= "3.11"
48
- Requires-Dist: websockets<17,>=16.1.1; python_version < "3.11"
49
- Requires-Dist: python-multipart<0.1,>=0.0.33; python_version >= "3.11"
50
- Requires-Dist: python-multipart<0.1,>=0.0.32; python_version < "3.11"
51
- Requires-Dist: jinja2<4,>=3.1.6
52
- Requires-Dist: markupsafe<4,>=3.0.4
53
- Requires-Dist: psutil<8,>=7.2.2
54
- Requires-Dist: exceptiongroup<2,>=1.3.1; python_version < "3.11"
55
- Requires-Dist: taskgroup<0.3,>=0.2.2; python_version < "3.11"
41
+ Requires-Dist: pyserial>=3.5
42
+ Requires-Dist: pyserial-asyncio-fast>=0.16
43
+ Requires-Dist: starlette>=0.46.1
44
+ Requires-Dist: uvicorn>=0.32.0
45
+ Requires-Dist: h11>=0.14.0
46
+ Requires-Dist: websockets>=14.2
47
+ Requires-Dist: python-multipart>=0.0.20
48
+ Requires-Dist: jinja2>=3.1.6
49
+ Requires-Dist: markupsafe>=2.1.3
50
+ Requires-Dist: psutil>=5.9.8
51
+ Requires-Dist: exceptiongroup>=1.2.0; python_version < "3.11"
52
+ Requires-Dist: taskgroup>=0.2.2; python_version < "3.11"
56
53
  Provides-Extra: mqtt
57
- Requires-Dist: paho-mqtt<3,>=1.6; extra == "mqtt"
54
+ Requires-Dist: paho-mqtt>=1.6.1; extra == "mqtt"
58
55
  Provides-Extra: ldap
59
- Requires-Dist: ldap3<3,>=2.9.1; extra == "ldap"
56
+ Requires-Dist: ldap3>=2.9.1; extra == "ldap"
60
57
  Provides-Extra: oidc
61
- Requires-Dist: authlib<2,>=1.9.5; extra == "oidc"
58
+ Requires-Dist: authlib>=1.4.0; extra == "oidc"
62
59
  Provides-Extra: tls
63
- Requires-Dist: cryptography>=50.0.2; extra == "tls"
60
+ Requires-Dist: cryptography>=43.0.0; extra == "tls"
64
61
  Provides-Extra: all
65
62
  Requires-Dist: ser2netweb[ldap,mqtt,oidc,tls]; extra == "all"
66
63
  Dynamic: license-file
@@ -34,6 +34,11 @@ browser libraries below.
34
34
  | exceptiongroup, taskgroup (Python 3.10 only) | MIT |
35
35
  | colorama (Windows only) | BSD-3-Clause |
36
36
 
37
+ Two modules of ser2netweb hold code copied from these, with their BSD-3-Clause notice:
38
+ `ser2netweb/engine/serial_transport.py` (pyserial-asyncio-fast 0.16's `SerialTransport`,
39
+ used where pyserial-asyncio-fast isn't installed) and `ser2netweb/web/starlette_compat.py`
40
+ (Starlette 1.10's request body limit, used with a Starlette older than 1.6).
41
+
37
42
  ## Optional feature packages (`requirements-optional.txt`)
38
43
 
39
44
  Not installed by the offline bootstrap; bundled into the standalone executables and the
@@ -85,6 +90,9 @@ the files and their sha256, and the license texts are in `tools/licenses/npm/` (
85
90
  | xterm.js (`xterm.js`, `xterm.css`) | `@xterm/xterm` | MIT |
86
91
  | xterm.js fit addon (`xterm-addon-fit.js`) | `@xterm/addon-fit` | MIT |
87
92
 
93
+ xterm.js 6 includes parts of Visual Studio Code's base library (its scrollbar and event
94
+ code; Copyright (c) Microsoft Corporation), under the same MIT license.
95
+
88
96
  ## LGPL components
89
97
 
90
98
  ldap3 is an LGPL library. ser2netweb uses it unmodified through its public API. The LGPL
@@ -48,42 +48,50 @@ classifiers = [
48
48
  "Topic :: System :: Hardware",
49
49
  "Topic :: System :: Networking",
50
50
  ]
51
- # The packages ser2netweb imports, from requirements.txt as ranges: at least the pinned
52
- # version (the one every test ran with), below the next release that may break it (the
53
- # next major; for a 0.x package the next minor, 0.0.x: below 0.1). A pin
54
- # that leaves its range fails tests/test_pyproject.py, so the two are bumped together (as
55
- # Dependabot does). Pins of packages only these need (anyio, click, idna,
51
+ # The packages ser2netweb imports, each from the oldest release it works with (the floor),
52
+ # so that a Linux or BSD distribution can build it with the versions it ships
53
+ # (docs/PACKAGING.md: the floors, the distributions' versions and what they lack). No
54
+ # upper bounds: one goes here only for a release known to break ser2netweb (none is). The
55
+ # floors are tested: CI's job "minimum dependencies" installs exactly requirements-min.pins
56
+ # (every floor, and the oldest dependencies of theirs a distribution there ships) on Python
57
+ # 3.10 and runs the whole suite. pip installs the newest release of each; the standalone
58
+ # executables, the Docker image and the test matrix keep to the tested, hash-locked pins
59
+ # (requirements.txt, requirements-lock.txt), and each pin has to be at or above its floor
60
+ # (tests/test_pyproject.py). Packages only these need (anyio, click, idna,
56
61
  # typing_extensions, colorama) come with them. psutil (the network interface lists) has
57
62
  # no pure-Python wheel: where PyPI has no wheel for the machine, pip builds it.
58
63
  dependencies = [
59
- "pyserial>=3.5,<4",
60
- "pyserial-asyncio-fast>=0.16,<0.17", # ser2netweb/engine/serial_compat.py patches it
61
- 'starlette>=1.10.0,<2; python_version >= "3.11"',
62
- 'starlette>=1.7.0,<2; python_version < "3.11"',
63
- "uvicorn>=0.54.0,<0.55", # ser2netweb/web/httpguard.py hooks into its h11 protocol
64
- "h11>=0.16.0,<0.17",
65
- 'websockets>=17.4,<18; python_version >= "3.11"',
66
- 'websockets>=16.1.1,<17; python_version < "3.11"',
67
- 'python-multipart>=0.0.33,<0.1; python_version >= "3.11"',
68
- 'python-multipart>=0.0.32,<0.1; python_version < "3.11"',
69
- "jinja2>=3.1.6,<4",
70
- "markupsafe>=3.0.4,<4",
71
- "psutil>=7.2.2,<8",
72
- 'exceptiongroup>=1.3.1,<2; python_version < "3.11"',
73
- 'taskgroup>=0.2.2,<0.3; python_version < "3.11"',
64
+ "pyserial>=3.5", # the release every distribution ships (2020)
65
+ # not packaged by most distributions: without it ser2netweb runs on its copy of the
66
+ # 0.16 transport (ser2netweb/engine/serial_transport.py), so a package may leave it out
67
+ "pyserial-asyncio-fast>=0.16",
68
+ # Debian 13; ser2netweb/web/starlette_compat.py stands in for the request body limits of
69
+ # Starlette 1.6
70
+ "starlette>=0.46.1",
71
+ # Debian 13; ser2netweb/web/httpguard.py subclasses its h11 protocol, which is the same
72
+ # from there on but for details it doesn't touch
73
+ "uvicorn>=0.32.0",
74
+ "h11>=0.14.0", # Debian 13, Ubuntu 26.04, EPEL 10
75
+ "websockets>=14.2", # RHEL 10 (uvicorn's WebSocket implementation)
76
+ "python-multipart>=0.0.20", # Debian 13, Ubuntu 26.04 (Starlette's form parser)
77
+ "jinja2>=3.1.6", # what every distribution here ships
78
+ "markupsafe>=2.1.3", # RHEL 10
79
+ "psutil>=5.9.8", # RHEL 10, Ubuntu 24.04
80
+ # Python 3.10 only (asyncio.TaskGroup / Runner, exception groups): no distribution here
81
+ # runs 3.10; the oldest release Ubuntu ships, and the one FreeBSD and conda-forge do
82
+ 'exceptiongroup>=1.2.0; python_version < "3.11"',
83
+ 'taskgroup>=0.2.2; python_version < "3.11"',
74
84
  ]
75
85
 
76
86
  # The features that need an optional package (requirements-optional.txt, which the
77
87
  # executables and the image bundle; each feature says what is missing without it):
78
88
  # pipx install "ser2netweb[all]", or pipx inject ser2netweb paho-mqtt
79
- # The same ranges, but cryptography: its major version moves with every release (every
80
- # few months) and its security fixes only come in the newest, so only the pin's floor;
81
- # paho-mqtt from 1.6, as for a source install (CI's job "MQTT with paho-mqtt 1.6").
89
+ # The floors as above (requirements-min.pins has them too); no upper bounds.
82
90
  [project.optional-dependencies]
83
- mqtt = ["paho-mqtt>=1.6,<3"] # MQTT publishing, Sparkplug B
84
- ldap = ["ldap3>=2.9.1,<3"] # LDAP / Active Directory sign-in
85
- oidc = ["authlib>=1.9.5,<2"] # OpenID Connect single sign-on
86
- tls = ["cryptography>=50.0.2"] # self-signed certificates in-process
91
+ mqtt = ["paho-mqtt>=1.6.1"] # MQTT publishing, Sparkplug B (1.x and 2.x)
92
+ ldap = ["ldap3>=2.9.1"] # LDAP / Active Directory sign-in (its last release)
93
+ oidc = ["authlib>=1.4.0"] # OpenID Connect single sign-on (Fedora 43)
94
+ tls = ["cryptography>=43.0.0"] # self-signed certificates in-process (Debian 13)
87
95
  all = ["ser2netweb[mqtt,ldap,oidc,tls]"]
88
96
 
89
97
  [project.scripts]
@@ -107,8 +115,10 @@ include-package-data = false
107
115
  [tool.setuptools.packages.find]
108
116
  include = ["ser2netweb", "ser2netweb.*"]
109
117
 
118
+ # (distro.json: none in this repository or on PyPI; a distribution's recipe in packaging/
119
+ # writes it into ser2netweb/ before the build, ser2netweb/layout.py reads it)
110
120
  [tool.setuptools.package-data]
111
- ser2netweb = ["locale/*", "web/templates/*", "web/static/*"]
121
+ ser2netweb = ["locale/*", "web/templates/*", "web/static/*", "distro.json"]
112
122
 
113
123
  # (named by its file: for "ser2netweb.__version__" setuptools would read ser2netweb.py, the
114
124
  # start script beside the package; it reads the assignment without importing anything)
@@ -1,7 +1,7 @@
1
1
  """ser2netweb — serial-to-network bridge with a web config UI."""
2
2
 
3
3
  # Single source of truth for the version (ser2netweb.py and the web layer import this).
4
- __version__ = "3.0.0"
4
+ __version__ = "3.1.0"
5
5
 
6
6
  # The product's name: up to 2.9.x it was ser2net (no relation to the C ser2net it can
7
7
  # import the configuration of; NOTICE)
@@ -0,0 +1,189 @@
1
+ """Timed captures: trace a mapping's traffic for a while, then stop by itself.
2
+
3
+ An operator starts one in the mapping's Trace panel or with
4
+ POST /api/v1/mappings/{id}/capture (15 minutes, 1 hour, 24 hours; the REST API takes any
5
+ number of minutes up to CAPTURE_MAX_S). The mapping keeps its clients and its serial port:
6
+ only its trace writer is opened, and closed again at the end (Supervisor.retrace).
7
+
8
+ The end time is stored in the mapping's options (trace_until, Unix seconds), so a capture
9
+ goes on after a restart and ends on time; one whose time passed while ser2netweb was not
10
+ running ends before the mappings start. While this process runs the time left is counted
11
+ on the monotonic clock: a step of the system clock neither cuts a capture short nor keeps
12
+ it going. trace_until is no setting: the edits (the form, a REST POST / PUT / PATCH, an
13
+ import, a Copy) keep a mapping's own and give a new one none. However it was set anyway (by
14
+ hand in config.json, a restored backup), a capture never lasts longer than CAPTURE_MAX_S
15
+ from when this process first saw it.
16
+
17
+ Only a mapping whose trace is off can be captured: its traffic goes to
18
+ traces/<id>-capture.log. A mapping that traces already (a trace file name in its
19
+ options) is refused, and the end of a capture only clears trace_until - a trace that is
20
+ on for good is never turned off here.
21
+ """
22
+ from __future__ import annotations
23
+
24
+ import asyncio
25
+ import contextlib
26
+ import time
27
+ from typing import TYPE_CHECKING, Optional
28
+
29
+ from . import clock
30
+ from .config import CAPTURE_MAX_S, ConfigError
31
+
32
+ if TYPE_CHECKING:
33
+ from .state import AppState
34
+
35
+ CHECK_S = 1.0 # how often the ends are looked at
36
+ # what the Trace panel offers, in minutes
37
+ CHOICES_MIN = (15, 60, 24 * 60)
38
+
39
+
40
+ class CaptureRefused(Exception):
41
+ """A capture that can't begin. `code`: "not_found" (no such mapping), "tracing" (its
42
+ trace is on already, by its trace file name) or "duration" (not 1 minute to
43
+ CAPTURE_MAX_S)."""
44
+
45
+ def __init__(self, code: str) -> None:
46
+ super().__init__(code)
47
+ self.code = code
48
+
49
+
50
+ def duration_text(seconds: float) -> str:
51
+ """'15 min', '1 h', '24 h', '1 h 30 min' (English: the log and the audit log)."""
52
+ minutes = max(1, round(seconds / 60))
53
+ hours, rest = divmod(minutes, 60)
54
+ if hours and rest:
55
+ return f"{hours} h {rest} min"
56
+ return f"{hours} h" if hours else f"{rest} min"
57
+
58
+
59
+ class Captures:
60
+ """The timed captures of an AppState's mappings: begin(), end(), and the watcher that
61
+ ends each one at its time."""
62
+
63
+ def __init__(self, state: "AppState") -> None:
64
+ self.state = state
65
+ # mapping id -> (the trace_until it was armed for, when on the monotonic clock, its
66
+ # length in seconds from then): what is left is the length minus the time passed
67
+ # since, so never more than the length (an end stored as start + length, read back
68
+ # as end - now, can round to a hair over it where the clock has not moved yet)
69
+ self._ends: dict[str, tuple[float, float, float]] = {}
70
+ self._task: Optional[asyncio.Task] = None
71
+
72
+ # ---------------- what the pages and the REST API ask ----------------
73
+ def left(self, mapping) -> Optional[float]:
74
+ """The seconds a mapping's capture still runs, None when it has none."""
75
+ until = mapping.options.trace_until
76
+ if not until:
77
+ return None
78
+ start, length = self._arm(mapping.id, until)
79
+ return min(length, max(0.0, length - (time.monotonic() - start)))
80
+
81
+ def until(self, mapping) -> Optional[float]:
82
+ """When a mapping's capture ends as the system clock reads now (Unix seconds),
83
+ None when it has none."""
84
+ left = self.left(mapping)
85
+ return None if left is None else time.time() + left
86
+
87
+ async def begin(self, mapping_id: str, seconds: float) -> float:
88
+ """Capture the mapping's traffic for `seconds` from now (a capture under way gets
89
+ this as its new end). Returns the end (Unix seconds). Raises CaptureRefused, or
90
+ ConfigError when config.json can't be written (nothing changed then)."""
91
+ if not 60 <= seconds <= CAPTURE_MAX_S:
92
+ raise CaptureRefused("duration")
93
+ async with self.state.edit_config(backup=False):
94
+ m = self.state.config.get_mapping(mapping_id)
95
+ if m is None:
96
+ raise CaptureRefused("not_found")
97
+ if m.options.trace_both:
98
+ raise CaptureRefused("tracing")
99
+ until = m.options.trace_until = time.time() + seconds
100
+ self._ends[m.id] = (until, time.monotonic(), float(seconds))
101
+ await self.state.supervisor.retrace(mapping_id)
102
+ return until
103
+
104
+ async def end(self, mapping_id: str, until: Optional[float] = None) -> bool:
105
+ """End the mapping's capture now. Returns whether it had one. Its trace is closed
106
+ (not one that is on by its trace file name) even when config.json can't be
107
+ written: ConfigError is raised then, and the next start ends it for good.
108
+ `until`: the end the watcher found due; a capture begun again meanwhile (another
109
+ end) is left alone, and False returned."""
110
+ try:
111
+ async with self.state.edit_config(backup=False, keep_on_failure=True):
112
+ m = self.state.config.get_mapping(mapping_id)
113
+ if m is None or not m.options.trace_until:
114
+ self._ends.pop(mapping_id, None)
115
+ return False
116
+ if until is not None and m.options.trace_until != until:
117
+ return False # (extended while this waited for the configuration)
118
+ self._ends.pop(mapping_id, None)
119
+ m.options.trace_until = 0.0
120
+ finally:
121
+ await self.state.supervisor.retrace(mapping_id)
122
+ return True
123
+
124
+ # ---------------- the watcher ----------------
125
+ async def end_overdue(self) -> None:
126
+ """Before the mappings start: end the captures whose time passed while ser2netweb
127
+ was not running, so that none of them is traced again."""
128
+ now = time.time()
129
+ for m in list(self.state.config.mappings):
130
+ until = m.options.trace_until
131
+ if until and until <= now:
132
+ await self._expire(m, "its time passed while ser2netweb was not running")
133
+
134
+ async def start(self) -> None:
135
+ self._task = asyncio.create_task(self._watch(), name="capture-watch")
136
+
137
+ async def stop(self) -> None:
138
+ task, self._task = self._task, None
139
+ if task is not None:
140
+ task.cancel()
141
+ with contextlib.suppress(asyncio.CancelledError):
142
+ await task
143
+
144
+ def _arm(self, mapping_id: str, until: float) -> tuple[float, float]:
145
+ """When a capture's time began on the monotonic clock and how long it is: from the
146
+ first time this process sees its trace_until, at most CAPTURE_MAX_S."""
147
+ armed = self._ends.get(mapping_id)
148
+ if armed is None or armed[0] != until:
149
+ length = min(max(until - time.time(), 0.0), float(CAPTURE_MAX_S))
150
+ armed = self._ends[mapping_id] = (until, time.monotonic(), length)
151
+ return armed[1], armed[2]
152
+
153
+ async def check(self) -> None:
154
+ """End the captures whose time has come (the watcher's step)."""
155
+ seen = set()
156
+ for m in list(self.state.config.mappings):
157
+ until = m.options.trace_until
158
+ if not until:
159
+ continue
160
+ seen.add(m.id)
161
+ if not self.left(m):
162
+ await self._expire(m, "")
163
+ for gone in [mid for mid in self._ends if mid not in seen]:
164
+ del self._ends[gone]
165
+
166
+ async def _expire(self, mapping, why: str) -> None:
167
+ name = mapping.name
168
+ try:
169
+ ended = await self.end(mapping.id, until=mapping.options.trace_until)
170
+ except ConfigError as e:
171
+ self.state.log(f"[{name}] timed capture ended, but config.json could not keep "
172
+ f"that ({e}): it ends again at the next start")
173
+ ended = True
174
+ if ended:
175
+ self.state.log(f"[{name}] timed capture ended" + (f": {why}" if why else ""))
176
+ self.state.audit("local", "trace_capture_end", name)
177
+
178
+ async def _watch(self) -> None:
179
+ while True:
180
+ await asyncio.sleep(CHECK_S)
181
+ try:
182
+ await self.check()
183
+ except Exception as e: # never let the watcher die
184
+ self.state.log(f"timed captures: watcher error: {e}")
185
+
186
+
187
+ def describe(until: float, seconds: float) -> str:
188
+ """'15 min, until 2026-11-13 12:15:00+03:00' for the log and the audit log."""
189
+ return f"{duration_text(seconds)}, until {clock.stamp(until)}"
@@ -0,0 +1,259 @@
1
+ """TLS certificates about to end: the admin UI's and each enabled TLS mapping's.
2
+
3
+ Once a day (and once soon after the start) the notifier reads the certificate files in
4
+ use with web/certinfo.py. A certificate that has fewer than 30, 7 or 1 days left, or has
5
+ ended, is logged with a WARNING and — with the optional cert_expiring event on — sent as a
6
+ notification: once per certificate and threshold and channel, also across restarts
7
+ (what was sent is kept in cert-notices.json in the data folder once a channel took it,
8
+ with the channels that did not, which get it at the next check, and only they; what was
9
+ sent for a certificate is kept while it can't be read, while its mapping is disabled or
10
+ the admin UI's TLS is off, and is forgotten when the certificate is renewed (another end
11
+ date at its path) or its mapping is deleted). What was read last is also what /metrics
12
+ (ser2net_tls_certificate_expiry_seconds) and GET /api/v1/status (certificates) answer.
13
+
14
+ Only reads the files; renewing one is the operator's (or certbot's), followed by a reload
15
+ of the configuration or a new upload in Settings.
16
+ """
17
+ from __future__ import annotations
18
+
19
+ import asyncio
20
+ import dataclasses
21
+ import json
22
+ import os
23
+ import threading
24
+ import time
25
+ from typing import Any, Optional
26
+
27
+ from .web import certinfo
28
+
29
+ THRESHOLD_DAYS = (30, 7, 1) # a notification when fewer days than each are left ...
30
+ EXPIRED = 0 # ... and one once the certificate has ended
31
+ CHECK_S = 86400.0 # how often the notifier looks
32
+ FRESH_S = 300.0 # /metrics and the status read the files again after this
33
+ NOTICES_FILE = "cert-notices.json"
34
+ _lock = threading.Lock()
35
+
36
+
37
+ @dataclasses.dataclass
38
+ class Certificate:
39
+ """A certificate file in use. `key`: "admin" or the mapping's id; `mapping`: the
40
+ mapping's name ("" for the admin UI); `info`: what the file says (None: `problem`
41
+ says why it could not be read)."""
42
+ key: str
43
+ mapping: str
44
+ path: str
45
+ info: Optional[certinfo.CertInfo] = None
46
+ problem: str = ""
47
+
48
+ @property
49
+ def label(self) -> str:
50
+ """Whose it is, for the log and the message (English)."""
51
+ return f"mapping {self.mapping!r}" if self.mapping else "admin UI"
52
+
53
+ def view(self, now: Optional[float] = None) -> dict[str, Any]:
54
+ """As GET /api/v1/status lists it."""
55
+ out: dict[str, Any] = {"use": "mapping" if self.mapping else "admin", "path": self.path}
56
+ if self.mapping:
57
+ out.update(id=self.key, mapping=self.mapping)
58
+ if self.info is None:
59
+ return {**out, "state": "unreadable", "detail": self.problem}
60
+ return {**out, "subject": self.info.subject, "not_after": self.info.not_after,
61
+ "days_left": self.info.days_left(now), "state": self.info.state(now)}
62
+
63
+
64
+ def in_use(config) -> list[Certificate]:
65
+ """The certificate files the configuration uses now: the admin UI's (when its TLS is
66
+ on) and each enabled TLS mapping's (a listener's certificate, or the client
67
+ certificate of a connect-out mapping)."""
68
+ out = []
69
+ admin = config.admin_ui
70
+ if admin.tls_enabled:
71
+ out.append(Certificate("admin", "", admin.tls_cert))
72
+ for m in config.mappings:
73
+ net = m.network
74
+ if m.enabled and m.kind == "net" and net.tls and net.mode != "udp" and net.tls_cert:
75
+ out.append(Certificate(m.id, m.name, net.tls_cert))
76
+ return out
77
+
78
+
79
+ def read_all(certificates: list[Certificate]) -> list[Certificate]:
80
+ """Read each certificate's file (blocking)."""
81
+ for c in certificates:
82
+ try:
83
+ c.info = certinfo.read(c.path)
84
+ except certinfo.CertReadError as e:
85
+ c.problem = "no PEM certificate in it" if e.code == "not_pem" else str(e)
86
+ return certificates
87
+
88
+
89
+ def threshold(info: certinfo.CertInfo, now: float) -> Optional[int]:
90
+ """The tightest threshold the certificate is past: EXPIRED, else the smallest of
91
+ THRESHOLD_DAYS it has fewer days left than; None while it has more than them all."""
92
+ left = info.not_after - now
93
+ if left < 0:
94
+ return EXPIRED
95
+ reached = [d for d in THRESHOLD_DAYS if left < d * 86400]
96
+ return min(reached) if reached else None
97
+
98
+
99
+ def message(c: Certificate, info: certinfo.CertInfo, now: float) -> str:
100
+ """The notification's detail and the log line: whose certificate, which file, what it
101
+ says."""
102
+ return f"{c.label} certificate {c.path}: {info.describe(now)}"
103
+
104
+
105
+ def load_notices(path: str) -> dict[str, list]:
106
+ """What was sent already: "<key>|<path>" -> [not_after, threshold], and a third item,
107
+ the channels that did not take that threshold's notice yet (notify.CHANNELS), when
108
+ there are any. {} when the file is missing or makes no sense (everything is then
109
+ sent once more); an entry that makes no sense is left out."""
110
+ try:
111
+ with open(path, encoding="utf-8") as fh:
112
+ data = json.load(fh)
113
+ except (OSError, ValueError):
114
+ return {}
115
+ if not isinstance(data, dict):
116
+ return {}
117
+ return {k: v for k, v in data.items() if _record(v)}
118
+
119
+
120
+ def _record(v: Any) -> bool:
121
+ return (isinstance(v, list) and len(v) in (2, 3)
122
+ and all(isinstance(x, (int, float)) and not isinstance(x, bool) for x in v[:2])
123
+ and (len(v) == 2 or isinstance(v[2], list)
124
+ and all(isinstance(c, str) for c in v[2])))
125
+
126
+
127
+ def kept_unused(notices: dict[str, list], used: set[str], config) -> dict[str, list]:
128
+ """The records ("<key>|<path>") of certificates not in use now that stay: a disabled
129
+ mapping's, the admin UI's with its TLS off, one a mapping no longer names. Forgotten
130
+ are those of a deleted mapping and those whose file now holds another certificate
131
+ (renewed: another end date); one that can't be read stays. Blocking (reads them)."""
132
+ out = {}
133
+ for name, record in notices.items():
134
+ if name in used:
135
+ continue
136
+ key, _sep, path = name.partition("|")
137
+ if key != "admin" and config.get_mapping(key) is None:
138
+ continue
139
+ try:
140
+ if certinfo.read(path).not_after != record[0]:
141
+ continue
142
+ except certinfo.CertReadError:
143
+ pass
144
+ out[name] = record
145
+ return out
146
+
147
+
148
+ def save_notices(path: str, notices: dict[str, list]) -> None:
149
+ """Rewrite the file whole (a temporary file renamed over it). Raises OSError."""
150
+ with _lock:
151
+ _write_notices(path, notices)
152
+
153
+
154
+ def note_sent(path: str, name: str, record: list) -> None:
155
+ """Remember one notice that went out ("<key>|<path>" -> [not_after, threshold]), next
156
+ to what the file holds. Raises OSError."""
157
+ with _lock:
158
+ notices = load_notices(path)
159
+ notices[name] = record
160
+ _write_notices(path, notices)
161
+
162
+
163
+ def _write_notices(path: str, notices: dict[str, list]) -> None:
164
+ tmp = path + ".tmp"
165
+ with open(tmp, "w", encoding="utf-8") as fh:
166
+ fh.write(json.dumps(notices, sort_keys=True) + "\n")
167
+ fh.flush()
168
+ os.fsync(fh.fileno())
169
+ os.replace(tmp, path)
170
+
171
+
172
+ class CertWatch:
173
+ """The certificates in use as last read, and which thresholds were said already."""
174
+
175
+ def __init__(self, state) -> None:
176
+ self.state = state
177
+ self._read: list[Certificate] = []
178
+ self._read_at: Optional[float] = None # time.monotonic() of the last read
179
+ self._logged: dict[str, tuple] = {} # key -> (not_after, threshold) logged
180
+ self._save_failed = False # logged once
181
+
182
+ @property
183
+ def notices_path(self) -> str:
184
+ return os.path.join(self.state.data_dir, NOTICES_FILE)
185
+
186
+ async def current(self, max_age: float = FRESH_S) -> list[Certificate]:
187
+ """The certificates in use, read again when the last read is older than
188
+ `max_age` seconds."""
189
+ now = time.monotonic()
190
+ if self._read_at is None or now - self._read_at >= max_age:
191
+ self._read = await asyncio.to_thread(read_all, in_use(self.state.config))
192
+ self._read_at = now
193
+ return self._read
194
+
195
+ async def check(self, emit, now: Optional[float] = None) -> int:
196
+ """Read the certificates and say which are past a threshold they were not said to
197
+ be past yet: a WARNING in the log (once per run and threshold), and
198
+ emit("cert_expiring", key, mapping name, detail, sent=..., channels=...) -> bool for
199
+ a notification, to every channel (channels None) or to those that did not take
200
+ that threshold's notice before; remembered in cert-notices.json once a channel
201
+ took it, with those that did not (Notifier.emit's sent). Returns how many were
202
+ queued."""
203
+ now = time.time() if now is None else now
204
+ certificates = await self.current(max_age=0)
205
+ notices = await asyncio.to_thread(load_notices, self.notices_path)
206
+ used = {f"{c.key}|{c.path}" for c in certificates}
207
+ kept = await asyncio.to_thread(kept_unused, notices, used, self.state.config)
208
+ due: list[tuple[Certificate, str, list, str, Optional[list[str]]]] = []
209
+ for c in certificates:
210
+ name = f"{c.key}|{c.path}"
211
+ if c.info is None: # (being replaced, say): what was sent for it stays said
212
+ if name in notices:
213
+ kept[name] = notices[name]
214
+ continue
215
+ if name in notices and notices[name][0] == c.info.not_after:
216
+ kept[name] = notices[name]
217
+ reached = threshold(c.info, now)
218
+ if reached is None:
219
+ continue
220
+ text = message(c, c.info, now)
221
+ if self._logged.get(name) != (c.info.not_after, reached):
222
+ self._logged[name] = (c.info.not_after, reached)
223
+ self.state.log(f"WARNING: TLS certificate: {text}")
224
+ before = kept.get(name)
225
+ if before is None or before[1] > reached: # (else said for it, or a tighter one)
226
+ due.append((c, name, [c.info.not_after, reached], text, None))
227
+ elif before[1] == reached and len(before) > 2 and before[2]:
228
+ # said, but not on every channel: to those it did not reach, and only them
229
+ due.append((c, name, [c.info.not_after, reached], text, list(before[2])))
230
+ # (first: a notice that is sent meanwhile is added to what this keeps)
231
+ if kept != notices: # (renewed certificates, deleted mappings: forgotten)
232
+ await self._save(save_notices, kept)
233
+ sent = 0
234
+ for c, name, record, text, channels in due:
235
+ if emit("cert_expiring", f"{name}|{record[1]}", c.mapping, text,
236
+ sent=self._remember(name, record), channels=channels):
237
+ sent += 1
238
+ return sent
239
+
240
+ def _remember(self, name: str, record: list):
241
+ """What Notifier.emit awaits once the notice was tried: once a channel took it
242
+ (or there was none to try), keep it as sent, with the channels that did not."""
243
+ async def sent(tried: list[str], failed: list[str]) -> None:
244
+ if tried and set(failed) >= set(tried):
245
+ return # nobody got it: the next check tries again (what was kept stays)
246
+ missed = sorted(set(failed))
247
+ await self._save(note_sent, name, record + ([missed] if missed else []))
248
+ return sent
249
+
250
+ async def _save(self, write, *args) -> None:
251
+ try:
252
+ await asyncio.to_thread(write, self.notices_path, *args)
253
+ self._save_failed = False
254
+ except OSError as e:
255
+ if not self._save_failed:
256
+ self._save_failed = True
257
+ self.state.log(f"TLS certificate notices: {NOTICES_FILE} could not be "
258
+ f"written ({e.strerror or e}): a notification may be sent "
259
+ "again after a restart")