-
Notifications
You must be signed in to change notification settings - Fork 7
/
worker.php
62 lines (58 loc) · 1.8 KB
/
worker.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
<?php
##
# Worker
# Run this file every 30 minutes
##
if (PHP_SAPI !== "cli") die("this should be run only via cli");
require("inc/settings.php");
require("inc/db.php");
$cli = new MongoClient(DB_SERVER);
$db = $cli->selectDB(DB_NAME);
if (isset($argv[1])){
switch ($argv[1]) {
case "update_cache":
##
# Update global distinct values
##
updateOverviewCache($db);
break;
case "del_old":
##
# Delete old and unrated reports
##
$db->reports->remove(array(
'timestamp' => array('$lt' => (time() - (60*60*24*21))),
'rate' => 0
));
//count each user results
$users = $db->users->find(array('api_key' => 1));
foreach ($users as $user) {
$reports_count = $db->reports->count(array('user' => $user['username']));
$db->users->update(
array('username'=>$user['username']),
array('$set' => array('reports_count' => $reports_count))
);
}
break;
case "create_indexes":
$db->reports->ensureIndex(array(
//'report.ports.portid' => 1,
//'report.ports.service.name' => 1,
//'report.ports.state' => 1,
'timestamp' => -1,
//'report.geoip.country' => 1,
//'user' => 1,
//'rate' => 1
), array("name" => "sl_global"));
break;
case "delete_indexes":
$db->reports->deleteIndexes();
break;
default:
die("Wrong action.\n");
break;
}
} else {
die("No action specified. See documentation or script sources.\n");
}
?>