Subversion Repositories ALCASAR

Rev

Rev 2934 | Rev 2991 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
838 richard 1
<?php
2688 lucas.echa 2
/* written by steweb57 & Rexy */
838 richard 3
# Choice of language
4
$Language = 'en';
5
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
6
	$Langue		= explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
7
	$Language	= strtolower(substr(chop($Langue[0]),0,2)); }
2853 rexy 8
if($Language == 'fr') {
838 richard 9
	$l_services_title	= "Configuration des services";
1157 stephane 10
	$l_main_services	= "Services principaux";
1476 richard 11
	$l_filter_services	= "Services de filtrage";
1157 stephane 12
	$l_opt_services		= "Services optionnels";
2926 rexy 13
	$l_service_title 	= "Rôle du service";
2134 richard 14
	$l_service_start 	= "Démarrer";
15
	$l_service_stop 	= "Arréter";
16
	$l_service_restart 	= "Redémarrer";
838 richard 17
	$l_service_status 	= "Status";
1006 richard 18
	$l_service_status_img_ok= "Démarré";
19
	$l_service_status_img_ko= "Arrété";
838 richard 20
	$l_service_action 	= "Actions";
21
	$l_radiusd		= "Serveur d'authentification et d'autorisation";
2531 rexy 22
	$l_chilli		= "Passerelle d'interception et serveur DHCP";
2521 armand.ito 23
	$l_e2guardian		= "Filtre d'URL et de contenu WEB";
1476 richard 24
	$l_mysqld		= "Serveur de la base des usagers";
2488 lucas.echa 25
	$l_lighttpd		= "Serveur WEB (Alcasar Control Center)";
1476 richard 26
	$l_sshd			= "Accès sécurisée distant";
2776 rexy 27
	$l_clamav_freshclam	= "Mise à jour de l'antivirus (toutes les 4 heures)";
2840 rexy 28
	$l_clamav_daemon	= "Antimalware";
838 richard 29
	$l_ntpd			= "Service de mise à l'heure réseau";
2531 rexy 30
	$l_fail2ban		= "Détecteur d'intrusion";
2775 rexy 31
	$l_nfcapd 		= "Collecteur de flux NetFlow";
2531 rexy 32
	$l_vnstat		= "Grapheur de flux réseau";
2688 lucas.echa 33
	$l_unbound		= "Serveur DNS principal";
34
	$l_unbound_blacklist	= "Serveur DNS pour la Blacklist";
35
	$l_unbound_whitelist	= "Serveur DNS pour la Whitelist";
36
	$l_dnsmasq_whitelist	= "Serveur DNS pour la Whitelist (IPSET)";
37
	$l_unbound_blackhole	= "Serveur DNS 'trou noir'";
1484 richard 38
	$l_ulogd_ssh		= "journalisation des accès par SSH";
1476 richard 39
	$l_ulogd_ext_access	= "journalisation des tentatives d'accès externes";
40
	$l_ulogd_traceability	= "journalisation des connexions WEB filtrés";
2926 rexy 41
	$l_wifi4eu_id	= "Entrez votre identifiant réseau";
1574 richard 42
	$l_execute		= "Exécuter";
2926 rexy 43
	$l_stop_restart		= "Arrêt et redémarrage du système";
1574 richard 44
	$l_halt			= "Arréter le système";
45
	$l_reboot		= "Relancer le système";
2853 rexy 46
} else if($Language == 'es') {
47
	$l_services_title	= "Configuración de Servicios";
48
	$l_main_services	= "Servicios Principales";
49
	$l_filter_services	= "Servicios de Filtrado";
50
	$l_opt_services		= "Servicios Opcionales";
2926 rexy 51
	$l_service_title 	= "función del servicio";
2853 rexy 52
	$l_service_start 	= "Iniciar";
53
	$l_service_stop 	= "Detener";
54
	$l_service_restart 	= "Reiniciar";
55
	$l_service_status 	= "Estado";
56
	$l_service_status_img_ok= "Corriendo";
57
	$l_service_status_img_ko= "Detenido";
58
	$l_service_action 	= "Acciones";
59
	$l_radiusd		= "Servidor de autenticación y autorización.";
60
	$l_chilli		= "Pasarela de interceptación y servidor DHCP";
61
	$l_e2guardian		= "Filtro de contenidos URL y WEB";
62
	$l_mysqld		= "Motor de base de datos para usuarios";
63
	$l_lighttpd		= "Servidor WEB (ALCASAR Control Center)";
64
	$l_sshd			= "Servidor Seguro Acceso Remoto";
65
	$l_clamav_freshclam		= "Proceso de actualización Antivirus (cada 4 horas)";
66
	$l_clamav_daemon	= "Antimalware";
67
	$l_ntpd			= "Servidor de hora";
68
	$l_fail2ban		= "Sistema de Detección de Intrusos";
69
	$l_nfcapd		= "Colector de flujo NetFlow";
70
	$l_vnstat		= "Graficador de tráfico de red";
71
	$l_unbound		= "Servidor DNS principal ";
72
	$l_unbound_blacklist	= "Servidor DNS de Lista Negra";
73
	$l_unbound_whitelist	= "Servidor DNS de Lista Blanca";
74
	$l_dnsmasq_whitelist	= "Servidor DNS de Lista Blanca (IPSET)";
75
	$l_unbound_blackhole	= "Agujero negro DNS";
76
	$l_ulogd_ssh		= "Proceso de registro para accesos SSH";
77
	$l_ulogd_ext_access	= "Proceso de registro de intentos de accesos externos";
78
	$l_ulogd_traceability	= "Proceso de registro de acceso WEB";
2926 rexy 79
	$l_wifi4eu_id	= "Introduzca su identificador de red";
2853 rexy 80
	$l_execute		= "Ejecutar";
81
	$l_stop_restart		= "Apagado y Reinicio del sistema";
82
	$l_halt			= "Apagar el sistema";
83
	$l_reboot		= "Reiniciar el sistema";
838 richard 84
} else {
85
	$l_services_title	= "Services configuration";
1157 stephane 86
	$l_main_services	= "Main services";
1476 richard 87
	$l_filter_services	= "Filtering services";
1157 stephane 88
	$l_opt_services		= "Optional services";
2926 rexy 89
	$l_service_title 	= "Role of the service";
838 richard 90
	$l_service_start 	= "Start";
91
	$l_service_stop 	= "Stop";
92
	$l_service_restart 	= "Restart";
93
	$l_service_status 	= "Status";
1006 richard 94
	$l_service_status_img_ok= "Running";
95
	$l_service_status_img_ko= "Stopped";
838 richard 96
	$l_service_action 	= "Actions";
1572 richard 97
	$l_radiusd		= "Authentication and authorisation server";
2531 rexy 98
	$l_chilli		= "Interception gateway and DHCP server";
2521 armand.ito 99
	$l_e2guardian		= "URL and WEB content filter";
838 richard 100
	$l_mysqld		= "User database server";
2488 lucas.echa 101
	$l_lighttpd		= "WEB server (ALCASAR Control Center)";
838 richard 102
	$l_sshd			= "Secure remote access";
2776 rexy 103
	$l_clamav_freshclam	= "Antivirus update process (every 4 hours)";
2840 rexy 104
	$l_clamav_daemon= "Antimalware";
1572 richard 105
	$l_ntpd			= "Network time server";
2531 rexy 106
	$l_fail2ban		= "Intrusion Dectection System";
2775 rexy 107
	$l_nfcapd		= "Netflow collector";
2531 rexy 108
	$l_vnstat		= "Network grapher";
2688 lucas.echa 109
	$l_unbound		= "Main DNS server";
110
	$l_unbound_blacklist	= "Blacklist DNS server";
111
	$l_unbound_whitelist	= "Whitelist DNS server";
112
	$l_dnsmasq_whitelist	= "Whitelist DNS server (IPSET)";
113
	$l_unbound_blackhole	= "Blackhole DNS server";
1476 richard 114
	$l_ulogd_ssh		= "SSH access logging process";
1572 richard 115
	$l_ulogd_ext_access	= "Extern access attempts logging process";
1476 richard 116
	$l_ulogd_traceability	= "Filtering WEB access logging process";
2926 rexy 117
	$l_wifi4eu_id	= "Enter your network identifier";
1574 richard 118
	$l_execute		= "Execute";
119
	$l_stop_restart		= "Halt and restart the system";
120
	$l_halt			= "Halt le system";
121
	$l_reboot		= "Restart the system";
838 richard 122
}
123
 
124
/****************************************************************
2531 rexy 125
*	                   CONST				*
838 richard 126
*****************************************************************/
127
define ("CONF_FILE", "/usr/local/etc/alcasar.conf");
128
 
129
/********************************************************
2531 rexy 130
*			CONF FILE test 			*
838 richard 131
*********************************************************/
132
if (!file_exists(CONF_FILE)){
133
	exit("Fichier de configuration ".CONF_FILE." non présent");
134
}
135
if (!is_readable(CONF_FILE)){
136
	exit("Vous n'avez pas les droits de lecture sur le fichier ".CONF_FILE);
137
}
2926 rexy 138
$file_conf = fopen(CONF_FILE, 'r');
139
if (!$file_conf) {
140
	exit('Error opening the file '.CONF_FILE);
141
}
142
while (!feof($file_conf)) {
143
	$buffer = fgets($file_conf, 4096);
144
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
145
		$tmp = explode('=', $buffer, 2);
146
		$conf[trim($tmp[0])] = trim($tmp[1]);
147
	}
148
}
149
fclose($file_conf);
150
$wifi4eu = $conf['WIFI4EU'];
151
$wifi4eu_code = $conf['WIFI4EU_CODE'];
2531 rexy 152
// Doing an action on a service (start,stop or restart)
838 richard 153
function serviceExec($service, $action){
154
	if (($action == "start")||($action == "stop")||($action == "restart")){
2934 rexy 155
		exec("sudo /usr/bin/systemctl $action ".escapeshellarg($service), $retval, $retstatus);
2926 rexy 156
		if ($service == "sshd"){ 
2688 lucas.echa 157
			if ($action == "start"){
2931 rexy 158
				//exec("sudo /usr/bin/systemctl enable ".escapeshellarg($service));
159
				file_put_contents(CONF_FILE, str_replace('SSH=off', 'SSH=on', file_get_contents(CONF_FILE))); // in order to keep that conf for SSH at next reboot
2299 tom.houday 160
				exec("sudo /usr/local/bin/alcasar-iptables.sh");
838 richard 161
				}
162
			if ($action == "stop"){
2931 rexy 163
				//exec("sudo /usr/bin/systemctl disable ".escapeshellarg($service));
838 richard 164
				file_put_contents(CONF_FILE, str_replace('SSH=on', 'SSH=off', file_get_contents(CONF_FILE)));
2299 tom.houday 165
				exec("sudo /usr/local/bin/alcasar-iptables.sh");
838 richard 166
				}
167
			}
168
		return $retstatus;
169
	} else {
170
		return false;
171
	}
172
}
2531 rexy 173
 
174
// Testing if a service is active
1006 richard 175
function checkServiceStatus($service){
838 richard 176
	$response = false;
2299 tom.houday 177
	exec("sudo /usr/bin/systemctl is-active ".escapeshellarg("$service.service"), $retval);
838 richard 178
	foreach( $retval as $val ) {
1006 richard 179
		if ($val == "active"){
838 richard 180
			$response = true;
181
			break;
182
		}
183
	}
184
	return $response;
185
}
186
 
187
//-------------------------------
2926 rexy 188
// WIFI4EU
189
//-------------------------------
190
if (isset($_POST['wifi4eu'])){
2934 rexy 191
	switch ($_POST['wifi4eu']){
192
		case 'on' :
2935 rexy 193
			$network_code = trim($_POST['wifi4eu_id']);
194
		        if ($network_code == '') {
195
				$network_code = '123e4567-e89b-12d3-a456-426655440000'; // WIFI4EU test code
196
			}
197
			file_put_contents(CONF_FILE, preg_replace('/WIFI4EU_CODE=.*/', 'WIFI4EU_CODE='.$network_code, file_get_contents(CONF_FILE)));
2934 rexy 198
			exec("sudo /usr/local/bin/alcasar-wifi4eu.sh -on");
199
		break;
200
		case 'off' :
201
			exec("sudo /usr/local/bin/alcasar-wifi4eu.sh -off");
202
		break;
203
	}
204
	header('Location: '.$_SERVER['PHP_SELF']);
2926 rexy 205
}
2934 rexy 206
 
2926 rexy 207
//-------------------------------
2934 rexy 208
// Stop/restart system
1574 richard 209
//-------------------------------
2934 rexy 210
if (isset($_POST['system'])){
211
	switch ($_POST['system']){
1574 richard 212
		case 'reboot' :
1827 raphael.pi 213
			exec ("sudo /usr/local/bin/alcasar-logout.sh all");
1599 richard 214
			exec ("sudo /usr/sbin/shutdown -r now");
1574 richard 215
		break;
216
		case 'halt' :
1827 raphael.pi 217
			exec ("sudo /usr/local/bin/alcasar-logout.sh all");
1599 richard 218
			exec ("sudo /usr/sbin/shutdown -h now");
1574 richard 219
		break;
220
	}
221
}
222
 
223
//-------------------------------
2934 rexy 224
// Actions on services
225
//-------------------------------
226
$autorizeService = array("radiusd","chilli","mysqld","lighttpd","unbound-forward","ulogd-ssh","ulogd-ext-access","ulogd-traceability","unbound-blacklist","unbound-whitelist","dnsmasq-whitelist","unbound-blackhole","e2guardian","clamav-daemon","clamav-freshclam","sshd","ntpd","fail2ban","nfcapd","vnstat");
227
$autorizeAction = array("start","stop","restart");
228
 
229
if (isset($_GET['service'])&&(in_array($_GET['service'], $autorizeService))) {
230
    if (isset($_GET['action'])&&(in_array($_GET['action'], $autorizeAction))) {
231
    	$execStatus = serviceExec($_GET['service'], $_GET['action']);
232
		// execStatus non exploité
233
	}
234
}
235
 
236
//-------------------------------
2531 rexy 237
// Check services status
838 richard 238
//-------------------------------
239
$MainServiceStatus = array();
2531 rexy 240
$MainServiceStatus['chilli'] = checkServiceStatus("chilli");
1006 richard 241
$MainServiceStatus['radiusd'] = checkServiceStatus("radiusd");
242
$MainServiceStatus['mysqld'] = checkServiceStatus("mysqld");
2488 lucas.echa 243
$MainServiceStatus['lighttpd'] = checkServiceStatus("lighttpd");
2724 rexy 244
$MainServiceStatus['unbound'] = checkServiceStatus("unbound");
2775 rexy 245
$MainServiceStatus['nfcapd'] = checkServiceStatus("nfcapd");
2531 rexy 246
$MainServiceStatus['ulogd_ssh'] = checkServiceStatus("ulogd-ssh");
247
$MainServiceStatus['ulogd_ext_access'] = checkServiceStatus("ulogd-ext-access");
248
$MainServiceStatus['ulogd_traceability'] = checkServiceStatus("ulogd-traceability");
2926 rexy 249
$MainServiceStatus['sshd'] = checkServiceStatus("sshd");
250
$MainServiceStatus['ntpd'] = checkServiceStatus("ntpd");
251
$MainServiceStatus['fail2ban'] = checkServiceStatus("fail2ban");
252
$MainServiceStatus['vnstat'] = checkServiceStatus("vnstat");
838 richard 253
 
1476 richard 254
$FilterServiceStatus = array();
2688 lucas.echa 255
$FilterServiceStatus['unbound_blacklist'] = checkServiceStatus("unbound-blacklist");
256
$FilterServiceStatus['unbound_whitelist'] = checkServiceStatus("unbound-whitelist");
2531 rexy 257
$FilterServiceStatus['dnsmasq_whitelist'] = checkServiceStatus("dnsmasq-whitelist");
2688 lucas.echa 258
$FilterServiceStatus['unbound_blackhole'] = checkServiceStatus("unbound-blackhole");
2531 rexy 259
$FilterServiceStatus['e2guardian'] = checkServiceStatus("e2guardian");
2840 rexy 260
$FilterServiceStatus['clamav_daemon'] = checkServiceStatus("clamav-daemon");
2776 rexy 261
$FilterServiceStatus['clamav_freshclam'] = checkServiceStatus("clamav-freshclam");
1476 richard 262
 
838 richard 263
/****************
264
*	MAIN	*
265
*****************/
266
 
2926 rexy 267
?><!DOCTYPE HTML>
268
<html>
838 richard 269
<head>
2926 rexy 270
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
271
	<title><?php echo $l_services_title; ?></title>
272
	<link rel="stylesheet" href="/css/acc.css" type="text/css">
838 richard 273
</head>
274
<body>
2926 rexy 275
<div class="panel">
276
	<div class="panel-header"><?= $l_main_services ?></div>
277
	<div class="panel-row">
278
	<table width="100%" border=0 cellspacing=0 cellpadding=0>
279
		<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>
280
		<?php foreach( $MainServiceStatus as $serviceName => $statusOK ) { ?>
281
		<tr>
282
		<?php if ($statusOK) { ?>
283
			<td align="center"><img src="/images/state_ok.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ok; ?>"></td>
284
			<td align="center"><?php $comment="l_$serviceName"; echo "<b>$serviceName</b></td><td>${$comment}" ;?> </td>
285
			<td width="80" align="center">---</td>
286
			<td width="80" align="center"><?php if (($serviceName != "chilli") && ($serviceName != "lighttpd")) { echo "<a href=\"".$_SERVER['PHP_SELF']."?action=stop&service=".str_replace('_','-',$serviceName)."\"> $l_service_stop</a>"; } else echo "---";?></td>
287
			<td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=restart&service=".str_replace('_','-',$serviceName)."\"> $l_service_restart";?></a></td>
288
		<?php } else { ?>
289
			<td align="center"><img src="/images/state_error.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ko ?>"></td>
290
			<td align="center"><?php $comment="l_$serviceName"; echo "$serviceName</td><td>${$comment}" ;?> </td>
291
			<td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=start&service=".str_replace('_','-',$serviceName)."\"> $l_service_start";?></a></td>
292
			<td width="80" align="center">---</td>
293
			<td width="80" align="center">---</td>
294
		<?php } ?>
295
		</tr>
296
		<?php } ?>
297
	</table>
298
	</div>
299
</div>
300
<div class="panel">
301
	<div class="panel-header"><?= $l_filter_services ?></div>
302
	<div class="panel-row">
303
	<table width="100%" border=0 cellspacing=0 cellpadding=0>
304
		<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>
305
		<!--	<TR align="center"> -->
306
		<?php foreach( $FilterServiceStatus as $serviceName => $statusOK ) { ?>
307
		<tr>
308
		<?php if ($statusOK) { ?>
309
			<td align="center"><img src="/images/state_ok.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ok; ?>"></td>
310
			<td align="center"><?php $comment="l_$serviceName"; echo "<b>$serviceName</b></td><td>${$comment}" ;?> </td>
311
			<td width="80" align="center">---</td>
312
			<td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=stop&service=".str_replace('_','-',$serviceName)."\"> $l_service_stop";?></a></td>
313
			<td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=restart&service=".str_replace('_','-',$serviceName)."\"> $l_service_restart";?></a></td>
314
			<?php } else { ?>
315
			<td align="center"><img src="/images/state_error.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ko ?>"></td>
316
			<td align="center"><?php $comment="l_$serviceName"; echo "$serviceName</td><td>${$comment}" ;?> </td>
317
			<td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=start&service=".str_replace('_','-',$serviceName)."\"> $l_service_start";?></a></td>
318
			<td width="80" align="center">---</td>
319
			<td width="80" align="center">---</td>
320
			<?php } ?>
321
		</tr>
322
		<?php } ?>
323
	</table>
324
	</div>
325
</div>
326
<div class="panel">
327
	<div class="panel-header"><?= $l_opt_services ?></div>
328
	<div class="panel-row">
329
	<form action="<?php echo $_SERVER['PHP_SELF']?>" method=POST>
330
	<table width="100%" border=0 cellspacing=0 cellpadding=0>
331
		<tr align="center"><td><?php echo $l_service_status;?></td><td colspan="2"> </td><td colspan="3"><?php echo $l_service_action;?></td></tr>
332
		<tr>
333
			<?php if ($wifi4eu == "on") { ?>
334
			<td align="center"><img src="/images/state_ok.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ok; ?>"></td>
335
			<td align="center"><b>WIFI4EU</b></td><td><?php echo "network ID : $wifi4eu_code"; ?></td>
336
			<td width="80" align="center">---</td>
2934 rexy 337
			<td width="80" align="center"><input type=submit value="<?echo $l_service_stop;?>"><input type=hidden name="wifi4eu" value="off"></td>
2926 rexy 338
			<td width="80" align="center">---</td>
339
			<?php } else { ?>
340
			<td align="center"><img src="/images/state_error.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ko; ?>"></td>
2935 rexy 341
			<td align="center">WIFI4EU</td><td><?php echo $l_wifi4eu_id; ?> : <input type ="text" name="wifi4eu_id" value="<?php echo $wifi4eu_code; ?>" size="40"></td>
2934 rexy 342
			<td width="80" align="center"><input type=submit value="<?echo $l_service_start;?>"><input type=hidden name="wifi4eu" value="on"></td>
2926 rexy 343
			<td width="80" align="center">---</td>
344
			<td width="80" align="center">---</td>
345
			<?php } ?>
346
		</tr>
347
	</table>
348
	</form>
349
	</div>
350
</div>
351
<div class="panel">
352
	<div class="panel-header"><?= $l_stop_restart ?></div>
353
	<div class="panel-row">
354
	<table width="100%" border=0 cellspacing=0 cellpadding=1>
355
		<tr><td valign="middle" align="left">
356
			<form action="<?php echo $_SERVER['PHP_SELF']?>" method=POST>
2934 rexy 357
			<select name='system'>
2926 rexy 358
				<option selected value="reboot"><?echo "$l_reboot";?>
359
				<option value="halt"><?echo "$l_halt";?>
360
			</select>
361
			<input type=submit value="<?echo "$l_execute";?>">
362
			</form>
363
		</td></tr>
364
	</table>
365
	</div>
366
</div>
838 richard 367
</body>
368
</html>