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