-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
318 lines (271 loc) · 8.75 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<?php
/**
*
* this is what you have to change if you want to alter the hosts
*
*/
function get_hosts(){
return array(array("scylla.cs.uoi.gr",22),array("ecourse.uoi.gr",80),array("eudoxus.gr",80),array("classweb.uoi.gr",443));
}
/**
* @param $ip
* @param $port
* @return bool
* Function to ping each host.
* It returns a simple boolean value based on whether that host is online
*/
function ping_address($ip,$port="") {
if(empty($port))
{
exec("/bin/ping -c 2 $ip", $outcome, $status);
return 0 == $status;
}
$fp = fsockopen("udp://".$ip, $port, $errno, $errstr);
if($errstr){
return false;
}
if (!$fp) {
//return false;
exec("/bin/ping -c 2 $ip", $outcome, $status);
return 0 == $status;
}else{
return true;
}
}
function get_status($hosts){
$servers=array();
$i=0;
foreach ($hosts as $key=>$server_port) {
$server=$server_port[0];
$port=$server_port[1];
$result=ping_address($server,$port);
$servers[$server]=$result;
}
return $servers;
}
function get_new_values($servers){
$values=array("time"=>time());
foreach($servers as $server=>$status)
{
if($status)
{
$values[$server]="true";
}else{
$values[$server]="false";
}
}
return $values;
}
function write_to_file($values,$file_name,$EOL=PHP_EOL,$delimiter=NULL)
{
if(is_null($delimiter))
{
global $file_delimiter;
$delimiter=$file_delimiter;
}
$result="";
foreach($values as $key=>$value)
{
$result=$result.$key.$delimiter.$value.$EOL;
}
file_put_contents($file_name, $result);
}
function renew_values($file_name)
{
$values=get_new_values(get_status(get_hosts()));
write_to_file($values,$file_name,"\n");
return $values;
}
/**
* @param $host
* @param $hosts
* @return int|void
* Function to get wether the host is http/https or something else
*/
function isHTTP($host,$hosts)
{
foreach($hosts as $temp_host)
{
if($host==$temp_host[0])
{
if($temp_host[1]==80)
{
return 1;
}
if($temp_host[1]==443)
{
return 0;
}
return -1;
}
}
}
/**
* @param $file_name
* @param $file_delimiter
* @return array
* Function to read the hosts that are temporarily stored in the file
*/
function read_file($file_name,$file_delimiter)
{
$fn = file($file_name);
$data=array();
foreach ($fn as $value) {
$temp_data=explode($file_delimiter,$value);
$data[$temp_data[0]]=$temp_data[1];
}
return $data;
}
/**
* Change these values to change the work progress of the program.
*/
$file_name="meassures.txt";
$file_delimiter=":";
$awaiting_time=5*60;
$data=read_file($file_name,$file_delimiter);
$renew=time()>intval($data["time"])+$awaiting_time;
if($renew)
{
//file_get_contents('update-cronjob.php');
$data=renew_values($file_name);
}
$new_data_values=array();
$new_data=array();
foreach ($data as $key => $value) {
if($key=="time")
{
// Adding 3*600 to make it from utc to utc+3
$new_data["next_update"]=date("D d-m-Y H:i:s",intval($value)+$awaiting_time);
$new_data["last_update"]=date("D d-m-Y H:i:s",intval($value));
}else{
if(trim($value)=="true")
{
$new_data[$key]=True;
}else{
$new_data[$key]=False;
}
$new_data_values[$key]=isHTTP($key,get_hosts());
}
}
?>
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>
<?php
$servers = array_slice($new_data, 2, count($new_data)-1, true);
$are_up=true;
foreach ($servers as $value) {
if(!$value)
{
$are_up=false;
}
}
if($are_up)
{
echo "Server is Online";
}else
{
echo "Server Maintenance";
}
?>
</title>
<meta name="description" content="Check the status of various servers. This page displays the online status of servers, including scylla.cs.uoi.gr, ecourse.uoi.gr, eudoxus.gr, and classweb.uoi.gr.">
<meta name="keywords" content="server status, online, scylla, ecourse, eudoxus, classweb">
<meta name="author" content="Παύλος Ορφανίδης">
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@paul_porfanid">
<meta name="twitter:title" content="Server Status - <?php if($are_up){ echo "Online";}else{echo "Offline";} ?>">
<meta name="twitter:description" content="Check the status of various servers. This page displays the online status of servers, including scylla.cs.uoi.gr, ecourse.uoi.gr, eudoxus.gr, and classweb.uoi.gr.">
<meta property="og:title" content="Server Status - <?php if($are_up){ echo "Online";}else{echo "Offline";} ?>">
<meta property="og:description" content="Check the status of various servers. This page displays the online status of servers, including scylla.cs.uoi.gr, ecourse.uoi.gr, eudoxus.gr, and classweb.uoi.gr.">
<meta property="og:type" content="website">
<meta property="og:url" content="https://cse.uoi.gr/~cse74134/servers">
<script src="https://tarptaeya.github.io/repo-card/repo-card.js"></script>
<!-- Add Twitter image here using: <meta name="twitter:image" content="your-image-url.jpg"> -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<style>
body { text-align: center; padding: 7%; font: 20px Helvetica, sans-serif; color: #333;}
.title{ font-size: 30px; }
article { display: block; text-align: left; width: 650px; margin: 0 auto; }
a { color: #dc8100; text-decoration: none; }
a:hover { color: #333; text-decoration: none; }
</style>
</head>
<body>
<article class="container mt-5">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Server</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php
$text="";
foreach ($servers as $host => $condition) {
$text=$text."<tr><td>";
if($new_data_values[$host]==0)
{
$text=$text."<strong><a href='https://$host' target='_blank'>$host</a></strong>";
}
else
{
if($new_data_values[$host]==1)
{
$text=$text."<strong><a href='http://$host' target='_blank'>$host</a></strong>";
}
else{
$text=$text."<strong>$host</strong>";
}
}
$text=$text."</td><td>";
//://$host' target='_blank'>$host</a> είναι: ";
if($condition)
{
$text=$text."<span class='badge bg-success'>online</span>";
}else{
$text=$text."<span class='badge bg-error'>offline</span>";
}
$text=$text."</td></tr>\n";
}
?>
<?php echo $text ?>
</tbody>
</table>
<div>
<p>Τα παραπάνω στοιχεία προκύπτουν με προσπάθεια σύνδεσης σε συγκεκριμένη θύρα, και αν αυτό αποτύχει, συνεχίζει με εκτέλεση της εντολής ping. Αυτό υποδηλώνει πως ο server απαντάει σε ορισμένα αιτήματα. Υπάρχει όμως η πιθανότητα και πάλι να μην μπορείτε να συνδεθείτε. Σε περίπτωση που συμβεί αυτό, μπορείτε πάντοτε να <a href="https://support.cs.uoi.gr/doku.php?id=cse:%CE%B3%CE%B5%CE%BD%CE%B9%CE%BA%CE%AC:%CE%B5%CF%80%CE%B9%CE%BA%CE%BF%CE%B9%CE%BD%CF%89%CE%BD%CE%AF%CE%B1">επικοινωνήσετε</a> με την ομάδα υποστήριξης.</p>
<p>
Το παρόν project μπορεί να βρεθεί στο GitHub:
<div class="repo-card" data-repo="porfanid/Server-Check"></div>
</p>
<p>— <a href="https://github.com/porfanid"> Παύλος Ορφανίδης</a></p>
</div>
</article>
<footer class="container mt-5">
Τελευταία ενημέρωση στις: <?php echo $new_data["last_update"]; ?><br>
Επόμενη ενημέρωση στίς: <?php echo $new_data["next_update"]; ?><br>
Η ενημέρωση γίνεται κάθε <?php $minutes=$awaiting_time/60; echo $minutes; ?> λεπτ<?php
if($minutes>1)
{
echo "ά";
}else{
echo "ό";
}
?>.
</footer>
<script src='https://storage.ko-fi.com/cdn/scripts/overlay-widget.js'></script>
<script>
kofiWidgetOverlay.draw('porfanid', {
'type': 'floating-chat',
'floating-chat.donateButton.text': 'Support me',
'floating-chat.donateButton.background-color': '#00b9fe',
'floating-chat.donateButton.text-color': '#fff'
});
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script>
</body>
</html>