]>
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(); | |
72fe12a9 | 124 | &Header::closebigbox(); |
72fe12a9 MT |
125 | &Header::closepage(); |
126 | ||
127 | sub isrunning | |
128 | { | |
129 | my $cmd = $_[0]; | |
130 | my $status = "<td bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>"; | |
131 | my $pid = ''; | |
132 | my $testcmd = ''; | |
133 | my $exename; | |
134 | ||
135 | $cmd =~ /(^[a-z]+)/; | |
136 | $exename = $1; | |
137 | ||
138 | if (open(FILE, "/var/run/${cmd}.pid")) | |
139 | { | |
140 | $pid = <FILE>; chomp $pid; | |
141 | close FILE; | |
142 | if (open(FILE, "/proc/${pid}/status")) | |
143 | { | |
144 | while (<FILE>) | |
145 | { | |
146 | if (/^Name:\W+(.*)/) { | |
147 | $testcmd = $1; } | |
148 | } | |
149 | close FILE; | |
150 | if ($testcmd =~ /$exename/) | |
151 | { | |
152 | $status = "<td bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>"; | |
153 | } | |
154 | } | |
155 | } | |
156 | ||
157 | return $status; | |
158 | } | |
159 | ||
160 | sub percentbar | |
161 | { | |
162 | my $percent = $_[0]; | |
163 | my $fg = '#a0a0a0'; | |
164 | my $bg = '#e2e2e2'; | |
165 | ||
166 | if ($percent =~ m/^(\d+)%$/ ) | |
167 | { | |
168 | print <<END | |
169 | <table width='100' border='1' cellspacing='0' cellpadding='0' style='border-width:1px;border-style:solid;border-color:$fg;width:100px;height:10px;'> | |
170 | <tr> | |
171 | END | |
172 | ; | |
173 | if ($percent eq "100%") { | |
174 | print "<td width='100%' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'>" | |
175 | } elsif ($percent eq "0%") { | |
176 | print "<td width='100%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>" | |
177 | } else { | |
178 | 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'>" | |
179 | } | |
180 | print <<END | |
181 | <img src='/images/null.gif' width='1' height='1' alt='' /></td></tr></table> | |
182 | END | |
183 | ; | |
184 | } | |
185 | } |