Check user-agent to serve different CSS for mobile

This commit is contained in:
Koray Yanik 2022-03-10 09:24:27 +00:00
parent b08abf01c0
commit d47683dc02
4 changed files with 45 additions and 11 deletions

@ -1 +1 @@
Subproject commit b408fd74161e03f3f670debf78df2473af4fb7ac
Subproject commit 99fcf7aa5be5210c082dd9c483717e1fb1204f93

View File

@ -1,14 +1,41 @@
#!/bin/bash
echo "[$(date +%T)] GET $1 ($2)" >> get.log
echo "[$(date +%T)] GET $REQUEST_PATH_SANE ($REQUEST_PATH)" >> Get.log
./handle_requests.sh $@
./handle_requests.sh "$@"
if [ $? -eq 0 ]; then
exit 0
fi
if [ -z "$1" -o "$1" == "index.html" ]; then
body="<html>\n<head>\n<title>$WAKEBOARD_TITLE</title>\n<script type='text/javascript' src='main.js'></script>\n<link rel='stylesheet' href='main.css'></link>\n</head>\n"
while [[ $# -gt 0 ]]; do
length="$1"
key="$2"
shift
shift
value=""
for i in $(seq 1 $length); do
value+="$1 "
shift
done
case $key in
User-Agent)
if [[ $value =~ Mobile ]]; then
mobile=1
fi
;;
esac
done
if [ -z "$REQUEST_PATH_SANE" -o "$REQUEST_PATH_SANE" == "index.html" ]; then
body="<html>\n<head>\n<title>$WAKEBOARD_TITLE</title>\n<script type='text/javascript' src='main.js'></script>\n"
if [ $mobile ]; then
body+="<link rel='stylesheet' href='mobile.css'></link>\n</head>\n"
else
body+="<link rel='stylesheet' href='main.css'></link>\n</head>\n"
fi
body+="<body>\n<table>\n<tr><td></td><td>Hostname</td><td>IP Address</td><td>MAC Address</td><td>Wakeup</td></tr>\n"
IFS=$'\n'

View File

@ -1,7 +1,7 @@
#!/bin/bash
if [[ "$1" =~ ^refresh ]]; then
ip=$(echo "$1" | cut -d '/' -f2)
if [[ "$REQUEST_PATH_SANE" =~ ^refresh ]]; then
ip=$(echo "$REQUEST_PATH_SANE" | cut -d '/' -f2)
body="{\n\"time\": \"$(date +%T)\",\n"
body+="\"status\": \"unknown\"\n}\n"
@ -30,8 +30,8 @@ EOF
exit 0
fi
if [[ "$1" =~ ^status ]]; then
ip=$(echo "$1" | cut -d '/' -f2)
if [[ "$REQUEST_PATH_SANE" =~ ^status ]]; then
ip=$(echo "$REQUEST_PATH_SANE" | cut -d '/' -f2)
if [ ! -r "status/$ip" ]; then
body="{\n\"status\": \"unknown\"\n}\n"
@ -46,8 +46,8 @@ EOF
exit 0
fi
if [[ "$1" =~ ^wol ]]; then
mac=$(echo "$1" | cut -d '/' -f2)
if [[ "$REQUEST_PATH_SANE" =~ ^wol ]]; then
mac=$(echo "$REQUEST_PATH_SANE" | cut -d '/' -f2)
wol "$mac" > /dev/null
body="{\"response\": \"ok\"}\n"

7
static/mobile.css Normal file
View File

@ -0,0 +1,7 @@
body {
background: #aa0000;
}
table {
background: #bbbbbb;
}