]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/perl | |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2008 Michael Tremer & Christian Schmidt # | |
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 | ||
22 | use strict; | |
23 | ||
24 | # enable only the following on debugging purpose | |
25 | #use warnings; | |
26 | #use CGI::Carp 'fatalsToBrowser'; | |
27 | ||
28 | require '/var/ipfire/general-functions.pl'; | |
29 | require "${General::swroot}/lang.pl"; | |
30 | require "${General::swroot}/header.pl"; | |
31 | require "${General::swroot}/graphs.pl"; | |
32 | ||
33 | my %color = (); | |
34 | my %mainsettings = (); | |
35 | my %netsettings=(); | |
36 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
37 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
38 | &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); | |
39 | ||
40 | #workaround to suppress a warning when a variable is used only once | |
41 | my @dummy = ( ${Header::colourred} ); | |
42 | undef (@dummy); | |
43 | ||
44 | ||
45 | my %cgiparams=(); | |
46 | # Maps a nice printable name to the changing part of the pid file, which | |
47 | # is also the name of the program | |
48 | my %servicenames =( | |
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', | |
57 | $Lang::tr{'vpn'} => 'pluto', | |
58 | $Lang::tr{'web proxy'} => 'squid', | |
59 | 'OpenVPN' => 'openvpn' | |
60 | ); | |
61 | ||
62 | my $lines=0; # Used to count the outputlines to make different bgcolor | |
63 | ||
64 | my $iface = ''; | |
65 | if (open(FILE, "${General::swroot}/red/iface")){ | |
66 | $iface = <FILE>; | |
67 | close FILE; | |
68 | chomp $iface; | |
69 | } | |
70 | ||
71 | $servicenames{"$Lang::tr{'intrusion detection system'} (RED)"} = "snort_${iface}"; | |
72 | $servicenames{"$Lang::tr{'intrusion detection system'} (GREEN)"} = "snort_$netsettings{'GREEN_DEV'}"; | |
73 | ||
74 | if ($netsettings{'ORANGE_DEV'} ne ''){ | |
75 | $servicenames{"$Lang::tr{'intrusion detection system'} (ORANGE)"} = "snort_$netsettings{'ORANGE_DEV'}"; | |
76 | } | |
77 | if ($netsettings{'BLUE_DEV'} ne ''){ | |
78 | $servicenames{"$Lang::tr{'intrusion detection system'} (BLUE)"} = "snort_$netsettings{'BLUE_DEV'}"; | |
79 | } | |
80 | ||
81 | my @querry = split(/\?/,$ENV{'QUERY_STRING'}); | |
82 | $querry[0] = '' unless defined $querry[0]; | |
83 | $querry[1] = 'hour' unless defined $querry[1]; | |
84 | ||
85 | if ( $querry[0] =~ "processescpu"){ | |
86 | print "Content-type: image/png\n\n"; | |
87 | binmode(STDOUT); | |
88 | &Graphs::updateprocessescpugraph($querry[1]); | |
89 | }elsif ( $querry[0] =~ "processesmemory"){ | |
90 | print "Content-type: image/png\n\n"; | |
91 | binmode(STDOUT); | |
92 | &Graphs::updateprocessesmemorygraph($querry[1]); | |
93 | }else{ | |
94 | &Header::showhttpheaders(); | |
95 | &Header::openpage($Lang::tr{'status information'}, 1, ''); | |
96 | &Header::openbigbox('100%', 'left'); | |
97 | ||
98 | &Header::openbox('100%', 'left', $Lang::tr{'services'}); | |
99 | print <<END | |
100 | <div align='center'> | |
101 | <table width='80%' cellspacing='1' border='0'> | |
102 | <tr bgcolor='$color{'color20'}'><td align='left'><b>$Lang::tr{'services'}</b></td><td align='center' ><b>$Lang::tr{'status'}</b></td><td align='center'><b>PID</b></td><td align='center'><b>$Lang::tr{'memory'}</b></td></tr> | |
103 | END | |
104 | ; | |
105 | my $key = ''; | |
106 | foreach $key (sort keys %servicenames){ | |
107 | $lines++; | |
108 | if ($lines % 2){ | |
109 | print "<tr bgcolor='$color{'color22'}'>\n<td align='left'>$key</td>\n"; | |
110 | }else{ | |
111 | print "<tr bgcolor='$color{'color20'}'>\n<td align='left'>$key</td>\n"; | |
112 | } | |
113 | ||
114 | my $shortname = $servicenames{$key}; | |
115 | my $status = &isrunning($shortname); | |
116 | ||
117 | print "$status\n"; | |
118 | print "</tr>\n"; | |
119 | } | |
120 | ||
121 | print "</table></div>\n"; | |
122 | &Header::closebox(); | |
123 | ||
124 | &Header::openbox('100%', 'left', "Addon - $Lang::tr{services}"); | |
125 | my $paramstr=$ENV{QUERY_STRING}; | |
126 | my @param=split(/!/, $paramstr); | |
127 | if ($param[1] ne ''){ | |
128 | system("/usr/local/bin/addonctrl @param[0] @param[1] > /dev/null 2>&1"); | |
129 | } | |
130 | ||
131 | print <<END | |
132 | <div align='center'> | |
133 | <table width='80%' cellspacing='1' border='0'> | |
134 | <tr bgcolor='$color{'color20'}'> | |
135 | <td align='center'><b>Addon</b></td> | |
136 | <td align='center'><b>Boot</b></td> | |
137 | <td align='center' colspan=2><b>$Lang::tr{'action'}</b></td> | |
138 | <td align='center'><b>$Lang::tr{'status'}</b></td> | |
139 | <td align='center'><b>PID</b></td> | |
140 | <td align='center'><b>$Lang::tr{'memory'}</b></td> | |
141 | </tr> | |
142 | END | |
143 | ; | |
144 | ||
145 | my $lines=0; # Used to count the outputlines to make different bgcolor | |
146 | ||
147 | # Generate list of installed addon pak's | |
148 | my @pak = `find /opt/pakfire/db/installed/meta-* 2>/dev/null | cut -d"-" -f2`; | |
149 | foreach (@pak){ | |
150 | chomp($_); | |
151 | ||
152 | # Check which of the paks are services | |
153 | my @svc = `find /etc/init.d/$_ 2>/dev/null | cut -d"/" -f4`; | |
154 | foreach (@svc){ | |
155 | # blacklist some packages | |
156 | # | |
157 | # alsa has trouble with the volume saving and was not really stopped | |
158 | # | |
159 | chomp($_); | |
160 | if ($_ ne "alsa"){ | |
161 | $lines++; | |
162 | if ($lines % 2){ | |
163 | print "<tr bgcolor='$color{'color22'}'>"; | |
164 | }else{ | |
165 | print "<tr bgcolor='$color{'color20'}'>"; | |
166 | } | |
167 | print "<td align='left'>$_</td> "; | |
168 | my $status = isautorun($_); | |
169 | print "$status "; | |
170 | print "<td align='center'><A HREF=services.cgi?$_!start><img alt='$Lang::tr{'start'}' title='$Lang::tr{'start'}' src='/images/go-up.png' border='0' /></A></td>"; | |
171 | print "<td align='center'><A HREF=services.cgi?$_!stop><img alt='$Lang::tr{'stop'}' title='$Lang::tr{'stop'}' src='/images/go-down.png' border='0' /></A></td> "; | |
172 | my $status = &isrunningaddon($_); | |
173 | $status =~ s/\\e\[[0-1]\;[0-9]+m//g; | |
174 | ||
175 | chomp($status); | |
176 | print "$status"; | |
177 | print "</tr>"; | |
178 | } | |
179 | } | |
180 | } | |
181 | ||
182 | print "</table></div>\n"; | |
183 | &Header::closebox(); | |
184 | ||
185 | &Header::openbox('100%', 'center', "$Lang::tr{'processes'} $Lang::tr{'graph'}"); | |
186 | &Graphs::makegraphbox("services.cgi","processescpu","day"); | |
187 | &Header::closebox(); | |
188 | ||
189 | &Header::openbox('100%', 'center', "$Lang::tr{'processes'} $Lang::tr{'memory'} $Lang::tr{'graph'}"); | |
190 | &Graphs::makegraphbox("services.cgi","processesmemory","day"); | |
191 | &Header::closebox(); | |
192 | ||
193 | &Header::closebigbox(); | |
194 | &Header::closepage(); | |
195 | } | |
196 | ||
197 | sub isautorun{ | |
198 | my $cmd = $_[0]; | |
199 | my $status = "<td align='center'></td>"; | |
200 | my $init = `find /etc/rc.d/rc3.d/S??${cmd} 2>/dev/null`; | |
201 | chomp ($init); | |
202 | if ($init ne ''){ | |
203 | $status = "<td align='center'><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>"; | |
204 | } | |
205 | $init = `find /etc/rc.d/rc3.d/off/S??${cmd} 2>/dev/null`; | |
206 | chomp ($init); | |
207 | if ($init ne ''){ | |
208 | $status = "<td align='center'><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>"; | |
209 | } | |
210 | ||
211 | return $status; | |
212 | } | |
213 | ||
214 | sub isrunning{ | |
215 | my $cmd = $_[0]; | |
216 | my $status = "<td align='center' bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td><td colspan='2'></td>"; | |
217 | my $pid = ''; | |
218 | my $testcmd = ''; | |
219 | my $exename; | |
220 | my @memory; | |
221 | ||
222 | $cmd =~ /(^[a-z]+)/; | |
223 | $exename = $1; | |
224 | ||
225 | if (open(FILE, "/var/run/${cmd}.pid")){ | |
226 | $pid = <FILE>; chomp $pid; | |
227 | close FILE; | |
228 | if (open(FILE, "/proc/${pid}/status")){ | |
229 | while (<FILE>){ | |
230 | if (/^Name:\W+(.*)/) { | |
231 | $testcmd = $1; | |
232 | } | |
233 | } | |
234 | close FILE; | |
235 | } | |
236 | if (open(FILE, "/proc/${pid}/statm")){ | |
237 | my $temp = <FILE>; | |
238 | @memory = split(/ /,$temp); | |
239 | } | |
240 | close FILE; | |
241 | if ($testcmd =~ /$exename/){ | |
242 | $status = "<td align='center' bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td><td align='center'>$pid</td><td align='center'>$memory[0] KB</td>"; | |
243 | } | |
244 | } | |
245 | return $status; | |
246 | } | |
247 | ||
248 | sub isrunningaddon{ | |
249 | my $cmd = $_[0]; | |
250 | my $status = "<td align='center' bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td><td colspan='2'></td>"; | |
251 | my $pid = ''; | |
252 | my $testcmd = ''; | |
253 | my $exename; | |
254 | my @memory; | |
255 | ||
256 | my $testcmd = `/usr/local/bin/addonctrl $_ status`; | |
257 | ||
258 | if ( $testcmd =~ /is\ running/ && $testcmd !~ /is\ not\ running/){ | |
259 | $status = "<td align='center' bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>"; | |
260 | $testcmd =~ s/[a-z_]//gi; | |
261 | $testcmd =~ s/\[[0-1]\;[0-9]+//gi; | |
262 | $testcmd =~ s/[\(\)\.]//gi; | |
263 | $testcmd =~ s/ //gi; | |
264 | $testcmd =~ s/\e//gi; | |
265 | ||
266 | my @pid = split(/\s/,$testcmd); | |
267 | $status .="<td align='center'>$pid[0]</td>"; | |
268 | ||
269 | my $memory = 0; | |
270 | ||
271 | foreach (@pid){ | |
272 | chomp($_); | |
273 | if (open(FILE, "/proc/$_/statm")){ | |
274 | my $temp = <FILE>; | |
275 | @memory = split(/ /,$temp); | |
276 | } | |
277 | $memory+=$memory[0]; | |
278 | } | |
279 | $status .="<td align='center'>$memory KB</td>"; | |
280 | }else{ | |
281 | $status = "<td align='center' bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td><td colspan='2'></td>"; | |
282 | } | |
283 | return $status; | |
284 | } |