Subversion Repositories ALCASAR

Rev

Rev 1848 | Rev 1960 | 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";
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 :";
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_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 :";
88
 
318 richard 89
}
841 richard 90
if (isset($_POST['choix'])){$choix=$_POST['choix'];} else {$choix="";}
91
switch ($choix)
92
{
1484 richard 93
case 'DHCP_On' :
1827 raphael.pi 94
	exec ("sudo /usr/local/bin/alcasar-dhcp.sh -on");
841 richard 95
	break;
96
case 'DHCP_Off' :
1827 raphael.pi 97
	exec ("sudo /usr/local/bin/alcasar-dhcp.sh -off");
841 richard 98
	break;
99
case 'new_mac' :
100
	if ((trim($_POST['add_mac']) != "") and (trim($_POST['add_ip']) != ""))
101
		{
102
		$tab=file(ETHERS_FILE);
1710 richard 103
		if ($tab)  # the file isn't empty
841 richard 104
			{
1959 richard 105
			$insert="True";
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]);
859 richard 110
				if (strcasecmp(trim($_POST['add_mac']),trim($mac_addr)) == 0)
841 richard 111
					{
112
					$insert="False";
113
					break;
114
					}
859 richard 115
				if (strcasecmp(trim($_POST['add_ip']), trim($ip_addr)) == 0)
841 richard 116
					{
117
					$insert="False";
118
					break;
119
					}
120
				}
1959 richard 121
			if ($insert == "True")
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);
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;
1959 richard 185
case 'del_mac' :
186
	foreach ($_POST as $key => $value)
187
		{
188
		if ($value == 'on')
189
			{
190
			$ether_file=ETHERS_FILE;
191
			exec("/bin/sed -i \"/^$key/d\" $ether_file"); 
192
			exec ("sudo /usr/bin/systemctl reload chilli");
193
			}
194
		}
195
	break;
318 richard 196
}
197
 
198
// Fonction de test de connectivité internet
199
function internetTest(){
696 franck 200
	$host = "www.google.fr"; # Google Test
318 richard 201
	$port = "80";
1710 richard 202
	//var $num;	//not used
203
	//var $error;	//not used
1733 richard 204
 
318 richard 205
	if (! $sock = @fsockopen($host, $port, $num, $error, 5)) {
206
		return false;
207
	} else {
208
		fclose($sock);
209
		return true;
210
	}
211
}
1822 raphael.pi 212
/***********************************
213
* 	Update ALCASAR_CONF_FILE   *
214
***********************************/
215
/*******************************************
216
*	Read ALCASAR_CONF_FILE Before     *
217
********************************************/
654 richard 218
$ouvre=fopen(CONF_FILE,"r");
318 richard 219
if ($ouvre){
220
	while (!feof ($ouvre))
221
	{
222
		$tampon = fgets($ouvre, 4096);
223
		if (strpos($tampon,"=")!==false){
224
			$tmp = explode("=",$tampon);
654 richard 225
			$conf[$tmp[0]] = $tmp[1];
318 richard 226
		}
227
	}
1748 richard 228
	fclose($ouvre);
318 richard 229
}
1822 raphael.pi 230
 
231
if(isset($_POST['dns1']) && preg_match($reg_ip,$_POST['dns1']))
232
{
233
	file_put_contents(CONF_FILE, str_replace('DNS1='.$conf['DNS1'],'DNS1='.$_POST['dns1']."\n",file_get_contents(CONF_FILE)));
234
	$network_modification=1;
235
}
236
if(isset($_POST['dns2']) && preg_match($reg_ip,$_POST['dns2']))
237
{
238
	file_put_contents(CONF_FILE, str_replace('DNS2='.$conf['DNS2'],'DNS2='.$_POST['dns2']."\n",file_get_contents(CONF_FILE)));
239
	$network_modification=1;
240
}
318 richard 241
 
1822 raphael.pi 242
if(isset($_POST['ip_public']) && preg_match($reg_ip_cidr,$_POST['ip_public']))
243
{
244
	file_put_contents(CONF_FILE, str_replace('PUBLIC_IP='.$conf['PUBLIC_IP'],'PUBLIC_IP='.$_POST['ip_public']."\n",file_get_contents(CONF_FILE)));
245
	$network_modification=1;
246
}
247
 
248
if(isset($_POST['ip_gw']) && preg_match($reg_ip,$_POST['ip_gw']))
249
{
250
	file_put_contents(CONF_FILE, str_replace('GW='.$conf['GW'],'GW='.$_POST['ip_gw']."\n",file_get_contents(CONF_FILE)));
251
	$network_modification=1;
252
}
253
 
254
if(isset($_POST['ip_private']) && preg_match($reg_ip_cidr,$_POST['ip_private']))
255
{
256
	file_put_contents(CONF_FILE, str_replace('PRIVATE_IP='.$conf['PRIVATE_IP'],'PRIVATE_IP='.$_POST['ip_private']."\n",file_get_contents(CONF_FILE)));
257
	$network_modification=1;
258
}
259
if($network_modification)
260
{
261
	exec("sudo /usr/local/bin/alcasar-conf.sh -apply");
262
}
263
 
264
/*******************************************
265
*	Read ALCASAR_CONF_FILE Updated     *
266
********************************************/
267
$ouvre=fopen(CONF_FILE,"r");
268
if ($ouvre){
269
	while (!feof ($ouvre))
270
	{
271
		$tampon = fgets($ouvre, 4096);
272
		if (strpos($tampon,"=")!==false){
273
			$tmp = explode("=",$tampon);
274
			$conf[$tmp[0]] = $tmp[1];
275
		}
276
	}
277
	fclose($ouvre);
278
}
1740 richard 279
?>
280
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
841 richard 281
<html><!-- written by steweb57 & rexy -->
318 richard 282
<head>
283
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
284
<title><?php echo $l_network_title; ?></title>
335 richard 285
<link rel="stylesheet" href="/css/style.css" type="text/css">
1578 richard 286
<script type="text/javascript">
287
function MAC_Control(formulaire){
288
/*MAC control (upper case and '-' separator*/
289
	var regex1 = /^([0-9a-fA-F]{2}(-|:)){5}[0-9a-fA-F]{2}$/; //vérification adresse mac
290
	if (regex1.test(document.forms[formulaire].add_mac.value)){
291
		document.forms[formulaire].add_mac.value=document.forms[formulaire].add_mac.value.toUpperCase().replace(/:/g, '-');
292
		return true;
293
	} else {
294
		alert("Invalid MAC address");//non internationnalisé
295
		return false;
296
	}
297
}
298
</script>
318 richard 299
</head>
300
<body>
301
<table width="100%" border="0" cellspacing="0" cellpadding="0">
353 richard 302
	<tr><th><?php echo $l_network_title; ?></th></tr>
318 richard 303
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
304
</table>
305
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
306
	<tr><td valign="middle" align="left">
307
	<fieldset>
308
	<legend><?php echo $l_internet_legend;
309
 	if (InternetTest()){
841 richard 310
		echo " <img src='/images/state_ok.gif'>";
1848 richard 311
		$IP_PUB = exec ("wget http://ipecho.net/plain -O - -o /dev/null");}
318 richard 312
	else 	{
841 richard 313
		echo " <img src='/images/state_error.gif'>";
318 richard 314
		$IP_PUB = "-.-.-.-";}
315
	?></legend>
316
	<table>
1848 richard 317
		<tr><td><?php echo $l_ip_public." : ".$IP_PUB;?></td></tr>
1822 raphael.pi 318
		<?php
319
		echo "<form action=".$_SERVER['PHP_SELF']." method='post'>";
320
		echo "<tr><td>".$l_ip_dns1." <input style='width:120px' type='text' name='dns1' value=".$conf["DNS1"]."/></td></tr>";
321
		echo "<tr><td>".$l_ip_dns2." <input style='width:120px' type='text' name='dns2' value=".$conf["DNS2"]."/></td></tr>";
322
		?>
318 richard 323
	</table>
324
	</fieldset>
325
	</td><td>
326
	<fieldset>
1478 richard 327
	<legend><?php echo $conf["EXTIF"].$l_extif_legend; ?></legend>
318 richard 328
	<table>
1822 raphael.pi 329
		<?php
330
		echo "<form action=".$_SERVER['PHP_SELF']." method='post'>";
1959 richard 331
		echo "<tr><td>".$l_ip_address." <input style='width:150px' type='text' name='ip_public' value=".$conf['PUBLIC_IP']."/></td></tr>";
1822 raphael.pi 332
		echo "<tr><td>".$l_ip_router." <input style='width:120px' type='text' name='ip_gw' value=".$conf['GW']."/></td></tr>";
333
		?>
318 richard 334
	</table>
335
	</fieldset>
336
	</td><td>
337
	<fieldset>
1478 richard 338
	<legend><?php echo $conf["INTIF"].$l_intif_legend; ?></legend>
318 richard 339
	<table>
1822 raphael.pi 340
	<?php
341
	echo "<form action=".$_SERVER['PHP_SELF']." method='post'>";
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>
1822 raphael.pi 347
	<?php 
1827 raphael.pi 348
	echo "<td><input type='submit' value='$l_apply' ></td>"; 	
1822 raphael.pi 349
	echo "</form>";
350
	?>
318 richard 351
</table>
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>";
366
echo "<input type=submit value='$l_apply'>";
1484 richard 367
echo "<br>$l_DHCP_off_explain";
841 richard 368
echo "</FORM>";
369
echo "</td></tr>";
1484 richard 370
if (strncmp($conf["DHCP"],"on",2) == 0) { require ('network2.php');}
861 richard 371
else { echo "</TABLE>"; }
1710 richard 372
$maxsize=100000;
841 richard 373
?>
1710 richard 374
 
375
<table width="100%" border="0" cellspacing="0" cellpadding="0">
1959 richard 376
	<tr><th><?php echo $l_local_dns;?></th></tr>
377
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
378
</table>
379
<table width="100%" border="1" cellspacing="0" cellpadding="0">
380
<tr><td colspan=2 align="center">
381
<?
382
echo "<FORM action='network.php' method='POST'>";
383
echo "<table cellspacing=2 cellpadding=3 border=1>";
384
echo "<tr><th>$l_host_name<th>$l_ip_address<th>$l_del</tr>";
385
// Read the "dns_local" file
386
$line_exist=False;
387
$tab=file(DNS_LOCAL_FILE);
388
if ($tab)  # not empty
389
	{
390
	$line_exist=True;
391
	foreach ($tab as $line)
392
		{
393
			if (preg_match ('/^address/', $line))
394
			{
395
				$field=explode("/", $line);
396
				$ip_addr=$field[1];
397
				$host_name=$field[2];
398
				echo "<tr><td>$ip_addr";
399
				echo "<td>$host_name";
400
				echo "<td><input type='checkbox' name='$host_name'>";
401
				echo "</tr>";
402
			}
403
		}
404
	}
405
echo "</table>";
406
if ($line_exist)
407
	{
408
	echo "<input type='hidden' name='choix' value='del_host'>";
409
	echo "<input type='submit' value='$l_apply'>";
410
	}	
411
echo "</form></td><td valign='middle' align='center'>";
412
echo "<FORM name='new_host' 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";
415
?>
416
<td></td></tr>
417
<tr><td>exemple : my_nas</td><td>exemple : 192.168.182.10</td><td></td></tr>
418
<tr><td><input type='text' name='add_host' size='17'></td>
419
<td><input type='text' name='add_ip' size='10'><input type='hidden' name='choix' value='new_host'></td>
420
<td><? echo "<input type=submit class=button value=\"$l_add_to_list\">"?></td>
421
</tr></table>
422
</form>
423
</td></tr>
424
</table>
425
<table width="100%" border="0" cellspacing="0" cellpadding="0">
1733 richard 426
	<tr><th><?php echo $l_import_cert;?></th></tr>
1710 richard 427
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
428
</table>
429
<table width="100%" border="1" cellspacing="0" cellpadding="0">
430
	<tr><td>
431
	<form method="post" action="network.php" enctype="multipart/form-data">
1740 richard 432
	<?php echo $l_private_key;?><input type="file" name="key"><br>
433
	<?php echo $l_certificate;?><input type="file" name="crt"><br>
434
	<?php echo $l_server_chain;?><input type="file" name="sc">
435
	<input type="hidden" name="MAX_FILE_SIZE" value=<?php echo $maxsize;?>><br>
436
	<input type="submit" <?php echo "value=\"".$l_import."\""?>>
1710 richard 437
	</form>
1743 clement.si 438
<?php
1764 richard 439
$cert_subject = exec("/bin/openssl x509 -noout -subject -in /etc/pki/tls/certs/alcasar.crt");
440
$cert_issuer = exec("/bin/openssl x509 -noout -issuer -in /etc/pki/tls/certs/alcasar.crt");
441
$cert_expiration_date = exec("/bin/openssl x509 -noout -dates -in /etc/pki/tls/certs/alcasar.crt|grep After|cut -d\"=\" -f2");
442
$domain = exec("echo $cert_subject | sed -n '/^subject/s/^.*CN=//p' | cut -d'/' -f 1");
443
$organization = exec("echo $cert_subject | sed -n '/^subject/s/^.*O=//p' | cut -d'/' -f 1");
444
$CAdomain = exec("echo $cert_issuer | sed -n '/^issuer/s/^.*CN=//p' | cut -d'/' -f 1");
445
$CAorganization = exec("echo $cert_issuer | sed -n '/^issuer/s/^.*O=//p' | cut -d'/' -f 1");
1743 clement.si 446
 
1764 richard 447
	echo "<br>";
448
	echo "<h3>".$l_current_certificate."</h3>";
449
	echo "Expiration Date : ".$cert_expiration_date."<br>";
450
	echo "Common name : ".$domain."<br>";
451
	echo "Organization : ".$organization."<br/>";
452
	echo "<h4>". $l_validated ."</h4>";
453
	echo "Common name : ".$CAdomain."<br>";
454
	echo "Organization : ".$CAorganization."<br>";
1743 clement.si 455
?>
1710 richard 456
	</td><td>
457
	<form method="post" action="network.php">
1740 richard 458
	<input type="hidden" name="default">
1764 richard 459
	<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 460
	</form>
461
	</td>
462
	</tr>
463
</table>
318 richard 464
</body>
465
</html>
1710 richard 466
 
467
<?php
468
if(isset($_POST['default'])){
1740 richard 469
	echo "$l_default_cert";
1733 richard 470
	exec("sudo alcasar-importcert.sh -d");
1710 richard 471
}
472
if(isset($_POST['MAX_FILE_SIZE'])){
473
	echo "changement";
474
	$maxsize = 100000;
475
	if(isset($_FILES['key']) && isset($_FILES['crt']) && $_FILES['key']['error'] == 0 && $_FILES['crt']['error'] == 0){
476
		$dest = "/tmp/";
477
		if($_FILES['key']['size'] <= $maxsize && $_FILES['crt']['size'] <= $maxsize)
478
		{
479
			if(pathinfo($_FILES['key']['name'])['extension'] == 'key' && pathinfo($_FILES['crt']['name'])['extension'] == 'crt')
480
			{
481
				$scpath = "";
482
				if(isset($_FILES['sc']) && pathinfo($_FILES['sc']['name'])['extension'] == 'crt')
483
				{
484
					$scpath = $dest."server-chain.crt";
1740 richard 485
					move_uploaded_file($_FILES['sc']['tmp_name'], $scpath);
1710 richard 486
				}
487
				$keypath = $dest."alcasar.key";
488
				$crtpath = $dest."alcasar.crt";
489
				move_uploaded_file($_FILES['key']['tmp_name'], $keypath);
490
				move_uploaded_file($_FILES['crt']['tmp_name'], $crtpath);
491
				exec("sudo alcasar-importcert.sh -i $crtpath -k $keypath -c $scpath");
492
			}
493
		}
494
	}
495
}
496
?>