]> git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/network.cgi
08fc8fb49af4bd1427ca374e6d4473562ac16b9c
[ipfire-2.x.git] / html / cgi-bin / network.cgi
1 #!/usr/bin/perl
2 #
3 # SmoothWall CGIs
4 #
5 # This code is distributed under the terms of the GPL
6 #
7 # (c) The SmoothWall Team
8 #
9 #
10
11 use strict;
12
13 # enable only the following on debugging purpose
14 #use warnings;
15 #use CGI::Carp 'fatalsToBrowser';
16
17 require '/var/ipfire/general-functions.pl';
18 require "${General::swroot}/lang.pl";
19 require "${General::swroot}/header.pl";
20 require "${General::swroot}/graphs.pl";
21
22 my %cgiparams=();
23 my %pppsettings=();
24 my %netsettings=();
25 my @cgiparams=();
26 my @graphs=();
27 my $iface='';
28 my %dhcpsettings=();
29 my %dhcpinfo=();
30 my $output='';
31
32 &Header::showhttpheaders();
33
34 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
35
36 $ENV{'QUERY_STRING'} =~ s/&//g;
37 @cgiparams = split(/network=/,$ENV{'QUERY_STRING'});
38 $cgiparams[1] = '' unless defined $cgiparams[1];
39
40 if ($cgiparams[1] =~ /red/) {
41 &Header::openpage($Lang::tr{'network traffic graphs external'}, 1, '');
42 push (@graphs, ("RED"));
43 push (@graphs, ('lq'));
44 } else {
45 &Header::openpage($Lang::tr{'network traffic graphs internal'}, 1, '');
46 push (@graphs, ('GREEN'));
47 if ($netsettings{'BLUE_DEV'}) {
48 push (@graphs, ('BLUE')); }
49 if ($netsettings{'ORANGE_DEV'}) {
50 push (@graphs, ('ORANGE')); }
51 }
52
53 &Header::openbigbox('100%', 'left');
54
55 foreach my $graphname (@graphs) {
56
57 if ($graphname eq "lq" )
58 { &Graphs::updatelqgraph("day"); }
59 else
60 { &Graphs::updateifgraph($graphname, "day"); }
61
62 &Header::openbox('100%', 'center', "$graphname $Lang::tr{'graph'}");
63 if (-e "$Header::graphdir/${graphname}-day.png") {
64 my $ftime = localtime((stat("$Header::graphdir/${graphname}-day.png"))[9]);
65 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
66 print "<a href='/cgi-bin/graphs.cgi?graph=$graphname'>";
67 print "<img alt='' src='/graphs/${graphname}-day.png' border='0' />";
68 print "</a>";
69 } else {
70 print $Lang::tr{'no information available'};
71 }
72 print "<br />\n";
73 &Header::closebox();
74 }
75
76 if ($cgiparams[1] =~ /red/) {
77
78 if ( $netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $netsettings{'RED_TYPE'} eq "DHCP") {
79
80 &Header::openbox('100%', 'left', "RED $Lang::tr{'dhcp configuration'}");
81 if (-s "${General::swroot}/dhcpc/dhcpcd-$netsettings{'RED_DEV'}.info") {
82
83 &General::readhash("${General::swroot}/dhcpc/dhcpcd-$netsettings{'RED_DEV'}.info", \%dhcpinfo);
84
85 my $DNS1=`echo $dhcpinfo{'DNS'} | cut -f 1 -d ,`;
86 my $DNS2=`echo $dhcpinfo{'DNS'} | cut -f 2 -d ,`;
87
88 my $lsetme=0;
89 my $leasetime="";
90 if ($dhcpinfo{'LEASETIME'} ne "") {
91 $lsetme=$dhcpinfo{'LEASETIME'};
92 $lsetme=($lsetme/60);
93 if ($lsetme > 59) {
94 $lsetme=($lsetme/60); $leasetime=$lsetme." Hour";
95 } else {
96 $leasetime=$lsetme." Minute";
97 }
98 if ($lsetme > 1) {
99 $leasetime=$leasetime."s";
100 }
101 }
102 my $rentme=0;
103 my $rnwltime="";
104 if ($dhcpinfo{'RENEWALTIME'} ne "") {
105 $rentme=$dhcpinfo{'RENEWALTIME'};
106 $rentme=($rentme/60);
107 if ($rentme > 59){
108 $rentme=($rentme/60); $rnwltime=$rentme." Hour";
109 } else {
110 $rnwltime=$rentme." Minute";
111 }
112 if ($rentme > 1){
113 $rnwltime=$rnwltime."s";
114 }
115 }
116 my $maxtme=0;
117 my $maxtime="";
118 if ($dhcpinfo{'REBINDTIME'} ne "") {
119 $maxtme=$dhcpinfo{'REBINDTIME'};
120 $maxtme=($maxtme/60);
121 if ($maxtme > 59){
122 $maxtme=($maxtme/60); $maxtime=$maxtme." Hour";
123 } else {
124 $maxtime=$maxtme." Minute";
125 }
126 if ($maxtme > 1) {
127 $maxtime=$maxtime."s";
128 }
129 }
130
131 print "<table width='100%'>";
132 if ($dhcpinfo{'HOSTNAME'}) {
133 print "<tr><td width='30%'>$Lang::tr{'hostname'}</td><td>$dhcpinfo{'HOSTNAME'}.$dhcpinfo{'DOMAIN'}</td></tr>\n";
134 } else {
135 print "<tr><td width='30%'>$Lang::tr{'domain'}</td><td>$dhcpinfo{'DOMAIN'}</td></tr>\n";
136 }
137 print <<END
138 <tr><td>$Lang::tr{'gateway'}</td><td>$dhcpinfo{'GATEWAY'}</td></tr>
139 <tr><td>$Lang::tr{'primary dns'}</td><td>$DNS1</td></tr>
140 <tr><td>$Lang::tr{'secondary dns'}</td><td>$DNS2</td></tr>
141 <tr><td>$Lang::tr{'dhcp server'}</td><td>$dhcpinfo{'DHCPSIADDR'}</td></tr>
142 <tr><td>$Lang::tr{'def lease time'}</td><td>$leasetime</td></tr>
143 <tr><td>$Lang::tr{'default renewal time'}</td><td>$rnwltime</td></tr>
144 <tr><td>$Lang::tr{'max renewal time'}</td><td>$maxtime</td></tr>
145 </table>
146 END
147 ;
148 }
149 else
150 {
151 print "$Lang::tr{'no dhcp lease'}";
152 }
153 &Header::closebox();
154 }
155
156 if ($dhcpsettings{'ENABLE_GREEN'} eq 'on' || $dhcpsettings{'ENABLE_BLUE'} eq 'on') {
157 &Header::CheckSortOrder;
158 &Header::PrintActualLeases;
159 }
160
161 } else {
162
163 &Header::openbox('100%', 'left', $Lang::tr{'routing table entries'});
164 $output = `/sbin/ip route show`;
165 $output = &Header::cleanhtml($output,"y");
166 print "<pre>$output</pre>\n";
167 &Header::closebox();
168
169 &Header::openbox('100%', 'left', $Lang::tr{'arp table entries'});
170 $output = `/sbin/ip neigh show`;
171 $output = &Header::cleanhtml($output,"y");
172 print "<pre>$output</pre>\n";
173 &Header::closebox();
174
175 }
176
177 &Header::closebigbox();
178 &Header::closepage();