From 495ab854aca3463dd01b2d08ef077a8606d829cd Mon Sep 17 00:00:00 2001 From: Shin'ya Minazuki Date: Sun, 16 Nov 2025 01:18:37 +0900 Subject: [PATCH] =?UTF-8?q?=E3=81=82=E3=81=AA=E3=81=9F=E3=82=92=E5=BE=85?= =?UTF-8?q?=E3=81=A3=E3=81=A6=E3=81=84=E3=81=BE=E3=81=99...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LICENSE | 3 ++- Makefile | 6 ++++++ mail.tmpl | 19 +++++++++++++++++++ makeuser | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 Makefile create mode 100644 mail.tmpl create mode 100644 makeuser diff --git a/LICENSE b/LICENSE index 9ff0c4e..989d054 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ MIT License -Copyright (c) 2025 LaidBackSYS +Copyright (c) 2018-2022 tilde.team +Copyright (c) 2025 Yakumo Laboratories Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..00d57d0 --- /dev/null +++ b/Makefile @@ -0,0 +1,6 @@ +install-mkdirs: + @install -m 0755 -d ${PREFIX}/share/laidback +install: install-mkdirs + @install -m 0755 makeuser ${PREFIX}/bin + @install -m 0600 mail.tmpl ${PREFIX}/share/laidback + diff --git a/mail.tmpl b/mail.tmpl new file mode 100644 index 0000000..c3dd50a --- /dev/null +++ b/mail.tmpl @@ -0,0 +1,19 @@ +To: newemail +Subject: Welcome ~newuser to hostname + +Welcome newuser-sama, + +You should be able to login at newuser@$hostname, using the SSH key you provided earlier. + +That being said, if you do not want to type the above every time you want to login, you can use this snippet and save it as ~/.ssh/config (in your device) + +Host laidback + Hostname hostname + User newuser + +Your password is newpassword, change it right away after login with `passwd` +It's only useful for E-mail and XMPP, the latter of which can have a different password altogether. + +You can read the (work in progress) documentation here: https://hostname/wiki + +Feel free to contact `support@laidback.moe` if you have any questions. diff --git a/makeuser b/makeuser new file mode 100644 index 0000000..60a3fff --- /dev/null +++ b/makeuser @@ -0,0 +1,51 @@ +#!/bin/sh + +msg_err() { + printf "\033[0;31m%s\033[0m\n" "$*" >&2 + exit 1 +} +msg_info() { + printf "\033[0;32m%s\033[0m\n" "$*" +} +msg_warn() { + printf "\033[0;33m%s\033[0m\n" "$*" +} +print_usage() { + msg_warn "Usage: $(basename $0) [-h|--help] \"\"" +} + +case $1 in + -h | --help) + print_usage; exit + ;; + -* | --*) + print_usage; exit 1 + ;; + *) + if [ $# -ne 3 ]; then + msg_err "Not enough arguments" + fi + + if id "$1" > /dev/null 2>&1; then + exit 0 + fi + + hostname="$(hostname)" + newpw="$(pwgen -s 20 1)" + newpw_hash="$(pwhash $newpw)" + + msg_info "Adding new user: %s" "$1" + useradd -m -g users -s "${newpw_hash}" /bin/sh "$1" || msg_err "Unable to create user" + + sed -e "s/newuser/$1/g" \ + -e "s/newpassword/$newpw/" \ + -e "s/newemail/$2/" \ + -e "s/hostname/$hostname/" \ + /usr/local/share/laidback/email.tmpl | sendmail "$1" "$2" + + + printf "%s\n" "$3" | doas tee "/home/$1/.ssh/authorized_keys" + + doas -u ejabberd /usr/pkg/sbin/ejabberdctl register "$1" "${hostname}" "$newpw" + ;; +esac