3 # Open a PPTP connection and add its routes
5 require './pptp-client-lib.pl';
6 &error_setup($text{'conn_err'});
10 @tunnels = &list_tunnels();
11 ($tunnel) = grep { $_->{'name'} eq $in{'tunnel'} } @tunnels;
12 $tunnel || &error($text{'conn_egone'});
13 &parse_comments($tunnel);
14 $tunnel->{'server'} || &error($text{'conn_einvalid'});
16 # Check if it is already active
17 @conns = &list_connected();
18 ($conn) = grep { $_->[0] eq $in{'tunnel'} } @conns;
19 $conn && &error($text{'conn_ealready'});
23 &ui_print_header(undef, $text{'conn_title'}, "");
25 print "<b>",&text('conn_cmd', "<tt>$config{'pptp'} $tunnel->{'server'} ".
26 "call $in{'tunnel'}</tt>"),"</b><p>\n";
28 # If a password is passed, use it to temprarily overwrite the one in
31 $login = &find("name", $tunnel->{'opts'});
32 $sn = $login ? $login->{'value'} : &get_system_hostname(1);
33 &lock_file($config{'pap_file'});
34 @secs = &list_secrets();
35 ($sec) = grep { $_->{'client'} eq $sn } @secs;
36 $oldsecret = $sec->{'secret'};
37 $sec->{'secret'} = $in{'cpass'};
40 ($ok, @status) = &connect_tunnel($tunnel);
41 $sec->{'secret'} = $oldsecret;
44 &unlock_file($config{'pap_file'});
45 &lock_file($config{'pap_file'});
48 ($ok, @status) = &connect_tunnel($tunnel);
53 print "<b>",&text('conn_ok', "<tt>$status[0]</tt>",
54 "<tt>$status[1]</tt>",
55 "<tt>$status[2]</tt>"),"</b><p>\n";
56 local @rcmds = @{$status[3]};
57 local @rout = @{$status[4]};
59 print "<b>$text{'conn_routes'}</b><pre>\n";
60 for($i=0; $i<@rcmds; $i++) {
61 print $rcmds[$i],"\n";
62 print "<i>$rout[$i]</i>";
69 print "<b>$text{'conn_timeout'}</b><p>\n";
70 print "<pre>$status[0]</pre>\n";
71 if ($status[0] =~ /mppe/) {
72 print "<b>",&text('conn_mppe', "edit_opts.cgi"),"</b><p>\n";
76 # Save tunnel as default
77 &lock_file("$module_config_directory/config");
78 $config{'tunnel'} = $in{'tunnel'};
79 $config{'iface'} = $status[0] if ($ok);
80 &write_file("$module_config_directory/config", \%config);
81 &unlock_file("$module_config_directory/config");
83 &webmin_log("conn", undef, $in{'tunnel'}, $newiface);
84 &ui_print_footer("", $text{'index_return'});