318 |
richard |
1 |
<?php
|
|
|
2 |
/* written by steweb57 */
|
|
|
3 |
|
|
|
4 |
# Choice of language
|
|
|
5 |
$Language = 'en';
|
|
|
6 |
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
|
|
|
7 |
$Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
|
|
8 |
$Language = strtolower(substr(chop($Langue[0]),0,2)); }
|
|
|
9 |
if($Language == 'fr'){
|
|
|
10 |
$l_network_title = "Configuration réseau";
|
|
|
11 |
$l_network_title1 = "Gestion de la configuration réseau";
|
|
|
12 |
$l_eth0_legend = "Eth0 (Interface connectée à Internet)";
|
|
|
13 |
$l_eth1_legend = "Eth1 (Réseau de consultation)";
|
|
|
14 |
$l_internet_legend = "INTERNET";
|
|
|
15 |
$l_ip_adr = "Adresse IP";
|
|
|
16 |
$l_ip_mask = "Masque";
|
|
|
17 |
$l_ip_router = "Passerelle";
|
|
|
18 |
$l_ip_public = "Adresse IP public";
|
|
|
19 |
$l_ip_dns1 = "DNS1";
|
|
|
20 |
$l_ip_dns2 = "DNS2";
|
|
|
21 |
$l_service_title = "Nom du services";
|
|
|
22 |
$l_service_start = "Démarrer";
|
|
|
23 |
$l_service_stop = "Arrêter";
|
|
|
24 |
$l_service_restart = "Redémarrer";
|
|
|
25 |
$l_service_status = "Status";
|
|
|
26 |
$l_service_action = "Actions";
|
|
|
27 |
$l_enable = "actif";
|
|
|
28 |
$l_disable = "inactif";
|
|
|
29 |
} else {
|
|
|
30 |
$l_network_title = "Network configuration";
|
|
|
31 |
$l_network_title1 = "Network configuration managment";
|
|
|
32 |
$l_eth0_legend = "Eth0 (Internet connected interface)";
|
|
|
33 |
$l_eth1_legend = "Eth1 (Private network)";
|
|
|
34 |
$l_internet_legend = "INTERNET";
|
|
|
35 |
$l_ip_adr = "IP Address";
|
|
|
36 |
$l_ip_mask = "Mask";
|
|
|
37 |
$l_ip_router = "Router";
|
|
|
38 |
$l_ip_public = "Public IP address";
|
|
|
39 |
$l_ip_dns1 = "DNS1 :";
|
|
|
40 |
$l_ip_dns2 = "DNS2";
|
|
|
41 |
$l_service_title = "Name of service";
|
|
|
42 |
$l_service_start = "Start";
|
|
|
43 |
$l_service_stop = "Stop";
|
|
|
44 |
$l_service_restart = "Restart";
|
|
|
45 |
$l_service_status = "Status";
|
|
|
46 |
$l_service_action = "Actions";
|
|
|
47 |
$l_enable = "enable";
|
|
|
48 |
$l_disable = "disable";
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
/********************************************************************
|
|
|
52 |
* CONSTANTES AVEC CHEMINS DES FICHIERS DE CONFIGURATION *
|
|
|
53 |
*********************************************************************/
|
|
|
54 |
|
|
|
55 |
define ("ALCASAR_CHILLI", "/etc/chilli/config");
|
|
|
56 |
define ("ALCASAR_ETH0", "/etc/sysconfig/network-scripts/default-ifcfg-eth0");
|
|
|
57 |
define ("ALCASAR_ETH1", "/etc/sysconfig/network-scripts/ifcfg-eth1");
|
|
|
58 |
|
|
|
59 |
/********************************************************************
|
|
|
60 |
* TEST DES FICHIERS DE CONFIGURATION *
|
|
|
61 |
*********************************************************************/
|
|
|
62 |
|
|
|
63 |
//Test de présence et des droits en lecture des fichiers de configuration.
|
|
|
64 |
if (!file_exists(ALCASAR_CHILLI)){
|
|
|
65 |
exit("Fichier de configuration ".ALCASAR_CHILLI." non présent");
|
|
|
66 |
}
|
|
|
67 |
if (!file_exists(ALCASAR_ETH0)){
|
|
|
68 |
exit("Fichier de configuration ".ALCASAR_ETH0." non présent");
|
|
|
69 |
}
|
|
|
70 |
if (!file_exists(ALCASAR_ETH0)){
|
|
|
71 |
exit("Fichier de configuration ".ALCASAR_ETH1." non présent");
|
|
|
72 |
}
|
|
|
73 |
if (!is_readable(ALCASAR_ETH0)){
|
|
|
74 |
exit("Vous n'avez pas les droits de lecture sur le fichier ".ALCASAR_ETH0);
|
|
|
75 |
}
|
|
|
76 |
if (!is_readable(ALCASAR_ETH0)){
|
|
|
77 |
exit("Vous n'avez pas les droits de lecture sur le fichier ".ALCASAR_ETH1);
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
//fonction pour faire une action (start,stop,restart) sur un service
|
|
|
81 |
function serviceExec($service, $action){
|
|
|
82 |
if (($action == "start")||($action == "stop")||($action == "restart")){
|
|
|
83 |
exec("sudo /sbin/service $service $action",$retval, $retstatus);
|
|
|
84 |
return $retstatus;
|
|
|
85 |
} else {
|
|
|
86 |
return false;
|
|
|
87 |
}
|
|
|
88 |
}
|
|
|
89 |
//fonction définissant le status d'un service
|
|
|
90 |
//(en fonction de la présence d'un mot clé dans la valeur de status)
|
|
|
91 |
function checkServiceStatus($service, $strMatch){
|
|
|
92 |
$response = false;
|
|
|
93 |
exec("sudo /sbin/service $service status",$retval);
|
|
|
94 |
foreach( $retval as $val ) {
|
|
|
95 |
if (strpos($val,$strMatch)){
|
|
|
96 |
$response = true;
|
|
|
97 |
break;
|
|
|
98 |
}
|
|
|
99 |
}
|
|
|
100 |
return $response;
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
//-------------------------------
|
|
|
104 |
// Les actions sur un service
|
|
|
105 |
//-------------------------------
|
|
|
106 |
//sécurité sur les actions à réaliser
|
|
|
107 |
$autorizeService = array("radiusd","chilli","dansguardian","mysqld","squid","dnsmasq","httpd","havp","sshd");
|
|
|
108 |
$autorizeAction = array("start","stop","restart");
|
|
|
109 |
|
|
|
110 |
if (isset($_GET['service'])&&(in_array($_GET['service'], $autorizeService))) {
|
|
|
111 |
if (isset($_GET['action'])&&(in_array($_GET['action'], $autorizeAction))) {
|
|
|
112 |
$execStatus = serviceExec($_GET['service'], $_GET['action']);
|
|
|
113 |
// execStatus non exploité
|
|
|
114 |
}
|
|
|
115 |
}
|
|
|
116 |
//-------------------------------
|
|
|
117 |
//recherche du status des services
|
|
|
118 |
//-------------------------------
|
|
|
119 |
$serviceStatus = array();
|
|
|
120 |
$serviceStatus['radiusd'] = checkServiceStatus("radiusd","pid");
|
|
|
121 |
$serviceStatus['chilli'] = checkServiceStatus("chilli","pid");
|
|
|
122 |
$serviceStatus['dansguardian'] = checkServiceStatus("dansguardian","pid");
|
|
|
123 |
$serviceStatus['mysqld'] = checkServiceStatus("mysqld","OK");
|
|
|
124 |
$serviceStatus['squid'] = checkServiceStatus("squid","pid");
|
|
|
125 |
$serviceStatus['dnsmasq'] = checkServiceStatus("dnsmasq","pid");
|
|
|
126 |
$serviceStatus['httpd'] = checkServiceStatus("httpd","pid");
|
|
|
127 |
$serviceStatus['havp'] = checkServiceStatus("havp","pid");
|
|
|
128 |
$serviceStatus['sshd'] = checkServiceStatus("sshd","pid");
|
|
|
129 |
|
|
|
130 |
// Fonction de test de connectivité internet
|
|
|
131 |
function internetTest(){
|
|
|
132 |
$host = "www.google.fr";
|
|
|
133 |
$port = "80";
|
|
|
134 |
//var $num; //non utilisé
|
|
|
135 |
//var $error; //non utilisé
|
|
|
136 |
|
|
|
137 |
if (! $sock = @fsockopen($host, $port, $num, $error, 5)) {
|
|
|
138 |
return false;
|
|
|
139 |
} else {
|
|
|
140 |
fclose($sock);
|
|
|
141 |
return true;
|
|
|
142 |
}
|
|
|
143 |
}
|
|
|
144 |
/********************************************************************
|
|
|
145 |
* Lecture du fichier ALCASAR_CHILLI *
|
|
|
146 |
*********************************************************************/
|
|
|
147 |
$ouvre=fopen(ALCASAR_CHILLI,"r");
|
|
|
148 |
if ($ouvre){
|
|
|
149 |
while (!feof ($ouvre))
|
|
|
150 |
{
|
|
|
151 |
$tampon = fgets($ouvre, 4096);
|
|
|
152 |
if (strpos($tampon,"=")!==false){
|
|
|
153 |
$tmp = explode("=",$tampon);
|
|
|
154 |
$chilli[$tmp[0]] = $tmp[1];
|
|
|
155 |
}
|
|
|
156 |
}
|
|
|
157 |
}else{
|
|
|
158 |
exit("Erreur d'ouverture du fichier ".ALCASAR_CHILLI);
|
|
|
159 |
}
|
|
|
160 |
fclose($ouvre);
|
|
|
161 |
|
|
|
162 |
/********************************************************************
|
|
|
163 |
* Lecture du fichier ALCASAR_ETH0 *
|
|
|
164 |
*********************************************************************/
|
|
|
165 |
$ouvre=fopen(ALCASAR_ETH0,"r");
|
|
|
166 |
if ($ouvre){
|
|
|
167 |
while (!feof ($ouvre))
|
|
|
168 |
{
|
|
|
169 |
$tampon = fgets($ouvre, 4096);
|
|
|
170 |
if (strpos($tampon,"=")!==false){
|
|
|
171 |
$tmp = explode("=",$tampon);
|
|
|
172 |
$eth0[$tmp[0]] = $tmp[1];
|
|
|
173 |
}
|
|
|
174 |
}
|
|
|
175 |
}else{
|
|
|
176 |
exit("Erreur d'ouverture du fichier ".ALCASAR_ETH0);
|
|
|
177 |
}
|
|
|
178 |
fclose($ouvre);
|
|
|
179 |
|
|
|
180 |
/********************************************************************
|
|
|
181 |
* Lecture du fichier ALCASAR_ETH1 *
|
|
|
182 |
*********************************************************************/
|
|
|
183 |
$ouvre=fopen(ALCASAR_ETH1,"r");
|
|
|
184 |
if ($ouvre){
|
|
|
185 |
while (!feof ($ouvre))
|
|
|
186 |
{
|
|
|
187 |
$tampon = fgets($ouvre, 4096);
|
|
|
188 |
if (strpos($tampon,"=")!==false){
|
|
|
189 |
$tmp = explode("=",$tampon);
|
|
|
190 |
$eth1[$tmp[0]] = $tmp[1];
|
|
|
191 |
}
|
|
|
192 |
}
|
|
|
193 |
}else{
|
|
|
194 |
exit("Erreur d'ouverture du fichier ".ALCASAR_ETH1);
|
|
|
195 |
}
|
|
|
196 |
fclose($ouvre);
|
|
|
197 |
|
|
|
198 |
/************************
|
|
|
199 |
* TO DO *
|
|
|
200 |
*************************/
|
|
|
201 |
//modification de la conf réseau, cmd : ifconfig eth0 .....
|
|
|
202 |
//synchro de la modification réseau dans les différentes couches d'alcasar
|
|
|
203 |
//gestion du dhcp (affichage,modification, ajout @static)
|
|
|
204 |
|
|
|
205 |
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
|
206 |
<html><!-- written by steweb57 / rexy -->
|
|
|
207 |
<head>
|
|
|
208 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
|
209 |
<title><?php echo $l_network_title; ?></title>
|
|
|
210 |
<link rel="stylesheet" href="../css/style.css" type="text/css">
|
|
|
211 |
</head>
|
|
|
212 |
<body>
|
|
|
213 |
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
|
|
214 |
<tr><th><?php echo $l_network_title1; ?></th></tr>
|
|
|
215 |
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
|
|
|
216 |
</table>
|
|
|
217 |
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
|
|
|
218 |
<tr><td valign="middle" align="left">
|
|
|
219 |
<fieldset>
|
|
|
220 |
<legend><?php echo $l_internet_legend;
|
|
|
221 |
if (InternetTest()){
|
|
|
222 |
echo " <img src='/images/state_ok.gif'> $l_enable";
|
|
|
223 |
$IP_PUB = exec ("wget http://checkip.dyndns.org/ -O - -o /dev/null | cut -d: -f 2 | cut -d\< -f 1");}
|
|
|
224 |
else {
|
|
|
225 |
echo " <img src='/images/state_error.gif'> $l_disable";
|
|
|
226 |
$IP_PUB = "-.-.-.-";}
|
|
|
227 |
?></legend>
|
|
|
228 |
<table>
|
|
|
229 |
<tr><td><?php echo $l_ip_public." : </td><td>".$IP_PUB;?></td></tr>
|
|
|
230 |
<tr><td><?php echo $l_ip_dns1." : </td><td>".$eth0["DNS1"];?></td></tr>
|
|
|
231 |
<tr><td><?php echo $l_ip_dns2." : </td><td>".$eth0["DNS2"];?></td></tr>
|
|
|
232 |
</table>
|
|
|
233 |
</fieldset>
|
|
|
234 |
</td><td>
|
|
|
235 |
<fieldset>
|
|
|
236 |
<legend><?php echo $l_eth0_legend; ?></legend>
|
|
|
237 |
<table>
|
|
|
238 |
<tr><td><?php echo $l_ip_adr." : </td><td>".$eth0["IPADDR"];?></td></tr>
|
|
|
239 |
<tr><td><?php echo $l_ip_mask." : </td><td>".$eth0["NETMASK"];?></td></tr>
|
|
|
240 |
<tr><td><?php echo $l_ip_router." : </td><td>".$eth0["GATEWAY"];?></td></tr>
|
|
|
241 |
</table>
|
|
|
242 |
</fieldset>
|
|
|
243 |
</td><td>
|
|
|
244 |
<fieldset>
|
|
|
245 |
<legend><?php echo $l_eth1_legend; ?></legend>
|
|
|
246 |
<table>
|
|
|
247 |
<tr><td><?php echo $l_ip_adr." : </td><td>".$eth1["IPADDR"];?></td></tr>
|
|
|
248 |
<tr><td><?php echo $l_ip_mask." : </td><td>".$eth1["NETMASK"];?></td></tr>
|
|
|
249 |
</table>
|
|
|
250 |
</fieldset>
|
|
|
251 |
</td></tr>
|
|
|
252 |
</table>
|
|
|
253 |
<table width="100%" border=0 cellspacing=0 cellpadding=0>
|
|
|
254 |
<tr><th><?php echo $l_service_status;?></th><th><?php echo $l_service_title;?></th><th colspan="3"><?php echo $l_service_action;?></th></tr>
|
|
|
255 |
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td><td><img src="/images/pix.gif" width="1" height="2"></td><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
|
|
|
256 |
</table>
|
|
|
257 |
<TABLE width="100%" border=1 cellspacing=0 cellpadding=0>
|
|
|
258 |
<TR align="center">
|
|
|
259 |
<?php foreach( $serviceStatus as $serviceName => $statusOK ) { ?>
|
|
|
260 |
<tr>
|
|
|
261 |
<?php if ($statusOK) { ?>
|
|
|
262 |
<td align="center"><img src="/images/state_ok.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ok; ?>"></td>
|
|
|
263 |
<td align="left"><?php echo $serviceName ;?> </td>
|
|
|
264 |
<td width="80" align="center">---</td>
|
|
|
265 |
<td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=stop&service=$serviceName\"> $l_service_stop";?></a></td>
|
|
|
266 |
<td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=restart&service=$serviceName\"> $l_service_restart";?></a></td>
|
|
|
267 |
<?php } else { ?>
|
|
|
268 |
<td align="center"><img src="/images/state_error.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ko ?>"></td>
|
|
|
269 |
<td><?php echo $serviceName ;?></td>
|
|
|
270 |
<td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=start&service=$serviceName\"> $l_service_start";?></a></td>
|
|
|
271 |
<td width="80" align="center">---</td>
|
|
|
272 |
<td width="80" align="center">---</td>
|
|
|
273 |
<?php } ?>
|
|
|
274 |
</tr>
|
|
|
275 |
<?php } ?>
|
|
|
276 |
</td></tr></table>
|
|
|
277 |
</table>
|
|
|
278 |
</body>
|
|
|
279 |
</html>
|