-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathp4.php
More file actions
70 lines (55 loc) · 1.66 KB
/
Copy pathp4.php
File metadata and controls
70 lines (55 loc) · 1.66 KB
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
<?php
require('app.php');
require('lib/encode.php');
require('lib/rabbit.php');
if(isset($config)) {
$rabbit = find_rabbit($db, $_REQUEST['sn']);
date_default_timezone_set($config['server-timezone']);
$apps = scheduled_apps_for_rabbit($db, $rabbit);
} else {
$rabbit = false;
$apps = array();
}
$seen_apps = array();
# Ping request from a rabbit
$ping_result_data = array(0x7f);
# encode ping interval block
array_push($ping_result_data, 0x03, 0x00, 0x00, 0x01, 10);
foreach($apps as $app) {
$name = $app['application'];
if(!array_key_exists($name, $seen_apps)) {
$seen_apps[$name] = true;
$success = true;
$app_ran = false;
try {
require_once('apps/'.$name.'_app.php');
if(($rabbit['asleep'] == 0) || in_array($name, $sleepy_instance_apps)) {
$app_ran = true;
$app_data = unserialize($app['data']);
$result = call_user_func($name."_rabbit_app", $db, $rabbit, $app_data);
if($result) {
$app['data'] = serialize($result);
save_rabbit_app($db, $rabbit, $app);
}
}
} catch (Exception $e) {
$success = false;
error_log("Something went wrong in an app: ".$e->getMessage());
}
if($app_ran) {
if($app['reschedule_interval'] && $success) {
reschedule_rabbit_app($db, $app);
} else {
remove_rabbit_app($db, $app);
}
}
}
}
# encode end of data
array_push($ping_result_data, 0xff, 0x0a);
#hex_dump(encode_array($ping_result_data));
echo encode_array($ping_result_data);
if($rabbit) {
finished_rabbit($db, $rabbit);
}
?>