Subversion Repositories ALCASAR

Rev

Rev 1764 | Rev 1827 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
318 richard 1
<?php
838 richard 2
/* written by steweb57 & Rexy */
318 richard 3
 
861 richard 4
/********************
1748 richard 5
* READ CONF FILES   *
861 richard 6
*********************/
841 richard 7
define ("CONF_FILE", "/usr/local/etc/alcasar.conf");
8
define ("ETHERS_FILE", "/usr/local/etc/alcasar-ethers");
1578 richard 9
$conf_files=array(CONF_FILE,ETHERS_FILE);
1822 raphael.pi 10
$reg_ip = '/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/';
11
$reg_ip_cidr = '/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$/';
12
$network_modification=0;
861 richard 13
foreach ($conf_files as $file){
14
if (!file_exists($file)){
15
	exit("Requested file ".$file." isn't present");}
16
if (!is_readable($file)){
17
	exit("Can't read the file ".$file);}
841 richard 18
}
19
 
1822 raphael.pi 20
 
318 richard 21
# Choice of language
22
$Language = 'en';
23
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
24
	$Langue		= explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
25
	$Language	= strtolower(substr(chop($Langue[0]),0,2)); }
26
if($Language == 'fr'){
27
	$l_network_title	= "Configuration réseau";
1478 richard 28
	$l_extif_legend		= " (Interface connectée à Internet)";
29
	$l_intif_legend		= " (Réseau de consultation)";
318 richard 30
	$l_internet_legend	= "INTERNET";
1733 richard 31
	$l_ip_adr		= "Adresse IP";
32
	$l_ip_mask		= "Masque";
318 richard 33
	$l_ip_router		= "Passerelle";
736 franck 34
	$l_ip_public		= "Adresse IP publique";
1733 richard 35
	$l_ip_dns1		= "DNS1";
36
	$l_ip_dns2		= "DNS2";
861 richard 37
	$l_dhcp_title		= "Service DHCP";
862 richard 38
	$l_dhcp_state		= "Mode actuel";
1484 richard 39
	$l_DHCP_on		= "actif";
40
	$l_DHCP_off		= "inactif";
1493 franck 41
	$l_DHCP_off_explain	= "! Avant d'arrêter le serveur DHCP, vous devez renseigner les paramètres d'un serveur externe (cf. documentation).";
841 richard 42
	$l_static_dhcp_title	= "Réservation d'adresses IP statiques";
43
	$l_mac_address		= "Adresse MAC";
44
	$l_ip_address		= "Adresse IP";
1733 richard 45
	$l_mac_del		= "Supprimer de la liste";
841 richard 46
	$l_add_to_list		= "Ajouter";
1733 richard 47
	$l_apply		= "Appliquer les changements";
48
	$l_import_cert		= "Import de certificat";
49
	$l_private_key		= "Clé privée (.key) :";
50
	$l_certificate		= "Certificat (.crt) :";
1740 richard 51
	$l_server_chain		= "Chaîne de certification (si nécéssaire : .crt) :";
52
	$l_default_cert		= "Revenir au certificat d'origine";
53
	$l_import		= "Importer";
1743 clement.si 54
	$l_current_certificate  = "Certificat actuel";
55
	$l_validated		= "Validé par :";
841 richard 56
 
318 richard 57
} else {
58
	$l_network_title	= "Network configuration";
1478 richard 59
	$l_extif_legend		= " (Internet connected interface)";
60
	$l_intif_legend		= " (Private network)";
318 richard 61
	$l_internet_legend	= "INTERNET";
1733 richard 62
	$l_ip_adr		= "IP Address";
63
	$l_ip_mask		= "Mask";
841 richard 64
	$l_ip_router		= "Gateway";
318 richard 65
	$l_ip_public		= "Public IP address";
1733 richard 66
	$l_ip_dns1		= "DNS1";
67
	$l_ip_dns2		= "DNS2";
861 richard 68
	$l_dhcp_title		= "DHCP service";
862 richard 69
	$l_dhcp_state		= "Current mode";
1484 richard 70
	$l_DHCP_on		= "enabled";
71
	$l_DHCP_off		= "disabled";
72
	$l_DHCP_off_explain	= "! Before disabling the DHCP server, you must write the extern DHCP parameters in the config file (see Documentation)";
841 richard 73
	$l_static_dhcp_title	= "Static IP addresses reservation";
74
	$l_mac_address		= "MAC Address";
75
	$l_ip_address		= "IP Address";
1733 richard 76
	$l_mac_del		= "Delete from list";
841 richard 77
	$l_add_to_list		= "Add";
1733 richard 78
	$l_apply		= "Apply changes";
79
	$l_import_cert		= "Certificate import";
80
	$l_private_key		= "Private key (.key) :";
81
	$l_certificate		= "Certificate (.crt) :";
1740 richard 82
	$l_server_chain		= "Server-chain (if necessary : .crt) :";
1733 richard 83
	$l_default_cert		= "Back to default certificate";
1740 richard 84
	$l_import		= "Import";
1743 clement.si 85
	$l_current_certificate  = "Current certificate";
86
	$l_validated		= "Validated by :";
87
 
318 richard 88
}
841 richard 89
if (isset($_POST['choix'])){$choix=$_POST['choix'];} else {$choix="";}
90
switch ($choix)
91
{
1484 richard 92
case 'DHCP_On' :
93
	exec ("sudo /usr/local/sbin/alcasar-dhcp.sh -on");
841 richard 94
	break;
95
case 'DHCP_Off' :
96
	exec ("sudo /usr/local/sbin/alcasar-dhcp.sh -off");
97
	break;
98
case 'new_mac' :
99
	if ((trim($_POST['add_mac']) != "") and (trim($_POST['add_ip']) != ""))
100
		{
101
		$tab=file(ETHERS_FILE);
102
		$insert="True";
1710 richard 103
		if ($tab)  # the file isn't empty
841 richard 104
			{
859 richard 105
			foreach ($tab as $line)  # verify that MAC or IP addresses doesn't exist
841 richard 106
				{
107
				$field=explode(" ", $line);
108
				$mac_addr=trim($field[0]);$ip_addr=trim($field[1]);
859 richard 109
				if (strcasecmp(trim($_POST['add_mac']),trim($mac_addr)) == 0)
841 richard 110
					{
111
					$insert="False";
112
					break;
113
					}
859 richard 114
				if (strcasecmp(trim($_POST['add_ip']), trim($ip_addr)) == 0)
841 richard 115
					{
116
					$insert="False";
117
					break;
118
					}
119
				}
120
			}
1733 richard 121
		if ($insert == "True")
841 richard 122
			{
123
			$line = trim($_POST['add_mac']) . " " . trim($_POST['add_ip']) . "\n";
124
			$pointeur=fopen(ETHERS_FILE,"a");
125
			fwrite ($pointeur, $line);
126
			fclose ($pointeur);
1707 richard 127
			exec ("sudo /usr/bin/systemctl reload chilli");
841 richard 128
			}
129
		}
130
	break;
131
case 'del_mac' :
132
	$tab=file(ETHERS_FILE);
133
	if ($tab)
134
		{
135
		$pointeur=fopen(ETHERS_FILE,"w+");
136
		foreach ($tab as $line)
137
			{
138
			$field=explode(" ", $line);
139
			$mac_addr=trim($field[0]);
140
			$remove_line = False;
141
			foreach ($_POST as $key => $value)
142
				{
143
				if ($mac_addr == $key)
144
			       		{
145
					$remove_line = True;
146
					break;
147
					}
148
				}
149
			if (! $remove_line) {fwrite($pointeur,$line);}
150
			}
151
		fclose($pointeur);
1578 richard 152
		exec ("sudo /usr/bin/systemctl reload chilli");
841 richard 153
		}
154
	break;
318 richard 155
}
156
 
157
// Fonction de test de connectivité internet
158
function internetTest(){
696 franck 159
	$host = "www.google.fr"; # Google Test
318 richard 160
	$port = "80";
1710 richard 161
	//var $num;	//not used
162
	//var $error;	//not used
1733 richard 163
 
318 richard 164
	if (! $sock = @fsockopen($host, $port, $num, $error, 5)) {
165
		return false;
166
	} else {
167
		fclose($sock);
168
		return true;
169
	}
170
}
1822 raphael.pi 171
/***********************************
172
* 	Update ALCASAR_CONF_FILE   *
173
***********************************/
318 richard 174
 
1822 raphael.pi 175
/*******************************************
176
*	Read ALCASAR_CONF_FILE Before     *
177
********************************************/
654 richard 178
$ouvre=fopen(CONF_FILE,"r");
318 richard 179
if ($ouvre){
180
	while (!feof ($ouvre))
181
	{
182
		$tampon = fgets($ouvre, 4096);
183
		if (strpos($tampon,"=")!==false){
184
			$tmp = explode("=",$tampon);
654 richard 185
			$conf[$tmp[0]] = $tmp[1];
318 richard 186
		}
187
	}
1748 richard 188
	fclose($ouvre);
318 richard 189
}
1822 raphael.pi 190
 
191
 
192
if(isset($_POST['dns1']) && preg_match($reg_ip,$_POST['dns1']))
193
{
194
	file_put_contents(CONF_FILE, str_replace('DNS1='.$conf['DNS1'],'DNS1='.$_POST['dns1']."\n",file_get_contents(CONF_FILE)));
195
	$network_modification=1;
196
}
197
if(isset($_POST['dns2']) && preg_match($reg_ip,$_POST['dns2']))
198
{
199
	file_put_contents(CONF_FILE, str_replace('DNS2='.$conf['DNS2'],'DNS2='.$_POST['dns2']."\n",file_get_contents(CONF_FILE)));
200
	$network_modification=1;
201
}
318 richard 202
 
1822 raphael.pi 203
if(isset($_POST['ip_public']) && preg_match($reg_ip_cidr,$_POST['ip_public']))
204
{
205
	file_put_contents(CONF_FILE, str_replace('PUBLIC_IP='.$conf['PUBLIC_IP'],'PUBLIC_IP='.$_POST['ip_public']."\n",file_get_contents(CONF_FILE)));
206
	$network_modification=1;
207
}
208
 
209
if(isset($_POST['ip_gw']) && preg_match($reg_ip,$_POST['ip_gw']))
210
{
211
	file_put_contents(CONF_FILE, str_replace('GW='.$conf['GW'],'GW='.$_POST['ip_gw']."\n",file_get_contents(CONF_FILE)));
212
	$network_modification=1;
213
}
214
 
215
if(isset($_POST['ip_private']) && preg_match($reg_ip_cidr,$_POST['ip_private']))
216
{
217
	file_put_contents(CONF_FILE, str_replace('PRIVATE_IP='.$conf['PRIVATE_IP'],'PRIVATE_IP='.$_POST['ip_private']."\n",file_get_contents(CONF_FILE)));
218
	$network_modification=1;
219
}
220
if($network_modification)
221
{
222
	exec("sudo /usr/local/bin/alcasar-conf.sh -apply");
223
 
224
}
225
 
226
 
227
 
228
 
229
/*******************************************
230
*	Read ALCASAR_CONF_FILE Updated     *
231
********************************************/
232
$ouvre=fopen(CONF_FILE,"r");
233
if ($ouvre){
234
	while (!feof ($ouvre))
235
	{
236
		$tampon = fgets($ouvre, 4096);
237
		if (strpos($tampon,"=")!==false){
238
			$tmp = explode("=",$tampon);
239
			$conf[$tmp[0]] = $tmp[1];
240
		}
241
	}
242
	fclose($ouvre);
243
}
244
 
318 richard 245
/************************
246
*	TO DO		*
247
*************************/
838 richard 248
//modification de la conf réseau  --> V3.0
318 richard 249
 
1740 richard 250
?>
251
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
841 richard 252
<html><!-- written by steweb57 & rexy -->
318 richard 253
<head>
254
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
255
<title><?php echo $l_network_title; ?></title>
335 richard 256
<link rel="stylesheet" href="/css/style.css" type="text/css">
1578 richard 257
<script type="text/javascript">
258
function MAC_Control(formulaire){
259
/*MAC control (upper case and '-' separator*/
260
	var regex1 = /^([0-9a-fA-F]{2}(-|:)){5}[0-9a-fA-F]{2}$/; //vérification adresse mac
261
	if (regex1.test(document.forms[formulaire].add_mac.value)){
262
		document.forms[formulaire].add_mac.value=document.forms[formulaire].add_mac.value.toUpperCase().replace(/:/g, '-');
263
		return true;
264
	} else {
265
		alert("Invalid MAC address");//non internationnalisé
266
		return false;
267
	}
268
}
269
</script>
318 richard 270
</head>
1822 raphael.pi 271
 
272
 
318 richard 273
<body>
274
<table width="100%" border="0" cellspacing="0" cellpadding="0">
353 richard 275
	<tr><th><?php echo $l_network_title; ?></th></tr>
318 richard 276
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
277
</table>
278
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
279
	<tr><td valign="middle" align="left">
280
	<fieldset>
281
	<legend><?php echo $l_internet_legend;
282
 	if (InternetTest()){
841 richard 283
		echo " <img src='/images/state_ok.gif'>";
318 richard 284
		$IP_PUB = exec ("wget http://checkip.dyndns.org/ -O - -o /dev/null | cut -d: -f 2 | cut -d\< -f 1");}
285
	else 	{
841 richard 286
		echo " <img src='/images/state_error.gif'>";
318 richard 287
		$IP_PUB = "-.-.-.-";}
288
	?></legend>
289
	<table>
290
		<tr><td><?php echo $l_ip_public." : </td><td>".$IP_PUB;?></td></tr>
1822 raphael.pi 291
		<?php
292
		echo "<form action=".$_SERVER['PHP_SELF']." method='post'>";
293
		echo "<tr><td>".$l_ip_dns1." <input style='width:120px' type='text' name='dns1' value=".$conf["DNS1"]."/></td></tr>";
294
		echo "<tr><td>".$l_ip_dns2." <input style='width:120px' type='text' name='dns2' value=".$conf["DNS2"]."/></td></tr>";
295
		?>
318 richard 296
	</table>
297
	</fieldset>
298
	</td><td>
299
	<fieldset>
1478 richard 300
	<legend><?php echo $conf["EXTIF"].$l_extif_legend; ?></legend>
318 richard 301
	<table>
1822 raphael.pi 302
		<?php
303
		echo "<form action=".$_SERVER['PHP_SELF']." method='post'>";
304
		echo "<tr><td>".$l_ip_adr." <input style='width:150px' type='text' name='ip_public' value=".$conf['PUBLIC_IP']."/></td></tr>";
305
		echo "<tr><td>".$l_ip_router." <input style='width:120px' type='text' name='ip_gw' value=".$conf['GW']."/></td></tr>";
306
		?>
318 richard 307
	</table>
308
	</fieldset>
309
	</td><td>
310
	<fieldset>
1478 richard 311
	<legend><?php echo $conf["INTIF"].$l_intif_legend; ?></legend>
318 richard 312
	<table>
1822 raphael.pi 313
	<?php
314
	echo "<form action=".$_SERVER['PHP_SELF']." method='post'>";
315
	echo "<tr><td>".$l_ip_adr."</td><td> <input style='width:150px' type='text' name='ip_private' value=".$conf['PRIVATE_IP']." /></td></tr>";
316
	?>
318 richard 317
	</table>
318
	</fieldset>
319
	</td></tr>
1822 raphael.pi 320
	<?php 
321
	echo "<td><input type='submit' value='$l_apply' disabled></td>"; 	
322
	echo "</form>";
323
	?>
318 richard 324
</table>
1822 raphael.pi 325
 
353 richard 326
<table width="100%" border="0" cellspacing="0" cellpadding="0">
841 richard 327
	<tr><th><?php echo $l_dhcp_title;?></th></tr>
353 richard 328
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
318 richard 329
</table>
841 richard 330
<table width="100%" border=1 cellspacing=0 cellpadding=0>
1484 richard 331
<tr><td colspan="2" valign="middle" align="left">
841 richard 332
<?
861 richard 333
$dhcp_state=trim($conf["DHCP"]);
862 richard 334
echo "<CENTER><H3>$l_dhcp_state : ${"l_DHCP_".$dhcp_state}</H3></CENTER>";
861 richard 335
echo "<FORM action='$_SERVER[PHP_SELF]' method=POST>";
336
echo "<select name='choix'>";
337
echo "<option value=\"DHCP_Off\" ";if (!strcmp($dhcp_state,"off")) echo "selected";echo ">$l_DHCP_off";
1484 richard 338
echo "<option value=\"DHCP_On\" ";if (!strcmp($dhcp_state,"on")) echo "selected";echo ">$l_DHCP_on";
861 richard 339
echo "</select>";
340
echo "<input type=submit value='$l_apply'>";
1484 richard 341
echo "<br>$l_DHCP_off_explain";
841 richard 342
echo "</FORM>";
343
echo "</td></tr>";
1484 richard 344
if (strncmp($conf["DHCP"],"on",2) == 0) { require ('network2.php');}
861 richard 345
else { echo "</TABLE>"; }
1710 richard 346
$maxsize=100000;
841 richard 347
?>
1710 richard 348
 
349
<table width="100%" border="0" cellspacing="0" cellpadding="0">
1733 richard 350
	<tr><th><?php echo $l_import_cert;?></th></tr>
1710 richard 351
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
352
</table>
353
<table width="100%" border="1" cellspacing="0" cellpadding="0">
354
	<tr><td>
355
	<form method="post" action="network.php" enctype="multipart/form-data">
1740 richard 356
	<?php echo $l_private_key;?><input type="file" name="key"><br>
357
	<?php echo $l_certificate;?><input type="file" name="crt"><br>
358
	<?php echo $l_server_chain;?><input type="file" name="sc">
359
	<input type="hidden" name="MAX_FILE_SIZE" value=<?php echo $maxsize;?>><br>
360
	<input type="submit" <?php echo "value=\"".$l_import."\""?>>
1710 richard 361
	</form>
1743 clement.si 362
<?php
1764 richard 363
$cert_subject = exec("/bin/openssl x509 -noout -subject -in /etc/pki/tls/certs/alcasar.crt");
364
$cert_issuer = exec("/bin/openssl x509 -noout -issuer -in /etc/pki/tls/certs/alcasar.crt");
365
$cert_expiration_date = exec("/bin/openssl x509 -noout -dates -in /etc/pki/tls/certs/alcasar.crt|grep After|cut -d\"=\" -f2");
366
$domain = exec("echo $cert_subject | sed -n '/^subject/s/^.*CN=//p' | cut -d'/' -f 1");
367
$organization = exec("echo $cert_subject | sed -n '/^subject/s/^.*O=//p' | cut -d'/' -f 1");
368
$CAdomain = exec("echo $cert_issuer | sed -n '/^issuer/s/^.*CN=//p' | cut -d'/' -f 1");
369
$CAorganization = exec("echo $cert_issuer | sed -n '/^issuer/s/^.*O=//p' | cut -d'/' -f 1");
1743 clement.si 370
 
1764 richard 371
	echo "<br>";
372
	echo "<h3>".$l_current_certificate."</h3>";
373
	echo "Expiration Date : ".$cert_expiration_date."<br>";
374
	echo "Common name : ".$domain."<br>";
375
	echo "Organization : ".$organization."<br/>";
376
	echo "<h4>". $l_validated ."</h4>";
377
	echo "Common name : ".$CAdomain."<br>";
378
	echo "Organization : ".$CAorganization."<br>";
1743 clement.si 379
?>
1710 richard 380
	</td><td>
381
	<form method="post" action="network.php">
1740 richard 382
	<input type="hidden" name="default">
1764 richard 383
	<input type="submit" <?php echo "value=\"".$l_default_cert."\""; if(!file_exists("/etc/pki/tls/certs/alcasar.crt.old") || !file_exists("/etc/pki/tls/private/alcasar.key.old")){ echo " disabled";}?>>
1710 richard 384
	</form>
385
	</td>
386
	</tr>
387
</table>
388
 
318 richard 389
</body>
390
</html>
1710 richard 391
 
392
<?php
393
if(isset($_POST['default'])){
1740 richard 394
	echo "$l_default_cert";
1733 richard 395
	exec("sudo alcasar-importcert.sh -d");
1710 richard 396
}
397
if(isset($_POST['MAX_FILE_SIZE'])){
398
	echo "changement";
399
	$maxsize = 100000;
400
	if(isset($_FILES['key']) && isset($_FILES['crt']) && $_FILES['key']['error'] == 0 && $_FILES['crt']['error'] == 0){
401
		$dest = "/tmp/";
402
		if($_FILES['key']['size'] <= $maxsize && $_FILES['crt']['size'] <= $maxsize)
403
		{
404
			if(pathinfo($_FILES['key']['name'])['extension'] == 'key' && pathinfo($_FILES['crt']['name'])['extension'] == 'crt')
405
			{
406
				$scpath = "";
407
				if(isset($_FILES['sc']) && pathinfo($_FILES['sc']['name'])['extension'] == 'crt')
408
				{
409
					$scpath = $dest."server-chain.crt";
1740 richard 410
					move_uploaded_file($_FILES['sc']['tmp_name'], $scpath);
1710 richard 411
				}
412
				$keypath = $dest."alcasar.key";
413
				$crtpath = $dest."alcasar.crt";
414
				move_uploaded_file($_FILES['key']['tmp_name'], $keypath);
415
				move_uploaded_file($_FILES['crt']['tmp_name'], $crtpath);
416
				exec("sudo alcasar-importcert.sh -i $crtpath -k $keypath -c $scpath");
417
			}
418
		}
419
	}
420
}
421
?>