Subversion Repositories ALCASAR

Rev

Rev 1484 | Rev 1578 | 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
*********************/
841 richard 7
define ("ALCASAR_CHILLI", "/etc/chilli.conf");
8
define ("CONF_FILE", "/usr/local/etc/alcasar.conf");
9
define ("ETHERS_FILE", "/usr/local/etc/alcasar-ethers");
861 richard 10
$conf_files=array(ALCASAR_CHILLI,CONF_FILE,ETHERS_FILE);
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);
859 richard 107
			exec ("sudo service chilli restart");
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);
132
		# exec ("sudo service chilli restart");
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	*
153
*********************************************************/
318 richard 154
$ouvre=fopen(ALCASAR_CHILLI,"r");
155
if ($ouvre){
156
	while (!feof ($ouvre))
157
	{
158
		$tampon = fgets($ouvre, 4096);
159
		if (strpos($tampon,"=")!==false){
160
			$tmp = explode("=",$tampon);
161
			$chilli[$tmp[0]] = $tmp[1];
162
		}
163
	}
164
}else{
165
	exit("Erreur d'ouverture du fichier ".ALCASAR_CHILLI);
166
}
167
fclose($ouvre);
168
 
861 richard 169
/***********************************
170
*	Read ALCASAR_CONF_FILE     *
171
************************************/
654 richard 172
$ouvre=fopen(CONF_FILE,"r");
318 richard 173
if ($ouvre){
174
	while (!feof ($ouvre))
175
	{
176
		$tampon = fgets($ouvre, 4096);
177
		if (strpos($tampon,"=")!==false){
178
			$tmp = explode("=",$tampon);
654 richard 179
			$conf[$tmp[0]] = $tmp[1];
318 richard 180
		}
181
	}
182
}else{
841 richard 183
	exit("Erreur d'ouverture du fichier ".CONF_FILE);
318 richard 184
}
185
fclose($ouvre);
186
 
187
/************************
188
*	TO DO		*
189
*************************/
838 richard 190
//modification de la conf réseau  --> V3.0
318 richard 191
 
192
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
841 richard 193
<html><!-- written by steweb57 & rexy -->
318 richard 194
<head>
195
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
196
<title><?php echo $l_network_title; ?></title>
335 richard 197
<link rel="stylesheet" href="/css/style.css" type="text/css">
318 richard 198
</head>
199
<body>
200
<table width="100%" border="0" cellspacing="0" cellpadding="0">
353 richard 201
	<tr><th><?php echo $l_network_title; ?></th></tr>
318 richard 202
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
203
</table>
204
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
205
	<tr><td valign="middle" align="left">
206
	<fieldset>
207
	<legend><?php echo $l_internet_legend;
208
 	if (InternetTest()){
841 richard 209
		echo " <img src='/images/state_ok.gif'>";
318 richard 210
		$IP_PUB = exec ("wget http://checkip.dyndns.org/ -O - -o /dev/null | cut -d: -f 2 | cut -d\< -f 1");}
211
	else 	{
841 richard 212
		echo " <img src='/images/state_error.gif'>";
318 richard 213
		$IP_PUB = "-.-.-.-";}
214
	?></legend>
215
	<table>
216
		<tr><td><?php echo $l_ip_public." : </td><td>".$IP_PUB;?></td></tr>
654 richard 217
		<tr><td><?php echo $l_ip_dns1." : </td><td>".$conf["DNS1"];?></td></tr>
218
		<tr><td><?php echo $l_ip_dns2." : </td><td>".$conf["DNS2"];?></td></tr>
318 richard 219
	</table>
220
	</fieldset>
221
	</td><td>
222
	<fieldset>
1478 richard 223
	<legend><?php echo $conf["EXTIF"].$l_extif_legend; ?></legend>
318 richard 224
	<table>
654 richard 225
		<tr><td><?php echo $l_ip_adr." : </td><td>".$conf["PUBLIC_IP"];?></td></tr>
226
		<tr><td><?php echo $l_ip_router." : </td><td>".$conf["GW"];?></td></tr>
318 richard 227
	</table>
228
	</fieldset>
229
	</td><td>
230
	<fieldset>
1478 richard 231
	<legend><?php echo $conf["INTIF"].$l_intif_legend; ?></legend>
318 richard 232
	<table>
654 richard 233
		<tr><td><?php echo $l_ip_adr." : </td><td>".$conf["PRIVATE_IP"];?></td></tr>
318 richard 234
	</table>
235
	</fieldset>
236
	</td></tr>
237
</table>
353 richard 238
<table width="100%" border="0" cellspacing="0" cellpadding="0">
841 richard 239
	<tr><th><?php echo $l_dhcp_title;?></th></tr>
353 richard 240
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
318 richard 241
</table>
841 richard 242
<table width="100%" border=1 cellspacing=0 cellpadding=0>
1484 richard 243
<tr><td colspan="2" valign="middle" align="left">
841 richard 244
<?
861 richard 245
$dhcp_state=trim($conf["DHCP"]);
862 richard 246
echo "<CENTER><H3>$l_dhcp_state : ${"l_DHCP_".$dhcp_state}</H3></CENTER>";
861 richard 247
echo "<FORM action='$_SERVER[PHP_SELF]' method=POST>";
248
echo "<select name='choix'>";
249
echo "<option value=\"DHCP_Off\" ";if (!strcmp($dhcp_state,"off")) echo "selected";echo ">$l_DHCP_off";
1484 richard 250
echo "<option value=\"DHCP_On\" ";if (!strcmp($dhcp_state,"on")) echo "selected";echo ">$l_DHCP_on";
861 richard 251
echo "</select>";
252
echo "<input type=submit value='$l_apply'>";
1484 richard 253
echo "<br>$l_DHCP_off_explain";
841 richard 254
echo "</FORM>";
255
echo "</td></tr>";
1484 richard 256
if (strncmp($conf["DHCP"],"on",2) == 0) { require ('network2.php');}
861 richard 257
else { echo "</TABLE>"; }
841 richard 258
?>
318 richard 259
</body>
260
</html>