]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/system.cgi
e627f2660e640034284f0f8249fc1456dc84cd55
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / system.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
21 #workaround to suppress a warning when a variable is used only once
22 my @dummy = ( ${Header::colourred} );
23 undef (@dummy);
24
25 my %netsettings=();
26 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
27
28 my %color = ();
29 my %mainsettings = ();
30 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
31 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
32
33 my %cgiparams=();
34 # Maps a nice printable name to the changing part of the pid file, which
35 # is also the name of the program
36 my %servicenames =
37 (
38 $Lang::tr{'dhcp server'} => 'dhcpd',
39 $Lang::tr{'web server'} => 'httpd',
40 $Lang::tr{'cron server'} => 'fcron',
41 $Lang::tr{'dns proxy server'} => 'dnsmasq',
42 $Lang::tr{'logging server'} => 'syslogd',
43 $Lang::tr{'kernel logging server'} => 'klogd',
44 $Lang::tr{'ntp server'} => 'ntpd',
45 $Lang::tr{'secure shell server'} => 'sshd',
46 $Lang::tr{'vpn'} => 'pluto',
47 $Lang::tr{'web proxy'} => 'squid',
48 'OpenVPN' => 'openvpn'
49 );
50
51 my $iface = '';
52 if (open(FILE, "${General::swroot}/red/iface"))
53 {
54 $iface = <FILE>;
55 close FILE;
56 chomp $iface;
57 }
58 $servicenames{"$Lang::tr{'intrusion detection system'} (RED)"} = "snort_${iface}";
59 $servicenames{"$Lang::tr{'intrusion detection system'} (GREEN)"} = "snort_$netsettings{'GREEN_DEV'}";
60 if ($netsettings{'ORANGE_DEV'} ne '') {
61 $servicenames{"$Lang::tr{'intrusion detection system'} (ORANGE)"} = "snort_$netsettings{'ORANGE_DEV'}";
62 }
63 if ($netsettings{'BLUE_DEV'} ne '') {
64 $servicenames{"$Lang::tr{'intrusion detection system'} (BLUE)"} = "snort_$netsettings{'BLUE_DEV'}";
65 }
66
67 &Header::showhttpheaders();
68
69 &Header::getcgihash(\%cgiparams);
70
71 &Header::openpage($Lang::tr{'status information'}, 1, '');
72
73 &Header::openbigbox('100%', 'left');
74
75 &Header::openbox('100%', 'center', "CPU $Lang::tr{'graph'}");
76 if (-e "$Header::graphdir/cpu-day.png") {
77 my $ftime = localtime((stat("$Header::graphdir/cpu-day.png"))[9]);
78 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
79 print "<a href='/cgi-bin/graphs.cgi?graph=cpu'>";
80 print "<img alt='' src='/graphs/cpu-day.png' border='0' />";
81 print "</a>";
82 } else {
83 print $Lang::tr{'no information available'};
84 }
85 print "<br />\n";
86 &Header::closebox();
87
88 &Header::openbox('100%', 'center', "Load $Lang::tr{'graph'}");
89 if (-e "$Header::graphdir/load-day.png") {
90 my $ftime = localtime((stat("$Header::graphdir/load-day.png"))[9]);
91 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
92 print "<a href='/cgi-bin/graphs.cgi?graph=load'>";
93 print "<img alt='' src='/graphs/load-day.png' border='0' />";
94 print "</a>";
95 } else {
96 print $Lang::tr{'no information available'};
97 }
98 print "<br />\n";
99 &Header::closebox();
100
101 &Header::openbox('100%', 'left', $Lang::tr{'services'});
102
103 print <<END
104 <div align='center'>
105 <table width='60%' cellspacing='0' border='0'>
106 END
107 ;
108
109 my $key = '';
110 foreach $key (sort keys %servicenames)
111 {
112 print "<tr>\n<td align='left'>$key</td>\n";
113 my $shortname = $servicenames{$key};
114 my $status = &isrunning($shortname);
115 print "$status\n";
116 print "</tr>\n";
117 }
118
119
120 print "</table></div>\n";
121
122 &Header::closebox();
123 &Header::closebigbox();
124 &Header::closepage();
125
126 sub isrunning
127 {
128 my $cmd = $_[0];
129 my $status = "<td bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>";
130 my $pid = '';
131 my $testcmd = '';
132 my $exename;
133
134 $cmd =~ /(^[a-z]+)/;
135 $exename = $1;
136
137 if (open(FILE, "/var/run/${cmd}.pid"))
138 {
139 $pid = <FILE>; chomp $pid;
140 close FILE;
141 if (open(FILE, "/proc/${pid}/status"))
142 {
143 while (<FILE>)
144 {
145 if (/^Name:\W+(.*)/) {
146 $testcmd = $1; }
147 }
148 close FILE;
149 if ($testcmd =~ /$exename/)
150 {
151 $status = "<td bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>";
152 }
153 }
154 }
155
156 return $status;
157 }
158
159 sub percentbar
160 {
161 my $percent = $_[0];
162 my $fg = '#a0a0a0';
163 my $bg = '#e2e2e2';
164
165 if ($percent =~ m/^(\d+)%$/ )
166 {
167 print <<END
168 <table width='100' border='1' cellspacing='0' cellpadding='0' style='border-width:1px;border-style:solid;border-color:$fg;width:100px;height:10px;'>
169 <tr>
170 END
171 ;
172 if ($percent eq "100%") {
173 print "<td width='100%' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'>"
174 } elsif ($percent eq "0%") {
175 print "<td width='100%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"
176 } else {
177 print "<td width='$percent' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'></td><td width='" . (100-$1) . "%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"
178 }
179 print <<END
180 <img src='/images/null.gif' width='1' height='1' alt='' /></td></tr></table>
181 END
182 ;
183 }
184 }