Subversion Repositories ALCASAR

Rev

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