-
Notifications
You must be signed in to change notification settings - Fork 2
/
import.php
132 lines (117 loc) · 2.97 KB
/
import.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?
require_once('common.php');
require('header.php');
$err = '';
$ds = array();
$rra = array();
$step = -1;
$got_data = 0;
$ds_p = array();
$rra_p = array();
function rq($s) {
if (preg_match('/^"(.*)"$/', $s, $m)) {
return $m[1];
}
return $s;
}
function parse_input() {
global $ds, $rra, $step, $got_data, $ds_p, $rra_p;
$s = gpost('text', '', '');
if ($s != '') {
$text = explode("\n", $s);
foreach ($text as $line) {
$line = trim($line);
if (preg_match('/^(ds|rra)\[([a-zA-Z0-9_]+)\]\.(\S+) = (.+)$/', $line, $m)) {
if ($m[1] == 'ds') {
$ds[$m[2]][$m[3]] = $m[4];
} elseif ($m[1] == 'rra') {
$rra[$m[2]][$m[3]] = $m[4];
} else {
trigger_error('oops', E_USER_ERROR);
}
} elseif (preg_match('/^step = (\d+)$/', $line, $m)) {
$step = $m[1];
} else {
// let's not be too strict and do not warn about unknown lines
}
}
if ($step == -1) {
return "Unable to find the step value.";
}
if (count($ds) == 0) {
return "No data sources found.";
}
if (count($rra) == 0) {
return "No RRAs found.";
}
foreach ($ds as $name => $data) {
if (!array_key_exists('type', $data)) {
return "Type for DS '$name' is unknown";
}
$ds_p[] = array(
'name' => rq($name),
'type' => rq($data['type']),
);
}
foreach ($rra as $name => $data) {
if (!array_key_exists('cf', $data)) {
return "CF for RRA '$name' is unknown";
}
if (!array_key_exists('rows', $data)) {
return "Rows for RRA '$name' are unknown";
}
if (!array_key_exists('pdp_per_row', $data)) {
return "pdp_per_row for RRA '$name' is unknown";
}
$rra_p[] = array(
'cf' => rq($data['cf']),
'steps' => rq($data['pdp_per_row']),
'rows' => rq($data['rows']),
);
}
$got_data = 1;
}
return '';
}
function dump_p($ar, $name) {
foreach ($ar as $i => $data) {
foreach ($data as $k => $v) {
?>
<input name="<?=$name?><?=$k?>_<?=$i?>" type="hidden" value="<?=h($v)?>">
<?
}
}
}
$err = parse_input();
?>
<? if ($err != '') { ?>
<h1 id="error" style="background-color: red">ERROR</h1>
<p><?=h($err)?></p>
<? } ?>
<? if ($got_data) { ?>
<h1 id="ok" style="background-color: green">Parsing successful</h1>
<dl>
<dt>
<form method="post" action="rrdgraph.php">
<input name="step" type="hidden" value="<?=h($step)?>">
<input name="ds_rows" type="hidden" value="<?=h(count($ds_p))?>">
<input name="rra_rows" type="hidden" value="<?=h(count($rra_p))?>">
<?dump_p($ds_p, 'ds')?>
<?dump_p($rra_p, 'rra')?>
<input type="submit" value="Proceed to Graph a RRD">
</form>
</dt>
</dl>
<? } ?>
<form method="post" action="?">
<h1 id="links">This section allows you to import and then create a graph for an existing RRD</h1>
<dl>
<dt>Please execute `rrdtool info <b>filename.rrd</b>` on your RRD file and then paste the whole output below:</dt>
<dd>
<textarea name="text" cols="80" rows="30"><?=h(gpost('text', '', ''))?></textarea><br>
<input type="submit" value="Submit">
</dd>
</dl>
</form>
<?
require('footer.php');