4 # Remove trailing CR, which may have been added by browser
6 # Collapse white spaces
8 # Remove starting and trailing white spaces
10 # Usernames starting with & # ? @ + will be invalid
12 # Usernames containing a / will be invalid
14 # Usernames must be between 3 and 24 characters
16 # Usernames may not span multiple lines
19 { [ $# -eq 0 ] && cat || printf %s "$*"; } \
20 | sed -E ':X; $!{N;bX;}'"$UNAME_VALID"
23 nickname="$(COOKIE nick |username)"
24 if [ ! "$nickname" ]; then
26 elif [ ! -d "$_DATA/@$nickname" ]; then
29 userclient="$(COOKIE user_client)"
30 secuid="$(cat "$_DATA/@$nickname/secuid")"
31 clientid="${userclient%%-*}"
32 clientid="${clientid}-$(printf '%s%s' "${clientid}" "${secuid}" |sha256sum)"
33 clientid="${clientid%% *}"
34 if [ "$clientid" = "$userclient" ]; then
36 SET_COOKIE +"$((86400 * 365))" "user_client=${clientid}" HttpOnly
37 SET_COOKIE +"$((86400 * 365))" "nick=$(URL "${nickname}")"
39 export ERROR=".nick Your current nickname has been registered elsewhere."
45 case $(POST action) in
47 nick="$(POST nickname |username)"
48 if [ -d "$_DATA/@$nick" ]; then
49 export ERROR=".nick This nickname has already been registered elsewhere."
50 elif [ -z "$(POST nickname)" ]; then
51 SET_COOKIE +1209600 "nick=$(URL "${nickname#\?}")"
52 REDIRECT "$(URL "/$LOCATION")"
53 elif [ -z "$nick" ]; then
54 export ERROR='.nick Nicknames must be between 3 and 24 characters long. They may not start with "&", "#", "?", "@", or "+" and they must not contain a "/".'
56 SET_COOKIE +1209600 "nick=$(URL $nick)"
57 REDIRECT "$(URL "/$LOCATION")"
61 regnick="$(POST regnick |username)"
62 userdir="$_DATA/@${regnick}"
63 if [ "$NICK_REGISTRATION" != on ]; then
64 export ERROR='.register Nickname registration is disabled on this server.'
65 elif [ "$regnick" = Guest ]; then
66 export ERROR='.register The name "Guest" may not be registered as a permanent nickname.'
67 elif [ -z "$regnick" ]; then
68 export ERROR='.register Nicknames must be between 3 and 24 characters long. They may not start with "&", "#", "?", "@", or "+" and they must not contain a "/".'
69 elif [ -d "$userdir" ]; then
70 export ERROR=".register This nickname has already been registered elsewhere."
71 elif mkdir "$userdir"; then
72 secuid="$(randomid)"; clientid="$(randomid)"
73 printf %s\\n "$secuid" >"${userdir}/secuid"
74 clientid="${clientid}-$(printf '%s%s' "${clientid}" "${secuid}" |sha256sum |cut -d\ -f1)"
75 SET_COOKIE +"$((86400 * 365))" "user_client=${clientid}" HttpOnly
76 SET_COOKIE +"$((86400 * 365))" "nick=$(URL "${regnick}")"
77 REDIRECT "$(URL "/$LOCATION")"
79 export ERROR=".register Registration failed, possibly due to faulty server configuration."