forked from vern/website
Add signup
This commit is contained in:
parent
ad2a3dc084
commit
6b4d8334f7
|
@ -1,9 +0,0 @@
|
|||
{
|
||||
"m.homeserver": {
|
||||
"base_url": "https://mtrx.vern.cc"
|
||||
},
|
||||
"m.identity_server": {
|
||||
"base_url": "https://vector.im"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
{
|
||||
"m.server": "mtrx.vern.cc:8448"
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"admins": [
|
||||
{
|
||||
"matrix_id": "@root:vern.cc",
|
||||
"email_address": "webmaster@vern.cc",
|
||||
"role": "admin"
|
||||
}
|
||||
],
|
||||
"support_page": "https://matrix.to/#/#vern:vern.cc"
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env bash
|
||||
source ../cgibashopts
|
||||
|
||||
echo "Content-type:text/html; charset=UTF-8\n\n"
|
||||
echo ""
|
||||
|
||||
if [[ $FORM_username =~ ^([a-z_][a-z0-9_]{0,30})$ ]] && ! id $FORM_username &> /dev/null; then
|
||||
echo "<br>Valid Username <b> $FORM_username </b><br>"
|
||||
VALID_USERNAME=1
|
||||
else
|
||||
id $FORM_username &> /dev/null &&
|
||||
echo "<br>Username already taken, try another one and resubmit the form<br>" ||
|
||||
echo "<br>Invalid Username, please go back and resubmit the form<br>"
|
||||
VALID_USERNAME=0
|
||||
fi
|
||||
if [[ "$FORM_email" =~ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$ ]]; then
|
||||
VALID_EMAIL=1
|
||||
echo "<br>Valid email address <b> $FORM_email</b><br>"
|
||||
else
|
||||
VALID_EMAIL=0
|
||||
echo "<br>Invalid email address, please go back and resubmit the form<br>"
|
||||
fi
|
||||
if ! <<< "$FORM_ssh" ssh-keygen -l -f - &> /dev/null; then
|
||||
echo "<br>Invalid SSH Key(s), please go back and resubmit the form<br>"
|
||||
VALID_SSH=0
|
||||
else
|
||||
echo "<br>Valid SSH Key(s)<br>"
|
||||
VALID_SSH=1
|
||||
fi
|
||||
echo "<br> Services requested: Tilde Email $FORM_git $FORM_fedi $FORM_matrix<br>"
|
||||
|
||||
set | grep ^FORM > /home/ak/test
|
||||
sshurl=$(echo $FORM_ssh | curl -s -F'file=@-;' https://envs.sh)
|
||||
if [[ $VALID_EMAIL == 1 ]] && [[ $VALID_USERNAME == 1 ]] && [[ $VALID_SSH == 1 ]]; then
|
||||
echo "<br>Signup Request has been submitted. More information will be sent to $FORM_email after it is approved.<br>"
|
||||
MAILNUM=$RANDOM
|
||||
echo "Subject: New membership request from $FORM_username <$FORM_email>" > /tmp/membershipemail$MAILNUM
|
||||
echo "Hello Administrators," >> /tmp/membershipemail$MAILNUM
|
||||
echo "There has been a new membership request. Please look at the details below and decide if this is worth approving" >> /tmp/membershipemail$MAILNUM
|
||||
echo "SSH Keys: $sshurl" >> /tmp/membershipemail$MAILNUM
|
||||
echo "Services requested: $FORM_git $FORM_fedi $FORM_matrix" >> /tmp/membershipemail$MAILNUM
|
||||
printf "\nReason for join request: \n $FORM_reason\n" >> /tmp/membershipemail$MAILNUM
|
||||
fi
|
|
@ -0,0 +1,169 @@
|
|||
#!/bin/bash
|
||||
# Author: (c) Colas Nahaboo http://colas.nahaboo.net with a MIT License.
|
||||
# See https://github.com/ColasNahaboo/cgibashopts
|
||||
# Uses the CGI env variables REQUEST_METHOD CONTENT_TYPE QUERY_STRING
|
||||
|
||||
export CGIBASHOPTS_RELEASE=4.1.0
|
||||
export CGIBASHOPTS_VERSION="${CGIBASHOPTS_RELEASE%%.*}"
|
||||
cr=$'\r'
|
||||
nl=$'\n'
|
||||
export FORMS=
|
||||
export FORMFILES=
|
||||
export FORMQUERY=
|
||||
|
||||
# parse options
|
||||
uploads=true
|
||||
tmpfs=/tmp
|
||||
OPTIONS='nd:'
|
||||
OPTIND=1
|
||||
while getopts "${OPTIONS}" _o;do
|
||||
case "$_o" in
|
||||
n) uploads=false;;
|
||||
d) tmpfs="$OPTARG";;
|
||||
*) echo "unknown option: $_o"; exit 1;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND-1))
|
||||
|
||||
if "$uploads"; then
|
||||
export CGIBASHOPTS_DIR="$tmpfs/cgibashopts-files.$$"
|
||||
CGIBASHOPTS_TMP="$CGIBASHOPTS_DIR.tmp"
|
||||
cgibashopts_clean() {
|
||||
[ -n "$CGIBASHOPTS_DIR" ] && [ -d "$CGIBASHOPTS_DIR" ] && rm -rf "$CGIBASHOPTS_DIR"
|
||||
}
|
||||
trap cgibashopts_clean 0
|
||||
else
|
||||
CGIBASHOPTS_TMP=/dev/null
|
||||
fi
|
||||
|
||||
# emulates bashlib param function. -f operate on uploaded file paths
|
||||
param () {
|
||||
if [ "$1" = -f ]; then
|
||||
shift
|
||||
if [ $# -eq 0 ]; then echo "$FORMFILES"
|
||||
elif [ $# -eq 1 ]; then eval echo "\$FORMFILE_$1"
|
||||
else declare -x "FORMFILE_$1=$*"
|
||||
fi
|
||||
else
|
||||
if [ $# -eq 0 ]; then echo "$FORMS"
|
||||
elif [ $# -eq 1 ]; then eval echo "\$FORM_$1"
|
||||
else declare -x "FORM_$1=$*"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# decodes the %XX url encoding in $1, same as urlencode -d but faster
|
||||
# removes carriage returns to force unix newlines, converts + into space
|
||||
urldecode() {
|
||||
local v="${1//+/ }" d r=''
|
||||
while [ -n "$v" ]; do
|
||||
if [[ $v =~ ^([^%]*)%([0-9a-fA-F][0-9a-fA-F])(.*)$ ]]; then
|
||||
eval d="\$'\x${BASH_REMATCH[2]}'"
|
||||
[ "$d" = "$cr" ] && d=
|
||||
r="$r${BASH_REMATCH[1]}$d"
|
||||
v="${BASH_REMATCH[3]}"
|
||||
else
|
||||
r="$r$v"
|
||||
break
|
||||
fi
|
||||
done
|
||||
echo "$r"
|
||||
}
|
||||
|
||||
# the reverse of urldecode above
|
||||
urlencode() {
|
||||
local length="${#1}" i c
|
||||
for (( i = 0; i < length; i++ )); do
|
||||
c="${1:i:1}"
|
||||
case $c in
|
||||
[a-zA-Z0-9.~_-]) echo -n "$c" ;;
|
||||
*) printf '%%%02X' "'$c" ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
if [ "${REQUEST_METHOD:-}" = POST ]; then
|
||||
if [[ ${CONTENT_TYPE:-} =~ ^multipart/form-data\;[[:space:]]*boundary=([^\;]+) ]]; then
|
||||
sep="--${BASH_REMATCH[1]}"
|
||||
OIFS="$IFS"; IFS=$'\r'
|
||||
while read -r line; do
|
||||
if [[ $line =~ ^Content-Disposition:\ *form-data\;\ *name=\"([^\"]+)\"(\;\ *filename=\"([^\"]+)\")? ]]; then
|
||||
var="${BASH_REMATCH[1]}"
|
||||
val="${BASH_REMATCH[3]}"
|
||||
[[ $val =~ [%+] ]] && val=$(urldecode "$val")
|
||||
type=
|
||||
read -r line
|
||||
while [ -n "$line" ]; do
|
||||
if [[ $line =~ ^Content-Type:\ *text/plain ]]; then
|
||||
type=txt
|
||||
elif [[ $line =~ ^Content-Type: ]]; then # any other type
|
||||
type=bin
|
||||
fi
|
||||
read -r line
|
||||
done
|
||||
if [ "$type" = bin ]; then # binary file upload
|
||||
# binary-read stdin till next step
|
||||
sed -n -e "{:loop p; n;/^$sep/q; b loop}" >$CGIBASHOPTS_TMP
|
||||
[ $CGIBASHOPTS_TMP != /dev/null ] && \
|
||||
truncate -s -2 $CGIBASHOPTS_TMP # remove last \r\n
|
||||
elif [ "$type" = txt ]; then # text file upload
|
||||
lp=
|
||||
while read -r line; do
|
||||
[[ $line =~ ^"$sep" ]] && break
|
||||
echo -n "$lp$line"
|
||||
lp="$nl"
|
||||
done >$CGIBASHOPTS_TMP
|
||||
else # string, possibly multi-line
|
||||
val=
|
||||
while read -r line; do
|
||||
[[ $line =~ ^"$sep" ]] && break
|
||||
val="$val${val:+$nl}${line}"
|
||||
done
|
||||
fi
|
||||
if [ -n "$type" ]; then
|
||||
if [ $CGIBASHOPTS_TMP != /dev/null ]; then
|
||||
if [ -n "$val" ]; then
|
||||
# a file was uploaded, even empty
|
||||
[ -n "$FORMFILES" ] || mkdir -p "$CGIBASHOPTS_DIR"
|
||||
FORMFILES="$FORMFILES${FORMFILES:+ }$var"
|
||||
declare -x "FORMFILE_$var=$CGIBASHOPTS_DIR/${var}"
|
||||
mv $CGIBASHOPTS_TMP "$CGIBASHOPTS_DIR/${var}"
|
||||
else
|
||||
rm -f $CGIBASHOPTS_TMP
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
FORMS="$FORMS${FORMS:+ }$var"
|
||||
declare -x "FORM_$var=$val"
|
||||
fi
|
||||
done
|
||||
s="${QUERY_STRING:-}"
|
||||
IFS="$OIFS"
|
||||
unset OIFS
|
||||
else
|
||||
stdin=$(cat) # indirection to avoid issues with terminating newlines
|
||||
s="${stdin}&${QUERY_STRING:-}"
|
||||
unset stdin
|
||||
fi
|
||||
else
|
||||
s="${QUERY_STRING:-}"
|
||||
fi
|
||||
|
||||
# regular (no file uploads) arguments processing
|
||||
if [[ $s =~ = ]]; then # modern & (or ;) separated list of key=value
|
||||
while [[ $s =~ ^([^=]*)=([^\&\;]*)[\;\&]*(.*)$ ]]; do
|
||||
var="${BASH_REMATCH[1]//[^a-zA-Z_0-9]/}"
|
||||
val="${BASH_REMATCH[2]}"
|
||||
s="${BASH_REMATCH[3]}"
|
||||
if [[ $var =~ ^[_[:alpha:]] ]]; then # ignore invalid vars
|
||||
[[ $val =~ [%+] ]] && val=$(urldecode "$val")
|
||||
FORMS="$FORMS${FORMS:+ }$var"
|
||||
declare -x "FORM_$var=$val"
|
||||
fi
|
||||
done
|
||||
else # legacy indexed search
|
||||
FORMQUERY=$(urldecode "$s")
|
||||
fi
|
||||
|
||||
# clean up our local variables
|
||||
unset sep line var val type s lp
|
|
@ -0,0 +1,36 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<title>~vern signup</title>
|
||||
</head>
|
||||
<body>
|
||||
<!--#include file="nav" -->
|
||||
<h1>Sign Up to ~vern</h1>
|
||||
<form action="cgi-bin/form.cgi" method=POST enctype='multipart/form-data'>
|
||||
<ul>
|
||||
<li><b>desired username: <input type=text size=64 name=username></b></li>
|
||||
<li><b>email address: <input type=text size=64 name=email></b></li>
|
||||
<li><b>SSH Keys: <br><textarea name=ssh rows="3" cols="50"></textarea></b></li>
|
||||
<li><b>Why do you want to join ~vern: <br><textarea name=reason rows="8" cols="50"></textarea></b></li>
|
||||
<h3>What services do you want? (You can always request an account on others later)</h3>
|
||||
<li><input type="checkbox" id="pubnix" name="pubnix" value="Pubnix" disabled checked>
|
||||
<b><label for="pubnix">Pubnix and E-mail</label><br></b></li>
|
||||
|
||||
<li><input type="checkbox" id="matrix" name="matrix" value="Matrix" checked>
|
||||
<b><label for="matrix">Matrix</label><br></b></li>
|
||||
|
||||
<li><input type="checkbox" id="fedi" name="fedi" value="Mastodon" checked>
|
||||
<b><label for="fedi">Mastodon</label><br></b></li>
|
||||
|
||||
<li><input type="checkbox" id="git" name="git" value="Gitea" checked>
|
||||
<b><label for="gitea">Gitea</label><br></b></li>
|
||||
</ul>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
<br><br><b>By signing up, you agree to the ~vern <a href=/rules>rules</a> and <a href=/privpol>privacy policy</a>. Thanks for using ~vern</b><br>
|
||||
<!--#include file="footer" -->
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue