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