]>
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"; | |
350b52c5 | 20 | require "${General::swroot}/graphs.pl"; |
72fe12a9 MT |
21 | |
22 | #workaround to suppress a warning when a variable is used only once | |
23 | my @dummy = ( ${Header::colourred} ); | |
24 | undef (@dummy); | |
25 | ||
26 | my %netsettings=(); | |
27 | &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); | |
28 | ||
f2fdd0c1 CS |
29 | my %color = (); |
30 | my %mainsettings = (); | |
31 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
32 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
33 | ||
72fe12a9 MT |
34 | my %cgiparams=(); |
35 | # Maps a nice printable name to the changing part of the pid file, which | |
36 | # is also the name of the program | |
37 | my %servicenames = | |
38 | ( | |
39 | $Lang::tr{'dhcp server'} => 'dhcpd', | |
40 | $Lang::tr{'web server'} => 'httpd', | |
41 | $Lang::tr{'cron server'} => 'fcron', | |
42 | $Lang::tr{'dns proxy server'} => 'dnsmasq', | |
43 | $Lang::tr{'logging server'} => 'syslogd', | |
44 | $Lang::tr{'kernel logging server'} => 'klogd', | |
45 | $Lang::tr{'ntp server'} => 'ntpd', | |
46 | $Lang::tr{'secure shell server'} => 'sshd', | |
47 | $Lang::tr{'vpn'} => 'pluto', | |
48 | $Lang::tr{'web proxy'} => 'squid', | |
49 | 'OpenVPN' => 'openvpn' | |
50 | ); | |
51 | ||
52 | my $iface = ''; | |
53 | if (open(FILE, "${General::swroot}/red/iface")) | |
54 | { | |
55 | $iface = <FILE>; | |
56 | close FILE; | |
57 | chomp $iface; | |
58 | } | |
59 | $servicenames{"$Lang::tr{'intrusion detection system'} (RED)"} = "snort_${iface}"; | |
60 | $servicenames{"$Lang::tr{'intrusion detection system'} (GREEN)"} = "snort_$netsettings{'GREEN_DEV'}"; | |
61 | if ($netsettings{'ORANGE_DEV'} ne '') { | |
62 | $servicenames{"$Lang::tr{'intrusion detection system'} (ORANGE)"} = "snort_$netsettings{'ORANGE_DEV'}"; | |
63 | } | |
64 | if ($netsettings{'BLUE_DEV'} ne '') { | |
65 | $servicenames{"$Lang::tr{'intrusion detection system'} (BLUE)"} = "snort_$netsettings{'BLUE_DEV'}"; | |
66 | } | |
67 | ||
350b52c5 CS |
68 | # Generate Graphs from rrd Data |
69 | &Graphs::updatecpugraph ("day"); | |
70 | &Graphs::updatecpugraph ("week"); | |
71 | &Graphs::updatecpugraph ("month"); | |
72 | &Graphs::updatecpugraph ("year"); | |
73 | &Graphs::updateloadgraph ("day"); | |
74 | &Graphs::updateloadgraph ("week"); | |
75 | &Graphs::updateloadgraph ("month"); | |
76 | &Graphs::updateloadgraph ("year"); | |
72fe12a9 | 77 | |
350b52c5 | 78 | &Header::showhttpheaders(); |
72fe12a9 | 79 | &Header::getcgihash(\%cgiparams); |
72fe12a9 | 80 | &Header::openpage($Lang::tr{'status information'}, 1, ''); |
72fe12a9 MT |
81 | &Header::openbigbox('100%', 'left'); |
82 | ||
83 | &Header::openbox('100%', 'center', "CPU $Lang::tr{'graph'}"); | |
84 | if (-e "$Header::graphdir/cpu-day.png") { | |
85 | my $ftime = localtime((stat("$Header::graphdir/cpu-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=cpu'>"; | |
88 | print "<img alt='' src='/graphs/cpu-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%', 'center', "Load $Lang::tr{'graph'}"); | |
97 | if (-e "$Header::graphdir/load-day.png") { | |
98 | my $ftime = localtime((stat("$Header::graphdir/load-day.png"))[9]); | |
99 | print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n"; | |
100 | print "<a href='/cgi-bin/graphs.cgi?graph=load'>"; | |
101 | print "<img alt='' src='/graphs/load-day.png' border='0' />"; | |
102 | print "</a>"; | |
103 | } else { | |
104 | print $Lang::tr{'no information available'}; | |
105 | } | |
106 | print "<br />\n"; | |
107 | &Header::closebox(); | |
108 | ||
109 | &Header::openbox('100%', 'left', $Lang::tr{'services'}); | |
110 | ||
111 | print <<END | |
112 | <div align='center'> | |
113 | <table width='60%' cellspacing='0' border='0'> | |
114 | END | |
115 | ; | |
116 | ||
72fe12a9 MT |
117 | my $key = ''; |
118 | foreach $key (sort keys %servicenames) | |
119 | { | |
f2fdd0c1 | 120 | print "<tr>\n<td align='left'>$key</td>\n"; |
72fe12a9 MT |
121 | my $shortname = $servicenames{$key}; |
122 | my $status = &isrunning($shortname); | |
123 | print "$status\n"; | |
124 | print "</tr>\n"; | |
72fe12a9 MT |
125 | } |
126 | ||
127 | ||
128 | print "</table></div>\n"; | |
129 | ||
130 | &Header::closebox(); | |
72fe12a9 | 131 | &Header::closebigbox(); |
72fe12a9 MT |
132 | &Header::closepage(); |
133 | ||
134 | sub isrunning | |
135 | { | |
136 | my $cmd = $_[0]; | |
137 | my $status = "<td bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>"; | |
138 | my $pid = ''; | |
139 | my $testcmd = ''; | |
140 | my $exename; | |
141 | ||
142 | $cmd =~ /(^[a-z]+)/; | |
143 | $exename = $1; | |
144 | ||
145 | if (open(FILE, "/var/run/${cmd}.pid")) | |
146 | { | |
147 | $pid = <FILE>; chomp $pid; | |
148 | close FILE; | |
149 | if (open(FILE, "/proc/${pid}/status")) | |
150 | { | |
151 | while (<FILE>) | |
152 | { | |
153 | if (/^Name:\W+(.*)/) { | |
154 | $testcmd = $1; } | |
155 | } | |
156 | close FILE; | |
157 | if ($testcmd =~ /$exename/) | |
158 | { | |
159 | $status = "<td bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>"; | |
160 | } | |
161 | } | |
162 | } | |
163 | ||
164 | return $status; | |
165 | } | |
166 | ||
167 | sub percentbar | |
168 | { | |
169 | my $percent = $_[0]; | |
170 | my $fg = '#a0a0a0'; | |
171 | my $bg = '#e2e2e2'; | |
172 | ||
173 | if ($percent =~ m/^(\d+)%$/ ) | |
174 | { | |
175 | print <<END | |
176 | <table width='100' border='1' cellspacing='0' cellpadding='0' style='border-width:1px;border-style:solid;border-color:$fg;width:100px;height:10px;'> | |
177 | <tr> | |
178 | END | |
179 | ; | |
180 | if ($percent eq "100%") { | |
181 | print "<td width='100%' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'>" | |
182 | } elsif ($percent eq "0%") { | |
183 | print "<td width='100%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>" | |
184 | } else { | |
185 | 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'>" | |
186 | } | |
187 | print <<END | |
188 | <img src='/images/null.gif' width='1' height='1' alt='' /></td></tr></table> | |
189 | END | |
190 | ; | |
191 | } | |
192 | } |