]>
Commit | Line | Data |
---|---|---|
0d6cc79d SF |
1 | #!/usr/bin/perl |
2 | # | |
3 | ############################################################################### | |
4 | # # | |
5 | # IPFire.org - A linux based firewall # | |
a25c95b3 | 6 | # Copyright (C) 2017-2018 Stephan Feddersen <sfeddersen@ipfire.org> # |
0d6cc79d SF |
7 | # All Rights Reserved. # |
8 | # # | |
9 | # This program is free software: you can redistribute it and/or modify # | |
10 | # it under the terms of the GNU General Public License as published by # | |
11 | # the Free Software Foundation, either version 3 of the License, or # | |
12 | # (at your option) any later version. # | |
13 | # # | |
14 | # This program is distributed in the hope that it will be useful, # | |
15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
17 | # GNU General Public License for more details. # | |
18 | # # | |
19 | # You should have received a copy of the GNU General Public License # | |
20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
21 | # # | |
22 | ############################################################################### | |
23 | # | |
a25c95b3 | 24 | # Version: 2017/07/11 21:32:23 |
0d6cc79d SF |
25 | # |
26 | # This wio-graphs.pl is based on the Code from the IPCop WIO Addon | |
27 | # and is extremly adapted to work with IPFire. | |
28 | # | |
29 | # Autor: Stephan Feddersen | |
30 | # Co-Autor: Alexander Marx | |
31 | # | |
32 | ||
33 | package WIOGraphs; | |
34 | ||
35 | use strict; | |
36 | ||
37 | # enable only the following on debugging purpose | |
38 | #use warnings; | |
39 | ||
40 | use RRDs; | |
41 | ||
42 | require '/var/ipfire/general-functions.pl'; | |
43 | require '/var/ipfire/lang.pl'; | |
44 | ||
45 | my ( %mainsettings, %color ) = (); | |
46 | ||
47 | &General::readhash('/var/ipfire/main/settings', \%mainsettings); | |
48 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
49 | ||
50 | sub wio { | |
51 | my $hostid = $_[0]; | |
52 | my $hostname = $_[1]; | |
53 | my $period = $_[2]; | |
54 | ||
55 | my @rrd = (); | |
56 | ||
57 | push @rrd, ("-"); | |
58 | push @rrd, @{&header($period, "$hostname ($Lang::tr{$period})")}; | |
59 | push @rrd, @{&body($hostid)}; | |
60 | ||
61 | RRDs::graph (@rrd); | |
62 | ||
63 | my $error = RRDs::error; | |
64 | print "Error in RRD::graph for Who Is Online: $error\n" if $error; | |
65 | } | |
66 | ||
67 | sub body { | |
68 | my $hostid = shift; | |
69 | my $result = []; | |
70 | ||
71 | push @$result, "DEF:mode=/var/log/rrd/wio/$hostid.rrd:mode:AVERAGE"; | |
72 | push @$result, "CDEF:online=mode,UN,0,mode,IF,50,GT,100,0,IF"; | |
73 | push @$result, "CDEF:offline=mode,UN,100,mode,IF,50,LT,100,0,IF"; | |
74 | push @$result, "AREA:online".$color{"color12"}.":$Lang::tr{'wio up'}\\j"; | |
75 | push @$result, "AREA:offline".$color{"color13"}.":$Lang::tr{'wio down'}\\j"; | |
76 | push @$result, "COMMENT:\r<span size='smaller'>$Lang::tr{'wio_last_update'}\\: ". lastupdate(scalar localtime()) ."</span>\\r"; | |
77 | ||
78 | return $result; | |
79 | } | |
80 | ||
81 | sub lastupdate { | |
82 | my $text = shift; | |
83 | ||
84 | return undef if not defined $text; | |
85 | $text =~ s/\\/\\\\/g; | |
86 | $text =~ s/:/\\:/g; | |
87 | ||
88 | return $text; | |
89 | } | |
90 | ||
91 | sub header { | |
92 | my $period = shift; | |
93 | my $title = shift; | |
94 | my $result = []; | |
95 | ||
96 | push @$result, ("--title", "$title"); | |
97 | push @$result, ("--start", "-1$period", "-aPNG", "-i", "-z"); | |
98 | push @$result, ("--border", "0"); | |
99 | push @$result, ("--full-size-mode"); | |
100 | push @$result, ("--slope-mode"); | |
101 | push @$result, ("--pango-markup"); | |
102 | push @$result, ("--alt-y-grid", "-w 910", "-h 300"); | |
103 | if ( $period eq 'day' ) { push @$result, ("--x-grid", "MINUTE:30:HOUR:1:HOUR:2:0:%H:%M"); } | |
104 | push @$result, ("--color", "SHADEA".$color{"color19"}); | |
105 | push @$result, ("--color", "SHADEB".$color{"color19"}); | |
106 | push @$result, ("--color", "BACK".$color{"color21"}); | |
107 | ||
108 | return $result; | |
109 | } | |
110 | ||
111 | sub wiographbox { | |
112 | print "<center>"; | |
113 | print "<table width='100%' cellspacing='0'>"; | |
114 | print "<tr>"; | |
115 | print "<td align='center' bgcolor='".$color{"color20"}."'><a href='".$_[0]."?".$_[1]."?hour?".$_[3]."' target='".$_[1]."box'><b>".$Lang::tr{'hour'}."</b></a></td>"; | |
116 | print "<td align='center' bgcolor='".$color{"color20"}."'><a href='".$_[0]."?".$_[1]."?day?".$_[3]."' target='".$_[1]."box'><b>".$Lang::tr{'day'}."</b></a></td>"; | |
117 | print "<td align='center' bgcolor='".$color{"color20"}."'><a href='".$_[0]."?".$_[1]."?week?".$_[3]."' target='".$_[1]."box'><b>".$Lang::tr{'week'}."</b></a></td>"; | |
118 | print "<td align='center' bgcolor='".$color{"color20"}."'><a href='".$_[0]."?".$_[1]."?month?".$_[3]."' target='".$_[1]."box'><b>".$Lang::tr{'month'}."</b></a></td>"; | |
119 | print "<td align='center' bgcolor='".$color{"color20"}."'><a href='".$_[0]."?".$_[1]."?year?".$_[3]."' target='".$_[1]."box'><b>".$Lang::tr{'year'}."</b></a></td>"; | |
120 | print "</tr>"; | |
121 | print "</table>"; | |
122 | print "<table width='100%' cellspacing='0'>"; | |
123 | print "<tr><td align='center' colspan='8'> </td></tr>"; | |
124 | print "<tr><td align='center' colspan='8'><iframe class='graph' src='".$_[0]."?".$_[1]."?".$_[2]."?".$_[3]."' scrolling='no' marginheight='0' frameborder='no' name='".$_[1]."box'></iframe></td></tr>"; | |
125 | print "</table>"; | |
126 | print "</center>"; | |
127 | } |