Subversion Repositories ALCASAR

Rev

Rev 2992 | Rev 2994 | 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);
36
 
37
$file_conf = fopen(CONF_FILE, 'r');
38
if (!$file_conf) {
39
	exit('Error opening the file '.CONF_FILE);
40
}
41
while (!feof($file_conf)) {
42
	$buffer = fgets($file_conf, 4096);
43
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
44
		$tmp = explode('=', $buffer, 2);
2991 rexy 45
		$conf[trim($tmp[0])] = trim($tmp[1]);
46
	}
47
}
48
fclose($file_conf);
49
 
2992 rexy 50
/****************************************
51
*			Choice of language			*
52
*****************************************/
53
$Language = 'en';
54
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
55
	$Langue	  = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
56
	$Language = strtolower(substr(chop($Langue[0]), 0, 2));
57
}
58
if ($Language === 'fr') {
2993 rexy 59
	$l_mail_title			= "Inscription par Email";
60
	$l_mail_registration	= "Activer l'inscription par Email :";
61
	$l_mail_choice			= "Quel type de service mail utiliser ?";
62
	$l_use_internal_server	= "Utiliser le serveur interne";
63
	$l_use_external_server	= "Relayer vers un serveur externe";
64
	$l_use_email_address	= "Utiliser une adresse mail";
65
	$l_email_address		= "Adresse mail utilisée pour l'envoi de mail";
66
	$l_email_password		= "Mot de passe";
67
	$l_email_password_confirm	= "Confirmez le mot de passe";
68
	$l_mail_service			= "Choisissez le service de messagerie";
69
	$l_mail_YES				= "OUI";
70
	$l_mail_NO				= "NON";
71
	$l_mail_submit			= "Enregistrer";
2992 rexy 72
} else {
2993 rexy 73
	$l_mail_title			= "Registration by Email";
74
	$l_mail_registration	= "Enable registration by Email :";
75
	$l_mail_choice			= "What type of mail service use ?";
76
	$l_internal_server		= "Use the internal server";
77
	$l_external_server		= "Relay to an external server";
78
	$l_email_address		= "Use an email address";
79
	$l_email_address		= "Email address used for sending mail";
80
	$l_email_password		= "Password";
81
	$l_email_password_confirm	= "Confirm password";
82
	$l_mail_service			= "Choose the mail service";
83
	$l_mail_YES				= "YES";
84
	$l_mail_NO				= "NO";
85
	$l_mail_submit			= "Save";
2992 rexy 86
}
2991 rexy 87
 
2992 rexy 88
// Mail configuration params
2993 rexy 89
$mail_status        	= $mail_conf['MAIL'];
90
$mail_type				= $mail_conf['MAIL_TYPE'];
91
$mail_address_mail		= $mail_conf['MAIL_ADDR'];
92
$mail_smtp	        	= $mail_conf['MAIL_SMTP'];
93
$mail_port				= $mail_conf['MAIL_PORT'];
94
$mail_address_ip		= $mail_conf['MAIL_SMTP_IP'];
2992 rexy 95
$mail_server			= "";
96
$mail_password_mail 	= "";
97
$mail_password_mail_2	= "";
2993 rexy 98
$admin_address			= $mail_conf['MAIL_ADMIN'];
99
$mail_whitelist			= $mail_conf['MAIL_WHITEDOMAIN'];
2991 rexy 100
 
2992 rexy 101
if(isset($_POST['submit'])){
2993 rexy 102
	if($_POST['auth_enable'] === 'on')
2992 rexy 103
	{
2993 rexy 104
//		exec("systemctl start postfix");
2992 rexy 105
		$mail_type 		= $_POST['mail_type'];
106
		$mail_address 	= $_POST['mail_address'];
107
		$mail_ip 		= $_POST['mail_ip'];
108
		$mail_server 	= $_POST['mail_server'];
109
		$mail_mdp 		= $_POST['mail_mdp'];
110
		$mail_mdp2 		= $_POST['mail_mdp2'];
111
		$admin_enable	= $_POST['admin_enable'];
112
		$admin_address	= $_POST['admin_address'];
113
		$mail_whitelist	= $_POST['mail_whitelist'];
2991 rexy 114
 
2992 rexy 115
		if ($mail_mdp == $mail_mdp2) {
116
			switch ($mail_server) {
117
			case '1':
118
				$mail_smtp		= "smtp.orange.fr";
119
				$mail_port		= 465;
120
				break;
121
			case '2':
122
				$mail_smtp		= "smtp.live.com";
123
				$mail_port		= 587;
124
				break;
125
			case '3':
126
				$mail_smtp		= "smtp.office365.com";
127
				$mail_port		= 587;
128
				break;
129
			case '4':
130
				$mail_smtp		= "smtp.sfr.fr";
131
				$mail_port		= 465;
132
				break;
133
			case '5':
134
				$mail_smtp		= "smtp.free.fr";
135
				$mail_port		= 465;	
136
				break;
137
			case '6':
138
				$mail_smtp		= "smtp.gmail.com";
139
				$mail_port		= 587;
140
				break;
141
			case '7':
142
				$mail_smtp		= "smtp.laposte.net";
143
				$mail_port		= 465;
144
				break;
145
			case '8':
146
				$mail_smtp		= "smtp.bbox.fr";
147
				$mail_port		= 587;
148
				break;
149
			default:
150
				echo "Erreur dans la saisie !";
151
				break;
152
			}
2993 rexy 153
			file_put_contents(CONF_FILE, str_replace('MAIL='.$mail_conf['MAIL'],'MAIL=on',file_get_contents(CONF_FILE)));
154
			file_put_contents(CONF_FILE, str_replace('MAIL_TYPE='.$mail_conf['MAIL_TYPE'],'MAIL_TYPE='.$mail_type,file_get_contents(CONF_FILE)));
155
			file_put_contents(CONF_FILE, str_replace('MAIL_ADDR='.$mail_conf['MAIL_ADDR'],'MAIL_ADDR='.$mail_address,file_get_contents(CONF_FILE)));
156
			file_put_contents(CONF_FILE, str_replace('MAIL_SMTP_IP='.$mail_conf['MAIL_SMTP_IP'],'MAIL_SMTP_IP='.$mail_ip,file_get_contents(CONF_FILE)));
157
			file_put_contents(CONF_FILE, str_replace('MAIL_SMTP='.$mail_conf['MAIL_SMTP'],'MAIL_SMTP='.$mail_smtp,file_get_contents(CONF_FILE)));
158
			file_put_contents(CONF_FILE, str_replace('MAIL_PORT='.$mail_conf['MAIL_PORT'],'MAIL_PORT='.$mail_port,file_get_contents(CONF_FILE)));
159
			file_put_contents(CONF_FILE, str_replace('MAIL_WHITEDOMAIN='.$mail_conf['MAIL_WHITEDOMAIN'],'MAIL_WHITEDOMAIN='.$mail_whitelist,file_get_contents(CONF_FILE)));
2992 rexy 160
			if (isset($admin_address)) {
2993 rexy 161
				file_put_contents(CONF_FILE, str_replace('MAIL_ADMIN='.$mail_conf['MAIL_ADMIN'],'MAIL_ADMIN='.$admin_address,file_get_contents(CONF_FILE)));
2992 rexy 162
			}
163
			switch ($mail_type) {
164
				case '1':
165
					$mail_port = 25;
2993 rexy 166
					file_put_contents(CONF_FILE, str_replace('port='.$mail_conf['port'],'port='.$mail_port,file_get_contents(CONF_FILE)));
2992 rexy 167
					if(isset($mail_admin)){
2993 rexy 168
						exec("sudo /usr/bin/bash /usr/local/bin/alcasar-mail-install.sh -1 -a $admin_address -w $mail_whitelist");
2991 rexy 169
					}
2992 rexy 170
					else {
2993 rexy 171
						exec("sudo /usr/bin/bash /usr/local/bin/alcasar-mail-install.sh -1 -w $mail_whitelist");
2992 rexy 172
					}
173
					break;
174
				case '2':
175
					if(isset($mail_admin)){
2993 rexy 176
						exec("sudo /usr/bin/bash /usr/local/bin/alcasar-mail-install.sh -2 -s $mail_smtp -p $mail_port -r $mail_ip -a $admin_address -w $mail_whitelist");
2992 rexy 177
					}
178
					else {
2993 rexy 179
						exec("sudo /usr/bin/bash /usr/local/bin/alcasar-mail-install.sh -2 -s $mail_smtp -p $mail_port -r $mail_ip -w $mail_whitelist");
2992 rexy 180
					}
181
					break;
182
				case '3':
183
					if(isset($mail_admin)){
2993 rexy 184
						exec("sudo /usr/bin/bash /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 185
					}
186
					else {
2993 rexy 187
						exec("sudo /usr/bin/bash /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 188
					}
189
					break;
190
				default:
191
					echo "Erreur dans la saisie !";
192
					break;
2991 rexy 193
			}
2992 rexy 194
		}
2993 rexy 195
		else { // password are not the same
2992 rexy 196
			echo "Erreur";
197
		}
2991 rexy 198
	}
2993 rexy 199
	else { // switch email registation off
200
		exec("/usr/local/bin/alcasar-mail-install.sh -0");
2992 rexy 201
	}
202
	header("Refresh:0");
203
	exit;
2991 rexy 204
}
205
 
206
?>
2992 rexy 207
<!DOCTYPE html>
208
<html>
209
<head>
210
	<meta charset="UTF-8">
211
	<title><?= $l_mail_title ?></title>
212
	<link type="text/css" href="/css/acc.css" rel="stylesheet">
213
	<link type="text/css" href="/css/mail.css" rel="stylesheet">
214
	<script>
215
	function onMailStatusChange() {
216
		var listToDisables1 = ['mail_type','admin_enable','admin_address','mail_whitelist'];
217
		var listToDisables2 = ['mail_server','mail_type','admin_enable','admin_address','mail_whitelist','mail_ip'];
218
		var listToDisables3 = ['mail_server','mail_mdp2','mail_mdp','mail_address','mail_type','admin_enable','admin_address','mail_whitelist'];
219
		var formSubmit = document.querySelector('form input[type="submit"]');
220
		var btn_checkConf = document.getElementById('btn-checkconf');
221
		var isChecked = false;
2993 rexy 222
		if (document.getElementById('auth_enable').value === 'on') {
2992 rexy 223
			for (var i=0; i<listToDisables1.length; i++) {
224
				document.getElementById(listToDisables1[i]).style.backgroundColor = '#c0c0c0';
225
				document.getElementById(listToDisables1[i]).disabled = true;
2991 rexy 226
			}
2992 rexy 227
			for (var i=0; i<listToDisables2.length; i++) {
228
				document.getElementById(listToDisables2[i]).style.backgroundColor = '#c0c0c0';
229
				document.getElementById(listToDisables2[i]).disabled = true;
230
			}
231
			for (var i=0; i<listToDisables3.length; i++) {
232
				document.getElementById(listToDisables3[i]).style.backgroundColor = '#c0c0c0';
233
				document.getElementById(listToDisables3[i]).disabled = true;
234
			}
235
			document.getElementById('mail_type').style.backgroundColor = null;
236
			document.getElementById('mail_type').disabled = false;
2993 rexy 237
			if (document.getElementById('mail_type').value === 'on') {
2992 rexy 238
				for (var i=0; i<listToDisables1.length; i++) {
239
				document.getElementById(listToDisables1[i]).style.backgroundColor = null;
240
				document.getElementById(listToDisables1[i]).disabled = false;
241
				}
242
				if (document.getElementById('admin_enable').value === '0') {
243
				document.getElementById('admin_address').style.backgroundColor = '#c0c0c0';
244
				document.getElementById('admin_address').disabled = true;
245
				}
246
			}
247
			else if (document.getElementById('mail_type').value === '2') {
248
				for (var i=0; i<listToDisables2.length; i++) {
249
				document.getElementById(listToDisables2[i]).style.backgroundColor = null;
250
				document.getElementById(listToDisables2[i]).disabled = false;
251
				}
252
				if (document.getElementById('admin_enable').value === '0') {
253
				document.getElementById('admin_address').style.backgroundColor = '#c0c0c0';
254
				document.getElementById('admin_address').disabled = true;
255
				}
256
			}
257
			else if (document.getElementById('mail_type').value === '3') {
258
				for (var i=0; i<listToDisables3.length; i++) {
259
				document.getElementById(listToDisables3[i]).style.backgroundColor = null;
260
				document.getElementById(listToDisables3[i]).disabled = false;
261
				}
262
				if (document.getElementById('admin_enable').value === '0') {
263
				document.getElementById('admin_address').style.backgroundColor = '#c0c0c0';
264
				document.getElementById('admin_address').disabled = true;
265
				}
266
			}
267
			formSubmit.style.display = null;
268
			btn_checkConf.style.display = 'none';
269
		} else {
270
			for (var i=0; i<listToDisables1.length; i++) {
271
				document.getElementById(listToDisables1[i]).style.backgroundColor = '#c0c0c0';
272
				document.getElementById(listToDisables1[i]).disabled = true;
273
			}
274
			for (var i=0; i<listToDisables2.length; i++) {
275
				document.getElementById(listToDisables2[i]).style.backgroundColor = '#c0c0c0';
276
				document.getElementById(listToDisables2[i]).disabled = true;
277
			}
278
			for (var i=0; i<listToDisables3.length; i++) {
279
				document.getElementById(listToDisables3[i]).style.backgroundColor = '#c0c0c0';
280
				document.getElementById(listToDisables3[i]).disabled = true;
281
			}
282
			formSubmit.style.display = null;
283
			btn_checkConf.style.display = 'none';
2991 rexy 284
		}
2992 rexy 285
	}
286
	</script>
287
</head>
288
<body onLoad="onMailStatusChange();">
289
	<div class="panel">
2993 rexy 290
		<div class="panel-header"><?= $l_mail_title ?></div>
2992 rexy 291
		<div class="panel-body">
292
			<form id="form-config_mail" name="config_mail" method="POST" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" enctype="multipart/form-data">
293
				<fieldset>
294
					<legend>
295
						<br>
296
						<div style="text-align: center">
297
						</div>
298
					</legend>
299
					<dl>
300
						<dt>
2993 rexy 301
							<label for="auth_enable"><?= $l_mail_registration ?></label>
2992 rexy 302
						</dt>
303
						<dd>
304
							<select id="auth_enable" name="auth_enable" onchange="onMailStatusChange();">
2993 rexy 305
								<option value="on"<?= ($mail_status == 'on')  ? ' selected="selected"' : '' ?>><?= $l_mail_YES ?></option>
306
								<option value="off"<?= ($mail_status == 'off') ? ' selected="selected"' : '' ?>><?= $l_mail_NO ?></option>
2992 rexy 307
							</select>
308
						</dd>
309
					</dl>
310
					<dl>
311
						<dt>
2993 rexy 312
							<label for="mail_type"><?= $l_mail_choice ?></label><br>
2992 rexy 313
						</dt>
314
						<dd>
315
							<select id="mail_type" name="mail_type" onchange="onMailStatusChange();">
2993 rexy 316
								<option value=1><?= $l_use_internal_server ?></option>
317
								<option value=2><?= $l_use_external_server ?></option>
318
								<option value=3><?= $l_use_email_address ?></option>
2992 rexy 319
							</select>
320
						</dd>
321
					</dl>
322
					<dl>
323
						<dt>
2993 rexy 324
							<label for="mail_address"><?= $l_email_address ?></label><br>
2992 rexy 325
						</dt>
326
						<dd>
327
							<input type="text" id="mail_address" size="40" name="mail_address" value="<?= $mail_address_mail ?>" oninput="onMailStatusChange();"> 
328
						</dd>
329
					</dl>
330
					<dl>
331
						<dt>
2993 rexy 332
							<label for="mail_mdp"><?= $l_email_password ?></label><br>
2992 rexy 333
						</dt>
334
						<dd>
335
							<input type="text" id="mail_mdp" size="40" name="mail_mdp" value="<?= $mail_password_mail ?>" oninput="onMailStatusChange();"> 
336
						</dd>
337
					</dl>
338
					<dl>
339
						<dt>
2993 rexy 340
							<label for="mail_mdp2"><?= $l_email_password_confirm ?></label><br>
2992 rexy 341
						</dt>
342
						<dd>
343
							<input type="text" id="mail_mdp2" size="40" name="mail_mdp2" value="<?= $mail_password_mail_2 ?>" oninput="onMailStatusChange();"> 
344
						</dd>
345
					</dl>
346
					<dl>
347
						<dt>
2993 rexy 348
							<label for="mail_server"><?= $l_mail_service ?></label><br>
2992 rexy 349
						</dt>
350
						<dd>
351
							<select id="mail_server" name="mail_server" onchange="onMailStatusChange();">
352
								<option value=1>Orange/Wanadoo</option>
353
								<option value=2>Hotmail</option>
354
								<option value=3>Outlook</option>
355
								<option value=4>SFR</option>
356
								<option value=5>Free</option>
357
								<option value=6>Gmail</option>
358
								<option value=7>Laposte</option>
359
								<option value=8>Bouygues</option>
360
								<option value=9>Personnalisé</option>
361
							</select>
362
						</dd>
363
					</dl>
364
					<dl>
365
						<dt>
366
							<label for="mail_ip"><?= "IP du serveur SMTP"?></label><br>
367
							<?= "Adresse IP du serveur SMTP utilisé" ?>
368
						</dt>
369
						<dd>
370
							<input type="text" id="mail_ip" size="40" name="mail_ip" value="<?= $mail_address_ip ?>" oninput="onMailStatusChange();"> 
371
						</dd>
372
					</dl>
373
					<dl>
374
						<dt>
375
							<label for="admin_enable"><?= "Activer l'adresse admin :" ?></label>
376
						</dt>
377
						<dd>
378
							<select id="admin_enable" name="admin_enable" onchange="onMailStatusChange();">
379
								<option value="1"<?= ($mail_status)  ? ' selected="selected"' : '' ?>><?= $l_mail_YES ?></option>
380
								<option value="0"<?= (!$mail_status) ? ' selected="selected"' : '' ?>><?= $l_mail_NO ?></option>
381
							</select>
382
						</dd>
383
					</dl>
384
					<dl>
385
						<dt>
386
							<label for="admin_address"><?= "Adresse Messagerie admin"?></label><br>
387
							<?= "Adresse de messagerie utilisé pour l'envoi" ?>
388
						</dt>
389
						<dd>
390
							<input type="text" id="admin_address" size="40" name="admin_address" value="<?= $admin_address ?>" oninput="onMailStatusChange();"> 
391
						</dd>
392
					</dl>
393
					<dl>
394
						<dt>
395
							<label for="mail_whitelist"><?= "whitelist domaine"?></label><br>
396
							<?= "Adresse de messagerie utilisé pour l'envoi" ?>
397
						</dt>
398
						<dd>
399
							<input type="text" id="mail_whitelist" size="40" name="mail_whitelist" value="<?= $mail_whitelist ?>" oninput="onMailStatusChange();"> 
400
						</dd>
401
					</dl>
402
					<p>
403
						<input id="submit" type="submit" value="<?= $l_mail_submit ?>" name="submit">
404
					</p>
405
				</fieldset>
406
			</form>
407
		</div>
408
	</div>
2991 rexy 409
</body>
410
</html>