]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/network.cgi
50f70a64f02f82d388ac47215b3813e0b7064ff8
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / network.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 use strict;
23
24 # enable only the following on debugging purpose
25 #use warnings;
26 #use CGI::Carp 'fatalsToBrowser';
27
28 require '/var/ipfire/general-functions.pl';
29 require "${General::swroot}/lang.pl";
30 require "${General::swroot}/header.pl";
31 require "${General::swroot}/graphs.pl";
32
33 my %cgiparams=();
34 my %pppsettings=();
35 my %netsettings=();
36 my @cgiparams=();
37 my @graphs=();
38 my $iface='';
39 my %dhcpsettings=();
40 my %dhcpinfo=();
41 my $output='';
42
43 &Header::showhttpheaders();
44
45 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
46
47 $ENV{'QUERY_STRING'} =~ s/&//g;
48 @cgiparams = split(/network=/,$ENV{'QUERY_STRING'});
49 $cgiparams[1] = '' unless defined $cgiparams[1];
50
51 if ($cgiparams[1] =~ /red/) {
52 &Header::openpage($Lang::tr{'network traffic graphs external'}, 1, '');
53 push (@graphs, ($netsettings{'RED_DEV'}));
54 if (-e "/var/log/rrd/collectd/localhost/interface/if_octets-ipsec0.rrd") {push (@graphs, ("ipsec0"));}
55 }elsif ($cgiparams[1] =~ /other/) {
56 &Header::openpage($Lang::tr{'network traffic graphs others'}, 1, '');
57 push (@graphs, ("lq"));
58 push (@graphs, ("fwhits"));
59 }else {
60 &Header::openpage($Lang::tr{'network traffic graphs internal'}, 1, '');
61 push (@graphs, ($netsettings{'GREEN_DEV'}));
62 if ($netsettings{'BLUE_DEV'}) {
63 push (@graphs, ($netsettings{'BLUE_DEV'})); }
64 if ($netsettings{'ORANGE_DEV'}) {
65 push (@graphs, ($netsettings{'ORANGE_DEV'})); }
66 }
67
68 &Header::openbigbox('100%', 'left');
69
70 foreach my $graphname (@graphs) {
71
72 if ($graphname eq "lq" )
73 { &Graphs::updatelqgraph("day"); }
74 elsif ($graphname eq "fwhits" )
75 { &Graphs::updatefwhitsgraph("day"); }
76 else
77 { &Graphs::updateifgraph($graphname, "day"); }
78
79 &Header::openbox('100%', 'center', "$graphname $Lang::tr{'graph'}");
80 if (-e "$Header::graphdir/${graphname}-day.png") {
81 my $ftime = localtime((stat("$Header::graphdir/${graphname}-day.png"))[9]);
82 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
83 print "<a href='/cgi-bin/graphs.cgi?graph=$graphname'>";
84 print "<img alt='' src='/graphs/${graphname}-day.png' border='0' />";
85 print "</a>";
86 } else {
87 print $Lang::tr{'no information available'};
88 }
89 print "<br />\n";
90 &Header::closebox();
91 }
92
93 if ($cgiparams[1] =~ /red/) {
94
95 if ( $netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $netsettings{'RED_TYPE'} eq "DHCP") {
96
97 &Header::openbox('100%', 'left', "RED $Lang::tr{'dhcp configuration'}");
98 if (-s "${General::swroot}/dhcpc/dhcpcd-$netsettings{'RED_DEV'}.info") {
99
100 &General::readhash("${General::swroot}/dhcpc/dhcpcd-$netsettings{'RED_DEV'}.info", \%dhcpinfo);
101
102 my $DNS1=`echo $dhcpinfo{'DNS'} | cut -f 1 -d ,`;
103 my $DNS2=`echo $dhcpinfo{'DNS'} | cut -f 2 -d ,`;
104
105 my $lsetme=0;
106 my $leasetime="";
107 if ($dhcpinfo{'LEASETIME'} ne "") {
108 $lsetme=$dhcpinfo{'LEASETIME'};
109 $lsetme=($lsetme/60);
110 if ($lsetme > 59) {
111 $lsetme=($lsetme/60); $leasetime=$lsetme." Hour";
112 } else {
113 $leasetime=$lsetme." Minute";
114 }
115 if ($lsetme > 1) {
116 $leasetime=$leasetime."s";
117 }
118 }
119 my $rentme=0;
120 my $rnwltime="";
121 if ($dhcpinfo{'RENEWALTIME'} ne "") {
122 $rentme=$dhcpinfo{'RENEWALTIME'};
123 $rentme=($rentme/60);
124 if ($rentme > 59){
125 $rentme=($rentme/60); $rnwltime=$rentme." Hour";
126 } else {
127 $rnwltime=$rentme." Minute";
128 }
129 if ($rentme > 1){
130 $rnwltime=$rnwltime."s";
131 }
132 }
133 my $maxtme=0;
134 my $maxtime="";
135 if ($dhcpinfo{'REBINDTIME'} ne "") {
136 $maxtme=$dhcpinfo{'REBINDTIME'};
137 $maxtme=($maxtme/60);
138 if ($maxtme > 59){
139 $maxtme=($maxtme/60); $maxtime=$maxtme." Hour";
140 } else {
141 $maxtime=$maxtme." Minute";
142 }
143 if ($maxtme > 1) {
144 $maxtime=$maxtime."s";
145 }
146 }
147
148 print "<table width='100%'>";
149 if ($dhcpinfo{'HOSTNAME'}) {
150 print "<tr><td width='30%'>$Lang::tr{'hostname'}</td><td>$dhcpinfo{'HOSTNAME'}.$dhcpinfo{'DOMAIN'}</td></tr>\n";
151 } else {
152 print "<tr><td width='30%'>$Lang::tr{'domain'}</td><td>$dhcpinfo{'DOMAIN'}</td></tr>\n";
153 }
154 print <<END
155 <tr><td>$Lang::tr{'gateway'}</td><td>$dhcpinfo{'GATEWAY'}</td></tr>
156 <tr><td>$Lang::tr{'primary dns'}</td><td>$DNS1</td></tr>
157 <tr><td>$Lang::tr{'secondary dns'}</td><td>$DNS2</td></tr>
158 <tr><td>$Lang::tr{'dhcp server'}</td><td>$dhcpinfo{'DHCPSIADDR'}</td></tr>
159 <tr><td>$Lang::tr{'def lease time'}</td><td>$leasetime</td></tr>
160 <tr><td>$Lang::tr{'default renewal time'}</td><td>$rnwltime</td></tr>
161 <tr><td>$Lang::tr{'max renewal time'}</td><td>$maxtime</td></tr>
162 </table>
163 END
164 ;
165 }
166 else
167 {
168 print "$Lang::tr{'no dhcp lease'}";
169 }
170 &Header::closebox();
171 }
172
173 if ($dhcpsettings{'ENABLE_GREEN'} eq 'on' || $dhcpsettings{'ENABLE_BLUE'} eq 'on') {
174 &Header::CheckSortOrder;
175 &Header::PrintActualLeases;
176 }
177
178 } else {
179
180 &Header::openbox('100%', 'left', $Lang::tr{'routing table entries'});
181 $output = `/sbin/ip route show`;
182 $output = &Header::cleanhtml($output,"y");
183 print "<pre>$output</pre>\n";
184 &Header::closebox();
185
186 &Header::openbox('100%', 'left', $Lang::tr{'arp table entries'});
187 $output = `/sbin/ip neigh show`;
188 $output = &Header::cleanhtml($output,"y");
189 print "<pre>$output</pre>\n";
190 &Header::closebox();
191
192 }
193
194 &Header::closebigbox();
195 &Header::closepage();