Subversion Repositories ALCASAR

Rev

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