Menu

[r4752]: / trunk / www / access_ldap.php  Maximize  Restore  History

Download this file

213 lines (190 with data), 10.4 kB

  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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/usr/local/bin/php
<?php
/*
acces_ldap.php
part of FreeNAS (http://www.freenas.org)
Copyright (C) 2005-2008 Olivier Cochard-Labbe <olivier@freenas.org>.
All rights reserved.
Based on m0n0wall (http://m0n0.ch/wall)
Copyright (C) 2003-2006 Manuel Kasper <mk@neon1.net>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require("auth.inc");
require("guiconfig.inc");
$pgtitle = array(gettext("Access"), gettext("LDAP"));
if (!is_array($config['ldap'])) {
$config['ldap'] = array();
}
if (!is_array($config['samba'])) {
$config['samba'] = array();
}
#LDAP take priority over MS ActiveDirectory (FreeNAS choicee), then disable AD:
if (!is_array($config['ad'])) {
$config['ad'] = array();
}
$pconfig['enable'] = isset($config['ldap']['enable']);
$pconfig['hostname'] = $config['ldap']['hostname'];
$pconfig['base'] = $config['ldap']['base'];
$pconfig['anonymousbind'] = isset($config['ldap']['anonymousbind']);
$pconfig['binddn'] = $config['ldap']['binddn'];
$pconfig['bindpw'] = $config['ldap']['bindpw'];
$pconfig['bindpw2'] = $config['ldap']['bindpw'];
$pconfig['rootbinddn'] = $config['ldap']['rootbinddn'];
$pconfig['rootbindpw'] = $config['ldap']['rootbindpw'];
$pconfig['rootbindpw2'] = $config['ldap']['rootbindpw'];
$pconfig['user_suffix'] = $config['ldap']['user_suffix'];
$pconfig['password_suffix'] = $config['ldap']['password_suffix'];
$pconfig['group_suffix'] = $config['ldap']['group_suffix'];
$pconfig['machine_suffix'] = $config['ldap']['machine_suffix'];
$pconfig['pam_password'] = $config['ldap']['pam_password'];
if (is_array($config['ldap']['auxparam']))
$pconfig['auxparam'] = implode("\n", $config['ldap']['auxparam']);
if ($_POST) {
unset($input_errors);
$pconfig = $_POST;
// Input validation.
if ($_POST['enable']) {
$reqdfields = explode(" ", "hostname base rootbinddn rootbindpw user_suffix group_suffix password_suffix machine_suffix");
$reqdfieldsn = array(gettext("Host name"), gettext("Base DN"), gettext("Root bind DN"), gettext("Root bind password"), gettext("User suffix"), gettext("Group suffix"), gettext("Password suffix"), gettext("Machine suffix"));
$reqdfieldst = explode(" ", "string string string password string string string string");
if (!$_POST['anonymousbind']) {
$reqdfields = array_merge($reqdfields, explode(" ", "binddn bindpw"));
$reqdfieldsn = array_merge($reqdfieldsn, array(gettext("Bind DN"), gettext("Bind password")));
$reqdfieldst = array_merge($reqdfieldst, explode(" ", "string password"));
}
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
do_input_validation_type($_POST, $reqdfields, $reqdfieldsn, $reqdfieldst, &$input_errors);
}
if (($_POST['bindpw'] !== $_POST['bindpw2'])) {
$input_errors[] = gettext("The confimed password does not match. Please ensure the passwords match exactly.");
}
if (!$input_errors) {
$config['ldap']['enable'] = $_POST['enable'] ? true : false;
$config['ldap']['hostname'] = $_POST['hostname'];
$config['ldap']['base'] = $_POST['base'];
$config['ldap']['anonymousbind'] = $_POST['anonymousbind'] ? true : false;
$config['ldap']['binddn'] = $_POST['binddn'];
$config['ldap']['bindpw'] = $_POST['bindpw'];
$config['ldap']['rootbinddn'] = $_POST['rootbinddn'];
$config['ldap']['rootbindpw'] = $_POST['rootbindpw'];
$config['ldap']['user_suffix'] = $_POST['user_suffix'];
$config['ldap']['password_suffix'] = $_POST['password_suffix'];
$config['ldap']['group_suffix'] = $_POST['group_suffix'];
$config['ldap']['machine_suffix'] = $_POST['machine_suffix'];
$config['ldap']['pam_password'] = $_POST['pam_password'];
# Write additional parameters.
unset($config['ldap']['auxparam']);
foreach (explode("\n", $_POST['auxparam']) as $auxparam) {
$auxparam = trim($auxparam, "\t\n\r");
if (!empty($auxparam))
$config['ldap']['auxparam'][] = $auxparam;
}
// Disable AD
if ($config['ldap']['enable']) {
$config['samba']['security'] = "user";
$config['ad']['enable'] = false;
}
write_config();
$retval = 0;
if (!file_exists($d_sysrebootreqd_path)) {
config_lock();
rc_exec_service("pam");
rc_exec_service("ldap");
rc_start_service("nsswitch");
rc_update_service("samba");
config_unlock();
}
$savemsg = get_std_save_message($retval);
}
}
?>
<?php include("fbegin.inc"); ?>
<script language="JavaScript">
<!--
function enable_change(enable_change) {
var endis = !(document.iform.enable.checked || enable_change);
document.iform.hostname.disabled = endis;
document.iform.base.disabled = endis;
document.iform.anonymousbind.disabled = endis;
document.iform.binddn.disabled = endis;
document.iform.bindpw.disabled = endis;
document.iform.bindpw2.disabled = endis;
document.iform.rootbinddn.disabled = endis;
document.iform.rootbindpw.disabled = endis;
document.iform.rootbindpw2.disabled = endis;
document.iform.user_suffix.disabled = endis;
document.iform.password_suffix.disabled = endis;
document.iform.group_suffix.disabled = endis;
document.iform.machine_suffix.disabled = endis;
document.iform.pam_password.disabled = endis;
document.iform.auxparam.disabled = endis;
}
function anonymousbind_change() {
switch (document.iform.anonymousbind.checked) {
case false:
showElementById('binddn_tr','show');
showElementById('bindpw_tr','show');
break;
case true:
showElementById('binddn_tr','hide');
showElementById('bindpw_tr','hide');
break;
}
}
//-->
</script>
<form action="access_ldap.php" method="post" name="iform" id="iform">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="tabcont">
<?php if ($input_errors) print_input_errors($input_errors);?>
<?php if ($savemsg) print_info_box($savemsg);?>
<table width="100%" border="0" cellpadding="6" cellspacing="0">
<?php html_titleline_checkbox("enable", gettext("Lightweight Directory Access Protocol"), $pconfig['enable'] ? true : false, gettext("Enable"), "enable_change(false)");?>
<?php html_inputbox("hostname", gettext("Host name"), $pconfig['hostname'], gettext("The name or IP address of the LDAP server."), true, 20);?>
<?php html_inputbox("base", gettext("Base DN"), $pconfig['base'], sprintf(gettext("The default base distinguished name (DN) to use for searches, e.g. %s"), "dc=test,dc=org"), true, 40);?>
<?php html_checkbox("anonymousbind", gettext("Anonymous bind"), $pconfig['anonymousbind'] ? true : false, gettext("Enable anonymous bind."), "", true, "anonymousbind_change()");?>
<?php html_inputbox("binddn", gettext("Bind DN"), $pconfig['binddn'], sprintf(gettext("The distinguished name with which to bind to the directory server, e.g. %s"), "cn=admin,dc=test,dc=org"), true, 40);?>
<?php html_passwordconfbox("bindpw", "bindpw2", gettext("Bind password"), $pconfig['bindpw'], $pconfig['bindpw2'], gettext("The cleartext credentials with which to bind."), true);?>
<?php html_inputbox("rootbinddn", gettext("Root bind DN"), $pconfig['rootbinddn'], sprintf(gettext("The distinguished name with which to bind to the directory server, e.g. %s"), "cn=admin,dc=test,dc=org"), true, 40);?>
<?php html_passwordconfbox("rootbindpw", "rootbindpw2", gettext("Root bind password"), $pconfig['rootbindpw'], $pconfig['rootbindpw2'], gettext("The credentials with which to bind."), true);?>
<?php html_combobox("pam_password", gettext("Password encryption"), $pconfig['pam_password'], array("clear" => "clear", "crypt" => "crypt", "md5" => "md5", "nds" => "nds", "racf" => "racf", "ad" => "ad", "exop" => "exop"), gettext("The password change protocol to use."), true);?>
<?php html_inputbox("user_suffix", gettext("User suffix"), $pconfig['user_suffix'], sprintf(gettext("This parameter specifies the suffix that is used for users when these are added to the LDAP directory, e.g. %s"), "ou=Users"), true, 20);?>
<?php html_inputbox("group_suffix", gettext("Group suffix"), $pconfig['group_suffix'], sprintf(gettext("This parameter specifies the suffix that is used for groups when these are added to the LDAP directory, e.g. %s"), "ou=Groups"), true, 20);?>
<?php html_inputbox("password_suffix", gettext("Password suffix"), $pconfig['password_suffix'], sprintf(gettext("This parameter specifies the suffix that is used for passwords when these are added to the LDAP directory, e.g. %s"), "ou=Users"), true, 20);?>
<?php html_inputbox("machine_suffix", gettext("Machine suffix"), $pconfig['machine_suffix'], sprintf(gettext("This parameter specifies the suffix that is used for machines when these are added to the LDAP directory, e.g. %s"), "ou=Computers"), true, 20);?>
<?php html_textarea("auxparam", gettext("Auxiliary parameters"), $pconfig['auxparam'], sprintf(gettext("These parameters are added to %s."), "ldap.conf"), false, 65, 5, false, false);?>
</tr>
</table>
<div id="submit">
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" onClick="enable_change(true)">
</div>
</td>
</tr>
</table>
<?php include("formend.inc");?>
</form>
<script language="JavaScript">
<!--
anonymousbind_change();
enable_change(false);
//-->
</script>
<?php include("fend.inc");?>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.