Use new module in top-level CGIs
[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(undef, undef, undef, undef, undef, 1, 1, undef,
33                             undef, "onLoad='document.forms[0].pass.value = \"\"; document.forms[0].user.focus()'");
34
35 if ($tconfig{'inframe'}) {
36         # Framed themes lose original page
37         $in{'page'} = "/";
38         }
39
40 print "<center>\n";
41 if (defined($in{'failed'})) {
42         print "<h3>$text{'session_failed'}</h3><p>\n";
43         }
44 elsif ($in{'logout'}) {
45         print "<h3>$text{'session_logout'}</h3><p>\n";
46         }
47 elsif ($in{'timed_out'}) {
48         print "<h3>",&text('session_timed_out', int($in{'timed_out'}/60)),"</h3><p>\n";
49         }
50 print "$text{'session_prefix'}\n";
51
52 print &ui_form_start("$gconfig{'webprefix'}/session_login.cgi", "post");
53 print &ui_hidden("page", $in{'page'});
54 print &ui_table_start($text{'session_header'},
55                       "width=40% class='loginform'", 2);
56
57 # Login message
58 if ($gconfig{'realname'}) {
59         $host = &get_display_hostname();
60         }
61 else {
62         $host = $ENV{'HTTP_HOST'};
63         $host =~ s/:\d+//g;
64         $host = &html_escape($host);
65         }
66 print &ui_table_row(undef,
67       &text($gconfig{'nohostname'} ? 'session_mesg2' : 'session_mesg',
68             "<tt>$host</tt>"), 2, [ "align=center", "align=center" ]);
69
70 # Username and password
71 print &ui_table_row($text{'session_user'},
72         &ui_textbox("user", $in{'failed'}, 20));
73 print &ui_table_row($text{'session_pass'},
74         &ui_password("pass", undef, 20));
75 if (!$gconfig{'noremember'}) {
76         print &ui_table_row(" ",
77                 &ui_checkbox("save", 1, $text{'session_save'}, 0));
78         }
79
80 print &ui_table_end(),"\n";
81 print &ui_submit($text{'session_login'});
82 print &ui_reset($text{'session_clear'});
83 print &ui_form_end();
84 print "</center>\n";
85
86 print "$text{'session_postfix'}\n";
87
88 # Output frame-detection Javascript, if theme uses frames
89 if ($tconfig{'inframe'}) {
90         print <<EOF;
91 <script>
92 if (window != window.top) {
93         window.top.location = window.location;
94         }
95 </script>
96 EOF
97         }
98
99 &ui_print_footer();
100