Subversion Repositories ALCASAR

Rev

Rev 2521 | Rev 2688 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

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