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: yearly-graph.php,v 1.2 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 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("yearlygraph");
54
55echo "</td></tr></tbody></table>";
56
57html_make_links("yearly");
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//$_GET['flag'] = invert_flag($_GET['flag']);
67
68
69$ar_results = array();
70$ar_results_all = array();
71$ar_hosts = array();
72
73$string = "";
74for ($l = 0; $l < count($ar_months); $l++) {
75    $_GET['month'] = $ar_months[$l];
76
77    $ar_months = create_ar_months();
78    $ar_days = create_ar_days();
79
80    for ($k = 0; $k < count($ar_days); $k++) {
81        $filename = "$ipfm_log_dir" . "/" . "ipfm-global-$_GET[year]-$ar_months[$l]-$ar_days[$k]" . ".log";
82        $datas = file($filename);
83
84        for($i=0; $i < count($datas); $i++) {
85
86            if(preg_match("/^# /", $datas[$i])) {
87
88                if(strstr("$datas[$i]", " IPFM")) {
89                    //interface, time, version ipfm...
90                    $string = split(" ", $datas[$i]);
91
92                    //dirty hack - for old versions ipfm.
93                    if($string[6] == "every") {
94                        $string[9] = $string[7];
95                        $string[13] = $string[11];
96                    }
97                }
98            }
99            else {
100                if(strlen($datas[$i]) != 0) {
101                    $elements = preg_split("/\s+/", $datas[$i]);
102
103                    $host = $elements[0];
104                    $in = $elements[1];
105                    $out = $elements[2];
106                    $total = $elements[3];
107
108                    if(!in_array($host, $ar_hosts)) {
109                        array_push($ar_hosts, "$host");
110                    }
111
112                    if (array_key_exists($host, $ar_results)) {
113                        $ar_results[$host][0] = $host;
114                        $ar_results[$host][1] += $in;
115                        $ar_results[$host][2] += $out;
116                        $ar_results[$host][3] += $total;
117                    }
118                    else {
119                        $ar_results[$host][0] = $host;
120                        $ar_results[$host][1] = $in;
121                        $ar_results[$host][2] = $out;
122                        $ar_results[$host][3] = $total;
123                    }
124                }
125
126                $sum_in += $in;
127                $sum_out += $out;
128                $sum_total += $total;
129            }
130        }
131    }
132}
133
134foreach ($ar_hosts as $host) {
135    $line = $ar_results[$host][0] . " " . $ar_results[$host][1] . " " . $ar_results[$host][2] . " " . $ar_results[$host][3];
136    array_push($ar_results_all, $line);
137}
138
139
140//if($_GET['flag'] == "ASC") {
141//    $datas = sortbycol($ar_results_all, $s, SORT_ASC);
142//}
143//else {
144    $datas = sortbycol($ar_results_all, $s, SORT_DESC);
145//}
146
147echo "<table class=\"graph\"><tbody><tr><td>";
148
149for($i=0; $i < count($datas); $i++) {
150    if(strlen($datas[$i]) != 0) {
151        $elements = preg_split("/\s+/", $datas[$i]);
152
153        $host = $elements[0];
154        $total = $elements[$s];
155
156        if (!isset($scale)) {
157	    $scale = calc_scale($datas[$i], $s);
158	}
159
160	$total_scaled = round($total) / round($scale);
161
162        //background color
163//        $style = set_table_bg_style($elements[$s]);
164
165	html_graph_horizon($host, $total, round($total_scaled));
166    }
167}
168
169echo "</td></tr></tbody></table>";
170
171html_make_empty_table();
172
173html_make_version_table($string[1], $string[3], $string[9], $string[13], $version);
174
175?>
176