-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsapi.php
More file actions
88 lines (82 loc) · 1.58 KB
/
sapi.php
File metadata and controls
88 lines (82 loc) · 1.58 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
include("inc/settings.php");
if($_GET["graph"] && is_numeric($_GET["value"]) && !$_POST)
{
$graph = $_GET['graph'];
$value = $_GET['value'];
if(is_numeric($_GET['timestamp']))
{
$timestamp = $_GET['timestamp'];
}
else
{
$timestamp = time();
}
$m = new MongoClient( "mongodb://".MONGO_HOST );
$dbm = $m->buckets;
$col = $dbm->$graph;
$document['value'] = $value;
$document['timestamp'] = $timestamp;
$r = $col->insert($document);
if($r['err'] == null)
{
$ret['status'] = 200;
$ret['msg'] = "stored";
}
else
{
$ret['status'] = 400;
$ret['msg'] = "unable to store value";
}
echo json_encode($ret);
}
elseif($_POST)
{
if(!isset($_POST['graph']))
{
$arr['status'] = 400;
$arr['msg'] = "no field named graph received";
echo json_encode($arr);
die;
}
if(!is_numeric($_POST['value']))
{
$arr['status'] = 400;
$arr['msg'] = "field named value must be numeric";
echo json_encode($arr);
die;
}
$graph = $_POST['graph'];
$value = $_POST['value'];
if(is_numeric($_POST['timestamp']))
{
$timestamp = $_POST['timestamp'];
}
else
{
$timestamp = time();
}
$m = new MongoClient( "mongodb://".MONGO_HOST );
$dbm = $m->buckets;
$col = $dbm->$graph;
$document['value'] = $value;
$document['timestamp'] = $timestamp;
$r = $col->insert($document);
if($r['err'] == null)
{
$ret['status'] = 200;
$ret['msg'] = "stored";
}
else
{
$ret['status'] = 400;
$ret['msg'] = "unable to store value";
}
echo json_encode($ret);
}
else
{
$arr['status'] = 400;
$arr['msg'] = "no value and graph parameter given";
echo json_encode($arr);
}