feature: the VPN, the router, the name server and WebDAV are components switched on the System tab and installed on demand, Caddy from the Ubuntu archive is a dependency and serves every HTTP and HTTPS port, HTTPS is chosen at install, its certificate is of the Servers Issuing CA or self-signed by default, of ACME or of another CA, the issuing CAs are in one tab, a locked account is unlocked again, the name of a CA is fixed once the CA exists, and a run of setup is no longer cut short by a change.
Release / release (push) Failing after 8s

This commit is contained in:
slawek committed 2026-11-24 05:51:27 +01:00
1 parent a649331aa2
commit a7bfabcb89
97 files changed
+4498 -1834

No files matched your search

+31 -12
View File
@@ -1,11 +1,14 @@
#!/usr/bin/env python3
"""An authenticator app on the command line: make a TOTP secret or print its current code: otp.py new|code.
The secret, base32, is kept in the file --secret-file or OTP_FILE names, readable by its owner
only. new makes a new secret of 20 random bytes in that file, refusing to replace one without
--force, and prints its otpauth URI, labelled with --account and --issuer when given. code prints
the code of the secret now, or at the Unix time --at. The codes are RFC 6238's, with --algorithm
(sha1 by default), --digits (6) and --period (30 seconds).
The secret is kept in the file --secret-file or OTP_FILE names, readable by its owner only, as
nothing but its base32 secret, or with --url as its otpauth URI, each without a line end, so the
file is a value Vault's TOTP engine imports as it is (key=@FILE or url=@FILE). new makes a new
secret of 20 random bytes in that file, refusing to replace one without --force, and prints its
otpauth URI, labelled with --account and --issuer when given. code prints the code of the secret
now, or at the Unix time --at, from either form of the file. The codes are RFC 6238's, with
--algorithm (sha1 by default), --digits (6) and --period (30 seconds); a file holding an otpauth
URI gives those of the URI instead.
"""
import argparse
@@ -33,17 +36,30 @@ def code_of(secret, now=None, digits=6, period=30, algorithm='sha1'):
return f'{value % 10 ** digits:0{digits}d}'
def stored(text, digits, period, algorithm):
"""The secret, digits, period and algorithm of the file's text: a base32 secret with the given settings, or an
otpauth URI with its own, the given ones where it has none."""
if not text.startswith('otpauth://'):
return text, digits, period, algorithm
query = {name: values[0] for name, values in urllib.parse.parse_qs(urllib.parse.urlsplit(text).query).items()}
found = query.get('algorithm', algorithm).lower()
if found not in ALGORITHMS:
sys.exit(f'the otpauth URI has the unknown algorithm {found}')
return query.get('secret', ''), int(query.get('digits', digits)), int(query.get('period', period)), found
def main():
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
parser.add_argument('action', choices=('new', 'code'))
parser.add_argument('--secret-file', default=os.environ.get('OTP_FILE'),
help='the file of the base32 secret (OTP_FILE)')
help='the file of the base32 secret or its otpauth URI (OTP_FILE)')
parser.add_argument('--algorithm', choices=ALGORITHMS, default='sha1', help='the HMAC hash (default sha1)')
parser.add_argument('--digits', type=int, default=6, help='the digits of a code (default 6)')
parser.add_argument('--period', type=int, default=30, help='the seconds a code is valid (default 30)')
parser.add_argument('--at', type=float, help='code: the Unix time of the code instead of now')
parser.add_argument('--account', help='new: the account name in the otpauth URI')
parser.add_argument('--issuer', help='new: the issuer in the otpauth URI')
parser.add_argument('--url', action='store_true', help='new: store the otpauth URI instead of the secret alone')
parser.add_argument('--force', action='store_true', help='new: replace an existing secret')
args = parser.parse_args()
if not args.secret_file:
@@ -55,21 +71,24 @@ def main():
if args.action == 'code':
if not secret_file.is_file():
sys.exit(f'no {secret_file}; make a secret with new')
print(code_of(secret_file.read_text(encoding='utf-8').strip(), args.at, args.digits, args.period, args.algorithm))
secret, digits, period, algorithm = stored(secret_file.read_text(encoding='utf-8').strip(), args.digits,
args.period, args.algorithm)
print(code_of(secret, args.at, digits, period, algorithm))
return
if secret_file.exists() and not args.force:
sys.exit(f'{secret_file} exists; give --force to replace its secret')
secret = base64.b32encode(secrets.token_bytes(20)).decode()
secret_file.parent.mkdir(parents=True, exist_ok=True)
secret_file.touch(mode=0o600)
secret_file.chmod(0o600)
secret_file.write_text(f'{secret}\n', encoding='utf-8')
label = urllib.parse.quote(':'.join(part for part in (args.issuer, args.account) if part) or 'otp')
query = {'secret': secret, 'algorithm': args.algorithm.upper(), 'digits': args.digits, 'period': args.period}
if args.issuer:
query['issuer'] = args.issuer
print(f'otpauth://totp/{label}?{urllib.parse.urlencode(query)}')
uri = f'otpauth://totp/{label}?{urllib.parse.urlencode(query)}'
secret_file.parent.mkdir(parents=True, exist_ok=True)
secret_file.touch(mode=0o600)
secret_file.chmod(0o600)
secret_file.write_text(uri if args.url else secret, encoding='utf-8')
print(uri)
if __name__ == '__main__':