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