9 Commits

Author SHA1 Message Date
08983174b8 make sure nextcloud gets its password 2026-07-13 12:26:52 +02:00
76e4eb751d separate adding user from setting it up
also, echo instead of cat
2026-07-13 12:26:15 +02:00
fc15f8fff7 delete root from active 2026-06-23 01:16:53 +02:00
59f1607812 active users fix 2026-06-23 00:54:31 +02:00
4f00bccbe5 Merge pull request 'move all steps to functions' (#7) from editor into main
Reviewed-on: #7
2026-06-23 00:52:03 +02:00
f082adf206 Merge pull request 'feat: add active users script' (#8) from io/helpers:main into main
Reviewed-on: #8
2026-06-23 00:51:52 +02:00
iodomi
9381838e4f fix: check users connected thru ssh 2026-06-22 22:59:12 +02:00
iodomi
62cdc6a67d feat: add active users script 2026-06-22 14:43:18 +02:00
146c6fb1b1 move all add user steps to functions 2026-06-09 15:47:14 +02:00
2 changed files with 39 additions and 19 deletions

12
active-users Executable file
View File

@@ -0,0 +1,12 @@
#!/usr/bin/php
<?php
$jsonFile = '/opt/html/online.json';
$activeUsers = shell_exec("ps -eo user=,comm= | awk '$2 ~ /sshd/ {print $1}' | grep -vE 'sshd|root' | sort -u");
$activeUsersArray = array_filter(explode("\n", $activeUsers));
$activeUsersJson = json_encode($activeUsersArray, JSON_PRETTY_PRINT);
file_put_contents($jsonFile, $activeUsersJson);
?>

View File

@@ -7,18 +7,22 @@ set -e
LOGIN="$1"
[ -z "$LOGIN" ] && { echo "Użycie: $0 <login>"; exit 1; }
setup_user() {
STEP=$2
PASS="$(openssl rand -base64 16 | sed 's/[\/\+\=\\]//g')"
add_user() {
adduser -D -s /bin/sh -h "/home/$LOGIN" -H "$LOGIN"
addgroup "$LOGIN" tildeusers
PASS="$(openssl rand -base64 16 | sed 's/[\/\+\=\\]//g')"
echo "$LOGIN":"$PASS" | chpasswd
zfs create -o mountpoint="/home/$LOGIN" -o quota=200M "tank/ROOT/homes/$LOGIN"
chown "$LOGIN":"$LOGIN" "/home/$LOGIN"
}
setup_user() {
addgroup "$LOGIN" tildeusers
# neomutt had issues with default vi
cat "export EDITOR=nvim" >> "/home/$LOGIN/.ashrc"
echo "export EDITOR=nvim" >> "/home/$LOGIN/.ashrc"
# set cgroup
CG_ROOT=/sys/fs/cgroup/users
@@ -111,11 +115,6 @@ setup_weechat () {
}
send_welcome_mail () {
cp welcome_tmp.txt welcome.txt
echo "Login: $LOGIN" >> welcome.txt
echo "Hasło: $PASS" >> welcome.txt
sendmail -f v0id1st@tylda.org "$LOGIN@tylda.org" << EOF
Subject: Witaj na tylda.org!
From: v0id1st@tylda.org
@@ -129,18 +128,27 @@ Twoje dane do Nextcloud to (https://cloud.tylda.org) to:
EOF
}
setup_user
setup_neomutt
setup_tmux
setup_gemini
setup_html
setup_weechat
setup_nextcloud
if [ -z "$STEP" ]; then
# critical path
add_user
setup_user
setup_nextcloud
send_welcome_mail
# less important stuff
# shouldn't impact user obtaining registration email
setup_neomutt
setup_tmux
setup_gemini
setup_html
setup_weechat
else
# use $STEP as fn to call
$STEP
fi
chown -R "$LOGIN":"$LOGIN" "/home/$LOGIN/"
send_welcome_mail
echo 524288000 > "$USER_CG/memory.max" # 500MB RAM
echo "50000 100000" > "$USER_CG/cpu.max" # 50% CPU (quota/period μs)