feat: rebranded from vpn-router to linux-manager.

This commit is contained in:
slawek committed 2026-11-22 09:51:07 +01:00
1 parent 8efe21bfa6
commit 85a1ffa21f
238 files changed
+5010 -3761

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
#!/usr/bin/python3
"""The auth proxy of rclone's WebDAV server of the web sites' folders (linux-manager-webdav.service).
rclone runs it for each new user and password with {"user", "pass"} on standard input. The user signs in with the
password of the server's directory, followed by the TOTP code for an enrolled user. A member of
linuxmanager_users.ADMIN_GROUP sees the folders of all sites, any other user those of the sites whose editors group
the user is a member of (linuxmanager_sites.editable), each as a folder named after its site. The answer on standard output
is rclone's combine backend of those folders; a failed sign-in, a user with no site or any failure is a message on
standard error and the exit status 1, which rclone refuses the user with.
"""
import json
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
import ldap
import linuxmanager_ldap
import linuxmanager_sites
import linuxmanager_users
def main():
try:
request = json.load(sys.stdin)
name, password = request['user'], request['pass']
linuxmanager_users.login(name, password, None)
connection = linuxmanager_ldap.manager()
try:
groups = linuxmanager_users.groups_of(connection, name)
finally:
connection.unbind_s()
if linuxmanager_users.ADMIN_GROUP in groups:
sites = [site['name'] for site in linuxmanager_sites.listing()]
else:
sites = linuxmanager_sites.editable(groups)
except (ValueError, KeyError, TypeError, OSError, ldap.LDAPError, linuxmanager_users.Failure,
linuxmanager_sites.DatabaseError) as exc:
sys.exit(f'webdav-auth: refused: {exc}')
if not sites:
sys.exit(f'webdav-auth: refused: {name} may change no site')
linuxmanager_sites.ensure_folders(sites)
upstreams = ' '.join(f'{site}={linuxmanager_sites.SITES_DIR / site}' for site in sites)
json.dump({'type': 'combine', '_root': '', 'upstreams': upstreams}, sys.stdout)
return 0
if __name__ == '__main__':
sys.exit(main())