]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/netexternal.cgi
8f29eb8a23a088a17ceb1610fcd16812c5d96350
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / netexternal.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2005-2010 IPFire Team #
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 use experimental 'smartmatch';
24
25 # enable only the following on debugging purpose
26 #use warnings;
27 #use CGI::Carp 'fatalsToBrowser';
28
29 use IO::Socket;
30
31 require '/var/ipfire/general-functions.pl';
32 require "${General::swroot}/lang.pl";
33 require "${General::swroot}/header.pl";
34 require "${General::swroot}/geoip-functions.pl";
35 require "${General::swroot}/graphs.pl";
36
37 my %color = ();
38 my %mainsettings = ();
39 my %netsettings=();
40 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
41 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
42 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
43
44 my @graphs=();
45 my %dhcpinfo=();
46
47 my @querry = split(/\?/,$ENV{'QUERY_STRING'});
48 $querry[0] = '' unless defined $querry[0];
49 $querry[1] = 'hour' unless defined $querry[1];
50
51 if ( $querry[0] ne~ ""){
52 print "Content-type: image/png\n\n";
53 binmode(STDOUT);
54 &Graphs::updateifgraph($querry[0],$querry[1]);
55 }else{
56
57 &Header::showhttpheaders();
58 &Header::openpage($Lang::tr{'network traffic graphs external'}, 1, '');
59 &Header::openbigbox('100%', 'left');
60
61 if ($netsettings{'RED_TYPE'} ne 'PPPOE'){
62 if ($netsettings{'RED_DEV'} ne $netsettings{'GREEN_DEV'}){
63 push (@graphs, ($netsettings{'RED_DEV'}));
64 }
65 }else{
66 push (@graphs, "ppp0");
67 }
68
69 if (-e "/var/log/rrd/collectd/localhost/interface/if_octets-ipsec0.rrd"){
70 push (@graphs, ("ipsec0"));
71 }
72
73 if (-e "/var/log/rrd/collectd/localhost/interface/if_octets-tun0.rrd"){
74 push (@graphs, ("tun0"));
75 }
76
77 foreach (@graphs) {
78 &Header::openbox('100%', 'center', "$_ $Lang::tr{'graph'}");
79 &Graphs::makegraphbox("netexternal.cgi",$_,"day");
80 &Header::closebox();
81 }
82
83 ## DNSSEC
84 my @nameservers = ();
85 foreach my $f ("${General::swroot}/red/dns1", "${General::swroot}/red/dns2") {
86 open(DNS, "<$f");
87 my $nameserver = <DNS>;
88 close(DNS);
89
90 chomp($nameserver);
91 if ($nameserver) {
92 push(@nameservers, $nameserver);
93 }
94 }
95
96 &Header::openbox('100%', 'center', $Lang::tr{'dnssec information'});
97
98 print <<END;
99 <table class="tbl" width='66%'>
100 <thead>
101 <tr>
102 <th align="center">
103 <strong>$Lang::tr{'nameserver'}</strong>
104 </th>
105 <th align="center">
106 <strong>$Lang::tr{'country'}</strong>
107 </th>
108 <th align="center">
109 <strong>$Lang::tr{'rdns'}</strong>
110 </th>
111 <th align="center">
112 <strong>$Lang::tr{'status'}</strong>
113 </th>
114 </tr>
115 </thead>
116 <tbody>
117 END
118
119 my $id = 0;
120 for my $nameserver (@nameservers) {
121 my $status = &check_dnssec($nameserver, "ping.ipfire.org");
122
123 my $colour = "";
124 my $bgcolour = "";
125 my $message = "";
126
127 # DNSSEC Not supported
128 if ($status == 0) {
129 $message = $Lang::tr{'dnssec not supported'};
130 $colour = "white";
131 $bgcolour = ${Header::colourred};
132
133 # DNSSEC Aware
134 } elsif ($status == 1) {
135 $message = $Lang::tr{'dnssec aware'};
136 $colour = "black";
137 $bgcolour = ${Header::colouryellow};
138
139 # DNSSEC Validating
140 } elsif ($status == 2) {
141 $message = $Lang::tr{'dnssec validating'};
142 $colour = "white";
143 $bgcolour = ${Header::colourgreen};
144
145 # Error
146 } else {
147 $colour = ${Header::colourred};
148 }
149
150 my $table_colour = ($id++ % 2) ? $color{'color22'} : $color{'color20'};
151
152 # collect more information about name server (rDNS, GeoIP country code)
153 my $ccode = &GeoIP::lookup($nameserver);
154 my $flag_icon = &GeoIP::get_flag_icon($ccode);
155
156 my $iaddr = inet_aton($nameserver);
157 my $rdns = gethostbyaddr($iaddr, AF_INET);
158 if (!$rdns) { $rdns = $Lang::tr{'lookup failed'}; }
159
160 print <<END;
161 <tr bgcolor="$table_colour">
162 <td>
163 $nameserver
164 </td>
165 <td align="center">
166 <a href='country.cgi#$ccode'><img src="$flag_icon" border="0" alt="$ccode" title="$ccode" /></a>
167 </td>
168 <td align="center">
169 $rdns
170 </td>
171 <td bgcolor="$bgcolour" align="center">
172 <font color="$colour"><strong>$message</strong></font>
173 </td>
174 </tr>
175 END
176 }
177
178 print <<END;
179 </tbody>
180 </table>
181 END
182
183 &Header::closebox();
184
185 if ( $netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/ && $netsettings{'RED_TYPE'} eq "DHCP"){
186
187 &Header::openbox('100%', 'left', "RED $Lang::tr{'dhcp configuration'}");
188 if (-s "${General::swroot}/dhcpc/dhcpcd-$netsettings{'RED_DEV'}.info") {
189
190 &General::readhash("${General::swroot}/dhcpc/dhcpcd-$netsettings{'RED_DEV'}.info", \%dhcpinfo);
191
192 my $DNS1=`echo $dhcpinfo{'domain_name_servers'} | cut -f 1 -d " "`;
193 my $DNS2=`echo $dhcpinfo{'domain_name_servers'} | cut -f 2 -d " "`;
194
195 my $lsetme=0;
196 my $leasetime="";
197 if ($dhcpinfo{'dhcp_lease_time'} ne "") {
198 $lsetme=$dhcpinfo{'dhcp_lease_time'};
199 $lsetme=($lsetme/60);
200
201 if ($lsetme > 59) {
202 $lsetme=($lsetme/60); $leasetime=$lsetme." Hour";
203 }else{
204 $leasetime=$lsetme." Minute";
205 }
206
207 if ($lsetme > 1) {
208 $leasetime=$leasetime."s";
209 }
210 }
211
212 my $rentme=0;
213 my $rnwltime="";
214
215 if ($dhcpinfo{'dhcp_renewal_time'} ne "") {
216 $rentme=$dhcpinfo{'dhcp_renewal_time'};
217 $rentme=($rentme/60);
218
219 if ($rentme > 59){
220 $rentme=($rentme/60); $rnwltime=$rentme." Hour";
221 }else{
222 $rnwltime=$rentme." Minute";
223 }
224
225 if ($rentme > 1){
226 $rnwltime=$rnwltime."s";
227 }
228 }
229
230 my $maxtme=0;
231 my $maxtime="";
232
233 if ($dhcpinfo{'dhcp_rebinding_time'} ne "") {
234 $maxtme=$dhcpinfo{'dhcp_rebinding_time'};
235 $maxtme=($maxtme/60);
236
237 if ($maxtme > 59){
238 $maxtme=($maxtme/60); $maxtime=$maxtme." Hour";
239 } else {
240 $maxtime=$maxtme." Minute";
241 }
242
243 if ($maxtme > 1) {
244 $maxtime=$maxtime."s";
245 }
246 }
247
248
249 print <<END
250 <table width='100%'>
251 <tr><td width='30%'>$Lang::tr{'domain'}</td><td>$dhcpinfo{'domain_name'}</td></tr>
252 <tr><td>$Lang::tr{'gateway'}</td><td>$dhcpinfo{'routers'}</td></tr>
253 <tr><td>$Lang::tr{'primary dns'}</td><td>$DNS1</td></tr>
254 <tr><td>$Lang::tr{'secondary dns'}</td><td>$DNS2</td></tr>
255 <tr><td>$Lang::tr{'dhcp server'}</td><td>$dhcpinfo{'dhcp_server_identifier'}</td></tr>
256 <tr><td>$Lang::tr{'def lease time'}</td><td>$leasetime</td></tr>
257 <tr><td>$Lang::tr{'default renewal time'}</td><td>$rnwltime</td></tr>
258 <tr><td>$Lang::tr{'max renewal time'}</td><td>$maxtime</td></tr>
259 </table>
260 END
261 ;
262 }else{
263 print "$Lang::tr{'no dhcp lease'}";
264 }
265 &Header::closebox();
266 }
267
268 &Header::closebigbox();
269 &Header::closepage();
270 }
271
272 sub check_dnssec($$) {
273 my $nameserver = shift;
274 my $record = shift;
275
276 my @command = ("dig", "+dnssec", $record, "\@$nameserver");
277
278 my @output = qx(@command);
279 my $output = join("", @output);
280
281 my $status = 0;
282 if ($output =~ m/status: (\w+)/) {
283 $status = ($1 eq "NOERROR");
284
285 if (!$status) {
286 return -1;
287 }
288 }
289
290 my @flags = ();
291 if ($output =~ m/flags: (.*);/) {
292 @flags = split(/ /, $1);
293 }
294
295 my $aware = ($output =~ m/RRSIG/);
296 my $validating = ("ad" ~~ @flags);
297
298 return $aware + $validating;
299 }