Subversion Repositories ALCASAR

Rev

Rev 3062 | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
2991 rexy 1
<?php
2992 rexy 2
# $Id: mail.php 2853 2020-07-19 21:50:07Z joss_p $
2991 rexy 3
 
2992 rexy 4
/* written by Joss_p & Rexy */
5
/****************************************************************
6
*			GLOBAL FILE PATHS			*
7
*****************************************************************/
2993 rexy 8
define('CONF_FILE', '/usr/local/etc/alcasar.conf');
2992 rexy 9
/****************************************************************
2993 rexy 10
*			Conf files reading test			*
2992 rexy 11
*****************************************************************/
12
$conf_files = array(CONF_FILE);
13
foreach ($conf_files as $file) {
14
	if (!file_exists($file)) {
15
		exit("Fichier $file non présent");
2991 rexy 16
	}
2992 rexy 17
	if (!is_readable($file)) {
18
		exit("Vous n'avez pas les droits de lecture sur le fichier $file");
2991 rexy 19
	}
20
}
21
/****************************************************************
2992 rexy 22
*			Read CONF_FILE				*
2991 rexy 23
*****************************************************************/
24
$file_conf = fopen(CONF_FILE, 'r');
25
if (!$file_conf) {
26
	exit('Error opening the file '.CONF_FILE);
27
}
28
while (!feof($file_conf)) {
29
	$buffer = fgets($file_conf, 4096);
30
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
31
		$tmp = explode('=', $buffer, 2);
3022 rexy 32
		$conf[trim($tmp[0])] = trim($tmp[1]);
2993 rexy 33
	}
34
}
35
fclose($file_conf);
2992 rexy 36
/****************************************
37
*			Choice of language			*
38
*****************************************/
39
$Language = 'en';
40
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
41
	$Langue	  = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
42
	$Language = strtolower(substr(chop($Langue[0]), 0, 2));
43
}
44
if ($Language === 'fr') {
3039 rexy 45
	$l_mail_title			= "Inscription par e-mail";
46
	$l_mail_registration	= "Activer l'inscription par e-mail :";
47
	$l_mail_choice			= "Quel type de service e-mail utiliser ?";
3001 rexy 48
	$l_use_internal_server	= "Utiliser le serveur de messagerie interne";
49
	$l_use_external_server	= "Relayer vers un serveur de messagerie externe";
3039 rexy 50
	$l_use_email_address	= "Utiliser une adresse e-mail déjà fonctionnelle";
51
	$l_email_address		= "Adresse e-mail utilisée pour l'envoi de mail";
3064 rexy 52
	$l_email_password		= "Mot de passe (ou 'mot de passe d'application' dans le cas de gmail)";
2993 rexy 53
	$l_email_password_confirm	= "Confirmez le mot de passe";
54
	$l_mail_service			= "Choisissez le service de messagerie";
3021 rexy 55
	$l_mail_smtp_ip			= "Adresse IP ou nom du serveur SMTP";
56
	$l_mail_smtp_port		= "Port d'écoute du serveur SMTP";
3054 franck 57
	$l_admin_log			= "Avertissement de l'administrateur";
3039 rexy 58
	$l_mail_admin			= "Adresse e-mail de l'administrateur";
3064 rexy 59
	$l_whitelist_domain		= "Nom de domaine autorisé (champ obligatoire)";
2993 rexy 60
	$l_mail_YES				= "OUI";
61
	$l_mail_NO				= "NON";
62
	$l_mail_submit			= "Enregistrer";
3022 rexy 63
} else if($Language == 'es') {
3039 rexy 64
	$l_mail_title			= "Registro por e-mail";
3022 rexy 65
	$l_mail_registration	= "Activar el registro por correo electrónico :";
66
	$l_mail_choice			= "Qué tipo de servicio de correo utiliza?";
67
	$l_use_internal_server	= "Utilizar el servidor de correo interno";
68
	$l_use_external_server	= "Retransmisión a un servidor de correo externo";
69
	$l_use_email_address	= "Utilizar una dirección de correo electrónico";
70
	$l_email_address		= "Dirección de correo electrónico utilizada para el envío de correo";
3064 rexy 71
	$l_email_password		= "Contraseña (o 'contraseña de la aplicación' en el caso de gmail)";
3022 rexy 72
	$l_email_password_confirm	= "Confirmar contraseña";
73
	$l_mail_service			= "Elija el servicio de correo";
74
	$l_mail_smtp_ip			= "Dirección IP o nombre del servidor de correo";
75
	$l_mail_smtp_port		= "Puerto de escucha del servidor de correo";
76
	$l_admin_log			= "Advertencia del administrador";
77
	$l_mail_admin			= "Dirección de correo electrónico del administrador";
3064 rexy 78
	$l_whitelist_domain		= "Nombre de dominio autorizado (obligatorio)";
3022 rexy 79
	$l_mail_YES				= "SI";
80
	$l_mail_NO				= "NO";
81
	$l_mail_submit			= "SI";
2992 rexy 82
} else {
3039 rexy 83
	$l_mail_title			= "Registration by e-mail";
84
	$l_mail_registration	= "Enable registration by e-mail :";
85
	$l_mail_choice			= "What type of e-mail service use ?";
3009 rexy 86
	$l_use_internal_server	= "Use the internal mail server";
87
	$l_use_external_server	= "Relay to an external mail server";
88
	$l_use_email_address	= "Use an email address";
2993 rexy 89
	$l_email_address		= "Email address used for sending mail";
3064 rexy 90
	$l_email_password		= "Password (or 'application password' in the case of gmail)";
2993 rexy 91
	$l_email_password_confirm	= "Confirm password";
92
	$l_mail_service			= "Choose the mail service";
3000 rexy 93
	$l_mail_smtp_ip			= "IP address or name of mail server";
3021 rexy 94
	$l_mail_smtp_port		= "Listen port of mail server";
2997 rexy 95
	$l_admin_log			= "Administrator's warning";
3001 rexy 96
	$l_mail_admin			= "Administrator Email address";
3064 rexy 97
	$l_whitelist_domain		= "Authorized domain name (required)";
2993 rexy 98
	$l_mail_YES				= "YES";
99
	$l_mail_NO				= "NO";
100
	$l_mail_submit			= "Save";
2992 rexy 101
}
2991 rexy 102
 
2992 rexy 103
// Mail configuration params
3022 rexy 104
$mail_status        	= $conf['MAIL'];
105
$mail_type				= $conf['MAIL_TYPE'];
106
$mail_smtp_ip			= $conf['MAIL_SMTP_IP'];
107
$mail_smtp_port			= $conf['MAIL_SMTP_PORT'];
3039 rexy 108
$mail_address			= $conf['MAIL_ADDR'];
109
$mail_mdp			 	= "";
110
$mail_mdp2				= "";
3022 rexy 111
$mail_admin				= $conf['MAIL_ADMIN'];
112
$mail_whitelist			= $conf['MAIL_WHITEDOMAIN'];
2991 rexy 113
 
2992 rexy 114
if(isset($_POST['submit'])){
3021 rexy 115
	if($_POST['mail_enable'] === 'on')
2992 rexy 116
	{
3021 rexy 117
		$mail_type = $_POST['mail_type'];
118
		$mail_whitelist = $_POST['mail_whitelist'];
119
		$admin_enable = $_POST['admin_enable'];
120
		if(isset($_POST['mail_address']))	{ $mail_address = $_POST['mail_address']; }
121
		if(isset($_POST['mail_server']))	{ $mail_server = $_POST['mail_server']; }
122
		if(isset($_POST['mail_smtp_ip']))	{ $mail_smtp_ip = $_POST['mail_smtp_ip']; }
3022 rexy 123
		if(isset($_POST['mail_smtp_port']))	{ $mail_smtp_port = $_POST['mail_smtp_port']; }
3021 rexy 124
		if(isset($_POST['mail_mdp']))		{ $mail_mdp = $_POST['mail_mdp']; }
125
		if(isset($_POST['mail_mdp2']))		{ $mail_mdp2 = $_POST['mail_mdp2']; }
126
		if ($admin_enable == "1") { $mail_admin = $_POST['mail_admin']; }
2997 rexy 127
		switch ($mail_type) {
3022 rexy 128
			case '1': // Act as a SMTP server
3038 rexy 129
				$mail_smtp_port = 587;
3001 rexy 130
				if ($admin_enable == "1"){
131
					exec("sudo /usr/local/bin/alcasar-mail-install.sh -1 -a $mail_admin -w $mail_whitelist");
2997 rexy 132
				}
133
				else {
134
					exec("sudo /usr/local/bin/alcasar-mail-install.sh -1 -w $mail_whitelist");
135
				}
2992 rexy 136
				break;
3022 rexy 137
			case '2': // Relay to an external SMTP server
3001 rexy 138
				if ($admin_enable == "1"){
3021 rexy 139
					exec("sudo /usr/local/bin/alcasar-mail-install.sh -2 -s $mail_smtp_ip -p $mail_smtp_port -a $mail_admin -w $mail_whitelist");
2997 rexy 140
				}
141
				else {
3021 rexy 142
					exec("sudo /usr/local/bin/alcasar-mail-install.sh -2 -s $mail_smtp_ip -p $mail_smtp_port -w $mail_whitelist");
2997 rexy 143
				}
2992 rexy 144
				break;
3022 rexy 145
			case '3': // Use an user Email address
3001 rexy 146
				if(($mail_mdp != '') && ($mail_mdp==$mail_mdp2)) {
2997 rexy 147
					switch ($mail_server) {
148
						case '1':
3000 rexy 149
							$mail_smtp_ip	= "smtp.orange.fr";
3021 rexy 150
							$mail_smtp_port		= 465;
2997 rexy 151
						break;
152
						case '2':
3062 rexy 153
							$mail_smtp_ip	= "smtp.office365.com";
3021 rexy 154
							$mail_smtp_port		= 587;
2997 rexy 155
						break;
156
						case '3':
3000 rexy 157
							$mail_smtp_ip	= "smtp.sfr.fr";
3021 rexy 158
							$mail_smtp_port		= 465;
2997 rexy 159
						break;
3062 rexy 160
						case '4':
3000 rexy 161
							$mail_smtp_ip	= "smtp.free.fr";
3021 rexy 162
							$mail_smtp_port		= 465;	
2997 rexy 163
						break;
3062 rexy 164
						case '5':
3000 rexy 165
							$mail_smtp_ip	= "smtp.gmail.com";
3021 rexy 166
							$mail_smtp_port		= 587;
2997 rexy 167
						break;
3062 rexy 168
						case '6':
3000 rexy 169
							$mail_smtp_ip	= "smtp.laposte.net";
3021 rexy 170
							$mail_smtp_port		= 465;
2997 rexy 171
						break;
3062 rexy 172
						case '7':
3000 rexy 173
							$mail_smtp_ip	= "smtp.bbox.fr";
3062 rexy 174
							$mail_smtp_port		= 465;
2997 rexy 175
						break;
176
						default:
177
							echo "Erreur dans la saisie !";
178
						break;
2991 rexy 179
					}
3001 rexy 180
					if ($admin_enable == "1"){
3021 rexy 181
						exec("sudo /usr/local/bin/alcasar-mail-install.sh -3 -s $mail_smtp_ip -p $mail_smtp_port -m $mail_address -o $mail_mdp -a $mail_admin -w $mail_whitelist");
2992 rexy 182
					}
183
					else {
3021 rexy 184
						exec("sudo /usr/local/bin/alcasar-mail-install.sh -3 -s $mail_smtp_ip -p $mail_smtp_port -m $mail_address -o $mail_mdp -w $mail_whitelist");
2992 rexy 185
					}
2997 rexy 186
				}
3001 rexy 187
				else { // no password or password are not same
188
					header("Refresh:0");
2997 rexy 189
				}
190
				break;
191
			default:
192
				echo "Erreur dans la saisie !";
193
				break;
2992 rexy 194
		}
2991 rexy 195
	}
2993 rexy 196
	else { // switch email registation off
2994 rexy 197
		exec("sudo /usr/local/bin/alcasar-mail-install.sh -0");
2992 rexy 198
	}
199
	header("Refresh:0");
200
	exit;
2991 rexy 201
}
202
 
203
?>
2992 rexy 204
<!DOCTYPE html>
205
<html>
206
<head>
207
	<meta charset="UTF-8">
208
	<title><?= $l_mail_title ?></title>
209
	<link type="text/css" href="/css/acc.css" rel="stylesheet">
210
	<script>
211
	function onMailStatusChange() {
3001 rexy 212
		var listToDisables1 = ['mail_type','admin_enable','mail_admin','mail_whitelist'];
3022 rexy 213
		var listToDisables2 = ['mail_type','admin_enable','mail_admin','mail_whitelist','mail_server','mail_smtp_ip','mail_smtp_port'];
214
		var listToDisables3 = ['mail_type','admin_enable','mail_admin','mail_whitelist','mail_server','mail_smtp_ip','mail_smtp_port','mail_address','mail_mdp','mail_mdp2'];
2992 rexy 215
		var formSubmit = document.querySelector('form input[type="submit"]');
216
		var isChecked = false;
3001 rexy 217
		for (var i=0; i<listToDisables3.length; i++) {
218
			document.getElementById(listToDisables3[i]).style.backgroundColor = '#c0c0c0';
219
			document.getElementById(listToDisables3[i]).disabled = true;
220
		}
3021 rexy 221
		if (document.getElementById('mail_enable').value === 'on') {
2992 rexy 222
			document.getElementById('mail_type').style.backgroundColor = null;
223
			document.getElementById('mail_type').disabled = false;
3001 rexy 224
			if (document.getElementById('mail_type').value === '1') {
2992 rexy 225
				for (var i=0; i<listToDisables1.length; i++) {
226
				document.getElementById(listToDisables1[i]).style.backgroundColor = null;
227
				document.getElementById(listToDisables1[i]).disabled = false;
228
				}
229
				if (document.getElementById('admin_enable').value === '0') {
3001 rexy 230
				document.getElementById('mail_admin').style.backgroundColor = '#c0c0c0';
231
				document.getElementById('mail_admin').disabled = true;
2992 rexy 232
				}
233
			}
234
			else if (document.getElementById('mail_type').value === '2') {
235
				for (var i=0; i<listToDisables2.length; i++) {
236
				document.getElementById(listToDisables2[i]).style.backgroundColor = null;
237
				document.getElementById(listToDisables2[i]).disabled = false;
238
				}
239
				if (document.getElementById('admin_enable').value === '0') {
3001 rexy 240
				document.getElementById('mail_admin').style.backgroundColor = '#c0c0c0';
241
				document.getElementById('mail_admin').disabled = true;
2992 rexy 242
				}
3001 rexy 243
				if (document.getElementById('mail_server').value != '9') {
244
				document.getElementById('mail_smtp_ip').style.backgroundColor = '#c0c0c0';
245
				document.getElementById('mail_smtp_ip').disabled = true;
3022 rexy 246
				document.getElementById('mail_smtp_port').style.backgroundColor = '#c0c0c0';
247
				document.getElementById('mail_smtp_port').disabled = true;
3001 rexy 248
				}
2992 rexy 249
			}
250
			else if (document.getElementById('mail_type').value === '3') {
251
				for (var i=0; i<listToDisables3.length; i++) {
252
				document.getElementById(listToDisables3[i]).style.backgroundColor = null;
253
				document.getElementById(listToDisables3[i]).disabled = false;
254
				}
255
				if (document.getElementById('admin_enable').value === '0') {
3001 rexy 256
				document.getElementById('mail_admin').style.backgroundColor = '#c0c0c0';
257
				document.getElementById('mail_admin').disabled = true;
2992 rexy 258
				}
3001 rexy 259
				if (document.getElementById('mail_server').value != '9') {
260
				document.getElementById('mail_smtp_ip').style.backgroundColor = '#c0c0c0';
261
				document.getElementById('mail_smtp_ip').disabled = true;
3022 rexy 262
				document.getElementById('mail_smtp_port').style.backgroundColor = '#c0c0c0';
263
				document.getElementById('mail_smtp_port').disabled = true;
3001 rexy 264
				}
2992 rexy 265
			}
266
			formSubmit.style.display = null;
2991 rexy 267
		}
2992 rexy 268
	}
269
	</script>
270
</head>
271
<body onLoad="onMailStatusChange();">
3028 rexy 272
<div id="ldoverlay" class="overlay">
273
	<div class="lds-spinner" id="spinner"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>
274
</div>
2992 rexy 275
	<div class="panel">
2993 rexy 276
		<div class="panel-header"><?= $l_mail_title ?></div>
2992 rexy 277
		<div class="panel-body">
278
			<form id="form-config_mail" name="config_mail" method="POST" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" enctype="multipart/form-data">
279
				<fieldset>
280
					<legend>
281
						<br>
282
						<div style="text-align: center">
283
						</div>
284
					</legend>
285
					<dl>
286
						<dt>
3021 rexy 287
							<label for="mail_enable"><?= $l_mail_registration ?></label>
2992 rexy 288
						</dt>
289
						<dd>
3021 rexy 290
							<select id="mail_enable" name="mail_enable" onchange="onMailStatusChange();">
2997 rexy 291
								<option value="on"<?= ($mail_status == 'on') ? ' selected="selected"' : '' ?>><?= $l_mail_YES ?></option>
2993 rexy 292
								<option value="off"<?= ($mail_status == 'off') ? ' selected="selected"' : '' ?>><?= $l_mail_NO ?></option>
2992 rexy 293
							</select>
294
						</dd>
295
					</dl>
296
					<dl>
297
						<dt>
2993 rexy 298
							<label for="mail_type"><?= $l_mail_choice ?></label><br>
2992 rexy 299
						</dt>
300
						<dd>
301
							<select id="mail_type" name="mail_type" onchange="onMailStatusChange();">
3038 rexy 302
								<option value="1"<?= ($mail_type == '1') ? ' selected="selected"' : '' ?> disabled><?= $l_use_internal_server ?></option>
303
								<option value="2"<?= ($mail_type == '2') ? ' selected="selected"' : '' ?> disabled><?= $l_use_external_server ?></option>
2997 rexy 304
								<option value="3"<?= ($mail_type == '3') ? ' selected="selected"' : '' ?>><?= $l_use_email_address ?></option>
2992 rexy 305
							</select>
306
						</dd>
307
					</dl>
308
					<dl>
309
						<dt>
2993 rexy 310
							<label for="mail_address"><?= $l_email_address ?></label><br>
2992 rexy 311
						</dt>
312
						<dd>
3039 rexy 313
							<input type="text" id="mail_address" size="40" name="mail_address" value="<?= $mail_address ?>" oninput="onMailStatusChange();">
2992 rexy 314
						</dd>
315
					</dl>
316
					<dl>
317
						<dt>
2993 rexy 318
							<label for="mail_mdp"><?= $l_email_password ?></label><br>
2992 rexy 319
						</dt>
320
						<dd>
3039 rexy 321
							<input type="password" id="mail_mdp" size="40" name="mail_mdp" value="<?= $mail_mdp ?>" oninput="onMailStatusChange();">
2992 rexy 322
						</dd>
323
					</dl>
324
					<dl>
325
						<dt>
2993 rexy 326
							<label for="mail_mdp2"><?= $l_email_password_confirm ?></label><br>
2992 rexy 327
						</dt>
328
						<dd>
3039 rexy 329
							<input type="password" id="mail_mdp2" size="40" name="mail_mdp2" value="<?= $mail_mdp2 ?>" oninput="onMailStatusChange();">
2992 rexy 330
						</dd>
331
					</dl>
332
					<dl>
333
						<dt>
2993 rexy 334
							<label for="mail_server"><?= $l_mail_service ?></label><br>
2992 rexy 335
						</dt>
336
						<dd>
337
							<select id="mail_server" name="mail_server" onchange="onMailStatusChange();">
3060 rexy 338
								<option value="1"<?= ($mail_smtp_ip == 'smtp.orange.fr') ? ' selected="selected"' : '' ?>>Orange</option>
3062 rexy 339
								<option value="2"<?= ($mail_smtp_ip == 'smtp.office365.com') ? ' selected="selected"' : '' ?>>Office365</option>
340
								<option value="3"<?= ($mail_smtp_ip == 'smtp.sfr.fr') ? ' selected="selected"' : '' ?>>SFR</option>
341
								<option value="4"<?= ($mail_smtp_ip == 'smtp.free.fr') ? ' selected="selected"' : '' ?>>Free</option>
342
								<option value="5"<?= ($mail_smtp_ip == 'smtp.gmail.com') ? ' selected="selected"' : '' ?>>Gmail</option>
343
								<option value="6"<?= ($mail_smtp_ip == 'smtp.laposte.net') ? ' selected="selected"' : '' ?>>Laposte</option>
344
								<option value="7"<?= ($mail_smtp_ip == 'smtp.bbox.fr') ? ' selected="selected"' : '' ?>>Bouygues</option>
345
								<option value="8">Personnalisé</option>
2992 rexy 346
							</select>
347
						</dd>
348
					</dl>
349
					<dl>
350
						<dt>
3000 rexy 351
							<label for="mail_smtp_ip"><?= $l_mail_smtp_ip ?></label><br>
2992 rexy 352
						</dt>
353
						<dd>
3039 rexy 354
							<input type="text" id="mail_smtp_ip" size="40" name="mail_smtp_ip" value="<?= $mail_smtp_ip ?>" oninput="onMailStatusChange();">
2992 rexy 355
						</dd>
3021 rexy 356
						<dt>
357
							<label for="mail_smtp_port"><?= $l_mail_smtp_port ?></label><br>
358
						</dt>
359
						<dd>
3039 rexy 360
							<input type="text" id="mail_smtp_port" size="5" name="mail_smtp_port" value="<?= $mail_smtp_port ?>" oninput="onMailStatusChange();">
3021 rexy 361
						</dd>
2992 rexy 362
					</dl>
363
					<dl>
364
						<dt>
2997 rexy 365
							<label for="admin_enable"><?= $l_admin_log ?></label>
2992 rexy 366
						</dt>
367
						<dd>
368
							<select id="admin_enable" name="admin_enable" onchange="onMailStatusChange();">
3001 rexy 369
								<option value="1"<?= ($mail_admin != '')  ? ' selected="selected"' : '' ?>><?= $l_mail_YES ?></option>
370
								<option value="0"<?= ($mail_admin == '') ? ' selected="selected"' : '' ?>><?= $l_mail_NO ?></option>
2992 rexy 371
							</select>
372
						</dd>
373
					</dl>
374
					<dl>
375
						<dt>
3001 rexy 376
							<label for="mail_admin"><?= $l_mail_admin ?></label><br>
2992 rexy 377
						</dt>
378
						<dd>
3039 rexy 379
							<input type="text" id="mail_admin" size="40" name="mail_admin" value="<?= $mail_admin ?>" oninput="onMailStatusChange();">
2992 rexy 380
						</dd>
381
					</dl>
382
					<dl>
383
						<dt>
2997 rexy 384
							<label for="mail_whitelist"><?= $l_whitelist_domain ?></label><br>
2992 rexy 385
						</dt>
386
						<dd>
3039 rexy 387
							<input type="text" id="mail_whitelist" size="40" name="mail_whitelist" value="<?= $mail_whitelist ?>" oninput="onMailStatusChange();">
2992 rexy 388
						</dd>
389
					</dl>
390
					<p>
3028 rexy 391
						<input id="submit" onClick="document.getElementById('ldoverlay').style.display='block';" type="submit" value="<?= $l_mail_submit ?>" name="submit">
2992 rexy 392
					</p>
393
				</fieldset>
394
			</form>
395
		</div>
396
	</div>
2991 rexy 397
</body>
398
</html>