Handle hostnames with upper-case letters
[webmin.git] / session_login.cgi
1 #!/usr/local/bin/perl
2 # session_login.cgi
3 # Display the login form used in session login mode
4
5 BEGIN { push(@INC, ".."); };
6 use WebminCore;
7
8 $pragma_no_cache = 1;
9 #$ENV{'MINISERV_INTERNAL'} || die "Can only be called by miniserv.pl";
10 &init_config();
11 &ReadParse();
12 if ($gconfig{'loginbanner'} && $ENV{'HTTP_COOKIE'} !~ /banner=1/ &&
13     !$in{'logout'} && !$in{'failed'} && !$in{'timed_out'}) {
14         # Show pre-login HTML page
15         print "Set-Cookie: banner=1; path=/\r\n";
16         &PrintHeader();
17         $url = $in{'page'};
18         open(BANNER, $gconfig{'loginbanner'});
19         while(<BANNER>) {
20                 s/LOGINURL/$url/g;
21                 print;
22                 }
23         close(BANNER);
24         return;
25         }
26 $sec = uc($ENV{'HTTPS'}) eq 'ON' ? "; secure" : "";
27 &get_miniserv_config(\%miniserv);
28 $sidname = $miniserv{'sidname'} || "sid";
29 print "Set-Cookie: banner=0; path=/$sec\r\n" if ($gconfig{'loginbanner'});
30 print "Set-Cookie: $sidname=x; path=/$sec\r\n" if ($in{'logout'});
31 print "Set-Cookie: testing=1; path=/$sec\r\n";
32 &ui_print_unbuffered_header(
33         undef, undef, undef, undef, undef, 1, 1, undef,
34         "<title>$text{'session_header'}</title>",
35         "onLoad='document.forms[0].pass.value = \"\"; ".
36         "document.forms[0].user.focus()'");
37
38 if ($tconfig{'inframe'}) {
39         # Framed themes lose original page
40         $in{'page'} = "/";
41         }
42
43 print "<center>\n";
44 if (defined($in{'failed'})) {
45         print "<h3>$text{'session_failed'}</h3><p>\n";
46         }
47 elsif ($in{'logout'}) {
48         print "<h3>$text{'session_logout'}</h3><p>\n";
49         }
50 elsif ($in{'timed_out'}) {
51         print "<h3>",&text('session_timed_out', int($in{'timed_out'}/60)),"</h3><p>\n";
52         }
53 print "$text{'session_prefix'}\n";
54
55 print &ui_form_start("$gconfig{'webprefix'}/session_login.cgi", "post");
56 print &ui_hidden("page", $in{'page'});
57 print &ui_table_start($text{'session_header'},
58                       "width=40% class='loginform'", 2);
59
60 # Login message
61 if ($gconfig{'realname'}) {
62         $host = &get_display_hostname();
63         }
64 else {
65         $host = $ENV{'HTTP_HOST'};
66         $host =~ s/:\d+//g;
67         $host = &html_escape($host);
68         }
69 print &ui_table_row(undef,
70       &text($gconfig{'nohostname'} ? 'session_mesg2' : 'session_mesg',
71             "<tt>$host</tt>"), 2, [ "align=center", "align=center" ]);
72
73 # Username and password
74 print &ui_table_row($text{'session_user'},
75         &ui_textbox("user", $in{'failed'}, 20));
76 print &ui_table_row($text{'session_pass'},
77         &ui_password("pass", undef, 20));
78 if (!$gconfig{'noremember'}) {
79         print &ui_table_row(" ",
80                 &ui_checkbox("save", 1, $text{'session_save'}, 0));
81         }
82
83 print &ui_table_end(),"\n";
84 print &ui_submit($text{'session_login'});
85 print &ui_reset($text{'session_clear'});
86 print &ui_form_end();
87 print "</center>\n";
88
89 print "$text{'session_postfix'}\n";
90
91 # Output frame-detection Javascript, if theme uses frames
92 if ($tconfig{'inframe'}) {
93         print <<EOF;
94 <script>
95 if (window != window.top) {
96         window.top.location = window.location;
97         }
98 </script>
99 EOF
100         }
101
102 &ui_print_footer();
103