[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r15077 - gauger/web
From: |
gnunet |
Subject: |
[GNUnet-SVN] r15077 - gauger/web |
Date: |
Tue, 26 Apr 2011 16:30:13 +0200 |
Author: bartpolot
Date: 2011-04-26 16:30:13 +0200 (Tue, 26 Apr 2011)
New Revision: 15077
Modified:
gauger/web/hosts
gauger/web/io.php
gauger/web/plot.php
gauger/web/template.php
Log:
WiP
Modified: gauger/web/hosts
===================================================================
--- gauger/web/hosts 2011-04-26 13:41:09 UTC (rev 15076)
+++ gauger/web/hosts 2011-04-26 14:30:13 UTC (rev 15077)
@@ -5,7 +5,7 @@
switch($_SERVER['REQUEST_METHOD']) {
case 'GET':
$_REQUEST['host'] = $_GET['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
init_params();
@@ -21,7 +21,7 @@
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':
Modified: gauger/web/io.php
===================================================================
--- gauger/web/io.php 2011-04-26 13:41:09 UTC (rev 15076)
+++ gauger/web/io.php 2011-04-26 14:30:13 UTC (rev 15077)
@@ -18,15 +18,46 @@
along with gauger. If not, see <http://www.gnu.org/licenses/>.
*/
+
+/**
+ * CONF: main configuration array
+ */
$CONF = parse_ini_file('gauger.conf');
-$DATADIR = array_key_exists('data', $CONF) && $CONF["data"] ? $CONF['data'] :
'data/';
+
+/**
+ * DATADIR: root data directory
+ */
+$DATADIR = array_key_exists('data', $CONF) && $CONF['data'] ? $CONF['data'] :
'data/';
+
+/**
+ * PAGELENGTH: number of graphs per page in host mode
+ */
$PAGELENGTH = array_key_exists('page_length', $CONF) && $CONF['page_lenght'] ?
$CONF['page_lenght'] : 5;
if ($DATADIR[strlen($DATADIR)-1] != '/') $DATADIR .= '/';
+
+/**
+ * hosts: array with all hosts in form $hosts[hostname] = [metrics]
+ * alphabetic order
+ */
$hosts = array();
+
+/**
+ * metrics: array with all the metrics in format $metric[filename] = metricname
+ * alphabetic order
+ */
$metrics = array();
+
+/**
+ * metrics_c: metrics in categories: $metric_c[cat][filename] = metricname
+ * alphabetic order
+ */
$metrics_c = array();
+/**
+ * get_range_global: get global range of data
+ * @return size 2 array with [min, max]
+ */
function get_range_global() {
global $DATADIR;
$f = fopen($DATADIR.'global_range.dat', 'r');
@@ -35,6 +66,12 @@
return explode(' ', $buffer);
}
+/**
+ * get_range: get range of a metric in a host
+ * @param $host name of the host
+ * @param $counter file name of the metric
+ * @return size 2 array with [min, max]
+ */
function get_range($host, $counter) {
global $DATADIR;
if(empty($host) || empty($counter)) return get_range_global();
@@ -51,6 +88,14 @@
return Array($b, $e);
}
+/**
+ * get_local_maximum: get the highest value between two indexes in a given
+ * host and metric
+ * @param $h name of the host
+ * @param $g file name of the metric
+ * @param $s begining of the range to consider
+ * @param $e end of the range
+ */
function get_local_maximum($h, $g, $s, $e) {
global $DATADIR;
$lm = false;
@@ -105,9 +150,97 @@
$d->close();
}
+function previous_record($f, $pos) {
+ fseek($f, $pos-1, SEEK_SET);
+ while(($b = fread($f, 1)) != "\n") {
+ fseek($f, -2, SEEK_CUR);
+ if(ftell($f) == 0) return 0;
+ } // at end of record
+ fseek($f, -2, SEEK_CUR);
+ while(($b = fread($f, 1)) != "\n") {
+ fseek($f, -2, SEEK_CUR);
+ if(ftell($f) == 0) return 0;
+ } // at beginning of record
+ return ftell($f);
+}
+
+function add_data_to_file($filename, $rev, $data) {
+ echo "<pre>";
+ $f = @fopen("$filename", 'r+');
+ if ($f === false) return false;
+ $size = filesize($filename);
+ $pos = $gap = $size/2;
+ fseek($f, $pos, SEEK_SET);
+ echo "Size: $size\n";
+ while ($gap > 0) { // max log2(size) steps
+ echo "GAP: $gap POS: " . ftell($f) . "\n";
+ $gap = $gap > 1 ? (int)(($gap+1)/2) : 0;
+ $lastpos = $pos;
+ if(ftell($f) != 0) {
+ echo '#';
+ $buffer = fgets($f, 512); //garbage til EOF
+ }
+ $pos = ftell($f);
+ $buffer = fgets($f, 512);
+ $pos2 = ftell($f);
+ $buffer2 = fgets($f, 512);
+ $l = explode(' ', $buffer);
+ $l2 = explode(' ', $buffer2);
+ if((int)$l[0] > (int)$rev) {
+ if($pos == 0) {
+ $pos2 = $pos;
+ break;
+ }
+ fseek($f, max(previous_record($f, $pos) - $gap, 0), SEEK_SET);
+ } else if((int)$l2[0] < (int)$rev && $pos2 != $size) {
+ fseek($f, $pos + $gap, SEEK_SET);
+ } else {
+ break;
+ }
+ }
+ fseek($f, $pos2, SEEK_SET);
+ $buffer = $pos2 < $size ? fread($f, $size - $pos2) : "";
+ fseek($f, $pos2, SEEK_SET);
+ fwrite($f, "$rev $data\n");
+ fwrite($f, $buffer);
+ fclose($f);
+ return true;
+}
+
+function check_permissions($path, $type = 'file') {
+ if(file_exists($path)) {
+ $f = 'is_'.$type;
+ if(!$f($path)) {
+ header('HTTP/1.1 500 Internal Server Error');
+ die("$path exists and is not a $type");
+ } else {
+ if(!is_writeable($path)) {
+ header('HTTP/1.1 500 Internal Server Error');
+ die("no write permissions for $path");
+ }
+ }
+ } else {
+ $c = $type == 'dir' ? 'mkdir' : 'touch';
+ if(!$c($path)){
+ header('HTTP/1.1 500 Internal Server Error');
+ die("cannot create $path");
+ }
+ }
+}
+
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);
+ $datadir .= '/' . $CONF['data'];
+ check_permissions($datadir, 'dir');
+ $datadir .= '/' . remove_slashes($h);
+ check_permissions($datadir, 'dir');
+ $datadir .= '/' . remove_slashes($g);
+ check_permissions($datadir, 'file');
+ check_permissions("$datadir.dat", 'file');
+ if(!add_data_to_file($datadir, $rev, $value)) {
+ header('HTTP/1.1 500 Internal Server Error');
+ die("cannot add data to $datadir");
+ }
+ die();
}
Modified: gauger/web/plot.php
===================================================================
--- gauger/web/plot.php 2011-04-26 13:41:09 UTC (rev 15076)
+++ gauger/web/plot.php 2011-04-26 14:30:13 UTC (rev 15077)
@@ -202,6 +202,7 @@
return $out;
}
+include "helper.php";
include "params.php";
include "io.php";
init_params();
Modified: gauger/web/template.php
===================================================================
--- gauger/web/template.php 2011-04-26 13:41:09 UTC (rev 15076)
+++ gauger/web/template.php 2011-04-26 14:30:13 UTC (rev 15077)
@@ -512,7 +512,7 @@
}
function test() {
- alert("hai");
+ $.get('ajax.php');
}
</script>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r15077 - gauger/web,
gnunet <=