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