Compare commits
3 Commits
editor
...
f082adf206
| Author | SHA1 | Date | |
|---|---|---|---|
| f082adf206 | |||
|
|
9381838e4f | ||
|
|
62cdc6a67d |
12
active-users
Executable file
12
active-users
Executable 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}' | sort -u");
|
||||
|
||||
$activeUsersArray = array_filter(explode("\n", $activeUsers));
|
||||
|
||||
$activeUsersJson = json_encode($activeUsersArray, JSON_PRETTY_PRINT);
|
||||
|
||||
file_put_contents($jsonFile, $activeUsersJson);
|
||||
?>
|
||||
151
add_user.sh
151
add_user.sh
@@ -2,51 +2,51 @@
|
||||
# Usage: add_user.sh <login>
|
||||
set -e
|
||||
|
||||
. /root/helpers/.env
|
||||
source /root/helpers/.env
|
||||
|
||||
LOGIN="$1"
|
||||
[ -z "$LOGIN" ] && { echo "Użycie: $0 <login>"; exit 1; }
|
||||
|
||||
setup_user() {
|
||||
adduser -D -s /bin/sh -h "/home/$LOGIN" -H "$LOGIN"
|
||||
addgroup "$LOGIN" tildeusers
|
||||
# 1. Użytkownik i hasło
|
||||
PASS="$(openssl rand -base64 16 | sed 's/[\/\+\=\\]//g')"
|
||||
adduser -D -s /bin/sh -h /home/$LOGIN -H "$LOGIN"
|
||||
echo "$LOGIN:$PASS" | chpasswd
|
||||
addgroup $LOGIN tildeusers
|
||||
|
||||
PASS="$(openssl rand -base64 16 | sed 's/[\/\+\=\\]//g')"
|
||||
echo "$LOGIN":"$PASS" | chpasswd
|
||||
# 2. Dataset ZFS (quota 200 MB)
|
||||
zfs create -o mountpoint=/home/$LOGIN -o quota=200M tank/ROOT/homes/$LOGIN
|
||||
chown $LOGIN:$LOGIN /home/$LOGIN
|
||||
cat "export EDITOR=nvim" >> /home/$LOGIN/.ashrc
|
||||
|
||||
zfs create -o mountpoint="/home/$LOGIN" -o quota=200M "tank/ROOT/homes/$LOGIN"
|
||||
chown "$LOGIN":"$LOGIN" "/home/$LOGIN"
|
||||
mkdir -p /home/$LOGIN/Maildir/Inbox/cur
|
||||
mkdir -p /home/$LOGIN/Maildir/Inbox/new
|
||||
mkdir -p /home/$LOGIN/Maildir/Inbox/tmp
|
||||
|
||||
# neomutt had issues with default vi
|
||||
cat "export EDITOR=nvim" >> "/home/$LOGIN/.ashrc"
|
||||
mkdir -p /home/$LOGIN/Maildir/Sent/cur
|
||||
mkdir -p /home/$LOGIN/Maildir/Sent/new
|
||||
mkdir -p /home/$LOGIN/Maildir/Sent/tmp
|
||||
|
||||
# set cgroup
|
||||
CG_ROOT=/sys/fs/cgroup/users
|
||||
mkdir -p "$CG_ROOT"
|
||||
# upewnij się, że kontrolery włączone w parent „users”
|
||||
echo "+cpu +memory" > "$CG_ROOT/cgroup.subtree_control" 2>/dev/null || true
|
||||
mkdir -p /home/$LOGIN/Maildir/Drafts/cur
|
||||
mkdir -p /home/$LOGIN/Maildir/Drafts/new
|
||||
mkdir -p /home/$LOGIN/Maildir/Drafts/tmp
|
||||
|
||||
USER_CG="$CG_ROOT/$LOGIN"
|
||||
mkdir "$USER_CG"
|
||||
mkdir -p /home/$LOGIN/Maildir/Trash/cur
|
||||
mkdir -p /home/$LOGIN/Maildir/Trash/new
|
||||
mkdir -p /home/$LOGIN/Maildir/Trash/tmp
|
||||
|
||||
# set default folders for ssh & gnu and set them private
|
||||
mkdir -m 0700 "/home/$LOGIN/.ssh"
|
||||
mkdir -m 0700 "/home/$LOGIN/.gnupg"
|
||||
}
|
||||
chmod -R 0700 /home/$LOGIN/Maildir
|
||||
|
||||
setup_neomutt () {
|
||||
for dir in "Inbox" "Sent" "Drafts" "Trash"; do
|
||||
for subdir in "cur" "new" "tmp"; do
|
||||
mkdir -p "/home/$LOGIN/Maildir/$dir/$subdir"
|
||||
done
|
||||
done
|
||||
cp -r /root/helpers/public_html /home/$LOGIN/
|
||||
sed -i "s/<<USER>>/$LOGIN/g" /home/$LOGIN/public_html/index.php
|
||||
sed -i "s/<<USER>>/$LOGIN/g" /home/$LOGIN/public_html/parts/header.php
|
||||
sed -i "s/<<USER>>/$LOGIN/g" /home/$LOGIN/public_html/blog/index.php
|
||||
|
||||
chmod -R 0700 /home/"$LOGIN"/Maildir
|
||||
}
|
||||
mkdir -p /home/$LOGIN/.config/weechat/
|
||||
|
||||
setup_tmux () {
|
||||
mkdir -p "/home/$LOGIN/.config/tmux"
|
||||
cat << EOF > "/home/$LOGIN/.config/tmux/tmux.conf"
|
||||
cp /root/helpers/irc.conf /home/$LOGIN/.config/weechat
|
||||
|
||||
mkdir -p /home/$LOGIN/.config/tmux
|
||||
cat << EOF > /home/$LOGIN/.config/tmux/tmux.conf
|
||||
set -g mouse on
|
||||
setw -g mode-keys vi
|
||||
bind -n F1 select-window -t 0
|
||||
@@ -65,79 +65,52 @@ set-hook -g client-attached "send-keys -t main:2 '/usr/local/bin/tylda-motd.sh'
|
||||
|
||||
EOF
|
||||
|
||||
cat << EOF > "/home/$LOGIN/.profile"
|
||||
cat << EOF > /home/$LOGIN/.profile
|
||||
if [ -z "\$TMUX" ]; then
|
||||
exec tmux attach -t main || exec tmux new -s main
|
||||
fi
|
||||
EOF
|
||||
}
|
||||
|
||||
setup_gemini () {
|
||||
gmi="/home/$LOGIN/public_gemini/"
|
||||
mkdir -p "$gmi"
|
||||
ln -s "$gmi" "/srv/gemini/~$LOGIN"
|
||||
|
||||
cat <<EOF > "$gmi/index.gmi"
|
||||
# 3. Cgroup v2
|
||||
CG_ROOT=/sys/fs/cgroup/users
|
||||
mkdir -p "$CG_ROOT"
|
||||
# upewnij się, że kontrolery włączone w parent „users”
|
||||
echo "+cpu +memory" > "$CG_ROOT/cgroup.subtree_control" 2>/dev/null || true
|
||||
|
||||
USER_CG="$CG_ROOT/$LOGIN"
|
||||
mkdir "$USER_CG"
|
||||
|
||||
# gemini
|
||||
gmi="/home/$LOGIN/public_gemini/"
|
||||
mkdir -p $gmi
|
||||
ln -s $gmi /srv/gemini/~$LOGIN
|
||||
|
||||
cat <<EOF > $gmi/index.gmi
|
||||
# $LOGIN
|
||||
EOF
|
||||
}
|
||||
# end gemini
|
||||
|
||||
setup_html () {
|
||||
cp -r /root/helpers/public_html "/home/$LOGIN/"
|
||||
sed -i "s/<<USER>>/$LOGIN/g" "/home/$LOGIN/"public_html/index.php
|
||||
sed -i "s/<<USER>>/$LOGIN/g" "/home/$LOGIN/"public_html/parts/header.php
|
||||
sed -i "s/<<USER>>/$LOGIN/g" "/home/$LOGIN/"public_html/blog/index.php
|
||||
mkdir -p /home/$LOGIN/.ssh
|
||||
mkdir -p /home/$LOGIN/.gnupg
|
||||
touch /home/$LOGIN/public_html/.webring
|
||||
|
||||
touch "/home/$LOGIN/public_html/.webring"
|
||||
}
|
||||
chmod 0700 /home/$LOGIN/.ssh
|
||||
chmod 0700 /home/$LOGIN/.gnupg
|
||||
|
||||
setup_nextcloud () {
|
||||
curl -X POST https://cloud.tylda.org/ocs/v1.php/cloud/users \
|
||||
-d userid="$LOGIN" \
|
||||
-d password="$PASS" \
|
||||
-H "OCS-APIRequest: true" \
|
||||
-u "$NEXTCLOUD_USER:$NEXTCLOUD_PASS"
|
||||
chown -R $LOGIN:$LOGIN /home/$LOGIN/
|
||||
|
||||
curl -X PUT "https://cloud.tylda.org/ocs/v1.php/cloud/users/$LOGIN" \
|
||||
-H "OCS-APIRequest: true" \
|
||||
-u "$NEXTCLOUD_USER:$NEXTCLOUD_PASS" \
|
||||
-d key="quota" \
|
||||
-d value="250MB"
|
||||
}
|
||||
curl -X POST https://cloud.tylda.org/ocs/v1.php/cloud/users -d userid="$LOGIN" -d password="$PASS" -H "OCS-APIRequest: true" -u "$NEXTCLOUD_USER:$NEXTCLOUD_PASS"
|
||||
curl -X PUT "https://cloud.tylda.org/ocs/v1.php/cloud/users/$LOGIN" -H "OCS-APIRequest: true" -u "$NEXTCLOUD_USER:$NEXTCLOUD_PASS" -d key="quota" -d value="250MB"
|
||||
|
||||
setup_weechat () {
|
||||
mkdir -p "/home/$LOGIN/.config/weechat/"
|
||||
cp /root/helpers/irc.conf "/home/$LOGIN/.config/weechat"
|
||||
}
|
||||
cp welcome_tmp.txt welcome.txt
|
||||
|
||||
send_welcome_mail () {
|
||||
sendmail -f v0id1st@tylda.org "$LOGIN@tylda.org" << EOF
|
||||
Subject: Witaj na tylda.org!
|
||||
From: v0id1st@tylda.org
|
||||
echo "Login: $LOGIN" >> welcome.txt
|
||||
echo "Hasło: $PASS" >> welcome.txt
|
||||
|
||||
Siemano :D
|
||||
Witaj na tyldzie, baw się dobrze! Wpadnij się przywitać na IRCa.
|
||||
sendmail -f v0id1st@tylda.org $LOGIN@tylda.org < welcome.txt
|
||||
|
||||
Twoje dane do Nextcloud to (https://cloud.tylda.org) to:
|
||||
Login: $LOGIN
|
||||
Hasło: $PASS
|
||||
EOF
|
||||
}
|
||||
|
||||
# critical path
|
||||
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
|
||||
|
||||
chown -R "$LOGIN":"$LOGIN" "/home/$LOGIN/"
|
||||
rm -f welcome.txt
|
||||
|
||||
echo 524288000 > "$USER_CG/memory.max" # 500 MB RAM
|
||||
echo "50000 100000" > "$USER_CG/cpu.max" # 50 % CPU (quota/period μs)
|
||||
|
||||
Reference in New Issue
Block a user