]>
Commit | Line | Data |
---|---|---|
ac1cfefa | 1 | #!/usr/bin/perl |
70df8302 MT |
2 | ############################################################################### |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
26906d98 | 5 | # Copyright (C) 2005-2010 IPFire Team # |
70df8302 MT |
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 | ############################################################################### | |
ac1cfefa MT |
21 | |
22 | use strict; | |
23 | ||
2032b6f9 | 24 | # enable only the following on debugging purpose |
2d281532 CS |
25 | #use warnings; |
26 | #use CGI::Carp 'fatalsToBrowser'; | |
2032b6f9 | 27 | |
f2fdd0c1 | 28 | require '/var/ipfire/general-functions.pl'; |
ac1cfefa MT |
29 | require "${General::swroot}/lang.pl"; |
30 | require "${General::swroot}/header.pl"; | |
773362c5 | 31 | require "${General::swroot}/graphs.pl"; |
ac1cfefa | 32 | |
2032b6f9 CS |
33 | my %color = (); |
34 | my %mainsettings = (); | |
4e481c3a | 35 | my %netsettings=(); |
2032b6f9 CS |
36 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); |
37 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
2032b6f9 | 38 | &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); |
ac1cfefa | 39 | |
4e481c3a CS |
40 | #workaround to suppress a warning when a variable is used only once |
41 | my @dummy = ( ${Header::colourred} ); | |
42 | undef (@dummy); | |
43 | ||
773362c5 | 44 | |
ac1cfefa | 45 | my %cgiparams=(); |
2032b6f9 CS |
46 | # Maps a nice printable name to the changing part of the pid file, which |
47 | # is also the name of the program | |
4e481c3a | 48 | my %servicenames =( |
2032b6f9 CS |
49 | $Lang::tr{'dhcp server'} => 'dhcpd', |
50 | $Lang::tr{'web server'} => 'httpd', | |
51 | $Lang::tr{'cron server'} => 'fcron', | |
9625be6f | 52 | $Lang::tr{'dns proxy server'} => 'unbound', |
2032b6f9 CS |
53 | $Lang::tr{'logging server'} => 'syslogd', |
54 | $Lang::tr{'kernel logging server'} => 'klogd', | |
55 | $Lang::tr{'ntp server'} => 'ntpd', | |
56 | $Lang::tr{'secure shell server'} => 'sshd', | |
70e8a248 | 57 | $Lang::tr{'vpn'} => 'charon', |
2032b6f9 | 58 | $Lang::tr{'web proxy'} => 'squid', |
0d8cc90f | 59 | $Lang::tr{'intrusion detection system'} => 'suricata', |
2032b6f9 CS |
60 | 'OpenVPN' => 'openvpn' |
61 | ); | |
62 | ||
533f1e11 JPT |
63 | my %link =( |
64 | $Lang::tr{'dhcp server'} => "<a href=\'dhcp.cgi\'>$Lang::tr{'dhcp server'}</a>", | |
65 | $Lang::tr{'web server'} => $Lang::tr{'web server'}, | |
66 | $Lang::tr{'cron server'} => $Lang::tr{'cron server'}, | |
67 | $Lang::tr{'dns proxy server'} => $Lang::tr{'dns proxy server'}, | |
68 | $Lang::tr{'logging server'} => $Lang::tr{'logging server'}, | |
69 | $Lang::tr{'kernel logging server'} => $Lang::tr{'kernel logging server'}, | |
70 | $Lang::tr{'ntp server'} => "<a href=\'time.cgi\'>$Lang::tr{'ntp server'}</a>", | |
71 | $Lang::tr{'secure shell server'} => "<a href=\'remote.cgi\'>$Lang::tr{'secure shell server'}</a>", | |
72 | $Lang::tr{'vpn'} => "<a href=\'vpnmain.cgi\'>$Lang::tr{'vpn'}</a>", | |
73 | $Lang::tr{'web proxy'} => "<a href=\'proxy.cgi\'>$Lang::tr{'web proxy'}</a>", | |
74 | 'OpenVPN' => "<a href=\'ovpnmain.cgi\'>OpenVPN</a>", | |
0d8cc90f | 75 | "$Lang::tr{'intrusion detection system'}" => "<a href=\'ids.cgi\'>$Lang::tr{'intrusion detection system'}</a>", |
533f1e11 JPT |
76 | ); |
77 | ||
0d8cc90f SS |
78 | # Hash to overwrite the process name of a process if it differs fromt the launch command. |
79 | my %overwrite_exename_hash = ( | |
80 | "suricata" => "Suricata-Main" | |
81 | ); | |
4e481c3a | 82 | |
0d8cc90f | 83 | my $lines=0; # Used to count the outputlines to make different bgcolor |
ac1cfefa | 84 | |
4e481c3a CS |
85 | my @querry = split(/\?/,$ENV{'QUERY_STRING'}); |
86 | $querry[0] = '' unless defined $querry[0]; | |
87 | $querry[1] = 'hour' unless defined $querry[1]; | |
88 | ||
89 | if ( $querry[0] =~ "processescpu"){ | |
90 | print "Content-type: image/png\n\n"; | |
91 | binmode(STDOUT); | |
92 | &Graphs::updateprocessescpugraph($querry[1]); | |
93 | }elsif ( $querry[0] =~ "processesmemory"){ | |
94 | print "Content-type: image/png\n\n"; | |
95 | binmode(STDOUT); | |
96 | &Graphs::updateprocessesmemorygraph($querry[1]); | |
97 | }else{ | |
98 | &Header::showhttpheaders(); | |
99 | &Header::openpage($Lang::tr{'status information'}, 1, ''); | |
100 | &Header::openbigbox('100%', 'left'); | |
101 | ||
102 | &Header::openbox('100%', 'left', $Lang::tr{'services'}); | |
103 | print <<END | |
2032b6f9 | 104 | <div align='center'> |
91a81810 | 105 | <table width='80%' cellspacing='1' class='tbl'> |
a9d40c03 | 106 | <tr> |
91a81810 AM |
107 | <th align='left'><b>$Lang::tr{'services'}</b></th> |
108 | <th align='center' ><b>$Lang::tr{'status'}</b></th> | |
109 | <th align='center'><b>PID</b></th> | |
110 | <th align='center'><b>$Lang::tr{'memory'}</b></th> | |
111 | </tr> | |
2032b6f9 CS |
112 | END |
113 | ; | |
4e481c3a | 114 | my $key = ''; |
91a81810 | 115 | my $col=""; |
4e481c3a CS |
116 | foreach $key (sort keys %servicenames){ |
117 | $lines++; | |
118 | if ($lines % 2){ | |
91a81810 AM |
119 | $col="bgcolor='$color{'color22'}'"; |
120 | print "<tr><td align='left' $col>"; | |
62a13aec | 121 | print $link{$key}; |
91a81810 | 122 | print "</td>"; |
4e481c3a | 123 | }else{ |
91a81810 AM |
124 | $col="bgcolor='$color{'color20'}'"; |
125 | print "<tr><td align='left' $col>"; | |
62a13aec | 126 | print $link{$key}; |
91a81810 | 127 | print "</td>"; |
4e481c3a | 128 | } |
ac1cfefa | 129 | |
4e481c3a | 130 | my $shortname = $servicenames{$key}; |
91a81810 | 131 | my $status = &isrunning($shortname,$col); |
ac1cfefa | 132 | |
4e481c3a CS |
133 | print "$status\n"; |
134 | print "</tr>\n"; | |
135 | } | |
ac1cfefa | 136 | |
4e481c3a CS |
137 | print "</table></div>\n"; |
138 | &Header::closebox(); | |
ac1cfefa | 139 | |
4e481c3a CS |
140 | &Header::openbox('100%', 'left', "Addon - $Lang::tr{services}"); |
141 | my $paramstr=$ENV{QUERY_STRING}; | |
142 | my @param=split(/!/, $paramstr); | |
143 | if ($param[1] ne ''){ | |
144 | system("/usr/local/bin/addonctrl @param[0] @param[1] > /dev/null 2>&1"); | |
145 | } | |
ac1cfefa | 146 | |
4e481c3a | 147 | print <<END |
2032b6f9 | 148 | <div align='center'> |
91a81810 | 149 | <table width='80%' cellspacing='1' class='tbl'> |
a9d40c03 | 150 | <tr> |
91a81810 AM |
151 | <th align='center'><b>Addon</b></th> |
152 | <th align='center'><b>Boot</b></th> | |
153 | <th align='center' colspan=2><b>$Lang::tr{'action'}</b></th> | |
154 | <th align='center'><b>$Lang::tr{'status'}</b></th> | |
155 | <th align='center'><b>PID</b></th> | |
156 | <th align='center'><b>$Lang::tr{'memory'}</b></th> | |
2032b6f9 | 157 | </tr> |
ac1cfefa MT |
158 | END |
159 | ; | |
ac1cfefa | 160 | |
4e481c3a CS |
161 | my $lines=0; # Used to count the outputlines to make different bgcolor |
162 | ||
163 | # Generate list of installed addon pak's | |
164 | my @pak = `find /opt/pakfire/db/installed/meta-* 2>/dev/null | cut -d"-" -f2`; | |
165 | foreach (@pak){ | |
166 | chomp($_); | |
167 | ||
168 | # Check which of the paks are services | |
169 | my @svc = `find /etc/init.d/$_ 2>/dev/null | cut -d"/" -f4`; | |
170 | foreach (@svc){ | |
171 | # blacklist some packages | |
172 | # | |
173 | # alsa has trouble with the volume saving and was not really stopped | |
bbd544ea | 174 | # mdadm should not stopped with webif because this could crash the system |
4e481c3a CS |
175 | # |
176 | chomp($_); | |
39d43569 AM |
177 | if ( $_ eq 'squid' ) { |
178 | next; | |
179 | } | |
bbd544ea | 180 | if ( ($_ ne "alsa") && ($_ ne "mdadm") ) { |
4e481c3a CS |
181 | $lines++; |
182 | if ($lines % 2){ | |
91a81810 AM |
183 | print "<tr>"; |
184 | $col="bgcolor='$color{'color22'}'"; | |
4e481c3a | 185 | }else{ |
91a81810 AM |
186 | print "<tr>"; |
187 | $col="bgcolor='$color{'color20'}'"; | |
4e481c3a | 188 | } |
a9d40c03 | 189 | print "<td align='left' $col width='31%'>$_</td> "; |
91a81810 | 190 | my $status = isautorun($_,$col); |
4e481c3a | 191 | print "$status "; |
df261521 AH |
192 | print "<td align='center' $col width='8%'><a href='services.cgi?$_!start'><img alt='$Lang::tr{'start'}' title='$Lang::tr{'start'}' src='/images/go-up.png' border='0' /></a></td>"; |
193 | print "<td align='center' $col width='8%'><a href='services.cgi?$_!stop'><img alt='$Lang::tr{'stop'}' title='$Lang::tr{'stop'}' src='/images/go-down.png' border='0' /></a></td> "; | |
91a81810 | 194 | my $status = &isrunningaddon($_,$col); |
4e481c3a CS |
195 | $status =~ s/\\e\[[0-1]\;[0-9]+m//g; |
196 | ||
197 | chomp($status); | |
198 | print "$status"; | |
199 | print "</tr>"; | |
200 | } | |
ac1cfefa | 201 | } |
ac1cfefa | 202 | } |
ac1cfefa | 203 | |
4e481c3a CS |
204 | print "</table></div>\n"; |
205 | &Header::closebox(); | |
ac1cfefa | 206 | |
4e481c3a CS |
207 | &Header::openbox('100%', 'center', "$Lang::tr{'processes'} $Lang::tr{'graph'}"); |
208 | &Graphs::makegraphbox("services.cgi","processescpu","day"); | |
209 | &Header::closebox(); | |
773362c5 | 210 | |
4e481c3a CS |
211 | &Header::openbox('100%', 'center', "$Lang::tr{'processes'} $Lang::tr{'memory'} $Lang::tr{'graph'}"); |
212 | &Graphs::makegraphbox("services.cgi","processesmemory","day"); | |
213 | &Header::closebox(); | |
214 | ||
215 | &Header::closebigbox(); | |
216 | &Header::closepage(); | |
773362c5 | 217 | } |
ac1cfefa | 218 | |
4e481c3a | 219 | sub isautorun{ |
2032b6f9 | 220 | my $cmd = $_[0]; |
91a81810 AM |
221 | my $col = $_[1]; |
222 | my $status = "<td align='center' $col></td>"; | |
bf660619 | 223 | my $init = `find /etc/rc.d/rc3.d/S??${cmd} 2>/dev/null`; |
2032b6f9 | 224 | chomp ($init); |
4e481c3a | 225 | if ($init ne ''){ |
df261521 | 226 | $status = "<td align='center' $col><a href='services.cgi?$_!disable'><img alt='$Lang::tr{'deactivate'}' title='$Lang::tr{'deactivate'}' src='/images/on.gif' border='0' width='16' height='16' /></a></td>"; |
ac1cfefa | 227 | } |
bf660619 | 228 | $init = `find /etc/rc.d/rc3.d/off/S??${cmd} 2>/dev/null`; |
2032b6f9 | 229 | chomp ($init); |
4e481c3a | 230 | if ($init ne ''){ |
df261521 | 231 | $status = "<td align='center' $col><a href='services.cgi?$_!enable'><img alt='$Lang::tr{'activate'}' title='$Lang::tr{'activate'}' src='/images/off.gif' border='0' width='16' height='16' /></a></td>"; |
ac1cfefa | 232 | } |
773362c5 | 233 | |
4e481c3a | 234 | return $status; |
2032b6f9 CS |
235 | } |
236 | ||
4e481c3a | 237 | sub isrunning{ |
2032b6f9 | 238 | my $cmd = $_[0]; |
91a81810 AM |
239 | my $col = $_[1]; |
240 | my $status = "<td align='center' bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td><td colspan='2' $col></td>"; | |
2032b6f9 CS |
241 | my $pid = ''; |
242 | my $testcmd = ''; | |
243 | my $exename; | |
24c82ed2 | 244 | my $memory; |
2032b6f9 CS |
245 | |
246 | $cmd =~ /(^[a-z]+)/; | |
0d8cc90f SS |
247 | |
248 | # Check if the exename needs to be overwritten. | |
249 | # This happens if the expected process name string | |
250 | # differs from the real one. This may happened if | |
251 | # a service uses multiple processes or threads. | |
252 | if (exists($overwrite_exename_hash{$1})) { | |
253 | # Grab the string which will be reported by | |
254 | # the process from the corresponding hash. | |
255 | $exename = $overwrite_exename_hash{$1}; | |
256 | } else { | |
257 | # Directly expect the launched command as | |
258 | # process name. | |
259 | $exename = $1; | |
260 | } | |
2032b6f9 CS |
261 | |
262 | if (open(FILE, "/var/run/${cmd}.pid")){ | |
263 | $pid = <FILE>; chomp $pid; | |
264 | close FILE; | |
265 | if (open(FILE, "/proc/${pid}/status")){ | |
266 | while (<FILE>){ | |
4e481c3a CS |
267 | if (/^Name:\W+(.*)/) { |
268 | $testcmd = $1; | |
269 | } | |
ac1cfefa | 270 | } |
2032b6f9 | 271 | close FILE; |
ac1cfefa | 272 | } |
24c82ed2 MT |
273 | if (open(FILE, "/proc/${pid}/status")) { |
274 | while (<FILE>) { | |
275 | my ($key, $val) = split(":", $_, 2); | |
276 | if ($key eq 'VmRSS') { | |
277 | $memory = $val; | |
278 | last; | |
279 | } | |
280 | } | |
281 | close(FILE); | |
ac1cfefa | 282 | } |
4e481c3a | 283 | if ($testcmd =~ /$exename/){ |
91a81810 | 284 | $status = "<td align='center' bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td><td align='center' $col>$pid</td><td align='center' $col>$memory</td>"; |
2032b6f9 | 285 | } |
4e481c3a CS |
286 | } |
287 | return $status; | |
ac1cfefa MT |
288 | } |
289 | ||
4e481c3a | 290 | sub isrunningaddon{ |
2032b6f9 | 291 | my $cmd = $_[0]; |
91a81810 AM |
292 | my $col = $_[1]; |
293 | my $status = "<td align='center' bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td><td colspan='2' $col></td>"; | |
2032b6f9 CS |
294 | my $pid = ''; |
295 | my $testcmd = ''; | |
296 | my $exename; | |
297 | my @memory; | |
773362c5 | 298 | |
26906d98 | 299 | my $testcmd = `/usr/local/bin/addonctrl $_ status 2>/dev/null`; |
ac1cfefa | 300 | |
2032b6f9 | 301 | if ( $testcmd =~ /is\ running/ && $testcmd !~ /is\ not\ running/){ |
4e481c3a | 302 | $status = "<td align='center' bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>"; |
7fb1b9f6 | 303 | $testcmd =~ s/.* //gi; |
4e481c3a CS |
304 | $testcmd =~ s/[a-z_]//gi; |
305 | $testcmd =~ s/\[[0-1]\;[0-9]+//gi; | |
306 | $testcmd =~ s/[\(\)\.]//gi; | |
307 | $testcmd =~ s/ //gi; | |
308 | $testcmd =~ s/\e//gi; | |
2032b6f9 | 309 | |
4e481c3a | 310 | my @pid = split(/\s/,$testcmd); |
91a81810 | 311 | $status .="<td align='center' $col>$pid[0]</td>"; |
773362c5 | 312 | |
4e481c3a | 313 | my $memory = 0; |
773362c5 | 314 | |
4e481c3a CS |
315 | foreach (@pid){ |
316 | chomp($_); | |
317 | if (open(FILE, "/proc/$_/statm")){ | |
2032b6f9 | 318 | my $temp = <FILE>; |
4e481c3a CS |
319 | @memory = split(/ /,$temp); |
320 | } | |
321 | $memory+=$memory[0]; | |
ac1cfefa | 322 | } |
91a81810 | 323 | $status .="<td align='center' $col>$memory KB</td>"; |
4e481c3a | 324 | }else{ |
91a81810 | 325 | $status = "<td align='center' bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td><td colspan='2' $col></td>"; |
ac1cfefa | 326 | } |
4e481c3a | 327 | return $status; |
ac1cfefa | 328 | } |