Subversion Repositories ALCASAR

Rev

Rev 1157 | Rev 1476 | 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";
11
	$l_opt_services		= "Services optionnels";
838 richard 12
	$l_service_title 	= "Nom du service";
13
	$l_service_start 	= "D&eacute;marrer";
14
	$l_service_stop 	= "Arr&ecirc;ter";
15
	$l_service_restart 	= "Red&eacute;marrer";
16
	$l_service_status 	= "Status";
1006 richard 17
	$l_service_status_img_ok= "Démarré";
18
	$l_service_status_img_ko= "Arrété";
838 richard 19
	$l_service_action 	= "Actions";
20
	$l_radiusd		= "Serveur d'authentification et d'autorisation";
21
	$l_chilli		= "Passerelle d'interception";
22
	$l_dansguardian		= "Filtre d'URL et de contenu WEB";
23
	$l_mysqld		= "Serveur de la base de données usager";
24
	$l_httpd		= "Serveur WEB (Centre de Gestion d'ALCASAR)";
25
	$l_sshd			= "Accès sécurisée à distance";
26
	$l_freshclam		= "Mise à jour de l'antivirus toutes les 2 heures";
27
	$l_ntpd			= "Service de mise à l'heure réseau";
1396 richard 28
	$l_havp			= "Proxy Antivirus 1";
29
	$l_havp2		= "Proxy Antivirus 2";
30
	$l_dnsmasq		= "Serveur DHCP et de cache DNS";
31
	$l_dnsmasq_blacklist	= "Serveur DHCP et de cache DNS pour la Blacklist";
32
	$l_dnsmasq_whitelist	= "Serveur DHCP et de cache DNS pour la Whitelist";
838 richard 33
} else {
34
	$l_services_title	= "Services configuration";
1157 stephane 35
	$l_main_services	= "Main services";
36
	$l_opt_services		= "Optional services";
838 richard 37
	$l_service_title 	= "Service name";
38
	$l_service_start 	= "Start";
39
	$l_service_stop 	= "Stop";
40
	$l_service_restart 	= "Restart";
41
	$l_service_status 	= "Status";
1006 richard 42
	$l_service_status_img_ok= "Running";
43
	$l_service_status_img_ko= "Stopped";
838 richard 44
	$l_service_action 	= "Actions";
45
	$l_radiusd		= "Authentication and authorisation serveur";
46
	$l_chilli		= "Interception gateway";
47
	$l_dansguardian		= "URL and WEB content filter";
48
	$l_mysqld		= "User database server";
49
	$l_httpd		= "WEB server (ALCASAR Control Center)";
50
	$l_sshd			= "Secure remote access";
51
	$l_freshclam		= "WEB antivirus update (every 2 hours)";
52
	$l_ntpd			= "Network time";
1396 richard 53
	$l_havp			= "Antivirus Proxy 1";
54
	$l_havp2		= "Antivirus Proxy 2";
55
	$l_dnsmasq		= "A lightweight DHCP and caching DNS server";
56
	$l_dnsmasq_blacklist	= "A lightweight DHCP and caching DNS server for the Blacklist";
57
	$l_dnsmasq_whitelist	= "A lightweight DHCP and caching DNS server for the Whitelist";
838 richard 58
}
59
 
60
/****************************************************************
61
*	CONSTANTES AVEC CHEMINS DES FICHIERS DE CONFIGURATION	*
62
*****************************************************************/
63
define ("CONF_FILE", "/usr/local/etc/alcasar.conf");
64
 
65
/********************************************************
66
*	TEST DU FICHIERS DE CONFIGURATION		*
67
*********************************************************/
68
//Test de présence et des droits en lecture des fichiers de configuration.
69
if (!file_exists(CONF_FILE)){
70
	exit("Fichier de configuration ".CONF_FILE." non présent");
71
}
72
if (!is_readable(CONF_FILE)){
73
	exit("Vous n'avez pas les droits de lecture sur le fichier ".CONF_FILE);
74
}
75
 
76
//fonction pour faire une action (start,stop,restart) sur un service
77
function serviceExec($service, $action){
78
	if (($action == "start")||($action == "stop")||($action == "restart")){
79
		exec("sudo /sbin/service $service $action",$retval, $retstatus);
80
		if ($service == "sshd"){
81
			if ($action == "start"){ 
1041 richard 82
				exec("sudo /bin/systemctl enable $service.service");
838 richard 83
				file_put_contents(CONF_FILE, str_replace('SSH=off', 'SSH=on', file_get_contents(CONF_FILE)));
84
				exec ("sudo /usr/local/bin/alcasar-iptables.sh");
85
				}
86
			if ($action == "stop"){
1055 richard 87
			       	exec("sudo /sbin/systemctl disable $service.service");
838 richard 88
				file_put_contents(CONF_FILE, str_replace('SSH=on', 'SSH=off', file_get_contents(CONF_FILE)));
89
				exec ("sudo /usr/local/bin/alcasar-iptables.sh");
90
				}
91
			}
92
		return $retstatus;
93
	} else {
94
		return false;
95
	}
96
}
97
//fonction définissant le status d'un service 
98
//(en fonction de la présence d'un mot clé dans la valeur de status)
1006 richard 99
function checkServiceStatus($service){
838 richard 100
	$response = false;
1006 richard 101
	exec("/bin/systemctl is-active $service.service",$retval);
838 richard 102
	foreach( $retval as $val ) {
1006 richard 103
		if ($val == "active"){
838 richard 104
			$response = true;
105
			break;
106
		}
107
	}
108
	return $response;
109
}
110
 
111
//-------------------------------
112
// Les actions sur un service
113
//-------------------------------
114
//sécurité sur les actions à réaliser
1396 richard 115
$autorizeService = array("radiusd","chilli","dansguardian","mysqld","httpd","sshd","freshclam","ntpd","havp","havp2","dnsmasq","dnsmasq-blacklist","dnsmasq-whitelist");
838 richard 116
$autorizeAction = array("start","stop","restart");
117
 
118
if (isset($_GET['service'])&&(in_array($_GET['service'], $autorizeService))) {
119
    if (isset($_GET['action'])&&(in_array($_GET['action'], $autorizeAction))) {
120
    	$execStatus = serviceExec($_GET['service'], $_GET['action']);
121
		// execStatus non exploité
122
	}
123
}
124
//-------------------------------
125
//recherche du status des services
126
//-------------------------------
127
$MainServiceStatus = array();
1006 richard 128
$MainServiceStatus['radiusd'] = checkServiceStatus("radiusd");
129
$MainServiceStatus['chilli'] = checkServiceStatus("chilli");
130
$MainServiceStatus['dansguardian'] = checkServiceStatus("dansguardian");
131
$MainServiceStatus['mysqld'] = checkServiceStatus("mysqld");
132
$MainServiceStatus['httpd'] = checkServiceStatus("httpd");
133
$MainServiceStatus['havp'] = checkServiceStatus("havp");
1396 richard 134
$MainServiceStatus['havp2'] = checkServiceStatus("havp2");
135
$MainServiceStatus['dnsmasq'] = checkServiceStatus("dnsmasq");
136
$MainServiceStatus['dnsmasq_blacklist'] = checkServiceStatus("dnsmasq-blacklist");
137
$MainServiceStatus['dnsmasq_whitelist'] = checkServiceStatus("dnsmasq-whitelist");
838 richard 138
 
139
$OptServiceStatus = array();
1006 richard 140
$OptServiceStatus['sshd'] = checkServiceStatus("sshd");
141
$OptServiceStatus['freshclam'] = checkServiceStatus("freshclam");
142
$OptServiceStatus['ntpd'] = checkServiceStatus("ntpd");
838 richard 143
 
144
/****************
145
*	MAIN	*
146
*****************/
147
 
148
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
149
<html><!-- written by steweb57 / rexy -->
150
<head>
151
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
152
<title><?php echo $l_services_title; ?></title>
153
<link rel="stylesheet" href="/css/style.css" type="text/css">
154
</head>
155
<body>
156
<table width="100%" border="0" cellspacing="0" cellpadding="0">
157
	<tr><th><?php echo $l_main_services; ?></th></tr>
158
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
159
</table>
160
<TABLE width="100%" border=1 cellspacing=0 cellpadding=0>
161
	<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>
162
	<TR align="center">
163
<?php foreach( $MainServiceStatus as $serviceName => $statusOK ) { ?>
164
<tr>
165
	<?php if ($statusOK) { ?>
166
    <td align="center"><img src="/images/state_ok.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ok; ?>"></td>
167
	<td align="center"><?php $comment="l_$serviceName"; echo "<b>$serviceName</b></td><td>${$comment}" ;?> </td>
168
    <td width="80" align="center">---</td>
1396 richard 169
    <td width="80" align="center"><?php if ($serviceName != "chilli" && $serviceName != "havp" && $serviceName != "havp2" && $serviceName != "dnsmasq" && $serviceName != "dnsmasq_blacklist" && $serviceName != "dnsmasq_whitelist") { echo "<a href=".$_SERVER['PHP_SELF']."?action=stop&service=$serviceName\"> $l_service_stop</a>"; } else echo "---";?></td>
838 richard 170
    <td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=restart&service=$serviceName\"> $l_service_restart";?></a></td>
171
	<?php } else { ?>
172
    <td align="center"><img src="/images/state_error.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ko ?>"></td>
173
    <td align="center"><?php $comment="l_$serviceName"; echo "<b>$serviceName</b></td><td>${$comment}" ;?> </td>
174
    <td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=start&service=$serviceName\"> $l_service_start";?></a></td>
175
    <td width="80" align="center">---</td>
176
    <td width="80" align="center">---</td>
177
    <?php } ?>
178
</tr>
179
<?php } ?>
180
</td></tr>
181
</table>
182
<table width="100%" border="0" cellspacing="0" cellpadding="0">
183
	<tr><th><?php echo $l_opt_services; ?></th></tr>
184
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
185
</table>
186
<TABLE width="100%" border=1 cellspacing=0 cellpadding=0>
187
	<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>
188
	<TR align="center">
189
<?php foreach( $OptServiceStatus as $serviceName => $statusOK ) { ?>
190
<tr>
191
	<?php if ($statusOK) { ?>
192
    <td align="center"><img src="/images/state_ok.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ok; ?>"></td>
193
	<td align="center"><?php $comment="l_$serviceName"; echo "<b>$serviceName</b></td><td>${$comment}" ;?> </td>
194
    <td width="80" align="center">---</td>
195
    <td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=stop&service=$serviceName\"> $l_service_stop";?></a></td>
196
    <td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=restart&service=$serviceName\"> $l_service_restart";?></a></td>
197
	<?php } else { ?>
198
    <td align="center"><img src="/images/state_error.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ko ?>"></td>
199
    <td align="center"><?php $comment="l_$serviceName"; echo "<b>$serviceName</b></td><td>${$comment}" ;?> </td>
200
    <td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=start&service=$serviceName\"> $l_service_start";?></a></td>
201
    <td width="80" align="center">---</td>
202
    <td width="80" align="center">---</td>
203
    <?php } ?>
204
</tr>
205
<?php } ?>
206
</td></tr>
207
</table>
208
</body>
209
</html>