File: login_form.php

package info (click to toggle)
phpldapadmin 1.2.6.3-0.3%2Bdeb12u1
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 6,836 kB
  • sloc: php: 17,571; javascript: 5,299; xml: 1,498; sh: 346; makefile: 26
file content (118 lines) | stat: -rw-r--r-- 4,548 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/**
 * Displays the login form for a server for users who specify 'cookie' or 'session' for their auth_type.
 *
 * @author The phpLDAPadmin development team
 * @package phpLDAPadmin
 * @see login.php
 */

/**
 */

require './common.php';

printf('<h3 class="title">%s %s</h3>',_('Authenticate to server'),$app['server']->getName());
echo '<br />';

# Check for a secure connection
$isHTTPS = false;

# Check if the current connection is encrypted
if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') {
        $isHTTPS = true;
}
# Check if a proxy server downstream does encryption for us
elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && strtolower($_SERVER['HTTP_X_FORWARDED_SSL'])
== 'on') {
        $isHTTPS = true;
}

if (!$isHTTPS) {
	echo '<div style="text-align: center; color:red">';
	printf('<acronym title="%s"><b>%s: %s.</b></acronym>',
		_('You are not using \'https\'. Web browser will transmit login information in clear text.'),
		_('Warning'),_('This web connection is unencrypted'));
	echo '</div>';

	echo '<br />';
}
unset($isSecure);

# HTTP Basic Auth Form.
if ($app['server']->getAuthType() == 'http') {
	ob_end_clean();

	# When we pop up the basic athentication, we come back to this script, so try the login again.
	if ($app['server']->isLoggedIn('user')) {
		system_message(array(
			'title'=>_('Authenticate to server'),
			'body'=>_('Successfully logged into server.'),
			'type'=>'info'),
			sprintf('cmd.php?server_id=%s&refresh=SID_%s',$app['server']->getIndex(),$app['server']->getIndex()));

		die();
	}

	header(sprintf('WWW-Authenticate: Basic realm="%s"',$_SESSION[APPCONFIG]->getValue('session','http_realm')));

	if ($_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.0')
		header('HTTP/1.0 401 Unauthorized'); // http 1.0 method
	else
		header('Status: 401 Unauthorized'); // http 1.1 method

	return;

# HTML Login Form
} else {
	echo '<form action="cmd.php" method="post" autocomplete="off">';
	echo '<div>';
	echo '<input type="hidden" name="cmd" value="login" />';
	printf('<input type="hidden" name="server_id" value="%s" />',$app['server']->getIndex());
	echo '<input type="hidden" name="nodecode[login_pass]" value="1" />';

	if (get_request('redirect','GET',false,false))
		printf('<input type="hidden" name="redirect" value="%s" />',rawurlencode(get_request('redirect','GET')));

	echo '</div>';

	echo '<table class="forminput" style="margin-left: auto; margin-right: auto;">';

	printf('<tr><td><b>%s:</b></td></tr>',
		$app['server']->getValue('login','auth_text') ? $app['server']->getValue('login','auth_text') :
			($app['server']->getValue('login','attr') == 'dn' ? ($app['server']->getValue('login', 'bind_dn_template') ? _('User Name') . ' / ' . _('Login DN') : _('Login DN')) : $_SESSION[APPCONFIG]->getFriendlyName($app['server']->getValue('login','attr'))));

	printf('<tr><td><input type="text" id="login" name="login" size="40" value="%s" /></td></tr>',
		$app['server']->getValue('login','attr',false) == 'dn' ? $app['server']->getValue('login','bind_id') : '');

	echo '<tr><td colspan="2">&nbsp;</td></tr>';
	printf('<tr><td><b>%s:</b></td></tr>',_('Password'));
	echo '<tr><td><input type="password" id="password" size="40" value="" name="login_pass" /></td></tr>';
	echo '<tr><td colspan="2">&nbsp;</td></tr>';

	#reCAPTCHA
	if ($_SESSION[APPCONFIG]->getValue('session', 'reCAPTCHA-enable')) {
		echo '<script src="https://www.google.com/recaptcha/api.js"></script>';
		echo '<tr><td><div class="g-recaptcha" data-sitekey="'.$_SESSION[APPCONFIG]->getValue('session', 'reCAPTCHA-key-site').'"></div></td></tr>';
		echo '<tr><td colspan="2">&nbsp;</td></tr>';
	}

	# If Anon bind allowed, then disable the form if the user choose to bind anonymously.
	if ($app['server']->isAnonBindAllowed())
		printf('<tr><td colspan="2"><small><b>%s</b></small> <input type="checkbox" name="anonymous_bind" onclick="form_field_toggle_enable(this,[\'login\',\'password\'],\'login\')" id="anonymous_bind_checkbox" /></td></tr>',
			_('Anonymous'));

	printf('<tr><td colspan="2" style="text-align: center;"><input type="submit" name="submit" value="%s" /></td></tr>',
		_('Authenticate'));

	echo '</table>';
	echo '</form>';

	echo '<br/>';

	echo '<script type="text/javascript">document.getElementById("login").focus()</script>';

	if ($app['server']->isAnonBindAllowed())
		printf('<script type="text/javascript" src="%sform_field_toggle_enable.js"></script>',JSDIR);
}
?>