Initial checkin of Webmin
[webmin.git] / pam_login.cgi
1 #!/usr/local/bin/perl
2 # Ask one PAM question
3
4 $pragma_no_cache = 1;
5 #$ENV{'MINISERV_INTERNAL'} || die "Can only be called by miniserv.pl";
6 require './web-lib.pl';
7 &init_config();
8 &ReadParse();
9 if ($gconfig{'loginbanner'} && $ENV{'HTTP_COOKIE'} !~ /banner=1/ &&
10     $in{'initial'}) {
11         # Show pre-login HTML page
12         print "Set-Cookie: banner=1; path=/\r\n";
13         &PrintHeader();
14         $url = $in{'page'};
15         open(BANNER, $gconfig{'loginbanner'});
16         while(<BANNER>) {
17                 s/LOGINURL/$url/g;
18                 print;
19                 }
20         close(BANNER);
21         return;
22         }
23 $sec = uc($ENV{'HTTPS'}) eq 'ON' ? "; secure" : "";
24 &get_miniserv_config(\%miniserv);
25 print "Set-Cookie: banner=0; path=/$sec\r\n" if ($gconfig{'loginbanner'});
26 print "Set-Cookie: testing=1; path=/$sec\r\n";
27 &header(undef, undef, undef, undef, 1, 1, undef, undef,
28         "document.forms[0].answer.focus()'");
29 print "<hr>\n";
30
31 print "<center>\n";
32 if (defined($in{'failed'})) {
33         print "<h3>$text{'session_failed'}</h3><p>\n";
34         }
35 elsif ($in{'logout'}) {
36         print "<h3>$text{'session_logout'}</h3><p>\n";
37         }
38 elsif ($in{'timed_out'}) {
39         print "<h3>",&text('session_timed_out', int($in{'timed_out'}/60)),"</h3><p>\n";
40         }
41
42 print "$text{'pam_prefix'}\n";
43 print "<form action=$gconfig{'webprefix'}/pam_login.cgi method=post>\n";
44 print "<input type=hidden name=cid value='$in{'cid'}'>\n";
45
46 print "<table border width=40%>\n";
47 print "<tr $tb> <td><b>$text{'pam_header'}</b></td> </tr>\n";
48 print "<tr $cb> <td align=center><table cellpadding=3>\n";
49 if ($gconfig{'realname'}) {
50         $host = &get_system_hostname();
51         }
52 else {
53         $host = $ENV{'HTTP_HOST'};
54         $host =~ s/:\d+//g;
55         $host = &html_escape($host);
56         }
57
58 if ($in{'message'}) {
59         # Showing a message
60         print "<tr> <td colspan=2 align=center>",
61               $in{'message'},"</td> </tr>\n";
62         print "<input type=hidden name=message value=1>\n";
63         }
64 else {
65         # Asking a question
66         print "<tr> <td colspan=2 align=center>",
67               &text($gconfig{'nohostname'} ? 'pam_mesg2' : 'pam_mesg',
68                     "<tt>$host</tt>"),"</td> </tr>\n";
69
70         $pass = "type=password" if ($in{'password'});
71         print "<tr> <td><b>$in{'question'}</b></td>\n";
72         print "<td><input name=answer $pass size=20></td> </tr>\n";
73         }
74
75 print "<tr> <td colspan=2 align=center>\n";
76 print "<input type=submit value='$text{'pam_login'}'>\n";
77 print "<input type=reset value='$text{'session_clear'}'>\n";
78 if (!$in{'initial'}) {
79         print "<input type=submit name=restart value='$text{'pam_restart'}'>\n";
80         }
81 print "<br>\n";
82
83 print "</td> </tr>\n";
84 print "</table></td></tr></table><p>\n";
85 print "<hr>\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 &footer();
101