http_send_data($content); exit; } ob_start(); html_start(); if (isset($_GET["tz"])) { $tz = $_GET["tz"]; } else { $tz = "EEST"; } printf('<h2><a href="%s">%s</a></h2>' . "\n", $CONFIG['weburl'] . 'host?h=' . htmlentities($host) . '&tz=' . $tz, $host); $term = array('2 hours' => 3600 * 2, '8 hours' => 3600 * 8, 'day' => 86400, 'week' => 86400 * 7, 'month' => 86400 * 31, 'quarter' => 86400 * 31 * 3, 'year' => 86400 * 365); $args = $_GET; print "<ul>\n"; foreach ($term as $key => $s) { $args['s'] = $s; printf('<li><a href="%s%s">%s</a></li>' . "\n", $CONFIG['weburl'], build_url('detail', $args), $key); } print "</ul>\n"; $plugins = collectd_plugins($host); if (!$plugins) { echo "Unknown host\n"; return false; } # show graph printf('<img src="%s%s">' . "\n", $CONFIG['weburl'], build_url('graph', $_GET)); html_end(); $content = ob_get_clean(); http_cache_etag(); http_send_data($content); $redis->setex($rediskey, 300, $content);
} function process_json($filename, $last_data) { // Return data array or false if not available. global $redis; $timestamp = $redis->get($filename . "-mtime"); if ($timestamp === FALSE) { $timestamp = 0; } $ret = array("file_timestamp" => $timestamp, "content_timestamp" => false, "content" => false); $ret["content"] = json_decode($redis->get($filename), true); if (isset($ret["content"]["timestamp"])) { $ret["content_timestamp"] = $ret["content"]["timestamp"]; } else { $ret["content_timestamp"] = $ret["file_timestamp"]; } if ($ret["content_timestamp"] < $last_data || $ret["file_timestamp"] < $last_data) { return false; } return $ret; } // Populate data $ret["twitter"] = process_json("data:twitter.json", $last_data); $ret["data"] = process_json($filename, $last_data); $ret["status"] = "success"; http_cache_etag(); http_send_content_type("application/json"); http_send_data(json_encode($ret)); // Update statistics $redis->incr("stats:web:json:processed"); stat_update("web:json:processed");
} if (isset($_GET["range"])) { $range = min(9000, max(1, intval($_GET["range"]))); } $tz = "EEST"; if (isset($_GET["tz"])) { $tz = substr($_GET["tz"], 0, 4); } $tz = timezone_name_from_abbr($tz); if ($tz === FALSE) { $tz = "Europe/Helsinki"; } if (isset($_GET["mode"])) { $mode = $_GET["mode"]; if (!isset($modes[$mode])) { $mode = "normal"; } $modestring = $modes[$mode]; } http_cache_etag(); $cachekey = "cache:sauna.png:{$width}:{$height}:{$range}:{$mode}:{$tz}"; $data = $redis->get($cachekey); if ($data) { http_send_data($data); } else { ob_start(); passthru('TZ=' . $tz . ' rrdtool graph - --end now --start end-' . $range . 'h --slope-mode -r ' . '--font TITLE:16:Helvetica --font WATERMARK:3:Helvetica --font AXIS:9:Helvetica --font UNIT:10:Helvetica ' . '-c "GRID#FFFFFF" -c "MGRID#FFFFFF" -c "ARROW#000000" -c "SHADEA#FFFFFF" -c "SHADEB#FFFFFF" -c "FRAME#FFFFFF" -c "BACK#FFFFFF" ' . '--full-size-mode --width ' . $width . ' --height ' . $height . ' ' . '"DEF:temperatureraw=' . $filename . ':temperature:AVERAGE" ' . '"CDEF:temperature=temperatureraw,24,110,LIMIT" ' . $modestring); $data = ob_get_clean(); $redis->setex($cachekey, 60, $data); http_send_data($data); }
/** * Test Http functions. */ function test_functions() { http_cache_last_modified(); http_chunked_decode(); http_deflate(); http_inflate(); http_build_cookie(); http_date(); http_get_request_body_stream(); http_get_request_body(); http_get_request_headers(); http_match_etag(); http_match_modified(); http_match_request_header(); http_support(); http_negotiate_charset(); http_negotiate_content_type(); http_negotiate_language(); ob_deflatehandler(); ob_etaghandler(); ob_inflatehandler(); http_parse_cookie(); http_parse_headers(); http_parse_message(); http_parse_params(); http_persistent_handles_clean(); http_persistent_handles_count(); http_persistent_handles_ident(); http_get(); http_head(); http_post_data(); http_post_fields(); http_put_data(); http_put_file(); http_put_stream(); http_request_body_encode(); http_request_method_exists(); http_request_method_name(); http_request_method_register(); http_request_method_unregister(); http_request(); http_redirect(); http_send_content_disposition(); http_send_content_type(); http_send_data(); http_send_file(); http_send_last_modified(); http_send_status(); http_send_stream(); http_throttle(); http_build_str(); http_build_url(); }