69,6 → 69,8 |
$l_ldap_cert_required_text = "Vérifier que le serveur LDAP utilise un certificat connu"; |
$l_ldap_cert_label = "Certificat SSL (CA)"; |
$l_ldap_cert_text = "Certificat de l'authorité de certification signant celui du serveur LDAP"; |
$l_ad_dns_domain_label = "Nom de domaine interne"; |
$l_ad_dns_domain_text = "Nom de domaine qui sera redirigé vers le serveur DNS de l'annuaire LDAP (vide pour désactivé)"; |
$l_ldap_cert_status_cur = "Certificat actuel : "; |
$l_ldap_cert_status_no = "Aucun certificat installé"; |
$l_ldap_submit = "Enregistrer"; |
110,6 → 112,8 |
$l_ldap_cert_required_text = "Verify that the LDAP server uses a trusted certificate"; |
$l_ldap_cert_label = "SSL certificate (CA)"; |
$l_ldap_cert_text = "Certificate of the certification authority that signed the LDAP server certificate"; |
$l_ad_dns_domain_label = "Internal domain name"; |
$l_ad_dns_domain_text = "Domain name that will be forwarded to the DNS server of the LDAP directory (empty for disabled)"; |
$l_ldap_cert_status_cur = "Current certificate:"; |
$l_ldap_cert_status_no = "No certificate imported"; |
$l_ldap_submit = "Save"; |
128,6 → 132,151 |
$l_checkingConf = "Checking this configuration..."; |
} |
|
// AJAX LDAP assitant |
if (isset($_GET['assistant'])) { |
$response = [ |
'values' => [] |
]; |
if (!isset($_POST['ldap_server'])) exit(); |
$ldap_server = $_POST['ldap_server']; |
|
// Check port 389 & 636 |
if (!$sock = @fsockopen($ldap_server, 389, $num, $error, 2)) { |
$ldap_port_389 = false; |
$ldap_srv_389 = false; |
} else { |
$ldap_port_389 = true; |
fclose($sock); |
} |
if (!$sock = @fsockopen($ldap_server, 636, $num, $error, 2)) { |
$ldap_port_636 = false; |
$ldap_srv_636 = false; |
$ldap_ssl = false; |
} else { |
$ldap_port_636 = true; |
$ldap_ssl = true; |
fclose($sock); |
} |
|
if (!$ldap_port_389 && !$ldap_port_636) { |
$response['result'] = -2; |
|
header('Content-Type: application/json'); |
echo json_encode($response); |
exit(); |
} |
|
// Check LDAP service |
if ($ldap_port_636) { |
if (PHP_VERSION_ID >= 70100): |
// Set LDAP SSL options |
ldap_set_option(null, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_NEVER); |
endif; |
$ldapconn = @ldap_connect('ldaps://'.$ldap_server); |
if (!$ldapconn) { |
$ldap_srv_636 = false; |
} else { |
ldap_set_option($ldapconn, LDAP_OPT_TIMELIMIT, 2); |
|
// Bind anonymous |
$ldap_srv_636 = true; |
if (!@ldap_bind($ldapconn, '', '')) { |
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3); |
if (!@ldap_bind($ldapconn, '', '')) { |
$ldap_srv_636 = false; |
} |
} |
} |
|
if ($ldap_srv_636) { |
$ldap_data = @ldap_read($ldapconn, '', 'objectClass=*', ['dnsHostName','rootDomainNamingContext','supportedCapabilities']); |
$ldap_rootDSE = @ldap_get_entries($ldapconn, $ldap_data); |
|
try { |
$response['values']['isAD'] = in_array('1.2.840.113556.1.4.800', $ldap_rootDSE[0]['supportedcapabilities']); |
} catch (Exception $e) { |
$response['values']['isAD'] = false; |
} |
|
if ($response['values']['isAD']) { |
try { |
$response['values']['ldap_base_dn'] = $ldap_rootDSE[0]['rootdomainnamingcontext'][0]; |
|
if ($response['values']['ldap_base_dn']) { |
$response['values']['int_dns_domain'] = str_replace('DC=', '', str_replace(',DC=', '.', $response['values']['ldap_base_dn'])); |
} |
|
$response['values']['ldap_base_dn'] = 'CN=Users,'.$response['values']['ldap_base_dn']; |
} catch (Exception $e) { } |
|
try { |
$response['values']['ldap_server_domain'] = $ldap_rootDSE[0]['dnshostname'][0]; |
} catch (Exception $e) { } |
} |
} |
} |
$response['values']['ldap_srv_636'] = $ldap_srv_636; |
|
if (!$ldap_srv_636) { |
$ldapconn = @ldap_connect('ldap://'.$ldap_server); |
if (!$ldapconn) { |
$ldap_srv_389 = false; |
} else { |
ldap_set_option($ldapconn, LDAP_OPT_TIMELIMIT, 2); |
|
// Bind anonymous |
$ldap_srv_389 = true; |
if (!@ldap_bind($ldapconn, '', '')) { |
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3); |
if (!@ldap_bind($ldapconn, '', '')) { |
$ldap_srv_389 = false; |
} |
} |
} |
|
if ($ldap_srv_389) { |
$ldap_data = @ldap_read($ldapconn, '', 'objectClass=*', ['dnsHostName','rootDomainNamingContext','supportedCapabilities']); |
$ldap_rootDSE = @ldap_get_entries($ldapconn, $ldap_data); |
|
try { |
$response['values']['isAD'] = in_array('1.2.840.113556.1.4.800', $ldap_rootDSE[0]['supportedcapabilities']); |
} catch (Exception $e) { |
$response['values']['isAD'] = false; |
} |
|
if ($response['values']['isAD']) { |
try { |
$response['values']['ldap_base_dn'] = $ldap_rootDSE[0]['rootdomainnamingcontext'][0]; |
|
if ($response['values']['ldap_base_dn']) { |
$response['values']['int_dns_domain'] = str_replace('DC=', '', str_replace(',DC=', '.', $response['values']['ldap_base_dn'])); |
} |
|
$response['values']['ldap_base_dn'] = 'CN=Users,'.$response['values']['ldap_base_dn']; |
} catch (Exception $e) { } |
|
try { |
$response['values']['ldap_server_domain'] = $ldap_rootDSE[0]['dnshostname'][0]; |
} catch (Exception $e) { } |
} |
} |
$response['values']['ldap_srv_389'] = $ldap_srv_389; |
} |
|
if (!$ldap_srv_636 && !$ldap_srv_389) { |
$response['result'] = -1; |
|
header('Content-Type: application/json'); |
echo json_encode($response); |
exit(); |
} |
|
$response['result'] = 0; |
header('Content-Type: application/json'); |
echo json_encode($response); |
exit(); |
} |
|
function ldap_checkServerConfig($f_ldap_server, $f_ldap_identity, $f_ldap_password, $f_ldap_basedn, $f_ldap_base_filter, $f_ldap_uid, $f_ldap_ssl, $f_ldap_cert, $f_ldap_cert_required) { |
// Socket to the LDAP port of the server |
if (!$sock = @fsockopen($f_ldap_server, (($f_ldap_ssl) ? 636 : 389), $num, $error, 2)) { |
136,18 → 285,20 |
} |
fclose($sock); |
|
if (PHP_VERSION_ID >= 70100): |
// Set LDAP SSL options |
if ($f_ldap_ssl) { |
if ($f_ldap_cert_required) { |
if ($f_ldap_cert) { |
ldap_set_option(NULL, LDAP_OPT_X_TLS_CACERTFILE, $f_ldap_cert); |
ldap_set_option(null, LDAP_OPT_X_TLS_CACERTFILE, $f_ldap_cert); |
} |
ldap_set_option(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_DEMAND); |
ldap_set_option(null, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_DEMAND); |
|
} else { |
ldap_set_option(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_NEVER); |
ldap_set_option(null, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_NEVER); |
} |
} |
endif; |
|
// if ok, Test LDAP connection |
$ldapconn = @ldap_connect((($f_ldap_ssl)?'ldaps':'ldap').'://'.$f_ldap_server); |
224,7 → 375,9 |
exec('sed -i '.escapeshellarg("s/^LDAP_USER=.*/LDAP_USER=$ldap_user/g").' '.CONF_FILE); |
exec('sed -i '.escapeshellarg("s/^LDAP_PASSWORD=.*/LDAP_PASSWORD=$ldap_password/g").' '.CONF_FILE); |
exec('sed -i '.escapeshellarg("s/^LDAP_SSL=.*/LDAP_SSL=$ldap_ssl/g").' '.CONF_FILE); |
exec('sed -i '.escapeshellarg("s/^LDAP_CERT_REQUIRED=.*/LDAP_CERT_REQUIRED=$ldap_cert_required/g").' '.CONF_FILE); |
if (isset($ldap_cert_required)) { |
exec('sed -i '.escapeshellarg("s/^LDAP_CERT_REQUIRED=.*/LDAP_CERT_REQUIRED=$ldap_cert_required/g").' '.CONF_FILE); |
} |
exec('sed -i \'s/^LDAP=.*/LDAP=on/g\' '.CONF_FILE); |
if (isset($ldap_cert) && ($ldap_cert['error'] === UPLOAD_ERR_OK)) { |
exec('sudo /usr/local/bin/alcasar-ldap.sh --import-cert '.escapeshellarg($ldap_cert['tmp_name'])); |
231,11 → 384,32 |
} |
exec('sudo /usr/local/bin/alcasar-ldap.sh --on'); |
$messages .= '<span style="font-weight: bold; color: green;">'.$l_ldap_update.'</span><br>'; |
|
if ((isset($_POST['ad_dns_domain'])) && ($_POST['ad_dns_domain'] !== $conf['INT_DNS_DOMAIN'])) { |
if (filter_var($ldap_server, FILTER_VALIDATE_IP) !== false) { |
$ldap_server_ip = $ldap_server; |
} else { |
$ldap_server_ip = gethostbyname($ldap_server); |
} |
if (filter_var($ldap_server_ip, FILTER_VALIDATE_IP) !== false) { |
file_put_contents(CONF_FILE, str_replace('INT_DNS_IP='.$conf['INT_DNS_IP'], 'INT_DNS_IP='.$ldap_server_ip, file_get_contents(CONF_FILE))); |
file_put_contents(CONF_FILE, str_replace('INT_DNS_DOMAIN='.$conf['INT_DNS_DOMAIN'], 'INT_DNS_DOMAIN='.$_POST['ad_dns_domain'], file_get_contents(CONF_FILE))); |
if (!empty($_POST['ad_dns_domain'])) { |
exec('sudo /usr/local/bin/alcasar-dns-local.sh --on'); |
} else { |
exec('sudo /usr/local/bin/alcasar-dns-local.sh --off'); |
} |
} |
} |
} |
} else { |
exec('sed -i "s/^LDAP=.*/LDAP=off/g" '.CONF_FILE); |
exec('sudo /usr/local/bin/alcasar-ldap.sh --off'); |
$messages .= '<span style="font-weight: bold; color: green;">'.$l_ldap_update.'</span><br>'; |
|
if ((isset($_POST['ad_dns_domain'])) && (empty($_POST['ad_dns_domain']))) { |
exec('sudo /usr/local/bin/alcasar-dns-local.sh --off'); |
} |
} |
|
// Reload configuration |
264,7 → 438,7 |
$ldap_ssl = ($conf['LDAP_SSL'] === 'on'); |
$ldap_cert_required = ($conf['LDAP_CERT_REQUIRED'] === 'on'); |
|
$ldap_cert_subject = NULL; |
$ldap_cert_subject = null; |
if (file_exists($LDAPS_CERT_LOC)) { |
$certificateInfos = openssl_x509_parse(file_get_contents($LDAPS_CERT_LOC)); |
if (preg_match_all('@/[a-zA-Z]+=([^/]+)@', $certificateInfos['name'], $matches)) { |
295,7 → 469,7 |
if (($ldap_cert_required) && isset($ldap_cert) && ($ldap_cert['error'] === UPLOAD_ERR_OK)) { |
$ldap_cert_tmpFilename = $ldap_cert['tmp_name']; |
} else { |
$ldap_cert_tmpFilename = NULL; |
$ldap_cert_tmpFilename = null; |
} |
|
if (!empty($varErrors)) { |
366,10 → 540,10 |
} |
formSubmit.style.display = 'none'; |
btn_checkConf.style.display = null; |
<?php if (PHP_VERSION_ID < 70100): ?> |
<?php if (PHP_VERSION_ID < 70100): ?> |
// Compatibility with PHP < 7.1.0 # TODO : remove if ever Mageia 7 is released |
formSubmit.style.display = null; |
<?php endif; ?> |
<?php endif; ?> |
} else { |
for (var i=0; i<listToDisables.length; i++) { |
document.getElementById(listToDisables[i]).style.backgroundColor = '#c0c0c0'; |
428,10 → 602,10 |
formSubmit.style.display = 'none'; |
btn_checkConf.style.display = null; |
} |
<?php if (PHP_VERSION_ID < 70100): ?> |
<?php if (PHP_VERSION_ID < 70100): ?> |
// Compatibility with PHP < 7.1.0 # TODO : remove if ever Mageia 7 is released |
formSubmit.style.display = null; |
<?php endif; ?> |
<?php endif; ?> |
|
if (typeof data.errors !== 'undefined') { |
messages = '<span style=\"color: red\">' + data.errors.join('</span><br><span style=\"color: red\">') + '</span><br>'; |
449,6 → 623,67 |
xhr.open('POST', 'ldap.php?conf_check', true); |
xhr.send(post_data); |
} |
|
function launchAssistant() { |
var messagesElem = document.querySelector('fieldset > legend > div'); |
var dom_ldap_server = document.getElementById('ldap_server'); |
var dom_ldap_ssl = document.getElementById('ldap_ssl'); |
var dom_ldap_cert_required = document.getElementById('ldap_cert_required'); |
var dom_ldap_dn = document.getElementById('ldap_dn'); |
var dom_ldap_uid = document.getElementById('ldap_uid'); |
var dom_ad_dns_domain = document.getElementById('ad_dns_domain'); |
post_data = 'ldap_server='+dom_ldap_server.value; |
|
var xhr = new XMLHttpRequest(); |
xhr.onreadystatechange = function() { |
if (this.readyState == 4) { |
if (this.status == 200) { |
var data = JSON.parse(this.responseText); |
var messages = ''; |
|
if (typeof data.result !== 'undefined') { |
if (data.result === -2) { |
messages += "<span style=\"color: red\"><?= $l_ldap_test_service_failed ?></span>"; |
} else if (data.result === -1) { |
messages += "<br><span style=\"color: red\"><?= $l_ldap_test_connection_failed ?></span>"; |
} else if (data.result === 0) { |
if ((typeof data.values.int_dns_domain !== 'undefined') && (dom_ad_dns_domain.value === '')) { |
dom_ad_dns_domain.value = data.values.int_dns_domain |
} |
if ((typeof data.values.ldap_base_dn !== 'undefined') && (dom_ldap_dn.value === '')) { |
dom_ldap_dn.value = data.values.ldap_base_dn |
} |
if (dom_ldap_uid.value === '') { |
if (data.values.isAD === true) { |
dom_ldap_uid.value = 'sAMAccountName'; |
} else { |
dom_ldap_uid.value = 'uid'; |
} |
} |
if (data.values.ldap_srv_636 === true) { |
dom_ldap_ssl.value = 'on' |
if ((typeof data.values.ldap_server_domain !== 'undefined') && (dom_ldap_cert_required.value === 'on')) { |
dom_ldap_server.value = data.values.ldap_server_domain |
} |
} else { |
if (dom_ldap_ssl.value === 'on') { |
dom_ldap_ssl.value = 'off'; |
} |
} |
onLdapStatusChange(); |
} |
} |
|
messagesElem.innerHTML = messages; |
} else { |
messagesElem.innerHTML = 'server error'; |
} |
} |
}; |
xhr.open('POST', 'ldap.php?assistant', true); |
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); |
xhr.send(post_data); |
} |
</script> |
</head> |
<body onLoad="onLdapStatusChange();"> |
482,34 → 717,41 |
<?= $l_ldap_server_text ?> |
</dt> |
<dd> |
<input type="text" id="ldap_server" size="40" name="ldap_server" value="<?= htmlspecialchars($ldap_server) ?>" oninput="onLdapStatusChange();"> |
<input type="text" id="ldap_server" size="40" name="ldap_server" value="<?= htmlspecialchars($ldap_server) ?>" oninput="onLdapStatusChange();"> <button onclick="launchAssistant(); return false;"><?= 'Assistant' ?></button> |
</dd> |
</dl> |
<dl> |
<dt> |
<label for="ldap_dn"><?= $l_ldap_base_dn_label ?></label><br> |
<?= $l_ldap_base_dn_text ?> |
<label for="ldap_ssl"><?= $l_ldap_ssl_label ?></label><br> |
<?= $l_ldap_ssl_text ?><br> |
</dt> |
<dd> |
<input type="text" id="ldap_dn" size="40" name="ldap_base_dn" value="<?= htmlspecialchars($ldap_base_dn) ?>" oninput="onLdapStatusChange();"> |
<select id="ldap_ssl" name="ldap_ssl" onchange="onLdapStatusChange();"> |
<option value="on"<?= ($ldap_ssl) ? ' selected="selected"' : '' ?>><?= $l_ldap_YES ?></option> |
<option value="off"<?= (!$ldap_ssl) ? ' selected="selected"' : '' ?>><?= $l_ldap_NO ?></option> |
</select> |
</dd> |
</dl> |
<dl> |
<dt> |
<label for="ldap_uid"><?= $l_ldap_uid_label ?></label><br> |
<?= $l_ldap_uid_text ?> |
<label for="ldap_cert_required"><?= $l_ldap_cert_required_label ?></label><br> |
<?= $l_ldap_cert_required_text ?><br> |
</dt> |
<dd> |
<input type="text" id="ldap_uid" size="40" name="ldap_uid" value="<?= htmlspecialchars($ldap_uid) ?>" oninput="onLdapStatusChange();"> |
<select id="ldap_cert_required" name="ldap_cert_required" onchange="onLdapStatusChange();"> |
<option value="on"<?= ($ldap_cert_required) ? ' selected="selected"' : '' ?>><?= $l_ldap_YES ?></option> |
<option value="off"<?= (!$ldap_cert_required) ? ' selected="selected"' : '' ?>><?= $l_ldap_NO ?></option> |
</select> |
</dd> |
</dl> |
<dl> |
<dt> |
<label for="ldap_base_filter"><?= $l_ldap_base_filter_label ?></label><br> |
<?= $l_ldap_base_filter_text ?> |
<label for="ldap_cert"><?= $l_ldap_cert_label ?></label><br> |
<?= $l_ldap_cert_text ?><br> |
<?= (($ldap_cert_subject) ? "$l_ldap_cert_status_cur $ldap_cert_subject" : $l_ldap_cert_status_no ) ?> |
</dt> |
<dd> |
<input type="text" id="ldap_base_filter" size="40" name="ldap_base_filter" value="<?= htmlspecialchars($ldap_base_filter) ?>" oninput="onLdapStatusChange();"> |
<input type="file" id="ldap_cert" name="ldap_cert" oninput="onLdapStatusChange();"> |
</dd> |
</dl> |
<dl> |
532,38 → 774,40 |
</dl> |
<dl> |
<dt> |
<label for="ldap_ssl"><?= $l_ldap_ssl_label ?></label><br> |
<?= $l_ldap_ssl_text ?><br> |
<label for="ldap_dn"><?= $l_ldap_base_dn_label ?></label><br> |
<?= $l_ldap_base_dn_text ?> |
</dt> |
<dd> |
<select id="ldap_ssl" name="ldap_ssl" onchange="onLdapStatusChange();"> |
<option value="on"<?= ($ldap_ssl) ? ' selected="selected"' : '' ?>><?= $l_ldap_YES ?></option> |
<option value="off"<?= (!$ldap_ssl) ? ' selected="selected"' : '' ?>><?= $l_ldap_NO ?></option> |
</select> |
<input type="text" id="ldap_dn" size="40" name="ldap_base_dn" value="<?= htmlspecialchars($ldap_base_dn) ?>" oninput="onLdapStatusChange();"> |
</dd> |
</dl> |
<dl> |
<dt> |
<label for="ldap_cert_required"><?= $l_ldap_cert_required_label ?></label><br> |
<?= $l_ldap_cert_required_text ?><br> |
<label for="ldap_uid"><?= $l_ldap_uid_label ?></label><br> |
<?= $l_ldap_uid_text ?> |
</dt> |
<dd> |
<select id="ldap_cert_required" name="ldap_cert_required" onchange="onLdapStatusChange();"> |
<option value="on"<?= ($ldap_cert_required) ? ' selected="selected"' : '' ?>><?= $l_ldap_YES ?></option> |
<option value="off"<?= (!$ldap_cert_required) ? ' selected="selected"' : '' ?>><?= $l_ldap_NO ?></option> |
</select> |
<input type="text" id="ldap_uid" size="40" name="ldap_uid" value="<?= htmlspecialchars($ldap_uid) ?>" oninput="onLdapStatusChange();"> |
</dd> |
</dl> |
<dl> |
<dt> |
<label for="ldap_cert"><?= $l_ldap_cert_label ?></label><br> |
<?= $l_ldap_cert_text ?><br> |
<?= (($ldap_cert_subject) ? "$l_ldap_cert_status_cur $ldap_cert_subject" : $l_ldap_cert_status_no ) ?> |
<label for="ldap_base_filter"><?= $l_ldap_base_filter_label ?></label><br> |
<?= $l_ldap_base_filter_text ?> |
</dt> |
<dd> |
<input type="file" id="ldap_cert" name="ldap_cert" oninput="onLdapStatusChange();"> |
<input type="text" id="ldap_base_filter" size="40" name="ldap_base_filter" value="<?= htmlspecialchars($ldap_base_filter) ?>" oninput="onLdapStatusChange();"> |
</dd> |
</dl> |
<dl> |
<dt> |
<label for="ad_dns_domain"><?= $l_ad_dns_domain_label ?></label><br> |
<?= $l_ad_dns_domain_text ?> |
</dt> |
<dd> |
<input type="text" id="ad_dns_domain" size="40" name="ad_dns_domain" value="<?= htmlspecialchars($conf['INT_DNS_DOMAIN']) ?>" oninput="onLdapStatusChange();"> |
</dd> |
</dl> |
<p> |
<button id="btn-checkconf" onclick="checkConfig(); return false;"><?= $l_check ?></button> |
<input id="submit" type="submit" value="<?= $l_ldap_submit ?>" name="submit"> |