Skip to content
Snippets Groups Projects
Verified Commit f79ebf2d authored by Aleksandr Gumroian's avatar Aleksandr Gumroian
Browse files

Move initial version from turris-os-packages

parents
Branches
Tags v4.1.0
No related merge requests found
This diff is collapsed.
#!/bin/sh
. /lib/functions.sh
config_load foris
config_get_bool WIZARD_FINISHED wizard finished "0"
config_get SCRIPTNAME server scriptname "/foris"
SCRIPTNAME=$(echo "$SCRIPTNAME" | sed -e 's;\\;\\\\;g' | sed -e 's;/*$;;g' | sed -e 's;^/*;;g' | sed -e 's;/+;/;g')
HTTPS_URL="https://$SERVER_NAME$REQUEST_URI"
HTTPS_REDIRECT="
let xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if(this.status == 200 &&
xhttp.responseText.search('redirectTo(url)')) {
redirectTo('$HTTPS_URL');
}
};
xhttp.open('GET', '$HTTPS_URL');
xhttp.send();
"
if [ "$WIZARD_FINISHED" = "1" ]; then
REDIRECT_SCRIPT=""
if [ "$REQUEST_SCHEME" = https ]; then
HTTPS_REDIRECT=""
fi
DELAY="25"
[ "$(ls -1 /usr/share/turris-webapps/[0-9]*.conf | wc -l)" -gt 2 ] || DELAY=5
URL=""
export LANG="$(uci -q get foris.settings.lang)"
export LANGUAGE="$LANG"
[ -e /usr/share/turris-webapps/default.conf ] && . /usr/share/turris-webapps/default.conf
[ -n "$URL" ] || . "$(ls -1 /usr/share/turris-webapps/[0-9]*.conf | head -n1)"
DEFAULT_URL="$URL"
cat << HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="refresh" content="$DELAY; URL=$URL" />
<style>
body {
background-color: white;
text-align: center;
}
.content {
width: 960px;
margin: auto;
}
.choice {
margin: 10px;
width: 290px;
height: 450px;
float: left;
border-radius: 7px;
box-shadow: 5px 10px;
border: 2px solid;
border-color: #000;
box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.5);
}
.choice p {
padding-top: auto;
padding-left: 5px;
padding-right: 5px;
padding-botom: 10px;
}
.choice:hover {
border-color: #888;
box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.2);
}
.selected {
border-color: #00a2e2;
margin-top: 15px;
margin-bottom: 5px;
box-shadow: 5px 5px 5px 0px rgba(0,162,226,0.8);
}
.selected:hover {
border-color: #00a2e2;
box-shadow: 5px 5px 5px 0px rgba(0,162,226,0.5);
}
.icon {
display: table-cell;
width: 290px;
height: 290px;
padding: 10px;
vertical-align: middle;
}
.name {
height: 160px;
width: 290px;
display: table-cell;
vertical-align: middle;
}
.icon img {
display: block;
max-width: 270px;
max-height: 270px;
margin: auto;
}
h1 {
color: black;
text-align: center;
}
a, a:visited {
color: #00a2e2;
}
a:active {
color: red;
}
</style>
</head>
<body>
<script>
var timer = $DELAY;
var timer_id;
window.onload = function () {
document.querySelector('#timeout').textContent = timer;
timer_id = setInterval(function () {
document.querySelector('#timeout').textContent = timer;
timer = Math.max(0, timer - 1);
if(timer == 0) {
redirectTo("$URL");
}
}, 1000);
$HTTPS_REDIRECT
};
function redirectTo(url) {
clearInterval(timer_id);
location.replace(url);
}
</script>
<h1>$(gettext -s "Available applications")</h1>
<p>$(gettext -s 'Switching to the selected one in <span id="timeout"></span> second.')</p>
<div class='content'>
HTML
for web in /usr/share/turris-webapps/[0-9]*.conf; do
URL=""
NAME=""
ICON=""
extra=""
. $web
# Get NAME_$LANG
LC_NAME="$(sh -c ". $web;"' echo "$NAME_'"$LANG"'"')"
[ -z "$LC_NAME" ] || NAME="$LC_NAME"
[ "$URL" \!= "$DEFAULT_URL" ] || extra=" selected"
[ -n "$ICON" ] || ICON=generic-web.svg
echo "<div class='choice$extra' onClick='redirectTo(\"$URL\");'><a href='$URL'><div class='icon'><img src='/static/webapps-icons/$ICON' alt='$NAME'/></div><div class="name"><p>$NAME</p></a></div></div>"
done
cat << HTML
</div>
</body>
</html>
HTML
else
cat << HTML
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="refresh" content="$DELAY; URL=$SCRIPTNAME/config/" />
</head>
<body>
<script>
window.onload = function () {
location.replace("$SCRIPTNAME/config/");
};
</script>
<p>Continue to <a href="$SCRIPTNAME/config/">first run wizard</a>...</p>
</body>
</html>
HTML
fi
# root page dynamic redirect via script
$HTTP["url"] =~ "^/*$" {
alias.url = ( "/" => "/usr/share/turris-webapps/turris-root-cgi" )
cgi.assign = ( "" => "" )
setenv.add-response-header = ( "Content-Type" => "text/html")
setenv.add-response-header += ( "Access-Control-Allow-Origin" => "*")
}
alias.url += ( "/static/webapps-icons/" => "/www/webapps-icons/")
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment