-
Notifications
You must be signed in to change notification settings - Fork 2
/
ynaas
executable file
·42 lines (34 loc) · 913 Bytes
/
ynaas
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
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash -x
host=ynaas.com
IFS=$' \t\n\r'
yn=(yes no)
read -r request _
while read -r header value; do
[[ $header = Host: ]] && host=$value
[[ $header = Content-Length: ]] && length=$value
[[ $header ]] || break
done
case $request in
GET)
[[ $host = *.ynaas.com ]] && host=${host%.com}
host=${host%.*}
host=${host//\/}
host=${host,,}
;;
POST)
IFS+=\& read -r -n "${length?}" subdomain yn
yn=${yn#yn=}
subdomain=${subdomain#subdomain=}
if [[ $yn = yes || $yn = no ]]; then
subdomain=${subdomain//\/}
subdomain=${subdomain,,}
ln "$yn" "$subdomain" &&
exec printf 'HTTP/1.1 302 Found\r\nLocation: http://%s.ynaas.com\r\n\r\n' "$subdomain"
fi
;;
*)
printf 'HTTP/1.1 200 OK\r\n\r\n'
exit
;;
esac
[[ -e $host ]] && cat "$host" || cat idk