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