From 540387955eb9ef2118c9d05a558dca4146fe7246 Mon Sep 17 00:00:00 2001 From: steering7253 Date: Wed, 8 Apr 2026 08:15:20 +0000 Subject: oops, forgot to change the AS... --- autopeer_shell.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/autopeer_shell.py b/autopeer_shell.py index 1670eb3..c891e63 100755 --- a/autopeer_shell.py +++ b/autopeer_shell.py @@ -1,9 +1,8 @@ #!/usr/bin/python3 #TODO: capture ^C during commands -#TODO: cronjob to generate config files from database -import cmd, functools, getpass, os, re, sys, time +import cmd, functools, getpass, os, re, subprocess, sys, time try: import readline except: pass @@ -12,9 +11,24 @@ from config import * from lib_autopeer import * def as_from_user(which=None): - # TODO: get list of user's maintained ASes - # from their MNTNER - user_ases=[4242422452] + if which is not None: + try: + which = int(which) + except: + raise Exception('your AS number has to be a number, silly') + + user_ases=[] + if not re.match(r'^[a-zA-Z0-9-]+$', MNTNER): + raise Exception('your mntner name has bad characters') + filenames = subprocess.run(['grep', '-l', '-r', '-P', fr'^\s*mnt-by:\s*{MNTNER}\s*$', '/opt/autopeer/dn42-registry/data/aut-num'], capture_output=True, text=True).stdout + for filename in filenames.split('\n'): + if not len(filename): + continue + if (mo := re.match(r'^.*/?AS(\d+)$', filename)): + user_ases.append(int(mo.group(1))) + else: + print(f"oops, something went wrong getting your ASes, specifically: {filename}", file=sys.stderr) + if which is None: return user_ases[0] elif which in user_ases: @@ -45,7 +59,11 @@ SELECTED_ASN = as_from_user() class AutopeerShell(cmd.Cmd): def preloop(self): self.intro = f'Welcome to the autopeer shell. Type help or ? to list commands.\nSelected AS: {SELECTED_ASN}' - self.prompt = f'{getpass.getuser()}@{socket.gethostname()}> ' + self.prompt = f'{getpass.getuser()}@{socket.gethostname()}:{SELECTED_ASN}> ' + + def postcmd(self, stop, line): + self.prompt = f'{getpass.getuser()}@{socket.gethostname()}:{SELECTED_ASN}> ' + return stop @parse(0) def do_ls(self): -- cgit v1.3.1-10-gc9f91