Subversion Repositories ALCASAR

Rev

Rev 335 | Rev 355 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

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