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