Subversion Repositories ALCASAR

Rev

Rev 2531 | Rev 2724 | 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)); }
8
if($Language == 'fr'){
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";
838 richard 13
	$l_service_title 	= "Nom 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";
2531 rexy 27
	$l_freshclam		= "Mise à jour de l'antivirus (toutes les 2 heures)";
838 richard 28
	$l_ntpd			= "Service de mise à l'heure réseau";
2531 rexy 29
	$l_fail2ban		= "Détecteur d'intrusion";
30
	$l_nfsen 		= "Grapheur de flux NetFlow";
31
	$l_vnstat		= "Grapheur de flux réseau";
32
	$l_havp			= "Proxy Antivirus";
1508 richard 33
	$l_tinyproxy		= "Proxy HTTP léger";
2688 lucas.echa 34
	$l_unbound		= "Serveur DNS principal";
35
	$l_unbound_blacklist	= "Serveur DNS pour la Blacklist";
36
	$l_unbound_whitelist	= "Serveur DNS pour la Whitelist";
37
	$l_dnsmasq_whitelist	= "Serveur DNS pour la Whitelist (IPSET)";
38
	$l_unbound_blackhole	= "Serveur DNS 'trou noir'";
1484 richard 39
	$l_ulogd_ssh		= "journalisation des accès par SSH";
1476 richard 40
	$l_ulogd_ext_access	= "journalisation des tentatives d'accès externes";
41
	$l_ulogd_traceability	= "journalisation des connexions WEB filtrés";
1574 richard 42
	$l_execute		= "Exécuter";
43
	$l_stop_restart		= "Arret et redémarrage du système";
44
	$l_halt			= "Arréter le système";
45
	$l_reboot		= "Relancer le système";
2688 lucas.echa 46
 
838 richard 47
} else {
48
	$l_services_title	= "Services configuration";
1157 stephane 49
	$l_main_services	= "Main services";
1476 richard 50
	$l_filter_services	= "Filtering services";
1157 stephane 51
	$l_opt_services		= "Optional services";
838 richard 52
	$l_service_title 	= "Service name";
53
	$l_service_start 	= "Start";
54
	$l_service_stop 	= "Stop";
55
	$l_service_restart 	= "Restart";
56
	$l_service_status 	= "Status";
1006 richard 57
	$l_service_status_img_ok= "Running";
58
	$l_service_status_img_ko= "Stopped";
838 richard 59
	$l_service_action 	= "Actions";
1572 richard 60
	$l_radiusd		= "Authentication and authorisation server";
2531 rexy 61
	$l_chilli		= "Interception gateway and DHCP server";
2521 armand.ito 62
	$l_e2guardian		= "URL and WEB content filter";
838 richard 63
	$l_mysqld		= "User database server";
2488 lucas.echa 64
	$l_lighttpd		= "WEB server (ALCASAR Control Center)";
838 richard 65
	$l_sshd			= "Secure remote access";
1572 richard 66
	$l_freshclam		= "Antivirus update process (every 2 hours)";
67
	$l_ntpd			= "Network time server";
2531 rexy 68
	$l_fail2ban		= "Intrusion Dectection System";
69
	$l_nfsen		= "Netflow grapher";
70
	$l_vnstat		= "Network grapher";
1572 richard 71
	$l_havp			= "Antivirus Proxy";
1508 richard 72
	$l_tinyproxy		= "Light HTTP Proxy";
2688 lucas.echa 73
	$l_unbound		= "Main DNS server";
74
	$l_unbound_blacklist	= "Blacklist DNS server";
75
	$l_unbound_whitelist	= "Whitelist DNS server";
76
	$l_dnsmasq_whitelist	= "Whitelist DNS server (IPSET)";
77
	$l_unbound_blackhole	= "Blackhole DNS server";
1476 richard 78
	$l_ulogd_ssh		= "SSH access logging process";
1572 richard 79
	$l_ulogd_ext_access	= "Extern access attempts logging process";
1476 richard 80
	$l_ulogd_traceability	= "Filtering WEB access logging process";
1574 richard 81
	$l_execute		= "Execute";
82
	$l_stop_restart		= "Halt and restart the system";
83
	$l_halt			= "Halt le system";
84
	$l_reboot		= "Restart the system";
838 richard 85
}
86
 
87
/****************************************************************
2531 rexy 88
*	                   CONST				*
838 richard 89
*****************************************************************/
90
define ("CONF_FILE", "/usr/local/etc/alcasar.conf");
91
 
92
/********************************************************
2531 rexy 93
*			CONF FILE test 			*
838 richard 94
*********************************************************/
95
if (!file_exists(CONF_FILE)){
96
	exit("Fichier de configuration ".CONF_FILE." non présent");
97
}
98
if (!is_readable(CONF_FILE)){
99
	exit("Vous n'avez pas les droits de lecture sur le fichier ".CONF_FILE);
100
}
101
 
2531 rexy 102
// Doing an action on a service (start,stop or restart)
838 richard 103
function serviceExec($service, $action){
104
	if (($action == "start")||($action == "stop")||($action == "restart")){
2299 tom.houday 105
		exec("sudo /usr/bin/systemctl $action ".escapeshellarg($service), $retval, $retstatus);
2531 rexy 106
		if ($service == "sshd"){ // in order to keep that conf for SSH at next reboot
2688 lucas.echa 107
			if ($action == "start"){
2299 tom.houday 108
				exec("sudo /usr/bin/systemctl enable ".escapeshellarg($service));
838 richard 109
				file_put_contents(CONF_FILE, str_replace('SSH=off', 'SSH=on', file_get_contents(CONF_FILE)));
2299 tom.houday 110
				exec("sudo /usr/local/bin/alcasar-iptables.sh");
838 richard 111
				}
112
			if ($action == "stop"){
2299 tom.houday 113
			       	exec("sudo /usr/bin/systemctl disable ".escapeshellarg($service));
838 richard 114
				file_put_contents(CONF_FILE, str_replace('SSH=on', 'SSH=off', file_get_contents(CONF_FILE)));
2299 tom.houday 115
				exec("sudo /usr/local/bin/alcasar-iptables.sh");
838 richard 116
				}
117
			}
118
		return $retstatus;
119
	} else {
120
		return false;
121
	}
122
}
2531 rexy 123
 
124
// Testing if a service is active
1006 richard 125
function checkServiceStatus($service){
838 richard 126
	$response = false;
2299 tom.houday 127
	exec("sudo /usr/bin/systemctl is-active ".escapeshellarg("$service.service"), $retval);
838 richard 128
	foreach( $retval as $val ) {
1006 richard 129
		if ($val == "active"){
838 richard 130
			$response = true;
131
			break;
132
		}
133
	}
134
	return $response;
135
}
136
 
137
//-------------------------------
1574 richard 138
// Actions on services
838 richard 139
//-------------------------------
2688 lucas.echa 140
$autorizeService = array("radiusd","chilli","mysqld","lighttpd","unbound-forward","ulogd-ssh","ulogd-ext-access","ulogd-traceability","unbound-blacklist","unbound-whitelist","dnsmasq-whitelist","unbound-blackhole","e2guardian","havp","tinyproxy","freshclam","sshd","ntpd","fail2ban","nfsen","vnstat");
2531 rexy 141
$autorizeAction = array("start","stop","restart");
838 richard 142
 
143
if (isset($_GET['service'])&&(in_array($_GET['service'], $autorizeService))) {
144
    if (isset($_GET['action'])&&(in_array($_GET['action'], $autorizeAction))) {
145
    	$execStatus = serviceExec($_GET['service'], $_GET['action']);
146
		// execStatus non exploité
147
	}
148
}
149
//-------------------------------
1574 richard 150
// Actions on system
151
//-------------------------------
152
if (isset($_POST['choix'])){
153
	switch ($_POST['choix']){
154
		case 'reboot' :
1827 raphael.pi 155
			exec ("sudo /usr/local/bin/alcasar-logout.sh all");
1599 richard 156
			exec ("sudo /usr/sbin/shutdown -r now");
1574 richard 157
		break;
158
		case 'halt' :
1827 raphael.pi 159
			exec ("sudo /usr/local/bin/alcasar-logout.sh all");
1599 richard 160
			exec ("sudo /usr/sbin/shutdown -h now");
1574 richard 161
		break;
162
	}
163
}
164
 
165
//-------------------------------
2531 rexy 166
// Check services status
838 richard 167
//-------------------------------
168
$MainServiceStatus = array();
2531 rexy 169
$MainServiceStatus['chilli'] = checkServiceStatus("chilli");
1006 richard 170
$MainServiceStatus['radiusd'] = checkServiceStatus("radiusd");
171
$MainServiceStatus['mysqld'] = checkServiceStatus("mysqld");
2488 lucas.echa 172
$MainServiceStatus['lighttpd'] = checkServiceStatus("lighttpd");
2688 lucas.echa 173
$MainServiceStatus['unbound'] = checkServiceStatus("unbound-forward");
2531 rexy 174
$MainServiceStatus['ulogd_ssh'] = checkServiceStatus("ulogd-ssh");
175
$MainServiceStatus['ulogd_ext_access'] = checkServiceStatus("ulogd-ext-access");
176
$MainServiceStatus['ulogd_traceability'] = checkServiceStatus("ulogd-traceability");
838 richard 177
 
1476 richard 178
$FilterServiceStatus = array();
2688 lucas.echa 179
$FilterServiceStatus['unbound_blacklist'] = checkServiceStatus("unbound-blacklist");
180
$FilterServiceStatus['unbound_whitelist'] = checkServiceStatus("unbound-whitelist");
2531 rexy 181
$FilterServiceStatus['dnsmasq_whitelist'] = checkServiceStatus("dnsmasq-whitelist");
2688 lucas.echa 182
$FilterServiceStatus['unbound_blackhole'] = checkServiceStatus("unbound-blackhole");
2531 rexy 183
$FilterServiceStatus['e2guardian'] = checkServiceStatus("e2guardian");
1476 richard 184
$FilterServiceStatus['havp'] = checkServiceStatus("havp");
1508 richard 185
$FilterServiceStatus['tinyproxy'] = checkServiceStatus("tinyproxy");
1476 richard 186
$FilterServiceStatus['freshclam'] = checkServiceStatus("freshclam");
187
 
838 richard 188
$OptServiceStatus = array();
1006 richard 189
$OptServiceStatus['sshd'] = checkServiceStatus("sshd");
190
$OptServiceStatus['ntpd'] = checkServiceStatus("ntpd");
2531 rexy 191
$OptServiceStatus['fail2ban'] = checkServiceStatus("fail2ban");
192
$OptServiceStatus['nfsen'] = checkServiceStatus("nfsen");
193
$OptServiceStatus['vnstat'] = checkServiceStatus("vnstat");
838 richard 194
/****************
195
*	MAIN	*
196
*****************/
197
 
198
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
199
<html><!-- written by steweb57 / rexy -->
200
<head>
201
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
202
<title><?php echo $l_services_title; ?></title>
203
<link rel="stylesheet" href="/css/style.css" type="text/css">
204
</head>
205
<body>
206
<table width="100%" border="0" cellspacing="0" cellpadding="0">
207
	<tr><th><?php echo $l_main_services; ?></th></tr>
208
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
209
</table>
210
<TABLE width="100%" border=1 cellspacing=0 cellpadding=0>
211
	<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>
212
<?php foreach( $MainServiceStatus as $serviceName => $statusOK ) { ?>
213
<tr>
214
	<?php if ($statusOK) { ?>
2531 rexy 215
	<td align="center"><img src="/images/state_ok.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ok; ?>"></td>
216
	<td align="center"><?php $comment="l_$serviceName"; echo "<b>$serviceName</b></td><td>${$comment}" ;?> </td>
217
	<td width="80" align="center">---</td>
218
	<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>
219
	<td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=restart&service=".str_replace('_','-',$serviceName)."\"> $l_service_restart";?></a></td>
838 richard 220
	<?php } else { ?>
2531 rexy 221
	<td align="center"><img src="/images/state_error.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ko ?>"></td>
222
	<td align="center"><?php $comment="l_$serviceName"; echo "<b>$serviceName</b></td><td>${$comment}" ;?> </td>
223
	<td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=start&service=".str_replace('_','-',$serviceName)."\"> $l_service_start";?></a></td>
224
	<td width="80" align="center">---</td>
225
	<td width="80" align="center">---</td>
838 richard 226
    <?php } ?>
227
</tr>
228
<?php } ?>
229
</table>
230
<table width="100%" border="0" cellspacing="0" cellpadding="0">
1476 richard 231
	<tr><th><?php echo $l_filter_services; ?></th></tr>
232
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
233
</table>
234
<TABLE width="100%" border=1 cellspacing=0 cellpadding=0>
235
	<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>
2134 richard 236
<!--	<TR align="center"> -->
1476 richard 237
<?php foreach( $FilterServiceStatus as $serviceName => $statusOK ) { ?>
238
<tr>
239
	<?php if ($statusOK) { ?>
240
    <td align="center"><img src="/images/state_ok.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ok; ?>"></td>
2531 rexy 241
	<td align="center"><?php $comment="l_$serviceName"; echo "<b>$serviceName</b></td><td>${$comment}" ;?> </td>
1476 richard 242
    <td width="80" align="center">---</td>
2531 rexy 243
    <td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=stop&service=".str_replace('_','-',$serviceName)."\"> $l_service_stop";?></a></td>
244
    <td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=restart&service=".str_replace('_','-',$serviceName)."\"> $l_service_restart";?></a></td>
1476 richard 245
	<?php } else { ?>
246
    <td align="center"><img src="/images/state_error.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ko ?>"></td>
2531 rexy 247
    <td align="center"><?php $comment="l_$serviceName"; echo "<b>$serviceName</b></td><td>${$comment}" ;?> </td>
248
    <td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=start&service=".str_replace('_','-',$serviceName)."\"> $l_service_start";?></a></td>
1476 richard 249
    <td width="80" align="center">---</td>
250
    <td width="80" align="center">---</td>
251
    <?php } ?>
252
</tr>
253
<?php } ?>
254
</table>
255
<table width="100%" border="0" cellspacing="0" cellpadding="0">
838 richard 256
	<tr><th><?php echo $l_opt_services; ?></th></tr>
257
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
258
</table>
259
<TABLE width="100%" border=1 cellspacing=0 cellpadding=0>
260
	<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>
261
<?php foreach( $OptServiceStatus as $serviceName => $statusOK ) { ?>
262
<tr>
263
	<?php if ($statusOK) { ?>
264
    <td align="center"><img src="/images/state_ok.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ok; ?>"></td>
2531 rexy 265
	<td align="center"><?php $comment="l_$serviceName"; echo "<b>$serviceName</b></td><td>${$comment}" ;?> </td>
838 richard 266
    <td width="80" align="center">---</td>
267
    <td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=stop&service=$serviceName\"> $l_service_stop";?></a></td>
268
    <td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=restart&service=$serviceName\"> $l_service_restart";?></a></td>
269
	<?php } else { ?>
270
    <td align="center"><img src="/images/state_error.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ko ?>"></td>
2531 rexy 271
    <td align="center"><?php $comment="l_$serviceName"; echo "<b>$serviceName</b></td><td>${$comment}" ;?> </td>
838 richard 272
    <td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=start&service=$serviceName\"> $l_service_start";?></a></td>
273
    <td width="80" align="center">---</td>
274
    <td width="80" align="center">---</td>
275
    <?php } ?>
276
</tr>
277
<?php } ?>
2134 richard 278
</table>
279
<table width="100%" border="0" cellspacing="0" cellpadding="0">
1574 richard 280
	<tr><th><? echo $l_stop_restart;?></th></tr>
281
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
2134 richard 282
</table>
283
<table width="100%" border=1 cellspacing=0 cellpadding=1>
1574 richard 284
	<tr><td valign="middle" align="left">
2134 richard 285
	<FORM action="services.php" method=POST>
286
		<select name='choix'>
1574 richard 287
			<option selected value="reboot"><?echo "$l_reboot";?>
288
			<option value="halt"><?echo "$l_halt";?>
289
		</select>
290
		<input type=submit value="<?echo "$l_execute";?>">
291
	</FORM>
292
	</td></tr>
2134 richard 293
</table>
838 richard 294
</body>
295
</html>