Subversion Repositories ALCASAR

Rev

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