]>
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 | ||
986e08d9 MT |
70 | if ( ( $pppsettings{'VALID'} eq 'yes' && $modemsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ )) { |
71 | if (open(IPADDR,"${General::swroot}/ddns/ipcache")) { | |
72 | $ipaddr = <IPADDR>; | |
73 | close IPADDR; | |
74 | chomp ($ipaddr); | |
75 | } | |
76 | if (open(IPADDR,"${General::swroot}/red/local-ipaddress")) { | |
77 | my $ipaddr = <IPADDR>; | |
78 | close IPADDR; | |
79 | chomp ($ipaddr); | |
80 | } | |
ac1cfefa MT |
81 | } elsif ($modemsettings{'VALID'} eq 'no') { |
82 | print "$Lang::tr{'modem settings have errors'}\n </b></font>\n"; | |
83 | } else { | |
84 | print "$Lang::tr{'profile has errors'}\n </b></font>\n"; | |
85 | } | |
86 | ||
e383179b MT |
87 | if ( $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) { |
88 | $ipaddr = $netsettings{'RED_ADDRESS'}; | |
89 | } | |
90 | ||
91 | print <<END; | |
92 | <table border='0'> | |
93 | <tr> | |
94 | <td align='center'><form method='post' action="$ENV{'SCRIPT_NAME'}"> | |
95 | <input type='submit' name='ACTION' value='$Lang::tr{'refresh'}' /> | |
96 | </form></td> | |
97 | </tr></table> | |
98 | ||
99 | <!-- Table of networks --> | |
100 | <table border='0' width=80%> | |
e383179b MT |
101 | <tr> <th bgcolor='lightgrey'>$Lang::tr{'network'} |
102 | <th bgcolor='lightgrey'>IP | |
103 | <th bgcolor='lightgrey'>$Lang::tr{'status'} | |
e383179b | 104 | <tr> <td bgcolor='$Header::colourred' width='25%'><font size='2' color='white'><b>$Lang::tr{'internet'}:</b></font><br> |
39a7cc11 MT |
105 | <td width='30%'>$ipaddr |
106 | <td width='45%'>$connstate | |
e383179b MT |
107 | <tr><td colspan='2'> |
108 | <form method='post' action='/cgi-bin/dial.cgi'>$Lang::tr{'profile'}: | |
109 | <select name='PROFILE'> | |
110 | END | |
111 | for ($c = 1; $c <= $maxprofiles; $c++) | |
112 | { | |
113 | if ($profilenames[$c] ne '') { | |
114 | $dialButtonDisabled = ""; | |
115 | print "\t<option value='$c' $selected{'PROFILE'}{$c}>$c. $profilenames[$c]</option>\n"; | |
116 | } | |
117 | } | |
118 | $dialButtonDisabled = "disabled='disabled'" if (-e '/var/run/ppp-ipcop.pid' || -e "${General::swroot}/red/active"); | |
119 | if ( ( $pppsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) { | |
120 | print <<END; | |
121 | </select> | |
122 | <input type='submit' name='ACTION' value='$Lang::tr{'dial profile'}' $dialButtonDisabled /> | |
123 | </form> | |
124 | <td align='center'> | |
125 | <table width='100%' border='0'> | |
126 | <tr> | |
127 | <td width='50%' align='right'> <form method='post' action='/cgi-bin/dial.cgi'> | |
128 | <input type='submit' name='ACTION' value='$Lang::tr{'dial'}'> | |
129 | </form> | |
130 | <td width='50%' align='left'> <form method='post' action='/cgi-bin/dial.cgi'> | |
131 | <input type='submit' name='ACTION' value='$Lang::tr{'hangup'}'> | |
132 | </form> | |
133 | </table> | |
134 | END | |
135 | } else { | |
136 | print "$Lang::tr{'profile has errors'}\n </b></font>\n"; | |
137 | } | |
138 | ||
072cd997 MT |
139 | if ( $netsettings{'GREEN_DEV'} ) { print <<END; |
140 | <tr><td bgcolor='$Header::colourgreen' width='25%'><font size='2' color='white'><b>$Lang::tr{'lan'}:</b></font> | |
141 | <td width='30%'>$netsettings{'GREEN_ADDRESS'} | |
142 | <td width='45%'> | |
e383179b | 143 | END |
072cd997 MT |
144 | if ( `cat /var/ipfire/proxy/advanced/settings | grep ^ENABLE=on` ) { |
145 | print "Proxy an"; | |
146 | if ( `cat /var/ipfire/proxy/advanced/settings | grep ^TRANSPARENT=on` ) { print " (transparent)"; } | |
147 | } else { print "Proxy aus"; } | |
148 | } | |
149 | if ( $netsettings{'BLUE_DEV'} ) { print <<END; | |
150 | <tr><td bgcolor='$Header::colourblue' width='25%'><font size='2' color='white'><b>$Lang::tr{'wireless'}:</b></font><br> | |
151 | <td width='30%'>$netsettings{'BLUE_ADDRESS'} | |
152 | <td width='45%'> | |
e383179b | 153 | END |
072cd997 MT |
154 | if ( `cat /var/ipfire/proxy/advanced/settings | grep ^ENABLE_BLUE=on` ) { |
155 | print "Proxy an"; | |
156 | if ( `cat /var/ipfire/proxy/advanced/settings | grep ^TRANSPARENT_BLUE=on` ) { print " (transparent)"; } | |
157 | } else { print "Proxy aus"; } | |
158 | } | |
39a7cc11 | 159 | if ( $netsettings{'ORANGE_DEV'} ) { print <<END; |
072cd997 MT |
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%'><font color=$Header::colourgreen>Online</font> | |
e383179b | 163 | END |
072cd997 | 164 | } |
39a7cc11 MT |
165 | if ( `cat /var/ipfire/vpn/settings | grep ^ENABLED=on` || |
166 | `cat /var/ipfire/vpn/settings | grep ^ENABLED_BLUE=on` ) { | |
072cd997 MT |
167 | my $ipsecip = `cat /var/ipfire/vpn/settings | grep ^VPN_IP= | cut -c 8-`; |
168 | print <<END; | |
169 | <tr><td bgcolor='$Header::colourvpn' width='25%'><font size='2' color='white'><b>$Lang::tr{'vpn'}:</b></font><br> | |
170 | <td width='30%'>$ipsecip | |
171 | <td width='45%'><font color=$Header::colourgreen>Online</font> | |
e383179b | 172 | END |
072cd997 MT |
173 | } |
174 | if ( `cat /var/ipfire/ovpn/settings | grep ^ENABLED=on` || | |
175 | `cat /var/ipfire/ovpn/settings | grep ^ENABLED_BLUE=on` || | |
176 | `cat /var/ipfire/ovpn/settings | grep ^ENABLED_ORANGE=on`) { | |
177 | my $ovpnip = `cat /var/ipfire/ovpn/settings | grep ^DOVPN_SUBNET= | cut -c 14- | sed -e 's\/\\/255.255.255.0\/\/'`; | |
178 | print <<END; | |
179 | <tr><td bgcolor='$Header::colourovpn' width='25%'><font size='2' color='white'><b>OpenVPN:</b></font><br> | |
180 | <td width='30%'>$ovpnip | |
181 | <td width='45%'><font color=$Header::colourgreen>Online</font> | |
182 | END | |
183 | } | |
184 | if ( $netsettings{'DNS1'} ) { print <<END; | |
185 | <tr><td>DNS-Server: <td>$netsettings{'DNS1'} | |
e383179b | 186 | END |
072cd997 MT |
187 | } |
188 | if ( $netsettings{'DNS2'} ) { print <<END; | |
189 | <td>$netsettings{'DNS2'} | |
190 | END | |
191 | } | |
e383179b MT |
192 | print <<END; |
193 | </table> | |
194 | END | |
ac1cfefa MT |
195 | |
196 | # Memory usage warning | |
197 | my @free = `/usr/bin/free`; | |
198 | $free[1] =~ m/(\d+)/; | |
199 | my $mem = $1; | |
200 | $free[2] =~ m/(\d+)/; | |
201 | my $used = $1; | |
202 | my $pct = int 100 * ($mem - $used) / $mem; | |
203 | if ($used / $mem > 90) { | |
204 | $warnmessage .= "<li> $Lang::tr{'high memory usage'}: $pct% !</li>\n"; | |
205 | } | |
206 | ||
207 | # Diskspace usage warning | |
208 | my @temp=(); | |
209 | my $temp2=(); | |
210 | my @df = `/bin/df -B M -x rootfs`; | |
211 | foreach my $line (@df) { | |
212 | next if $line =~ m/^Filesystem/; | |
213 | if ($line =~ m/root/ ) { | |
214 | $line =~ m/^.* (\d+)M.*$/; | |
215 | @temp = split(/ +/,$line); | |
216 | if ($1<5) { | |
217 | # available:plain value in MB, and not %used as 10% is too much to waste on small disk | |
218 | # and root size should not vary during time | |
219 | $warnmessage .= "<li> $Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$1M</b> !</li>\n"; | |
220 | } | |
221 | ||
222 | } else { | |
223 | # $line =~ m/^.* (\d+)m.*$/; | |
224 | $line =~ m/^.* (\d+)\%.*$/; | |
225 | if ($1>90) { | |
226 | @temp = split(/ /,$line); | |
227 | $temp2=int(100-$1); | |
228 | $warnmessage .= "<li> $Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$temp2%</b> !</li>\n"; | |
229 | } | |
230 | } | |
231 | } | |
232 | ||
ac1cfefa | 233 | if ($warnmessage) { |
072cd997 | 234 | print "<table border='0'><tr><td align='center' bgcolor=$Header::colourred>$warnmessage</table>"; |
ac1cfefa MT |
235 | } |
236 | ||
ac1cfefa MT |
237 | &Header::closebox(); |
238 | ||
ac1cfefa MT |
239 | &Header::closebigbox(); |
240 | ||
241 | &Header::closepage(); |