Subversion Repositories ALCASAR

Rev

Rev 2991 | Rev 2993 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2991 Rev 2992
Line 1... Line 1...
1
<?php
1
<?php
2
/* written by K@M3L & joss_p & Rexy */
2
# $Id: mail.php 2853 2020-07-19 21:50:07Z joss_p $
3
 
3
 
4
// partie $_POST du service mail
4
/* written by Joss_p & Rexy */
5
$php_self = htmlspecialchars($_SERVER['PHP_SELF']);
-
 
6
if(!empty($_POST)){
-
 
7
	var_dump($_POST);
-
 
8
// contient les options et les arguments au configurateur
5
/****************************************************************
9
	$optArg = "";
-
 
10
	
-
 
11
	if(!empty($_POST['testConf'])){ 	
-
 
12
		$optArg .= " -".trim($_POST['testConf']);
-
 
13
	}
-
 
14
	if(!empty($_POST['smtp'])){ 	
-
 
15
		$optArg .= " -s \"".trim($_POST['smtp'])."\"";
-
 
16
	}
-
 
17
	if(!empty($_POST['port'])){ 	
-
 
18
		$optArg .= " -p \"".trim($_POST['port'])."\"";
-
 
19
	}
-
 
20
	if(!empty($_POST['smtpPort'])){ 	
-
 
21
		$smtpPort = explode(" ", $_POST['smtpPort']);
-
 
22
		$optArg .= " -s \"".trim($smtpPort[0])."\" -p \"".trim($smtpPort[1])."\"";
-
 
23
	}
-
 
24
	if(!empty($_POST['smtpIP'])){ 	
6
*			GLOBAL FILE PATHS			*
25
		$optArg .= " -r \"".trim($_POST['smtpIP'])."\"";
-
 
26
	}
-
 
27
	if(!empty($_POST['mailAddr'])){ 	
-
 
28
		$optArg .= " -m \"".trim($_POST['mailAddr'])."\"";
-
 
29
	}
-
 
30
	if(!empty($_POST['pswd1']) && !empty($_POST['pswd2'])){
-
 
31
		if (trim($_POST['pswd1']) == trim($_POST['pswd2'])){
-
 
32
			$optArg .= " -o \"".trim($_POST['pswd2'])."\"";
-
 
33
		} else {
-
 
34
			echo "<script> alert(\"Les deux mots de passe sont différents\"); window.location.href=\"services.php\";</script>";
-
 
35
		}
-
 
36
	}
-
 
37
	if(!empty($_POST['adminMail'])){ 	
-
 
38
		$optArg .= " -a \"".$_POST['adminMail']."\"";
-
 
39
	}
-
 
40
	if(!empty($_POST['wld'])){ 	
-
 
41
		$optArg .= " -w \"".str_replace("\r"," ",trim($_POST['wld']))."\"";
7
*****************************************************************/
42
	}
-
 
43
 
-
 
44
// Supprimer la WLD ou l'email de l'admin
-
 
45
	if(!empty($_POST['unset'])){
-
 
46
		exec("sudo sed -i '/". $_POST['unset']."/d' /usr/local/etc/alcasar-mail.conf", $output, $retval);
-
 
47
 
-
 
48
		var_dump($output);
-
 
49
		echo "<br>\$retval : " . $retval;
-
 
50
	}
-
 
51
 
-
 
52
// Supprimer toute la configuration actuelle
-
 
53
	if(!empty($_POST['uninstall'])){
-
 
54
//		echo "sudo /usr/local/bin/alcasar-mail-uninstall.sh <br>";
8
define('CONF_FILE', '/usr/local/etc/alcasar-mail.conf');
55
		exec("sudo /usr/local/bin/alcasar-mail-uninstall.sh", $output, $retval);
-
 
56
 
9
 
-
 
10
/****************************************************************
57
		var_dump($output);
11
*			FILE reading test			*
-
 
12
*****************************************************************/
-
 
13
$conf_files = array(CONF_FILE);
-
 
14
foreach ($conf_files as $file) {
-
 
15
	if (!file_exists($file)) {
58
		echo "<br>\$retval : " . $retval;
16
		exit("Fichier $file non présent");
59
	}
17
	}
60
	
-
 
61
	if(!empty($optArg)){
18
	if (!is_readable($file)) {
62
		echo "sudo /usr/local/bin/alcasar-mail-install.sh".$optArg;
19
		exit("Vous n'avez pas les droits de lecture sur le fichier $file");
63
		exec("sudo /usr/local/bin/alcasar-mail-install.sh".escapeshellcmd($optArg), $output, $retval);
-
 
64
		var_dump($output);
-
 
65
		echo "<br>\$retval : " . $retval;
-
 
66
	}
20
	}
67
//	à décommenté une fois tests et debugs réalisé pour recharger la page sans le $_POST
-
 
68
//	header("Location:services.php");
-
 
69
 
-
 
70
}// Fin de la partie $_POST du service mail
-
 
71
 
-
 
72
 
-
 
73
# Choice of language
-
 
74
$Language = 'en';
-
 
75
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
-
 
76
	$Langue		= explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
-
 
77
	$Language	= strtolower(substr(chop($Langue[0]),0,2)); }
-
 
78
if($Language == 'fr') {
-
 
79
	$l_reboot		= "Relancer le système";
-
 
80
} else if($Language == 'es') {
-
 
81
	$l_reboot		= "Reiniciar el sistema";
-
 
82
} else {
-
 
83
	$l_reboot		= "Restart the system";
-
 
84
}
21
}
85
 
22
 
86
/****************************************************************
23
/****************************************************************
87
*	                   CONST				*
24
*			Read CONF_FILE				*
88
*****************************************************************/
25
*****************************************************************/
89
define ("CONF_FILE", "/usr/local/etc/alcasar.conf");
-
 
90
 
-
 
91
/********************************************************
-
 
92
*			CONF FILE test 			*
-
 
93
*********************************************************/
-
 
94
if (!file_exists(CONF_FILE)){
-
 
95
	exit("Fichier de configuration ".CONF_FILE." non présent");
-
 
96
}
-
 
97
if (!is_readable(CONF_FILE)){
-
 
98
	exit("Vous n'avez pas les droits de lecture sur le fichier ".CONF_FILE);
-
 
99
}
-
 
100
$file_conf = fopen(CONF_FILE, 'r');
26
$file_conf = fopen(CONF_FILE, 'r');
101
if (!$file_conf) {
27
if (!$file_conf) {
102
	exit('Error opening the file '.CONF_FILE);
28
	exit('Error opening the file '.CONF_FILE);
103
}
29
}
104
while (!feof($file_conf)) {
30
while (!feof($file_conf)) {
Line 108... Line 34...
108
		$conf[trim($tmp[0])] = trim($tmp[1]);
34
		$conf[trim($tmp[0])] = trim($tmp[1]);
109
	}
35
	}
110
}
36
}
111
fclose($file_conf);
37
fclose($file_conf);
112
 
38
 
113
/****************
39
/****************************************
114
*	MAIN	*
40
*			Choice of language			*
115
*****************/
41
*****************************************/
116
 
-
 
117
?><!DOCTYPE HTML>
42
$Language = 'en';
118
<html>
-
 
119
<head>
-
 
120
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
-
 
121
	<title><?php echo $l_services_title; ?></title>
43
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
122
	<link rel="stylesheet" href="/css/acc.css" type="text/css">
44
	$Langue	  = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
123
	<script type="text/javascript" src="/js/jquery.min.js"></script>
45
	$Language = strtolower(substr(chop($Langue[0]), 0, 2));
124
</head>
-
 
125
<body>
-
 
126
<?php
-
 
127
 
-
 
128
echo <<<EOT
-
 
129
 
46
}
130
<div class="panel">
-
 
131
	<div class="panel-header">POSTFIX actuelle Configuration</div>
-
 
132
	<div class="panel-row">
47
if ($Language === 'fr') {
133
		<table width="100%" border=0 cellspacing=0 cellpadding=0><br>
48
	$l_mail_title			= "Authentification externe : Adresse mail";
134
 
-
 
135
EOT;
-
 
136
 
-
 
137
// la conf actuelle, si le fichier alcasar-mail.conf est présent
49
	$l_mail_auth_enable_label	= "Activer l'authentification par mail :";
138
			$alcasarMailConf = "/usr/local/etc/alcasar-mail.conf";
-
 
139
			if (is_file ($alcasarMailConf)){
-
 
140
 
-
 
141
				$tab=file($alcasarMailConf);
-
 
142
 
-
 
143
				if ($tab){
-
 
144
					foreach ($tab as $line)		{
-
 
145
 
-
 
146
						$field=explode("=", $line);
-
 
147
 
-
 
148
						switch ($field[0]) {
-
 
149
						
-
 
150
							case 'smtp':
-
 
151
								$smtp = trim($field[1]);
-
 
152
echo <<<EOT
-
 
153
								<tr align="center">
-
 
154
									<td><b>SMTP : </b>$smtp</td>
-
 
155
								</tr>
-
 
156
EOT;
-
 
157
							break;
-
 
158
							case 'port':
-
 
159
								$port = trim($field[1]);
-
 
160
echo <<<EOT
-
 
161
								<tr align="center">
-
 
162
									<td><b>Port : </b>$port</td>
-
 
163
								</tr>
-
 
164
EOT;
-
 
165
							break;
-
 
166
							case 'smtpIP':
-
 
167
								$smtpIP = trim($field[1]);
-
 
168
echo <<<EOT
-
 
169
								<tr align="center">
-
 
170
									<td><b>SMTP ip : </b>$smtpIP</td>
-
 
171
								</tr>
-
 
172
EOT;
-
 
173
							break;
-
 
174
							case 'mailAddr':
50
	$l_mail_YES			= "OUI";
175
								$mailAddr = trim($field[1]);
-
 
176
echo <<<EOT
-
 
177
								<tr align="center">
-
 
178
									<td><b>Email Addr : </b>$mailAddr</td>
-
 
179
								</tr>
-
 
180
EOT;
-
 
181
							break;
51
	$l_mail_NO			= "NON";
182
							case 'adminMail':
-
 
183
								$adminMail = trim($field[1]);
-
 
184
echo <<<EOT
52
} else {
185
								<tr align="center">
-
 
186
									<td><b>Admin email : </b>$adminMail</td>
53
	$l_mail_title			= "External authentication : Address mail";
187
								</tr>
-
 
188
EOT;
-
 
189
							break;
-
 
190
							case 'whiteDomain':
-
 
191
								$whiteDomain = explode(" ", trim($field[1]));
54
	$l_mail_auth_enable_label	= "Enable email authentication :";
192
							break;
-
 
193
						}
-
 
194
					}
-
 
195
				}
-
 
196
echo <<<EOT
-
 
197
			<form action="$php_self" method="post">
-
 
198
				<tr align="center">
55
	$l_mail_YES			= "YES";
199
					<td colspan="2">
56
	$l_mail_NO			= "NO";
200
						<input type="hidden" name="uninstall" value="uninstall">
-
 
201
						<br><input type="submit" class="btn btn-default" name="submit" value="Supprimer toute la configuration">
-
 
202
					</td>
-
 
203
				</tr>
-
 
204
			</form>
-
 
205
				<tr align="center">
-
 
206
					<td colspan="2"><font color=red>ATTENTION : la suppression enlève toute la configuration du SERVICE MAIL</font>
-
 
207
 
-
 
208
					</td>
-
 
209
				</tr>
-
 
210
EOT;
-
 
211
			// si le fichier alcasar-mail.conf n'existe pas
-
 
212
			} else {
-
 
213
 
57
}
214
echo <<<EOT
-
 
215
			<tr align="center">
-
 
216
				<td><b>POSTFIX n'est pas configuré par ALCASAR.</b></td>
-
 
217
			</tr>
-
 
218
EOT;
-
 
219
 
58
 
-
 
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'];
-
 
71
 
-
 
72
 
-
 
73
if(isset($_POST['submit'])){
-
 
74
	if($_POST['auth_enable'] === '1')
-
 
75
	{
-
 
76
		exec("systemctl start postfix");
-
 
77
 
-
 
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");
-
 
94
 
-
 
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;
220
			}
132
			}
221
 
-
 
222
// Partie de paramétrage de la configuration
-
 
223
 
-
 
224
// Configuration de l'adresse email de l'administrateur
-
 
225
echo <<<EOT
-
 
226
		</table><br>
-
 
227
	</div>
-
 
228
</div><br>
-
 
229
<div class="panel">
-
 
230
	<div class="panel-header">POSTFIX Configuration</div>
-
 
231
	<div class="panel-row conf" id="conf">	
-
 
232
		<table width="100%" border=0 cellspacing=0 cellpadding=0><br>
-
 
233
			<tr align="center">
-
 
234
				<td><input type="radio" name="conf" class="mail" value="One"/><b>Service autonome</b></td>
-
 
235
				<td><input type="radio" name="conf" class="mail" value="Two"/><b>Service relay</b></td>
-
 
236
				<td><input type="radio" name="conf" class="mail" value="Three"/> <b>Adresse mail</b></td>
133
			file_put_contents(CONF_FILE, str_replace('MAIL='.$conf['MAIL'],'MAIL='.$mail_status,file_get_contents(CONF_FILE)));
237
			</tr>
-
 
238
		</table><br>
-
 
239
	</div>
-
 
240
	<div class="myDiv hide" id="showOne">
-
 
241
		<table width="100%" border=0 cellspacing=0 cellpadding=0><br>
-
 
242
			<tr align="center">
-
 
243
				<td><b>Serveur mail est autonome :</b></td>
-
 
244
			</tr>
-
 
245
			<tr align="center">
-
 
246
				<td>
-
 
247
					<form action="$php_self" method="post">
-
 
248
						<input type="hidden" name="testConf" value="1">
-
 
249
						<input type="submit" class="btn btn-default" name="submit" value="Configurer"><br>
-
 
250
					</form>
-
 
251
				</td>
-
 
252
			</tr>
-
 
253
		</table>
-
 
254
	</div>
-
 
255
 
-
 
256
	<div class="myDiv hide" id="showTwo">
-
 
257
		<table width="100%" border=0 cellspacing=0 cellpadding=0><br>
-
 
258
			<form action="$php_self" method="post">
-
 
259
				<tr align="center">
-
 
260
					<td colspan="2"><b>SMTP Relais :</b></td>
-
 
261
				</tr>
-
 
262
				<tr align="center">
-
 
263
					<td colspan="2">Postfix envois, ralaye les emails sorants à un autre serveur SMTP.</td>
-
 
264
				</tr>
-
 
265
				<tr>
-
 
266
					<td><label>Enterez le serveur SMTP relai en FQDN ou IP</label></td>
-
 
267
					<td><input type="text" name="smtp" placeholder="SMTP" required/></td>
-
 
268
				</tr>
-
 
269
				<tr>
-
 
270
					<td><label>Enterez le port SMTP</label></td>
-
 
271
					<td><input type="text" name="port" placeholder="port" required/></td>
-
 
272
				</tr>
-
 
273
				<tr>
-
 
274
					<td><label>Enterez l'IP du serveur SMTP relais (0.0.0.0/0 si c'est dynamique/par défaut si vide)</label></td>
134
			file_put_contents(CONF_FILE, str_replace('TYPE_MAIL='.$conf['TYPE_MAIL'],'TYPE_MAIL='.$mail_type,file_get_contents(CONF_FILE)));
275
					<td><input type="text" name="smtpIP" placeholder="IP du SMTP relais" required/></td>
-
 
276
				</tr>
-
 
277
				<tr align="center">
-
 
278
					<td colspan="2">
-
 
279
						<input type="hidden" name="testConf" value="2">
-
 
280
						<input type="submit" class="btn btn-default" name="submit" value="Valider"><br>
-
 
281
					</td>
-
 
282
				</tr>
-
 
283
			</form>
-
 
284
		</table><br>
-
 
285
	</div>
-
 
286
 
-
 
287
	<div class="myDiv hide" id="showThree">
-
 
288
		<table width="100%" border=0 cellspacing=0 cellpadding=0><br>
-
 
289
			<form method="post" action="$php_self">
-
 
290
				<tr colspan="2" align="center">
-
 
291
					<td><b>Configuration de serveur mail via un compte email :</b></td>
-
 
292
				</tr>
-
 
293
				<tr align="center">
-
 
294
					<td>
-
 
295
						<table class="table table-striped">
-
 
296
							<tr>
-
 
297
								<td><label>Entez votre email</label></td>
-
 
298
								<td><input type="email" name="mailAddr" placeholder="Enter your email" required/></td>
135
			file_put_contents(CONF_FILE, str_replace('mailAddr='.$conf['mailAddr'],'mailAddr='.$mail_address,file_get_contents(CONF_FILE)));
299
							</tr>
-
 
300
							<tr>
-
 
301
								<td><label>Entez le mot de passe</label></td>
-
 
302
								<td><input type="password" id="pswd1" name="pswd1" required/></td>
-
 
303
							</tr>
-
 
304
							<tr>
-
 
305
								<td><label>Confirmer le mot de passe</label></td>
-
 
306
								<td><input type="password" id="pswd2" name="pswd2" required/></td>
-
 
307
							</tr>
-
 
308
 
-
 
309
						</table>
-
 
310
						<table class="table table-striped">
-
 
311
						  <thead>
-
 
312
							    <tr>
-
 
313
							      <th scope="col">#</th>
-
 
314
							      <th scope="col">compte de messagerie</th>
-
 
315
							      <th scope="col">adresse de messagerie</th>
-
 
316
							      <th scope="col">serveur sortant</th>
-
 
317
							      <th scope="col">port sortant</th>
-
 
318
							    </tr>
-
 
319
						  </thead>
-
 
320
						  <tbody>
-
 
321
EOT;
-
 
322
$smtpsConf = [
-
 
323
	["Orange", "Orange/Wanadoo", "orange.fr /wanadoo.fr", "smtp.orange.fr", 465],
-
 
324
	["Hotmail", "Hotmail", "hotmail.com/.fr / live.com/.fr / msn.com", "smtp.live.com", 587],
-
 
325
	["Outlook", "Outlook", "hotmail.xx/live.xx/msn.com/outlook/office365", "smtp.office365.com", 587],
136
			file_put_contents(CONF_FILE, str_replace('mailIP='.$conf['mailIP'],'mailIP='.$mail_ip,file_get_contents(CONF_FILE)));
326
	["SFR", "SFR", "sfr.fr", "smtp.sfr.fr", 465],
-
 
327
	["Free", "Free", "free.fr", "smtp.free.fr", 465],
-
 
328
	["Gmail", "Gmail", "gmail.com", "smtp.gmail.com", 587],
-
 
329
	["Laposte", "Laposte", "laposte.net", "smtp.laposte.net", 465],
-
 
330
	["Bouygues", "Bouygues Telecom", "bbox.fr", "smtp.bbox.fr", 587]
-
 
331
];
-
 
332
 
-
 
333
foreach( $smtpsConf as $smtpConf ) {
-
 
334
echo <<< EOT
-
 
335
							    <tr>
-
 
336
							      <th scope="row"><input class="form-check-input blur" type="radio" name="smtpPort" value="$smtpConf[3] $smtpConf[4]"/></th>
137
			file_put_contents(CONF_FILE, str_replace('smtp='.$conf['smtp'],'smtp='.$mail_smtp,file_get_contents(CONF_FILE)));
337
 
-
 
338
							      <td>$smtpConf[1]</td>
-
 
339
							      <td>$smtpConf[2]</td>
-
 
340
							      <td>$smtpConf[3]</td>
-
 
341
							      <td align="center">$smtpConf[4]</td>
-
 
342
							    </tr>
-
 
343
EOT;
-
 
344
}
-
 
345
echo<<<EOT
-
 
346
							    <tr>
-
 
347
							      <th scope="row"><input id="perso" class="form-check-input" type="radio" name="smtpPort"/></th>
138
			file_put_contents(CONF_FILE, str_replace('port='.$conf['port'],'port='.$mail_port,file_get_contents(CONF_FILE)));
348
							      <td>Personalisez votre smtp</td>
-
 
349
							      <td><input type="text" id="smtpPerso" name="smtpPerso" class="perso" oninput="valPerso()" placeholder="Entrez le serveur SMTP" disabled/></td>
139
			file_put_contents(CONF_FILE, str_replace('whiteDomain='.$conf['mail_whitelist'],'whiteDomain='.$mail_whitelist,file_get_contents(CONF_FILE)));
350
							      <td>Personalisez le port</td>
140
			if (isset($admin_address)) {
351
							      <td><input type="text" id="portPerso" name="portPerso" class="perso" oninput="valPerso()" placeholder="Entrez le serveur Port" disabled/></td>
141
				file_put_contents(CONF_FILE, str_replace('adminMail='.$conf['admin_address'],'adminMail='.$admin_address,file_get_contents(CONF_FILE)));
352
							    </tr>
-
 
353
						  </tbody>
-
 
354
						</table>
-
 
355
			  		</td>
-
 
356
				</tr>
142
			}
357
				<tr align="center">
143
			switch ($mail_type) {
358
					<td class="testConf3">
-
 
359
					</td>
144
				case '1':
360
				</tr>
-
 
361
				<tr align="center">
145
					$mail_port = 25;
362
					<td>
-
 
363
						<input type="hidden" name="testConf" value="3">
-
 
364
						<input type="submit" class="btn btn-default" name="submit" value="Valider" id="testConf3"><br>
146
					file_put_contents(CONF_FILE, str_replace('port='.$conf['port'],'port='.$mail_port,file_get_contents(CONF_FILE)));
365
					</td>
-
 
366
				</tr>
-
 
367
			</form>	  
-
 
368
		</table><br>
-
 
369
	</div>
-
 
370
</div><br>
-
 
371
<div class="panel">
-
 
372
	<div class="panel-header">Mail admin</div>
-
 
373
	<div class="panel-row conf" id="conf">	
-
 
374
		<table width="100%" border=0 cellspacing=0 cellpadding=0><br>
-
 
375
			<form action="$php_self" method="post">
-
 
376
				<tr align="center">
-
 
377
					<td colspan="2"><b>Mail admin</b></td>
-
 
378
				</tr>
-
 
379
				<tr align="center">
-
 
380
					<td colspan="2">L'adresse email de l'administrateur pour recevoir les alertes des nouvelles inscriptions, et l'archive hebdomadaire des logs</td>
-
 
381
				</tr>
-
 
382
				<tr>
-
 
383
EOT;
-
 
384
					if (empty($adminMail)){
147
					if(isset($mail_admin)){
385
						echo "<td><label>Enterez l'adresse email</label></td>";
-
 
386
					} else {
-
 
387
						echo "<td>L'email configuré actuellement est : " . $adminMail . "</td>";
148
						exec("sudo /usr/bin/bash /usr/local/bin/alcasar-mail-install-V2.sh -1 -a $admin_address -w $mail_whitelist");
388
					}
149
					}
389
echo <<<EOT
150
					else {
390
					<td><input type="email" name="adminMail" placeholder="Enter your email" required/></td>
151
						exec("sudo /usr/bin/bash /usr/local/bin/alcasar-mail-install-V2.sh -1 -w $mail_whitelist");
391
				</tr>
152
					}
392
 
153
					break;
393
				<tr align="center">
154
				case '2':
394
					<td colspan="2">
155
					if(isset($mail_admin)){
395
						<input type="submit" class="btn btn-default" name="submit" value="Valider"><br>
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");
396
					</td>
157
					}
397
				</tr>
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");
398
			</form>
160
					}
399
			<form action="$php_self" method="post">
161
					break;
400
				<tr align="center">
162
				case '3':
401
					<td colspan="2">
163
					if(isset($mail_admin)){
402
						<input type="hidden" name="unset" value="adminMail">
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 {
403
						<input type="submit" class="btn btn-default" name="submit" value="Supprimer l'admin email"><br>
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");
404
					</td>
168
					}
405
				</tr>
169
					break;
406
			</form>
170
				default:
-
 
171
					echo "Erreur dans la saisie !";
407
		</table><br>
172
					break;
408
	</div>
173
			}
-
 
174
		}
409
</div><br>
175
		else {
410
<div class="panel">
176
			echo "Erreur";
-
 
177
		}
-
 
178
	}
-
 
179
	else {
411
	<div class="panel-header">WhiteList Domains Configuration</div>
180
		exec("cp -f /etc/postfix/main.cf.origin  /etc/postfix/main.cf");
412
	<div class="panel-row conf" id="conf">	
181
		exec("rm -rf /etc/postfix/sasl/");
413
		<table width="100%" border=0 cellspacing=0 cellpadding=0><br>
182
		exec("cp -f /var/www/mail/alcasar-mail.conf /usr/local/etc/");
414
			<tr align="center">
183
		exec("systemctl restart postfix");
415
				<td>La liste blanche limite les inscriptions utilisateurs à un, ou plusieurs domaines.</td>
-
 
416
			</tr>
-
 
417
			<form method="post" action="$php_self">
184
		exec("systemctl stop postfix");
418
				<tr align="center">
185
		exec("sed -i '/SMTP_IP=/ s/^/#/g' /usr/local/etc/alcasar-iptables-local.sh");
419
					<td width="50%" align="center">Mettez vos domaines à configurer. Un par ligne</td>
186
		exec("sed -i '/SMTP_PORT=/ s/^/#/g' /usr/local/etc/alcasar-iptables-local.sh");
420
				</tr>
-
 
421
				<tr align="center">
187
		exec("rm -f /var/www/html/header.php");
422
					<td>
-
 
423
 						<br><textarea name='wld' rows=5 cols=50 placeholder="Aucune WLD configurée actuellement"">
188
		exec("rm -f /var/www/html/inscription.php");
424
EOT;
-
 
425
if(!empty($whiteDomain)){
189
		exec("rm -f /var/www/html/inscription_traitement.php");
426
	foreach ($whiteDomain as $domain){
190
		exec("cp -f /var/www/html/acc/admin/services.php.origin /var/www/html/acc/admin/services.php");
427
		echo "$domain\n";
191
		exec("sudo /usr/bin/bash /usr/local/bin/alcasar-iptables.sh");
428
	}
192
	}
-
 
193
	header("Refresh:0");
-
 
194
	exit;
429
}
195
}
430
echo<<<EOT
-
 
431
</textarea>
-
 
432
					</td>
-
 
433
				</tr>
-
 
434
				<tr align="center">
-
 
435
					<td colspan="2">
-
 
436
						<br><input type="submit" class="btn btn-default" name="submit" value="Valider"><br>
-
 
437
					</td>
-
 
438
				</tr>
-
 
439
			</form>
-
 
440
			<form action="$php_self" method="post">
-
 
441
				<tr align="center">
-
 
442
					<td colspan="2">
-
 
443
						<input type="hidden" name="unset" value="whiteDomain">
-
 
444
						<input type="submit" class="btn btn-default" name="submit" value="Supprimer la WLD"><br>
-
 
445
					</td>
-
 
446
				</tr>
-
 
447
			</form>
-
 
448
		</table><br>
-
 
449
	</div>
-
 
450
</div><br>
-
 
451
 
-
 
452
EOT;
-
 
453
 
196
 
454
?>
197
?>
-
 
198
<!DOCTYPE html>
455
 
199
<html>
456
<script>
200
<head>
457
	$(document).ready(function(){
201
	<meta charset="UTF-8">
458
		$("div.hide").hide();
202
	<title><?= $l_mail_title ?></title>
459
 
-
 
460
		$('#conf input[type="radio"]').click(function(){
203
	<link type="text/css" href="/css/acc.css" rel="stylesheet">
461
			var value = $(this).val(); 
204
	<link type="text/css" href="/css/mail.css" rel="stylesheet">
462
			$("div.myDiv").hide();
205
	<script>
463
			$("#show"+value).show();
206
	function onMailStatusChange() {
464
		});
-
 
465
 
-
 
466
		//On vérifie si le mot de passe est ok
207
		var listToDisables1 = ['mail_type','admin_enable','admin_address','mail_whitelist'];
467
		$("#pswd2").keyup(function(){
208
		var listToDisables2 = ['mail_server','mail_type','admin_enable','admin_address','mail_whitelist','mail_ip'];
468
			if($("#pswd1").val() != "" && $("#pswd2").val() != "" && $("#pswd1").val() != $("#pswd2").val()){
209
		var listToDisables3 = ['mail_server','mail_mdp2','mail_mdp','mail_address','mail_type','admin_enable','admin_address','mail_whitelist'];
469
				$(".testConf3").html("<br>Les deux mots de passe sont différents");
210
		var formSubmit = document.querySelector('form input[type="submit"]');
470
				$("#testConf3").attr("disabled", true);
211
		var btn_checkConf = document.getElementById('btn-checkconf');
471
			} else {
212
		var isChecked = false;
472
				$("#testConf3").attr("disabled", false);
213
		if (document.getElementById('auth_enable').value === '1') {
473
				$(".testConf3").fadeOut(800);
214
			for (var i=0; i<listToDisables1.length; i++) {
-
 
215
				document.getElementById(listToDisables1[i]).style.backgroundColor = '#c0c0c0';
-
 
216
				document.getElementById(listToDisables1[i]).disabled = true;
474
			}
217
			}
-
 
218
			for (var i=0; i<listToDisables2.length; i++) {
-
 
219
				document.getElementById(listToDisables2[i]).style.backgroundColor = '#c0c0c0';
-
 
220
				document.getElementById(listToDisables2[i]).disabled = true;
475
		})
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;
476
	});
225
			}
477
 
-
 
-
 
226
			document.getElementById('mail_type').style.backgroundColor = null;
-
 
227
			document.getElementById('mail_type').disabled = false;
-
 
228
			if (document.getElementById('mail_type').value === '1') {
478
	$('#perso').click(function(){
229
				for (var i=0; i<listToDisables1.length; i++) {
-
 
230
				document.getElementById(listToDisables1[i]).style.backgroundColor = null;
-
 
231
				document.getElementById(listToDisables1[i]).disabled = false;
479
 
232
				}
-
 
233
				if (document.getElementById('admin_enable').value === '0') {
-
 
234
				document.getElementById('admin_address').style.backgroundColor = '#c0c0c0';
480
		$(".perso").attr("disabled", false);
235
				document.getElementById('admin_address').disabled = true;
481
	});
236
				}
482
 
237
			}
-
 
238
			else if (document.getElementById('mail_type').value === '2') {
483
	$('.blur').click(function(){
239
				for (var i=0; i<listToDisables2.length; i++) {
-
 
240
				document.getElementById(listToDisables2[i]).style.backgroundColor = null;
-
 
241
				document.getElementById(listToDisables2[i]).disabled = false;
484
 
242
				}
-
 
243
				if (document.getElementById('admin_enable').value === '0') {
-
 
244
				document.getElementById('admin_address').style.backgroundColor = '#c0c0c0';
485
		$(".perso").attr("disabled", true);
245
				document.getElementById('admin_address').disabled = true;
486
	});
246
				}
487
 
247
			}
-
 
248
			else if (document.getElementById('mail_type').value === '3') {
488
	function valPerso(){
249
				for (var i=0; i<listToDisables3.length; i++) {
-
 
250
				document.getElementById(listToDisables3[i]).style.backgroundColor = null;
489
		var valSmtpPerso = document.getElementById("smtpPerso").value;
251
				document.getElementById(listToDisables3[i]).disabled = false;
-
 
252
				}
490
		var valPortPerso = document.getElementById("portPerso").value;
253
				if (document.getElementById('admin_enable').value === '0') {
491
		document.getElementById("perso").value = valSmtpPerso + " " + valPortPerso;
254
				document.getElementById('admin_address').style.backgroundColor = '#c0c0c0';
-
 
255
				document.getElementById('admin_address').disabled = true;
492
	};
256
				}
493
 
257
			}
494
	function hideShow(x){
258
			formSubmit.style.display = null;
495
		$("div." + x).toggle();
259
			btn_checkConf.style.display = 'none';
-
 
260
		} else {
496
		var value = $("input." + x).val();
261
			for (var i=0; i<listToDisables1.length; i++) {
-
 
262
				document.getElementById(listToDisables1[i]).style.backgroundColor = '#c0c0c0';
497
		var elem = document.getElementById("btn-" + x);
263
				document.getElementById(listToDisables1[i]).disabled = true;
-
 
264
			}
498
		if (elem.value=="Configurer"){
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
			}
499
			elem.value = "Annuler";
269
			for (var i=0; i<listToDisables3.length; i++) {
-
 
270
				document.getElementById(listToDisables3[i]).style.backgroundColor = '#c0c0c0';
-
 
271
				document.getElementById(listToDisables3[i]).disabled = true;
500
		} else{
272
			}
501
			elem.value = "Configurer";
273
			formSubmit.style.display = null;
-
 
274
			btn_checkConf.style.display = 'none';
502
		}
275
		}
503
	};
276
	}
504
 
-
 
505
</script>
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>
506
</body>
406
</body>
507
</html>
407
</html>