diff --git a/README.md b/README.md index 30e82cf..96f766a 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,8 @@ contact ~ben or sose on tilde.chat (in the #slbr channel) to sign up. ## TODO - Install-time configuration (setting proper ips, hostname, etc.) +- Fix user tracking +======= - A goal and a way to check it This is a ~ work in progress ~ diff --git a/deluser.sh b/deluser.sh index 926ada7..b9cf7dd 100755 --- a/deluser.sh +++ b/deluser.sh @@ -1,6 +1,8 @@ #!/bin/sh SLBRUSER=$1 test -z "$SLBRUSER" && echo "no user provided" && exit +grep -qv "$SLBRUSER" users.txt && echo "user not found in users.txt, will not delete" && exit + if ps -o stat= -p $PPID | grep -qv S+ #check if this is being called from listen.py then echo "YOU ARE ABOUT TO PERMANENTLY DELETE USER $SLBRUSER AND ALL OF THEIR DATA. RE-ENTER THE USERS NAME TO CONTINUE" @@ -11,5 +13,5 @@ lxc stop "$SLBRUSER" lxc delete "$SLBRUSER" sudo rm -rf "$SLBRUSER" sudo userdel "$SLBRUSER" -tr '\n' ' ' < users | sed "s/$SLBRUSER //" | tr ' ' '\n' > users.temp +tr '\n' ' ' < users.txt | sed "s/$SLBRUSER//g" | tr ' ' '\n' > users.temp mv users.temp users diff --git a/listen.py b/listen.py index 4a3411c..4f115a7 100755 --- a/listen.py +++ b/listen.py @@ -24,11 +24,17 @@ def clientthread(conn): os.system("./sendmsg.sh \"$(tail -n1 gamelog.txt)\"") # oh noooooo print("sent message: " + message) - userisdead = ( - True - ) # Eventually add a check to differentiate death messages from other messages + userisdead = False + deaduser = message.split(" ")[0] + + print("Looking for user in userfile") + with open("users.txt") as userfile: + if deaduser in userfile.read(): + userisdead = True + else: + print("could not find user in userfile, will not delete") + if userisdead: - deaduser = message.split(" ")[0] print("eliminating " + deaduser) os.system("./deluser.sh " + deaduser) conn.close() diff --git a/newuser.sh b/newuser.sh index e0dbd02..a40eecf 100755 --- a/newuser.sh +++ b/newuser.sh @@ -2,13 +2,17 @@ SLBRUSER=$1 PUBKEY=$2 test -z "$SLBRUSER" && echo "no user provided" && exit +test -z "$PUBKEY" && echo "no key provided" && exit +PUBKEY="$(cat "$PUBKEY")" + +cut -d: -f1 /etc/passwd | grep -q "$SLBRUSER" && echo "user already exists" && exit echo "Creating homedir..." mkdir "/home/slbr/$SLBRUSER" mkdir "/home/slbr/$SLBRUSER/.ssh" echo "Copying key..." echo "$PUBKEY" >> "/home/slbr/$SLBRUSER/.ssh/authorized_keys" -echo "$SLBRUSER" >> users +echo "$SLBRUSER" >> users.txt echo "Creating container..." echo "lxc exec $SLBRUSER bash" > "/home/slbr/$SLBRUSER/.profile" chmod -w "/home/slbr/$SLBRUSER/.profile" diff --git a/users b/users deleted file mode 100644 index e69de29..0000000 diff --git a/users.txt b/users.txt new file mode 100644 index 0000000..4db90f4 --- /dev/null +++ b/users.txt @@ -0,0 +1 @@ +testuser