Subversion Repositories ALCASAR

Rev

Rev 2997 | Rev 3001 | 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 ?";
48
	$l_use_internal_server	= "Utiliser le serveur interne";
49
	$l_use_external_server	= "Relayer vers un serveur externe";
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";
3000 rexy 57
	$l_admin_address		= "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 ?";
66
	$l_internal_server		= "Use the internal server";
67
	$l_external_server		= "Relay to an external server";
68
	$l_email_address		= "Use an email address";
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";
3000 rexy 75
	$l_admin_address		= "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	= "";
2993 rexy 91
$admin_address			= $mail_conf['MAIL_ADMIN'];
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'];
103
		$admin_address	= $_POST['admin_address'];
104
		$mail_whitelist	= $_POST['mail_whitelist'];
2997 rexy 105
		switch ($mail_type) {
2992 rexy 106
			case '1':
2997 rexy 107
				$mail_port = 25;
108
				if(isset($mail_admin)){
109
					exec("sudo /usr/local/bin/alcasar-mail-install.sh -1 -a $admin_address -w $mail_whitelist");
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':
2997 rexy 116
				if(isset($mail_admin)){
3000 rexy 117
					exec("sudo /usr/local/bin/alcasar-mail-install.sh -2 -s $mail_smtp_ip -p $mail_port -r $mail_ip -a $admin_address -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':
2997 rexy 124
				if ($mail_mdp == $mail_mdp2) {
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
					}
2992 rexy 162
					if(isset($mail_admin)){
3000 rexy 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 $admin_address -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
				}
169
				else { // password are not the same
170
					echo "Erreur";
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() {
195
		var listToDisables1 = ['mail_type','admin_enable','admin_address','mail_whitelist'];
3000 rexy 196
		var listToDisables2 = ['mail_server','mail_type','admin_enable','admin_address','mail_whitelist','mail_smtp_ip'];
2992 rexy 197
		var listToDisables3 = ['mail_server','mail_mdp2','mail_mdp','mail_address','mail_type','admin_enable','admin_address','mail_whitelist'];
198
		var formSubmit = document.querySelector('form input[type="submit"]');
199
		var btn_checkConf = document.getElementById('btn-checkconf');
200
		var isChecked = false;
2993 rexy 201
		if (document.getElementById('auth_enable').value === 'on') {
2992 rexy 202
			for (var i=0; i<listToDisables1.length; i++) {
203
				document.getElementById(listToDisables1[i]).style.backgroundColor = '#c0c0c0';
204
				document.getElementById(listToDisables1[i]).disabled = true;
2991 rexy 205
			}
2992 rexy 206
			for (var i=0; i<listToDisables2.length; i++) {
207
				document.getElementById(listToDisables2[i]).style.backgroundColor = '#c0c0c0';
208
				document.getElementById(listToDisables2[i]).disabled = true;
209
			}
210
			for (var i=0; i<listToDisables3.length; i++) {
211
				document.getElementById(listToDisables3[i]).style.backgroundColor = '#c0c0c0';
212
				document.getElementById(listToDisables3[i]).disabled = true;
213
			}
214
			document.getElementById('mail_type').style.backgroundColor = null;
215
			document.getElementById('mail_type').disabled = false;
2993 rexy 216
			if (document.getElementById('mail_type').value === 'on') {
2992 rexy 217
				for (var i=0; i<listToDisables1.length; i++) {
218
				document.getElementById(listToDisables1[i]).style.backgroundColor = null;
219
				document.getElementById(listToDisables1[i]).disabled = false;
220
				}
221
				if (document.getElementById('admin_enable').value === '0') {
222
				document.getElementById('admin_address').style.backgroundColor = '#c0c0c0';
223
				document.getElementById('admin_address').disabled = true;
224
				}
225
			}
226
			else if (document.getElementById('mail_type').value === '2') {
227
				for (var i=0; i<listToDisables2.length; i++) {
228
				document.getElementById(listToDisables2[i]).style.backgroundColor = null;
229
				document.getElementById(listToDisables2[i]).disabled = false;
230
				}
231
				if (document.getElementById('admin_enable').value === '0') {
232
				document.getElementById('admin_address').style.backgroundColor = '#c0c0c0';
233
				document.getElementById('admin_address').disabled = true;
234
				}
235
			}
236
			else if (document.getElementById('mail_type').value === '3') {
237
				for (var i=0; i<listToDisables3.length; i++) {
238
				document.getElementById(listToDisables3[i]).style.backgroundColor = null;
239
				document.getElementById(listToDisables3[i]).disabled = false;
240
				}
241
				if (document.getElementById('admin_enable').value === '0') {
242
				document.getElementById('admin_address').style.backgroundColor = '#c0c0c0';
243
				document.getElementById('admin_address').disabled = true;
244
				}
245
			}
246
			formSubmit.style.display = null;
247
			btn_checkConf.style.display = 'none';
248
		} else {
249
			for (var i=0; i<listToDisables1.length; i++) {
250
				document.getElementById(listToDisables1[i]).style.backgroundColor = '#c0c0c0';
251
				document.getElementById(listToDisables1[i]).disabled = true;
252
			}
253
			for (var i=0; i<listToDisables2.length; i++) {
254
				document.getElementById(listToDisables2[i]).style.backgroundColor = '#c0c0c0';
255
				document.getElementById(listToDisables2[i]).disabled = true;
256
			}
257
			for (var i=0; i<listToDisables3.length; i++) {
258
				document.getElementById(listToDisables3[i]).style.backgroundColor = '#c0c0c0';
259
				document.getElementById(listToDisables3[i]).disabled = true;
260
			}
261
			formSubmit.style.display = null;
262
			btn_checkConf.style.display = 'none';
2991 rexy 263
		}
2992 rexy 264
	}
265
	</script>
266
</head>
267
<body onLoad="onMailStatusChange();">
268
	<div class="panel">
2993 rexy 269
		<div class="panel-header"><?= $l_mail_title ?></div>
2992 rexy 270
		<div class="panel-body">
271
			<form id="form-config_mail" name="config_mail" method="POST" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" enctype="multipart/form-data">
272
				<fieldset>
273
					<legend>
274
						<br>
275
						<div style="text-align: center">
276
						</div>
277
					</legend>
278
					<dl>
279
						<dt>
2993 rexy 280
							<label for="auth_enable"><?= $l_mail_registration ?></label>
2992 rexy 281
						</dt>
282
						<dd>
283
							<select id="auth_enable" name="auth_enable" onchange="onMailStatusChange();">
2997 rexy 284
								<option value="on"<?= ($mail_status == 'on') ? ' selected="selected"' : '' ?>><?= $l_mail_YES ?></option>
2993 rexy 285
								<option value="off"<?= ($mail_status == 'off') ? ' selected="selected"' : '' ?>><?= $l_mail_NO ?></option>
2992 rexy 286
							</select>
287
						</dd>
288
					</dl>
289
					<dl>
290
						<dt>
2993 rexy 291
							<label for="mail_type"><?= $l_mail_choice ?></label><br>
2992 rexy 292
						</dt>
293
						<dd>
294
							<select id="mail_type" name="mail_type" onchange="onMailStatusChange();">
2997 rexy 295
								<option value="1"<?= ($mail_type == '1') ? ' selected="selected"' : '' ?>><?= $l_use_internal_server ?></option>
296
								<option value="2"<?= ($mail_type == '2') ? ' selected="selected"' : '' ?>><?= $l_use_external_server ?></option>
297
								<option value="3"<?= ($mail_type == '3') ? ' selected="selected"' : '' ?>><?= $l_use_email_address ?></option>
2992 rexy 298
							</select>
299
						</dd>
300
					</dl>
301
					<dl>
302
						<dt>
2993 rexy 303
							<label for="mail_address"><?= $l_email_address ?></label><br>
2992 rexy 304
						</dt>
305
						<dd>
3000 rexy 306
							<input type="text" id="mail_address" size="40" name="mail_address" value="<?= $mail_address ?>" oninput="onMailStatusChange();"> 
2992 rexy 307
						</dd>
308
					</dl>
309
					<dl>
310
						<dt>
2993 rexy 311
							<label for="mail_mdp"><?= $l_email_password ?></label><br>
2992 rexy 312
						</dt>
313
						<dd>
314
							<input type="text" id="mail_mdp" size="40" name="mail_mdp" value="<?= $mail_password_mail ?>" oninput="onMailStatusChange();"> 
315
						</dd>
316
					</dl>
317
					<dl>
318
						<dt>
2993 rexy 319
							<label for="mail_mdp2"><?= $l_email_password_confirm ?></label><br>
2992 rexy 320
						</dt>
321
						<dd>
322
							<input type="text" id="mail_mdp2" size="40" name="mail_mdp2" value="<?= $mail_password_mail_2 ?>" oninput="onMailStatusChange();"> 
323
						</dd>
324
					</dl>
325
					<dl>
326
						<dt>
2993 rexy 327
							<label for="mail_server"><?= $l_mail_service ?></label><br>
2992 rexy 328
						</dt>
329
						<dd>
330
							<select id="mail_server" name="mail_server" onchange="onMailStatusChange();">
3000 rexy 331
								<option value="1"<?= ($mail_smtp_ip == 'smtp.orange.fr') ? ' selected="selected"' : '' ?>>Orange/Wanadoo</option>
332
								<option value="2"<?= ($mail_smtp_ip == 'smtp.live.com') ? ' selected="selected"' : '' ?>>Hotmail</option>
333
								<option value="3"<?= ($mail_smtp_ip == 'smtp.office365.com') ? ' selected="selected"' : '' ?>>Outlook</option>
334
								<option value="4"<?= ($mail_smtp_ip == 'smtp.sfr.fr') ? ' selected="selected"' : '' ?>>SFR</option>
335
								<option value="5"<?= ($mail_smtp_ip == 'smtp.free.fr') ? ' selected="selected"' : '' ?>>Free</option>
336
								<option value="6"<?= ($mail_smtp_ip == 'smtp.gmail.com') ? ' selected="selected"' : '' ?>>Gmail</option>
337
								<option value="7"<?= ($mail_smtp_ip == 'smtp.laposte.net') ? ' selected="selected"' : '' ?>>Laposte</option>
338
								<option value="8"<?= ($mail_smtp_ip == 'smtp.bbox.fr') ? ' selected="selected"' : '' ?>>Bouygues</option>
339
								<option value="9">Personnalisé</option>
2992 rexy 340
							</select>
341
						</dd>
342
					</dl>
343
					<dl>
344
						<dt>
3000 rexy 345
							<label for="mail_smtp_ip"><?= $l_mail_smtp_ip ?></label><br>
2992 rexy 346
						</dt>
347
						<dd>
3000 rexy 348
							<input type="text" id="mail_smtp_ip" size="40" name="mail_smtp_ip" value="<?= $mail_smtp_ip ?>" oninput="onMailStatusChange();"> 
2992 rexy 349
						</dd>
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();">
3000 rexy 357
								<option value="1"<?= ($admin_address != '')  ? ' selected="selected"' : '' ?>><?= $l_mail_YES ?></option>
358
								<option value="0"<?= ($admin_address == '') ? ' selected="selected"' : '' ?>><?= $l_mail_NO ?></option>
2992 rexy 359
							</select>
360
						</dd>
361
					</dl>
362
					<dl>
363
						<dt>
3000 rexy 364
							<label for="admin_address"><?= $l_admin_address ?></label><br>
2992 rexy 365
						</dt>
366
						<dd>
367
							<input type="text" id="admin_address" size="40" name="admin_address" value="<?= $admin_address ?>" oninput="onMailStatusChange();"> 
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>