Subversion Repositories ALCASAR

Rev

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