]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - html/cgi-bin/entropy.cgi
Add link to entropy page and show if there is hardware support available.
[people/teissler/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
64 &Header::openbox('100%', 'center', $Lang::tr{'hardware support'});
65 print <<EOF;
66 <p style="color: $message_colour; text-align: center;">$message</p>
67EOF
68 &Header::closebox();
69
15b023b9
MT
70 &Header::closebigbox();
71 &Header::closepage();
72}
84004f05
MT
73
74sub has_hwrng() {
75 return (-c "/dev/hwrng");
76}
77
78sub has_rdrand() {
79 open(FILE, "/proc/cpuinfo") or return 0;
80 my @cpuinfo = <FILE>;
81 close(FILE);
82
83 my @result = grep(/rdrand/, @cpuinfo);
84 if (@result) {
85 return 1;
86 }
87
88 return 0;
89}