Subversion Repositories ALCASAR

Rev

Rev 3039 | Rev 3060 | Go to most recent revision | 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";
2993 rexy 52
	$l_email_password		= "Mot de passe";
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";
2997 rexy 59
	$l_whitelist_domain		= "Noms de domaine autorisés (whitelist)";
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";
71
	$l_email_password		= "Contraseña";
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";
78
	$l_whitelist_domain		= "Nombres de dominio autorizados (lista blanca)";
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";
90
	$l_email_password		= "Password";
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";
2997 rexy 97
	$l_whitelist_domain		= "Authorized domain names (whitelist)";
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':
3000 rexy 153
							$mail_smtp_ip	= "smtp.live.com";
3021 rexy 154
							$mail_smtp_port		= 587;
2997 rexy 155
						break;
156
						case '3':
3000 rexy 157
							$mail_smtp_ip	= "smtp.office365.com";
3021 rexy 158
							$mail_smtp_port		= 587;
2997 rexy 159
						break;
160
						case '4':
3000 rexy 161
							$mail_smtp_ip	= "smtp.sfr.fr";
3021 rexy 162
							$mail_smtp_port		= 465;
2997 rexy 163
						break;
164
						case '5':
3000 rexy 165
							$mail_smtp_ip	= "smtp.free.fr";
3021 rexy 166
							$mail_smtp_port		= 465;	
2997 rexy 167
						break;
168
						case '6':
3000 rexy 169
							$mail_smtp_ip	= "smtp.gmail.com";
3021 rexy 170
							$mail_smtp_port		= 587;
2997 rexy 171
						break;
172
						case '7':
3000 rexy 173
							$mail_smtp_ip	= "smtp.laposte.net";
3021 rexy 174
							$mail_smtp_port		= 465;
2997 rexy 175
						break;
176
						case '8':
3000 rexy 177
							$mail_smtp_ip	= "smtp.bbox.fr";
3021 rexy 178
							$mail_smtp_port		= 587;
2997 rexy 179
						break;
180
						default:
181
							echo "Erreur dans la saisie !";
182
						break;
2991 rexy 183
					}
3001 rexy 184
					if ($admin_enable == "1"){
3021 rexy 185
						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 186
					}
187
					else {
3021 rexy 188
						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 189
					}
2997 rexy 190
				}
3001 rexy 191
				else { // no password or password are not same
192
					header("Refresh:0");
2997 rexy 193
				}
194
				break;
195
			default:
196
				echo "Erreur dans la saisie !";
197
				break;
2992 rexy 198
		}
2991 rexy 199
	}
2993 rexy 200
	else { // switch email registation off
2994 rexy 201
		exec("sudo /usr/local/bin/alcasar-mail-install.sh -0");
2992 rexy 202
	}
203
	header("Refresh:0");
204
	exit;
2991 rexy 205
}
206
 
207
?>
2992 rexy 208
<!DOCTYPE html>
209
<html>
210
<head>
211
	<meta charset="UTF-8">
212
	<title><?= $l_mail_title ?></title>
213
	<link type="text/css" href="/css/acc.css" rel="stylesheet">
214
	<script>
215
	function onMailStatusChange() {
3001 rexy 216
		var listToDisables1 = ['mail_type','admin_enable','mail_admin','mail_whitelist'];
3022 rexy 217
		var listToDisables2 = ['mail_type','admin_enable','mail_admin','mail_whitelist','mail_server','mail_smtp_ip','mail_smtp_port'];
218
		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 219
		var formSubmit = document.querySelector('form input[type="submit"]');
220
		var isChecked = false;
3001 rexy 221
		for (var i=0; i<listToDisables3.length; i++) {
222
			document.getElementById(listToDisables3[i]).style.backgroundColor = '#c0c0c0';
223
			document.getElementById(listToDisables3[i]).disabled = true;
224
		}
3021 rexy 225
		if (document.getElementById('mail_enable').value === 'on') {
2992 rexy 226
			document.getElementById('mail_type').style.backgroundColor = null;
227
			document.getElementById('mail_type').disabled = false;
3001 rexy 228
			if (document.getElementById('mail_type').value === '1') {
2992 rexy 229
				for (var i=0; i<listToDisables1.length; i++) {
230
				document.getElementById(listToDisables1[i]).style.backgroundColor = null;
231
				document.getElementById(listToDisables1[i]).disabled = false;
232
				}
233
				if (document.getElementById('admin_enable').value === '0') {
3001 rexy 234
				document.getElementById('mail_admin').style.backgroundColor = '#c0c0c0';
235
				document.getElementById('mail_admin').disabled = true;
2992 rexy 236
				}
237
			}
238
			else if (document.getElementById('mail_type').value === '2') {
239
				for (var i=0; i<listToDisables2.length; i++) {
240
				document.getElementById(listToDisables2[i]).style.backgroundColor = null;
241
				document.getElementById(listToDisables2[i]).disabled = false;
242
				}
243
				if (document.getElementById('admin_enable').value === '0') {
3001 rexy 244
				document.getElementById('mail_admin').style.backgroundColor = '#c0c0c0';
245
				document.getElementById('mail_admin').disabled = true;
2992 rexy 246
				}
3001 rexy 247
				if (document.getElementById('mail_server').value != '9') {
248
				document.getElementById('mail_smtp_ip').style.backgroundColor = '#c0c0c0';
249
				document.getElementById('mail_smtp_ip').disabled = true;
3022 rexy 250
				document.getElementById('mail_smtp_port').style.backgroundColor = '#c0c0c0';
251
				document.getElementById('mail_smtp_port').disabled = true;
3001 rexy 252
				}
2992 rexy 253
			}
254
			else if (document.getElementById('mail_type').value === '3') {
255
				for (var i=0; i<listToDisables3.length; i++) {
256
				document.getElementById(listToDisables3[i]).style.backgroundColor = null;
257
				document.getElementById(listToDisables3[i]).disabled = false;
258
				}
259
				if (document.getElementById('admin_enable').value === '0') {
3001 rexy 260
				document.getElementById('mail_admin').style.backgroundColor = '#c0c0c0';
261
				document.getElementById('mail_admin').disabled = true;
2992 rexy 262
				}
3001 rexy 263
				if (document.getElementById('mail_server').value != '9') {
264
				document.getElementById('mail_smtp_ip').style.backgroundColor = '#c0c0c0';
265
				document.getElementById('mail_smtp_ip').disabled = true;
3022 rexy 266
				document.getElementById('mail_smtp_port').style.backgroundColor = '#c0c0c0';
267
				document.getElementById('mail_smtp_port').disabled = true;
3001 rexy 268
				}
2992 rexy 269
			}
270
			formSubmit.style.display = null;
2991 rexy 271
		}
2992 rexy 272
	}
273
	</script>
274
</head>
275
<body onLoad="onMailStatusChange();">
3028 rexy 276
<div id="ldoverlay" class="overlay">
277
	<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>
278
</div>
2992 rexy 279
	<div class="panel">
2993 rexy 280
		<div class="panel-header"><?= $l_mail_title ?></div>
2992 rexy 281
		<div class="panel-body">
282
			<form id="form-config_mail" name="config_mail" method="POST" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" enctype="multipart/form-data">
283
				<fieldset>
284
					<legend>
285
						<br>
286
						<div style="text-align: center">
287
						</div>
288
					</legend>
289
					<dl>
290
						<dt>
3021 rexy 291
							<label for="mail_enable"><?= $l_mail_registration ?></label>
2992 rexy 292
						</dt>
293
						<dd>
3021 rexy 294
							<select id="mail_enable" name="mail_enable" onchange="onMailStatusChange();">
2997 rexy 295
								<option value="on"<?= ($mail_status == 'on') ? ' selected="selected"' : '' ?>><?= $l_mail_YES ?></option>
2993 rexy 296
								<option value="off"<?= ($mail_status == 'off') ? ' selected="selected"' : '' ?>><?= $l_mail_NO ?></option>
2992 rexy 297
							</select>
298
						</dd>
299
					</dl>
300
					<dl>
301
						<dt>
2993 rexy 302
							<label for="mail_type"><?= $l_mail_choice ?></label><br>
2992 rexy 303
						</dt>
304
						<dd>
305
							<select id="mail_type" name="mail_type" onchange="onMailStatusChange();">
3038 rexy 306
								<option value="1"<?= ($mail_type == '1') ? ' selected="selected"' : '' ?> disabled><?= $l_use_internal_server ?></option>
307
								<option value="2"<?= ($mail_type == '2') ? ' selected="selected"' : '' ?> disabled><?= $l_use_external_server ?></option>
2997 rexy 308
								<option value="3"<?= ($mail_type == '3') ? ' selected="selected"' : '' ?>><?= $l_use_email_address ?></option>
2992 rexy 309
							</select>
310
						</dd>
311
					</dl>
312
					<dl>
313
						<dt>
2993 rexy 314
							<label for="mail_address"><?= $l_email_address ?></label><br>
2992 rexy 315
						</dt>
316
						<dd>
3039 rexy 317
							<input type="text" id="mail_address" size="40" name="mail_address" value="<?= $mail_address ?>" oninput="onMailStatusChange();">
2992 rexy 318
						</dd>
319
					</dl>
320
					<dl>
321
						<dt>
2993 rexy 322
							<label for="mail_mdp"><?= $l_email_password ?></label><br>
2992 rexy 323
						</dt>
324
						<dd>
3039 rexy 325
							<input type="password" id="mail_mdp" size="40" name="mail_mdp" value="<?= $mail_mdp ?>" oninput="onMailStatusChange();">
2992 rexy 326
						</dd>
327
					</dl>
328
					<dl>
329
						<dt>
2993 rexy 330
							<label for="mail_mdp2"><?= $l_email_password_confirm ?></label><br>
2992 rexy 331
						</dt>
332
						<dd>
3039 rexy 333
							<input type="password" id="mail_mdp2" size="40" name="mail_mdp2" value="<?= $mail_mdp2 ?>" oninput="onMailStatusChange();">
2992 rexy 334
						</dd>
335
					</dl>
336
					<dl>
337
						<dt>
2993 rexy 338
							<label for="mail_server"><?= $l_mail_service ?></label><br>
2992 rexy 339
						</dt>
340
						<dd>
341
							<select id="mail_server" name="mail_server" onchange="onMailStatusChange();">
3000 rexy 342
								<option value="1"<?= ($mail_smtp_ip == 'smtp.orange.fr') ? ' selected="selected"' : '' ?>>Orange/Wanadoo</option>
343
								<option value="2"<?= ($mail_smtp_ip == 'smtp.live.com') ? ' selected="selected"' : '' ?>>Hotmail</option>
344
								<option value="3"<?= ($mail_smtp_ip == 'smtp.office365.com') ? ' selected="selected"' : '' ?>>Outlook</option>
345
								<option value="4"<?= ($mail_smtp_ip == 'smtp.sfr.fr') ? ' selected="selected"' : '' ?>>SFR</option>
346
								<option value="5"<?= ($mail_smtp_ip == 'smtp.free.fr') ? ' selected="selected"' : '' ?>>Free</option>
347
								<option value="6"<?= ($mail_smtp_ip == 'smtp.gmail.com') ? ' selected="selected"' : '' ?>>Gmail</option>
348
								<option value="7"<?= ($mail_smtp_ip == 'smtp.laposte.net') ? ' selected="selected"' : '' ?>>Laposte</option>
349
								<option value="8"<?= ($mail_smtp_ip == 'smtp.bbox.fr') ? ' selected="selected"' : '' ?>>Bouygues</option>
350
								<option value="9">Personnalisé</option>
2992 rexy 351
							</select>
352
						</dd>
353
					</dl>
354
					<dl>
355
						<dt>
3000 rexy 356
							<label for="mail_smtp_ip"><?= $l_mail_smtp_ip ?></label><br>
2992 rexy 357
						</dt>
358
						<dd>
3039 rexy 359
							<input type="text" id="mail_smtp_ip" size="40" name="mail_smtp_ip" value="<?= $mail_smtp_ip ?>" oninput="onMailStatusChange();">
2992 rexy 360
						</dd>
3021 rexy 361
						<dt>
362
							<label for="mail_smtp_port"><?= $l_mail_smtp_port ?></label><br>
363
						</dt>
364
						<dd>
3039 rexy 365
							<input type="text" id="mail_smtp_port" size="5" name="mail_smtp_port" value="<?= $mail_smtp_port ?>" oninput="onMailStatusChange();">
3021 rexy 366
						</dd>
2992 rexy 367
					</dl>
368
					<dl>
369
						<dt>
2997 rexy 370
							<label for="admin_enable"><?= $l_admin_log ?></label>
2992 rexy 371
						</dt>
372
						<dd>
373
							<select id="admin_enable" name="admin_enable" onchange="onMailStatusChange();">
3001 rexy 374
								<option value="1"<?= ($mail_admin != '')  ? ' selected="selected"' : '' ?>><?= $l_mail_YES ?></option>
375
								<option value="0"<?= ($mail_admin == '') ? ' selected="selected"' : '' ?>><?= $l_mail_NO ?></option>
2992 rexy 376
							</select>
377
						</dd>
378
					</dl>
379
					<dl>
380
						<dt>
3001 rexy 381
							<label for="mail_admin"><?= $l_mail_admin ?></label><br>
2992 rexy 382
						</dt>
383
						<dd>
3039 rexy 384
							<input type="text" id="mail_admin" size="40" name="mail_admin" value="<?= $mail_admin ?>" oninput="onMailStatusChange();">
2992 rexy 385
						</dd>
386
					</dl>
387
					<dl>
388
						<dt>
2997 rexy 389
							<label for="mail_whitelist"><?= $l_whitelist_domain ?></label><br>
2992 rexy 390
						</dt>
391
						<dd>
3039 rexy 392
							<input type="text" id="mail_whitelist" size="40" name="mail_whitelist" value="<?= $mail_whitelist ?>" oninput="onMailStatusChange();">
2992 rexy 393
						</dd>
394
					</dl>
395
					<p>
3028 rexy 396
						<input id="submit" onClick="document.getElementById('ldoverlay').style.display='block';" type="submit" value="<?= $l_mail_submit ?>" name="submit">
2992 rexy 397
					</p>
398
				</fieldset>
399
			</form>
400
		</div>
401
	</div>
2991 rexy 402
</body>
403
</html>