Use new module in top-level CGIs
[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{'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 print "Set-Cookie: banner=0; path=/$sec\r\n" if ($gconfig{'loginbanner'});
28 print "Set-Cookie: testing=1; path=/$sec\r\n";
29 &ui_print_unbuffered_header(undef, undef, undef, undef, undef, 1, 1, undef,
30                             undef, "onLoad='document.forms[0].answer.focus()'");
31
32 print "<center>\n";
33 if (defined($in{'failed'})) {
34         print "<h3>$text{'session_failed'}</h3><p>\n";
35         }
36 elsif ($in{'logout'}) {
37         print "<h3>$text{'session_logout'}</h3><p>\n";
38         }
39 elsif ($in{'timed_out'}) {
40         print "<h3>",&text('session_timed_out', int($in{'timed_out'}/60)),"</h3><p>\n";
41         }
42
43 print "$text{'pam_prefix'}\n";
44 print "<form action=$gconfig{'webprefix'}/pam_login.cgi method=post>\n";
45 print "<input type=hidden name=cid value='",&quote_escape($in{'cid'}),"'>\n";
46
47 print "<table border width=40%>\n";
48 print "<tr $tb> <td><b>$text{'pam_header'}</b></td> </tr>\n";
49 print "<tr $cb> <td align=center><table cellpadding=3>\n";
50 if ($gconfig{'realname'}) {
51         $host = &get_system_hostname();
52         }
53 else {
54         $host = $ENV{'HTTP_HOST'};
55         $host =~ s/:\d+//g;
56         $host = &html_escape($host);
57         }
58
59 if ($in{'message'}) {
60         # Showing a message
61         print "<tr> <td colspan=2 align=center>",
62               &html_escape($in{'message'}),"</td> </tr>\n";
63         print "<input type=hidden name=message value=1>\n";
64         }
65 else {
66         # Asking a question
67         print "<tr> <td colspan=2 align=center>",
68               &text($gconfig{'nohostname'} ? 'pam_mesg2' : 'pam_mesg',
69                     "<tt>$host</tt>"),"</td> </tr>\n";
70
71         $pass = "type=password" if ($in{'password'});
72         print "<tr> <td><b>",&html_escape($in{'question'}),"</b></td>\n";
73         print "<td><input name=answer $pass size=20></td> </tr>\n";
74         }
75
76 print "<tr> <td colspan=2 align=center>\n";
77 print "<input type=submit value='$text{'pam_login'}'>\n";
78 print "<input type=reset value='$text{'session_clear'}'>\n";
79 if (!$in{'initial'}) {
80         print "<input type=submit name=restart value='$text{'pam_restart'}'>\n";
81         }
82 print "<br>\n";
83
84 print "</td> </tr>\n";
85 print "</table></td></tr></table><p>\n";
86 print "</form></center>\n";
87 print "$text{'pam_postfix'}\n";
88
89 # Output frame-detection Javascript, if theme uses frames
90 if ($tconfig{'inframe'}) {
91         print <<EOF;
92 <script>
93 if (window != window.top) {
94         window.top.location = window.location;
95         }
96 </script>
97 EOF
98         }
99
100 &ui_print_footer();
101