]>
Commit | Line | Data |
---|---|---|
72fe12a9 MT |
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 %cgiparams=(); | |
29 | # Maps a nice printable name to the changing part of the pid file, which | |
30 | # is also the name of the program | |
31 | my %servicenames = | |
32 | ( | |
33 | $Lang::tr{'dhcp server'} => 'dhcpd', | |
34 | $Lang::tr{'web server'} => 'httpd', | |
35 | $Lang::tr{'cron server'} => 'fcron', | |
36 | $Lang::tr{'dns proxy server'} => 'dnsmasq', | |
37 | $Lang::tr{'logging server'} => 'syslogd', | |
38 | $Lang::tr{'kernel logging server'} => 'klogd', | |
39 | $Lang::tr{'ntp server'} => 'ntpd', | |
40 | $Lang::tr{'secure shell server'} => 'sshd', | |
41 | $Lang::tr{'vpn'} => 'pluto', | |
42 | $Lang::tr{'web proxy'} => 'squid', | |
43 | 'OpenVPN' => 'openvpn' | |
44 | ); | |
45 | ||
46 | my $iface = ''; | |
47 | if (open(FILE, "${General::swroot}/red/iface")) | |
48 | { | |
49 | $iface = <FILE>; | |
50 | close FILE; | |
51 | chomp $iface; | |
52 | } | |
53 | $servicenames{"$Lang::tr{'intrusion detection system'} (RED)"} = "snort_${iface}"; | |
54 | $servicenames{"$Lang::tr{'intrusion detection system'} (GREEN)"} = "snort_$netsettings{'GREEN_DEV'}"; | |
55 | if ($netsettings{'ORANGE_DEV'} ne '') { | |
56 | $servicenames{"$Lang::tr{'intrusion detection system'} (ORANGE)"} = "snort_$netsettings{'ORANGE_DEV'}"; | |
57 | } | |
58 | if ($netsettings{'BLUE_DEV'} ne '') { | |
59 | $servicenames{"$Lang::tr{'intrusion detection system'} (BLUE)"} = "snort_$netsettings{'BLUE_DEV'}"; | |
60 | } | |
61 | ||
62 | &Header::showhttpheaders(); | |
63 | ||
64 | &Header::getcgihash(\%cgiparams); | |
65 | ||
66 | &Header::openpage($Lang::tr{'status information'}, 1, ''); | |
67 | ||
68 | &Header::openbigbox('100%', 'left'); | |
69 | ||
70 | &Header::openbox('100%', 'center', "CPU $Lang::tr{'graph'}"); | |
71 | if (-e "$Header::graphdir/cpu-day.png") { | |
72 | my $ftime = localtime((stat("$Header::graphdir/cpu-day.png"))[9]); | |
73 | print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n"; | |
74 | print "<a href='/cgi-bin/graphs.cgi?graph=cpu'>"; | |
75 | print "<img alt='' src='/graphs/cpu-day.png' border='0' />"; | |
76 | print "</a>"; | |
77 | } else { | |
78 | print $Lang::tr{'no information available'}; | |
79 | } | |
80 | print "<br />\n"; | |
81 | &Header::closebox(); | |
82 | ||
83 | &Header::openbox('100%', 'center', "Load $Lang::tr{'graph'}"); | |
84 | if (-e "$Header::graphdir/load-day.png") { | |
85 | my $ftime = localtime((stat("$Header::graphdir/load-day.png"))[9]); | |
86 | print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n"; | |
87 | print "<a href='/cgi-bin/graphs.cgi?graph=load'>"; | |
88 | print "<img alt='' src='/graphs/load-day.png' border='0' />"; | |
89 | print "</a>"; | |
90 | } else { | |
91 | print $Lang::tr{'no information available'}; | |
92 | } | |
93 | print "<br />\n"; | |
94 | &Header::closebox(); | |
95 | ||
96 | &Header::openbox('100%', 'left', $Lang::tr{'services'}); | |
97 | ||
98 | print <<END | |
99 | <div align='center'> | |
100 | <table width='60%' cellspacing='0' border='0'> | |
101 | END | |
102 | ; | |
103 | ||
104 | my $lines = 0; | |
105 | my $key = ''; | |
106 | foreach $key (sort keys %servicenames) | |
107 | { | |
108 | if ($lines % 2) { | |
109 | print "<tr bgcolor='${Header::table1colour}'>\n"; } | |
110 | else { | |
111 | print "<tr bgcolor='${Header::table2colour}'>\n"; } | |
112 | print "<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 | $lines++; | |
118 | } | |
119 | ||
120 | ||
121 | print "</table></div>\n"; | |
122 | ||
123 | &Header::closebox(); | |
124 | ||
125 | &Header::openbox('100%', 'left', $Lang::tr{'loaded modules'}); | |
126 | my $module = qx(/bin/lsmod | awk -F" " '{print \$1}'); | |
127 | my $size = qx(/bin/lsmod | awk -F" " '{print \$2}'); | |
128 | my $used = qx(/bin/lsmod | awk -F" " '{print \$3}'); | |
129 | my @usedby = qx(/bin/lsmod | awk -F" " '{print \$4}'); | |
130 | my @usedbyf; | |
131 | my $usedbyline; | |
132 | ||
133 | foreach $usedbyline(@usedby) | |
134 | { | |
135 | my $laenge = length($usedbyline); | |
136 | ||
137 | if ( $laenge > 30) | |
138 | { | |
139 | my $usedbylinef=substr($usedbyline,0,30); | |
140 | $usedbyline="$usedbylinef ...\n"; | |
141 | push(@usedbyf,$usedbyline); | |
142 | } | |
143 | else | |
144 | {push(@usedbyf,$usedbyline);} | |
145 | } | |
146 | print <<END | |
147 | <table cellspacing=25><tr> | |
148 | <td><pre>$module</pre></td> | |
149 | <td><pre>$size</pre></td> | |
150 | <td><pre>$used</pre></td> | |
151 | <td><pre>@usedbyf</pre></td> | |
152 | </tr></table> | |
153 | END | |
154 | ; | |
155 | ||
156 | print ""; | |
157 | &Header::closebox(); | |
158 | ||
159 | &Header::closebigbox(); | |
160 | ||
161 | &Header::closepage(); | |
162 | ||
163 | sub isrunning | |
164 | { | |
165 | my $cmd = $_[0]; | |
166 | my $status = "<td bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>"; | |
167 | my $pid = ''; | |
168 | my $testcmd = ''; | |
169 | my $exename; | |
170 | ||
171 | $cmd =~ /(^[a-z]+)/; | |
172 | $exename = $1; | |
173 | ||
174 | if (open(FILE, "/var/run/${cmd}.pid")) | |
175 | { | |
176 | $pid = <FILE>; chomp $pid; | |
177 | close FILE; | |
178 | if (open(FILE, "/proc/${pid}/status")) | |
179 | { | |
180 | while (<FILE>) | |
181 | { | |
182 | if (/^Name:\W+(.*)/) { | |
183 | $testcmd = $1; } | |
184 | } | |
185 | close FILE; | |
186 | if ($testcmd =~ /$exename/) | |
187 | { | |
188 | $status = "<td bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>"; | |
189 | } | |
190 | } | |
191 | } | |
192 | ||
193 | return $status; | |
194 | } | |
195 | ||
196 | sub percentbar | |
197 | { | |
198 | my $percent = $_[0]; | |
199 | my $fg = '#a0a0a0'; | |
200 | my $bg = '#e2e2e2'; | |
201 | ||
202 | if ($percent =~ m/^(\d+)%$/ ) | |
203 | { | |
204 | print <<END | |
205 | <table width='100' border='1' cellspacing='0' cellpadding='0' style='border-width:1px;border-style:solid;border-color:$fg;width:100px;height:10px;'> | |
206 | <tr> | |
207 | END | |
208 | ; | |
209 | if ($percent eq "100%") { | |
210 | print "<td width='100%' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'>" | |
211 | } elsif ($percent eq "0%") { | |
212 | print "<td width='100%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>" | |
213 | } else { | |
214 | 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'>" | |
215 | } | |
216 | print <<END | |
217 | <img src='/images/null.gif' width='1' height='1' alt='' /></td></tr></table> | |
218 | END | |
219 | ; | |
220 | } | |
221 | } |