1<? 2/* 3 * (C) Copyright 2003 Krzysztof Gibas <sdas (at) gibas org> 4 * - current maintainer 5 * 2001 Gonthar <gonthar (at) moon net pl> 6 * - developed scr_ipfm-0.1 7 * 8 * scr_ipfm generates graphical statistics from ipfm logs. 9 * 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; either version 2 of the License, or 13 * (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, 23 * USA. 24 * 25 * $Id: monthinyear-graph.php,v 1.3 2003/11/08 00:56:54 gibas Exp $ 26 */ 27 28$sum_in = 0; 29$sum_out = 0; 30$sum_total = 0; 31 32$in = 0; 33$out = 0; 34$total = 0; 35 36//default values of variables. 37secure_sort(); 38secure_flag(); 39 40$ar_years = create_ar_years(); 41$ar_months = create_ar_months(); 42$ar_days = create_ar_days(); 43 44secure_year(); 45 46$filename = "$ipfm_log_dir" . "ipfm-global-" . $_GET['year']; 47 48$header = "Statistics for month-in-year " . $_GET['year']; 49 50html_make_header_en($auto_refresh, $header, $version); 51 52echo "<table class=\"tabletop\" border=\"0\" cellspacing=\"1\" cellpadding=\"3\"><tbody><tr class=\"tabletop\"><td>"; 53html_make_links_year("monthinyeargraph"); 54 55echo "</td></tr></tbody></table>"; 56 57html_make_links("monthinyeargraph"); 58 59 60check_dir_exists($ipfm_log_dir); 61check_file_exists("$filename" . "-" . end($ar_months) . "-" . end($ar_days) . ".log", "year"); 62 63//sets global variables: $*_style, $s and $*_flag 64set_style_flag_s(); 65 66 67//$_GET['flag'] = invert_flag($_GET['flag']); 68 69 70$ar_results = array(); 71$ar_results_all = array(); 72 73$string = ""; 74for ($l = 0; $l < count($ar_months); $l++) { 75 $ar_results[$l][1] = 0; 76 $ar_results[$l][2] = 0; 77 $ar_results[$l][3] = 0; 78 79 $_GET['month'] = $ar_months[$l]; 80 81 $ar_months = create_ar_months(); 82 $ar_days = create_ar_days(); 83 84 for ($k = 0; $k < count($ar_days); $k++) { 85 $filename = "$ipfm_log_dir" . "/" . "ipfm-global-$_GET[year]-$ar_months[$l]-$ar_days[$k]" . ".log"; 86 $datas = file($filename); 87 88 for($i=0; $i < count($datas); $i++) { 89 90 if(preg_match("/^# /", $datas[$i])) { 91 92 if(strstr("$datas[$i]", " IPFM")) { 93 //interface, time, version ipfm... 94 $string = split(" ", $datas[$i]); 95 96 //dirty hack - for old versions ipfm. 97 if($string[6] == "every") { 98 $string[9] = $string[7]; 99 $string[13] = $string[11]; 100 } 101 } 102 } 103 else { 104 if(strlen($datas[$i]) != 0) { 105 $elements = preg_split("/\s+/", $datas[$i]); 106 107 $host = $elements[0]; 108 $in = $elements[1]; 109 $out = $elements[2]; 110 $total = $elements[3]; 111 112 $ar_results[$l][0] = "href=\"index.php?sort=total&monthly=1&flag=ASC&year=" . $_GET['year'] . "&month=" . $ar_months[$l] . "\">" . $_GET['year'] . "-".$ar_months[$l] . "</a>"; 113 $ar_results[$l][1] += $in; 114 $ar_results[$l][2] += $out; 115 $ar_results[$l][3] += $total; 116 } 117 118 $sum_in += $in; 119 $sum_out += $out; 120 $sum_total += $total; 121 } 122 } 123 } 124} 125 126for ($i = 0; $i < $l; $i++) { 127 if (isset($ar_results[$i][0])) { 128 $line = $ar_results[$i][0] . " " . $ar_results[$i][1] . " " . $ar_results[$i][2] . " " . $ar_results[$i][3]; 129 array_push($ar_results_all, $line); 130 } 131} 132 133 134//if($_GET['flag'] == "ASC") { 135// $datas = sortbycol($ar_results_all, $s, SORT_ASC); 136//} 137//else { 138 $datas = sortbycol($ar_results_all, $s, SORT_DESC); 139//} 140 141echo "<table class=\"graph\"><tbody><tr><td>"; 142 143for($i=0; $i < count($datas); $i++) { 144 if(strlen($datas[$i]) != 0) { 145 $elements = preg_split("/\s+/", $datas[$i]); 146 147 $host = $elements[0]; 148 $total = $elements[$s]; 149 150 if (!isset($scale)) { 151 $scale = calc_scale($datas[$i], $s); 152 } 153 154 //background color 155 $style = set_table_bg_style($elements[$s]); 156 157 //$tmp = $i + 1; 158 159 $total_scaled = round($total) / round($scale); 160 161 $host = "<a class=\"link\" " . $host; 162 163 html_graph_horizon($host, $total, round($total_scaled)); 164 } 165} 166 167echo "</td></tr></tbody></table>"; 168 169html_make_empty_table(); 170 171html_make_version_table($string[1], $string[3], $string[9], $string[13], $version); 172 173?> 174