-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.php
68 lines (59 loc) · 1.71 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
<?php
require_once dirname(__FILE__) . '/Shingetsu_Server.php';
require_once dirname(__FILE__) . '/config.php';
$server = new Shingetsu_Server();
if (!file_exists($server->nodelist)) {
touch($server->nodelist);
chmod($server->nodelist, 0666);
file_put_contents($server->nodelist, 'node.shingetsu.info:8000/server.cgi' . PHP_EOL);
}
$support_method = array(
'ping', 'node',
'join', 'bye',
'have', 'get',
'head', 'update',
'recent',
);
$pathinfo = array();
if (isset($_SERVER['PATH_INFO'])) {
$pathinfo = explode('/', $_SERVER['PATH_INFO']);
}
if (!isset($pathinfo[1])) {
exit('method not found.');
}
if (!in_array($pathinfo[1], $support_method)) {
exit('method not support.');
}
$log_file = dirname(__FILE__) . '/data/log.txt';
if (!file_exists($log_file)) {
touch($log_file);
chmod($log_file, 0666);
}
$log = file_get_contents($log_file);
$log = $log . date('Y-m-d H:i:s') . "|{$_SERVER['REMOTE_ADDR']}|{$_SERVER['PATH_INFO']}\n";
file_put_contents($log_file, $log);
$command = $pathinfo[1];
if ($command === 'join' || $command === 'bye') {
$server->$command($pathinfo[2], $_SERVER['REMOTE_ADDR']);
} else if ($command === 'get' || $command === 'head') {
$id = false;
if (isset($pathinfo[4])) {
$id = $pathinfo[4];
}
$server->$command($pathinfo[2], $pathinfo[3], $id);
} else if ($command === 'update') {
$node = $pathinfo[5];
if ($node[0] == ':') {
$node = $_SERVER['REMOTE_ADDR'] . $node;
}
$server->update(
$filename = $pathinfo[2],
$timestamp = $pathinfo[3],
$id = $pathinfo[4],
$node
);
} else if (isset($pathinfo[2])) {
$server->$command($pathinfo[2]);
} else {
$server->$command();
}