Completed user generation script

This commit is contained in:
Elizabeth Cray 2022-06-26 02:40:39 +00:00
parent 0f7aa1d448
commit 49220107c2
6 changed files with 86 additions and 5 deletions

View File

@ -1,4 +1,4 @@
# Hackers Town Tilde User Generator
# Hackers Town Server User Generator
use Mastodon oauth to generate system users

View File

@ -63,13 +63,13 @@ if(!validateUsername($User->username)){
error("Invalid Username");
}
// Create temporary pubkey holding file
$TempFileName = "/tmp/mkuser/".uniqid("ssh-", true).".pub";
$TempFileName = "/etc/ttyserver/tmp/".uniqid("ssh-", true).".pub";
if(!file_put_contents($TempFileName, $pubkey."\n")){
error("Key Addition Failed: Temp");
}
// Run User Generation Tool
// TODO: Replace with custom Rust PHP Extension
$UserGenCode = shell_exec("/etc/ttyserver/bin/mkuser.tmp \"".$User->username."\" \"".$TempFileName."\" 2>&1; echo $?");
$UserGenCode = shell_exec("/usr/bin/sudo /etc/ttyserver/bin/mkuser \"".$User->username."\" \"".$TempFileName."\" 2>&1; echo $?");
if($UserGenCode != "0"){
error("Key Addition Failed: MK-".$UserGenCode);
}

11
auth/~liz/.ssh/authorized_keys Executable file
View File

@ -0,0 +1,11 @@
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCrVG2rZuVS3O7KoWw8oN1wsVfoKi6iSdFfxSh9wzVz0Ho3YgiCL837hhYTeXram31iftdbv47C4KA/Cv+EeBVd1dWT5alIrqa6jnRGjebYJclrPJfh2ObmPFs5H4dJJubCDnFavNRICet66CkwU3FJKFQLPmWq1cy+7st+nPu2DjxA2+Smm0cQuPSk++AFhYER4uFCmUOfSnFT1ayyNOvIgWfZdZzYh45x+6Bpk9zV+tWmTv0ZJdyKLVLmiJvYLCnZNIBpzL3b/oOlhFU/rl0Hx0c4dzPnokPuyZTK9mQ488gVOO5bwKMTovqX2x3fkpn6hdsfEFtEco7OqInBOKcl namehere
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCrVG2rZuVS3O7KoWw8oN1wsVfoKi6iSdFfxSh9wzVz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ZJdyKLVLmiJvYLCnZNIBpzL3b/oOlhFU/rl0Hx0c4dzPnokPuyZTK9mQ488gVOO5bwKMTovqX2x3fkpn6hdsfEFtEco7OqInBOKcl namehere
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCrVG2rZuVS3O7KoWw8oN1wsVfoKi6iSdFfxSh9wzVz0Ho3YgiCL837hhYTeXram31iftdbv47C4KA/Cv+EeBVd1dWT5alIrqa6jnRGjebYJclrPJfh2ObmPFs5H4dJJubCDnFavNRICet66CkwU3FJKFQLPmWq1cy+7st+nPu2DjxA2+Smm0cQuPSk++AFhYER4uFCmUOfSnFT1ayyNOvIgWfZdZzYh45x+6Bpk9zV+tWmTv0ZJdyKLVLmiJvYLCnZNIBpzL3b/oOlhFU/rl0Hx0c4dzPnokPuyZTK9mQ488gVOO5bwKMTovqX2x3fkpn6hdsfEFtEco7OqInBOKcl namehere

8
config.json.example Normal file
View File

@ -0,0 +1,8 @@
{
"description": "This config file is inaccessible from the web",
"oauth": {
"key": "PHQaa7pbq1ljN6LolYouLookedEolYKIm1qkKxrP2zM",
"secret": "9_-i-fbZF1CBhE1DEADBEEFj8WBTvB-tWyvXTgYuPE8",
"token": "TM7xgyYccUFFE8vM3IhnkxXopCf26w_ZdtCHf_Y4Y3U"
}
}

View File

@ -1,4 +1,4 @@
const DEBUG = false;
var DEBUG = false;
var isMobile = false;
const dbp = (msg) => {
@ -104,16 +104,28 @@ const sendSSH = (key, id, token) => {
...SwalConfig,
title: "Success!",
text: "Your key has been uploaded to the server."
}).then(()=>{
window.location.reload();
});
}else{
Swal.fire({
...SwalConfig,
title: "Failed!",
text: response.error
}).then(()=>{
window.location.reload();
});
}
}).fail(() => {
}).fail((resp) => {
dbp("Failed");
dbd(resp);
Swal.fire({
...SwalConfig,
title: "Failed!",
text: resp.toString()
}).then(()=>{
window.location.reload();
});
});
}

50
mkuser Executable file
View File

@ -0,0 +1,50 @@
#!/bin/bash
# This tool generates the users and/or appends the given SSH kjey to the authorized file
# $1 = username
# $2 = tempfile
LOGFILE="/etc/ttyserver/mkuser.log"
if [ "$EUID" -ne 0 ];then
#echo "Please run as root"
echo "Not run as root" >> $LOGFILE
exit 60
fi
#echo $1 >> $LOGFILE
# If not exists, create new user with
if [[ "$1" =~ ^[a-zA-Z0-9][a-zA-Z0-9-]+$ ]]; then
echo "Valid username: \"$1\"" >> $LOGFILE
# Is valid username
CHECKUSER=`getent passwd "$1"`
if [[ ${#CHECKUSER} -gt 6 ]]; then
# User Exists
echo "\"$1\" Exists" >> $LOGFILE
else
useradd -G webadd -m -b /htusers -s /usr/bin/bash "$1"
echo "Added \"$1\" to the system" >> $LOGFILE
fi
# Ensure SSH filder exists
USERDIR="$(eval echo "~$1")"
if [ ! -d "$USERDIR/.ssh" ]; then
echo "Generate ssh directory for \"$1\"" >> $LOGFILE
mkdir -p "$USERDIR/.ssh"
chown -R "$1" "USERDIR/.ssh"
else
echo "User .ssh exists" >> $LOGFILE
fi
# Append new key
echo "$2 -> $USERDIR/.ssh/authorized_keys" >> $LOGFILE
cat "$2" >> "$USERDIR/.ssh/authorized_keys"
chmod 700 "$USERDIR/.ssh/authorized_keys"
chown "$1" "$USERDIR/.ssh/authorized_keys"
# Remove temp file
rm -f "$2"
echo "Done appending key to \"$1\"" >> $LOGFILE
exit 0
else
echo "\"$1\" Was an invalid username" >> $LOGFILE
exit 64
fi