Subversion Repositories ALCASAR

Rev

Rev 838 | Rev 859 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 838 Rev 841
Line 1... Line 1...
1
<?php
1
<?php
2
/* written by steweb57 & Rexy */
2
/* written by steweb57 & Rexy */
3
 
3
 
-
 
4
/****************************************************************
-
 
5
*	CONSTANTES AVEC CHEMINS DES FICHIERS DE CONFIGURATION	*
-
 
6
*****************************************************************/
-
 
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");
-
 
10
 
-
 
11
/********************************************************************************
-
 
12
*				TEST DES FICHIERS DE CONFIGURATION		*
-
 
13
********************************************************************************/
-
 
14
//Test de présence et des droits en lecture des fichiers de configuration.
-
 
15
if (!file_exists(ALCASAR_CHILLI)){
-
 
16
	exit("Fichier de configuration ".ALCASAR_CHILLI." non présent");
-
 
17
}
-
 
18
if (!is_readable(ALCASAR_CHILLI)){
-
 
19
	exit("Vous n'avez pas les droits de lecture sur le fichier ".ALCASAR_CHILLI);
-
 
20
}
-
 
21
if (!file_exists(CONF_FILE)){
-
 
22
	exit("Fichier de configuration ".CONF_FILE." non présent");
-
 
23
}
-
 
24
if (!is_readable(CONF_FILE)){
-
 
25
	exit("Vous n'avez pas les droits de lecture sur le fichier ".CONF_FILE);
-
 
26
}
-
 
27
if (!file_exists(ETHERS_FILE)){
-
 
28
	exit("Fichier de configuration ".ETHERS_FILE." non présent");
-
 
29
}
-
 
30
if (!is_readable(ETHERS_FILE)){
-
 
31
	exit("Vous n'avez pas les droits de lecture sur le fichier ".ETHERS_FILE);
-
 
32
}
-
 
33
 
4
# Choice of language
34
# Choice of language
5
$Language = 'en';
35
$Language = 'en';
6
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
36
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
7
	$Langue		= explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
37
	$Langue		= explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
8
	$Language	= strtolower(substr(chop($Langue[0]),0,2)); }
38
	$Language	= strtolower(substr(chop($Langue[0]),0,2)); }
Line 15... Line 45...
15
	$l_ip_mask		= "Masque";
45
	$l_ip_mask		= "Masque";
16
	$l_ip_router		= "Passerelle";
46
	$l_ip_router		= "Passerelle";
17
	$l_ip_public		= "Adresse IP publique";
47
	$l_ip_public		= "Adresse IP publique";
18
	$l_ip_dns1		= "DNS1";
48
	$l_ip_dns1		= "DNS1";
19
	$l_ip_dns2		= "DNS2";
49
	$l_ip_dns2		= "DNS2";
-
 
50
	$l_dhcp_title		= "Serveur DHCP";
-
 
51
	$l_dhcp_on		= "Le service DHCP est actuellement activé";
-
 
52
	$l_dhcp_off		= "Le service DHCP est actuellement arrêté";
-
 
53
	$l_switch_on		= "Démarrer le service DHCP";
-
 
54
	$l_switch_off		= "Arrêter le service DHCP";
-
 
55
	$l_static_dhcp_title	= "Réservation d'adresses IP statiques";
-
 
56
	$l_mac_address		= "Adresse MAC";
-
 
57
	$l_ip_address		= "Adresse IP";
-
 
58
	$l_mac_del		= "Supprimer de la liste";
-
 
59
	$l_add_to_list		= "Ajouter";
-
 
60
	$l_submit		= "Appliquer";
-
 
61
 
20
} else {
62
} else {
21
	$l_network_title	= "Network configuration";
63
	$l_network_title	= "Network configuration";
22
	$l_eth0_legend		= "Eth0 (Internet connected interface)";
64
	$l_eth0_legend		= "Eth0 (Internet connected interface)";
23
	$l_eth1_legend		= "Eth1 (Private network)";
65
	$l_eth1_legend		= "Eth1 (Private network)";
24
	$l_internet_legend	= "INTERNET";
66
	$l_internet_legend	= "INTERNET";
25
	$l_ip_adr		= "IP Address";
67
	$l_ip_adr		= "IP Address";
26
	$l_ip_mask		= "Mask";
68
	$l_ip_mask		= "Mask";
27
	$l_ip_router		= "Router";
69
	$l_ip_router		= "Gateway";
28
	$l_ip_public		= "Public IP address";
70
	$l_ip_public		= "Public IP address";
29
	$l_ip_dns1		= "DNS1 :";
71
	$l_ip_dns1		= "DNS1 :";
30
	$l_ip_dns2		= "DNS2";
72
	$l_ip_dns2		= "DNS2";
-
 
73
	$l_dhcp_title		= "DHCP server";
-
 
74
	$l_dhcp_on		= "The DHCP service is enabled";
-
 
75
	$l_dhcp_off		= "The DHCP service is disabled";
-
 
76
	$l_switch_on		= "Start the DHCP service";
-
 
77
	$l_switch_off		= "Stop the DHCP service";
-
 
78
	$l_static_dhcp_title	= "Static IP addresses reservation";
-
 
79
	$l_mac_address		= "MAC Address";
-
 
80
	$l_ip_address		= "IP Address";
-
 
81
	$l_mac_del		= "Delete from list";
-
 
82
	$l_add_to_list		= "Add";
-
 
83
	$l_submit		= "Apply";
31
}
84
}
-
 
85
if (isset($_POST['choix'])){$choix=$_POST['choix'];} else {$choix="";}
-
 
86
switch ($choix)
32
 
87
{
-
 
88
case 'DHCP_On' :
33
/********************************************************************
89
	exec ("sudo /usr/local/sbin/alcasar-dhcp.sh -on");
-
 
90
	break;
-
 
91
case 'DHCP_Off' :
34
*	CONSTANTES AVEC CHEMINS DES FICHIERS DE CONFIGURATION			*
92
	exec ("sudo /usr/local/sbin/alcasar-dhcp.sh -off");
-
 
93
	break;
-
 
94
case 'new_mac' :
35
*********************************************************************/
95
	if ((trim($_POST['add_mac']) != "") and (trim($_POST['add_ip']) != ""))
-
 
96
		{
36
define ("ALCASAR_CHILLI", "/etc/chilli.conf");
97
		$tab=file(ETHERS_FILE);
-
 
98
		$insert="True";
37
define ("CONF_FILE", "/usr/local/etc/alcasar.conf");
99
		if ($tab)  # le fichier n'est pas vide
38
 
100
			{
-
 
101
			foreach ($tab as $line)  # on vérifie que les adresses mac et IP ne sont pas déjà présentes
-
 
102
				{
-
 
103
				$field=explode(" ", $line);
39
/********************************************************************
104
				$mac_addr=trim($field[0]);$ip_addr=trim($field[1]);
40
*				TEST DES FICHIERS DE CONFIGURATION					*
105
				if (trim($_POST['add_mac']) == trim ($mac_addr))
-
 
106
					{
-
 
107
					$insert="False";
-
 
108
					break;
-
 
109
					}
41
*********************************************************************/
110
				if (trim($_POST['add_iip']) == trim ($ip_addr))
-
 
111
					{
-
 
112
					$insert="False";
-
 
113
					break;
-
 
114
					}
-
 
115
				}
-
 
116
			}
-
 
117
		if ($insert == "True") 
-
 
118
			{
42
//Test de présence et des droits en lecture des fichiers de configuration.
119
			$line = trim($_POST['add_mac']) . " " . trim($_POST['add_ip']) . "\n";
43
if (!file_exists(ALCASAR_CHILLI)){
120
			$pointeur=fopen(ETHERS_FILE,"a");
-
 
121
			fwrite ($pointeur, $line);
-
 
122
			fclose ($pointeur);
44
	exit("Fichier de configuration ".ALCASAR_CHILLI." non présent");
123
			# exec ("sudo service chilli restart");
-
 
124
			}
45
}
125
		}
-
 
126
	break;
-
 
127
case 'del_mac' :
46
if (!file_exists(CONF_FILE)){
128
	$tab=file(ETHERS_FILE);
-
 
129
	if ($tab)
-
 
130
		{
47
	exit("Fichier de configuration ".CONF_FILE." non présent");
131
		$pointeur=fopen(ETHERS_FILE,"w+");
-
 
132
		foreach ($tab as $line)
48
}
133
			{
49
if (!is_readable(ALCASAR_CHILLI)){
134
			$field=explode(" ", $line);
-
 
135
			$mac_addr=trim($field[0]);
-
 
136
			$remove_line = False;
-
 
137
			foreach ($_POST as $key => $value)
-
 
138
				{
-
 
139
				if ($mac_addr == $key)
-
 
140
			       		{
-
 
141
					$remove_line = True;
-
 
142
					break;
-
 
143
					}
-
 
144
				}
50
	exit("Vous n'avez pas les droits de lecture sur le fichier ".ALCASAR_CHILLI);
145
			if (! $remove_line) {fwrite($pointeur,$line);}
51
}
146
			}
52
if (!is_readable(CONF_FILE)){
147
		fclose($pointeur);
53
	exit("Vous n'avez pas les droits de lecture sur le fichier ".CONF_FILE);
148
		# exec ("sudo service chilli restart");
-
 
149
		}
-
 
150
	break;
54
}
151
}
55
 
152
 
56
// Fonction de test de connectivité internet
153
// Fonction de test de connectivité internet
57
function internetTest(){
154
function internetTest(){
58
	$host = "www.google.fr"; # Google Test
155
	$host = "www.google.fr"; # Google Test
Line 97... Line 194...
97
			$tmp = explode("=",$tampon);
194
			$tmp = explode("=",$tampon);
98
			$conf[$tmp[0]] = $tmp[1];
195
			$conf[$tmp[0]] = $tmp[1];
99
		}
196
		}
100
	}
197
	}
101
}else{
198
}else{
102
	exit("Erreur d'ouverture du fichier ".ALCASAR_ETH1);
199
	exit("Erreur d'ouverture du fichier ".CONF_FILE);
103
}
200
}
104
fclose($ouvre);
201
fclose($ouvre);
105
 
202
 
106
/************************
203
/************************
107
*	TO DO		*
204
*	TO DO		*
108
*************************/
205
*************************/
109
//modification de la conf réseau  --> V3.0
206
//modification de la conf réseau  --> V3.0
110
//gestion du dhcp (affichage,modification, ajout @static)
-
 
111
 
207
 
112
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
208
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
113
<html><!-- written by steweb57 / rexy -->
209
<html><!-- written by steweb57 & rexy -->
114
<head>
210
<head>
115
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
211
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
116
<title><?php echo $l_network_title; ?></title>
212
<title><?php echo $l_network_title; ?></title>
117
<link rel="stylesheet" href="/css/style.css" type="text/css">
213
<link rel="stylesheet" href="/css/style.css" type="text/css">
118
</head>
214
</head>
Line 124... Line 220...
124
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
220
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
125
	<tr><td valign="middle" align="left">
221
	<tr><td valign="middle" align="left">
126
	<fieldset>
222
	<fieldset>
127
	<legend><?php echo $l_internet_legend;
223
	<legend><?php echo $l_internet_legend;
128
 	if (InternetTest()){
224
 	if (InternetTest()){
129
		echo " <img src='/images/state_ok.gif'> $l_enable";
225
		echo " <img src='/images/state_ok.gif'>";
130
		$IP_PUB = exec ("wget http://checkip.dyndns.org/ -O - -o /dev/null | cut -d: -f 2 | cut -d\< -f 1");}
226
		$IP_PUB = exec ("wget http://checkip.dyndns.org/ -O - -o /dev/null | cut -d: -f 2 | cut -d\< -f 1");}
131
	else 	{
227
	else 	{
132
		echo " <img src='/images/state_error.gif'> $l_disable";
228
		echo " <img src='/images/state_error.gif'>";
133
		$IP_PUB = "-.-.-.-";}
229
		$IP_PUB = "-.-.-.-";}
134
	?></legend>
230
	?></legend>
135
	<table>
231
	<table>
136
		<tr><td><?php echo $l_ip_public." : </td><td>".$IP_PUB;?></td></tr>
232
		<tr><td><?php echo $l_ip_public." : </td><td>".$IP_PUB;?></td></tr>
137
		<tr><td><?php echo $l_ip_dns1." : </td><td>".$conf["DNS1"];?></td></tr>
233
		<tr><td><?php echo $l_ip_dns1." : </td><td>".$conf["DNS1"];?></td></tr>
Line 154... Line 250...
154
	</table>
250
	</table>
155
	</fieldset>
251
	</fieldset>
156
	</td></tr>
252
	</td></tr>
157
</table>
253
</table>
158
<table width="100%" border="0" cellspacing="0" cellpadding="0">
254
<table width="100%" border="0" cellspacing="0" cellpadding="0">
159
	<tr><th><?php echo $l_main_services; ?></th></tr>
255
	<tr><th><?php echo $l_dhcp_title;?></th></tr>
160
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
256
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
161
</table>
257
</table>
-
 
258
<table width="100%" border=1 cellspacing=0 cellpadding=0>
-
 
259
<tr><td valign="middle" align="left">
-
 
260
<?
-
 
261
if (strncmp ($conf["DHCP"],"on",2) == 0)
-
 
262
 	{
-
 
263
	echo "<CENTER><H3>$l_dhcp_on</H3></CENTER>";
-
 
264
	echo "<FORM action='$_SERVER[PHP_SELF]' method=POST>";
-
 
265
	echo "<input type=hidden name='choix' value=\"DHCP_Off\">";
-
 
266
	echo "<input type=submit value=\"$l_switch_off\">";
-
 
267
	}
-
 
268
else
-
 
269
	{
-
 
270
	echo "<CENTER><H3>$l_dhcp_off</H3></CENTER>";
-
 
271
 	echo "<FORM action='$_SERVER[PHP_SELF]' method=POST>";
-
 
272
	echo "<input type=hidden name='choix' value=\"DHCP_On\">";
-
 
273
	echo "<input type=submit value=\"$l_switch_on\">";
-
 
274
	}
-
 
275
echo "</FORM>";
-
 
276
echo "</td></tr>";
-
 
277
echo "</TABLE>";
-
 
278
if (strncmp($conf["DHCP"],"on",2) == 0) require ('network2.php');
-
 
279
?>
-
 
280
</BODY>
162
</body>
281
</body>
163
</html>
282
</html>