about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authoradmins <admins@tilde.institute>2020-05-21 01:19:09 -0400
committeradmins <admins@tilde.institute>2020-05-21 01:19:09 -0400
commit7803adbd089082efe8c55d0a50071bb08844eb6c (patch)
tree62633a4a69e373933f7b169bbeb5cb93a25b8526
parent24595a69c6eed2c50129b5a59c4f033a65aeb143 (diff)
downloadadmin-7803adbd089082efe8c55d0a50071bb08844eb6c.tar.gz
fixed username truncation properly
-rwxr-xr-xbin/connusers.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/bin/connusers.py b/bin/connusers.py
index 998669b..ebdde7f 100755
--- a/bin/connusers.py
+++ b/bin/connusers.py
@@ -3,6 +3,10 @@
 # Lists currently connected users for https://tilde.institute/stats
 # gbmor <ben@gbmor.dev>
 
+# 'ps' truncates usernames at 8 characters (called by 'showwhoison' to find mosh users)
+# so I'm matching the potentially-partial username to a home directory to retrieve
+# the full username.
+
 from sys import exit
 import subprocess
 
@@ -13,20 +17,19 @@ def checkconns():
         print("Can't access connected user table. Who are you?")
         exit(0)
 
-    connusers = list(set(subprocess.check_output("/usr/local/bin/showwhoison | sed -n '1!p'; exit 0", stderr=subprocess.STDOUT,shell=True).decode().split("\n")))
+    connusers = sorted(list(subprocess.check_output("/usr/local/bin/showwhoison | sed -n '1!p'; exit 0", stderr=subprocess.STDOUT,shell=True).decode().split("\n")))
     conntable.write("<ul>\n")
 
+    lastusers = list(subprocess.check_output("/bin/ls /home", stderr=subprocess.STDOUT,shell=True).decode().split("\n"))
+
     seen = set()
     for conns in connusers:
         split = conns.split(' ')
         for conn in split:
             if conn != "" and conn != " " and conn != "root" and conn not in seen:
-                # this needs to be fixed. truncates long usernames
-                # resulting in broken links to their pages. thanks, ps(1)
-                if conn == "sarmonsi":
-                    conn = "sarmonsiill"
                 seen.add(conn)
-                conntable.write("<li><a href=\"https://"+ conn +".tilde.institute\">"+ conn +"</a></li>\n")
+                match = ''.join([s for s in lastusers if conn in s])
+                conntable.write("<li><a href=\"https://"+ match +".tilde.institute\">"+ match +"</a></li>\n")
 
 
     conntable.write("</ul>\n")