-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmc_rpc_handler.php
78 lines (67 loc) · 1.5 KB
/
mc_rpc_handler.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
<?php
// CGI handler for HERA M&C RPCs
// DEPRECATED
error_reporting(E_ALL);
ini_set('display_errors', true);
ini_set('display_startup_errors', true);
require_once("mc_db.inc");
init_db(MC_DB_NAME);
// return JSON error reply
//
function error($msg) {
$reply = new StdClass;
$reply->success = false;
$reply->message = $msg;
echo json_encode($reply);
}
// return success reply object
//
function success() {
$reply = new StdClass;
$reply->success = true;
return $reply;
}
// handler for create observation RPC
//
function create_observation($req) {
$source = source_lookup_auth($req->authenticator);
if (!$source) {
error("auth failure");
return;
}
$req->source_id = $source->id;
if (!observation_insert_mc($req)) {
error(db_error());
return;
}
$reply = success();
$reply->id = insert_id();
echo json_encode($reply);
}
function create_status($req) {
$source = source_lookup_auth($req->authenticator);
if (!$source) {
error("auth failure");
return;
}
$req->source_id = $source->id;
if (!status_insert($req)) {
error(db_error());
return;
}
$reply = success();
$reply->id = insert_id();
echo json_encode($reply);
}
$req = json_decode($_POST['request']);
switch ($req->operation) {
case 'create_observation':
create_observation($req);
break;
case 'create_status':
create_status($req);
break;
default:
error("unknown op $req->operation");
}
?>