Subversion Repositories ALCASAR

Rev

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