Subversion Repositories ALCASAR

Rev

Rev 2991 | Rev 2993 | 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
*****************************************************************/
8
define('CONF_FILE', '/usr/local/etc/alcasar-mail.conf');
2991 rexy 9
 
2992 rexy 10
/****************************************************************
11
*			FILE reading test			*
12
*****************************************************************/
13
$conf_files = array(CONF_FILE);
14
foreach ($conf_files as $file) {
15
	if (!file_exists($file)) {
16
		exit("Fichier $file non présent");
2991 rexy 17
	}
2992 rexy 18
	if (!is_readable($file)) {
19
		exit("Vous n'avez pas les droits de lecture sur le fichier $file");
2991 rexy 20
	}
21
}
22
 
23
/****************************************************************
2992 rexy 24
*			Read CONF_FILE				*
2991 rexy 25
*****************************************************************/
26
$file_conf = fopen(CONF_FILE, 'r');
27
if (!$file_conf) {
28
	exit('Error opening the file '.CONF_FILE);
29
}
30
while (!feof($file_conf)) {
31
	$buffer = fgets($file_conf, 4096);
32
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
33
		$tmp = explode('=', $buffer, 2);
34
		$conf[trim($tmp[0])] = trim($tmp[1]);
35
	}
36
}
37
fclose($file_conf);
38
 
2992 rexy 39
/****************************************
40
*			Choice of language			*
41
*****************************************/
42
$Language = 'en';
43
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
44
	$Langue	  = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
45
	$Language = strtolower(substr(chop($Langue[0]), 0, 2));
46
}
47
if ($Language === 'fr') {
48
	$l_mail_title			= "Authentification externe : Adresse mail";
49
	$l_mail_auth_enable_label	= "Activer l'authentification par mail :";
50
	$l_mail_YES			= "OUI";
51
	$l_mail_NO			= "NON";
52
} else {
53
	$l_mail_title			= "External authentication : Address mail";
54
	$l_mail_auth_enable_label	= "Enable email authentication :";
55
	$l_mail_YES			= "YES";
56
	$l_mail_NO			= "NO";
57
}
2991 rexy 58
 
2992 rexy 59
// Mail configuration params
60
$mail_status        	= $conf['MAIL'];
61
$mail_type				= $conf['TYPE_MAIL'];
62
$mail_address_mail		= $conf['mailAddr'];
63
$mail_smtp	        	= $conf['smtp'];
64
$mail_port				= $conf['port'];
65
$mail_address_ip		= $conf['mailIP'];
66
$mail_server			= "";
67
$mail_password_mail 	= "";
68
$mail_password_mail_2	= "";
69
$admin_address			= $conf['adminMail'];
70
$mail_whitelist			= $conf['whiteDomain'];
2991 rexy 71
 
72
 
2992 rexy 73
if(isset($_POST['submit'])){
74
	if($_POST['auth_enable'] === '1')
75
	{
76
		exec("systemctl start postfix");
2991 rexy 77
 
2992 rexy 78
		$mail_status 	= $_POST['auth_enable'];
79
		$mail_type 		= $_POST['mail_type'];
80
		$mail_address 	= $_POST['mail_address'];
81
		$mail_ip 		= $_POST['mail_ip'];
82
		$mail_server 	= $_POST['mail_server'];
83
		$mail_mdp 		= $_POST['mail_mdp'];
84
		$mail_mdp2 		= $_POST['mail_mdp2'];
85
		$admin_enable	= $_POST['admin_enable'];
86
		$admin_address	= $_POST['admin_address'];
87
		$mail_whitelist	= $_POST['mail_whitelist'];
88
 
89
//		exec("cp /var/www/mail/header.php /var/www/html");
90
//		exec("cp /var/www/mail/inscription.php /var/www/html");
91
//		exec("cp /var/www/mail/inscription_traitement.php /var/www/html");
92
//		exec("cp /var/www/html/acc/admin/services.php /var/www/html/acc/admin/services.php.origin");
93
//		exec("cp /var/www/mail/services.php /var/www/html/acc/admin");
2991 rexy 94
 
2992 rexy 95
		if ($mail_mdp == $mail_mdp2) {
96
			switch ($mail_server) {
97
			case '1':
98
				$mail_smtp		= "smtp.orange.fr";
99
				$mail_port		= 465;
100
				break;
101
			case '2':
102
				$mail_smtp		= "smtp.live.com";
103
				$mail_port		= 587;
104
				break;
105
			case '3':
106
				$mail_smtp		= "smtp.office365.com";
107
				$mail_port		= 587;
108
				break;
109
			case '4':
110
				$mail_smtp		= "smtp.sfr.fr";
111
				$mail_port		= 465;
112
				break;
113
			case '5':
114
				$mail_smtp		= "smtp.free.fr";
115
				$mail_port		= 465;	
116
				break;
117
			case '6':
118
				$mail_smtp		= "smtp.gmail.com";
119
				$mail_port		= 587;
120
				break;
121
			case '7':
122
				$mail_smtp		= "smtp.laposte.net";
123
				$mail_port		= 465;
124
				break;
125
			case '8':
126
				$mail_smtp		= "smtp.bbox.fr";
127
				$mail_port		= 587;
128
				break;
129
			default:
130
				echo "Erreur dans la saisie !";
131
				break;
132
			}
133
			file_put_contents(CONF_FILE, str_replace('MAIL='.$conf['MAIL'],'MAIL='.$mail_status,file_get_contents(CONF_FILE)));
134
			file_put_contents(CONF_FILE, str_replace('TYPE_MAIL='.$conf['TYPE_MAIL'],'TYPE_MAIL='.$mail_type,file_get_contents(CONF_FILE)));
135
			file_put_contents(CONF_FILE, str_replace('mailAddr='.$conf['mailAddr'],'mailAddr='.$mail_address,file_get_contents(CONF_FILE)));
136
			file_put_contents(CONF_FILE, str_replace('mailIP='.$conf['mailIP'],'mailIP='.$mail_ip,file_get_contents(CONF_FILE)));
137
			file_put_contents(CONF_FILE, str_replace('smtp='.$conf['smtp'],'smtp='.$mail_smtp,file_get_contents(CONF_FILE)));
138
			file_put_contents(CONF_FILE, str_replace('port='.$conf['port'],'port='.$mail_port,file_get_contents(CONF_FILE)));
139
			file_put_contents(CONF_FILE, str_replace('whiteDomain='.$conf['mail_whitelist'],'whiteDomain='.$mail_whitelist,file_get_contents(CONF_FILE)));
140
			if (isset($admin_address)) {
141
				file_put_contents(CONF_FILE, str_replace('adminMail='.$conf['admin_address'],'adminMail='.$admin_address,file_get_contents(CONF_FILE)));
142
			}
143
			switch ($mail_type) {
144
				case '1':
145
					$mail_port = 25;
146
					file_put_contents(CONF_FILE, str_replace('port='.$conf['port'],'port='.$mail_port,file_get_contents(CONF_FILE)));
147
					if(isset($mail_admin)){
148
						exec("sudo /usr/bin/bash /usr/local/bin/alcasar-mail-install-V2.sh -1 -a $admin_address -w $mail_whitelist");
2991 rexy 149
					}
2992 rexy 150
					else {
151
						exec("sudo /usr/bin/bash /usr/local/bin/alcasar-mail-install-V2.sh -1 -w $mail_whitelist");
152
					}
153
					break;
154
				case '2':
155
					if(isset($mail_admin)){
156
						exec("sudo /usr/bin/bash /usr/local/bin/alcasar-mail-install-V2.sh -2 -s $mail_smtp -p $mail_port -r $mail_ip -a $admin_address -w $mail_whitelist");
157
					}
158
					else {
159
						exec("sudo /usr/bin/bash /usr/local/bin/alcasar-mail-install-V2.sh -2 -s $mail_smtp -p $mail_port -r $mail_ip -w $mail_whitelist");
160
					}
161
					break;
162
				case '3':
163
					if(isset($mail_admin)){
164
						exec("sudo /usr/bin/bash /usr/local/bin/alcasar-mail-install-V2.sh -3 -s $mail_smtp -p $mail_port -m $mail_address -o $mail_mdp -a $admin_address -w $mail_whitelist");
165
					}
166
					else {
167
						exec("sudo /usr/bin/bash /usr/local/bin/alcasar-mail-install-V2.sh -3 -s $mail_smtp -p $mail_port -m $mail_address -o $mail_mdp -w $mail_whitelist");
168
					}
169
					break;
170
				default:
171
					echo "Erreur dans la saisie !";
172
					break;
2991 rexy 173
			}
2992 rexy 174
		}
175
		else {
176
			echo "Erreur";
177
		}
2991 rexy 178
	}
2992 rexy 179
	else {
180
		exec("cp -f /etc/postfix/main.cf.origin  /etc/postfix/main.cf");
181
		exec("rm -rf /etc/postfix/sasl/");
182
		exec("cp -f /var/www/mail/alcasar-mail.conf /usr/local/etc/");
183
		exec("systemctl restart postfix");
184
		exec("systemctl stop postfix");
185
		exec("sed -i '/SMTP_IP=/ s/^/#/g' /usr/local/etc/alcasar-iptables-local.sh");
186
		exec("sed -i '/SMTP_PORT=/ s/^/#/g' /usr/local/etc/alcasar-iptables-local.sh");
187
		exec("rm -f /var/www/html/header.php");
188
		exec("rm -f /var/www/html/inscription.php");
189
		exec("rm -f /var/www/html/inscription_traitement.php");
190
		exec("cp -f /var/www/html/acc/admin/services.php.origin /var/www/html/acc/admin/services.php");
191
		exec("sudo /usr/bin/bash /usr/local/bin/alcasar-iptables.sh");
192
	}
193
	header("Refresh:0");
194
	exit;
2991 rexy 195
}
196
 
197
?>
2992 rexy 198
<!DOCTYPE html>
199
<html>
200
<head>
201
	<meta charset="UTF-8">
202
	<title><?= $l_mail_title ?></title>
203
	<link type="text/css" href="/css/acc.css" rel="stylesheet">
204
	<link type="text/css" href="/css/mail.css" rel="stylesheet">
205
	<script>
206
	function onMailStatusChange() {
207
		var listToDisables1 = ['mail_type','admin_enable','admin_address','mail_whitelist'];
208
		var listToDisables2 = ['mail_server','mail_type','admin_enable','admin_address','mail_whitelist','mail_ip'];
209
		var listToDisables3 = ['mail_server','mail_mdp2','mail_mdp','mail_address','mail_type','admin_enable','admin_address','mail_whitelist'];
210
		var formSubmit = document.querySelector('form input[type="submit"]');
211
		var btn_checkConf = document.getElementById('btn-checkconf');
212
		var isChecked = false;
213
		if (document.getElementById('auth_enable').value === '1') {
214
			for (var i=0; i<listToDisables1.length; i++) {
215
				document.getElementById(listToDisables1[i]).style.backgroundColor = '#c0c0c0';
216
				document.getElementById(listToDisables1[i]).disabled = true;
2991 rexy 217
			}
2992 rexy 218
			for (var i=0; i<listToDisables2.length; i++) {
219
				document.getElementById(listToDisables2[i]).style.backgroundColor = '#c0c0c0';
220
				document.getElementById(listToDisables2[i]).disabled = true;
221
			}
222
			for (var i=0; i<listToDisables3.length; i++) {
223
				document.getElementById(listToDisables3[i]).style.backgroundColor = '#c0c0c0';
224
				document.getElementById(listToDisables3[i]).disabled = true;
225
			}
226
			document.getElementById('mail_type').style.backgroundColor = null;
227
			document.getElementById('mail_type').disabled = false;
228
			if (document.getElementById('mail_type').value === '1') {
229
				for (var i=0; i<listToDisables1.length; i++) {
230
				document.getElementById(listToDisables1[i]).style.backgroundColor = null;
231
				document.getElementById(listToDisables1[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 === '2') {
239
				for (var i=0; i<listToDisables2.length; i++) {
240
				document.getElementById(listToDisables2[i]).style.backgroundColor = null;
241
				document.getElementById(listToDisables2[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
			else if (document.getElementById('mail_type').value === '3') {
249
				for (var i=0; i<listToDisables3.length; i++) {
250
				document.getElementById(listToDisables3[i]).style.backgroundColor = null;
251
				document.getElementById(listToDisables3[i]).disabled = false;
252
				}
253
				if (document.getElementById('admin_enable').value === '0') {
254
				document.getElementById('admin_address').style.backgroundColor = '#c0c0c0';
255
				document.getElementById('admin_address').disabled = true;
256
				}
257
			}
258
			formSubmit.style.display = null;
259
			btn_checkConf.style.display = 'none';
260
		} else {
261
			for (var i=0; i<listToDisables1.length; i++) {
262
				document.getElementById(listToDisables1[i]).style.backgroundColor = '#c0c0c0';
263
				document.getElementById(listToDisables1[i]).disabled = true;
264
			}
265
			for (var i=0; i<listToDisables2.length; i++) {
266
				document.getElementById(listToDisables2[i]).style.backgroundColor = '#c0c0c0';
267
				document.getElementById(listToDisables2[i]).disabled = true;
268
			}
269
			for (var i=0; i<listToDisables3.length; i++) {
270
				document.getElementById(listToDisables3[i]).style.backgroundColor = '#c0c0c0';
271
				document.getElementById(listToDisables3[i]).disabled = true;
272
			}
273
			formSubmit.style.display = null;
274
			btn_checkConf.style.display = 'none';
2991 rexy 275
		}
2992 rexy 276
	}
277
	</script>
278
</head>
279
<body onLoad="onMailStatusChange();">
280
	<div class="panel">
281
		<div class="panel-header"><?= "Authentication Mail" ?></div>
282
		<div class="panel-body">
283
			<form id="form-config_mail" name="config_mail" method="POST" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" enctype="multipart/form-data">
284
				<fieldset>
285
					<legend>
286
						<br>
287
						<div style="text-align: center">
288
						</div>
289
					</legend>
290
					<dl>
291
						<dt>
292
							<label for="auth_enable"><?= "Activer l'authentification par mail :" ?></label>
293
						</dt>
294
						<dd>
295
							<select id="auth_enable" name="auth_enable" onchange="onMailStatusChange();">
296
								<option value="1"<?= ($mail_status)  ? ' selected="selected"' : '' ?>><?= $l_mail_YES ?></option>
297
								<option value="0"<?= (!$mail_status) ? ' selected="selected"' : '' ?>><?= $l_mail_NO ?></option>
298
							</select>
299
						</dd>
300
					</dl>
301
					<dl>
302
						<dt>
303
							<label for="mail_type"><?= "Type Messagerie" ?></label><br>
304
							<?= "Choississez le type de messagerie a utiliser" ?><br>
305
						</dt>
306
						<dd>
307
							<select id="mail_type" name="mail_type" onchange="onMailStatusChange();">
308
								<option value=1>Nom de domaine</option>
309
								<option value=2>Serveur mail ou serveur SMTP</option>
310
								<option value=3>Adresse de messagerie</option>
311
							</select>
312
						</dd>
313
					</dl>
314
					<dl>
315
						<dt>
316
							<label for="mail_address"><?= "Adresse Messagerie"?></label><br>
317
							<?= "Adresse de messagerie utilisé pour l'envoi" ?>
318
						</dt>
319
						<dd>
320
							<input type="text" id="mail_address" size="40" name="mail_address" value="<?= $mail_address_mail ?>" oninput="onMailStatusChange();"> 
321
						</dd>
322
					</dl>
323
					<dl>
324
						<dt>
325
							<label for="mail_mdp"><?= "Mot de passe Messagerie"?></label><br>
326
							<?= "Mot de passe de la messagerie utilisé pour l'envoi" ?>
327
						</dt>
328
						<dd>
329
							<input type="text" id="mail_mdp" size="40" name="mail_mdp" value="<?= $mail_password_mail ?>" oninput="onMailStatusChange();"> 
330
						</dd>
331
					</dl>
332
					<dl>
333
						<dt>
334
							<label for="mail_mdp2"><?= "Confirmer Mot de passe Messagerie"?></label><br>
335
							<?= "Confirmer le mot de passe de la messagerie utilisé pour l'envoi" ?>
336
						</dt>
337
						<dd>
338
							<input type="text" id="mail_mdp2" size="40" name="mail_mdp2" value="<?= $mail_password_mail_2 ?>" oninput="onMailStatusChange();"> 
339
						</dd>
340
					</dl>
341
					<dl>
342
						<dt>
343
							<label for="mail_server"><?= "CHoix Serveur SMTP" ?></label><br>
344
							<?= "Choissisiez le serveur SMTP correspondant à l'adress de messagerie" ?><br>
345
						</dt>
346
						<dd>
347
							<select id="mail_server" name="mail_server" onchange="onMailStatusChange();">
348
								<option value=1>Orange/Wanadoo</option>
349
								<option value=2>Hotmail</option>
350
								<option value=3>Outlook</option>
351
								<option value=4>SFR</option>
352
								<option value=5>Free</option>
353
								<option value=6>Gmail</option>
354
								<option value=7>Laposte</option>
355
								<option value=8>Bouygues</option>
356
								<option value=9>Personnalisé</option>
357
							</select>
358
						</dd>
359
					</dl>
360
					<dl>
361
						<dt>
362
							<label for="mail_ip"><?= "IP du serveur SMTP"?></label><br>
363
							<?= "Adresse IP du serveur SMTP utilisé" ?>
364
						</dt>
365
						<dd>
366
							<input type="text" id="mail_ip" size="40" name="mail_ip" value="<?= $mail_address_ip ?>" oninput="onMailStatusChange();"> 
367
						</dd>
368
					</dl>
369
					<dl>
370
						<dt>
371
							<label for="admin_enable"><?= "Activer l'adresse admin :" ?></label>
372
						</dt>
373
						<dd>
374
							<select id="admin_enable" name="admin_enable" onchange="onMailStatusChange();">
375
								<option value="1"<?= ($mail_status)  ? ' selected="selected"' : '' ?>><?= $l_mail_YES ?></option>
376
								<option value="0"<?= (!$mail_status) ? ' selected="selected"' : '' ?>><?= $l_mail_NO ?></option>
377
							</select>
378
						</dd>
379
					</dl>
380
					<dl>
381
						<dt>
382
							<label for="admin_address"><?= "Adresse Messagerie admin"?></label><br>
383
							<?= "Adresse de messagerie utilisé pour l'envoi" ?>
384
						</dt>
385
						<dd>
386
							<input type="text" id="admin_address" size="40" name="admin_address" value="<?= $admin_address ?>" oninput="onMailStatusChange();"> 
387
						</dd>
388
					</dl>
389
					<dl>
390
						<dt>
391
							<label for="mail_whitelist"><?= "whitelist domaine"?></label><br>
392
							<?= "Adresse de messagerie utilisé pour l'envoi" ?>
393
						</dt>
394
						<dd>
395
							<input type="text" id="mail_whitelist" size="40" name="mail_whitelist" value="<?= $mail_whitelist ?>" oninput="onMailStatusChange();"> 
396
						</dd>
397
					</dl>
398
					<p>
399
						<!--<button id="btn-checkconf" onclick="checkConfig(); return false;"><?= $l_check ?></button>-->
400
						<input id="submit" type="submit" value="<?= $l_mail_submit ?>" name="submit">
401
					</p>
402
				</fieldset>
403
			</form>
404
		</div>
405
	</div>
2991 rexy 406
</body>
407
</html>