Subversion Repositories ALCASAR

Rev

Rev 2297 | Rev 2304 | 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");
2274 richard 9
define ("ETHERS_INFO_FILE", "/usr/local/etc/alcasar-ethers-info");
1959 richard 10
define ("DNS_LOCAL_FILE", "/usr/local/etc/alcasar-dns-name");
2274 richard 11
$conf_files=array(CONF_FILE,ETHERS_FILE,ETHERS_INFO_FILE,DNS_LOCAL_FILE);
1822 raphael.pi 12
$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])$/';
13
$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]))$/';
14
$network_modification=0;
861 richard 15
foreach ($conf_files as $file){
16
if (!file_exists($file)){
17
	exit("Requested file ".$file." isn't present");}
18
if (!is_readable($file)){
19
	exit("Can't read the file ".$file);}
841 richard 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_mask		= "Masque";
318 richard 32
	$l_ip_router		= "Passerelle";
736 franck 33
	$l_ip_public		= "Adresse IP publique";
1733 richard 34
	$l_ip_dns1		= "DNS1";
35
	$l_ip_dns2		= "DNS2";
861 richard 36
	$l_dhcp_title		= "Service DHCP";
862 richard 37
	$l_dhcp_state		= "Mode actuel";
1484 richard 38
	$l_DHCP_on		= "actif";
39
	$l_DHCP_off		= "inactif";
1493 franck 40
	$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 41
	$l_static_dhcp_title	= "Réservation d'adresses IP statiques";
42
	$l_mac_address		= "Adresse MAC";
43
	$l_ip_address		= "Adresse IP";
1959 richard 44
	$l_host_name		= "Nom d'hôte";
45
	$l_del			= "Supprimer de la liste";
841 richard 46
	$l_add_to_list		= "Ajouter";
1733 richard 47
	$l_apply		= "Appliquer les changements";
1959 richard 48
	$l_local_dns		= "Résolution local de nom";
1733 richard 49
	$l_import_cert		= "Import de certificat";
50
	$l_private_key		= "Clé privée (.key) :";
51
	$l_certificate		= "Certificat (.crt) :";
1740 richard 52
	$l_server_chain		= "Chaîne de certification (si nécéssaire : .crt) :";
53
	$l_default_cert		= "Revenir au certificat d'origine";
54
	$l_import		= "Importer";
1743 clement.si 55
	$l_current_certificate  = "Certificat actuel";
56
	$l_validated		= "Validé par :";
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_mask		= "Mask";
841 richard 63
	$l_ip_router		= "Gateway";
318 richard 64
	$l_ip_public		= "Public IP address";
1733 richard 65
	$l_ip_dns1		= "DNS1";
66
	$l_ip_dns2		= "DNS2";
861 richard 67
	$l_dhcp_title		= "DHCP service";
862 richard 68
	$l_dhcp_state		= "Current mode";
1484 richard 69
	$l_DHCP_on		= "enabled";
70
	$l_DHCP_off		= "disabled";
71
	$l_DHCP_off_explain	= "! Before disabling the DHCP server, you must write the extern DHCP parameters in the config file (see Documentation)";
841 richard 72
	$l_static_dhcp_title	= "Static IP addresses reservation";
73
	$l_mac_address		= "MAC Address";
74
	$l_ip_address		= "IP Address";
1959 richard 75
	$l_host_name		= "Host name";
76
	$l_del			= "Delete from list";
841 richard 77
	$l_add_to_list		= "Add";
1733 richard 78
	$l_apply		= "Apply changes";
1959 richard 79
	$l_local_dns		= "Local name resolution";
1733 richard 80
	$l_import_cert		= "Certificate import";
81
	$l_private_key		= "Private key (.key) :";
82
	$l_certificate		= "Certificate (.crt) :";
1740 richard 83
	$l_server_chain		= "Server-chain (if necessary : .crt) :";
1733 richard 84
	$l_default_cert		= "Back to default certificate";
1740 richard 85
	$l_import		= "Import";
1743 clement.si 86
	$l_current_certificate  = "Current certificate";
87
	$l_validated		= "Validated by :";
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' :
1827 raphael.pi 93
	exec ("sudo /usr/local/bin/alcasar-dhcp.sh -on");
841 richard 94
	break;
95
case 'DHCP_Off' :
1827 raphael.pi 96
	exec ("sudo /usr/local/bin/alcasar-dhcp.sh -off");
841 richard 97
	break;
98
case 'new_mac' :
99
	if ((trim($_POST['add_mac']) != "") and (trim($_POST['add_ip']) != ""))
100
		{
101
		$tab=file(ETHERS_FILE);
1710 richard 102
		if ($tab)  # the file isn't empty
841 richard 103
			{
1959 richard 104
			$insert="True";
2265 richard 105
			$new_mac_addr=trim($_POST['add_mac'],"\x00..\x20");
106
			$new_ip_addr=trim($_POST['add_ip'],"\x00..\x20");
1959 richard 107
			foreach ($tab as $line)  # verify that MAC or IP address doesn't exist
841 richard 108
				{
109
				$field=explode(" ", $line);
110
				$mac_addr=trim($field[0]);$ip_addr=trim($field[1]);
2265 richard 111
				if (strcasecmp($new_mac_addr, $mac_addr) == 0)
841 richard 112
					{
113
					$insert="False";
114
					break;
115
					}
2265 richard 116
				if (strcasecmp($new_ip_addr, $ip_addr) == 0)
841 richard 117
					{
118
					$insert="False";
119
					break;
120
					}
121
				}
1959 richard 122
			if ($insert == "True")
123
				{
2274 richard 124
				$line = $new_mac_addr . " " . $new_ip_addr . "\n";
1959 richard 125
				$pointeur=fopen(ETHERS_FILE,"a");
126
				fwrite ($pointeur, $line);
127
				fclose ($pointeur);
2274 richard 128
				$pointeur=fopen(ETHERS_INFO_FILE,"a");
2277 richard 129
				$line = $new_mac_addr . " " . $new_ip_addr . " #" . trim($_POST['info'],"\x00..\x20") . "\n";
2274 richard 130
				fwrite ($pointeur, $line);
131
				fclose ($pointeur);
1959 richard 132
				exec ("sudo /usr/bin/systemctl reload chilli");
133
				}
841 richard 134
			}
1959 richard 135
		}
136
	break;
137
case 'del_mac' :
138
	foreach ($_POST as $key => $value)
139
		{
140
		if ($value == 'on')
841 richard 141
			{
1959 richard 142
			$ether_file=ETHERS_FILE;
143
			exec("/bin/sed -i \"/^$key/d\" $ether_file");
2274 richard 144
			$ether_file=ETHERS_INFO_FILE;
145
			exec("/bin/sed -i \"/^$key/d\" $ether_file");
1707 richard 146
			exec ("sudo /usr/bin/systemctl reload chilli");
841 richard 147
			}
148
		}
149
	break;
1959 richard 150
case 'new_host' :
151
	if ((trim($_POST['add_host']) != "") and (trim($_POST['add_ip']) != ""))
841 richard 152
		{
1959 richard 153
		$tab=file(DNS_LOCAL_FILE);
154
		$insert="True";
155
		if ($tab)  # the file isn't empty
841 richard 156
			{
1959 richard 157
			foreach ($tab as $line)  # verify that host or IP address doesn't exist
841 richard 158
				{
1959 richard 159
				if (preg_match ('/^address/', $line))
160
					{
161
					$field=explode("/", $line);
162
					$host_name=trim($field[1]);$ip_addr=trim($field[2]);
163
					if (strcasecmp(trim($_POST['add_host']),trim($host_name)) == 0)
164
						{
165
						$insert="False";
166
						break;
167
						}
168
					if (strcasecmp(trim($_POST['add_ip']), trim($ip_addr)) == 0)
169
						{
170
						$insert="False";
171
						break;
172
						}
841 richard 173
					}
174
				}
1959 richard 175
			if ($insert == "True")
176
				{
177
				$line1 = "address=/".trim($_POST['add_host'])."/".trim($_POST['add_ip'])."\n";
178
				$explode_ip=explode('.',trim($_POST['add_ip']));
179
				$reverse_ip=implode('.',array_reverse($explode_ip));
180
				$line2 = "ptr-record=".$reverse_ip.".in-addr.arpa,".trim($_POST['add_host'])."\n";
181
				$pointeur=fopen(DNS_LOCAL_FILE,"a");
182
				fwrite ($pointeur, $line1);
183
				fwrite ($pointeur, $line2);
184
				fclose ($pointeur);
185
				exec ("sudo /usr/bin/systemctl restart dnsmasq");
186
				exec ("sudo /usr/bin/systemctl restart dnsmasq-blacklist");
187
				exec ("sudo /usr/bin/systemctl restart dnsmasq-whitelist");
188
				}
841 richard 189
			}
190
		}
191
	break;
1960 richard 192
case 'del_host' :
1959 richard 193
	foreach ($_POST as $key => $value)
194
		{
195
		if ($value == 'on')
196
			{
1960 richard 197
			$dns_local_file=DNS_LOCAL_FILE;
198
			exec("/bin/sed -i \"/$key/d\" $dns_local_file");
199
			exec ("sudo /usr/bin/systemctl restart dnsmasq");
200
			exec ("sudo /usr/bin/systemctl restart dnsmasq-blacklist");
201
			exec ("sudo /usr/bin/systemctl restart dnsmasq-whitelist");
1959 richard 202
			}
203
		}
204
	break;
318 richard 205
}
206
 
207
// Fonction de test de connectivité internet
208
function internetTest(){
696 franck 209
	$host = "www.google.fr"; # Google Test
318 richard 210
	$port = "80";
1710 richard 211
	//var $num;	//not used
212
	//var $error;	//not used
1733 richard 213
 
318 richard 214
	if (! $sock = @fsockopen($host, $port, $num, $error, 5)) {
215
		return false;
216
	} else {
217
		fclose($sock);
218
		return true;
219
	}
220
}
1822 raphael.pi 221
/***********************************
222
* 	Update ALCASAR_CONF_FILE   *
223
***********************************/
224
/*******************************************
225
*	Read ALCASAR_CONF_FILE Before     *
226
********************************************/
2299 tom.houday 227
$file_conf = fopen(CONF_FILE, 'r');
228
if (!$file_conf) {
229
	exit('Error opening the file '.CONF_FILE);
230
}
231
while (!feof($file_conf)) {
232
	$buffer = fgets($file_conf, 4096);
233
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
234
		$tmp = explode('=', $buffer);
235
		$conf[trim($tmp[0])] = trim($tmp[1]);
318 richard 236
	}
237
}
2299 tom.houday 238
fclose($file_conf);
1822 raphael.pi 239
 
240
if(isset($_POST['dns1']) && preg_match($reg_ip,$_POST['dns1']))
241
{
242
	file_put_contents(CONF_FILE, str_replace('DNS1='.$conf['DNS1'],'DNS1='.$_POST['dns1']."\n",file_get_contents(CONF_FILE)));
243
	$network_modification=1;
244
}
245
if(isset($_POST['dns2']) && preg_match($reg_ip,$_POST['dns2']))
246
{
247
	file_put_contents(CONF_FILE, str_replace('DNS2='.$conf['DNS2'],'DNS2='.$_POST['dns2']."\n",file_get_contents(CONF_FILE)));
248
	$network_modification=1;
249
}
318 richard 250
 
1822 raphael.pi 251
if(isset($_POST['ip_public']) && preg_match($reg_ip_cidr,$_POST['ip_public']))
252
{
253
	file_put_contents(CONF_FILE, str_replace('PUBLIC_IP='.$conf['PUBLIC_IP'],'PUBLIC_IP='.$_POST['ip_public']."\n",file_get_contents(CONF_FILE)));
254
	$network_modification=1;
255
}
256
 
257
if(isset($_POST['ip_gw']) && preg_match($reg_ip,$_POST['ip_gw']))
258
{
259
	file_put_contents(CONF_FILE, str_replace('GW='.$conf['GW'],'GW='.$_POST['ip_gw']."\n",file_get_contents(CONF_FILE)));
260
	$network_modification=1;
261
}
262
 
263
if(isset($_POST['ip_private']) && preg_match($reg_ip_cidr,$_POST['ip_private']))
264
{
265
	file_put_contents(CONF_FILE, str_replace('PRIVATE_IP='.$conf['PRIVATE_IP'],'PRIVATE_IP='.$_POST['ip_private']."\n",file_get_contents(CONF_FILE)));
266
	$network_modification=1;
267
}
268
if($network_modification)
269
{
270
	exec("sudo /usr/local/bin/alcasar-conf.sh -apply");
271
}
272
 
273
/*******************************************
274
*	Read ALCASAR_CONF_FILE Updated     *
275
********************************************/
2299 tom.houday 276
$file_conf = fopen(CONF_FILE, 'r');
277
if (!$file_conf) {
278
	exit('Error opening the file '.CONF_FILE);
279
}
280
while (!feof($file_conf)) {
281
	$buffer = fgets($file_conf, 4096);
282
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
283
		$tmp = explode('=', $buffer);
284
		$conf[trim($tmp[0])] = trim($tmp[1]);
1822 raphael.pi 285
	}
286
}
2299 tom.houday 287
fclose($file_conf);
1740 richard 288
?>
289
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
841 richard 290
<html><!-- written by steweb57 & rexy -->
318 richard 291
<head>
292
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
293
<title><?php echo $l_network_title; ?></title>
335 richard 294
<link rel="stylesheet" href="/css/style.css" type="text/css">
1578 richard 295
<script type="text/javascript">
296
function MAC_Control(formulaire){
297
/*MAC control (upper case and '-' separator*/
298
	var regex1 = /^([0-9a-fA-F]{2}(-|:)){5}[0-9a-fA-F]{2}$/; //vérification adresse mac
299
	if (regex1.test(document.forms[formulaire].add_mac.value)){
300
		document.forms[formulaire].add_mac.value=document.forms[formulaire].add_mac.value.toUpperCase().replace(/:/g, '-');
301
		return true;
302
	} else {
303
		alert("Invalid MAC address");//non internationnalisé
304
		return false;
305
	}
306
}
307
</script>
318 richard 308
</head>
309
<body>
310
<table width="100%" border="0" cellspacing="0" cellpadding="0">
353 richard 311
	<tr><th><?php echo $l_network_title; ?></th></tr>
318 richard 312
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
313
</table>
2134 richard 314
<? echo "<form action=".$_SERVER['PHP_SELF']." method='post'>";?>
318 richard 315
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
316
	<tr><td valign="middle" align="left">
317
	<fieldset>
318
	<legend><?php echo $l_internet_legend;
319
 	if (InternetTest()){
841 richard 320
		echo " <img src='/images/state_ok.gif'>";
1848 richard 321
		$IP_PUB = exec ("wget http://ipecho.net/plain -O - -o /dev/null");}
318 richard 322
	else 	{
841 richard 323
		echo " <img src='/images/state_error.gif'>";
318 richard 324
		$IP_PUB = "-.-.-.-";}
325
	?></legend>
326
	<table>
1848 richard 327
		<tr><td><?php echo $l_ip_public." : ".$IP_PUB;?></td></tr>
1822 raphael.pi 328
		<?php
329
		echo "<tr><td>".$l_ip_dns1." <input style='width:120px' type='text' name='dns1' value=".$conf["DNS1"]."/></td></tr>";
330
		echo "<tr><td>".$l_ip_dns2." <input style='width:120px' type='text' name='dns2' value=".$conf["DNS2"]."/></td></tr>";
331
		?>
318 richard 332
	</table>
333
	</fieldset>
334
	</td><td>
335
	<fieldset>
1478 richard 336
	<legend><?php echo $conf["EXTIF"].$l_extif_legend; ?></legend>
318 richard 337
	<table>
1822 raphael.pi 338
		<?php
1959 richard 339
		echo "<tr><td>".$l_ip_address." <input style='width:150px' type='text' name='ip_public' value=".$conf['PUBLIC_IP']."/></td></tr>";
1822 raphael.pi 340
		echo "<tr><td>".$l_ip_router." <input style='width:120px' type='text' name='ip_gw' value=".$conf['GW']."/></td></tr>";
341
		?>
318 richard 342
	</table>
343
	</fieldset>
344
	</td><td>
345
	<fieldset>
1478 richard 346
	<legend><?php echo $conf["INTIF"].$l_intif_legend; ?></legend>
318 richard 347
	<table>
1822 raphael.pi 348
	<?php
1959 richard 349
	echo "<tr><td>".$l_ip_address."</td><td> <input style='width:150px' type='text' name='ip_private' value=".$conf['PRIVATE_IP']." /></td></tr>";
1822 raphael.pi 350
	?>
318 richard 351
	</table>
352
	</fieldset>
353
	</td></tr>
2134 richard 354
	<tr><td colspan="3" align="center">
355
	<?php echo "<input type='submit' value='$l_apply'>";?>
356
	</td></tr>
318 richard 357
</table>
2134 richard 358
</form>
353 richard 359
<table width="100%" border="0" cellspacing="0" cellpadding="0">
841 richard 360
	<tr><th><?php echo $l_dhcp_title;?></th></tr>
353 richard 361
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
318 richard 362
</table>
841 richard 363
<table width="100%" border=1 cellspacing=0 cellpadding=0>
1484 richard 364
<tr><td colspan="2" valign="middle" align="left">
841 richard 365
<?
861 richard 366
$dhcp_state=trim($conf["DHCP"]);
862 richard 367
echo "<CENTER><H3>$l_dhcp_state : ${"l_DHCP_".$dhcp_state}</H3></CENTER>";
861 richard 368
echo "<FORM action='$_SERVER[PHP_SELF]' method=POST>";
369
echo "<select name='choix'>";
370
echo "<option value=\"DHCP_Off\" ";if (!strcmp($dhcp_state,"off")) echo "selected";echo ">$l_DHCP_off";
1484 richard 371
echo "<option value=\"DHCP_On\" ";if (!strcmp($dhcp_state,"on")) echo "selected";echo ">$l_DHCP_on";
861 richard 372
echo "</select>";
2016 raphael.pi 373
echo "<input type=submit value='$l_apply'>";
374
echo "<br>$l_DHCP_off_explain";
2013 raphael.pi 375
 
841 richard 376
echo "</FORM>";
377
echo "</td></tr>";
1484 richard 378
if (strncmp($conf["DHCP"],"on",2) == 0) { require ('network2.php');}
861 richard 379
else { echo "</TABLE>"; }
1710 richard 380
$maxsize=100000;
841 richard 381
?>
1710 richard 382
 
383
<table width="100%" border="0" cellspacing="0" cellpadding="0">
1959 richard 384
	<tr><th><?php echo $l_local_dns;?></th></tr>
385
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
386
</table>
387
<table width="100%" border="1" cellspacing="0" cellpadding="0">
388
<tr><td colspan=2 align="center">
389
<?
390
echo "<FORM action='network.php' method='POST'>";
391
echo "<table cellspacing=2 cellpadding=3 border=1>";
392
echo "<tr><th>$l_host_name<th>$l_ip_address<th>$l_del</tr>";
393
// Read the "dns_local" file
394
$line_exist=False;
395
$tab=file(DNS_LOCAL_FILE);
396
if ($tab)  # not empty
397
	{
398
	foreach ($tab as $line)
399
		{
400
			if (preg_match ('/^address/', $line))
401
			{
1960 richard 402
				$line_exist=True;
1959 richard 403
				$field=explode("/", $line);
1960 richard 404
				$host_name=$field[1];
405
				$ip_addr=$field[2];
406
				echo "<tr><td>$host_name";
407
				echo "<td>$ip_addr";
1959 richard 408
				echo "<td><input type='checkbox' name='$host_name'>";
409
				echo "</tr>";
410
			}
411
		}
412
	}
413
echo "</table>";
414
if ($line_exist)
415
	{
416
	echo "<input type='hidden' name='choix' value='del_host'>";
417
	echo "<input type='submit' value='$l_apply'>";
418
	}
419
echo "</form></td><td valign='middle' align='center'>";
420
echo "<FORM name='new_host' action='network.php' method='POST'>";
421
echo "<table cellspacing=2 cellpadding=3 border=1>";
422
echo "<tr><th>$l_host_name<th>$l_ip_address";
423
?>
424
<td></td></tr>
2265 richard 425
<tr><td>Ex. : my_nas</td><td>Ex. : 192.168.182.10</td><td></td></tr>
1959 richard 426
<tr><td><input type='text' name='add_host' size='17'></td>
427
<td><input type='text' name='add_ip' size='10'><input type='hidden' name='choix' value='new_host'></td>
428
<td><? echo "<input type=submit class=button value=\"$l_add_to_list\">"?></td>
429
</tr></table>
430
</form>
431
</td></tr>
432
</table>
433
<table width="100%" border="0" cellspacing="0" cellpadding="0">
1733 richard 434
	<tr><th><?php echo $l_import_cert;?></th></tr>
1710 richard 435
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
436
</table>
437
<table width="100%" border="1" cellspacing="0" cellpadding="0">
438
	<tr><td>
2297 tom.houday 439
			<form method="post" action="network.php" enctype="multipart/form-data">
440
			<?php echo $l_private_key;?><input type="file" name="key"><br>
441
			<?php echo $l_certificate;?><input type="file" name="crt"><br>
442
			<?php echo $l_server_chain;?><input type="file" name="sc">
443
			<input type="hidden" name="MAX_FILE_SIZE" value=<?php echo $maxsize;?>><br>
444
			<input type="submit" <?php echo "value=\"".$l_import."\""?>>
445
			</form>
1743 clement.si 446
 
2297 tom.houday 447
			<?php
448
			$certificateInfos = openssl_x509_parse(file_get_contents('/etc/pki/tls/certs/alcasar.crt'));
449
 
450
			$cert_expiration_date = date('d-m-Y H:i:s', $certificateInfos['validTo_time_t']);
451
			$domain               = $certificateInfos['subject']['CN'];
452
			$organization         = (isset($certificateInfos['subject']['O'])) ? $certificateInfos['subject']['O'] : '';
453
			$CAdomain             = $certificateInfos['issuer']['CN'];
454
			$CAorganization       = (isset($certificateInfos['issuer']['O'])) ? $certificateInfos['issuer']['O'] : '';
455
			?>
456
			<br>
457
			<h3><?= $l_current_certificate ?></h3>
458
			Expiration Date : <?= $cert_expiration_date ?><br>
459
			Common name : <?= $domain ?><br>
460
			Organization : <?= $organization ?><br/>
461
			<h4><?=  $l_validated ?></h4>
462
			Common name : <?= $CAdomain ?><br>
463
			Organization : <?= $CAorganization ?><br>
464
			</td><td>
465
			<form method="post" action="network.php">
466
			<input type="hidden" name="default">
467
			<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";}?>>
468
			</form>
469
		</td>
1710 richard 470
	</tr>
471
</table>
318 richard 472
</body>
473
</html>
1710 richard 474
 
475
<?php
476
if(isset($_POST['default'])){
1740 richard 477
	echo "$l_default_cert";
1733 richard 478
	exec("sudo alcasar-importcert.sh -d");
1710 richard 479
}
480
if(isset($_POST['MAX_FILE_SIZE'])){
481
	echo "changement";
482
	$maxsize = 100000;
483
	if(isset($_FILES['key']) && isset($_FILES['crt']) && $_FILES['key']['error'] == 0 && $_FILES['crt']['error'] == 0){
484
		$dest = "/tmp/";
485
		if($_FILES['key']['size'] <= $maxsize && $_FILES['crt']['size'] <= $maxsize)
486
		{
487
			if(pathinfo($_FILES['key']['name'])['extension'] == 'key' && pathinfo($_FILES['crt']['name'])['extension'] == 'crt')
488
			{
489
				$scpath = "";
490
				if(isset($_FILES['sc']) && pathinfo($_FILES['sc']['name'])['extension'] == 'crt')
491
				{
492
					$scpath = $dest."server-chain.crt";
1740 richard 493
					move_uploaded_file($_FILES['sc']['tmp_name'], $scpath);
1710 richard 494
				}
495
				$keypath = $dest."alcasar.key";
496
				$crtpath = $dest."alcasar.crt";
497
				move_uploaded_file($_FILES['key']['tmp_name'], $keypath);
498
				move_uploaded_file($_FILES['crt']['tmp_name'], $crtpath);
499
				exec("sudo alcasar-importcert.sh -i $crtpath -k $keypath -c $scpath");
500
			}
501
		}
502
	}
503
}
504
?>
2013 raphael.pi 505