]> git.ipfire.org Git - ipfire-2.x.git/blame - html/cgi-bin/entropy.cgi
vpn-statistic: change title of ovpn RW statistic page
[ipfire-2.x.git] / html / cgi-bin / entropy.cgi
CommitLineData
15b023b9
MT
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
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 @querry = split(/\?/,$ENV{'QUERY_STRING'});
34$querry[0] = '' unless defined $querry[0];
35$querry[1] = 'hour' unless defined $querry[1];
36
37if ( $querry[0] ne~ "") {
38 print "Content-type: image/png\n\n";
39 binmode(STDOUT);
40 &Graphs::updateentropygraph($querry[1]);
41
42} else {
43 &Header::showhttpheaders();
44 &Header::openpage($Lang::tr{'entropy'}, 1, '');
45 &Header::openbigbox('100%', 'left');
46
47 &Header::openbox('100%', 'center', $Lang::tr{'entropy'});
48 &Graphs::makegraphbox("entropy.cgi", "day", '', 350);
49 &Header::closebox();
50
84004f05
MT
51 # Check for hardware support.
52 my $message;
53 my $message_colour = $Header::colourred;
54 if (&has_hwrng()) {
55 $message = $Lang::tr{'system has hwrng'};
56 $message_colour = $Header::colourgreen;
57 } elsif (&has_rdrand()) {
58 $message = $Lang::tr{'system has rdrand'};
59 $message_colour = $Header::colourgreen;
60 } else {
61 $message = $Lang::tr{'no hardware random number generator'};
62 }
63
742c334a
MT
64 my $rngd_status = "<td align='center' bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>";
65 if (&rngd_is_running()) {
66 $rngd_status = "<td align='center' bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>";
67 }
68
84004f05
MT
69 &Header::openbox('100%', 'center', $Lang::tr{'hardware support'});
70 print <<EOF;
71 <p style="color: $message_colour; text-align: center;">$message</p>
742c334a
MT
72
73 <table width='80%' cellspacing='1' class='tbl'>
74 <tr>
75 <th align='center'><b>$Lang::tr{'service'}</b></th>
76 <th align='center'><b>$Lang::tr{'status'}</b></th>
77 </tr>
78 <tr>
79 <td align='center'>
80 $Lang::tr{'random number generator daemon'}
81 </td>
82 $rngd_status
83 </tr>
84 </table>
84004f05
MT
85EOF
86 &Header::closebox();
87
15b023b9
MT
88 &Header::closebigbox();
89 &Header::closepage();
90}
84004f05
MT
91
92sub has_hwrng() {
93 return (-c "/dev/hwrng");
94}
95
96sub has_rdrand() {
97 open(FILE, "/proc/cpuinfo") or return 0;
98 my @cpuinfo = <FILE>;
99 close(FILE);
100
101 my @result = grep(/rdrand/, @cpuinfo);
102 if (@result) {
103 return 1;
104 }
105
106 return 0;
107}
742c334a
MT
108
109sub rngd_is_running() {
110 return (-e "/var/run/rngd.pid");
111}