Subversion Repositories ALCASAR

Rev

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