Hinzugefuegt:
[ipfire-2.x.git] / html / cgi-bin / dial / 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 my $death = 0;
40 my $rebirth = 0;
41
42 if ($cgiparams{'ACTION'} eq $Lang::tr{'shutdown'}) {
43 $death = 1;
44 &General::log($Lang::tr{'shutting down ipfire'});
45 system '/usr/local/bin/ipfirereboot down';
46 } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'reboot'}) {
47 $rebirth = 1;
48 &General::log($Lang::tr{'rebooting ipfire'});
49 system '/usr/local/bin/ipfirereboot boot';
50 }
51
52 my $connstate = &Header::connectionstatus();
53 if ($connstate =~ /$Lang::tr{'dod waiting'}/ || -e "${General::swroot}/main/refreshindex") {
54 $refresh = "<meta http-equiv='refresh' content='30;'>";
55 } elsif ($connstate =~ /$Lang::tr{'connecting'}/) {
56 $refresh = "<meta http-equiv='refresh' content='5;'>";
57 }
58
59 my $c;
60 my $maxprofiles = 5;
61 my @profilenames = ();
62
63 for ($c = 1; $c <= $maxprofiles; $c++)
64 {
65 my %temppppsettings = ();
66 $temppppsettings{'PROFILENAME'} = '';
67 &General::readhash("${General::swroot}/ppp/settings-$c", \%temppppsettings);
68 $profilenames[$c] = $temppppsettings{'PROFILENAME'};
69 }
70 my %selected;
71 for ($c = 1; $c <= $maxprofiles; $c++) {
72 $selected{'PROFILE'}{$c} = '';
73 }
74 $selected{'PROFILE'}{$pppsettings{'PROFILE'}} = "selected='selected'";
75 my $dialButtonDisabled = "disabled='disabled'";
76
77
78 &Header::openpagewithoutmenu($Lang::tr{'main page'}, 1, $refresh);
79 &Header::openbigbox('', 'center');
80 &Header::openbox('100%', 'center', &Header::cleanhtml(`/bin/uname -n`,"y"));
81
82 if ( ( $pppsettings{'VALID'} eq 'yes' && $modemsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ )) {
83 if (open(IPADDR,"${General::swroot}/ddns/ipcache")) {
84 $ipaddr = <IPADDR>;
85 close IPADDR;
86 chomp ($ipaddr);
87 }
88 if (open(IPADDR,"${General::swroot}/red/local-ipaddress")) {
89 my $ipaddr = <IPADDR>;
90 close IPADDR;
91 chomp ($ipaddr);
92 }
93 } elsif ($modemsettings{'VALID'} eq 'no') {
94 print "$Lang::tr{'modem settings have errors'}\n </b></font>\n";
95 } else {
96 print "$Lang::tr{'profile has errors'}\n </b></font>\n";
97 }
98
99 if ( $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) {
100 $ipaddr = $netsettings{'RED_ADDRESS'};
101 }
102
103 print <<END;
104 <table border='0'>
105 <tr>
106 <td align='center'><form method='post' action="$ENV{'SCRIPT_NAME'}">
107 <input type='submit' name='ACTION' value='$Lang::tr{'refresh'}' />
108 </form></td>
109 </tr></table>
110
111 <!-- Table of networks -->
112 <table border='0' width=80%>
113 <tr> <th bgcolor='lightgrey'>$Lang::tr{'network'}
114 <th bgcolor='lightgrey'>IP
115 <th bgcolor='lightgrey'>$Lang::tr{'status'}
116 <tr> <td bgcolor='$Header::colourred' width='25%'><font size='2' color='white'><b>$Lang::tr{'internet'}:</b></font><br>
117 <td width='30%'>$ipaddr
118 <td width='45%'>$connstate
119 <tr><td colspan='2'>
120 <form method='post' action='/cgi-bin/dial/dial.cgi'>$Lang::tr{'profile'}:
121 <select name='PROFILE'>
122 END
123 for ($c = 1; $c <= $maxprofiles; $c++)
124 {
125 if ($profilenames[$c] ne '') {
126 $dialButtonDisabled = "";
127 print "\t<option value='$c' $selected{'PROFILE'}{$c}>$c. $profilenames[$c]</option>\n";
128 }
129 }
130 $dialButtonDisabled = "disabled='disabled'" if (-e '/var/run/ppp-ipcop.pid' || -e "${General::swroot}/red/active");
131 if ( ( $pppsettings{'VALID'} eq 'yes' ) || ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} =~ /^(DHCP|STATIC)$/ ) ) {
132 print <<END;
133 </select>
134 <input type='submit' name='ACTION' value='$Lang::tr{'dial profile'}' $dialButtonDisabled />
135 </form>
136 <td align='center'>
137 <table width='100%' border='0'>
138 <tr>
139 <td width='50%' align='right'> <form method='post' action='/cgi-bin/dial/dial.cgi'>
140 <input type='submit' name='ACTION' value='$Lang::tr{'dial'}'>
141 </form>
142 <td width='50%' align='left'> <form method='post' action='/cgi-bin/dial/dial.cgi'>
143 <input type='submit' name='ACTION' value='$Lang::tr{'hangup'}'>
144 </form>
145 </table>
146 END
147 } else {
148 print "$Lang::tr{'profile has errors'}\n </b></font>\n";
149 }
150
151 if ( $netsettings{'GREEN_DEV'} ) { print <<END;
152 <tr><td bgcolor='$Header::colourgreen' width='25%'><font size='2' color='white'><b>$Lang::tr{'lan'}:</b></font>
153 <td width='30%'>$netsettings{'GREEN_ADDRESS'}
154 <td width='45%'>
155 END
156 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^ENABLE=on` ) {
157 print "Proxy an";
158 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^TRANSPARENT=on` ) { print " (transparent)"; }
159 } else { print "Proxy aus"; }
160 }
161 if ( $netsettings{'BLUE_DEV'} ) { print <<END;
162 <tr><td bgcolor='$Header::colourblue' width='25%'><font size='2' color='white'><b>$Lang::tr{'wireless'}:</b></font><br>
163 <td width='30%'>$netsettings{'BLUE_ADDRESS'}
164 <td width='45%'>
165 END
166 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^ENABLE_BLUE=on` ) {
167 print "Proxy an";
168 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^TRANSPARENT_BLUE=on` ) { print " (transparent)"; }
169 } else { print "Proxy aus"; }
170 }
171 if ( $netsettings{'ORANGE_DEV'} ) { print <<END;
172 <tr><td bgcolor='$Header::colourorange' width='25%'><font size='2' color='white'><b>$Lang::tr{'dmz'}:</b></font><br>
173 <td width='30%'>$netsettings{'ORANGE_ADDRESS'}
174 <td width='45%'><font color=$Header::colourgreen>Online</font>
175 END
176 }
177 if ( `cat /var/ipfire/vpn/settings | grep ^ENABLED=on` ||
178 `cat /var/ipfire/vpn/settings | grep ^ENABLED_BLUE=on` ) {
179 my $ipsecip = `cat /var/ipfire/vpn/settings | grep ^VPN_IP= | cut -c 8-`;
180 print <<END;
181 <tr><td bgcolor='$Header::colourvpn' width='25%'><font size='2' color='white'><b>$Lang::tr{'vpn'}:</b></font><br>
182 <td width='30%'>$ipsecip
183 <td width='45%'><font color=$Header::colourgreen>Online</font>
184 END
185 }
186 if ( `cat /var/ipfire/ovpn/settings | grep ^ENABLED=on` ||
187 `cat /var/ipfire/ovpn/settings | grep ^ENABLED_BLUE=on` ||
188 `cat /var/ipfire/ovpn/settings | grep ^ENABLED_ORANGE=on`) {
189 my $ovpnip = `cat /var/ipfire/ovpn/settings | grep ^DOVPN_SUBNET= | cut -c 14- | sed -e 's\/\\/255.255.255.0\/\/'`;
190 print <<END;
191 <tr><td bgcolor='$Header::colourovpn' width='25%'><font size='2' color='white'><b>OpenVPN:</b></font><br>
192 <td width='30%'>$ovpnip
193 <td width='45%'><font color=$Header::colourgreen>Online</font>
194 END
195 }
196 if ( $netsettings{'DNS1'} ) { print <<END;
197 <tr><td>DNS-Server: <td>$netsettings{'DNS1'}
198 END
199 }
200 if ( $netsettings{'DNS2'} ) { print <<END;
201 <td>$netsettings{'DNS2'}
202 END
203 }
204 print <<END;
205 </table>
206 END
207
208 &Header::closebox();
209
210 &Header::openbox('100%', 'left', $Lang::tr{'shutdown2'});
211
212 if ($death == 0 && $rebirth == 0) {
213 print <<END
214 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
215 <table width='100%'>
216 <tr>
217 <td width='50%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'reboot'}' /></td>
218 <td width='50%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'shutdown'}' /></td>
219 </tr>
220 </table>
221 </form>
222 END
223 ;
224 } else {
225 my $message='';
226 my $title='';
227 if ($death) {
228 $title = $Lang::tr{'shutting down'};
229 $message = $Lang::tr{'ipfire has now shutdown'};
230 } else {
231 $title = $Lang::tr{'rebooting'};
232 $message = $Lang::tr{'ipfire has now rebooted'};
233 }
234 print <<END
235 <font size='6'><center>$message</center></font>
236 END
237 ;
238 }
239
240 &Header::closebox();
241
242 &Header::closebigbox();
243
244 &Header::closepage();