0,0 → 1,190 |
<?php |
//------------------------------- |
// Fonctions |
//------------------------------- |
|
// Fonction de test de connectivité internet |
function internetTest(){ |
$host = "www.google.fr"; |
$port = "80"; |
//var $num; //non utilisé |
//var $error; //non utilisé |
|
if (! $sock = @fsockopen($host, $port, $num, $error, 5)) { |
return false; |
} else { |
fclose($sock); |
return true; |
} |
} |
|
// Fonction de test du filtrage |
function filtrageTest($file, $search_regex){ |
$pointeur = fopen($file,"r"); |
$result = false; |
if ($pointeur) |
{ |
while (!feof($pointeur)) |
{ |
$ligne = fgets($pointeur); |
if (preg_match($search_regex, $ligne, $r)) |
{ |
$result = true; |
break; |
} |
} |
} |
fclose($pointeur); |
return $result; |
} |
|
//fonction pour faire une action (start,stop,restart) sur un service |
function serviceExec($service, $action){ |
if (($action == "start")||($action == "stop")||($action == "restart")){ |
exec("sudo /sbin/service $service $action",$retval, $retstatus); |
return $retstatus; |
} else { |
return false; |
} |
} |
//fonction définissant le status d'un service |
//(en fonction de la présence d'un mot clé dans la valeur de status) |
function checkServiceStatus($service, $strMatch){ |
$response = false; |
exec("sudo /sbin/service $service status",$retval); |
foreach( $retval as $val ) { |
if (strpos($val,$strMatch)){ |
$response = true; |
break; |
} |
} |
return $response; |
} |
|
//------------------------------- |
// Les actions sur un service |
//------------------------------- |
//sécurité sur les actions à réaliser |
$autorizeService = array("radiusd","chilli","dansguardian","mysqld","squid","named","sshd"); |
$autorizeAction = array("start","stop","restart"); |
|
if (isset($_GET['service'])&&(in_array($_GET['service'], $autorizeService))) { |
if (isset($_GET['action'])&&(in_array($_GET['action'], $autorizeAction))) { |
$execStatus = serviceExec($_GET['service'], $_GET['action']); |
// execStatus non exploité |
} |
} |
//------------------------------- |
//recherche du status des services |
//------------------------------- |
$serviceStatus = array(); |
|
$serviceStatus['radiusd'] = checkServiceStatus("radiusd","pid"); |
$serviceStatus['chilli'] = checkServiceStatus("chilli","pid"); |
$serviceStatus['dansguardian'] = checkServiceStatus("dansguardian","pid"); |
$serviceStatus['mysqld'] = checkServiceStatus("mysqld","OK"); |
$serviceStatus['squid'] = checkServiceStatus("squid","pid"); |
$serviceStatus['named'] = checkServiceStatus("named","up"); |
$serviceStatus['sshd'] = checkServiceStatus("sshd","pid"); |
|
?> |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html> |
<!-- written by steweb57 --> |
<head> |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
<title>Services</title> |
<link rel="stylesheet" href="/css/style.css" type="text/css"> |
</head> |
<body> |
<?php |
# choice of language |
$Language = "en"; |
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){ |
$Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']); |
$Language = strtolower(substr(chop($Langue[0]),0,2));} |
if ($Language == 'fr'){ |
$l_service = "Services"; |
$l_service_internet = "Lien Internet"; |
$l_netfilter="Filtrage réseau"; |
$l_webfilter="Filtrage WEB"; |
$l_enable = "actif"; |
$l_disable = "inactif"; |
$l_service_title = "Nom du services"; |
$l_service_start = "Démarrer"; |
$l_service_stop = "Arrêter"; |
$l_service_restart = "Redémarrer"; |
$l_service_status = "Status"; |
$l_service_action = "Actions"; |
$l_service_status_img_ok = "Démarré"; |
$l_service_status_img_ko = "Arrêté"; |
} |
else { |
$l_service = "Services"; |
$l_service_internet = "Internet connexion"; |
$l_netfilter = "Network filter"; |
$l_webfilter="WEB filter"; |
$l_enable = "enable"; |
$l_disable = "disable"; |
$l_service_title = "Name of service"; |
$l_service_start = "Start"; |
$l_service_stop = "Stop"; |
$l_service_restart = "Restart"; |
$l_service_status = "Status"; |
$l_service_action = "Actions"; |
$l_service_status_img_ok = "Started"; |
$l_service_status_img_ko = "Stopped"; |
} |
?> |
<table width="100%" border="0" cellspacing="0" cellpadding="0"> |
<tr><th><?php echo $l_service;?></th></tr> |
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td> </tr> |
</table> |
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1> |
<tr><td valign="middle" align="left"> |
<?php |
if (InternetTest()){ |
echo "<h1><img src='/images/state_ok.gif'> $l_service_internet : <font color='green'>$l_enable</font></h1>"; |
} else { |
echo "<h1><img src='/images/state_error.gif'> $l_service_internet : <font color='red'>$l_disable</font></h1>"; |
} |
if (filtrageTest("/usr/local/bin/alcasar-iptables.sh", "/^FILTERING=\"yes\"/")){ |
echo "<h1><img src='/images/state_ok.gif'> $l_netfilter : <font color='green'>$l_enable</font></h1>"; |
} else { |
echo "<h1><img src='/images/state_error.gif'> $l_netfilter : <font color='red'>$l_disable</font></h1>"; |
} |
if (filtrageTest("/etc/dansguardian/dansguardian.conf","/^reportinglevel = 3/")){ |
echo "<h1><img src='/images/state_ok.gif'> $l_webfilter : <font color='green'>$l_enable</font></h1>"; |
} else { |
echo "<h1><img src='/images/state_error.gif'> $l_webfilter : <font color='red'>$l_disable</font></h1>"; |
} |
?> |
</td></tr> |
</table> |
<table width="100%" border=0 cellspacing=0 cellpadding=0> |
<tr><th><?php echo $l_service_status;?></th><th><?php echo $l_service_title;?></th><th colspan="3"><?php echo $l_service_action;?></th></tr> |
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td><td><img src="/images/pix.gif" width="1" height="2"></td><td><img src="/images/pix.gif" width="1" height="2"></td></tr> |
</table> |
<TABLE width="100%" border=1 cellspacing=0 cellpadding=0> |
<TR align="center"> |
<?php foreach( $serviceStatus as $serviceName => $statusOK ) { ?> |
<tr> |
<?php if ($statusOK) { ?> |
<td><img src="/images/state_ok.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ok; ?>"></td> |
<td><?php echo $serviceName ;?></td> |
<td width="30" align="center">---</td> |
<td width="30" align="center"><a href="services.php?action=stop&service=<?php echo $serviceName;?>"><?php echo $l_service_stop;?></a></td> |
<td width="30" align="center"><a href="services.php?action=restart&service=<?php echo $serviceName;?>"><?php echo $l_service_restart;?></a></td> |
<?php } else { ?> |
<td><img src="/images/state_error.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ko ?>"></td> |
<td><?php echo $serviceName ;?></td> |
<td width="30" align="center"><a href="services.php?action=start&service=<?php echo $serviceName;?>"><?php echo $l_service_start;?></a></td> |
<td width="30" align="center">---</td> |
<td width="30" align="center">---</td> |
<?php } ?> |
</tr> |
<?php } ?> |
</td></tr></table> |
</table> |
</body> |
</html> |