Subversion Repositories ALCASAR

Rev

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