-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync.php
77 lines (71 loc) · 2.37 KB
/
sync.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
<?php
$fi = new FilesystemIterator(__DIR__, FilesystemIterator::SKIP_DOTS);
class sync
{
public $mp4files = array();
public $mp4signatures = array();
public $srt = array();
public $srtsignatures = array();
public $sel = 0;
public $userCount = 0;
}
class users
{
public $ips = array();
public $timestamps = array();
}
$e = new sync();
$userlist = new users();
$ip = $_SERVER['REMOTE_ADDR'];
$newTimeStamp = time();
$dir = __DIR__ . "/users.bin";
if (file_exists($dir)) {
$userlist = json_decode(file_get_contents($dir));
$c = 0;
if (!empty($userlist->ips)) {
foreach ($userlist->ips as $ips) {
$diff = $userlist->timestamps[$c];
$diff = $newTimeStamp-$diff;
if($userlist->ips[$c] !== $ip){
if($diff > 120){
//echo "remove ip; ".$userlist->ips[$c];
unset($userlist->timestamps[$c]);
unset($userlist->ips[$c]);
$userlist->timestamps = array_values($userlist->timestamps);
$userlist->ips = array_values($userlist->ips);
}
}elseif($userlist->ips[$c] === $ip){
$userlist->timestamps[$c] = $newTimeStamp;
//echo "update; ".$userlist->ips[$c];
}
$c++;
}
$isIn = in_array($ip, $userlist->ips);
if(!$isIn){
array_push($userlist->ips, $ip);
array_push($userlist->timestamps, $newTimeStamp."");
}
}else{
array_push($userlist->ips, $ip);
array_push($userlist->timestamps, $newTimeStamp."");
}
file_put_contents($dir, json_encode($userlist));
} else {
array_push($userlist->ips, $ip);
array_push($userlist->timestamps, $newTimeStamp."");
file_put_contents($dir, json_encode($userlist));
}
foreach ($fi as $file) {
if (basename($file) !== "sync.php" && basename($file) !== "users.bin") {
if (pathinfo($file, PATHINFO_EXTENSION) === "mp4") {
array_push($e->mp4files, basename($file));
array_push($e->mp4signatures, hash_file('md5', $file));
} elseif (pathinfo($file, PATHINFO_EXTENSION) === "srt") {
array_push($e->srt, basename($file));
array_push($e->srtsignatures, hash_file('md5', $file));
}
$e->userCount = count($e->ips)+1;
}
}
echo (json_encode($e));
?>