Subversion Repositories ALCASAR

Rev

Rev 3021 | Rev 3028 | 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') {
2993 rexy 45
	$l_mail_title			= "Inscription par Email";
46
	$l_mail_registration	= "Activer l'inscription par Email :";
47
	$l_mail_choice			= "Quel type de service 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";
2993 rexy 50
	$l_use_email_address	= "Utiliser une adresse mail";
51
	$l_email_address		= "Adresse mail utilisée pour l'envoi de mail";
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";
2997 rexy 57
	$l_admin_log			= "Avertissement de l'administratateur";
3001 rexy 58
	$l_mail_admin			= "Adresse Email 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') {
64
	$l_mail_title			= "Registro por email";
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 {
2993 rexy 83
	$l_mail_title			= "Registration by Email";
84
	$l_mail_registration	= "Enable registration by Email :";
85
	$l_mail_choice			= "What type of 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_address			= $conf['MAIL_ADDR'];
107
$mail_smtp_ip			= $conf['MAIL_SMTP_IP'];
108
$mail_smtp_port			= $conf['MAIL_SMTP_PORT'];
2992 rexy 109
$mail_password_mail 	= "";
110
$mail_password_mail_2	= "";
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
3021 rexy 129
				$mail_smtp_port = 25;
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();">
276
	<div class="panel">
2993 rexy 277
		<div class="panel-header"><?= $l_mail_title ?></div>
2992 rexy 278
		<div class="panel-body">
279
			<form id="form-config_mail" name="config_mail" method="POST" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" enctype="multipart/form-data">
280
				<fieldset>
281
					<legend>
282
						<br>
283
						<div style="text-align: center">
284
						</div>
285
					</legend>
286
					<dl>
287
						<dt>
3021 rexy 288
							<label for="mail_enable"><?= $l_mail_registration ?></label>
2992 rexy 289
						</dt>
290
						<dd>
3021 rexy 291
							<select id="mail_enable" name="mail_enable" onchange="onMailStatusChange();">
2997 rexy 292
								<option value="on"<?= ($mail_status == 'on') ? ' selected="selected"' : '' ?>><?= $l_mail_YES ?></option>
2993 rexy 293
								<option value="off"<?= ($mail_status == 'off') ? ' selected="selected"' : '' ?>><?= $l_mail_NO ?></option>
2992 rexy 294
							</select>
295
						</dd>
296
					</dl>
297
					<dl>
298
						<dt>
2993 rexy 299
							<label for="mail_type"><?= $l_mail_choice ?></label><br>
2992 rexy 300
						</dt>
301
						<dd>
302
							<select id="mail_type" name="mail_type" onchange="onMailStatusChange();">
3022 rexy 303
								<option value="1"<?= ($mail_type == '1') ? ' selected="selected"' : '' ?>><?= $l_use_internal_server ?></option>
2997 rexy 304
								<option value="2"<?= ($mail_type == '2') ? ' selected="selected"' : '' ?>><?= $l_use_external_server ?></option>
305
								<option value="3"<?= ($mail_type == '3') ? ' selected="selected"' : '' ?>><?= $l_use_email_address ?></option>
2992 rexy 306
							</select>
307
						</dd>
308
					</dl>
309
					<dl>
310
						<dt>
2993 rexy 311
							<label for="mail_address"><?= $l_email_address ?></label><br>
2992 rexy 312
						</dt>
313
						<dd>
3000 rexy 314
							<input type="text" id="mail_address" size="40" name="mail_address" value="<?= $mail_address ?>" oninput="onMailStatusChange();"> 
2992 rexy 315
						</dd>
316
					</dl>
317
					<dl>
318
						<dt>
2993 rexy 319
							<label for="mail_mdp"><?= $l_email_password ?></label><br>
2992 rexy 320
						</dt>
321
						<dd>
3022 rexy 322
							<input type="password" id="mail_mdp" size="40" name="mail_mdp" value="<?= $mail_password_mail ?>" oninput="onMailStatusChange();"> 
2992 rexy 323
						</dd>
324
					</dl>
325
					<dl>
326
						<dt>
2993 rexy 327
							<label for="mail_mdp2"><?= $l_email_password_confirm ?></label><br>
2992 rexy 328
						</dt>
329
						<dd>
3022 rexy 330
							<input type="password" id="mail_mdp2" size="40" name="mail_mdp2" value="<?= $mail_password_mail_2 ?>" oninput="onMailStatusChange();"> 
2992 rexy 331
						</dd>
332
					</dl>
333
					<dl>
334
						<dt>
2993 rexy 335
							<label for="mail_server"><?= $l_mail_service ?></label><br>
2992 rexy 336
						</dt>
337
						<dd>
338
							<select id="mail_server" name="mail_server" onchange="onMailStatusChange();">
3000 rexy 339
								<option value="1"<?= ($mail_smtp_ip == 'smtp.orange.fr') ? ' selected="selected"' : '' ?>>Orange/Wanadoo</option>
340
								<option value="2"<?= ($mail_smtp_ip == 'smtp.live.com') ? ' selected="selected"' : '' ?>>Hotmail</option>
341
								<option value="3"<?= ($mail_smtp_ip == 'smtp.office365.com') ? ' selected="selected"' : '' ?>>Outlook</option>
342
								<option value="4"<?= ($mail_smtp_ip == 'smtp.sfr.fr') ? ' selected="selected"' : '' ?>>SFR</option>
343
								<option value="5"<?= ($mail_smtp_ip == 'smtp.free.fr') ? ' selected="selected"' : '' ?>>Free</option>
344
								<option value="6"<?= ($mail_smtp_ip == 'smtp.gmail.com') ? ' selected="selected"' : '' ?>>Gmail</option>
345
								<option value="7"<?= ($mail_smtp_ip == 'smtp.laposte.net') ? ' selected="selected"' : '' ?>>Laposte</option>
346
								<option value="8"<?= ($mail_smtp_ip == 'smtp.bbox.fr') ? ' selected="selected"' : '' ?>>Bouygues</option>
347
								<option value="9">Personnalisé</option>
2992 rexy 348
							</select>
349
						</dd>
350
					</dl>
351
					<dl>
352
						<dt>
3000 rexy 353
							<label for="mail_smtp_ip"><?= $l_mail_smtp_ip ?></label><br>
2992 rexy 354
						</dt>
355
						<dd>
3000 rexy 356
							<input type="text" id="mail_smtp_ip" size="40" name="mail_smtp_ip" value="<?= $mail_smtp_ip ?>" oninput="onMailStatusChange();"> 
2992 rexy 357
						</dd>
3021 rexy 358
						<dt>
359
							<label for="mail_smtp_port"><?= $l_mail_smtp_port ?></label><br>
360
						</dt>
361
						<dd>
362
							<input type="text" id="mail_smtp_port" size="5" name="mail_smtp_port" value="<?= $mail_smtp_port ?>" oninput="onMailStatusChange();"> 
363
						</dd>
2992 rexy 364
					</dl>
365
					<dl>
366
						<dt>
2997 rexy 367
							<label for="admin_enable"><?= $l_admin_log ?></label>
2992 rexy 368
						</dt>
369
						<dd>
370
							<select id="admin_enable" name="admin_enable" onchange="onMailStatusChange();">
3001 rexy 371
								<option value="1"<?= ($mail_admin != '')  ? ' selected="selected"' : '' ?>><?= $l_mail_YES ?></option>
372
								<option value="0"<?= ($mail_admin == '') ? ' selected="selected"' : '' ?>><?= $l_mail_NO ?></option>
2992 rexy 373
							</select>
374
						</dd>
375
					</dl>
376
					<dl>
377
						<dt>
3001 rexy 378
							<label for="mail_admin"><?= $l_mail_admin ?></label><br>
2992 rexy 379
						</dt>
380
						<dd>
3001 rexy 381
							<input type="text" id="mail_admin" size="40" name="mail_admin" value="<?= $mail_admin ?>" oninput="onMailStatusChange();"> 
2992 rexy 382
						</dd>
383
					</dl>
384
					<dl>
385
						<dt>
2997 rexy 386
							<label for="mail_whitelist"><?= $l_whitelist_domain ?></label><br>
2992 rexy 387
						</dt>
388
						<dd>
389
							<input type="text" id="mail_whitelist" size="40" name="mail_whitelist" value="<?= $mail_whitelist ?>" oninput="onMailStatusChange();"> 
390
						</dd>
391
					</dl>
392
					<p>
393
						<input id="submit" type="submit" value="<?= $l_mail_submit ?>" name="submit">
394
					</p>
395
				</fieldset>
396
			</form>
397
		</div>
398
	</div>
2991 rexy 399
</body>
400
</html>