[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r15072 - gauger/web
From: |
gnunet |
Subject: |
[GNUnet-SVN] r15072 - gauger/web |
Date: |
Thu, 21 Apr 2011 18:53:16 +0200 |
Author: bartpolot
Date: 2011-04-21 18:53:15 +0200 (Thu, 21 Apr 2011)
New Revision: 15072
Added:
gauger/web/io.php
Removed:
gauger/web/explore.php
Modified:
gauger/web/ajax.php
gauger/web/graphs
gauger/web/helper.php
gauger/web/hosts
gauger/web/index.php
gauger/web/params.php
gauger/web/plot.php
gauger/web/template.php
gauger/web/template_menu.php
Log:
WiP (implement POSTable data)
Modified: gauger/web/ajax.php
===================================================================
--- gauger/web/ajax.php 2011-04-21 15:14:14 UTC (rev 15071)
+++ gauger/web/ajax.php 2011-04-21 16:53:15 UTC (rev 15072)
@@ -20,7 +20,7 @@
*/
include "params.php"; // Manage all parameters given by the user
-include "explore.php"; // Gather all existing hosts and counters
+include "io.php"; // Gather all existing hosts and counters
init_params();
explore();
Deleted: gauger/web/explore.php
===================================================================
--- gauger/web/explore.php 2011-04-21 15:14:14 UTC (rev 15071)
+++ gauger/web/explore.php 2011-04-21 16:53:15 UTC (rev 15072)
@@ -1,132 +0,0 @@
-<?php
-/** explore.php
-
- This file is part of gauger.
- Copyright 2011 Bartlomiej Polot
-
- gauger is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- gauger is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with gauger. If not, see <http://www.gnu.org/licenses/>.
-
-*/
-$CONF = parse_ini_file('gauger.conf');
-$DATADIR = array_key_exists('data', $CONF) && $CONF["data"] ? $CONF['data'] :
'data/';
-$PAGELENGTH = array_key_exists('page_length', $CONF) && $CONF['page_lenght'] ?
$CONF['page_lenght'] : 5;
-if ($DATADIR[strlen($DATADIR)-1] != '/') $DATADIR .= '/';
-$hosts = array();
-$metrics = array();
-$metrics_c = array();
-
-function get_counter_name($s) {
- $s = str_replace('-SLASH-', '/', $s);
- if(($b = strpos($s, ':::')) !== FALSE)
- $b += 3;
- else
- $b = 0;
- if(($e = strpos($s, '___')) === FALSE)
- return substr($s, $b);
- return substr($s, $b, $e-$b);
-}
-
-function get_counter_unit($s) {
- $s = str_replace('-SLASH-', '/', $s);
- if(($b = strpos($s, '___')) !== FALSE)
- return substr($s, $b+3);
- else
- return "";
-}
-
-function get_counter_category($s) {
- $s = str_replace('-SLASH-', '/', $s);
- if(($b = strpos($s, ':::')) !== FALSE)
- return substr($s, 0, $b);
- else
- return "";
-}
-
-function get_range_global() {
- global $DATADIR;
- $f = fopen($DATADIR.'global_range.dat', 'r');
- $buffer = fgets($f, 512);
- fclose($f);
- return explode(' ', $buffer);
-}
-
-function get_range($host, $counter) {
- global $DATADIR;
- if(empty($host) || empty($counter)) return get_range_global();
- $f = @fopen("$DATADIR$host/$counter.dat", 'r');
- if ($f === false) return get_range_global();
- $b = false;
- while (($buffer = fgets($f, 512)) !== false) {
- if($b === false) {$b = explode(' ', $buffer); $b = $b[0]; }
- $e = $buffer;
- }
- fclose($f);
- $e = explode(' ', $e);
- $e = $e[0];
- return Array($b, $e);
-}
-
-function get_local_maximum($h, $g, $s, $e) {
- global $DATADIR;
- $lm = false;
- $f = @fopen("$DATADIR$h/$g.dat", 'r');
- if ($f === false) return 1;
- while (($buffer = fgets($f, 512)) !== false) {
- $l = explode(' ', $buffer);
- if($l[0] >= $s && $l[0] <= $e) {
- if($lm === false || $l[1] > $lm) $lm = $l[1];
- }
- }
- fclose($f);
- return $lm ? $lm : 1;
-}
-
-function explore() {
- global $DATADIR;
- global $hosts;
- global $metrics;
- global $metrics_c;
- global $q;
- $d = dir($DATADIR);
- while (false !== ($entry = $d->read())) {
- if (is_dir($DATADIR.$entry) && !($entry[0] == ".")) {
- $hosts[$entry] = array();
- $d2 = dir($DATADIR.$entry);
- while (false !== ($counter = $d2->read())) {
- // Do not include files containing dots or tildes or
incomplete files
- if (($q === "" || strpos($counter, $q) !== false) &&
- preg_match("/(\.|~)/", $counter) === 0 &&
- is_file("$DATADIR$entry/$counter.dat")) {
- $hosts[$entry][] = $counter;
- $metrics[$counter] = get_counter_name($counter);
- $metrics_c[get_counter_category($counter)][$counter] =
get_counter_name($counter);
- }
- }
- }
- }
-
- ksort($hosts);
- foreach ($hosts as $host => $a) {
- sort(&$hosts[$host]);
- }
- foreach ($metrics_c as $id => $a) {
- ksort(&$metrics_c[$id]);
- }
- ksort(&$metrics_c);
- if (array_key_exists('', $metrics_c)) {
- $others = array_shift($metrics_c);
- $metrics_c[''] = $others;
- }
- $d->close();
-}
Modified: gauger/web/graphs
===================================================================
--- gauger/web/graphs 2011-04-21 15:14:14 UTC (rev 15071)
+++ gauger/web/graphs 2011-04-21 16:53:15 UTC (rev 15072)
@@ -1,29 +1,21 @@
<?php
-$es = explode('/',$_SERVER['PATH_INFO']);
-// foreach($es as $i => $e) {
-// $es[$i] = explode(',',$e);
-// }
+include "helper.php";
-$basedir = preg_replace('/(.*)\/.*/','\1',$_SERVER['SCRIPT_NAME']);
-
switch($_SERVER['REQUEST_METHOD']) {
case 'GET':
- $_GET['graph'] = $es[1];
- $_REQUEST['graph'] = $es[1];
- include "helper.php"; // Auxiliary functions
+ $_REQUEST['graph'] = $_GET['graph'] = count($urlpath) > 1 ?
$urlpath[1] : "";
+
include "params.php"; // Manage all parameters given by the user
- include "explore.php"; // Gather all existing hosts and counters
+ include "io.php"; // Gather all existing hosts and counters
init_params();
explore();
-// echo "<pre>";
-// print_r($_GET);
-// die();
include "template.php"; // Display info
break;
case 'POST':
- echo "method is post";
- break;
+ case 'PUT':
+ case 'DELETE':
default:
- echo "method is.. not allowed";
+ echo "method is not allowed";
+ die();
}
\ No newline at end of file
Modified: gauger/web/helper.php
===================================================================
--- gauger/web/helper.php 2011-04-21 15:14:14 UTC (rev 15071)
+++ gauger/web/helper.php 2011-04-21 16:53:15 UTC (rev 15072)
@@ -18,7 +18,54 @@
along with gauger. If not, see <http://www.gnu.org/licenses/>.
*/
+
+function remove_slashes($s) {
+ return str_replace('/', '-SLASH-', $s);
+}
+
+function put_slashes($s) {
+ return str_replace('-SLASH-', '/', $s);
+}
+
+function get_counter_name($s) {
+ $s = put_slashes($s);
+ if(($b = strpos($s, ':::')) !== FALSE)
+ $b += 3;
+ else
+ $b = 0;
+ if(($e = strpos($s, '___')) === FALSE)
+ return substr($s, $b);
+ return substr($s, $b, $e-$b);
+}
+
+function get_counter_unit($s) {
+ $s = put_slashes($s);
+ if(($b = strpos($s, '___')) !== FALSE)
+ return substr($s, $b+3);
+ else
+ return "";
+}
+
+function get_counter_category($s) {
+ $s = put_slashes($s);
+ if(($b = strpos($s, ':::')) !== FALSE)
+ return substr($s, 0, $b);
+ else
+ return "";
+}
+
+
function url($r = '') {
global $basedir;
return $basedir.'/'.$r;
-}
\ No newline at end of file
+}
+
+if(array_key_exists('PATH_INFO', $_SERVER))
+ $urlpath = explode('/',$_SERVER['PATH_INFO']);
+else
+ $urlpath = array();
+// foreach($es as $i => $e) {
+// $es[$i] = explode(',',$e);
+// }
+
+$basedir = preg_replace('/(.*)\/.*/','\1',$_SERVER['SCRIPT_NAME']);
Modified: gauger/web/hosts
===================================================================
--- gauger/web/hosts 2011-04-21 15:14:14 UTC (rev 15071)
+++ gauger/web/hosts 2011-04-21 16:53:15 UTC (rev 15072)
@@ -1,29 +1,31 @@
<?php
-$es = explode('/',$_SERVER['PATH_INFO']);
-// foreach($es as $i => $e) {
-// $es[$i] = explode(',',$e);
-// }
+include "helper.php";
-$basedir = preg_replace('/(.*)\/.*/','\1',$_SERVER['SCRIPT_NAME']);
-
switch($_SERVER['REQUEST_METHOD']) {
case 'GET':
- $_GET['host'] = $es[1];
- $_REQUEST['host'] = $es[1];
- include "helper.php"; // Auxiliary functions
+ $_REQUEST['host'] = $_GET['host'] = count($urlpath) > 1 ? $urlpath[1]
: "";
+
include "params.php"; // Manage all parameters given by the user
- include "explore.php"; // Gather all existing hosts and counters
+ include "io.php"; // Gather all existing hosts and counters
init_params();
explore();
-// echo "<pre>";
-// print_r($_GET);
-// die();
include "template.php"; // Display info
break;
case 'POST':
- echo "method is post";
+ $_REQUEST['host'] = $_POST['host'] = count($urlpath) > 1 ? $urlpath[1]
: "";
+ include "params.php"; // Manage all parameters given by the user
+ include "io.php"; // Gather all existing hosts and counters
+ $s = $_POST['user'].','.$_POST['pass'];
+ if(!array_key_exists($s, $CONF) || $CONF[$s] != $_POST['host']) {
+ header('HTTP/1.1 403 Forbidden');
+ echo "user/pass not correct";
+ die();
+ }
+ add_data_to_host($_POST['host'], $_POST['name'], $_POST['revision'],
$_POST['value']);
break;
+ case 'PUT':
+ case 'DELETE':
default:
- echo "method is.. not allowed";
+ echo "method is not allowed";
}
\ No newline at end of file
Modified: gauger/web/index.php
===================================================================
--- gauger/web/index.php 2011-04-21 15:14:14 UTC (rev 15071)
+++ gauger/web/index.php 2011-04-21 16:53:15 UTC (rev 15072)
@@ -21,7 +21,7 @@
$basedir = preg_replace('/(.*)\/.*/','\1',$_SERVER['SCRIPT_NAME']);
include "helper.php";
include "params.php"; // Manage all parameters given by the user
-include "explore.php"; // Gather all existing hosts and counters
+include "io.php"; // Gather all existing hosts and counters
init_params();
explore();
include "template.php"; // Display info
\ No newline at end of file
Copied: gauger/web/io.php (from rev 15052, gauger/web/explore.php)
===================================================================
--- gauger/web/io.php (rev 0)
+++ gauger/web/io.php 2011-04-21 16:53:15 UTC (rev 15072)
@@ -0,0 +1,113 @@
+<?php
+/** explore.php
+
+ This file is part of gauger.
+ Copyright 2011 Bartlomiej Polot
+
+ gauger is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ gauger is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with gauger. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+$CONF = parse_ini_file('gauger.conf');
+$DATADIR = array_key_exists('data', $CONF) && $CONF["data"] ? $CONF['data'] :
'data/';
+$PAGELENGTH = array_key_exists('page_length', $CONF) && $CONF['page_lenght'] ?
$CONF['page_lenght'] : 5;
+if ($DATADIR[strlen($DATADIR)-1] != '/') $DATADIR .= '/';
+$hosts = array();
+$metrics = array();
+$metrics_c = array();
+
+
+function get_range_global() {
+ global $DATADIR;
+ $f = fopen($DATADIR.'global_range.dat', 'r');
+ $buffer = fgets($f, 512);
+ fclose($f);
+ return explode(' ', $buffer);
+}
+
+function get_range($host, $counter) {
+ global $DATADIR;
+ if(empty($host) || empty($counter)) return get_range_global();
+ $f = @fopen("$DATADIR$host/$counter.dat", 'r');
+ if ($f === false) return get_range_global();
+ $b = false;
+ while (($buffer = fgets($f, 512)) !== false) {
+ if($b === false) {$b = explode(' ', $buffer); $b = $b[0]; }
+ $e = $buffer;
+ }
+ fclose($f);
+ $e = explode(' ', $e);
+ $e = $e[0];
+ return Array($b, $e);
+}
+
+function get_local_maximum($h, $g, $s, $e) {
+ global $DATADIR;
+ $lm = false;
+ $f = @fopen("$DATADIR$h/$g.dat", 'r');
+ if ($f === false) return 1;
+ while (($buffer = fgets($f, 512)) !== false) {
+ $l = explode(' ', $buffer);
+ if($l[0] >= $s && $l[0] <= $e) {
+ if($lm === false || $l[1] > $lm) $lm = $l[1];
+ }
+ }
+ fclose($f);
+ return $lm ? $lm : 1;
+}
+
+function explore() {
+ global $DATADIR;
+ global $hosts;
+ global $metrics;
+ global $metrics_c;
+ global $q;
+ $d = dir($DATADIR);
+ while (false !== ($entry = $d->read())) {
+ if (is_dir($DATADIR.$entry) && !($entry[0] == ".")) {
+ $hosts[$entry] = array();
+ $d2 = dir($DATADIR.$entry);
+ while (false !== ($counter = $d2->read())) {
+ // Do not include files containing dots or tildes or
incomplete files
+ if (($q === "" || strpos($counter, $q) !== false) &&
+ preg_match("/(\.|~)/", $counter) === 0 &&
+ is_file("$DATADIR$entry/$counter.dat")) {
+ $hosts[$entry][] = $counter;
+ $metrics[$counter] = get_counter_name($counter);
+ $metrics_c[get_counter_category($counter)][$counter] =
get_counter_name($counter);
+ }
+ }
+ }
+ }
+
+ ksort($hosts);
+ foreach ($hosts as $host => $a) {
+ sort(&$hosts[$host]);
+ }
+ foreach ($metrics_c as $id => $a) {
+ ksort(&$metrics_c[$id]);
+ }
+ ksort(&$metrics_c);
+ if (array_key_exists('', $metrics_c)) {
+ $others = array_shift($metrics_c);
+ $metrics_c[''] = $others;
+ }
+ $d->close();
+}
+
+function add_data_to_host($h, $g, $rev, $value) {
+ global $CONF;
+ $datadir = preg_replace('/(.*)\/.*/', '\1', $_SERVER['SCRIPT_FILENAME']);
+ $datadir .= '/' . $CONF['data'] . '/' . remove_slashes($h) . '/' .
remove_slashes($g);
+ die($datadir);
+}
Modified: gauger/web/params.php
===================================================================
--- gauger/web/params.php 2011-04-21 15:14:14 UTC (rev 15071)
+++ gauger/web/params.php 2011-04-21 16:53:15 UTC (rev 15072)
@@ -20,8 +20,8 @@
*/
$range_parameters = Array('x_max', 'x_min',
- 'y_max', 'y_min',
- 'png_x_size', 'png_y_size');
+ 'y_max', 'y_min',
+ 'png_x_size', 'png_y_size');
$mode_host = FALSE;
$mode_graph = FALSE;
$current = "";
Modified: gauger/web/plot.php
===================================================================
--- gauger/web/plot.php 2011-04-21 15:14:14 UTC (rev 15071)
+++ gauger/web/plot.php 2011-04-21 16:53:15 UTC (rev 15072)
@@ -203,7 +203,7 @@
}
include "params.php";
-include "explore.php";
+include "io.php";
init_params();
explore();
Modified: gauger/web/template.php
===================================================================
--- gauger/web/template.php 2011-04-21 15:14:14 UTC (rev 15071)
+++ gauger/web/template.php 2011-04-21 16:53:15 UTC (rev 15072)
@@ -488,10 +488,6 @@
}
}
- function debug(param) {
- $( "#debug" ).html($( "#debug" ).html() + param + ' ');
- }
-
function reset_session() {
$.cookie('instant_search_hosts', null);
$.cookie('instant_search_metrics', null);
@@ -511,6 +507,14 @@
return s.replace(/.*___/g, '');
}
+ function debug(param) {
+ $( "#debug" ).html($( "#debug" ).html() + param + ' ');
+ }
+
+ function test() {
+ alert("hai");
+ }
+
</script>
</head>
Modified: gauger/web/template_menu.php
===================================================================
--- gauger/web/template_menu.php 2011-04-21 15:14:14 UTC (rev 15071)
+++ gauger/web/template_menu.php 2011-04-21 16:53:15 UTC (rev 15072)
@@ -53,4 +53,5 @@
<div class="slider" id="change_size_y_slider"></div>
</div> |
<a href="#" onclick="reset_session(); return false;">Reset
Session</a>
+ | <a href="#" onclick="test(); return false;">Test</a>
</div>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r15072 - gauger/web,
gnunet <=