]>
Commit | Line | Data |
---|---|---|
ac1cfefa 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 | # | |
ac1cfefa MT |
9 | |
10 | use strict; | |
11 | ||
12 | # enable only the following on debugging purpose | |
13 | #use warnings; | |
14 | #use CGI::Carp 'fatalsToBrowser'; | |
15 | ||
e383179b | 16 | require '/var/ipfire/general-functions.pl'; |
ac1cfefa MT |
17 | require "${General::swroot}/lang.pl"; |
18 | require "${General::swroot}/header.pl"; | |
19 | ||
20 | my %cgiparams=(); | |
21 | my %pppsettings=(); | |
22 | my %modemsettings=(); | |
23 | my %netsettings=(); | |
24 | my %ddnssettings=(); | |
25 | my $warnmessage = ''; | |
26 | my $refresh = ''; | |
e383179b | 27 | my $ipaddr=''; |
ac1cfefa MT |
28 | |
29 | &Header::showhttpheaders(); | |
30 | ||
31 | $cgiparams{'ACTION'} = ''; | |
32 | &Header::getcgihash(\%cgiparams); | |
33 | $pppsettings{'VALID'} = ''; | |
34 | $pppsettings{'PROFILENAME'} = 'None'; | |
35 | &General::readhash("${General::swroot}/ppp/settings", \%pppsettings); | |
36 | &General::readhash("${General::swroot}/modem/settings", \%modemsettings); | |
37 | &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); | |
38 | &General::readhash("${General::swroot}/ddns/settings", \%ddnssettings); | |
39 | ||
40 | my $connstate = &Header::connectionstatus(); | |
41 | if ($connstate =~ /$Lang::tr{'dod waiting'}/ || -e "${General::swroot}/main/refreshindex") { | |
42 | $refresh = "<meta http-equiv='refresh' content='30;'>"; | |
43 | } elsif ($connstate =~ /$Lang::tr{'connecting'}/) { | |
44 | $refresh = "<meta http-equiv='refresh' content='5;'>"; | |
45 | } | |
46 | ||
e383179b MT |
47 | my $c; |
48 | my $maxprofiles = 5; | |
49 | my @profilenames = (); | |
50 | ||
51 | for ($c = 1; $c <= $maxprofiles; $c++) | |
52 | { | |
53 | my %temppppsettings = (); | |
54 | $temppppsettings{'PROFILENAME'} = ''; | |
55 | &General::readhash("${General::swroot}/ppp/settings-$c", \%temppppsettings); | |
56 | $profilenames[$c] = $temppppsettings{'PROFILENAME'}; | |
57 | } | |
58 | my %selected; | |
59 | for ($c = 1; $c <= $maxprofiles; $c++) { | |
60 | $selected{'PROFILE'}{$c} = ''; | |
61 | } | |
62 | $selected{'PROFILE'}{$pppsettings{'PROFILE'}} = "selected='selected'"; | |
63 | my $dialButtonDisabled = "disabled='disabled'"; | |
64 | ||
65 | ||
ac1cfefa MT |
66 | &Header::openpage($Lang::tr{'main page'}, 1, $refresh); |
67 | &Header::openbigbox('', 'center'); | |
68 | &Header::openbox('100%', 'center', &Header::cleanhtml(`/bin/uname -n`,"y")); | |
69 | ||
e383179b | 70 | if ( ( $pppsettings{'VALID'} eq 'yes'&& $modemsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ )) { |
ac1cfefa | 71 | if ($connstate =~ /$Lang::tr{'connected'}/) { |
ac1cfefa MT |
72 | if ($ddnssettings{'BEHINDROUTER'} eq 'FETCH_IP') { |
73 | if (open(IPADDR,"${General::swroot}/ddns/ipcache")) { | |
e383179b | 74 | $ipaddr = <IPADDR>; |
ac1cfefa | 75 | close IPADDR; |
e383179b | 76 | chomp ($ipaddr); |
ac1cfefa MT |
77 | } |
78 | } | |
79 | if (open(IPADDR,"${General::swroot}/red/local-ipaddress")) { | |
80 | my $ipaddr = <IPADDR>; | |
81 | close IPADDR; | |
82 | chomp ($ipaddr); | |
ac1cfefa MT |
83 | } |
84 | } | |
ac1cfefa MT |
85 | } elsif ($modemsettings{'VALID'} eq 'no') { |
86 | print "$Lang::tr{'modem settings have errors'}\n </b></font>\n"; | |
87 | } else { | |
88 | print "$Lang::tr{'profile has errors'}\n </b></font>\n"; | |
89 | } | |
90 | ||
e383179b MT |
91 | if ( $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) { |
92 | $ipaddr = $netsettings{'RED_ADDRESS'}; | |
93 | } | |
94 | ||
95 | print <<END; | |
96 | <table border='0'> | |
97 | <tr> | |
98 | <td align='center'><form method='post' action="$ENV{'SCRIPT_NAME'}"> | |
99 | <input type='submit' name='ACTION' value='$Lang::tr{'refresh'}' /> | |
100 | </form></td> | |
101 | </tr></table> | |
102 | ||
103 | <!-- Table of networks --> | |
104 | <table border='0' width=80%> | |
105 | <!-- Headline --> | |
106 | <tr> <th bgcolor='lightgrey'>$Lang::tr{'network'} | |
107 | <th bgcolor='lightgrey'>IP | |
108 | <th bgcolor='lightgrey'>$Lang::tr{'status'} | |
109 | <!-- RED --> | |
110 | <tr> <td bgcolor='$Header::colourred' width='25%'><font size='2' color='white'><b>$Lang::tr{'internet'}:</b></font><br> | |
111 | <td width='30%'>$ipaddr <td width='45%'>$connstate | |
112 | <tr><td colspan='2'> | |
113 | <form method='post' action='/cgi-bin/dial.cgi'>$Lang::tr{'profile'}: | |
114 | <select name='PROFILE'> | |
115 | END | |
116 | for ($c = 1; $c <= $maxprofiles; $c++) | |
117 | { | |
118 | if ($profilenames[$c] ne '') { | |
119 | $dialButtonDisabled = ""; | |
120 | print "\t<option value='$c' $selected{'PROFILE'}{$c}>$c. $profilenames[$c]</option>\n"; | |
121 | } | |
122 | } | |
123 | $dialButtonDisabled = "disabled='disabled'" if (-e '/var/run/ppp-ipcop.pid' || -e "${General::swroot}/red/active"); | |
124 | if ( ( $pppsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) { | |
125 | print <<END; | |
126 | </select> | |
127 | <input type='submit' name='ACTION' value='$Lang::tr{'dial profile'}' $dialButtonDisabled /> | |
128 | </form> | |
129 | <td align='center'> | |
130 | <table width='100%' border='0'> | |
131 | <tr> | |
132 | <td width='50%' align='right'> <form method='post' action='/cgi-bin/dial.cgi'> | |
133 | <input type='submit' name='ACTION' value='$Lang::tr{'dial'}'> | |
134 | </form> | |
135 | <td width='50%' align='left'> <form method='post' action='/cgi-bin/dial.cgi'> | |
136 | <input type='submit' name='ACTION' value='$Lang::tr{'hangup'}'> | |
137 | </form> | |
138 | </table> | |
139 | END | |
140 | } else { | |
141 | print "$Lang::tr{'profile has errors'}\n </b></font>\n"; | |
142 | } | |
143 | ||
144 | print <<END; | |
145 | <!-- Green --> | |
146 | <tr><td bgcolor='$Header::colourgreen' width='25%'> | |
147 | <font size='2' color='white'><b>$Lang::tr{'lan'}:</b></font> | |
148 | <td width='30%'>$netsettings{'GREEN_ADDRESS'} | |
149 | <td width='45%'> | |
150 | END | |
151 | if (`ifconfig | grep $netsettings{'GREEN_DEV'}`) { print "<font color=$Header::colourgreen>Online</font>"; } else { print "<font color=$Header::colourred>Offline</font>"; } | |
152 | print <<END; | |
153 | <!-- BLUE --> | |
154 | <tr><td bgcolor='$Header::colourblue' width='25%'><font size='2' color='white'><b>$Lang::tr{'wireless'}:</b></font><br> | |
155 | <td width='30%'>$netsettings{'BLUE_ADDRESS'} | |
156 | <td width='45%'> | |
157 | END | |
158 | if (`ifconfig | grep $netsettings{'BLUE_DEV'}`) { print "<font color=$Header::colourgreen>Online</font>"; } else { print "<font color=$Header::colourred>Offline</font>"; } | |
159 | print <<END; | |
160 | <tr><td bgcolor='$Header::colourorange' width='25%'><font size='2' color='white'><b>$Lang::tr{'dmz'}:</b></font><br> | |
161 | <td width='30%'>$netsettings{'ORANGE_ADDRESS'} | |
162 | <td width='45%'> | |
163 | END | |
164 | if (`ifconfig | grep $netsettings{'ORANGE_DEV'}`) { print "<font color=$Header::colourgreen>Online</font>"; } else { print "<font color=$Header::colourred>Offline</font>"; } | |
165 | print <<END; | |
166 | <tr><td bgcolor='$Header::colourvpn' width='25%'><font size='2' color='white'><b>$Lang::tr{'vpn'}:</b></font><br> | |
167 | <td width='30%'>N/A | |
168 | <td width='45%'> | |
169 | END | |
170 | if (`ifconfig | grep ipsec0`) { print "<font color=$Header::colourgreen>Online</font>"; } else { print "<font color=$Header::colourred>Offline</font>"; } | |
171 | print <<END; | |
172 | <tr><td bgcolor='$Header::colourovpn' width='25%'><font size='2' color='white'><b>OpenVPN:</b></font><br> | |
173 | <td width='30%'>N/A | |
174 | <td width='45%'> | |
175 | END | |
176 | if (`ifconfig | grep tun0`) { print "<font color=$Header::colourgreen>Online</font>"; } else { print "<font color=$Header::colourred>Offline</font>"; } | |
177 | print <<END; | |
178 | </table> | |
179 | END | |
ac1cfefa MT |
180 | |
181 | # Memory usage warning | |
182 | my @free = `/usr/bin/free`; | |
183 | $free[1] =~ m/(\d+)/; | |
184 | my $mem = $1; | |
185 | $free[2] =~ m/(\d+)/; | |
186 | my $used = $1; | |
187 | my $pct = int 100 * ($mem - $used) / $mem; | |
188 | if ($used / $mem > 90) { | |
189 | $warnmessage .= "<li> $Lang::tr{'high memory usage'}: $pct% !</li>\n"; | |
190 | } | |
191 | ||
192 | # Diskspace usage warning | |
193 | my @temp=(); | |
194 | my $temp2=(); | |
195 | my @df = `/bin/df -B M -x rootfs`; | |
196 | foreach my $line (@df) { | |
197 | next if $line =~ m/^Filesystem/; | |
198 | if ($line =~ m/root/ ) { | |
199 | $line =~ m/^.* (\d+)M.*$/; | |
200 | @temp = split(/ +/,$line); | |
201 | if ($1<5) { | |
202 | # available:plain value in MB, and not %used as 10% is too much to waste on small disk | |
203 | # and root size should not vary during time | |
204 | $warnmessage .= "<li> $Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$1M</b> !</li>\n"; | |
205 | } | |
206 | ||
207 | } else { | |
208 | # $line =~ m/^.* (\d+)m.*$/; | |
209 | $line =~ m/^.* (\d+)\%.*$/; | |
210 | if ($1>90) { | |
211 | @temp = split(/ /,$line); | |
212 | $temp2=int(100-$1); | |
213 | $warnmessage .= "<li> $Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$temp2%</b> !</li>\n"; | |
214 | } | |
215 | } | |
216 | } | |
217 | ||
218 | # Patches warning | |
219 | open(AV, "<${General::swroot}/patches/available") or die "Could not open available patches database ($!)"; | |
220 | my @av = <AV>; | |
221 | close(AV); | |
222 | open(PF, "<${General::swroot}/patches/installed") or die "Could not open installed patches file. ($!)<br />"; | |
223 | while(<PF>) | |
224 | { | |
225 | next if $_ =~ m/^#/; | |
226 | @temp = split(/\|/,$_); | |
227 | @av = grep(!/^$temp[0]/, @av); | |
228 | } | |
229 | close(PF); | |
230 | ||
231 | if ($#av != -1) | |
232 | { | |
233 | $warnmessage .= "<li> $Lang::tr{'there are updates'}</li>"; | |
234 | } | |
235 | my $age = &General::age("/${General::swroot}/patches/available"); | |
236 | if ($age =~ m/(\d{1,3})d/) { | |
237 | if ($1 >= 7) { | |
238 | $warnmessage .= "<li>$Lang::tr{'updates is old1'} $age $Lang::tr{'updates is old2'}</li>\n"; | |
239 | } | |
240 | } | |
241 | ||
242 | if ($warnmessage) { | |
243 | print "<ol>$warnmessage</ol>"; | |
244 | } | |
245 | ||
246 | print "<p>"; | |
247 | system('/usr/bin/uptime'); | |
248 | print "</p>\n"; | |
249 | ||
250 | &Header::closebox(); | |
251 | ||
ac1cfefa MT |
252 | &Header::closebigbox(); |
253 | ||
254 | &Header::closepage(); |