]>
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', | |
52 | $Lang::tr{'dns proxy server'} => 'dnsmasq', | |
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 CS |
58 | $Lang::tr{'web proxy'} => 'squid', |
59 | 'OpenVPN' => 'openvpn' | |
60 | ); | |
61 | ||
533f1e11 JPT |
62 | my %link =( |
63 | $Lang::tr{'dhcp server'} => "<a href=\'dhcp.cgi\'>$Lang::tr{'dhcp server'}</a>", | |
64 | $Lang::tr{'web server'} => $Lang::tr{'web server'}, | |
65 | $Lang::tr{'cron server'} => $Lang::tr{'cron server'}, | |
66 | $Lang::tr{'dns proxy server'} => $Lang::tr{'dns proxy server'}, | |
67 | $Lang::tr{'logging server'} => $Lang::tr{'logging server'}, | |
68 | $Lang::tr{'kernel logging server'} => $Lang::tr{'kernel logging server'}, | |
69 | $Lang::tr{'ntp server'} => "<a href=\'time.cgi\'>$Lang::tr{'ntp server'}</a>", | |
70 | $Lang::tr{'secure shell server'} => "<a href=\'remote.cgi\'>$Lang::tr{'secure shell server'}</a>", | |
71 | $Lang::tr{'vpn'} => "<a href=\'vpnmain.cgi\'>$Lang::tr{'vpn'}</a>", | |
72 | $Lang::tr{'web proxy'} => "<a href=\'proxy.cgi\'>$Lang::tr{'web proxy'}</a>", | |
73 | 'OpenVPN' => "<a href=\'ovpnmain.cgi\'>OpenVPN</a>", | |
74 | "$Lang::tr{'intrusion detection system'} (GREEN)" => "<a href=\'ids.cgi\'>$Lang::tr{'intrusion detection system'} (GREEN)</a>", | |
75 | "$Lang::tr{'intrusion detection system'} (RED)" => "<a href=\'ids.cgi\'>$Lang::tr{'intrusion detection system'} (RED)</a>", | |
76 | "$Lang::tr{'intrusion detection system'} (ORANGE)" => "<a href=\'ids.cgi\'>$Lang::tr{'intrusion detection system'} (ORANGE)</a>", | |
77 | "$Lang::tr{'intrusion detection system'} (BLUE)" => "<a href=\'ids.cgi\'>$Lang::tr{'intrusion detection system'} (BLUE)</a>" | |
78 | ); | |
79 | ||
2032b6f9 CS |
80 | my $lines=0; # Used to count the outputlines to make different bgcolor |
81 | ||
82 | my $iface = ''; | |
4e481c3a | 83 | if (open(FILE, "${General::swroot}/red/iface")){ |
2032b6f9 CS |
84 | $iface = <FILE>; |
85 | close FILE; | |
86 | chomp $iface; | |
ac1cfefa | 87 | } |
4e481c3a | 88 | |
2032b6f9 CS |
89 | $servicenames{"$Lang::tr{'intrusion detection system'} (RED)"} = "snort_${iface}"; |
90 | $servicenames{"$Lang::tr{'intrusion detection system'} (GREEN)"} = "snort_$netsettings{'GREEN_DEV'}"; | |
4e481c3a CS |
91 | |
92 | if ($netsettings{'ORANGE_DEV'} ne ''){ | |
2032b6f9 | 93 | $servicenames{"$Lang::tr{'intrusion detection system'} (ORANGE)"} = "snort_$netsettings{'ORANGE_DEV'}"; |
ac1cfefa | 94 | } |
4e481c3a | 95 | if ($netsettings{'BLUE_DEV'} ne ''){ |
2032b6f9 | 96 | $servicenames{"$Lang::tr{'intrusion detection system'} (BLUE)"} = "snort_$netsettings{'BLUE_DEV'}"; |
ac1cfefa MT |
97 | } |
98 | ||
4e481c3a CS |
99 | my @querry = split(/\?/,$ENV{'QUERY_STRING'}); |
100 | $querry[0] = '' unless defined $querry[0]; | |
101 | $querry[1] = 'hour' unless defined $querry[1]; | |
102 | ||
103 | if ( $querry[0] =~ "processescpu"){ | |
104 | print "Content-type: image/png\n\n"; | |
105 | binmode(STDOUT); | |
106 | &Graphs::updateprocessescpugraph($querry[1]); | |
107 | }elsif ( $querry[0] =~ "processesmemory"){ | |
108 | print "Content-type: image/png\n\n"; | |
109 | binmode(STDOUT); | |
110 | &Graphs::updateprocessesmemorygraph($querry[1]); | |
111 | }else{ | |
112 | &Header::showhttpheaders(); | |
113 | &Header::openpage($Lang::tr{'status information'}, 1, ''); | |
114 | &Header::openbigbox('100%', 'left'); | |
115 | ||
116 | &Header::openbox('100%', 'left', $Lang::tr{'services'}); | |
117 | print <<END | |
2032b6f9 | 118 | <div align='center'> |
91a81810 | 119 | <table width='80%' cellspacing='1' class='tbl'> |
a9d40c03 | 120 | <tr> |
91a81810 AM |
121 | <th align='left'><b>$Lang::tr{'services'}</b></th> |
122 | <th align='center' ><b>$Lang::tr{'status'}</b></th> | |
123 | <th align='center'><b>PID</b></th> | |
124 | <th align='center'><b>$Lang::tr{'memory'}</b></th> | |
125 | </tr> | |
2032b6f9 CS |
126 | END |
127 | ; | |
4e481c3a | 128 | my $key = ''; |
91a81810 | 129 | my $col=""; |
4e481c3a CS |
130 | foreach $key (sort keys %servicenames){ |
131 | $lines++; | |
132 | if ($lines % 2){ | |
91a81810 AM |
133 | $col="bgcolor='$color{'color22'}'"; |
134 | print "<tr><td align='left' $col>"; | |
62a13aec | 135 | print $link{$key}; |
91a81810 | 136 | print "</td>"; |
4e481c3a | 137 | }else{ |
91a81810 AM |
138 | $col="bgcolor='$color{'color20'}'"; |
139 | print "<tr><td align='left' $col>"; | |
62a13aec | 140 | print $link{$key}; |
91a81810 | 141 | print "</td>"; |
4e481c3a | 142 | } |
ac1cfefa | 143 | |
4e481c3a | 144 | my $shortname = $servicenames{$key}; |
91a81810 | 145 | my $status = &isrunning($shortname,$col); |
ac1cfefa | 146 | |
4e481c3a CS |
147 | print "$status\n"; |
148 | print "</tr>\n"; | |
149 | } | |
ac1cfefa | 150 | |
4e481c3a CS |
151 | print "</table></div>\n"; |
152 | &Header::closebox(); | |
ac1cfefa | 153 | |
4e481c3a CS |
154 | &Header::openbox('100%', 'left', "Addon - $Lang::tr{services}"); |
155 | my $paramstr=$ENV{QUERY_STRING}; | |
156 | my @param=split(/!/, $paramstr); | |
157 | if ($param[1] ne ''){ | |
158 | system("/usr/local/bin/addonctrl @param[0] @param[1] > /dev/null 2>&1"); | |
159 | } | |
ac1cfefa | 160 | |
4e481c3a | 161 | print <<END |
2032b6f9 | 162 | <div align='center'> |
91a81810 | 163 | <table width='80%' cellspacing='1' class='tbl'> |
a9d40c03 | 164 | <tr> |
91a81810 AM |
165 | <th align='center'><b>Addon</b></th> |
166 | <th align='center'><b>Boot</b></th> | |
167 | <th align='center' colspan=2><b>$Lang::tr{'action'}</b></th> | |
168 | <th align='center'><b>$Lang::tr{'status'}</b></th> | |
169 | <th align='center'><b>PID</b></th> | |
170 | <th align='center'><b>$Lang::tr{'memory'}</b></th> | |
2032b6f9 | 171 | </tr> |
ac1cfefa MT |
172 | END |
173 | ; | |
ac1cfefa | 174 | |
4e481c3a CS |
175 | my $lines=0; # Used to count the outputlines to make different bgcolor |
176 | ||
177 | # Generate list of installed addon pak's | |
178 | my @pak = `find /opt/pakfire/db/installed/meta-* 2>/dev/null | cut -d"-" -f2`; | |
179 | foreach (@pak){ | |
180 | chomp($_); | |
181 | ||
182 | # Check which of the paks are services | |
183 | my @svc = `find /etc/init.d/$_ 2>/dev/null | cut -d"/" -f4`; | |
184 | foreach (@svc){ | |
185 | # blacklist some packages | |
186 | # | |
187 | # alsa has trouble with the volume saving and was not really stopped | |
bbd544ea | 188 | # mdadm should not stopped with webif because this could crash the system |
4e481c3a CS |
189 | # |
190 | chomp($_); | |
39d43569 AM |
191 | if ( $_ eq 'squid' ) { |
192 | next; | |
193 | } | |
bbd544ea | 194 | if ( ($_ ne "alsa") && ($_ ne "mdadm") ) { |
4e481c3a CS |
195 | $lines++; |
196 | if ($lines % 2){ | |
91a81810 AM |
197 | print "<tr>"; |
198 | $col="bgcolor='$color{'color22'}'"; | |
4e481c3a | 199 | }else{ |
91a81810 AM |
200 | print "<tr>"; |
201 | $col="bgcolor='$color{'color20'}'"; | |
4e481c3a | 202 | } |
a9d40c03 | 203 | print "<td align='left' $col width='31%'>$_</td> "; |
91a81810 | 204 | my $status = isautorun($_,$col); |
4e481c3a | 205 | print "$status "; |
df261521 AH |
206 | 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>"; |
207 | 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 | 208 | my $status = &isrunningaddon($_,$col); |
4e481c3a CS |
209 | $status =~ s/\\e\[[0-1]\;[0-9]+m//g; |
210 | ||
211 | chomp($status); | |
212 | print "$status"; | |
213 | print "</tr>"; | |
214 | } | |
ac1cfefa | 215 | } |
ac1cfefa | 216 | } |
ac1cfefa | 217 | |
4e481c3a CS |
218 | print "</table></div>\n"; |
219 | &Header::closebox(); | |
ac1cfefa | 220 | |
4e481c3a CS |
221 | &Header::openbox('100%', 'center', "$Lang::tr{'processes'} $Lang::tr{'graph'}"); |
222 | &Graphs::makegraphbox("services.cgi","processescpu","day"); | |
223 | &Header::closebox(); | |
773362c5 | 224 | |
4e481c3a CS |
225 | &Header::openbox('100%', 'center', "$Lang::tr{'processes'} $Lang::tr{'memory'} $Lang::tr{'graph'}"); |
226 | &Graphs::makegraphbox("services.cgi","processesmemory","day"); | |
227 | &Header::closebox(); | |
228 | ||
229 | &Header::closebigbox(); | |
230 | &Header::closepage(); | |
773362c5 | 231 | } |
ac1cfefa | 232 | |
4e481c3a | 233 | sub isautorun{ |
2032b6f9 | 234 | my $cmd = $_[0]; |
91a81810 AM |
235 | my $col = $_[1]; |
236 | my $status = "<td align='center' $col></td>"; | |
bf660619 | 237 | my $init = `find /etc/rc.d/rc3.d/S??${cmd} 2>/dev/null`; |
2032b6f9 | 238 | chomp ($init); |
4e481c3a | 239 | if ($init ne ''){ |
df261521 | 240 | $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 | 241 | } |
bf660619 | 242 | $init = `find /etc/rc.d/rc3.d/off/S??${cmd} 2>/dev/null`; |
2032b6f9 | 243 | chomp ($init); |
4e481c3a | 244 | if ($init ne ''){ |
df261521 | 245 | $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 | 246 | } |
773362c5 | 247 | |
4e481c3a | 248 | return $status; |
2032b6f9 CS |
249 | } |
250 | ||
4e481c3a | 251 | sub isrunning{ |
2032b6f9 | 252 | my $cmd = $_[0]; |
91a81810 AM |
253 | my $col = $_[1]; |
254 | 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 |
255 | my $pid = ''; |
256 | my $testcmd = ''; | |
257 | my $exename; | |
24c82ed2 | 258 | my $memory; |
2032b6f9 CS |
259 | |
260 | $cmd =~ /(^[a-z]+)/; | |
261 | $exename = $1; | |
262 | ||
263 | if (open(FILE, "/var/run/${cmd}.pid")){ | |
264 | $pid = <FILE>; chomp $pid; | |
265 | close FILE; | |
266 | if (open(FILE, "/proc/${pid}/status")){ | |
267 | while (<FILE>){ | |
4e481c3a CS |
268 | if (/^Name:\W+(.*)/) { |
269 | $testcmd = $1; | |
270 | } | |
ac1cfefa | 271 | } |
2032b6f9 | 272 | close FILE; |
ac1cfefa | 273 | } |
24c82ed2 MT |
274 | if (open(FILE, "/proc/${pid}/status")) { |
275 | while (<FILE>) { | |
276 | my ($key, $val) = split(":", $_, 2); | |
277 | if ($key eq 'VmRSS') { | |
278 | $memory = $val; | |
279 | last; | |
280 | } | |
281 | } | |
282 | close(FILE); | |
ac1cfefa | 283 | } |
4e481c3a | 284 | if ($testcmd =~ /$exename/){ |
91a81810 | 285 | $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 | 286 | } |
4e481c3a CS |
287 | } |
288 | return $status; | |
ac1cfefa MT |
289 | } |
290 | ||
4e481c3a | 291 | sub isrunningaddon{ |
2032b6f9 | 292 | my $cmd = $_[0]; |
91a81810 AM |
293 | my $col = $_[1]; |
294 | 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 |
295 | my $pid = ''; |
296 | my $testcmd = ''; | |
297 | my $exename; | |
298 | my @memory; | |
773362c5 | 299 | |
26906d98 | 300 | my $testcmd = `/usr/local/bin/addonctrl $_ status 2>/dev/null`; |
ac1cfefa | 301 | |
2032b6f9 | 302 | if ( $testcmd =~ /is\ running/ && $testcmd !~ /is\ not\ running/){ |
4e481c3a | 303 | $status = "<td align='center' bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>"; |
7fb1b9f6 | 304 | $testcmd =~ s/.* //gi; |
4e481c3a CS |
305 | $testcmd =~ s/[a-z_]//gi; |
306 | $testcmd =~ s/\[[0-1]\;[0-9]+//gi; | |
307 | $testcmd =~ s/[\(\)\.]//gi; | |
308 | $testcmd =~ s/ //gi; | |
309 | $testcmd =~ s/\e//gi; | |
2032b6f9 | 310 | |
4e481c3a | 311 | my @pid = split(/\s/,$testcmd); |
91a81810 | 312 | $status .="<td align='center' $col>$pid[0]</td>"; |
773362c5 | 313 | |
4e481c3a | 314 | my $memory = 0; |
773362c5 | 315 | |
4e481c3a CS |
316 | foreach (@pid){ |
317 | chomp($_); | |
318 | if (open(FILE, "/proc/$_/statm")){ | |
2032b6f9 | 319 | my $temp = <FILE>; |
4e481c3a CS |
320 | @memory = split(/ /,$temp); |
321 | } | |
322 | $memory+=$memory[0]; | |
ac1cfefa | 323 | } |
91a81810 | 324 | $status .="<td align='center' $col>$memory KB</td>"; |
4e481c3a | 325 | }else{ |
91a81810 | 326 | $status = "<td align='center' bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td><td colspan='2' $col></td>"; |
ac1cfefa | 327 | } |
4e481c3a | 328 | return $status; |
ac1cfefa | 329 | } |