-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
153 lines (125 loc) · 4.77 KB
/
index.php
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
require_once "lib.php";
global $config;
session_start();
$dest = $_GET[GET_PARAM_REDIRECT_URL] ?? null;
$is_up = is_up();
$timeout = $config->{"timeout"};
$try_count = $_SESSION[SESSION_PARAM_TRY_COUNT] ?? 0;
if (isset($dest)) {
// direct redirect
if ($is_up) {
header("Location: " . urldecode($dest));
exit(0);
}
// well, host is down -> try to wake up
$wake_state = wake();
$try_count++;
$_SESSION[SESSION_PARAM_TRY_COUNT] = $try_count;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="theme-color" content="#ffffff">
<meta name="msapplication-TileColor" content="#ffc40d">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="robots" content="noindex, nofollow">
<?php if (isset($dest) && $timeout > 0): ?>
<meta http-equiv="refresh" content="<?= $timeout ?>"/>
<?php endif; ?>
<title><?= isset($dest) ? "Server is starting" : "No destination" ?></title>
<link href="index.css" type="text/css" rel="stylesheet">
<!-- favicon support -->
<link rel="apple-touch-icon" sizes="180x180" href="images/apple-touch-icon.png?v=3jkrji349">
<link rel="icon" type="image/png" sizes="32x32" href="images/favicon-32x32.png?v=3jkrji349">
<link rel="icon" type="image/png" sizes="16x16" href="images/favicon-16x16.png?v=3jkrji349">
<link rel="manifest" href="site.webmanifest?v=3jkrji349">
<link rel="mask-icon" href="images/safari-pinned-tab.svg?v=3jkrji349" color="#0092bb">
<link rel="shortcut icon" href="favicon.ico?v=3jkrji349">
<script>
'use strict';
window.onload = function () {
// const refreshTime = 5 * 1000;
const refreshTime = <?= $timeout ?> * 1000;
const container = document.getElementById("animated-container");
const elements = container !== null ? container.children : [];
// we actually count the steps between the hides, therefore +1
const cycleTime = refreshTime / (elements.length + 1);
// console.log(`Refresh time: ${refreshTime}ms`);
// console.log(`Cycle time: ${cycleTime}ms`);
// console.log("Elements:", elements);
let current = elements.length - 1;
function cycle() {
if (current >= 0) {
// console.log("Next element:", current);
// next call -> hide current element
elements[current].classList.add("hide");
// decrement for next call
current--;
}
}
// JS...
cycle = cycle.bind(this);
// console.log("Start cycle");
if (elements.length > 0 && cycleTime > 0) setInterval(cycle, cycleTime);
}
</script>
</head>
<body>
<?php if (isset($dest)): ?>
<div>
<div>
<h1>Server is starting</h1>
<img src="images/booting-server.svg" alt="Booting server icon"/>
<div id="animated-container" class="progress-container">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<p class="subtitle">Please wait for the host to come up</p>
<?php if ($config->{"details"}): ?>
<table class="subtitle details">
<tr>
<td>Destination host:</td>
<td><?= $config->{"host"}->{"ip"} ?></td>
</tr>
<tr>
<td>Host State:</td>
<td><?= $is_up ? "Up" : "Down" ?></td>
</tr>
<tr>
<td>Destination URL:</td>
<td><?= htmlspecialchars(urldecode($dest)) ?></td>
</tr>
<tr>
<td>Timeout:</td>
<td><?= $timeout ?></td>
</tr>
<tr>
<td>WoL packet sent:</td>
<td><?= isset($wake_state) ? $wake_state ? "successfully" : "failed" : "undefined" ?></td>
</tr>
<tr>
<td>Try count:</td>
<td><?= $try_count ?></td>
</tr>
</table>
<?php endif; ?>
</div>
</div>
<?php else: ?>
<div>
<div>
<h1>No Destination</h1>
<p>Please add a destination to the parameter list.</p>
<p>Use the <code>encode_url.php</code> script to generate one.</p>
</div>
</div>
<?php endif; ?>
</body>
</html>