Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

https interface for user management #648

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Next Next commit
simple htpasswd generator using openssl
  • Loading branch information
nanda committed Mar 23, 2021
commit ed50537bddb0f3a9d032829b8a8e9e44d0c475ff
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LABEL maintainer="Kyle Manna <[email protected]>"

# Testing: pamtester
RUN echo "http:https://dl-cdn.alpinelinux.org/alpine/edge/testing/" >> /etc/apk/repositories && \
apk add --update openvpn iptables bash easy-rsa openvpn-auth-pam google-authenticator pamtester libqrencode && \
apk add --update openvpn iptables bash easy-rsa openvpn-auth-pam google-authenticator pamtester libqrencode lighttpd && \
ln -s /usr/share/easy-rsa/easyrsa /usr/local/bin && \
rm -rf /tmp/* /var/tmp/* /var/cache/apk/* /var/cache/distfiles/*

Expand Down
70 changes: 70 additions & 0 deletions bin/openssl-htpasswd
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash
#

print_help()
{
echo "$(basename \"$0\") [-Dci] passwdfile username [password]"
echo -e "\t-D delete given user"
echo -e "\t-c truncate file (will contain only new user"
echo -e "\t-i read password from stdin"
echo -e "\t-h print this help"
}

ensure_pwd()
{
[ "$STDIN" = 1 ] && read -s PWD
[ -z "$PWD" ] && echo "missing or empty password" >&2 && print_help >&2 && exit 1
PWD=$(openssl passwd -crypt "$PWD")
}

action="modify"
while getopts "Dcid" arg; do
case $arg in
D)
action="delete"
;;
c)
action="create"
;;
i)
STDIN=1
;;
*)
echo "invalid usage" >&2
print_help >&2
exit 1
;;
esac
done
shift $(($OPTIND - 1))

FILE="$1"
USER="$2"
PWD="$3"

[ -z "$USER" ] && echo "missing username" >&2 && print_help >&2 && exit 1
[ -z "$FILE" ] && echo "missing filename" >&2 && print_help >&2

case "$action" in
delete)
[ ! -f "$FILE" ] && exit 0
tmp=$(mktemp)
grep -v "^$USER:" "$FILE" > "$tmp"
cat "$tmp" > "$FILE" && rm "$tmp" && exit 0
;;

create)
ensure_pwd
echo "$USER:$PWD" > "$FILE" && exit 0
;;

modify)
ensure_pwd
tmp=$(mktemp)
(grep -v "^$USER:" "$FILE" 2>/dev/null; echo "$USER:$PWD") > "$tmp" && cat "$tmp" > "$FILE" && rm "$tmp" && exit 0
;;
esac

# should not reach here
exit 1