Handle hostnames with upper-case letters
[webmin.git] / pam_login.cgi
1 #!/usr/local/bin/perl
2 # Ask one PAM question
3
4 BEGIN { push(@INC, ".."); };
5 use WebminCore;
6
7 $pragma_no_cache = 1;
8 #$ENV{'MINISERV_INTERNAL'} || die "Can only be called by miniserv.pl";
9 &init_config();
10 &ReadParse();
11 if ($gconfig{'loginbanner'} && $ENV{'HTTP_COOKIE'} !~ /banner=1/ &&
12     !$in{'logout'} && $in{'initial'}) {
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].answer.focus()'");
33
34 print "<center>\n";
35 if (defined($in{'failed'})) {
36         print "<h3>$text{'session_failed'}</h3><p>\n";
37         }
38 elsif ($in{'logout'}) {
39         print "<h3>$text{'session_logout'}</h3><p>\n";
40         }
41 elsif ($in{'timed_out'}) {
42         print "<h3>",&text('session_timed_out', int($in{'timed_out'}/60)),"</h3><p>\n";
43         }
44
45 print "$text{'pam_prefix'}\n";
46
47 print &ui_form_start("$gconfig{'webprefix'}/pam_login.cgi", "post");
48 print &ui_hidden("cid", $in{'cid'});
49
50 print &ui_table_start($text{'pam_header'},
51                       "width=40% class='loginform'", 2);
52
53 if ($gconfig{'realname'}) {
54         $host = &get_system_hostname();
55         }
56 else {
57         $host = $ENV{'HTTP_HOST'};
58         $host =~ s/:\d+//g;
59         $host = &html_escape($host);
60         }
61
62 if ($in{'message'}) {
63         # Showing a message
64         pirnt &ui_table_row(undef,
65               &html_escape($in{'message'}), 2);
66         print &ui_hidden("message", 1);
67         }
68 else {
69         # Asking a question
70         print &ui_table_row(undef,
71               &text($gconfig{'nohostname'} ? 'pam_mesg2' : 'pam_mesg',
72                     "<tt>$host</tt>"), 2, [ "align=center", "align=center" ]);
73
74         print &ui_table_row(&html_escape($in{'question'}),
75                 $in{'password'} ? &ui_password("answer", undef, 20)
76                                 : &ui_textbox("answer", undef, 20));
77         }
78
79 print &ui_table_end(),"\n";
80 print &ui_submit($text{'pam_login'});
81 print &ui_reset($text{'session_clear'});
82 if (!$in{'initial'}) {
83         print &ui_submit($text{'pam_restart'}, 'restart');
84         }
85 print &ui_form_end();
86 print "</center>\n";
87
88 print "$text{'pam_postfix'}\n";
89
90 # Output frame-detection Javascript, if theme uses frames
91 if ($tconfig{'inframe'}) {
92         print <<EOF;
93 <script>
94 if (window != window.top) {
95         window.top.location = window.location;
96         }
97 </script>
98 EOF
99         }
100
101 &ui_print_footer();
102