ser2netweb 3.0.0__py3-none-any.whl

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 (121) hide show
  1. ser2netweb/__init__.py +20 -0
  2. ser2netweb/__main__.py +6 -0
  3. ser2netweb/accounts.py +503 -0
  4. ser2netweb/cli.py +489 -0
  5. ser2netweb/clock.py +128 -0
  6. ser2netweb/config.py +4491 -0
  7. ser2netweb/console.py +181 -0
  8. ser2netweb/datalock.py +181 -0
  9. ser2netweb/engine/__init__.py +0 -0
  10. ser2netweb/engine/access.py +173 -0
  11. ser2netweb/engine/bindhint.py +115 -0
  12. ser2netweb/engine/bridge.py +1928 -0
  13. ser2netweb/engine/cluster.py +1140 -0
  14. ser2netweb/engine/modbus.py +530 -0
  15. ser2netweb/engine/modbus_gateway.py +1465 -0
  16. ser2netweb/engine/mqtt_pub.py +632 -0
  17. ser2netweb/engine/netguard.py +805 -0
  18. ser2netweb/engine/netinfo.py +199 -0
  19. ser2netweb/engine/portdiag.py +414 -0
  20. ser2netweb/engine/portlist.py +471 -0
  21. ser2netweb/engine/protocols/__init__.py +28 -0
  22. ser2netweb/engine/protocols/base.py +117 -0
  23. ser2netweb/engine/protocols/raw.py +12 -0
  24. ser2netweb/engine/protocols/rfc2217.py +586 -0
  25. ser2netweb/engine/protocols/telnet.py +172 -0
  26. ser2netweb/engine/serial_compat.py +598 -0
  27. ser2netweb/engine/serial_io.py +210 -0
  28. ser2netweb/engine/serial_link.py +414 -0
  29. ser2netweb/engine/sockopts.py +103 -0
  30. ser2netweb/engine/sparkplug.py +538 -0
  31. ser2netweb/engine/sparkplug_node.py +550 -0
  32. ser2netweb/engine/supervisor.py +533 -0
  33. ser2netweb/engine/tls.py +232 -0
  34. ser2netweb/envvars.py +57 -0
  35. ser2netweb/explain.py +117 -0
  36. ser2netweb/healthcheck.py +78 -0
  37. ser2netweb/i18n.py +110 -0
  38. ser2netweb/importer.py +550 -0
  39. ser2netweb/layout.py +118 -0
  40. ser2netweb/licences.py +86 -0
  41. ser2netweb/locale/tr.json +1569 -0
  42. ser2netweb/logsetup.py +253 -0
  43. ser2netweb/logtext.py +23 -0
  44. ser2netweb/notify.py +761 -0
  45. ser2netweb/optional.py +76 -0
  46. ser2netweb/reload.py +295 -0
  47. ser2netweb/runtime.py +762 -0
  48. ser2netweb/sdnotify.py +85 -0
  49. ser2netweb/ser2net_import.py +2001 -0
  50. ser2netweb/signins.py +98 -0
  51. ser2netweb/standalone.py +154 -0
  52. ser2netweb/state.py +1457 -0
  53. ser2netweb/storage.py +130 -0
  54. ser2netweb/textfold.py +51 -0
  55. ser2netweb/tlsreload.py +37 -0
  56. ser2netweb/watchdog.py +201 -0
  57. ser2netweb/web/__init__.py +0 -0
  58. ser2netweb/web/api.py +793 -0
  59. ser2netweb/web/auth.py +699 -0
  60. ser2netweb/web/certinfo.py +144 -0
  61. ser2netweb/web/httpguard.py +413 -0
  62. ser2netweb/web/ldap_auth.py +556 -0
  63. ser2netweb/web/oidc_auth.py +330 -0
  64. ser2netweb/web/proxy.py +398 -0
  65. ser2netweb/web/routes/__init__.py +78 -0
  66. ser2netweb/web/routes/cluster.py +669 -0
  67. ser2netweb/web/routes/common.py +359 -0
  68. ser2netweb/web/routes/console.py +451 -0
  69. ser2netweb/web/routes/forms.py +853 -0
  70. ser2netweb/web/routes/login.py +573 -0
  71. ser2netweb/web/routes/mappings.py +470 -0
  72. ser2netweb/web/routes/ops.py +374 -0
  73. ser2netweb/web/routes/settings.py +2135 -0
  74. ser2netweb/web/routes/system.py +308 -0
  75. ser2netweb/web/routes/totp.py +282 -0
  76. ser2netweb/web/selfsigned.py +129 -0
  77. ser2netweb/web/server.py +483 -0
  78. ser2netweb/web/static/app.css +327 -0
  79. ser2netweb/web/static/app.js +1102 -0
  80. ser2netweb/web/static/htmx.min.js +1 -0
  81. ser2netweb/web/static/points.js +218 -0
  82. ser2netweb/web/static/theme.js +7 -0
  83. ser2netweb/web/static/xterm-addon-fit.js +2 -0
  84. ser2netweb/web/static/xterm.css +218 -0
  85. ser2netweb/web/static/xterm.js +2 -0
  86. ser2netweb/web/templates/_cluster_body.html +109 -0
  87. ser2netweb/web/templates/_console.html +21 -0
  88. ser2netweb/web/templates/_footer.html +13 -0
  89. ser2netweb/web/templates/_login_notice.html +8 -0
  90. ser2netweb/web/templates/_macros.html +21 -0
  91. ser2netweb/web/templates/_mapping_form.html +477 -0
  92. ser2netweb/web/templates/_mapping_log.html +28 -0
  93. ser2netweb/web/templates/_mapping_traces.html +44 -0
  94. ser2netweb/web/templates/_mappings_body.html +149 -0
  95. ser2netweb/web/templates/_modbus_read.html +18 -0
  96. ser2netweb/web/templates/_ports_table.html +37 -0
  97. ser2netweb/web/templates/_serial_port_select.html +48 -0
  98. ser2netweb/web/templates/_shell.html +41 -0
  99. ser2netweb/web/templates/audit.html +55 -0
  100. ser2netweb/web/templates/base.html +77 -0
  101. ser2netweb/web/templates/dashboard.html +72 -0
  102. ser2netweb/web/templates/licenses.html +18 -0
  103. ser2netweb/web/templates/login.html +32 -0
  104. ser2netweb/web/templates/login_totp.html +23 -0
  105. ser2netweb/web/templates/settings.html +830 -0
  106. ser2netweb/web/templates/setup.html +43 -0
  107. ser2netweb/web/templates/totp.html +41 -0
  108. ser2netweb/web/totp.py +94 -0
  109. ser2netweb/winservice.py +1793 -0
  110. ser2netweb-3.0.0.dist-info/METADATA +120 -0
  111. ser2netweb-3.0.0.dist-info/RECORD +121 -0
  112. ser2netweb-3.0.0.dist-info/WHEEL +5 -0
  113. ser2netweb-3.0.0.dist-info/entry_points.txt +2 -0
  114. ser2netweb-3.0.0.dist-info/licenses/COMMERCIAL_LICENSE.md +94 -0
  115. ser2netweb-3.0.0.dist-info/licenses/LICENSE +662 -0
  116. ser2netweb-3.0.0.dist-info/licenses/NOTICE +20 -0
  117. ser2netweb-3.0.0.dist-info/licenses/THIRD-PARTY-NOTICES.md +105 -0
  118. ser2netweb-3.0.0.dist-info/licenses/tools/licenses/npm/htmx.org.txt +13 -0
  119. ser2netweb-3.0.0.dist-info/licenses/tools/licenses/npm/xterm-addon-fit.txt +19 -0
  120. ser2netweb-3.0.0.dist-info/licenses/tools/licenses/npm/xterm.txt +21 -0
  121. ser2netweb-3.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,830 @@
1
+ {% extends "_shell.html" %}
2
+ {% block title %}{% if node_name %}{{ node_name }} · {% endif %}{{ _("Settings") }} — ser2netweb{% endblock %}
3
+ {% block main %}
4
+ {% set is_admin = me and me.role == 'admin' %}
5
+ {% set is_operator = me and me.role in ['operator', 'admin'] %}
6
+ {% set is_anonymous = me and me.source == 'anonymous' %}
7
+ {% set my_name = me.username if me and not is_anonymous else none %}
8
+ {% set unchanged = _('•••••• (unchanged)') %}
9
+ {% macro group_warning(w) -%}
10
+ {%- set setting = {'admin_group': _('Admin group'), 'operator_group': _('Operator group'), 'viewer_group': _('Viewer group')}[w.setting] -%}
11
+ <div class="banner warn">{% if w.got %}{{ _('At a sign-in at %(time)s, the %(setting)s “%(value)s” matched the group “%(group)s” of %(user)s only as part of its name. That no longer counts, so %(user)s got %(got)s instead of %(was)s. Enter the group’s whole name, such as “%(name)s”, and save.', time=w.time, setting=setting, value=w.value, group=w.group, user=w.user, got=w.got, was=w.was, name=w.name) }}{% else %}{{ _('At a sign-in at %(time)s, the %(setting)s “%(value)s” matched the group “%(group)s” of %(user)s only as part of its name. That no longer counts, so %(user)s could not sign in (before, they got %(was)s). Enter the group’s whole name, such as “%(name)s”, and save.', time=w.time, setting=setting, value=w.value, group=w.group, user=w.user, was=w.was, name=w.name) }}{% endif %}</div>
12
+ {%- endmacro %}
13
+ {% macro tls_problem(p) -%}
14
+ <div class="banner warn">{% if p.kind == 'ca_file' and p.unreadable %}{{ _('At a sign-in at %(time)s, the CA certificate file %(file)s could not be read, so LDAP sign-in failed. Correct “CA certificate file” below and save.', time=p.time, file=p.ca_file) }}{% elif p.kind == 'ca_file' %}{{ _('At a sign-in at %(time)s, the CA certificate file %(file)s held no certificate (PEM or DER), so LDAP sign-in failed. Correct “CA certificate file” below and save.', time=p.time, file=p.ca_file) }}{% elif p.kind == 'name' %}{{ _('At a sign-in at %(time)s, the certificate of the directory server %(uri)s was not accepted (%(reason)s): it was issued for another name, so LDAP sign-in failed; nothing was sent over that connection. Use a name the certificate was issued for in the server URI (an IP address only if the certificate lists it) and save.', time=p.time, uri=p.uri, reason=p.reason) }}{% elif p.ca_file %}{{ _('At a sign-in at %(time)s, the certificate of the directory server %(uri)s was not accepted (%(reason)s), so LDAP sign-in failed; nothing was sent over that connection. The CA certificate file %(file)s doesn’t hold the CA that issued it: enter a file with that CA’s certificate (PEM or DER) and save.', time=p.time, uri=p.uri, reason=p.reason, file=p.ca_file) }}{% else %}{{ _('At a sign-in at %(time)s, the certificate of the directory server %(uri)s was not accepted (%(reason)s), so LDAP sign-in failed; nothing was sent over that connection. If the directory’s certificates come from your own CA (such as Active Directory Certificate Services) or are self-signed, enter the file with that CA’s certificate (PEM or DER) as “CA certificate file” below and save.', time=p.time, uri=p.uri, reason=p.reason) }}{% endif %}</div>
15
+ {%- endmacro %}
16
+ {#- what a form did, or why not: in the section that has the form (`section`, the id
17
+ of its <section>; another one, at the top), which takes the keyboard focus (app.js);
18
+ `submitted`: what a refused form had, shown again in it #}
19
+ {% macro feedback(name) -%}
20
+ {%- set where = section if section in ['account', 'admin-interface', 'access', 'audit-log', 'retention', 'users', 'ldap', 'oidc', 'cluster-settings', 'notifications', 'tls', 'reverse-proxy', 'api-token', 'import', 'backups'] else 'account' -%}
21
+ {%- if where == name -%}
22
+ {% if ok %}<div class="banner ok" role="status" tabindex="-1" data-feedback>{{ ok }}</div>{% endif %}
23
+ {% if error %}<div class="banner error" role="alert" tabindex="-1" data-feedback>{{ error }}</div>{% endif %}
24
+ {%- endif -%}
25
+ {%- endmacro %}
26
+ {#- a role as the role selects offer it: its name (as the REST API, the audit log and the
27
+ docs write it) and what it may do, in the page's language #}
28
+ {% macro role_label(r) -%}
29
+ {{ r }} ({% if r == 'admin' %}{{ _("everything") }}{% elif r == 'operator' %}{{ _("manage mappings") }}{% else %}{{ _("read-only") }}{% endif %})
30
+ {%- endmacro %}
31
+ {% macro package_problem(p, what) -%}
32
+ <div class="banner warn">{% if p.missing and p.frozen %}{{ _('%(what)s is on, but <span class="mono">%(package)s</span> is missing from this executable, which should contain it; please report this. Local accounts still work.', what=what, package=p.dist) }}{% elif p.missing %}{{ _('%(what)s is on, but <span class="mono">%(package)s</span> is not installed, so it won’t work until you install it: <span class="mono">%(command)s</span>. Local accounts still work.', what=what, package=p.dist, command=p.hint) }}{% else %}{{ _('%(what)s is on, but <span class="mono">%(package)s</span> is installed and failed to import, so it won’t work until that is fixed and ser2netweb restarted. Local accounts still work. The error: <span class="mono">%(error)s</span>', what=what, package=p.dist, error=p.error) }}{% if p.override %} {{ _('%(name)s loads modules from <span class="mono">%(folder)s</span> first; check the copy there.', name=p.override_env, folder=p.override) }}{% endif %}{% endif %}</div>
33
+ {%- endmacro %}
34
+
35
+ <section class="panel panel-narrow" id="account">
36
+ {% if is_anonymous %}
37
+ <div class="panel-head"><h2>{{ _("Signed out (open access)") }}</h2></div>
38
+ {{ feedback('account') }}
39
+ <p>{{ _('Login is switched off for this UI, so you are using it without an account, with the <span class="mono">%(role)s</span> role. <a href="%(url)s">Sign in</a> for your own role (or to change your password).', role=me.role, url=base ~ '/login') }}</p>
40
+ {% else %}
41
+ <div class="panel-head"><h2>{{ _("Change your password") }}</h2></div>
42
+ {{ feedback('account') }}
43
+ <form method="post" action="{{ base }}/settings/password" class="authform">
44
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
45
+ <label>{{ _("Current password") }} <input type="password" name="current" autocomplete="current-password" required></label>
46
+ <label>{{ _("New password (min 8 chars)") }} <input type="password" name="password" autocomplete="new-password" required></label>
47
+ <label>{{ _("Confirm new password") }} <input type="password" name="password2" autocomplete="new-password" required></label>
48
+ <button class="btn primary" type="submit">{{ _("Update password") }}</button>
49
+ </form>
50
+ <form method="post" action="{{ base }}/settings/sessions/signout-others" class="authform mt-sm">
51
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
52
+ <p class="muted mb-sm">{{ _("Ends your sign-ins in other browsers and on other devices; this one stays signed in.") }}</p>
53
+ <button class="btn" type="submit">{{ _("Sign out my other sessions") }}</button>
54
+ </form>
55
+ {% if me and me.source == 'local' %}
56
+ <h3 class="mt-sm">{{ _("Two-factor sign-in") }}</h3>
57
+ <p class="mb-sm">{% if me.totp_on %}<span class="tag">{{ _("enabled") }}</span> {{ _("Signing in takes your password and a code from your authenticator app.") }}{% else %}<span class="tag">{{ _("disabled") }}</span> <span class="muted">{{ _("Your password alone signs you in. Add a code from an authenticator app on your phone or computer, so a password alone is not enough.") }}</span>{% endif %}</p>
58
+ <a class="btn" href="{{ base }}/settings/totp">{{ _("Turn off…") if me.totp_on else _("Set up…") }}</a>
59
+ {% endif %}
60
+ {% endif %}
61
+ </section>
62
+
63
+ <section class="panel panel-narrow" id="admin-interface">
64
+ <div class="panel-head"><h2>{{ _("Admin interface") }}</h2></div>
65
+ {{ feedback('admin-interface') }}
66
+ <p>{{ _('Listening on <span class="mono">%(address)s</span>', address=serving_address) }}
67
+ {% if serving_tls %}<span class="tag">TLS</span>{% else %}<span class="tag">HTTP</span>{% endif %}</p>
68
+ {% if pending_address %}<div class="banner warn">{{ _('config.json sets <span class="mono">%(address)s</span>: the admin UI moves there when ser2netweb starts again.', address=pending_address) }}</div>{% endif %}
69
+ {% if pending_tls %}<div class="banner warn">{{ _('The admin TLS settings saved are used from the next start.') }}</div>{% endif %}
70
+ {% if public_url %}<p>{{ _('Published as <a class="mono" href="%(url)s">%(url)s</a> (Settings → Reverse proxy)', url=public_url) }}</p>{% endif %}
71
+ {% if address_hint == 'env' %}
72
+ <p class="muted">{{ _('The address comes from <span class="mono">SER2NETWEB_BIND_IP</span> / <span class="mono">SER2NETWEB_PORT</span> (for a container: its environment), which win over config.json at every start: change them there and start ser2netweb (the container) again.') }}</p>
73
+ {% elif address_hint == 'service' %}
74
+ <p class="muted">{{ _('To change the address, run <span class="mono">%(command)s</span> from an elevated prompt: it stops the service, asks for the address and starts the service again.', command=address_command) }}</p>
75
+ {% else %}
76
+ <p class="muted">{{ _('To change the address, stop ser2netweb and start it as the account it runs as with <span class="mono">%(command)s</span>, which asks for the address; or change <span class="mono">admin_ui.bind_ip</span> / <span class="mono">port</span> in config.json and restart ser2netweb.', command=address_command) }}</p>
77
+ {% endif %}
78
+ {% if is_admin %}
79
+ {% with admin = submitted.node or admin %}
80
+ <form method="post" action="{{ base }}/settings/node-name" class="authform mt-sm">
81
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
82
+ <label>{{ _("Name of this instance") }} <span class="muted">({{ _("for instances that share a host name: notifications, the browser tab, the top bar and the cluster’s fleet view show it · blank: the host name, %(host)s", host=hostname) }})</span>
83
+ {% if node_name_env %}<input type="text" value="{{ node_name }}" disabled>
84
+ {% else %}<input type="text" name="node_name" value="{{ admin.node_name }}" maxlength="{{ node_name_max }}" placeholder="{{ hostname }}" autocomplete="off" spellcheck="false" data-1p-ignore data-lpignore="true" data-bwignore>{% endif %}</label>
85
+ {% if node_name_env %}<p class="muted">{{ _('Set by <span class="mono">%(name)s</span> for this run; the field takes effect again once that is removed.', name=node_name_env) }}</p>{% endif %}
86
+ <button class="btn primary" type="submit">{{ _("Save name") }}</button>
87
+ </form>
88
+ {% endwith %}
89
+ {% endif %}
90
+ <p>{{ _('Server time: <span class="mono">%(utc)s UTC</span> · local <span class="mono">%(local)s</span> (%(zone)s)', utc=server_utc, local=server_local[:19], zone=server_zone()) }}</p>
91
+ {% if clock_behind %}<div class="banner warn">{% if clock_behind.what == 'backup' %}{{ _("The server’s clock reads %(now)s UTC, earlier than the newest configuration backup (%(when)s UTC): it is probably wrong, or it was ahead when that backup was made.", now=server_utc, when=clock_behind.when) }}{% elif clock_behind.what == 'config' %}{{ _("The server’s clock reads %(now)s UTC, earlier than the last change to config.json (%(when)s UTC): it is probably wrong.", now=server_utc, when=clock_behind.when) }}{% else %}{{ _("The server’s clock reads %(now)s UTC, before this version of ser2netweb was made (%(when)s): it is wrong.", now=server_utc, when=clock_behind.when[:10]) }}{% endif %} {{ _("Logs, the audit log and backups get wrong times, and sign-ins and certificate checks can fail. ser2netweb never sets the clock: set it on the server, or let its time sync (NTP) do it.") }}</div>{% endif %}
92
+ <div class="banner warn" data-clock-skew hidden></div>
93
+ </section>
94
+
95
+ {% if is_admin %}
96
+ <section class="panel panel-narrow" id="access">
97
+ <div class="panel-head"><h2>{{ _("Web UI access") }}</h2></div>
98
+ {{ feedback('access') }}
99
+ <p class="muted mb-sm">{{ _('By default every visitor must sign in. On a trusted network you can let visitors use this UI <em>without a password</em>, with the role chosen below; signing in still gives a user their own role. Open access is honoured only when the UI is reached by IP address, <span class="mono">localhost</span> or this machine’s host name (protection against DNS rebinding — other names still ask for a login); behind a reverse proxy, have it pass the original name in <span class="mono">X-Forwarded-Host</span>, or keep login on. Other cluster nodes are only shown and managed after signing in, and the REST API always needs its token.') }}</p>
100
+ {% if not admin.require_login %}
101
+ <div class="banner warn">{{ _('Open access is <b>ON</b>: anyone who can reach this page gets the <span class="mono">%(role)s</span> role without a password.', role=admin.anonymous_role) }}{% if admin.bind_ip not in ['127.0.0.1', '::1'] %} {{ _('The UI listens on <span class="mono">%(ip)s</span>.', ip=admin.bind_ip or '*') }}{% endif %}</div>
102
+ {% endif %}
103
+ {% with admin = submitted.access or admin, session_minutes = submitted.session_minutes or session_minutes %}
104
+ <form method="post" action="{{ base }}/settings/access" class="authform">
105
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
106
+ <label class="chk"><input type="checkbox" name="require_login" {% if admin.require_login %}checked{% endif %}> {{ _("Require login (password) for the web UI") }}</label>
107
+ <label>{{ _("Role for visitors without login") }} <span class="muted">({{ _("used only when login is not required") }})</span>
108
+ <select name="anonymous_role">
109
+ {% for r in roles %}<option value="{{ r }}" {% if r == admin.anonymous_role %}selected{% endif %}>{{ role_label(r) }}</option>{% endfor %}
110
+ </select>
111
+ </label>
112
+ <label>{{ _("Session lifetime (minutes)") }} <span class="muted">({{ _("how long a sign-in lasts · 5 min – 30 days · applies to new sign-ins") }})</span>
113
+ <input type="number" name="session_minutes" min="5" max="43200" value="{{ session_minutes }}" required>
114
+ </label>
115
+ <label>{{ _("Default language") }} <span class="muted">({{ _("for visitors who haven’t picked one with the language switch") }})</span>
116
+ <select name="default_language">
117
+ <option value="auto" {% if admin.language == 'auto' %}selected{% endif %}>{{ _("The browser’s language") }}</option>
118
+ {% for code, label in languages.items() %}<option value="{{ code }}" {% if admin.language == code %}selected{% endif %}>{{ label }}</option>{% endfor %}
119
+ </select>
120
+ </label>
121
+ <button class="btn primary" type="submit">{{ _("Save access") }}</button>
122
+ </form>
123
+ {% endwith %}
124
+ {% with admin = submitted.login_notice or admin %}
125
+ <form method="post" action="{{ base }}/settings/login-notice" class="authform mt-sm">
126
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
127
+ <label>{{ _("Sign-in notice") }} <span class="muted">({{ _("shown on the sign-in page before anyone signs in, such as a privacy notice or a system-use warning · plain text, at most %(max)s characters · blank: none", max=login_notice_max) }})</span>
128
+ <textarea name="login_notice" rows="4" maxlength="{{ login_notice_max }}">{{ admin.login_notice }}</textarea></label>
129
+ <label>{{ _("Link to the full notice") }} <span class="muted">({{ _("optional · an http:// or https:// address") }})</span>
130
+ <input type="url" name="login_notice_url" value="{{ admin.login_notice_url }}" maxlength="{{ login_notice_url_max }}" placeholder="https://example.com/privacy" autocomplete="off" spellcheck="false"></label>
131
+ {% if not admin.require_login %}<p class="muted">{{ _("With open access, visitors who don’t sign in find it under “Notice” in the top bar.") }}</p>{% endif %}
132
+ <button class="btn" type="submit">{{ _("Save notice") }}</button>
133
+ </form>
134
+ {% endwith %}
135
+ <form method="post" action="{{ base }}/settings/sessions/revoke-all" class="authform mt-sm"
136
+ data-confirm="{{ _('Sign everyone out of this web UI, on every device? You stay signed in here.') }}">
137
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
138
+ <p class="muted mb-sm">{{ _("Ends every web UI session at once by making a new session key — also sessions signed with the key in an old copy of config.json or of a backup. You stay signed in here.") }}</p>
139
+ <button class="btn" type="submit">{{ _("Sign out everyone") }}</button>
140
+ </form>
141
+ </section>
142
+
143
+ <section class="panel panel-narrow" id="audit-log">
144
+ <div class="panel-head"><h2>{{ _("Audit log") }}</h2><a class="btn sm" href="{{ base }}/settings/audit">{{ _("Open audit log →") }}</a></div>
145
+ {{ feedback('audit-log') }}
146
+ <p class="muted">{{ _("Sign-ins and every configuration change: who, from where, what — with search, filters and CSV export.") }}</p>
147
+ <form method="post" action="{{ base }}/settings/request-log" class="authform mt-sm">
148
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
149
+ <label>{{ _("Web UI requests in all.log") }} <span class="muted">({{ _("one line each, with the client’s IP address; sign-ins and the audit log’s records are written either way") }})</span>
150
+ <select name="request_log">
151
+ {% set request_log_labels = {'all': _("Every page and change (the default)"), 'changes': _("Only changes, and refused or failed requests"), 'off': _("None")} %}
152
+ {% for m in request_log_modes %}<option value="{{ m }}" {% if m == admin.request_log %}selected{% endif %}>{{ request_log_labels[m] }}</option>{% endfor %}
153
+ </select>
154
+ </label>
155
+ <button class="btn" type="submit">{{ _("Save") }}</button>
156
+ </form>
157
+ </section>
158
+
159
+ <section class="panel panel-narrow" id="retention">
160
+ <div class="panel-head"><h2>{{ _("Retention") }}</h2></div>
161
+ {{ feedback('retention') }}
162
+ {% if disk and disk.free is not none %}
163
+ {% if disk.free < disk.floor %}<div class="banner warn">{{ _("The data disk is almost full: trace files are paused. Delete trace files that are no longer needed, or make room on the disk.") }}</div>{% endif %}
164
+ <p class="muted">{{ _("The data folder’s disk: %(free)s free of %(total)s (trace files pause below %(floor)s free). Traces take %(traces)s, logs %(logs)s.", free=size_text(disk.free), total=size_text(disk.total), floor=size_text(disk.floor), traces=size_text(disk.traces), logs=size_text(disk.logs)) }}</p>
165
+ {% endif %}
166
+ {% with trace_days = submitted.retention.trace_max_age_days if submitted.retention else trace_days, log_days = submitted.retention.log_max_age_days if submitted.retention else log_days %}
167
+ <form method="post" action="{{ base }}/settings/retention" class="authform">
168
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
169
+ <label>{{ _("Delete trace files not written for (days)") }} <span class="muted">({{ _("0 = keep them, the default · up to %(max)s", max=trace_days_max) }})</span>
170
+ <input type="number" name="trace_max_age_days" min="0" max="{{ trace_days_max }}" value="{{ trace_days }}" required>
171
+ </label>
172
+ <p class="muted">{{ _("Off by default: a trace file stays until an operator deletes it in its mapping’s Trace panel. With a number of days, every trace file not written for that long is deleted at once and then every hour, also the one a mapping is writing (the next traffic begins it again), and the log says how many went.") }} {{ _("A file a mapping keeps writing into begins anew once it holds traffic from that many days ago, so its traffic goes too, that many days after its last write.") }}</p>
173
+ <label>{{ _("Delete log and audit records and configuration backups older than (days)") }} <span class="muted">({{ _("0 = only the size limits, the default · up to %(max)s", max=log_days_max) }})</span>
174
+ <input type="number" name="log_max_age_days" min="0" max="{{ log_days_max }}" value="{{ log_days }}" required>
175
+ </label>
176
+ <p class="muted">{{ _("Off by default: all.log (10 MB × 6 files), audit.log (5 MB × 2) and the newest 50 configuration backups are kept within their sizes however old they are, and a mapping’s log keeps 15 days (always its last 1000 lines). With a number of days, all.log and audit.log begin a new file once their first record is a fifth of that old and delete a file once its first record is older (so at least four fifths of the period stay, sizes allowing; audit.log then keeps up to 6 files), a mapping’s log keeps no more days than that, and older backups go, but never the newest %(min)s. Checked at once and then every hour; a clock set ahead while ser2netweb runs deletes nothing early. The copy of the log on the standard output (Docker, journald) has its own limits.", min=backups_min) }}</p>
177
+ <button class="btn" type="submit">{{ _("Save") }}</button>
178
+ </form>
179
+ {% endwith %}
180
+ </section>
181
+
182
+ <section class="panel panel-narrow" id="users">
183
+ <div class="panel-head"><h2>{{ _("Users") }}</h2></div>
184
+ {{ feedback('users') }}
185
+ <div class="table-scroll">
186
+ <table class="grid th-wrap">
187
+ <thead><tr><th>{{ _("Username") }}</th><th>{{ _("Role") }}</th><th></th></tr></thead>
188
+ <tbody>
189
+ {% for u in users %}
190
+ <tr>
191
+ <td class="mono"><span id="user-{{ loop.index }}-name">{{ u.username }}</span>{% if u.username == my_name %} <span class="tag">{{ _("you") }}</span>{% endif %}{% if u.source != 'local' %} <span class="tag">{{ u.source|upper }}</span>{% endif %}{% if u.totp_on %} <span class="tag" title="{{ _('two-factor sign-in') }}">2FA</span>{% endif %}<br><span class="muted">{{ _("last sign-in: %(time)s", time=last_sign_in[u.username]) }}</span></td>
192
+ <td>
193
+ {% if u.source != 'local' %}
194
+ <span class="mono">{{ u.role }}</span> <span class="muted">({{ _("from %(source)s", source=u.source|upper) }})</span>
195
+ {% else %}
196
+ <form method="post" action="{{ base }}/settings/users/role" class="inline">
197
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
198
+ <input type="hidden" name="username" value="{{ u.username }}">
199
+ <select name="role" aria-label="{{ _('Role of %(user)s', user=u.username) }}">
200
+ {% for r in roles %}<option value="{{ r }}" {% if r == u.role %}selected{% endif %}>{{ role_label(r) }}</option>{% endfor %}
201
+ </select>
202
+ <button class="btn sm" type="submit" aria-describedby="user-{{ loop.index }}-name">{{ _("Set") }}</button>
203
+ </form>
204
+ {% endif %}
205
+ </td>
206
+ <td>
207
+ {% if u.username != my_name %}
208
+ <div class="row-actions">
209
+ <form method="post" action="{{ base }}/settings/users/signout" class="inline">
210
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
211
+ <input type="hidden" name="username" value="{{ u.username }}">
212
+ <button class="btn sm" type="submit" aria-describedby="user-{{ loop.index }}-name">{{ _("Sign out") }}</button>
213
+ </form>
214
+ {% if u.totp_on %}
215
+ <form method="post" action="{{ base }}/settings/users/totp-reset" class="inline"
216
+ data-confirm="{{ _('Turn off two-factor sign-in for %(user)s? They are signed out, and their password alone signs them in until they set it up again.', user=u.username) }}">
217
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
218
+ <input type="hidden" name="username" value="{{ u.username }}">
219
+ <button class="btn sm" type="submit">{{ _("Turn off 2FA") }}</button>
220
+ </form>
221
+ {% endif %}
222
+ {#- asked for a local account: its password is gone with it (a directory account
223
+ comes back at its next sign-in while the directory allows it) #}
224
+ <form method="post" action="{{ base }}/settings/users/delete" class="inline"{% if u.source == 'local' %}
225
+ data-confirm="{{ _('Delete the user “%(user)s”? The password goes with it: only restoring a configuration backup brings it back.', user=u.username) }}"{% endif %}>
226
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
227
+ <input type="hidden" name="username" value="{{ u.username }}">
228
+ <button class="btn sm danger" type="submit" aria-describedby="user-{{ loop.index }}-name">{{ _("Delete") }}</button>
229
+ </form>
230
+ </div>
231
+ {% endif %}
232
+ </td>
233
+ </tr>
234
+ {% endfor %}
235
+ </tbody>
236
+ </table>
237
+ </div>
238
+ <p class="muted mb-sm">{{ _('Roles: <span class="mono">admin</span> (everything), <span class="mono">operator</span> (manage mappings), <span class="mono">viewer</span> (read-only).') }}</p>
239
+ {% if ldap.enabled or oidc.enabled or users|rejectattr("source", "equalto", "local")|list %}
240
+ <p class="muted mb-sm">{{ _("LDAP / OIDC accounts are made at their first sign-in, and every sign-in takes their role from the directory or the identity provider again. Delete signs such an account out at once, but whether that person can sign in again is up to the directory: while a mapped group or the default role still applies, their next sign-in makes a new account.") }}</p>
241
+ <form method="post" action="{{ base }}/settings/users/expiry" class="authform mb-sm">
242
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
243
+ <label>{{ _("Remove LDAP / OIDC accounts not signed in for (days)") }} <span class="muted">({{ _("0 = off, the default · %(min)s to %(max)s", min=expire_min, max=expire_max) }})</span>
244
+ <input type="number" name="expire_days" min="0" max="{{ expire_max }}" value="{{ submitted.expire_days or expire_days }}" required>
245
+ </label>
246
+ <p class="muted">{{ _("Off by default: an account that stops signing in stays until you delete it. With a number of days, LDAP / OIDC accounts not signed in for that long are removed at once and then every hour, each logged and audited — never admins or local accounts; they come back at their next sign-in while the directory still gives them a role.") }}</p>
247
+ <button class="btn" type="submit">{{ _("Save") }}</button>
248
+ </form>
249
+ {% endif %}
250
+ {% set nu = submitted.new_user or {} %}
251
+ <form method="post" action="{{ base }}/settings/users" class="authform">
252
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
253
+ <div class="grid2">
254
+ <label>{{ _("Username") }} <input type="text" name="username" value="{{ nu.username }}" placeholder="{{ _('e.g. %(example)s', example='operator1') }}" autocomplete="off" autocapitalize="none" autocorrect="off" spellcheck="false" maxlength="32" pattern="[A-Za-z0-9._\-]{1,32}" title="{{ _("Username must be 1-32 characters: English letters (a-z, A-Z), digits, '.', '_' or '-'.") }}" required></label>
255
+ <label>{{ _("Role") }}
256
+ <select name="role">{% for r in roles %}<option value="{{ r }}" {% if r == (nu.role or 'viewer') %}selected{% endif %}>{{ role_label(r) }}</option>{% endfor %}</select>
257
+ </label>
258
+ </div>
259
+ <div class="grid2">
260
+ <label>{{ _("Password (min 8)") }} <input type="password" name="password" autocomplete="new-password" required></label>
261
+ <label>{{ _("Confirm") }} <input type="password" name="password2" autocomplete="new-password" required></label>
262
+ </div>
263
+ <button class="btn" type="submit">{{ _("Add user") }}</button>
264
+ </form>
265
+ {% set resettable = users|selectattr("source", "equalto", "local")|rejectattr("username", "equalto", my_name)|list %}
266
+ {% if resettable %}
267
+ <h3 class="mt-sm">{{ _("Set another user’s password") }}</h3>
268
+ <p class="muted mb-sm">{{ _("For someone who forgot theirs; it also signs that user out everywhere. “Sign out” in the table ends a user’s sessions without changing anything else.") }}</p>
269
+ <form method="post" action="{{ base }}/settings/users/password" class="authform">
270
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
271
+ <label>{{ _("User") }}
272
+ <select name="username">{% for u in resettable %}<option value="{{ u.username }}"{% if u.username == submitted.reset_user %} selected{% endif %}>{{ u.username }}</option>{% endfor %}</select>
273
+ </label>
274
+ <div class="grid2">
275
+ <label>{{ _("New password (min 8 chars)") }} <input type="password" name="password" autocomplete="new-password" required></label>
276
+ <label>{{ _("Confirm") }} <input type="password" name="password2" autocomplete="new-password" required></label>
277
+ </div>
278
+ <button class="btn" type="submit">{{ _("Set password") }}</button>
279
+ </form>
280
+ {% endif %}
281
+ </section>
282
+
283
+ <section class="panel panel-narrow" id="ldap">
284
+ <div class="panel-head"><h2>LDAP / Active Directory</h2></div>
285
+ {{ feedback('ldap') }}
286
+ <p class="muted mb-sm">{{ _('Authenticate users against a directory; their group membership maps to a ser2netweb role. Local accounts above keep working. Needs <span class="mono">ldap3</span> (optional).') }} {{ _('Setup for Active Directory and OpenLDAP: <span class="mono">docs/SSO.md</span>.') }}</p>
287
+ {% if ldap_problem %}{{ package_problem(ldap_problem, _("LDAP sign-in")) }}{% endif %}
288
+ {% if ldap.enabled and ldap_tls_problem %}{{ tls_problem(ldap_tls_problem) }}{% endif %}
289
+ {% if ldap.enabled and ldap.uses_tls and not ldap.tls_verify %}<div class="banner warn">{{ _('The directory server’s certificate is not checked: anyone on the network between ser2netweb and the directory could read the passwords and sign in as anyone. Set the CA certificate file below and untick “Don’t check the server certificate” as soon as you can.') }}</div>
290
+ {% elif ldap.enabled and ldap.sends_plaintext %}<div class="banner warn">{{ _('Passwords go to the directory unencrypted (ldap:// without StartTLS): anyone on the network between ser2netweb and the directory can read them. Use ldaps:// or tick StartTLS.') }}</div>{% endif %}
291
+ {% for w in group_warnings.ldap %}{{ group_warning(w) }}{% endfor %}
292
+ {% with ldap = submitted.ldap or ldap %}
293
+ <form method="post" action="{{ base }}/settings/ldap" class="authform">
294
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
295
+ <label class="chk"><input type="checkbox" name="ldap_enabled" {% if ldap.enabled %}checked{% endif %}> {{ _("Enable LDAP / AD login") }}</label>
296
+ <div class="grid2">
297
+ <label>{{ _("Server URI") }} <input type="text" name="ldap_server_uri" value="{{ ldap.server_uri }}" placeholder="ldaps://dc.corp.local:636"></label>
298
+ <label class="chk chk-pad"><input type="checkbox" name="ldap_start_tls" {% if ldap.start_tls %}checked{% endif %}> StartTLS</label>
299
+ </div>
300
+ <input type="hidden" name="ldap_tls_shown" value="1">
301
+ <label>{{ _("CA certificate file") }} <span class="muted">({{ _("LDAPS / StartTLS: the server’s certificate must come from this CA; PEM or DER; blank = the CAs this system trusts") }})</span>
302
+ <input type="text" name="ldap_ca_file" value="{{ ldap.ca_file }}" placeholder="{{ _('optional') }}">
303
+ </label>
304
+ <label class="chk"><input type="checkbox" name="ldap_tls_insecure" {% if not ldap.tls_verify %}checked{% endif %}> {{ _("Don’t check the server certificate (insecure: anyone on the network path could read the passwords)") }}</label>
305
+ <label>{{ _("User DN template") }} <span class="muted">({{ _("direct bind") }} — AD: <span class="mono">{username}@corp.local</span>; LDAP: <span class="mono">uid={username},ou=people,dc=ex,dc=com</span>)</span>
306
+ <input type="text" name="ldap_user_dn_template" value="{{ ldap.user_dn_template }}" placeholder="{{ _('optional') }}" autocapitalize="none" autocorrect="off" spellcheck="false">
307
+ </label>
308
+ <p class="muted">{{ _("…or search + bind with a service account:") }}</p>
309
+ <div class="grid2">
310
+ <label>Bind DN <input type="text" name="ldap_bind_dn" value="{{ ldap.bind_dn }}" placeholder="cn=svc,dc=ex,dc=com" autocomplete="off" autocapitalize="none" autocorrect="off" spellcheck="false"></label>
311
+ <label>{{ _("Bind password") }} <input type="password" name="ldap_bind_password" autocomplete="new-password" data-1p-ignore data-lpignore="true" data-bwignore placeholder="{% if ldap.bind_password %}{{ unchanged }}{% endif %}"></label>
312
+ </div>
313
+ <div class="grid2">
314
+ <label>{{ _("User search base") }} <input type="text" name="ldap_user_search_base" value="{{ ldap.user_search_base }}" placeholder="ou=people,dc=ex,dc=com"></label>
315
+ <label>{{ _("User search filter") }} <input type="text" name="ldap_user_search_filter" value="{{ ldap.user_search_filter }}" placeholder="(sAMAccountName={username})"></label>
316
+ </div>
317
+ <div class="grid2">
318
+ <label>{{ _("Group attribute") }} <input type="text" name="ldap_group_attr" value="{{ ldap.group_attr }}" placeholder="memberOf"></label>
319
+ <label>{{ _("Default role") }} <span class="muted">({{ _("if in no mapped group") }})</span>
320
+ <select name="ldap_default_role">
321
+ <option value="" {% if not ldap.default_role %}selected{% endif %}>{{ _("— deny login —") }}</option>
322
+ {% for r in roles %}<option value="{{ r }}" {% if r == ldap.default_role %}selected{% endif %}>{{ role_label(r) }}</option>{% endfor %}
323
+ </select>
324
+ </label>
325
+ </div>
326
+ <div class="grid3">
327
+ <label>{{ _("Admin group") }} <input type="text" name="ldap_admin_group" value="{{ ldap.admin_group }}" placeholder="ser2netweb-admins"></label>
328
+ <label>{{ _("Operator group") }} <input type="text" name="ldap_operator_group" value="{{ ldap.operator_group }}" placeholder="ser2netweb-operators"></label>
329
+ <label>{{ _("Viewer group") }} <input type="text" name="ldap_viewer_group" value="{{ ldap.viewer_group }}" placeholder="ser2netweb-viewers"></label>
330
+ </div>
331
+ <p class="muted">{{ _('A group setting is the whole name of one group, in any letter case (Turkish İ/ı too): its name (the CN, such as <span class="mono">ser2netweb-admins</span>) or its full DN. Part of a name, such as <span class="mono">admins</span> for ser2netweb-admins, doesn’t match.') }}</p>
332
+ <input type="hidden" name="ldap_nested_groups_shown" value="1">
333
+ <label class="chk"><input type="checkbox" name="ldap_nested_groups" {% if ldap.nested_groups %}checked{% endif %}> {{ _("Also count nested groups (Active Directory: groups the user is in through another group)") }}</label>
334
+ <button class="btn primary" type="submit">{{ _("Save LDAP") }}</button>
335
+ </form>
336
+ {% endwith %}
337
+ </section>
338
+
339
+ <section class="panel panel-narrow" id="oidc">
340
+ <div class="panel-head"><h2>{{ _("Single sign-on (OIDC)") }}</h2></div>
341
+ {{ feedback('oidc') }}
342
+ <p class="muted mb-sm">{{ _('OpenID Connect SSO (Keycloak, Entra ID, Google, Okta…). A claim maps to a ser2netweb role. Needs <span class="mono">authlib</span> (optional).') }} {{ _('Keycloak, Entra ID and Google settings: <span class="mono">docs/SSO.md</span>.') }}</p>
343
+ {% if oidc_problem %}{{ package_problem(oidc_problem, _("Single sign-on (OIDC)")) }}{% endif %}
344
+ <p class="mb-sm" id="oidc-redirect" data-uri="{{ oidc_redirect_uri }}"{% if oidc_redirect_auto %} data-auto{% endif %}>{{ _("Redirect URI to register at the identity provider:") }} <span class="mono">{{ oidc_redirect_uri }}</span>
345
+ <span class="muted">({% if oidc_redirect_public %}{{ _("Redirect URI below is blank, so it is made from the public URL (Settings → Reverse proxy)") }}{% elif oidc_redirect_auto %}{{ _("Redirect URI below is blank, so it is made from the address in this page’s request") }}{% else %}{{ _("as set below") }}{% endif %})</span></p>
346
+ {% if (oidc_redirect_auto or oidc_redirect_public) and oidc_redirect_http %}<div class="banner warn">{{ _("This redirect URI starts with http://: most identity providers accept http:// only for localhost. Use HTTPS (Admin TLS, or a reverse proxy with TLS) and register the https:// address.") }}</div>{% endif %}
347
+ <div class="banner warn" id="oidc-redirect-mismatch" hidden>{{ _('This browser has the page at another address, for which the redirect URI is <span class="mono" data-browser-uri></span>: a reverse proxy in between changed the address ser2netweb sees. If users sign in at this browser’s address, enter that value as Redirect URI below and register it at the identity provider.') }}</div>
348
+ {% for w in group_warnings.oidc %}{{ group_warning(w) }}{% endfor %}
349
+ {% with oidc = submitted.oidc or oidc %}
350
+ <form method="post" action="{{ base }}/settings/oidc" class="authform">
351
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
352
+ <label class="chk"><input type="checkbox" name="oidc_enabled" {% if oidc.enabled %}checked{% endif %}> {{ _("Enable SSO login") }}</label>
353
+ <label>{{ _("Issuer URL") }} <input type="text" name="oidc_issuer" value="{{ oidc.issuer }}" placeholder="https://keycloak.example.com/realms/main"></label>
354
+ <div class="grid2">
355
+ <label>Client ID <input type="text" name="oidc_client_id" value="{{ oidc.client_id }}" autocomplete="off" autocapitalize="none" autocorrect="off" spellcheck="false"></label>
356
+ <label>Client secret <input type="password" name="oidc_client_secret" autocomplete="new-password" data-1p-ignore data-lpignore="true" data-bwignore placeholder="{% if oidc.client_secret %}{{ unchanged }}{% endif %}"></label>
357
+ </div>
358
+ <div class="grid2">
359
+ <label>Redirect URI <span class="muted">({{ _("blank = auto") }})</span><input type="text" name="oidc_redirect_uri" value="{{ oidc.redirect_uri }}" placeholder="{{ _('auto from request') }}"></label>
360
+ <label>Scopes <input type="text" name="oidc_scopes" value="{{ oidc.scopes }}" placeholder="openid email profile"></label>
361
+ </div>
362
+ <div class="grid2">
363
+ <label>{{ _("Username claim") }} <input type="text" name="oidc_username_claim" value="{{ oidc.username_claim }}" placeholder="preferred_username"></label>
364
+ <label>{{ _("Groups/roles claim") }} <input type="text" name="oidc_groups_claim" value="{{ oidc.groups_claim }}" placeholder="groups"></label>
365
+ </div>
366
+ <p class="muted mb-sm">{{ _('Both are read from the ID token only, as top-level claims: Keycloak needs a mapper with “Add to ID token” (its realm roles are nested and can’t be read), and Entra ID sends the groups’ Object IDs, which are what the group settings below then name.') }}</p>
367
+ <div class="grid3">
368
+ <label>{{ _("Admin group") }} <input type="text" name="oidc_admin_group" value="{{ oidc.admin_group }}" placeholder="ser2netweb-admins"></label>
369
+ <label>{{ _("Operator group") }} <input type="text" name="oidc_operator_group" value="{{ oidc.operator_group }}"></label>
370
+ <label>{{ _("Viewer group") }} <input type="text" name="oidc_viewer_group" value="{{ oidc.viewer_group }}"></label>
371
+ </div>
372
+ <p class="muted">{{ _('A group setting is the whole name of one group as the provider sends it, in any letter case (Turkish İ/ı too); of a path, the last part is enough: <span class="mono">ser2netweb-admins</span> matches <span class="mono">/team/ser2netweb-admins</span>. Part of a name, such as <span class="mono">admins</span> for ser2netweb-admins, doesn’t match.') }}</p>
373
+ <label>{{ _("Default role") }} <span class="muted">({{ _("if no group matched") }})</span>
374
+ <select name="oidc_default_role">
375
+ <option value="" {% if not oidc.default_role %}selected{% endif %}>{{ _("— deny login —") }}</option>
376
+ {% for r in roles %}<option value="{{ r }}" {% if r == oidc.default_role %}selected{% endif %}>{{ role_label(r) }}</option>{% endfor %}
377
+ </select>
378
+ </label>
379
+ <button class="btn primary" type="submit">{{ _("Save SSO") }}</button>
380
+ </form>
381
+ {% endwith %}
382
+ </section>
383
+
384
+ <section class="panel panel-narrow" id="cluster-settings">
385
+ <div class="panel-head"><h2>{{ _("LAN cluster") }}</h2></div>
386
+ {{ feedback('cluster-settings') }}
387
+ <p class="muted mb-sm">{{ _('Discover other ser2netweb nodes on the local network (signed UDP broadcast — no mDNS) and show every node’s mappings in one table on the dashboard, each row tagged with its host (name + IP). Set the <em>same shared key</em> on every node so they trust each other; with the key, operators can start/stop/restart a peer’s mappings from the unified view. This node’s ID: <span class="mono">%(id)s</span>.', id=instance_id[:8]) }}</p>
388
+ {% for c in cluster_copies %}
389
+ <div class="banner warn">{{ _("Another node uses this node’s identity: %(name)s at %(addr)s — probably a copy of this installation (its data folder, disk or VM image). Give one of the two a new identity (below).", name=c.name, addr=c.addr) }}</div>
390
+ {% endfor %}
391
+ {% if new_cluster_key %}
392
+ <div class="banner ok">{{ _("New cluster key (copy it now — it is not shown again). Set the same key on every node:") }}
393
+ <div class="mono token-box">{{ new_cluster_key }}</div>
394
+ <button type="button" class="btn sm mt-sm" data-copy>{{ _("Copy") }}</button>
395
+ </div>
396
+ {% endif %}
397
+ {% if cluster_key_hint == 'weak' %}
398
+ <div class="banner warn">{{ _("The cluster key is short or simple. Any host on this network can try to guess it offline from the beacons every node broadcasts, and the key lets a node start, stop and change the mappings of every other node: use at least 16 random characters, or generate one.") }}</div>
399
+ {% elif cluster_key_hint == 'ascii' and cluster.legacy_auth %}
400
+ <div class="banner warn">{{ _("The cluster key has letters outside ASCII: nodes running 2.8.0 or older can’t use it. Upgrade them or use an ASCII key.") }}</div>
401
+ {% endif %}
402
+ {% set sc = submitted.cluster %}
403
+ {% with cluster = sc or cluster, cluster_peers_text = sc.peers_text if sc else cluster_peers_text %}
404
+ <form method="post" action="{{ base }}/settings/cluster" class="authform">
405
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
406
+ <input type="hidden" name="cluster_form" value="2">
407
+ <label class="chk"><input type="checkbox" name="enabled" {% if cluster.enabled %}checked{% endif %}> {{ _("Enable LAN cluster") }}</label>
408
+ <label>{{ _("Shared cluster key") }} <span class="muted">({{ _("the same on every node") }}{% if cluster_key_set %}; {{ _("blank = unchanged") }}{% endif %})</span>
409
+ <input type="password" name="key" autocomplete="new-password" data-1p-ignore data-lpignore="true" data-bwignore placeholder="{% if cluster_key_set %}{{ unchanged }}{% else %}{{ _('a long random string — or use “Generate a new key and save”') }}{% endif %}"></label>
410
+ {% if cluster_key_set %}
411
+ <label class="chk"><input type="checkbox" name="keep_old_key"{% if not sc or sc.keep_old_key %} checked{% endif %}> {{ _("When the key changes, keep accepting the current one for 7 days, until every node has the new one (untick it if the key leaked)") }}</label>
412
+ {% if cluster_previous %}
413
+ <p class="muted">{% if cluster_previous_until %}{{ _("The previous key is also accepted, until %(until)s UTC.", until=cluster_previous_until) }}{% else %}{{ _("The previous key is also accepted.") }}{% endif %}</p>
414
+ <label class="chk"><input type="checkbox" name="clear_previous_key"{% if sc and sc.clear_previous_key %} checked{% endif %}> {{ _("Stop accepting the previous key now") }}</label>
415
+ {% endif %}
416
+ <label class="chk"><input type="checkbox" name="clear_key"{% if sc and sc.clear_key %} checked{% endif %}> {{ _("Remove the stored key") }}</label>
417
+ {% endif %}
418
+ <label class="chk"><input type="checkbox" name="legacy_auth" {% if cluster.legacy_auth %}checked{% endif %}> {{ _("Legacy authentication: also accept and use the unsigned key with nodes running 2.8.0 or older") }}</label>
419
+ {% if cluster.legacy_auth %}
420
+ <p class="muted">{% if cluster_legacy %}{{ _("In use with: %(nodes)s.", nodes=cluster_legacy|join(", ")) }}{% else %}{{ _("No node has used it recently.") }}{% endif %} {{ _("Nodes running 2.8.0 or older send the key itself in every request, readable on the network; once every node is upgraded, turn this off.") }}</p>
421
+ {% endif %}
422
+ <label class="chk"><input type="checkbox" name="discovery" {% if cluster.discovery %}checked{% endif %}> {{ _("Find other nodes automatically (UDP broadcast); off = manual peers only") }}</label>
423
+ <div class="grid2">
424
+ <label>{{ _("Discovery UDP port") }} <input type="number" name="discovery_port" value="{{ cluster.discovery_port }}" min="1" max="65535"></label>
425
+ <label>{{ _("Advertise IP") }} <span class="muted">({{ _("blank = auto-detect") }})</span><input type="text" name="advertise_ip" value="{{ cluster.advertise_ip }}" placeholder="{{ _('this node’s LAN IP others reach') }}"></label>
426
+ </div>
427
+ <label>{{ _("Manual peers") }} <span class="muted">({{ _('one <span class="mono">host:port</span> per line — for routed/L3 networks broadcast can’t reach') }})</span>
428
+ <textarea name="peers" rows="3" placeholder="10.0.5.12:8080&#10;https://plc-gw.example:8443">{{ cluster_peers_text }}</textarea></label>
429
+ <div class="row-actions start">
430
+ <button class="btn primary" type="submit">{{ _("Save cluster") }}</button>
431
+ <button class="btn" type="submit" name="then" value="generate">{{ _("Generate a new key and save") }}</button>
432
+ </div>
433
+ </form>
434
+ {% endwith %}
435
+ <form method="post" action="{{ base }}/settings/cluster/identity" class="inline mt-sm"
436
+ data-confirm="{{ _('Give this node a new identity? Everyone signed in to it is signed out (you stay signed in), and other nodes see it as a new node.') }}">
437
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
438
+ <button class="btn" type="submit">{{ _("Give this node a new identity") }}</button>
439
+ </form>
440
+ <p class="muted mt-sm">{{ _("For a node copied from another installation (its data folder, disk or VM image): a new cluster ID and a new session key, so the copies no longer hide each other in the cluster and a sign-in to one is not valid on the other.") }}</p>
441
+ </section>
442
+
443
+ <section class="panel panel-narrow" id="notifications">
444
+ <div class="panel-head"><h2>{{ _("Notifications") }}</h2></div>
445
+ {{ feedback('notifications') }}
446
+ <p class="muted mb-sm">{{ _("Get a message when something needs attention — to a chat (Slack, Microsoft Teams, Discord, Telegram, or any service that accepts a JSON webhook) and/or by e-mail. The same event for the same mapping is sent at most once per repeat interval.") }}</p>
447
+ <p class="muted mb-sm">{{ _("Messages go to the service you set here, which may be run in another country; the host name and the instance name are in every one.") }}</p>
448
+ {% with notify = submitted.notify or notify %}
449
+ <form method="post" action="{{ base }}/settings/notifications" class="authform">
450
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
451
+ <label class="chk"><input type="checkbox" name="notify_enabled" {% if notify.enabled %}checked{% endif %}> {{ _("Send notifications") }}</label>
452
+ <fieldset>
453
+ <legend>{{ _("Events") }}</legend>
454
+ {% set event_labels = {
455
+ 'device_lost': _("Serial device lost (unplugged, error, reconnecting)"),
456
+ 'device_back': _("Serial device back"),
457
+ 'start_failed': _("Mapping failed to start (e.g. port in use)"),
458
+ 'link_lost': _("Connect-out mapping can't reach its remote server"),
459
+ 'link_back': _("Connect-out mapping reaches its remote server again"),
460
+ 'client_connected': _("Client connected"),
461
+ 'client_disconnected': _("Client disconnected"),
462
+ 'login_failed': _("Failed sign-in to this UI"),
463
+ 'disk_low': _("Data disk almost full (traces pause)"),
464
+ 'no_data': _("No data from a serial device (a mapping’s no-data alarm, set in its options)"),
465
+ 'data_back': _("Data from that device again"),
466
+ 'peer_offline': _("Cluster node offline (not heard from, or a configured peer that doesn’t answer)"),
467
+ 'peer_back': _("Cluster node back"),
468
+ 'service_started': _("ser2netweb started (which mappings run)"),
469
+ 'unit_offline': _("Modbus unit stopped answering (a gateway's polling: no reply to any of its points in 3 polls in a row)"),
470
+ 'unit_back': _("Modbus unit answering again"),
471
+ } %}
472
+ {% set event_hints = {
473
+ 'client_connected': _("sends the client’s IP address"),
474
+ 'client_disconnected': _("sends the client’s IP address"),
475
+ 'login_failed': _("sends the account name, or “(unknown user)”, and the IP address"),
476
+ } %}
477
+ {% for e in notify_events %}
478
+ <label class="chk"><input type="checkbox" name="notify_event_{{ e }}" {% if e in notify.events %}checked{% endif %}> {{ event_labels[e] }}{% if e in event_hints %} <span class="muted">({{ event_hints[e] }})</span>{% endif %}</label>
479
+ {% endfor %}
480
+ <input type="hidden" name="notify_privacy_fields" value="1">
481
+ <label class="chk"><input type="checkbox" name="notify_mask_personal_data" {% if notify.mask_personal_data %}checked{% endif %}> {{ _("Leave out personal data: IP addresses only as their network (10.0.5.x; IPv6 /48), no account names") }}</label>
482
+ <label>{{ _("Repeat interval (minutes)") }} <span class="muted">({{ _("0 = every time") }})</span>
483
+ <input type="number" name="notify_repeat_min" min="0" max="1440" step="any" value="{{ '%g'|format(notify.repeat_s / 60) }}"></label>
484
+ </fieldset>
485
+ <fieldset>
486
+ <legend>Webhook</legend>
487
+ <div class="grid2">
488
+ <label>URL <span class="muted">({{ _("kept secret") }}{% if notify.webhook_url %}; {{ _("blank = unchanged") }}{% endif %})</span>
489
+ <input type="url" name="notify_webhook_url" autocomplete="off" spellcheck="false" data-1p-ignore data-lpignore="true" data-bwignore placeholder="{% if notify.webhook_url %}{{ unchanged }}{% else %}https://hooks.slack.com/services/…{% endif %}"></label>
490
+ <label>{{ _("Format") }}
491
+ <select name="notify_webhook_format">
492
+ {% set formats = {'json': _('JSON (generic)'), 'slack': 'Slack / Mattermost', 'teams': 'Microsoft Teams (Workflows)', 'discord': 'Discord', 'telegram': _('Telegram bot')} %}
493
+ {% for f in webhook_formats %}<option value="{{ f }}" {% if f == notify.webhook_format %}selected{% endif %}>{{ formats[f] }}</option>{% endfor %}
494
+ </select></label>
495
+ </div>
496
+ <div class="grid2">
497
+ <label>{{ _("Telegram chat ID") }} <span class="muted">({{ _("Telegram only; URL: https://api.telegram.org/bot&lt;token&gt;/sendMessage") }})</span>
498
+ <input type="text" name="notify_telegram_chat_id" value="{{ notify.telegram_chat_id }}"></label>
499
+ {% if notify.webhook_url %}<label class="chk chk-pad"><input type="checkbox" name="notify_webhook_clear"> {{ _("Remove the stored URL") }}</label>{% endif %}
500
+ </div>
501
+ </fieldset>
502
+ <fieldset>
503
+ <legend>{{ _("E-mail") }}</legend>
504
+ <div class="grid2">
505
+ <label>{{ _("To") }} <span class="muted">({{ _("comma-separated") }})</span><input type="text" name="notify_email_to" value="{{ notify.email_to }}" placeholder="ops@example.com"></label>
506
+ <label>{{ _("From") }} <span class="muted">({{ _("blank = ser2net@&lt;host&gt;") }})</span><input type="text" name="notify_email_from" value="{{ notify.email_from }}"></label>
507
+ </div>
508
+ <label class="chk"><input type="checkbox" name="notify_email_separately" {% if notify.email_separately %}checked{% endif %}> {{ _("Send each recipient a message of their own (they don’t see each other’s addresses)") }}</label>
509
+ <div class="grid3">
510
+ <label>{{ _("SMTP server") }} <input type="text" name="notify_smtp_host" value="{{ notify.smtp_host }}" placeholder="smtp.example.com"></label>
511
+ <label>{{ _("Port") }} <input type="number" name="notify_smtp_port" min="1" max="65535" value="{{ notify.smtp_port }}"></label>
512
+ <label>{{ _("Security") }}
513
+ <select name="notify_smtp_security">
514
+ {% set securities = {'starttls': 'STARTTLS (587)', 'ssl': 'TLS (465)', 'none': _('none (trusted network only)')} %}
515
+ {% for x in smtp_security %}<option value="{{ x }}" {% if x == notify.smtp_security %}selected{% endif %}>{{ securities[x] }}</option>{% endfor %}
516
+ </select></label>
517
+ </div>
518
+ <div class="grid2">
519
+ <label>{{ _("Username") }} <span class="muted">({{ _("optional") }})</span><input type="text" name="notify_smtp_username" value="{{ notify.smtp_username }}" autocomplete="off" autocapitalize="none" autocorrect="off" spellcheck="false"></label>
520
+ <label>{{ _("Password") }} <input type="password" name="notify_smtp_password" autocomplete="new-password" data-1p-ignore data-lpignore="true" data-bwignore placeholder="{% if notify.smtp_password %}{{ unchanged }}{% endif %}"></label>
521
+ </div>
522
+ {% if notify.smtp_security == 'none' and notify.smtp_username %}
523
+ <div class="banner warn">{{ _("With security “none”, the user name and password go to the mail server unencrypted. Choose STARTTLS or TLS unless the network to it is trusted.") }}</div>
524
+ {% endif %}
525
+ </fieldset>
526
+ <div class="row-actions start">
527
+ <button class="btn primary" type="submit">{{ _("Save notifications") }}</button>
528
+ <button class="btn" type="submit" name="then" value="test">{{ _("Save and send a test") }}</button>
529
+ </div>
530
+ </form>
531
+ {% endwith %}
532
+ </section>
533
+
534
+ <section class="panel panel-narrow" id="tls">
535
+ <div class="panel-head"><h2>{{ _("Admin TLS (HTTPS)") }}</h2></div>
536
+ {{ feedback('tls') }}
537
+ <p class="muted mb-sm">{{ _("Encrypts this management UI. A change applies to new connections at once (the files are read when you save, and again when ser2netweb reloads config.json); connections already open keep theirs.") }}</p>
538
+ {% set cert = tls_certificate %}
539
+ {% if cert and cert.problem == 'unreadable' %}<div class="banner warn">{{ _("The certificate file can’t be read (%(error)s): ser2netweb can’t start with TLS until it can.", error=cert.detail) }}</div>
540
+ {% elif cert and cert.problem == 'not_pem' %}<div class="banner warn">{{ _("The certificate file holds no PEM certificate: ser2netweb can’t start with TLS like this.") }}</div>
541
+ {% elif cert and cert.problem %}<p class="muted mb-sm">{{ _('Install the <span class="mono">cryptography</span> package to see the certificate’s details here.') }}</p>
542
+ {% elif cert %}
543
+ <p class="mb-sm">{{ _('Certificate: <span class="mono">%(subject)s</span>', subject=cert.subject|softbreak) }}{% if cert.self_signed %} <span class="tag">{{ _("self-signed") }}</span>{% endif %}
544
+ {% if cert.state == 'expired' %}<span class="tag tag-danger">{{ _("expired") }}</span>{% elif cert.state == 'not_yet_valid' %}<span class="tag tag-danger">{{ _("not valid yet") }}</span>{% elif cert.state == 'expiring' %}<span class="tag tag-warn">{{ ngettext("ends in %(num)s day", "ends in %(num)s days", cert.days) }}</span>{% else %}<span class="tag">{{ ngettext("%(num)s day left", "%(num)s days left", cert.days) }}</span>{% endif %}<br>
545
+ <span class="muted">{{ _("Valid from %(start)s to %(end)s UTC", start=cert.start, end=cert.end) }}{% if cert.names %} · {{ _("names: %(names)s", names=cert.names|softbreak) }}{% endif %}</span></p>
546
+ {% if cert.state == 'expired' %}<div class="banner warn">{{ _("By this server’s clock the certificate ended at %(end)s UTC: browsers and clients that check it refuse the connection. Renew it, or generate a new self-signed one.", end=cert.end) }}</div>
547
+ {% elif cert.state == 'not_yet_valid' %}<div class="banner warn">{{ _("The certificate starts at %(start)s UTC, later than this server’s clock reads: the clock is behind (see Admin interface), or the certificate was made while a clock was ahead. Clients whose clock reads earlier refuse it.", start=cert.start) }}</div>{% endif %}
548
+ {% endif %}
549
+ {% with admin = submitted.tls or admin %}
550
+ <form method="post" action="{{ base }}/settings/tls" class="authform">
551
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
552
+ <label>{{ _("Certificate path") }} <input type="text" name="tls_cert" value="{{ admin.tls_cert }}" placeholder="/path/cert.pem"></label>
553
+ <label>{{ _("Key path") }} <input type="text" name="tls_key" value="{{ admin.tls_key }}" placeholder="/path/key.pem"></label>
554
+ <label>{{ _("Key password") }} <span class="muted">({{ _("only for an encrypted key") }})</span>
555
+ <input type="password" name="tls_key_password" autocomplete="new-password" data-1p-ignore data-lpignore="true" data-bwignore placeholder="{% if admin.tls_key_password %}{{ unchanged }}{% else %}{{ _('optional') }}{% endif %}"></label>
556
+ {% if admin.tls_key_password %}<label class="chk"><input type="checkbox" name="tls_key_password_clear"> {{ _("Remove the stored password") }}</label>{% endif %}
557
+ <label>{{ _("HSTS max-age (seconds)") }} <span class="muted">({{ _("31536000 = one year, the default · 0 = off · applies at once") }})</span>
558
+ <input type="number" name="hsts_max_age" min="0" max="{{ hsts_max }}" step="1" value="{{ admin.hsts_max_age }}" required></label>
559
+ <p class="muted">{{ _("With TLS, browsers that trust the certificate and reach this UI by host name use only https:// for that name, on every port, for this long after each visit: other plain-HTTP or self-signed web pages on the same name stop opening there. Before turning TLS off, set 0 and let the users open this UI once.") }}</p>
560
+ <button class="btn primary" type="submit">{{ _("Save TLS") }}</button>
561
+ </form>
562
+ {% endwith %}
563
+ <form method="post" action="{{ base }}/settings/tls/generate" class="inline mt-sm"{% if admin.tls_cert %}
564
+ data-confirm="{{ _('Replace the certificate %(cert)s with a new self-signed one, from the next restart? Browsers warn about a new certificate until they are told to trust it.', cert=admin.tls_cert) }}"{% endif %}>
565
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
566
+ <button class="btn" type="submit">{{ _("Generate a self-signed certificate") }}</button>
567
+ </form>
568
+ </section>
569
+
570
+ <section class="panel panel-narrow" id="reverse-proxy">
571
+ <div class="panel-head"><h2>{{ _("Reverse proxy") }}</h2></div>
572
+ {{ feedback('reverse-proxy') }}
573
+ <p class="muted mb-sm">{{ _('Only for a reverse proxy (nginx, Apache, Caddy, Traefik, IIS) in front of this UI; <span class="mono">docs/REVERSE-PROXY.md</span> has examples. Changes apply at once.') }}</p>
574
+ {% with admin = submitted.proxy or admin %}
575
+ <form method="post" action="{{ base }}/settings/proxy" class="authform">
576
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
577
+ <label>{{ _("Public URL") }} <span class="muted">({{ _("the address users open, such as https://ser2netweb.example.com, or https://gw.example.com/ser2netweb to serve the UI under that path too · blank: none") }})</span>
578
+ {% if public_url_env %}<input type="url" value="{{ public_url }}" disabled>
579
+ {% else %}<input type="url" name="public_url" value="{{ admin.public_url }}" placeholder="https://ser2netweb.example.com" autocomplete="off" spellcheck="false" data-1p-ignore data-lpignore="true" data-bwignore>{% endif %}</label>
580
+ {% if public_url_env %}<p class="muted">{{ _('Set by <span class="mono">%(name)s</span> for this run; the field takes effect again once that is removed.', name=public_url_env) }}</p>{% endif %}
581
+ <label>{{ _("Trusted proxies") }} <span class="muted">({{ _("IP addresses or networks of the proxies, such as 127.0.0.1 or 172.18.0.0/16 · blank: none") }})</span>
582
+ {% if trusted_env %}<input type="text" value="{{ trusted[0]|join(' ') }}" disabled>
583
+ {% else %}<input type="text" name="trusted_proxies" value="{{ admin.trusted_proxies|join(' ') }}" autocomplete="off" spellcheck="false" data-1p-ignore data-lpignore="true" data-bwignore>{% endif %}</label>
584
+ {% if trusted_env %}<p class="muted">{{ _('Set by <span class="mono">%(name)s</span> for this run; the field takes effect again once that is removed.', name=trusted_env) }}</p>
585
+ {% elif trusted[1] == 'FORWARDED_ALLOW_IPS' %}<p class="muted">{{ _('<span class="mono">FORWARDED_ALLOW_IPS</span> gives <span class="mono">%(list)s</span> while this is blank.', list=trusted[0]|join(' ')) }}</p>{% endif %}
586
+ <p class="muted">{{ _("Only a connection from one of them may say who the client is (X-Forwarded-For: for the sign-in limits, the audit log and all.log) and that the browser used HTTPS (X-Forwarded-Proto). Without them every client behind a proxy has the proxy’s address.") }}</p>
587
+ <label class="chk"><input type="checkbox" name="proxy_hsts" {% if admin.proxy_hsts %}checked{% endif %}> {{ _("Send HSTS on HTTPS through the proxy") }}</label>
588
+ <p class="muted">{{ _("With the max-age set under Admin TLS: browsers then use only https:// for that host name, on every port, a direct http:// address of the same name included. The proxy can send it instead.") }}</p>
589
+ <p class="muted">{{ _("Pages at the public URL count as this UI’s own (forms, console), a blank SSO redirect URI becomes the public URL followed by %(path)s, and notifications link to it. With a path, the UI is served under it too (the proxy passes the path on, or strips it and sends it as X-Forwarded-Prefix), and its cookies there are its own: users sign in once more.", path='/auth/oidc/callback') }}</p>
590
+ <button class="btn primary" type="submit">{{ _("Save reverse proxy settings") }}</button>
591
+ </form>
592
+ {% endwith %}
593
+ </section>
594
+
595
+ <section class="panel panel-narrow" id="api-token">
596
+ <div class="panel-head"><h2>{{ _("REST API token") }}</h2></div>
597
+ {{ feedback('api-token') }}
598
+ <p class="muted mb-sm">{{ _('A bearer token for the JSON API at <span class="mono">/api/v1</span> (automation, Ansible, fleet tools). Send it as <span class="mono">Authorization: Bearer &lt;token&gt;</span>. Spec: <a href="%(url)s">openapi.json</a>.', url=base ~ '/api/v1/openapi.json') }}</p>
599
+ {% if new_api_token %}
600
+ <div class="banner ok">{{ _("New token (copy now — shown only once):") }}
601
+ <div class="mono token-box">{{ new_api_token }}</div>
602
+ <button type="button" class="btn sm mt-sm" data-copy>{{ _("Copy") }}</button>
603
+ </div>
604
+ {% endif %}
605
+ <p>{{ _("Status:") }}
606
+ {% if api_token_set %}<span class="tag">{{ _("enabled") }}</span> <span class="muted">{{ _('role: <span class="mono">%(role)s</span>', role=api_token_role) }} · {{ _("last used: %(time)s", time=api_token_last_used) }}</span>{% else %}<span class="tag">{{ _("disabled") }}</span>{% endif %}
607
+ </p>
608
+ <form method="post" action="{{ base }}/settings/api-token" class="inline">
609
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
610
+ <label>{{ _("Role") }} <span class="muted">({{ _("viewer = read-only") }})</span>
611
+ <select name="api_token_role">
612
+ {% set cur = api_token_role if api_token_set else 'admin' %}
613
+ {% for r in roles %}<option value="{{ r }}" {% if r == cur %}selected{% endif %}>{{ role_label(r) }}</option>{% endfor %}
614
+ </select>
615
+ </label>
616
+ {% if api_token_set %}
617
+ <button class="btn primary" type="submit"
618
+ data-confirm="{{ _('Replace the REST API token? Everything that uses the current one gets 401 until it is given the new one.') }}">{{ _("Regenerate token") }}</button>
619
+ {# the same token, another role: nothing that uses it has to change #}
620
+ <button class="btn" type="submit" formaction="{{ base }}/settings/api-token/role">{{ _("Change the role only") }}</button>
621
+ {% else %}
622
+ <button class="btn primary" type="submit">{{ _("Generate token") }}</button>
623
+ {% endif %}
624
+ </form>
625
+ {% if api_token_set %}
626
+ <form method="post" action="{{ base }}/settings/api-token/revoke" class="inline mt-sm"
627
+ data-confirm="{% if api_token_rows %}{{ _('Revoke the REST API token? Everything that uses it gets 401; the other tokens keep working.') }}{% else %}{{ _('Revoke the REST API token? The REST API is switched off, and everything that uses it gets 401.') }}{% endif %}">
628
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
629
+ <button class="btn" type="submit">{{ _("Revoke") }}</button>
630
+ </form>
631
+ {% endif %}
632
+ <h3 class="mt-sm">{{ _("More tokens") }}</h3>
633
+ <p class="muted mb-sm">{{ _('Give each client its own token: a read-only one for monitoring, one that may change mappings for automation. Each has a name — the audit log shows it as <span class="mono">api-token:NAME</span> — a role and, if you like, an expiry; revoking one leaves the others working. The token above works as before. When a token was last used is known since ser2netweb started.') }}</p>
634
+ {% if api_token_rows %}
635
+ <div class="table-scroll">
636
+ <table class="grid th-wrap">
637
+ <thead><tr><th>{{ _("Name") }}</th><th>{{ _("Role") }}</th><th></th></tr></thead>
638
+ <tbody>
639
+ {% for t in api_token_rows %}
640
+ <tr>
641
+ <td class="mono">{{ t.name }}{% if t.expired %} <span class="tag">{{ _("expired") }}</span>{% endif %}<br><span class="muted">{{ _("created %(date)s", date=t.created) }} · {% if t.expires %}{{ _("expires %(date)s", date=t.expires) }}{% else %}{{ _("never expires") }}{% endif %} · {{ _("last used: %(time)s", time=t.last_used) }}</span></td>
642
+ <td class="mono">{{ t.role }}</td>
643
+ <td>
644
+ <form method="post" action="{{ base }}/settings/api-tokens/revoke" class="inline"
645
+ data-confirm="{{ _('Revoke the token “%(name)s”? Everything that uses it gets 401; the other tokens keep working.', name=t.name) }}">
646
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
647
+ <input type="hidden" name="id" value="{{ t.id }}">
648
+ <button class="btn sm danger" type="submit">{{ _("Revoke") }}</button>
649
+ </form>
650
+ </td>
651
+ </tr>
652
+ {% endfor %}
653
+ </tbody>
654
+ </table>
655
+ </div>
656
+ {% endif %}
657
+ {% if api_token_rows|length < api_token_max %}
658
+ {% set nt = submitted.new_token or {} %}
659
+ <form method="post" action="{{ base }}/settings/api-tokens" class="authform">
660
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
661
+ <div class="grid2">
662
+ <label>{{ _("Name") }} <input type="text" name="name" value="{{ nt.name }}" placeholder="{{ _('e.g. %(example)s', example='prometheus') }}" autocapitalize="none" autocorrect="off" spellcheck="false" maxlength="64" pattern="[A-Za-z0-9._\-]{1,64}" title="{{ _("A token name is 1-64 characters: English letters, digits, '.', '_' or '-'.") }}" required></label>
663
+ <label>{{ _("Role") }} <span class="muted">({{ _("viewer = read-only") }})</span>
664
+ <select name="role"><option value="viewer"{% if nt.role != 'operator' %} selected{% endif %}>viewer</option><option value="operator"{% if nt.role == 'operator' %} selected{% endif %}>operator</option></select>
665
+ </label>
666
+ </div>
667
+ <label>{{ _("Expires after (days)") }} <span class="muted">({{ _("empty or 0 = never · at most %(max)s", max=api_token_days_max) }})</span>
668
+ <input type="number" name="expires_days" min="0" max="{{ api_token_days_max }}" value="{{ nt.expires_days }}">
669
+ </label>
670
+ <button class="btn" type="submit">{{ _("Add token") }}</button>
671
+ </form>
672
+ {% endif %}
673
+ </section>
674
+ {% endif %}
675
+
676
+ {% if is_operator %}
677
+ <section class="panel panel-narrow" id="import">
678
+ <div class="panel-head"><h2>{{ _("Mappings export / import") }}</h2></div>
679
+ {{ feedback('import') }}
680
+ <p><a class="btn" href="{{ base }}/settings/config/export">{{ _("⤓ Export mappings (JSON)") }}</a></p>
681
+ <p class="muted mb-sm">{{ _("The export holds each mapping’s MQTT broker password in plain text: keep the file as safe as a password.") }}</p>
682
+ {% if import_preview %}
683
+ {% set p = import_preview %}
684
+ <h3>{{ _("Import preview") }} <span class="muted">— {{ ngettext("%(num)s mapping from a %(source)s, mode: %(mode)s", "%(num)s mappings from a %(source)s, mode: %(mode)s", p.count, source=p.source, mode=_("merge") if p.mode == 'merge' else _("replace")) }}</span></h3>
685
+ {% for w in p.warnings %}<div class="banner warn">{{ w }}</div>{% endfor %}
686
+ {% if p.problem %}<div class="banner error" role="alert">{{ _("This import can’t be applied: %(problem)s", problem=p.problem) }}</div>{% endif %}
687
+ <div class="table-scroll">
688
+ <table class="grid import-preview stackable">
689
+ <thead><tr><th>{{ _("Mapping") }}</th><th>{{ _("Port / network") }}</th><th>{{ _("After import") }}</th><th>{{ _("Change") }}</th></tr></thead>
690
+ <tbody>
691
+ {% for r in p.rows %}
692
+ <tr{% if r.notes %} class="has-notes"{% endif %}>
693
+ <td class="col-name">{{ r.name|softbreak }}</td>
694
+ <td class="mono" data-label="{{ _('Port / network') }}">{{ r.kind|softbreak }}</td>
695
+ <td{% if r.after %} data-label="{{ _('After import') }}"{% endif %}>
696
+ {%- if r.after %}{% set a = r.after %}
697
+ {%- if a.enabled %}<span class="muted">{{ _("enabled") }}</span>{% else %}<span class="tag">{{ _("disabled") }}</span>{% endif %}
698
+ {%- if a.tls %} <span class="tag">TLS</span>{% endif %}
699
+ {%- if a.read_only %} <span class="tag" title="{{ _('read-only') }}">RO</span>{% endif %}
700
+ {%- if a.clients is not none %} <span class="tag{% if a.open %} tag-warn{% endif %}">{% if a.clients %}{{ ngettext("%(num)s allowed address", "%(num)s allowed addresses", a.clients) }}{% else %}{{ _("any client") }}{% endif %}</span>{% endif %}
701
+ {%- endif %}
702
+ </td>
703
+ <td data-label="{{ _('Change') }}">
704
+ {% if r.action == 'add' %}<span class="tag">{{ _("new") }}</span>
705
+ {% elif r.action == 'update' %}<span class="tag">{{ _("updates") }}</span>{% if r.target != r.name %} <span class="muted">“{{ r.target }}”</span>{% endif %}
706
+ {% elif r.action == 'same' %}<span class="muted">{{ _("unchanged") }}</span>
707
+ {% else %}<span class="tag tag-danger">{{ _("removed") }}</span>{% endif %}
708
+ {%- if r.changes %}<ul class="cell-list">{% for c in r.changes %}<li{% if c.security %} class="security"{% endif %}>{% if c.security %}⚠ {% endif %}{% if c.kept %}{{ _("%(what)s: %(value)s is kept (the file has %(file)s)", what=c.what, value=c.before, file=c.file) }}{% else %}{{ c.what }}: {{ c.before }} → {{ c.after }}{% endif %}</li>{% endfor %}</ul>{% endif %}
709
+ </td>
710
+ </tr>
711
+ {%- if r.notes %}
712
+ <tr class="notes-row"><td colspan="4"><ul class="cell-list">{% for n in r.notes %}<li{% if n.security %} class="security"{% endif %}>{% if n.security %}⚠ {% endif %}{{ n.text }}</li>{% endfor %}</ul></td></tr>
713
+ {%- endif %}
714
+ {% endfor %}
715
+ </tbody>
716
+ </table>
717
+ </div>
718
+ <form method="post" action="{{ base }}/settings/config/import/apply" class="inline mt-sm">
719
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
720
+ <input type="hidden" name="token" value="{{ p.token }}">
721
+ <input type="hidden" name="mode" value="{{ p.mode }}">
722
+ <button class="btn primary" type="submit" {% if p.problem %}disabled{% endif %}>{{ _("Apply import") }}</button>
723
+ </form>
724
+ <a class="btn mt-sm" href="{{ base }}/settings#import">{{ _("Cancel") }}</a>
725
+ {% else %}
726
+ <form method="post" action="{{ base }}/settings/config/import" enctype="multipart/form-data" class="authform">
727
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
728
+ <input type="hidden" name="step" value="preview">
729
+ <label>{{ _("Mappings file") }} <span class="muted">({{ _('a ser2netweb export or config.json — or a classic ser2net <span class="mono">ser2net.yaml</span> / <span class="mono">ser2net.conf</span> to migrate from') }})</span>
730
+ <input type="file" name="file" accept="application/json,.json,.yaml,.yml,.conf,text/plain" required>
731
+ </label>
732
+ <label class="chk"><input type="radio" name="mode" value="merge" checked> {{ _("Merge — update mappings with the same name, add the others, keep the rest") }}</label>
733
+ <label class="chk"><input type="radio" name="mode" value="replace"> {{ _("Replace — the file’s mappings replace all current ones") }}</label>
734
+ <button class="btn" type="submit">{{ _("Preview import") }}</button>
735
+ </form>
736
+ <p class="muted mt-sm">{{ _("Nothing changes until you apply the preview. The current configuration is kept as a backup either way.") }}</p>
737
+ <p class="muted">{{ _('Moving from the classic ser2net (stop its service first; ports below 1024; what works differently): <span class="mono">docs/MIGRATING-FROM-SER2NET.md</span>.') }}</p>
738
+ {% endif %}
739
+ </section>
740
+ {% endif %}
741
+
742
+ {% if is_admin %}
743
+ <section class="panel panel-narrow" id="backups">
744
+ <div class="panel-head"><h2>{{ _("Configuration backups") }}</h2></div>
745
+ {{ feedback('backups') }}
746
+ <p class="muted mb-sm">{{ _('Every change keeps the <span class="mono">config.json</span> it writes in the data folder’s <span class="mono">backups/</span>, and the one it replaces if that isn’t there yet (the newest 50; the one in use is marked), so the current configuration is kept there too, also when an older version takes over. Starting or stopping a mapping takes no backup of its own (the newest one is updated), so it doesn’t push out the backups of real changes. Restoring one brings back its mappings and settings after showing what changes for sign-in and access; the user accounts, the REST API token and the cluster key stay as they are unless you restore them too. A restore can be undone. Backups contain password hashes and secrets: only admins see them, and a download leaves out the session key.') }}</p>
747
+ {% if outside_edit %}<div class="banner warn">{{ _('config.json was changed outside ser2netweb (%(time)s) and is not in use: reload it to apply it. A change saved here before that replaces it; the edited file is then kept in the backups below.', time=outside_edit) }}</div>{% endif %}
748
+ {% if outside_gone %}<div class="banner warn">{{ _('config.json is gone from the data folder: ser2netweb goes on with the configuration in use and writes it again at the next change.') }}</div>{% endif %}
749
+ {% if replaced_edit and replaced_edit.backup %}<div class="banner warn">{{ _('A change saved at %(saved)s replaced a config.json edited outside ser2netweb (%(edited)s). The edited file is kept as <span class="mono">%(backup)s</span>: <a href="%(link)s">restore it</a> to use it.', saved=replaced_edit.saved, edited=replaced_edit.edited, backup=replaced_edit.backup, link=base ~ '/settings?restore=' ~ replaced_edit.backup ~ '#backups') }}</div>
750
+ {% elif replaced_edit %}<div class="banner warn">{{ _('A change saved at %(saved)s replaced a config.json edited outside ser2netweb (%(edited)s); its backup could not be written (all.log says why).', saved=replaced_edit.saved, edited=replaced_edit.edited) }}</div>{% endif %}
751
+ <form method="post" action="{{ base }}/settings/config/reload" class="authform mb-sm">
752
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
753
+ <p class="muted mb-sm">{{ _('<span class="mono">config.json</span> changed by hand or by a tool (Ansible …) is used once ser2netweb reads it again: here, with <span class="mono">ser2netweb --reload</span>, or on Linux with SIGHUP (<span class="mono">systemctl reload ser2netweb</span>). Mappings whose settings didn’t change keep running with their clients; certificate files are read again. A file that doesn’t validate changes nothing (all.log says why); a new admin UI address waits for the next start.') }}</p>
754
+ <button class="btn" type="submit">{{ _("Reload config.json") }}</button>
755
+ </form>
756
+ {% if newer_writer %}<div class="banner warn">{{ _('At start-up, config.json had been written by ser2netweb %(newer)s, a newer version than this one (%(this)s). What only that version knows is not used here, and it is left out when this version saves config.json. The backups below keep the file as that version left it: restore it after upgrading again.', newer=newer_writer, this=app_version) }}</div>{% endif %}
757
+ {% if unknown_keys %}<div class="banner warn">{{ _('At start-up, config.json had settings this version doesn’t know: %(keys)s. They are not used here, and they are left out when config.json is saved; the backups below keep the file with them.', keys=(unknown_keys[:10] | join(', ')) ~ (' …' if unknown_keys | length > 10 else '')) }}</div>{% endif %}
758
+ {% if restore_preview %}
759
+ {% set rp = restore_preview %}
760
+ <h3 class="mt-sm">{{ _("Restore the configuration saved at %(time)s UTC", time=rp.time) }}</h3>
761
+ {% if rp.settings %}
762
+ <p class="mb-sm">{{ _("Sign-in and access settings it changes:") }}</p>
763
+ <ul>{% for line in rp.settings %}<li>{{ line }}</li>{% endfor %}</ul>
764
+ {% else %}
765
+ <p class="muted mb-sm">{{ _("It changes no sign-in or access setting.") }}</p>
766
+ {% endif %}
767
+ <form method="post" action="{{ base }}/settings/backups/restore" class="authform mb-sm">
768
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
769
+ <input type="hidden" name="name" value="{{ rp.name }}">
770
+ <label class="chk"><input type="checkbox" name="accounts" {% if not rp.accounts_ok %}disabled{% endif %}> {{ _("Also restore its user accounts, REST API token and cluster key (everyone else is signed out)") }}</label>
771
+ {% if rp.accounts %}<ul class="muted">{% for line in rp.accounts %}<li>{{ line }}</li>{% endfor %}</ul>
772
+ {% elif rp.accounts_ok %}<p class="muted">{{ _("Its accounts and credentials are the same as now.") }}</p>{% endif %}
773
+ {% for note in rp.notes %}<div class="banner warn">{{ note }}</div>{% endfor %}
774
+ <div class="row-actions start">
775
+ <button class="btn primary" type="submit">{{ _("Restore") }}</button>
776
+ <button class="btn" type="submit" formaction="{{ base }}/settings/backups/restore-mappings">{{ _("Only its mappings…") }}</button>
777
+ <a class="btn" href="{{ base }}/settings#backups">{{ _("Cancel") }}</a>
778
+ </div>
779
+ </form>
780
+ {% endif %}
781
+ {% if backups %}
782
+ <div class="table-scroll">
783
+ <table class="grid th-wrap">
784
+ <thead><tr><th>{{ _("Saved (UTC)") }}</th><th>{{ _("Contents") }}</th><th class="col-actions"></th></tr></thead>
785
+ <tbody>
786
+ {% for bk in backups %}
787
+ <tr>
788
+ <td class="mono">{{ bk.time }}</td>
789
+ <td>{{ _("%(mappings)s mappings, %(users)s users", mappings=bk.mappings if bk.mappings is not none else '?', users=bk.users if bk.users is not none else '?') }}<br><span class="muted">{{ _("written by ser2netweb %(version)s", version=bk.written_by) if bk.written_by else _("written by 2.8.1 or older") }}</span>{% if bk.file_time %}<br><span class="muted">{{ _("saved at %(time)s UTC, when the clock was behind the newest backup", time=bk.file_time) }}</span>{% endif %}{% if bk.current %} <span class="tag">{{ _("in use") }}</span>{% endif %}
790
+ {% if bk.accounts %}<details class="muted"><summary>{{ _("Accounts") }}</summary><span class="mono">{% for a in bk.accounts %}{{ a.username }} ({{ a.role }}{% if a.source != 'local' %}, {{ a.source|upper }}{% endif %}){% if not loop.last %}, {% endif %}{% endfor %}</span></details>{% endif %}</td>
791
+ <td class="col-actions">
792
+ <div class="row-actions">
793
+ <a class="btn sm" href="{{ base }}/settings/backups/{{ bk.name }}">{{ _("Download") }}</a>
794
+ <a class="btn sm" href="{{ base }}/settings?restore={{ bk.name }}#backups">{{ _("Restore…") }}</a>
795
+ <form method="post" action="{{ base }}/settings/backups/delete" class="inline"
796
+ data-confirm="{{ _('Delete the backup of %(time)s UTC? This can’t be undone.', time=bk.time) }}">
797
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
798
+ <input type="hidden" name="name" value="{{ bk.name }}">
799
+ <button class="btn sm danger" type="submit">{{ _("Delete") }}</button>
800
+ </form>
801
+ </div>
802
+ </td>
803
+ </tr>
804
+ {% endfor %}
805
+ </tbody>
806
+ </table>
807
+ </div>
808
+ {% if backup_gone_accounts %}
809
+ <form method="post" action="{{ base }}/settings/backups/remove-account" class="authform mt-sm"
810
+ data-confirm="{{ _('Remove this account from every backup that has it? A restore can then no longer bring it back, and this can’t be undone.') }}">
811
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
812
+ <p class="muted mb-sm">{{ _("Deleting a user leaves the account, with its password hash, in the backups made before. These backups hold accounts that no longer exist; removing one from them leaves everything else in each backup as it was.") }}</p>
813
+ <label>{{ _("Account no longer in use") }}
814
+ <select name="username">{% for name in backup_gone_accounts %}<option value="{{ name }}">{{ name }}</option>{% endfor %}</select>
815
+ </label>
816
+ <button class="btn" type="submit">{{ _("Remove it from the backups") }}</button>
817
+ </form>
818
+ {% endif %}
819
+ <form method="post" action="{{ base }}/settings/backups/delete" class="authform mt-sm"
820
+ data-confirm="{{ _('Delete every configuration backup? This can’t be undone.') }}">
821
+ <input type="hidden" name="_csrf" value="{{ request.state.csrf_token }}">
822
+ <input type="hidden" name="all" value="on">
823
+ <button class="btn danger" type="submit">{{ _("Delete all backups") }}</button>
824
+ </form>
825
+ {% else %}
826
+ <p class="muted">{{ _("No backups yet — the first one is made at the next configuration change.") }}</p>
827
+ {% endif %}
828
+ </section>
829
+ {% endif %}
830
+ {% endblock %}