Subversion Repositories ALCASAR

Rev

Rev 2992 | Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
2991 rexy 1
<?php
2
/* written by K@M3L & joss_p & Rexy */
3
 
4
// partie $_POST du service mail
5
$php_self = htmlspecialchars($_SERVER['PHP_SELF']);
6
if(!empty($_POST)){
7
	var_dump($_POST);
8
// contient les options et les arguments au configurateur
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'])){ 	
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']))."\"";
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>";
55
		exec("sudo /usr/local/bin/alcasar-mail-uninstall.sh", $output, $retval);
56
 
57
		var_dump($output);
58
		echo "<br>\$retval : " . $retval;
59
	}
60
 
61
	if(!empty($optArg)){
62
		echo "sudo /usr/local/bin/alcasar-mail-install.sh".$optArg;
63
		exec("sudo /usr/local/bin/alcasar-mail-install.sh".escapeshellcmd($optArg), $output, $retval);
64
		var_dump($output);
65
		echo "<br>\$retval : " . $retval;
66
	}
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
}
85
 
86
/****************************************************************
87
*	                   CONST				*
88
*****************************************************************/
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');
101
if (!$file_conf) {
102
	exit('Error opening the file '.CONF_FILE);
103
}
104
while (!feof($file_conf)) {
105
	$buffer = fgets($file_conf, 4096);
106
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
107
		$tmp = explode('=', $buffer, 2);
108
		$conf[trim($tmp[0])] = trim($tmp[1]);
109
	}
110
}
111
fclose($file_conf);
112
 
113
/****************
114
*	MAIN	*
115
*****************/
116
 
117
?><!DOCTYPE HTML>
118
<html>
119
<head>
120
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
121
	<title><?php echo $l_services_title; ?></title>
122
	<link rel="stylesheet" href="/css/acc.css" type="text/css">
123
	<script type="text/javascript" src="/js/jquery.min.js"></script>
124
</head>
125
<body>
126
<?php
127
 
128
echo <<<EOT
129
 
130
<div class="panel">
131
	<div class="panel-header">POSTFIX actuelle Configuration</div>
132
	<div class="panel-row">
133
		<table width="100%" border=0 cellspacing=0 cellpadding=0><br>
134
 
135
EOT;
136
 
137
// la conf actuelle, si le fichier alcasar-mail.conf est présent
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':
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;
182
							case 'adminMail':
183
								$adminMail = trim($field[1]);
184
echo <<<EOT
185
								<tr align="center">
186
									<td><b>Admin email : </b>$adminMail</td>
187
								</tr>
188
EOT;
189
							break;
190
							case 'whiteDomain':
191
								$whiteDomain = explode(" ", trim($field[1]));
192
							break;
193
						}
194
					}
195
				}
196
echo <<<EOT
197
			<form action="$php_self" method="post">
198
				<tr align="center">
199
					<td colspan="2">
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
 
214
echo <<<EOT
215
			<tr align="center">
216
				<td><b>POSTFIX n'est pas configuré par ALCASAR.</b></td>
217
			</tr>
218
EOT;
219
 
220
			}
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>
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>
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>
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],
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>
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>
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>
350
							      <td>Personalisez le port</td>
351
							      <td><input type="text" id="portPerso" name="portPerso" class="perso" oninput="valPerso()" placeholder="Entrez le serveur Port" disabled/></td>
352
							    </tr>
353
						  </tbody>
354
						</table>
355
			  		</td>
356
				</tr>
357
				<tr align="center">
358
					<td class="testConf3">
359
					</td>
360
				</tr>
361
				<tr align="center">
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>
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)){
385
						echo "<td><label>Enterez l'adresse email</label></td>";
386
					} else {
387
						echo "<td>L'email configuré actuellement est : " . $adminMail . "</td>";
388
					}
389
echo <<<EOT
390
					<td><input type="email" name="adminMail" placeholder="Enter your email" required/></td>
391
				</tr>
392
 
393
				<tr align="center">
394
					<td colspan="2">
395
						<input type="submit" class="btn btn-default" name="submit" value="Valider"><br>
396
					</td>
397
				</tr>
398
			</form>
399
			<form action="$php_self" method="post">
400
				<tr align="center">
401
					<td colspan="2">
402
						<input type="hidden" name="unset" value="adminMail">
403
						<input type="submit" class="btn btn-default" name="submit" value="Supprimer l'admin email"><br>
404
					</td>
405
				</tr>
406
			</form>
407
		</table><br>
408
	</div>
409
</div><br>
410
<div class="panel">
411
	<div class="panel-header">WhiteList Domains Configuration</div>
412
	<div class="panel-row conf" id="conf">	
413
		<table width="100%" border=0 cellspacing=0 cellpadding=0><br>
414
			<tr align="center">
415
				<td>La liste blanche limite les inscriptions utilisateurs à un, ou plusieurs domaines.</td>
416
			</tr>
417
			<form method="post" action="$php_self">
418
				<tr align="center">
419
					<td width="50%" align="center">Mettez vos domaines à configurer. Un par ligne</td>
420
				</tr>
421
				<tr align="center">
422
					<td>
423
 						<br><textarea name='wld' rows=5 cols=50 placeholder="Aucune WLD configurée actuellement"">
424
EOT;
425
if(!empty($whiteDomain)){
426
	foreach ($whiteDomain as $domain){
427
		echo "$domain\n";
428
	}
429
}
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
 
454
?>
455
 
456
<script>
457
	$(document).ready(function(){
458
		$("div.hide").hide();
459
 
460
		$('#conf input[type="radio"]').click(function(){
461
			var value = $(this).val(); 
462
			$("div.myDiv").hide();
463
			$("#show"+value).show();
464
		});
465
 
466
		//On vérifie si le mot de passe est ok
467
		$("#pswd2").keyup(function(){
468
			if($("#pswd1").val() != "" && $("#pswd2").val() != "" && $("#pswd1").val() != $("#pswd2").val()){
469
				$(".testConf3").html("<br>Les deux mots de passe sont différents");
470
				$("#testConf3").attr("disabled", true);
471
			} else {
472
				$("#testConf3").attr("disabled", false);
473
				$(".testConf3").fadeOut(800);
474
			}
475
		})
476
	});
477
 
478
	$('#perso').click(function(){
479
 
480
		$(".perso").attr("disabled", false);
481
	});
482
 
483
	$('.blur').click(function(){
484
 
485
		$(".perso").attr("disabled", true);
486
	});
487
 
488
	function valPerso(){
489
		var valSmtpPerso = document.getElementById("smtpPerso").value;
490
		var valPortPerso = document.getElementById("portPerso").value;
491
		document.getElementById("perso").value = valSmtpPerso + " " + valPortPerso;
492
	};
493
 
494
	function hideShow(x){
495
		$("div." + x).toggle();
496
		var value = $("input." + x).val();
497
		var elem = document.getElementById("btn-" + x);
498
		if (elem.value=="Configurer"){
499
			elem.value = "Annuler";
500
		} else{
501
			elem.value = "Configurer";
502
		}
503
	};
504
 
505
</script>
506
</body>
507
</html>