Subversion Repositories ALCASAR

Rev

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