Subversion Repositories ALCASAR

Rev

Rev 3020 | Rev 3022 | 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);
2993 rexy 32
		$mail_conf[trim($tmp[0])] = trim($tmp[1]);
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";
2992 rexy 63
} else {
2993 rexy 64
	$l_mail_title			= "Registration by Email";
65
	$l_mail_registration	= "Enable registration by Email :";
66
	$l_mail_choice			= "What type of mail service use ?";
3009 rexy 67
	$l_use_internal_server	= "Use the internal mail server";
68
	$l_use_external_server	= "Relay to an external mail server";
69
	$l_use_email_address	= "Use an email address";
2993 rexy 70
	$l_email_address		= "Email address used for sending mail";
71
	$l_email_password		= "Password";
72
	$l_email_password_confirm	= "Confirm password";
73
	$l_mail_service			= "Choose the mail service";
3000 rexy 74
	$l_mail_smtp_ip			= "IP address or name of mail server";
3021 rexy 75
	$l_mail_smtp_port		= "Listen port of mail server";
2997 rexy 76
	$l_admin_log			= "Administrator's warning";
3001 rexy 77
	$l_mail_admin			= "Administrator Email address";
2997 rexy 78
	$l_whitelist_domain		= "Authorized domain names (whitelist)";
2993 rexy 79
	$l_mail_YES				= "YES";
80
	$l_mail_NO				= "NO";
81
	$l_mail_submit			= "Save";
2992 rexy 82
}
2991 rexy 83
 
2992 rexy 84
// Mail configuration params
2993 rexy 85
$mail_status        	= $mail_conf['MAIL'];
86
$mail_type				= $mail_conf['MAIL_TYPE'];
3000 rexy 87
$mail_address			= $mail_conf['MAIL_ADDR'];
3021 rexy 88
$mail_smtp_port			= $mail_conf['MAIL_SMTP_PORT'];
3000 rexy 89
$mail_smtp_ip			= $mail_conf['MAIL_SMTP_IP'];
2992 rexy 90
$mail_password_mail 	= "";
91
$mail_password_mail_2	= "";
3001 rexy 92
$mail_admin				= $mail_conf['MAIL_ADMIN'];
2993 rexy 93
$mail_whitelist			= $mail_conf['MAIL_WHITEDOMAIN'];
2991 rexy 94
 
2992 rexy 95
if(isset($_POST['submit'])){
3021 rexy 96
	if($_POST['mail_enable'] === 'on')
2992 rexy 97
	{
3021 rexy 98
		$mail_type = $_POST['mail_type'];
99
		$mail_whitelist = $_POST['mail_whitelist'];
100
		$admin_enable = $_POST['admin_enable'];
101
		if(isset($_POST['mail_address']))	{ $mail_address = $_POST['mail_address']; }
102
		if(isset($_POST['mail_server']))	{ $mail_server = $_POST['mail_server']; }
103
		if(isset($_POST['mail_smtp_ip']))	{ $mail_smtp_ip = $_POST['mail_smtp_ip']; }
104
		if(isset($_POST['mail_smtp_port']))	{ $mail_smtp_ip = $_POST['mail_smtp_port']; }
105
		if(isset($_POST['mail_mdp']))		{ $mail_mdp = $_POST['mail_mdp']; }
106
		if(isset($_POST['mail_mdp2']))		{ $mail_mdp2 = $_POST['mail_mdp2']; }
107
		if ($admin_enable == "1") { $mail_admin = $_POST['mail_admin']; }
2997 rexy 108
		switch ($mail_type) {
2992 rexy 109
			case '1':
3021 rexy 110
				$mail_smtp_port = 25;
3001 rexy 111
				if ($admin_enable == "1"){
112
					exec("sudo /usr/local/bin/alcasar-mail-install.sh -1 -a $mail_admin -w $mail_whitelist");
2997 rexy 113
				}
114
				else {
115
					exec("sudo /usr/local/bin/alcasar-mail-install.sh -1 -w $mail_whitelist");
116
				}
2992 rexy 117
				break;
118
			case '2':
3001 rexy 119
				if ($admin_enable == "1"){
3021 rexy 120
					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 121
				}
122
				else {
3021 rexy 123
					exec("sudo /usr/local/bin/alcasar-mail-install.sh -2 -s $mail_smtp_ip -p $mail_smtp_port -w $mail_whitelist");
2997 rexy 124
				}
2992 rexy 125
				break;
126
			case '3':
3001 rexy 127
				if(($mail_mdp != '') && ($mail_mdp==$mail_mdp2)) {
2997 rexy 128
					switch ($mail_server) {
129
						case '1':
3000 rexy 130
							$mail_smtp_ip	= "smtp.orange.fr";
3021 rexy 131
							$mail_smtp_port		= 465;
2997 rexy 132
						break;
133
						case '2':
3000 rexy 134
							$mail_smtp_ip	= "smtp.live.com";
3021 rexy 135
							$mail_smtp_port		= 587;
2997 rexy 136
						break;
137
						case '3':
3000 rexy 138
							$mail_smtp_ip	= "smtp.office365.com";
3021 rexy 139
							$mail_smtp_port		= 587;
2997 rexy 140
						break;
141
						case '4':
3000 rexy 142
							$mail_smtp_ip	= "smtp.sfr.fr";
3021 rexy 143
							$mail_smtp_port		= 465;
2997 rexy 144
						break;
145
						case '5':
3000 rexy 146
							$mail_smtp_ip	= "smtp.free.fr";
3021 rexy 147
							$mail_smtp_port		= 465;	
2997 rexy 148
						break;
149
						case '6':
3000 rexy 150
							$mail_smtp_ip	= "smtp.gmail.com";
3021 rexy 151
							$mail_smtp_port		= 587;
2997 rexy 152
						break;
153
						case '7':
3000 rexy 154
							$mail_smtp_ip	= "smtp.laposte.net";
3021 rexy 155
							$mail_smtp_port		= 465;
2997 rexy 156
						break;
157
						case '8':
3000 rexy 158
							$mail_smtp_ip	= "smtp.bbox.fr";
3021 rexy 159
							$mail_smtp_port		= 587;
2997 rexy 160
						break;
161
						default:
162
							echo "Erreur dans la saisie !";
163
						break;
2991 rexy 164
					}
3001 rexy 165
					if ($admin_enable == "1"){
3021 rexy 166
						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 167
					}
168
					else {
3021 rexy 169
						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 170
					}
2997 rexy 171
				}
3001 rexy 172
				else { // no password or password are not same
173
					header("Refresh:0");
2997 rexy 174
				}
175
				break;
176
			default:
177
				echo "Erreur dans la saisie !";
178
				break;
2992 rexy 179
		}
2991 rexy 180
	}
2993 rexy 181
	else { // switch email registation off
2994 rexy 182
		exec("sudo /usr/local/bin/alcasar-mail-install.sh -0");
2992 rexy 183
	}
184
	header("Refresh:0");
185
	exit;
2991 rexy 186
}
187
 
188
?>
2992 rexy 189
<!DOCTYPE html>
190
<html>
191
<head>
192
	<meta charset="UTF-8">
193
	<title><?= $l_mail_title ?></title>
194
	<link type="text/css" href="/css/acc.css" rel="stylesheet">
195
	<link type="text/css" href="/css/mail.css" rel="stylesheet">
196
	<script>
197
	function onMailStatusChange() {
3001 rexy 198
		var listToDisables1 = ['mail_type','admin_enable','mail_admin','mail_whitelist'];
199
		var listToDisables2 = ['mail_type','admin_enable','mail_admin','mail_whitelist','mail_server','mail_smtp_ip'];
200
		var listToDisables3 = ['mail_type','admin_enable','mail_admin','mail_whitelist','mail_server','mail_smtp_ip','mail_mdp2','mail_mdp','mail_address'];
2992 rexy 201
		var formSubmit = document.querySelector('form input[type="submit"]');
202
		var isChecked = false;
3001 rexy 203
		for (var i=0; i<listToDisables1.length; i++) {
204
			document.getElementById(listToDisables1[i]).style.backgroundColor = '#c0c0c0';
205
			document.getElementById(listToDisables1[i]).disabled = true;
206
		}
207
		for (var i=0; i<listToDisables2.length; i++) {
208
			document.getElementById(listToDisables2[i]).style.backgroundColor = '#c0c0c0';
209
			document.getElementById(listToDisables2[i]).disabled = true;
210
		}
211
		for (var i=0; i<listToDisables3.length; i++) {
212
			document.getElementById(listToDisables3[i]).style.backgroundColor = '#c0c0c0';
213
			document.getElementById(listToDisables3[i]).disabled = true;
214
		}
3021 rexy 215
		if (document.getElementById('mail_enable').value === 'on') {
2992 rexy 216
			document.getElementById('mail_type').style.backgroundColor = null;
217
			document.getElementById('mail_type').disabled = false;
3001 rexy 218
			if (document.getElementById('mail_type').value === '1') {
2992 rexy 219
				for (var i=0; i<listToDisables1.length; i++) {
220
				document.getElementById(listToDisables1[i]).style.backgroundColor = null;
221
				document.getElementById(listToDisables1[i]).disabled = false;
222
				}
223
				if (document.getElementById('admin_enable').value === '0') {
3001 rexy 224
				document.getElementById('mail_admin').style.backgroundColor = '#c0c0c0';
225
				document.getElementById('mail_admin').disabled = true;
2992 rexy 226
				}
227
			}
228
			else if (document.getElementById('mail_type').value === '2') {
229
				for (var i=0; i<listToDisables2.length; i++) {
230
				document.getElementById(listToDisables2[i]).style.backgroundColor = null;
231
				document.getElementById(listToDisables2[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
				}
3001 rexy 237
				if (document.getElementById('mail_server').value != '9') {
238
				document.getElementById('mail_smtp_ip').style.backgroundColor = '#c0c0c0';
239
				document.getElementById('mail_smtp_ip').disabled = true;
240
				}
2992 rexy 241
			}
242
			else if (document.getElementById('mail_type').value === '3') {
243
				for (var i=0; i<listToDisables3.length; i++) {
244
				document.getElementById(listToDisables3[i]).style.backgroundColor = null;
245
				document.getElementById(listToDisables3[i]).disabled = false;
246
				}
247
				if (document.getElementById('admin_enable').value === '0') {
3001 rexy 248
				document.getElementById('mail_admin').style.backgroundColor = '#c0c0c0';
249
				document.getElementById('mail_admin').disabled = true;
2992 rexy 250
				}
3001 rexy 251
				if (document.getElementById('mail_server').value != '9') {
252
				document.getElementById('mail_smtp_ip').style.backgroundColor = '#c0c0c0';
253
				document.getElementById('mail_smtp_ip').disabled = true;
254
				}
2992 rexy 255
			}
256
			formSubmit.style.display = null;
2991 rexy 257
		}
2992 rexy 258
	}
259
	</script>
260
</head>
261
<body onLoad="onMailStatusChange();">
262
	<div class="panel">
2993 rexy 263
		<div class="panel-header"><?= $l_mail_title ?></div>
2992 rexy 264
		<div class="panel-body">
265
			<form id="form-config_mail" name="config_mail" method="POST" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" enctype="multipart/form-data">
266
				<fieldset>
267
					<legend>
268
						<br>
269
						<div style="text-align: center">
270
						</div>
271
					</legend>
272
					<dl>
273
						<dt>
3021 rexy 274
							<label for="mail_enable"><?= $l_mail_registration ?></label>
2992 rexy 275
						</dt>
276
						<dd>
3021 rexy 277
							<select id="mail_enable" name="mail_enable" onchange="onMailStatusChange();">
2997 rexy 278
								<option value="on"<?= ($mail_status == 'on') ? ' selected="selected"' : '' ?>><?= $l_mail_YES ?></option>
2993 rexy 279
								<option value="off"<?= ($mail_status == 'off') ? ' selected="selected"' : '' ?>><?= $l_mail_NO ?></option>
2992 rexy 280
							</select>
281
						</dd>
282
					</dl>
283
					<dl>
284
						<dt>
2993 rexy 285
							<label for="mail_type"><?= $l_mail_choice ?></label><br>
2992 rexy 286
						</dt>
287
						<dd>
288
							<select id="mail_type" name="mail_type" onchange="onMailStatusChange();">
3021 rexy 289
								<!--<option value="1"<?= ($mail_type == '1') ? ' selected="selected"' : '' ?>><?= $l_use_internal_server ?></option>-->
2997 rexy 290
								<option value="2"<?= ($mail_type == '2') ? ' selected="selected"' : '' ?>><?= $l_use_external_server ?></option>
291
								<option value="3"<?= ($mail_type == '3') ? ' selected="selected"' : '' ?>><?= $l_use_email_address ?></option>
2992 rexy 292
							</select>
293
						</dd>
294
					</dl>
295
					<dl>
296
						<dt>
2993 rexy 297
							<label for="mail_address"><?= $l_email_address ?></label><br>
2992 rexy 298
						</dt>
299
						<dd>
3000 rexy 300
							<input type="text" id="mail_address" size="40" name="mail_address" value="<?= $mail_address ?>" oninput="onMailStatusChange();"> 
2992 rexy 301
						</dd>
302
					</dl>
303
					<dl>
304
						<dt>
2993 rexy 305
							<label for="mail_mdp"><?= $l_email_password ?></label><br>
2992 rexy 306
						</dt>
307
						<dd>
308
							<input type="text" id="mail_mdp" size="40" name="mail_mdp" value="<?= $mail_password_mail ?>" oninput="onMailStatusChange();"> 
309
						</dd>
310
					</dl>
311
					<dl>
312
						<dt>
2993 rexy 313
							<label for="mail_mdp2"><?= $l_email_password_confirm ?></label><br>
2992 rexy 314
						</dt>
315
						<dd>
316
							<input type="text" id="mail_mdp2" size="40" name="mail_mdp2" value="<?= $mail_password_mail_2 ?>" oninput="onMailStatusChange();"> 
317
						</dd>
318
					</dl>
319
					<dl>
320
						<dt>
2993 rexy 321
							<label for="mail_server"><?= $l_mail_service ?></label><br>
2992 rexy 322
						</dt>
323
						<dd>
324
							<select id="mail_server" name="mail_server" onchange="onMailStatusChange();">
3000 rexy 325
								<option value="1"<?= ($mail_smtp_ip == 'smtp.orange.fr') ? ' selected="selected"' : '' ?>>Orange/Wanadoo</option>
326
								<option value="2"<?= ($mail_smtp_ip == 'smtp.live.com') ? ' selected="selected"' : '' ?>>Hotmail</option>
327
								<option value="3"<?= ($mail_smtp_ip == 'smtp.office365.com') ? ' selected="selected"' : '' ?>>Outlook</option>
328
								<option value="4"<?= ($mail_smtp_ip == 'smtp.sfr.fr') ? ' selected="selected"' : '' ?>>SFR</option>
329
								<option value="5"<?= ($mail_smtp_ip == 'smtp.free.fr') ? ' selected="selected"' : '' ?>>Free</option>
330
								<option value="6"<?= ($mail_smtp_ip == 'smtp.gmail.com') ? ' selected="selected"' : '' ?>>Gmail</option>
331
								<option value="7"<?= ($mail_smtp_ip == 'smtp.laposte.net') ? ' selected="selected"' : '' ?>>Laposte</option>
332
								<option value="8"<?= ($mail_smtp_ip == 'smtp.bbox.fr') ? ' selected="selected"' : '' ?>>Bouygues</option>
333
								<option value="9">Personnalisé</option>
2992 rexy 334
							</select>
335
						</dd>
336
					</dl>
337
					<dl>
338
						<dt>
3000 rexy 339
							<label for="mail_smtp_ip"><?= $l_mail_smtp_ip ?></label><br>
2992 rexy 340
						</dt>
341
						<dd>
3000 rexy 342
							<input type="text" id="mail_smtp_ip" size="40" name="mail_smtp_ip" value="<?= $mail_smtp_ip ?>" oninput="onMailStatusChange();"> 
2992 rexy 343
						</dd>
3021 rexy 344
						<dt>
345
							<label for="mail_smtp_port"><?= $l_mail_smtp_port ?></label><br>
346
						</dt>
347
						<dd>
348
							<input type="text" id="mail_smtp_port" size="5" name="mail_smtp_port" value="<?= $mail_smtp_port ?>" oninput="onMailStatusChange();"> 
349
						</dd>
2992 rexy 350
					</dl>
351
					<dl>
352
						<dt>
2997 rexy 353
							<label for="admin_enable"><?= $l_admin_log ?></label>
2992 rexy 354
						</dt>
355
						<dd>
356
							<select id="admin_enable" name="admin_enable" onchange="onMailStatusChange();">
3001 rexy 357
								<option value="1"<?= ($mail_admin != '')  ? ' selected="selected"' : '' ?>><?= $l_mail_YES ?></option>
358
								<option value="0"<?= ($mail_admin == '') ? ' selected="selected"' : '' ?>><?= $l_mail_NO ?></option>
2992 rexy 359
							</select>
360
						</dd>
361
					</dl>
362
					<dl>
363
						<dt>
3001 rexy 364
							<label for="mail_admin"><?= $l_mail_admin ?></label><br>
2992 rexy 365
						</dt>
366
						<dd>
3001 rexy 367
							<input type="text" id="mail_admin" size="40" name="mail_admin" value="<?= $mail_admin ?>" oninput="onMailStatusChange();"> 
2992 rexy 368
						</dd>
369
					</dl>
370
					<dl>
371
						<dt>
2997 rexy 372
							<label for="mail_whitelist"><?= $l_whitelist_domain ?></label><br>
2992 rexy 373
						</dt>
374
						<dd>
375
							<input type="text" id="mail_whitelist" size="40" name="mail_whitelist" value="<?= $mail_whitelist ?>" oninput="onMailStatusChange();"> 
376
						</dd>
377
					</dl>
378
					<p>
379
						<input id="submit" type="submit" value="<?= $l_mail_submit ?>" name="submit">
380
					</p>
381
				</fieldset>
382
			</form>
383
		</div>
384
	</div>
2991 rexy 385
</body>
386
</html>