Subversion Repositories ALCASAR

Rev

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