From 8c385dff1dce5a9c032ee01b5e2c41ac83d6e016 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 20 Sep 2018 15:18:17 +0000 Subject: [PATCH 1/7] bash version --- email.tmpl | 43 +++++++++++++++++++ makeuser | 121 +++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 156 insertions(+), 8 deletions(-) create mode 100644 email.tmpl diff --git a/email.tmpl b/email.tmpl new file mode 100644 index 0000000..2c07303 --- /dev/null +++ b/email.tmpl @@ -0,0 +1,43 @@ +Subject: welcome to tilde.team! + +hey ~newusername, + +welcome to tilde.team! + +your new account has been established. you can ssh into tilde.team with +the ssh key you supplied on registration. + +your password is "newpassword". please change it when you log in for +the first time. the password is used for imap/smtp auth, not shell login, +which is set to only use ssh key authentication. + +to get started, type `motd` at the command prompt to see a few ways to +get started. have fun! + +the greatest value of tilde.team is not the services provided by the +server, but rather the interesting and welcoming community built by its +users. this is possible because of people like you who choose to make +this a great place. the best way you can help tilde.team is by working +to support a great system culture. chat on irc; build cool programs and +share them with others; focus on learning, and help others learn; be a +good example for others; have fun! + +also, your ~/public_html directory is served at +https://tilde.team/~newusername/ +(you can also use https://newusername.tilde.team) + +check out our wiki at https://tilde.team/wiki/ for more information (and +maybe help us write a new wiki article:) + +our irc is tilde.chat, an irc network connecting several +tilde servers. the `chat` command on your ~team shell will open up +weechat with some nice default configs and plugins. +see our wiki article (https://tilde.team/wiki/?page=irc) +or https://tilde.chat site for information on how to connect from elsewhere. +we also have a webclient at https://irc.tilde.team that you can +register for by running the `webirc` command from a shell session. + +we look forward to seeing you around! welcome to the ~team! + +~tilde.team admins + diff --git a/makeuser b/makeuser index 6ab69fb..6d82b3c 100755 --- a/makeuser +++ b/makeuser @@ -1,11 +1,116 @@ -#!/usr/bin/python3 +#!/bin/bash +# --------------------------------------------------------------------------- +# makeuser - tilde.team new user creation -import os,argparse +# Copyright 2018, Ben Harris + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. -parser = argparse.ArgumentParser(prog="makeuser",description="A user adding script.") -parser.add_argument("username",help="Username of user.") -parser.add_argument("email",help="Email of user.") -parser.add_argument("key",help="The user's SSH pubkey.") -args = parser.parse_args() +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License at for +# more details. + +# Usage: makeuser [-h|--help] + +# Revision history: +# 2018-09-20 Created by new_script ver. 3.3 +# --------------------------------------------------------------------------- + +PROGNAME=${0##*/} +VERSION="0.1" + +clean_up() { # Perform pre-exit housekeeping + return +} + +error_exit() { + echo -e "${PROGNAME}: ${1:-"Unknown Error"}" >&2 + clean_up + exit 1 +} + +graceful_exit() { + clean_up + exit +} + +signal_exit() { # Handle trapped signals + case $1 in + INT) + error_exit "Program interrupted by user" ;; + TERM) + echo -e "\n$PROGNAME: Program terminated" >&2 + graceful_exit ;; + *) + error_exit "$PROGNAME: Terminating on unknown signal" ;; + esac +} + +usage() { + echo -e "usage: $PROGNAME [-h|--help] " +} + +help_message() { + cat <<- _EOF_ + $PROGNAME ver. $VERSION + tilde.team new user creation + + $(usage) + + Options: + -h, --help Display this help message and exit. + + NOTE: You must be the superuser to run this script. + +_EOF_ + return +} + +# Trap signals +trap "signal_exit TERM" TERM HUP +trap "signal_exit INT" INT + +# Check for root UID +if [[ $(id -u) != 0 ]]; then + error_exit "you must be the superuser to run this script." +fi + +# Parse command-line +while [[ -n $1 ]]; do + case $1 in + -h | --help) + help_message; graceful_exit ;; + -* | --*) + usage + error_exit "unknown option $1" ;; + *) + user=$1 + email=$2 + sshkey="$3" + echo "adding new user $user with and pubkey $sshkey" + + newpw=$(pwgen -1B 10) + pwcrypt=$(perl -e "print crypt('${newpw}', 'sa');") + + useradd -m -p $pwcrypt -s /bin/bash $user || exit 1 + + sed -e 's/newusername/$user/g' -e 's/newpassword/$newpw/' email.tmpl | sendmail $email sudoers@tilde.team + + echo "$sshkey" | sudo tee /home/$user/.ssh/authorized_keys + toot "welcome new user ~$user!" + + break + ;; + + esac + shift +done + + +graceful_exit -print(args.username,args.email,args.key) From 8ac1e9271b1230a77beefbd7fbc623295e92b782 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Thu, 20 Sep 2018 11:40:17 -0400 Subject: [PATCH 2/7] working now! --- makeuser | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/makeuser b/makeuser index 6d82b3c..154310e 100755 --- a/makeuser +++ b/makeuser @@ -52,7 +52,7 @@ signal_exit() { # Handle trapped signals } usage() { - echo -e "usage: $PROGNAME [-h|--help] " + echo -e "usage: $PROGNAME [-h|--help] \"\"" } help_message() { @@ -99,7 +99,7 @@ while [[ -n $1 ]]; do useradd -m -p $pwcrypt -s /bin/bash $user || exit 1 - sed -e 's/newusername/$user/g' -e 's/newpassword/$newpw/' email.tmpl | sendmail $email sudoers@tilde.team + sed -e "s/newusername/$user/g" -e "s/newpassword/$newpw/" email.tmpl | sendmail $email sudoers@tilde.team echo "$sshkey" | sudo tee /home/$user/.ssh/authorized_keys toot "welcome new user ~$user!" From abaff4c37df37eab60a24b6db749630b80e05beb Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Thu, 20 Sep 2018 11:44:00 -0400 Subject: [PATCH 3/7] add users to team group --- makeuser | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makeuser b/makeuser index 154310e..d9ddd11 100755 --- a/makeuser +++ b/makeuser @@ -97,7 +97,7 @@ while [[ -n $1 ]]; do newpw=$(pwgen -1B 10) pwcrypt=$(perl -e "print crypt('${newpw}', 'sa');") - useradd -m -p $pwcrypt -s /bin/bash $user || exit 1 + useradd -m -g 100 -p $pwcrypt -s /bin/bash $user || exit 1 sed -e "s/newusername/$user/g" -e "s/newpassword/$newpw/" email.tmpl | sendmail $email sudoers@tilde.team From 85f01bf5b54a17a13346ed194a543c8d750182f0 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Fri, 21 Sep 2018 10:10:50 -0400 Subject: [PATCH 4/7] remove unnecessary boilerplate and license --- makeuser | 113 +++++++++---------------------------------------------- 1 file changed, 17 insertions(+), 96 deletions(-) diff --git a/makeuser b/makeuser index d9ddd11..745a1ac 100755 --- a/makeuser +++ b/makeuser @@ -1,116 +1,37 @@ #!/bin/bash # --------------------------------------------------------------------------- # makeuser - tilde.team new user creation - -# Copyright 2018, Ben Harris - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License at for -# more details. - -# Usage: makeuser [-h|--help] - -# Revision history: -# 2018-09-20 Created by new_script ver. 3.3 +# Usage: makeuser [-h|--help] "" # --------------------------------------------------------------------------- PROGNAME=${0##*/} VERSION="0.1" -clean_up() { # Perform pre-exit housekeeping - return -} - error_exit() { echo -e "${PROGNAME}: ${1:-"Unknown Error"}" >&2 - clean_up exit 1 } -graceful_exit() { - clean_up - exit -} - -signal_exit() { # Handle trapped signals - case $1 in - INT) - error_exit "Program interrupted by user" ;; - TERM) - echo -e "\n$PROGNAME: Program terminated" >&2 - graceful_exit ;; - *) - error_exit "$PROGNAME: Terminating on unknown signal" ;; - esac -} - usage() { echo -e "usage: $PROGNAME [-h|--help] \"\"" } -help_message() { - cat <<- _EOF_ - $PROGNAME ver. $VERSION - tilde.team new user creation +[[ $(id -u) != 0 ]] && error_exit "you must be the superuser to run this script." - $(usage) +case $1 in + -h | --help) + usage; exit ;; + -* | --*) + usage; error_exit "unknown option $1" ;; + *) + [[ $# -ne 3 ]] && error_exit "not enough args" + echo "adding new user $1" + newpw=$(pwgen -1B 10) + pwcrypt=$(perl -e "print crypt('${newpw}', 'sa');") + useradd -m -g 100 -p $pwcrypt -s /bin/bash $1 || exit 1 - Options: - -h, --help Display this help message and exit. - - NOTE: You must be the superuser to run this script. - -_EOF_ - return -} - -# Trap signals -trap "signal_exit TERM" TERM HUP -trap "signal_exit INT" INT - -# Check for root UID -if [[ $(id -u) != 0 ]]; then - error_exit "you must be the superuser to run this script." -fi - -# Parse command-line -while [[ -n $1 ]]; do - case $1 in - -h | --help) - help_message; graceful_exit ;; - -* | --*) - usage - error_exit "unknown option $1" ;; - *) - user=$1 - email=$2 - sshkey="$3" - echo "adding new user $user with and pubkey $sshkey" - - newpw=$(pwgen -1B 10) - pwcrypt=$(perl -e "print crypt('${newpw}', 'sa');") - - useradd -m -g 100 -p $pwcrypt -s /bin/bash $user || exit 1 - - sed -e "s/newusername/$user/g" -e "s/newpassword/$newpw/" email.tmpl | sendmail $email sudoers@tilde.team - - echo "$sshkey" | sudo tee /home/$user/.ssh/authorized_keys - toot "welcome new user ~$user!" - - break - ;; - - esac - shift -done - - -graceful_exit + sed -e "s/newusername/$1/g" -e "s/newpassword/$newpw/" email.tmpl | sendmail $2 sudoers@tilde.team + echo "$3" | tee /home/$1/.ssh/authorized_keys + toot "welcome new user ~$1!" ;; +esac From 1750d636bd0639ff42c6493dea9f5b4c2109c32a Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Fri, 19 Oct 2018 12:37:57 -0400 Subject: [PATCH 5/7] forward mail to new user too --- makeuser | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makeuser b/makeuser index 745a1ac..43951f1 100755 --- a/makeuser +++ b/makeuser @@ -30,7 +30,7 @@ case $1 in pwcrypt=$(perl -e "print crypt('${newpw}', 'sa');") useradd -m -g 100 -p $pwcrypt -s /bin/bash $1 || exit 1 - sed -e "s/newusername/$1/g" -e "s/newpassword/$newpw/" email.tmpl | sendmail $2 sudoers@tilde.team + sed -e "s/newusername/$1/g" -e "s/newpassword/$newpw/" email.tmpl | sendmail $1 $2 sudoers@tilde.team echo "$3" | tee /home/$1/.ssh/authorized_keys toot "welcome new user ~$1!" ;; From 8b3957cfbdbc165db41f15f3f3b59abcaabd291d Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Fri, 14 Dec 2018 20:29:03 -0500 Subject: [PATCH 6/7] sub new users to the mailing list --- makeuser | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/makeuser b/makeuser index 43951f1..47ad657 100755 --- a/makeuser +++ b/makeuser @@ -16,6 +16,13 @@ usage() { echo -e "usage: $PROGNAME [-h|--help] \"\"" } +sub_to_list() { + echo " +From: $1 +Subject: subscribe +" | sudo -u $1 sendmail tildeteam-join@lists.tildeverse.org +} + [[ $(id -u) != 0 ]] && error_exit "you must be the superuser to run this script." case $1 in @@ -31,6 +38,7 @@ case $1 in useradd -m -g 100 -p $pwcrypt -s /bin/bash $1 || exit 1 sed -e "s/newusername/$1/g" -e "s/newpassword/$newpw/" email.tmpl | sendmail $1 $2 sudoers@tilde.team + sub_to_list $1 echo "$3" | tee /home/$1/.ssh/authorized_keys toot "welcome new user ~$1!" ;; From 31e109040cfd0f04fcc43da81960404360bee9d5 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Fri, 15 Feb 2019 13:26:17 -0500 Subject: [PATCH 7/7] add znc user --- makeuser | 1 + 1 file changed, 1 insertion(+) diff --git a/makeuser b/makeuser index 47ad657..4fc3835 100755 --- a/makeuser +++ b/makeuser @@ -39,6 +39,7 @@ case $1 in sed -e "s/newusername/$1/g" -e "s/newpassword/$newpw/" email.tmpl | sendmail $1 $2 sudoers@tilde.team sub_to_list $1 + sudo -u znc /home/znc/add_znc_user.sh $1 echo "$3" | tee /home/$1/.ssh/authorized_keys toot "welcome new user ~$1!" ;;