-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.php
611 lines (497 loc) · 21.6 KB
/
server.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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
<?php
// Data Relay Center server.
// (C) 2019 CubicleSoft. All Rights Reserved.
if (!isset($_SERVER["argc"]) || !$_SERVER["argc"])
{
echo "This file is intended to be run from the command-line.";
exit();
}
// Temporary root.
$rootpath = str_replace("\\", "/", dirname(__FILE__));
require_once $rootpath . "/support/drc_functions.php";
require_once $rootpath . "/support/websocket_server.php";
require_once $rootpath . "/support/websocket_server_libev.php";
require_once $rootpath . "/support/websocket.php";
require_once $rootpath . "/support/ipaddr.php";
require_once $rootpath . "/support/str_basics.php";
require_once $rootpath . "/support/random.php";
// Load configuration.
$config = DRC_LoadConfig();
if ($argc > 1)
{
// Service Manager PHP SDK.
require_once $rootpath . "/support/servicemanager.php";
$sm = new ServiceManager($rootpath . "/servicemanager");
echo "Service manager: " . $sm->GetServiceManagerRealpath() . "\n\n";
$servicename = "php-data-relay-center";
if ($argv[1] == "install")
{
// Install the service.
$args = array();
$options = array(
"nixuser" => "php-drc",
"nixgroup" => "php-drc"
);
$result = $sm->Install($servicename, __FILE__, $args, $options, true);
if (!$result["success"]) CLI::DisplayError("Unable to install the '" . $servicename . "' service.", $result);
}
else if ($argv[1] == "start")
{
// Start the service.
$result = $sm->Start($servicename, true);
if (!$result["success"]) CLI::DisplayError("Unable to start the '" . $servicename . "' service.", $result);
}
else if ($argv[1] == "stop")
{
// Stop the service.
$result = $sm->Stop($servicename, true);
if (!$result["success"]) CLI::DisplayError("Unable to stop the '" . $servicename . "' service.", $result);
}
else if ($argv[1] == "uninstall")
{
// Uninstall the service.
$result = $sm->Uninstall($servicename, true);
if (!$result["success"]) CLI::DisplayError("Unable to uninstall the '" . $servicename . "' service.", $result);
}
else if ($argv[1] == "dumpconfig")
{
$result = $sm->GetConfig($servicename);
if (!$result["success"]) CLI::DisplayError("Unable to retrieve the configuration for the '" . $servicename . "' service.", $result);
echo "Service configuration: " . $result["filename"] . "\n\n";
echo "Current service configuration:\n\n";
foreach ($result["options"] as $key => $val) echo " " . $key . " = " . $val . "\n";
}
else
{
echo "Command not recognized. Run the service manager directly for anything other than 'install', 'start', 'stop', 'uninstall', and 'dumpconfig'.\n";
}
exit();
}
// Process configuration.
$whitelist = array();
foreach ($config["whitelist"] as $ipaddr => $protocols)
{
$ipaddr = IPAddr::NormalizeIP($ipaddr);
$whitelist[$ipaddr["shortipv6"]] = $protocols;
}
// Initialize server.
$wsserver = (LibEvWebSocketServer::IsSupported() ? new LibEvWebSocketServer() : new WebSocketServer());
$wsserver->SetAllowedOrigins($config["origins"]);
echo "Starting server " . (LibEvWebSocketServer::IsSupported() ? "with PECL libev support" : "without PECL libev support (not recommended)") . "...\n";
$result = $wsserver->Start("127.0.0.1", "7328");
if (!$result["success"])
{
var_dump($result);
exit();
}
echo "Ready.\n";
$channelmap = array();
$channels = array();
$nextchannel = 1;
const CM_RECV_ONLY = 0;
const CM_SEND_TO_AUTHS = 1;
const CM_SEND_TO_ANY = 2;
$rng = new CSPRNG();
$tokenmap = array();
$nexttoken = 1;
function LeaveChannel($client, $channel)
{
global $wsserver, $channelmap, $channels, $tokenmap;
// Remove the client.
if (!$client->appdata["channels"][$channel]) $client->appdata["no_auth"]--;
unset($client->appdata["channels"][$channel]);
$info = $channels[$channel]["clients"][$client->id];
unset($channels[$channel]["clients"][$client->id]);
// Notify all previously notified clients of the removed client.
foreach ($channels[$channel]["clients"] as $id2 => $info2)
{
$client2 = $wsserver->GetClient($id2);
if ($client2 === false) continue;
if (!$info["auth"] && ($info2["mode"] === CM_RECV_ONLY || $info2["mode"] === CM_SEND_TO_AUTHS)) continue;
$ws2 = $client2->websocket;
$result = array(
"channel" => $channel,
"success" => true,
"cmd" => "LEFT",
"from" => 0,
"id" => $client->id
);
$ws2->Write(json_encode($result, JSON_UNESCAPED_SLASHES), WebSocket::FRAMETYPE_TEXT);
$wsserver->UpdateClientState($id2);
}
// Update token map to handle temporary client disconnects.
if ($info["tokenid"] !== false && $info["token"] !== false)
{
$tokenmap[$info["tokenid"]] = array(
"expires" => time() + 30,
"token" => $info["token"],
"channel" => $channels[$channel]["channel"],
"protocol" => $channels[$channel]["protocol"],
"clientmode" => $info["mode"],
"extra" => $info["extra"],
"makeauth" => $info["auth"]
);
}
// Remove empty channels.
if (!count($channels[$channel]["clients"]))
{
$key = $channels[$channel]["channel"] . "|" . $channels[$channel]["protocol"];
unset($channelmap[$key]);
unset($channels[$channel]);
}
$result = array(
"channel" => $channel,
"success" => true,
"cmd" => "LEFT",
"from" => 0,
"id" => $client->id
);
return $result;
}
$stopfilename = __FILE__ . ".notify.stop";
$reloadfilename = __FILE__ . ".notify.reload";
$lastservicecheck = time();
$running = true;
do
{
$result = $wsserver->Wait(3);
// Handle active clients.
foreach ($result["clients"] as $id => $client)
{
if ($client->appdata === false)
{
echo "WebSocket client ID " . $id . " connected.\n";
$client->appdata = array("channels" => array(), "no_auth" => 0);
// Parse "X-Forwarded-For" header for channel authority whitelist (if any).
$pos = strrpos($client->ipaddr, ":");
if ($pos !== false) $client->ipaddr = substr($client->ipaddr, 0, $pos);
$client->ipaddr = str_replace(array("[", "]"), "", $client->ipaddr);
$ipaddr = IPAddr::NormalizeIP(isset($client->headers["X-Forwarded-For"]) ? $client->headers["X-Forwarded-For"] : $client->ipaddr);
$client->ipaddr = $ipaddr["shortipv6"];
}
$ws = $client->websocket;
$result2 = $ws->Read();
while ($result2["success"] && $result2["data"] !== false)
{
// Attempt to normalize the input.
$data = @json_decode($result2["data"]["payload"], true);
if (!is_array($data)) $result3 = array("channel" => 0, "success" => false, "error" => "Data sent is not an array/object or was not able to be decoded.", "errorcode" => "invalid_data");
else if (!isset($data["cmd"]) || !is_string($data["cmd"]) || $data["cmd"] === "GRANTED" || $data["cmd"] === "JOINED" || $data["cmd"] === "LEFT") $result3 = array("channel" => 0, "success" => false, "error" => "The 'cmd' is missing or invalid.", "errorcode" => "missing_invalid_cmd");
else if ($data["cmd"] === "GRANT")
{
if (!isset($data["channel"]) || !is_string($data["channel"]) || !strlen($data["channel"]) || strlen($data["channel"]) > 256) $result3 = array("channel" => 0, "success" => false, "error" => "The 'channel' is missing or invalid.", "errorcode" => "missing_invalid_channel");
else if (!isset($data["protocol"]) || !is_string($data["protocol"]) || !strlen($data["protocol"]) || strlen($data["protocol"]) > 64) $result3 = array("channel" => 0, "success" => false, "error" => "The 'protocol' is missing or invalid.", "errorcode" => "missing_invalid_protocol");
else if (!isset($data["clientmode"]) || !is_numeric($data["clientmode"]) || (int)$data["clientmode"] < 0 || (int)$data["clientmode"] > 2) $result3 = array("channel" => 0, "success" => false, "error" => "The 'clientmode' is missing or invalid.", "errorcode" => "missing_invalid_clientmode");
else if (!isset($data["extra"]) || !is_array($data["extra"])) $result3 = array("channel" => 0, "success" => false, "error" => "The 'extra' option is missing or invalid.", "errorcode" => "missing_invalid_extra");
else
{
// Create a client authorization token.
if (isset($whitelist[$client->ipaddr]) && ($whitelist[$client->ipaddr] === true || in_array($data["protocol"], $whitelist[$client->ipaddr]))) $auth = true;
else
{
$auth = false;
if (isset($data["token"]) && is_string($data["token"]))
{
// Scan tokens list in constant time.
foreach ($config["tokens"] as $token => $protocols)
{
if (Str::CTstrcmp($token, $data["token"]) === 0 && ($protocols === true || in_array($data["protocol"], $protocols))) $auth = true;
}
}
}
if (!$auth) $result3 = array("channel" => 0, "success" => false, "error" => "Access denied. Invalid or missing authorization.", "errorcode" => "access_denied");
else
{
$token = $rng->GenerateToken();
$tokenmap[$nexttoken] = array(
"expires" => time() + 30,
"token" => $token,
"channel" => $data["channel"],
"protocol" => $data["protocol"],
"clientmode" => $data["clientmode"],
"extra" => $data["extra"],
"makeauth" => (isset($data["makeauth"]) && $data["makeauth"] === true)
);
$result3 = array(
"channel" => 0,
"success" => true,
"cmd" => "GRANTED",
"token" => $token . "-" . $nexttoken,
"channelname" => $data["channel"],
"protocol" => $data["protocol"]
);
$nexttoken++;
}
}
}
else if ($data["cmd"] === "JOIN")
{
if (!isset($data["channel"]) || !is_string($data["channel"]) || !strlen($data["channel"]) || strlen($data["channel"]) > 256) $result3 = array("channel" => 0, "success" => false, "error" => "The 'channel' is missing or invalid.", "errorcode" => "missing_invalid_channel");
else if (!isset($data["protocol"]) || !is_string($data["protocol"]) || !strlen($data["protocol"]) || strlen($data["protocol"]) > 64) $result3 = array("channel" => 0, "success" => false, "error" => "The 'protocol' is missing or invalid.", "errorcode" => "missing_invalid_protocol");
else
{
// Join the channel.
$info = array(
"auth" => false,
"mode" => CM_RECV_ONLY,
"tokenid" => false,
"token" => false,
"extra" => false
);
if ((!isset($data["ipauth"]) || $data["ipauth"] !== false) && isset($whitelist[$client->ipaddr]) && ($whitelist[$client->ipaddr] === true || in_array($data["protocol"], $whitelist[$client->ipaddr]))) $info["auth"] = true;
else if (isset($data["token"]) && is_string($data["token"]))
{
// Scan tokens list in constant time.
foreach ($config["tokens"] as $token => $protocols)
{
if (Str::CTstrcmp($token, $data["token"]) === 0 && ($protocols === true || in_array($data["protocol"], $protocols))) $info["auth"] = true;
}
// Attempt to match a client token.
if (!$info["auth"])
{
$pos = strrpos($data["token"], "-");
if ($pos !== false)
{
$id2 = (int)substr($data["token"], $pos + 1);
$token = substr($data["token"], 0, $pos);
if (isset($tokenmap[$id2]) && Str::CTstrcmp($tokenmap[$id2]["token"], $token) === 0 && $tokenmap[$id2]["channel"] === $data["channel"] && $tokenmap[$id2]["protocol"] === $data["protocol"])
{
$info["mode"] = $tokenmap[$id2]["clientmode"];
$info["tokenid"] = $id2;
$info["token"] = $token;
$info["extra"] = $tokenmap[$id2]["extra"];
if ($tokenmap[$id2]["makeauth"]) $info["auth"] = true;
unset($tokenmap[$id2]);
}
}
}
}
if ($info["auth"]) $info["mode"] = CM_SEND_TO_ANY;
if (!$info["auth"] && $client->appdata["no_auth"] >= 256) $result3 = array("channel" => 0, "success" => false, "error" => "Per-connection channel limit reached.", "errorcode" => "max_channel_limit_reached");
else if (!$info["auth"] && $info["extra"] === false) $result3 = array("channel" => 0, "success" => false, "error" => "Access denied. Invalid or missing token.", "errorcode" => "access_denied");
else
{
// Create the channel if it doesn't exist.
$key = $data["channel"] . "|" . $data["protocol"];
if (!isset($channelmap[$key]))
{
$channelmap[$key] = $nextchannel;
$channels[$nextchannel] = array(
"channel" => $data["channel"],
"protocol" => $data["protocol"],
"clients" => array()
);
$nextchannel++;
}
$channel = $channelmap[$key];
$channels[$channel]["clients"][$id] = $info;
$client->appdata["channels"][$channel] = $info["auth"];
if (!$info["auth"]) $client->appdata["no_auth"]++;
$cleaninfo = $info;
unset($cleaninfo["tokenid"]);
unset($cleaninfo["token"]);
// Notify all clients with sufficient access to send to the new client.
foreach ($channels[$channel]["clients"] as $id2 => $info2)
{
$client2 = $wsserver->GetClient($id2);
if ($client2 === false || $client2->websocket === false) continue;
if ($id !== $id2 && !$info["auth"] && ($info2["mode"] === CM_RECV_ONLY || $info2["mode"] === CM_SEND_TO_AUTHS)) continue;
$ws2 = $client2->websocket;
$result3 = array(
"channel" => $channel,
"success" => true,
"cmd" => "JOINED",
"from" => 0,
"id" => $id,
"info" => $cleaninfo
);
if ($id === $id2)
{
$result3["channelname"] = $data["channel"];
$result3["protocol"] = $data["protocol"];
$result3["clients"] = array();
foreach ($channels[$channel]["clients"] as $id3 => $info3)
{
if ($id !== $id3 && !$info["auth"] && $info["mode"] !== CM_SEND_TO_ANY && !$info3["auth"]) continue;
unset($info3["tokenid"]);
unset($info3["token"]);
$result3["clients"][$id3] = $info3;
}
}
$ws2->Write(json_encode($result3, JSON_UNESCAPED_SLASHES), $result2["data"]["opcode"]);
$wsserver->UpdateClientState($id2);
}
$result3 = false;
}
}
}
else if ($data["cmd"] === "SET_EXTRA")
{
if (!isset($data["channel"])) $result3 = array("channel" => 0, "success" => false, "error" => "The 'channel' is missing.", "errorcode" => "missing_channel");
else if (!is_numeric($data["channel"]) || !isset($channels[(int)$data["channel"]]) || !isset($client->appdata["channels"][(int)$data["channel"]])) $result3 = array("channel" => 0, "success" => false, "error" => "The 'channel' is invalid.", "errorcode" => "invalid_channel");
else if (!$channels[(int)$data["channel"]]["clients"][$client->id]["auth"]) $result3 = array("channel" => 0, "success" => false, "error" => "Access denied. Not an authority.", "errorcode" => "access_denied");
else if (!is_numeric($data["id"]) || !isset($channels[(int)$data["channel"]]["clients"][(int)$data["id"]])) $result3 = array("channel" => 0, "success" => false, "error" => "The 'id' is invalid.", "errorcode" => "invalid_id");
else if (!isset($data["extra"]) || !is_array($data["extra"])) $result3 = array("channel" => 0, "success" => false, "error" => "The 'extra' option is missing or invalid.", "errorcode" => "missing_invalid_extra");
else
{
$channel = (int)$data["channel"];
$id2 = (int)$data["id"];
$info = $channels[(int)$data["channel"]]["clients"][$id2];
$info["extra"] = $data["extra"];
$channels[(int)$data["channel"]]["clients"][$id2] = $info;
// Notify all clients with sufficient access to send to the client.
foreach ($channels[$channel]["clients"] as $id2 => $info2)
{
$client2 = $wsserver->GetClient($id2);
if ($client2 === false || $client2->websocket === false) continue;
if (!$info["auth"] && ($info2["mode"] === CM_RECV_ONLY || $info2["mode"] === CM_SEND_TO_AUTHS)) continue;
$ws2 = $client2->websocket;
$result3 = array(
"channel" => $channel,
"success" => true,
"cmd" => "SET_EXTRA",
"from" => 0,
"id" => $id2,
"extra" => $info["extra"]
);
$ws2->Write(json_encode($result3, JSON_UNESCAPED_SLASHES), $result2["data"]["opcode"]);
$wsserver->UpdateClientState($id2);
}
$result3 = false;
}
}
else if ($data["cmd"] === "LEAVE")
{
if (!isset($data["channel"])) $result3 = array("channel" => 0, "success" => false, "error" => "The 'channel' is missing.", "errorcode" => "missing_channel");
else if (!is_numeric($data["channel"]) || !isset($channels[(int)$data["channel"]]) || !isset($client->appdata["channels"][(int)$data["channel"]])) $result3 = array("channel" => 0, "success" => false, "error" => "The 'channel' is invalid.", "errorcode" => "invalid_channel");
else
{
$channel = (int)$data["channel"];
$result3 = LeaveChannel($client, $channel);
}
}
else
{
if (!isset($data["channel"])) $result3 = array("channel" => 0, "success" => false, "error" => "The 'channel' is missing.", "errorcode" => "missing_channel");
else if (!is_numeric($data["channel"]) || !isset($channels[(int)$data["channel"]]) || !isset($client->appdata["channels"][(int)$data["channel"]])) $result3 = array("channel" => 0, "success" => false, "error" => "The 'channel' is invalid.", "errorcode" => "invalid_channel");
else
{
$channel = (int)$data["channel"];
$info = $channels[$channel]["clients"][$client->id];
if ($info["mode"] === CM_RECV_ONLY) $result3 = array("channel" => $channel, "success" => false, "error" => "Access denied. Sending is not allowed on this channel.", "errorcode" => "access_denied");
else if (!isset($data["to"])) $result3 = array("channel" => $channel, "success" => false, "error" => "The 'to' recipient is missing.", "errorcode" => "missing_to");
else if (!is_numeric($data["to"]) || ((int)$data["to"] > -1 && !isset($channels[$channel]["clients"][(int)$data["to"]]))) $result3 = array("channel" => $channel, "success" => false, "error" => "The 'to' recipient is invalid.", "errorcode" => "invalid_to");
else
{
$to = (int)$data["to"];
unset($data["to"]);
$result3 = array(
"channel" => $channel,
"success" => true,
"from" => $client->id,
"cmd" => $data["cmd"]
);
$result3 = $result3 + $data;
if ($to > -1)
{
$info2 = $channels[$channel]["clients"][$to];
if ($info["mode"] === CM_SEND_TO_AUTHS && !$info2["auth"]) $result3 = array("channel" => $channel, "success" => false, "error" => "The 'to' recipient is invalid.", "errorcode" => "invalid_to");
else
{
$client2 = $wsserver->GetClient($to);
if ($client2 === false || $client2->websocket === false) $result3 = array("channel" => $channel, "success" => false, "error" => "The 'to' recipient is invalid.", "errorcode" => "invalid_to");
else
{
$client2->websocket->Write(json_encode($result3, JSON_UNESCAPED_SLASHES), $result2["data"]["opcode"]);
$wsserver->UpdateClientState($to);
$result3 = false;
}
}
}
else
{
// Broadcast the packet to all accessible clients.
foreach ($channels[$channel]["clients"] as $id2 => $info2)
{
$client2 = $wsserver->GetClient($id2);
if ($client2 === false || $client2->websocket === false) continue;
if ($info["mode"] === CM_SEND_TO_AUTHS && !$info2["auth"]) continue;
$client2->websocket->Write(json_encode($result3, JSON_UNESCAPED_SLASHES), $result2["data"]["opcode"]);
$wsserver->UpdateClientState($id2);
}
$result3 = false;
}
}
}
}
// Send the response.
if ($result3 !== false)
{
$ws->Write(json_encode($result3, JSON_UNESCAPED_SLASHES), $result2["data"]["opcode"]);
$wsserver->UpdateClientState($id);
}
$result2 = $ws->Read();
}
}
foreach ($result["removed"] as $id => $result2)
{
if ($result2["client"]->appdata !== false)
{
echo "WebSocket client ID " . $id . " disconnected.\n";
// Leave associated channels.
foreach ($result2["client"]->appdata["channels"] as $channel => $auth)
{
LeaveChannel($result2["client"], $channel);
}
}
}
$ts = time();
if ($lastservicecheck <= $ts - 3)
{
// Remove expired tokens from the token map.
foreach ($tokenmap as $num => $info)
{
if ($ts >= $info["expires"]) unset($tokenmap[$num]);
else break;
}
// Cleanup RAM.
if (function_exists("gc_mem_caches")) gc_mem_caches();
// Check the status of the two service file options for correct Service Manager integration.
if (file_exists($stopfilename))
{
// Initialize termination.
echo "Stop requested.\n";
$running = false;
}
else if (file_exists($reloadfilename) && !filesize($reloadfilename))
{
// Reload configuration and then remove reload file.
echo "Reload requested. Disconnecting all clients and reloading configuration.\n";
$clients = $wsserver->GetClients();
foreach ($clients as $client)
{
$wsserver->RemoveClient($client->id);
// Leave associated channels.
if ($client->appdata !== false)
{
foreach ($client->appdata["channels"] as $channel => $auth)
{
LeaveChannel($client, $channel);
}
}
}
$config = DRC_LoadConfig();
$whitelist = array();
foreach ($config["whitelist"] as $ipaddr => $protocols)
{
$ipaddr = IPAddr::NormalizeIP($ipaddr);
$whitelist[$ipaddr["shortipv6"]] = $protocols;
}
$wsserver->SetAllowedOrigins($config["origins"]);
file_put_contents($reloadfilename, "DONE");
@unlink($reloadfilename);
}
$lastservicecheck = $ts;
}
} while ($running);
?>