Blame | Last modification | View Log
<?php
# $Id: mail.php 2853 2020-07-19 21:50:07Z joss_p $
/* written by Joss_p */
/****************************************************************
* GLOBAL FILE PATHS *
*****************************************************************/
define('CONF_FILE', '/usr/local/etc/alcasar-mail.conf');
/****************************************************************
* FILE reading test *
*****************************************************************/
$conf_files = array(CONF_FILE);
foreach ($conf_files as $file) {
if (!file_exists($file)) {
exit("Fichier $file non présent");
}
if (!is_readable($file)) {
exit("Vous n'avez pas les droits de lecture sur le fichier $file");
}
}
/****************************************************************
* Read CONF_FILE *
*****************************************************************/
$file_conf = fopen(CONF_FILE, 'r');
if (!$file_conf) {
exit('Error opening the file '.CONF_FILE);
}
while (!feof($file_conf)) {
$buffer = fgets($file_conf, 4096);
if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
$tmp = explode('=', $buffer, 2);
$conf[trim($tmp[0])] = trim($tmp[1]);
}
}
fclose($file_conf);
/****************************************************************
* Choice of language *
*****************************************************************/
$Language = 'en';
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$Langue = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
$Language = strtolower(substr(chop($Langue[0]), 0, 2));
}
if ($Language === 'fr') {
$l_ldap_update = "Mise à jour des paramètres LDAP effectuée";
$l_mail_title = "Authentification externe : Adresse mail";
$l_ldap_legend = "Authentification LDAP";
$l_mail_auth_enable_label = "Activer l'authentification par mail :";
$l_mail_YES = "OUI";
$l_mail_NO = "NON";
$l_ldap_server_label = "Serveur LDAP:";
$l_ldap_server_text = "Adresse IP du serveur";
$l_ldap_base_dn_label = "DN de la base:";
$l_ldap_base_dn_text = "Le DN (Distinguished Name) définit où se situent les informations des utilisateurs dans l'annuaire.<br> - Exemple LDAP: 'o=mycompany, c=FR'.<br> - Exemple AD 'cn=Users,dc=server_name,dc=localdomain'";
$l_ldap_uid_label = "Identifiant d'utilisateur (UID):";
$l_ldap_uid_text = "Clé utilisée pour rechercher un identifiant de connexion.<br> - Exemple LDAP: 'uid', 'sn', etc.<br> - Pour A.D. mettre 'sAMAccountName'.";
$l_ldap_base_filter_label = "Filtre de recherche des utilisateurs (optionnel):";
$l_ldap_base_filter_text = "Vous pouvez limiter les objets recherchés avec des filtres additionnels.<br> Exemple 'objectClass=posixGroup' ajouterait le filtre '(&(uid=username)(objectClass=posixGroup))'";
$l_ldap_user_label = "CN de l'utilisateur exploité par ALCASAR:";
$l_ldap_user_text = "CN=Common Name. Laissez vide pour utiliser un accès invité (ou anonyme). Obligatoire sur un AD.<br> - Exemple LDAP : 'uid=username,ou=my_lan,o=mycompany,c=FR'.<br> - Exemple AD : 'username' ou 'cn=username,cn=Users,dc=server_name,dc=localdomain'";
$l_ldap_password_label = "Mot de passe:";
$l_ldap_password_text = "Laissez vide pour un accès invité (ou anonyme). Obligatoire sur un AD.";
$l_ldap_ssl_label = "Connexion chiffré";
$l_mail_type_text = "Utiliser une connexion chiffré avec SSL (LDAPS)";
$l_ldap_cert_required_label = "Vérifier le certificat SSL";
$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_mail_submit = "Enregistrer";
$l_ldap_test_service_failed = "Service LDAP injoignable sur ce serveur (vérifiez l'@IP).";
$l_ldap_test_service_ok = "Un port 389 (636 avec SSL) est actif sur ce serveur";
$l_ldap_test_connection_failed = "Connexion LDAP impossible (vérifiez le service LDAP sur ce serveur)";
$l_ldap_test_connection_ok = "Une connexion LDAP a été établie";
$l_ldap_test_bind_failed = "Echec d'authentification (vérifiez l'utilisateur et le mot de passe)";
$l_ldap_test_bind_ok = "L'authentification a réussie";
$l_ldap_test_dn_failed = "Le DN de la base semble incorrect (vérifiez le)";
$l_ldap_test_dn_ok = "Le DN de la base semble correct";
$l_ldap_error = "erreur LDAP";
$l_ldap_entries = "entrées dans la base";
$l_ldap_cert_cn_diff_dn = "Le CommonName du certificat (§cert_domainName§) est différent du nom de domaine du serveur";
$l_check = "Vérifier cette configuration";
$l_checkingConf = "Vérification de cette configuration...";
} else {
$l_ldap_update = "LDAP settings updated";
$l_mail_title = "External authentication : Address mail";
$l_ldap_legend = "LDAP authentication";
$l_mail_auth_enable_label = "Enable email authentication :";
$l_mail_YES = "YES";
$l_mail_NO = "NO";
$l_ldap_server_label = "LDAP server :";
$l_ldap_server_text = "IP address of the LDAP server.";
$l_ldap_base_dn_label = "DN of the base:";
$l_ldap_base_dn_text = "The DN (Distinguished Name) is used to locate the users information in the directory.<br> e.g. LDAP : 'o=MyCompany,c=US'.<br> e.g. AD : 'cn=Users,dc=server_name,dc=localdomain'";
$l_ldap_uid_label = "User IDentifier (UID):";
$l_ldap_uid_text = "Key used to search for a given login identity.<br>e.g. 'uid', 'sn', etc.. For AD use 'sAMAccountName'.";
$l_ldap_base_filter_label = "User search filter (optional):";
$l_ldap_base_filter_text = "You can further limit the searched objects with additional filters.<br> For example 'objectClass=posixGroup' would result in the use of '(&(uid=username)(objectClass=posixGroup))'";
$l_ldap_user_label = "CN of the user operated by ALCASAR:";
$l_ldap_user_text = "CN=Common Name. Leave blank to use anonymous binding. Mandatory for AD.<br> e.g. LDAP :'uid=Username,ou=my_lan,o=mycompany,c=US'.<br> e.g. AD : 'username' or 'cn=username,cn=Users,dc=server_name,dc=localdomain'";
$l_ldap_password_label = "Password:";
$l_ldap_password_text = "Leave blank to use anonymous binding. Mandatory for AD.";
$l_ldap_ssl_label = "Secure connection";
$l_mail_type_text = "Use an encrypted connection with SSL (LDAPS)";
$l_ldap_cert_required_label = "Check the SSL certificate";
$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_mail_submit = "Save";
$l_ldap_test_service_failed = "LDAP service is not reachable on that server (check IP)";
$l_ldap_test_service_ok = "A port 389 (636 with SSL) is open on this server";
$l_ldap_test_connection_failed = "LDAP connexion failed (check the LDAP service on this server)";
$l_ldap_test_connection_ok = "A LDAP connexion is established";
$l_ldap_test_bind_failed = "LDAP authentication failed (check the LDAP user and password)";
$l_ldap_test_bind_ok = "Successful authentication";
$l_ldap_test_dn_failed = "DN of the base seems to be wrong (check it)";
$l_ldap_test_dn_ok = "DN of the base seems to be ok";
$l_ldap_error = "LDAP error";
$l_ldap_entries = "entries in the base";
$l_ldap_cert_cn_diff_dn = "Certificate CommonName (§cert_domainName§) is different from the server domain name";
$l_check = "Check this config";
$l_checkingConf = "Checking this configuration...";
}
// Mail configuration params
$mail_status = $conf['MAIL'];
$mail_type = $conf['TYPE_MAIL'];
$mail_address_mail = $conf['mailAddr'];
$mail_smtp = $conf['smtp'];
$mail_port = $conf['port'];
$mail_address_ip = $conf['mailIP'];
$mail_server = "";
$mail_password_mail = "";
$mail_password_mail_2 = "";
$admin_address = $conf['adminMail'];
$mail_whitelist = $conf['whiteDomain'];
if(isset($_POST['submit'])){
if($_POST['auth_enable'] === '1')
{
exec("systemctl start postfix");
$mail_status = $_POST['auth_enable'];
$mail_type = $_POST['mail_type'];
$mail_address = $_POST['mail_address'];
$mail_ip = $_POST['mail_ip'];
$mail_server = $_POST['mail_server'];
$mail_mdp = $_POST['mail_mdp'];
$mail_mdp2 = $_POST['mail_mdp2'];
$admin_enable = $_POST['admin_enable'];
$admin_address = $_POST['admin_address'];
$mail_whitelist = $_POST['mail_whitelist'];
exec("cp /var/www/mail/header.php /var/www/html");
exec("cp /var/www/mail/inscription.php /var/www/html");
exec("cp /var/www/mail/inscription_traitement.php /var/www/html");
exec("cp /var/www/html/acc/admin/services.php /var/www/html/acc/admin/services.php.origin");
exec("cp /var/www/mail/services.php /var/www/html/acc/admin");
if ($mail_mdp == $mail_mdp2) {
switch ($mail_server) {
case '1':
$mail_smtp = "smtp.orange.fr";
$mail_port = 465;
break;
case '2':
$mail_smtp = "smtp.live.com";
$mail_port = 587;
break;
case '3':
$mail_smtp = "smtp.office365.com";
$mail_port = 587;
break;
case '4':
$mail_smtp = "smtp.sfr.fr";
$mail_port = 465;
break;
case '5':
$mail_smtp = "smtp.free.fr";
$mail_port = 465;
break;
case '6':
$mail_smtp = "smtp.gmail.com";
$mail_port = 587;
break;
case '7':
$mail_smtp = "smtp.laposte.net";
$mail_port = 465;
break;
case '8':
$mail_smtp = "smtp.bbox.fr";
$mail_port = 587;
break;
default:
echo "Erreur dans la saisie !";
break;
}
file_put_contents(CONF_FILE, str_replace('MAIL='.$conf['MAIL'],'MAIL='.$mail_status,file_get_contents(CONF_FILE)));
file_put_contents(CONF_FILE, str_replace('TYPE_MAIL='.$conf['TYPE_MAIL'],'TYPE_MAIL='.$mail_type,file_get_contents(CONF_FILE)));
file_put_contents(CONF_FILE, str_replace('mailAddr='.$conf['mailAddr'],'mailAddr='.$mail_address,file_get_contents(CONF_FILE)));
file_put_contents(CONF_FILE, str_replace('mailIP='.$conf['mailIP'],'mailIP='.$mail_ip,file_get_contents(CONF_FILE)));
file_put_contents(CONF_FILE, str_replace('smtp='.$conf['smtp'],'smtp='.$mail_smtp,file_get_contents(CONF_FILE)));
file_put_contents(CONF_FILE, str_replace('port='.$conf['port'],'port='.$mail_port,file_get_contents(CONF_FILE)));
file_put_contents(CONF_FILE, str_replace('whiteDomain='.$conf['mail_whitelist'],'whiteDomain='.$mail_whitelist,file_get_contents(CONF_FILE)));
if (isset($admin_address)) {
file_put_contents(CONF_FILE, str_replace('adminMail='.$conf['admin_address'],'adminMail='.$admin_address,file_get_contents(CONF_FILE)));
}
switch ($mail_type) {
case '1':
$mail_port = 25;
file_put_contents(CONF_FILE, str_replace('port='.$conf['port'],'port='.$mail_port,file_get_contents(CONF_FILE)));
if(isset($mail_admin)){
exec("sudo /usr/bin/bash /usr/local/bin/alcasar-mail-install-V2.sh -1 -a $admin_address -w $mail_whitelist");
}
else {
exec("sudo /usr/bin/bash /usr/local/bin/alcasar-mail-install-V2.sh -1 -w $mail_whitelist");
}
break;
case '2':
if(isset($mail_admin)){
exec("sudo /usr/bin/bash /usr/local/bin/alcasar-mail-install-V2.sh -2 -s $mail_smtp -p $mail_port -r $mail_ip -a $admin_address -w $mail_whitelist");
}
else {
exec("sudo /usr/bin/bash /usr/local/bin/alcasar-mail-install-V2.sh -2 -s $mail_smtp -p $mail_port -r $mail_ip -w $mail_whitelist");
}
break;
case '3':
if(isset($mail_admin)){
exec("sudo /usr/bin/bash /usr/local/bin/alcasar-mail-install-V2.sh -3 -s $mail_smtp -p $mail_port -m $mail_address -o $mail_mdp -a $admin_address -w $mail_whitelist");
}
else {
exec("sudo /usr/bin/bash /usr/local/bin/alcasar-mail-install-V2.sh -3 -s $mail_smtp -p $mail_port -m $mail_address -o $mail_mdp -w $mail_whitelist");
}
break;
default:
echo "Erreur dans la saisie !";
break;
}
}
else {
echo "Erreur";
}
}
else {
exec("cp -f /etc/postfix/main.cf.origin /etc/postfix/main.cf");
exec("rm -rf /etc/postfix/sasl/");
exec("cp -f /var/www/mail/alcasar-mail.conf /usr/local/etc/");
exec("systemctl restart postfix");
exec("systemctl stop postfix");
exec("sed -i '/SMTP_IP=/ s/^/#/g' /usr/local/etc/alcasar-iptables-local.sh");
exec("sed -i '/SMTP_PORT=/ s/^/#/g' /usr/local/etc/alcasar-iptables-local.sh");
exec("rm -f /var/www/html/header.php");
exec("rm -f /var/www/html/inscription.php");
exec("rm -f /var/www/html/inscription_traitement.php");
exec("cp -f /var/www/html/acc/admin/services.php.origin /var/www/html/acc/admin/services.php");
exec("sudo /usr/bin/bash /usr/local/bin/alcasar-iptables.sh");
}
header("Refresh:0");
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><?= $l_mail_title ?></title>
<link type="text/css" href="/css/acc.css" rel="stylesheet">
<link type="text/css" href="/css/mail.css" rel="stylesheet">
<script>
function onMailStatusChange() {
var listToDisables1 = ['mail_type','admin_enable','admin_address','mail_whitelist'];
var listToDisables2 = ['mail_server','mail_type','admin_enable','admin_address','mail_whitelist','mail_ip'];
var listToDisables3 = ['mail_server','mail_mdp2','mail_mdp','mail_address','mail_type','admin_enable','admin_address','mail_whitelist'];
var formSubmit = document.querySelector('form input[type="submit"]');
var btn_checkConf = document.getElementById('btn-checkconf');
var isChecked = false;
if (document.getElementById('auth_enable').value === '1') {
for (var i=0; i<listToDisables1.length; i++) {
document.getElementById(listToDisables1[i]).style.backgroundColor = '#c0c0c0';
document.getElementById(listToDisables1[i]).disabled = true;
}
for (var i=0; i<listToDisables2.length; i++) {
document.getElementById(listToDisables2[i]).style.backgroundColor = '#c0c0c0';
document.getElementById(listToDisables2[i]).disabled = true;
}
for (var i=0; i<listToDisables3.length; i++) {
document.getElementById(listToDisables3[i]).style.backgroundColor = '#c0c0c0';
document.getElementById(listToDisables3[i]).disabled = true;
}
document.getElementById('mail_type').style.backgroundColor = null;
document.getElementById('mail_type').disabled = false;
if (document.getElementById('mail_type').value === '1') {
for (var i=0; i<listToDisables1.length; i++) {
document.getElementById(listToDisables1[i]).style.backgroundColor = null;
document.getElementById(listToDisables1[i]).disabled = false;
}
if (document.getElementById('admin_enable').value === '0') {
document.getElementById('admin_address').style.backgroundColor = '#c0c0c0';
document.getElementById('admin_address').disabled = true;
}
}
else if (document.getElementById('mail_type').value === '2') {
for (var i=0; i<listToDisables2.length; i++) {
document.getElementById(listToDisables2[i]).style.backgroundColor = null;
document.getElementById(listToDisables2[i]).disabled = false;
}
if (document.getElementById('admin_enable').value === '0') {
document.getElementById('admin_address').style.backgroundColor = '#c0c0c0';
document.getElementById('admin_address').disabled = true;
}
}
else if (document.getElementById('mail_type').value === '3') {
for (var i=0; i<listToDisables3.length; i++) {
document.getElementById(listToDisables3[i]).style.backgroundColor = null;
document.getElementById(listToDisables3[i]).disabled = false;
}
if (document.getElementById('admin_enable').value === '0') {
document.getElementById('admin_address').style.backgroundColor = '#c0c0c0';
document.getElementById('admin_address').disabled = true;
}
}
formSubmit.style.display = null;
btn_checkConf.style.display = 'none';
} else {
for (var i=0; i<listToDisables1.length; i++) {
document.getElementById(listToDisables1[i]).style.backgroundColor = '#c0c0c0';
document.getElementById(listToDisables1[i]).disabled = true;
}
for (var i=0; i<listToDisables2.length; i++) {
document.getElementById(listToDisables2[i]).style.backgroundColor = '#c0c0c0';
document.getElementById(listToDisables2[i]).disabled = true;
}
for (var i=0; i<listToDisables3.length; i++) {
document.getElementById(listToDisables3[i]).style.backgroundColor = '#c0c0c0';
document.getElementById(listToDisables3[i]).disabled = true;
}
formSubmit.style.display = null;
btn_checkConf.style.display = 'none';
}
}
</script>
</head>
<body onLoad="onMailStatusChange();">
<div class="panel">
<div class="panel-header"><?= "Authentication Mail" ?></div>
<div class="panel-body">
<form id="form-config_mail" name="config_mail" method="POST" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" enctype="multipart/form-data">
<fieldset>
<legend>
<br>
<div style="text-align: center">
</div>
</legend>
<dl>
<dt>
<label for="auth_enable"><?= "Activer l'authentification par mail :" ?></label>
</dt>
<dd>
<select id="auth_enable" name="auth_enable" onchange="onMailStatusChange();">
<option value="1"<?= ($mail_status) ? ' selected="selected"' : '' ?>><?= $l_mail_YES ?></option>
<option value="0"<?= (!$mail_status) ? ' selected="selected"' : '' ?>><?= $l_mail_NO ?></option>
</select>
</dd>
</dl>
<dl>
<dt>
<label for="mail_type"><?= "Type Messagerie" ?></label><br>
<?= "Choississez le type de messagerie a utiliser" ?><br>
</dt>
<dd>
<select id="mail_type" name="mail_type" onchange="onMailStatusChange();">
<option value=1>Nom de domaine</option>
<option value=2>Serveur mail ou serveur SMTP</option>
<option value=3>Adresse de messagerie</option>
</select>
</dd>
</dl>
<dl>
<dt>
<label for="mail_address"><?= "Adresse Messagerie"?></label><br>
<?= "Adresse de messagerie utilisé pour l'envoi" ?>
</dt>
<dd>
<input type="text" id="mail_address" size="40" name="mail_address" value="<?= $mail_address_mail ?>" oninput="onMailStatusChange();">
</dd>
</dl>
<dl>
<dt>
<label for="mail_mdp"><?= "Mot de passe Messagerie"?></label><br>
<?= "Mot de passe de la messagerie utilisé pour l'envoi" ?>
</dt>
<dd>
<input type="text" id="mail_mdp" size="40" name="mail_mdp" value="<?= $mail_password_mail ?>" oninput="onMailStatusChange();">
</dd>
</dl>
<dl>
<dt>
<label for="mail_mdp2"><?= "Confirmer Mot de passe Messagerie"?></label><br>
<?= "Confirmer le mot de passe de la messagerie utilisé pour l'envoi" ?>
</dt>
<dd>
<input type="text" id="mail_mdp2" size="40" name="mail_mdp2" value="<?= $mail_password_mail_2 ?>" oninput="onMailStatusChange();">
</dd>
</dl>
<dl>
<dt>
<label for="mail_server"><?= "CHoix Serveur SMTP" ?></label><br>
<?= "Choissisiez le serveur SMTP correspondant à l'adress de messagerie" ?><br>
</dt>
<dd>
<select id="mail_server" name="mail_server" onchange="onMailStatusChange();">
<option value=1>Orange/Wanadoo</option>
<option value=2>Hotmail</option>
<option value=3>Outlook</option>
<option value=4>SFR</option>
<option value=5>Free</option>
<option value=6>Gmail</option>
<option value=7>Laposte</option>
<option value=8>Bouygues</option>
<option value=9>Personnalisé</option>
</select>
</dd>
</dl>
<dl>
<dt>
<label for="mail_ip"><?= "IP du serveur SMTP"?></label><br>
<?= "Adresse IP du serveur SMTP utilisé" ?>
</dt>
<dd>
<input type="text" id="mail_ip" size="40" name="mail_ip" value="<?= $mail_address_ip ?>" oninput="onMailStatusChange();">
</dd>
</dl>
<dl>
<dt>
<label for="admin_enable"><?= "Activer l'adresse admin :" ?></label>
</dt>
<dd>
<select id="admin_enable" name="admin_enable" onchange="onMailStatusChange();">
<option value="1"<?= ($mail_status) ? ' selected="selected"' : '' ?>><?= $l_mail_YES ?></option>
<option value="0"<?= (!$mail_status) ? ' selected="selected"' : '' ?>><?= $l_mail_NO ?></option>
</select>
</dd>
</dl>
<dl>
<dt>
<label for="admin_address"><?= "Adresse Messagerie admin"?></label><br>
<?= "Adresse de messagerie utilisé pour l'envoi" ?>
</dt>
<dd>
<input type="text" id="admin_address" size="40" name="admin_address" value="<?= $admin_address ?>" oninput="onMailStatusChange();">
</dd>
</dl>
<dl>
<dt>
<label for="mail_whitelist"><?= "whitelist domaine"?></label><br>
<?= "Adresse de messagerie utilisé pour l'envoi" ?>
</dt>
<dd>
<input type="text" id="mail_whitelist" size="40" name="mail_whitelist" value="<?= $mail_whitelist ?>" oninput="onMailStatusChange();">
</dd>
</dl>
<p>
<!--<button id="btn-checkconf" onclick="checkConfig(); return false;"><?= $l_check ?></button>-->
<input id="submit" type="submit" value="<?= $l_mail_submit ?>" name="submit">
</p>
</fieldset>
</form>
</div>
</div>
</body>
</html>