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";
|
|
|
10 |
$l_main_services = "Services réseau principaux";
|
|
|
11 |
$l_opt_services = "Services réseau optionnels";
|
|
|
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";
|
|
|
17 |
$l_service_action = "Actions";
|
|
|
18 |
$l_enable = "actif";
|
|
|
19 |
$l_disable = "inactif";
|
|
|
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";
|
|
|
33 |
$l_main_services = "Main network services";
|
|
|
34 |
$l_opt_services = "Optional network services";
|
|
|
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";
|
|
|
40 |
$l_service_action = "Actions";
|
|
|
41 |
$l_enable = "enable";
|
|
|
42 |
$l_disable = "disable";
|
|
|
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"){
|
|
|
78 |
exec("sudo /sbin/chkconfig --add $service");
|
|
|
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"){
|
|
|
83 |
exec("sudo /sbin/chkconfig --del $service");
|
|
|
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)
|
|
|
95 |
function checkServiceStatus($service, $strMatch){
|
|
|
96 |
$response = false;
|
|
|
97 |
exec("sudo /sbin/service $service status",$retval);
|
|
|
98 |
foreach( $retval as $val ) {
|
|
|
99 |
if (strpos($val,$strMatch)){
|
|
|
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();
|
|
|
124 |
$MainServiceStatus['radiusd'] = checkServiceStatus("radiusd","pid");
|
|
|
125 |
$MainServiceStatus['chilli'] = checkServiceStatus("chilli","pid");
|
|
|
126 |
$MainServiceStatus['dansguardian'] = checkServiceStatus("dansguardian","pid");
|
|
|
127 |
$MainServiceStatus['mysqld'] = checkServiceStatus("mysqld","OK");
|
|
|
128 |
$MainServiceStatus['squid'] = checkServiceStatus("squid","pid");
|
|
|
129 |
$MainServiceStatus['dnsmasq'] = checkServiceStatus("dnsmasq","pid");
|
|
|
130 |
$MainServiceStatus['httpd'] = checkServiceStatus("httpd","pid");
|
|
|
131 |
$MainServiceStatus['havp'] = checkServiceStatus("havp","pid");
|
|
|
132 |
|
|
|
133 |
$OptServiceStatus = array();
|
|
|
134 |
$OptServiceStatus['sshd'] = checkServiceStatus("sshd","pid");
|
|
|
135 |
$OptServiceStatus['freshclam'] = checkServiceStatus("freshclam","pid");
|
|
|
136 |
$OptServiceStatus['ntpd'] = checkServiceStatus("ntpd","pid");
|
|
|
137 |
|
|
|
138 |
/********************************************************************
|
|
|
139 |
* Lecture du fichier CONF_FILE *
|
|
|
140 |
*********************************************************************/
|
|
|
141 |
$ouvre=fopen(CONF_FILE,"r");
|
|
|
142 |
if ($ouvre){
|
|
|
143 |
while (!feof ($ouvre))
|
|
|
144 |
{
|
|
|
145 |
$tampon = fgets($ouvre, 4096);
|
|
|
146 |
if (strpos($tampon,"=")!==false){
|
|
|
147 |
$tmp = explode("=",$tampon);
|
|
|
148 |
$conf[$tmp[0]] = $tmp[1];
|
|
|
149 |
}
|
|
|
150 |
}
|
|
|
151 |
}else{
|
|
|
152 |
exit("Erreur d'ouverture du fichier ".ALCASAR_ETH1);
|
|
|
153 |
}
|
|
|
154 |
fclose($ouvre);
|
|
|
155 |
|
|
|
156 |
/****************
|
|
|
157 |
* MAIN *
|
|
|
158 |
*****************/
|
|
|
159 |
|
|
|
160 |
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
|
161 |
<html><!-- written by steweb57 / rexy -->
|
|
|
162 |
<head>
|
|
|
163 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
|
164 |
<title><?php echo $l_services_title; ?></title>
|
|
|
165 |
<link rel="stylesheet" href="/css/style.css" type="text/css">
|
|
|
166 |
</head>
|
|
|
167 |
<body>
|
|
|
168 |
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
|
|
169 |
<tr><th><?php echo $l_main_services; ?></th></tr>
|
|
|
170 |
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
|
|
|
171 |
</table>
|
|
|
172 |
<TABLE width="100%" border=1 cellspacing=0 cellpadding=0>
|
|
|
173 |
<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>
|
|
|
174 |
<TR align="center">
|
|
|
175 |
<?php foreach( $MainServiceStatus as $serviceName => $statusOK ) { ?>
|
|
|
176 |
<tr>
|
|
|
177 |
<?php if ($statusOK) { ?>
|
|
|
178 |
<td align="center"><img src="/images/state_ok.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ok; ?>"></td>
|
|
|
179 |
<td align="center"><?php $comment="l_$serviceName"; echo "<b>$serviceName</b></td><td>${$comment}" ;?> </td>
|
|
|
180 |
<td width="80" align="center">---</td>
|
|
|
181 |
<td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=stop&service=$serviceName\"> $l_service_stop";?></a></td>
|
|
|
182 |
<td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=restart&service=$serviceName\"> $l_service_restart";?></a></td>
|
|
|
183 |
<?php } else { ?>
|
|
|
184 |
<td align="center"><img src="/images/state_error.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ko ?>"></td>
|
|
|
185 |
<td align="center"><?php $comment="l_$serviceName"; echo "<b>$serviceName</b></td><td>${$comment}" ;?> </td>
|
|
|
186 |
<td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=start&service=$serviceName\"> $l_service_start";?></a></td>
|
|
|
187 |
<td width="80" align="center">---</td>
|
|
|
188 |
<td width="80" align="center">---</td>
|
|
|
189 |
<?php } ?>
|
|
|
190 |
</tr>
|
|
|
191 |
<?php } ?>
|
|
|
192 |
</td></tr>
|
|
|
193 |
</table>
|
|
|
194 |
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
|
|
195 |
<tr><th><?php echo $l_opt_services; ?></th></tr>
|
|
|
196 |
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
|
|
|
197 |
</table>
|
|
|
198 |
<TABLE width="100%" border=1 cellspacing=0 cellpadding=0>
|
|
|
199 |
<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>
|
|
|
200 |
<TR align="center">
|
|
|
201 |
<?php foreach( $OptServiceStatus as $serviceName => $statusOK ) { ?>
|
|
|
202 |
<tr>
|
|
|
203 |
<?php if ($statusOK) { ?>
|
|
|
204 |
<td align="center"><img src="/images/state_ok.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ok; ?>"></td>
|
|
|
205 |
<td align="center"><?php $comment="l_$serviceName"; echo "<b>$serviceName</b></td><td>${$comment}" ;?> </td>
|
|
|
206 |
<td width="80" align="center">---</td>
|
|
|
207 |
<td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=stop&service=$serviceName\"> $l_service_stop";?></a></td>
|
|
|
208 |
<td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=restart&service=$serviceName\"> $l_service_restart";?></a></td>
|
|
|
209 |
<?php } else { ?>
|
|
|
210 |
<td align="center"><img src="/images/state_error.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ko ?>"></td>
|
|
|
211 |
<td align="center"><?php $comment="l_$serviceName"; echo "<b>$serviceName</b></td><td>${$comment}" ;?> </td>
|
|
|
212 |
<td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=start&service=$serviceName\"> $l_service_start";?></a></td>
|
|
|
213 |
<td width="80" align="center">---</td>
|
|
|
214 |
<td width="80" align="center">---</td>
|
|
|
215 |
<?php } ?>
|
|
|
216 |
</tr>
|
|
|
217 |
<?php } ?>
|
|
|
218 |
</td></tr>
|
|
|
219 |
</table>
|
|
|
220 |
</body>
|
|
|
221 |
</html>
|