Subversion Repositories ALCASAR

Rev

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