blob: 95b9d4c52eda804503f051e26ebd2449763c9e7a (
about) (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#!/bin/bash
set -o pipefail
cd /opt/autopeer
NOTIFY_TO="$(python3 -c 'import config; print(config.NOTIFY_TO)')"
echo "[autopeer $(hostname -f)] attempt: $@" | socat stdio "$NOTIFY_TO"
user="$1"
if [ "$1" = "new" ]; then
type="$2"
key="$3"
connection="$4"
if user="$(grep -l -s -r -P '^\s*auth:\s*\Q'"$type"'\E\s+\Q'"$key"'\E(\s|$)' /opt/autopeer/dn42-registry/data/mntner/ | perl -ne 's@^.*/@@; s@-MNT$@@; print lc;' | head -1)"; then
perl -ne 'print if s@^\s*auth:\s*ssh-@restrict,pty ssh-@' </opt/autopeer/dn42-registry/data/mntner/"$(echo "$user" | perl -ne 's@$@-MNT@; print uc;')"
if getent passwd "$user"; then
exit 0
else
echo "[autopeer $(hostname -f)] New user being created: $user from $key $connection" | socat stdio "$NOTIFY_TO"
/usr/sbin/adduser --disabled-password --quiet --comment "created at $(date +%s) by $key ${connection//:/_}" --ingroup autopeer "$user"
/usr/sbin/adduser "$user" bird
( umask 0077; touch "/var/log/autopeer/$user".{tim,io}; )
chown "$user" "/var/log/autopeer/$user".{tim,io}
fi
fi
else # not new user
perl -ne 'print if s@^\s*auth:\s*ssh-@restrict,pty ssh-@' </opt/autopeer/dn42-registry/data/mntner/"$(echo "$user" | perl -ne 's@$@-MNT@; print uc;')"
fi
exit 0
|