\n";
print &text('login_desc', "$openurl"),"\n";
print &ui_form_start("/$module_name/login.cgi", "post");
print &ui_hidden("url", $openurl);
print &ui_table_start($text{'login_header'}, undef, 2);
print &ui_table_row($text{'login_user'},
&ui_textbox("user", undef, 20));
print &ui_table_row($text{'login_pass'},
&ui_password("pass", undef, 20));
print &ui_table_end();
print &ui_form_end([ [ undef, $text{'login_login'} ] ]);
print "
\n";
&ui_print_footer("", $text{'index_return'});
exit;
}
}
elsif ($config{'loginmode'} == 1) {
# Login is fixed
$user = $config{'user'};
$pass = $config{'pass'};
}
# Connect to the server
my $con = &make_http_connection($host, $port, $ssl, $meth, $path);
&error($con) if (!ref($con));
# Send request headers
&write_http_connection($con, "Host: $host\r\n");
&write_http_connection($con, "User-Agent: Webmin\r\n");
if ($user) {
my $auth = &encode_base64("$user:$pass");
$auth =~ s/\n//g;
&write_http_connection($con, "Authorization: basic $auth\r\n");
}
&write_http_connection($con, sprintf(
"Webmin-servers: %s://%s:%d/$module_name/\r\n",
$ENV{'HTTPS'} eq "ON" ? "https" : "http",
$ENV{'SERVER_NAME'}, $ENV{'SERVER_PORT'}));
my $cl = $ENV{'CONTENT_LENGTH'};
&write_http_connection($con, "Content-Length: $cl\r\n") if ($cl);
&write_http_connection($con, "Content-Type: $ENV{'CONTENT_TYPE'}\r\n")
if ($ENV{'CONTENT_TYPE'});
&write_http_connection($con, "\r\n");
if ($cl) {
my $post;
&read_fully(\*STDIN, \$post, $cl);
&write_http_connection($con, $post);
}
# read back the headers
my $dummy = &read_http_connection($con);
my ($headers, %header);
while(1) {
my $headline;
($headline = &read_http_connection($con)) =~ s/\r|\n//g;
last if (!$headline);
$headline =~ /^(\S+):\s+(.*)$/ || &error("Bad header");
$header{lc($1)} = $2;
$headers .= $headline."\n";
}
my $defport = $ssl ? 443 : 80;
if ($header{'location'}) {
# fix a redirect
&redirect("/$module_name/link.cgi/$header{'location'}");
exit;
}
if ($header{'location'} =~ /^(http|https):\/\/$host:$port$path(.*)$/ ||
$header{'location'} =~ /^(http|https):\/\/$host$path(.*)/ &&
$port == $defport) {
# fix a redirect
&redirect("$url/$2");
exit;
}
elsif ($header{'www-authenticate'}) {
# Invalid login
if ($config{'loginmode'} == 2) {
print "Set-Cookie: tunnel=; path=/\n";
&error(&text('link_eautologin', "