Subversion Repositories ALCASAR

Rev

Rev 1478 | Rev 1508 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log

<?php
/* written by steweb57 & Rexy */ 
# 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_services_title       = "Configuration des services";
        $l_main_services        = "Services principaux";
        $l_filter_services      = "Services de filtrage";
        $l_opt_services         = "Services optionnels";
        $l_service_title        = "Nom du service";
        $l_service_start        = "D&eacute;marrer";
        $l_service_stop         = "Arr&ecirc;ter";
        $l_service_restart      = "Red&eacute;marrer";
        $l_service_status       = "Status";
        $l_service_status_img_ok= "Démarré";
        $l_service_status_img_ko= "Arrété";
        $l_service_action       = "Actions";
        $l_radiusd              = "Serveur d'authentification et d'autorisation";
        $l_chilli               = "Passerelle d'interception";
        $l_dansguardian         = "Filtre d'URL et de contenu WEB";
        $l_mysqld               = "Serveur de la base des usagers";
        $l_httpd                = "Serveur WEB (Alcasar Control Center)";
        $l_sshd                 = "Accès sécurisée distant";
        $l_freshclam            = "Mise à jour de l'antivirus toutes les 2 heures";
        $l_ntpd                 = "Service de mise à l'heure réseau";
        $l_havp                 = "Proxy Antivirus 1";
        $l_havp2                = "Proxy Antivirus 2";
        $l_dnsmasq              = "Serveur DNS et DHCP";
        $l_dnsmasq_blacklist    = "Serveur DNS pour la Blacklist";
        $l_dnsmasq_whitelist    = "Serveur DNS pour la Whitelist";
        $l_dnsmasq_blackhole    = "Serveur DNS 'trou noir'";
        $l_ulogd_ssh            = "journalisation des accès par SSH";
        $l_ulogd_ext_access     = "journalisation des tentatives d'accès externes";
        $l_ulogd_traceability   = "journalisation des connexions WEB filtrés";
} else {
        $l_services_title       = "Services configuration";
        $l_main_services        = "Main services";
        $l_filter_services      = "Filtering services";
        $l_opt_services         = "Optional services";
        $l_service_title        = "Service name";
        $l_service_start        = "Start";
        $l_service_stop         = "Stop";
        $l_service_restart      = "Restart";
        $l_service_status       = "Status";
        $l_service_status_img_ok= "Running";
        $l_service_status_img_ko= "Stopped";
        $l_service_action       = "Actions";
        $l_radiusd              = "Authentication and authorisation serveur";
        $l_chilli               = "Interception gateway";
        $l_dansguardian         = "URL and WEB content filter";
        $l_mysqld               = "User database server";
        $l_httpd                = "WEB server (ALCASAR Control Center)";
        $l_sshd                 = "Secure remote access";
        $l_freshclam            = "WEB antivirus update (every 2 hours)";
        $l_ntpd                 = "Network time";
        $l_havp                 = "Antivirus Proxy 1";
        $l_havp2                = "Antivirus Proxy 2";
        $l_dnsmasq              = "DNS and DHCP server";
        $l_dnsmasq_blacklist    = "DNS server for the Blacklist";
        $l_dnsmasq_whitelist    = "DNS server for the Whitelist";
        $l_dnsmasq_blackhole    = "DNS server (blackhole)";
        $l_ulogd_ssh            = "SSH access logging process";
        $l_ulogd_ext_access     = "Extern access attempts logging processs";
        $l_ulogd_traceability   = "Filtering WEB access logging process";
}

/****************************************************************
*       CONSTANTES AVEC CHEMINS DES FICHIERS DE CONFIGURATION   *
*****************************************************************/
define ("CONF_FILE", "/usr/local/etc/alcasar.conf");

/********************************************************
*       TEST DU FICHIERS DE CONFIGURATION               *
*********************************************************/
//Test de présence et des droits en lecture des fichiers de configuration.
if (!file_exists(CONF_FILE)){
        exit("Fichier de configuration ".CONF_FILE." non présent");
}
if (!is_readable(CONF_FILE)){
        exit("Vous n'avez pas les droits de lecture sur le fichier ".CONF_FILE);
}

//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);
                if ($service == "sshd"){
                        if ($action == "start"){ 
                                exec("sudo /bin/systemctl enable $service.service");
                                file_put_contents(CONF_FILE, str_replace('SSH=off', 'SSH=on', file_get_contents(CONF_FILE)));
                                exec ("sudo /usr/local/bin/alcasar-iptables.sh");
                                }
                        if ($action == "stop"){
                                exec("sudo /sbin/systemctl disable $service.service");
                                file_put_contents(CONF_FILE, str_replace('SSH=on', 'SSH=off', file_get_contents(CONF_FILE)));
                                exec ("sudo /usr/local/bin/alcasar-iptables.sh");
                                }
                        }
                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){
        $response = false;
        exec("/bin/systemctl is-active $service.service",$retval);
        foreach( $retval as $val ) {
                if ($val == "active"){
                        $response = true;
                        break;
                }
        }
        return $response;
}

//-------------------------------
// Les actions sur un service
//-------------------------------
//sécurité sur les actions à réaliser
$autorizeService = array("radiusd","chilli","dansguardian","mysqld","httpd","sshd","freshclam","ntpd","havp","havp2","dnsmasq","dnsmasq-blacklist","dnsmasq-whitelist","dnsmasq-blackhole");
$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
//-------------------------------
$MainServiceStatus = array();
$MainServiceStatus['radiusd'] = checkServiceStatus("radiusd");
$MainServiceStatus['chilli'] = checkServiceStatus("chilli");
$MainServiceStatus['mysqld'] = checkServiceStatus("mysqld");
$MainServiceStatus['httpd'] = checkServiceStatus("httpd");
$MainServiceStatus['dnsmasq'] = checkServiceStatus("dnsmasq");
$MainServiceStatus['ulogd_ssh'] = checkServiceStatus("ulogd-ssh");
$MainServiceStatus['ulogd_ext_access'] = checkServiceStatus("ulogd-ext-access");
$MainServiceStatus['ulogd_traceability'] = checkServiceStatus("ulogd-traceability");

$FilterServiceStatus = array();
$FilterServiceStatus['dnsmasq_blacklist'] = checkServiceStatus("dnsmasq-blacklist");
$FilterServiceStatus['dnsmasq_whitelist'] = checkServiceStatus("dnsmasq-whitelist");
$FilterServiceStatus['dnsmasq_blackhole'] = checkServiceStatus("dnsmasq-blackhole");
$filterServiceStatus['dansguardian'] = checkServiceStatus("dansguardian");
$FilterServiceStatus['havp'] = checkServiceStatus("havp");
$FilterServiceStatus['havp2'] = checkServiceStatus("havp2");
$FilterServiceStatus['freshclam'] = checkServiceStatus("freshclam");


$OptServiceStatus = array();
$OptServiceStatus['sshd'] = checkServiceStatus("sshd");
$OptServiceStatus['ntpd'] = checkServiceStatus("ntpd");

/****************
*       MAIN    *
*****************/

?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><!-- written by steweb57 / rexy -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?php echo $l_services_title; ?></title>
<link rel="stylesheet" href="/css/style.css" type="text/css">
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr><th><?php echo $l_main_services; ?></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=0>
        <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>
        <TR align="center">
<?php foreach( $MainServiceStatus as $serviceName => $statusOK ) { ?>
<tr>
        <?php if ($statusOK) { ?>
    <td align="center"><img src="/images/state_ok.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ok; ?>"></td>
        <td align="center"><?php $comment="l_$serviceName"; echo "<b>$serviceName</b></td><td>${$comment}" ;?> </td>
    <td width="80" align="center">---</td>
    <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>
    <td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=restart&service=$serviceName\"> $l_service_restart";?></a></td>
        <?php } else { ?>
    <td align="center"><img src="/images/state_error.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ko ?>"></td>
    <td align="center"><?php $comment="l_$serviceName"; echo "<b>$serviceName</b></td><td>${$comment}" ;?> </td>
    <td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=start&service=$serviceName\"> $l_service_start";?></a></td>
    <td width="80" align="center">---</td>
    <td width="80" align="center">---</td>
    <?php } ?>
</tr>
<?php } ?>
</td></tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr><th><?php echo $l_filter_services; ?></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=0>
        <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>
        <TR align="center">
<?php foreach( $FilterServiceStatus as $serviceName => $statusOK ) { ?>
<tr>
        <?php if ($statusOK) { ?>
    <td align="center"><img src="/images/state_ok.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ok; ?>"></td>
        <td align="center"><?php $comment="l_$serviceName"; echo "<b>$serviceName</b></td><td>${$comment}" ;?> </td>
    <td width="80" align="center">---</td>
    <td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=stop&service=$serviceName\"> $l_service_stop";?></a></td>
    <td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=restart&service=$serviceName\"> $l_service_restart";?></a></td>
        <?php } else { ?>
    <td align="center"><img src="/images/state_error.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ko ?>"></td>
    <td align="center"><?php $comment="l_$serviceName"; echo "<b>$serviceName</b></td><td>${$comment}" ;?> </td>
    <td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=start&service=$serviceName\"> $l_service_start";?></a></td>
    <td width="80" align="center">---</td>
    <td width="80" align="center">---</td>
    <?php } ?>
</tr>
<?php } ?>
</td></tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr><th><?php echo $l_opt_services; ?></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=0>
        <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>
        <TR align="center">
<?php foreach( $OptServiceStatus as $serviceName => $statusOK ) { ?>
<tr>
        <?php if ($statusOK) { ?>
    <td align="center"><img src="/images/state_ok.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ok; ?>"></td>
        <td align="center"><?php $comment="l_$serviceName"; echo "<b>$serviceName</b></td><td>${$comment}" ;?> </td>
    <td width="80" align="center">---</td>
    <td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=stop&service=$serviceName\"> $l_service_stop";?></a></td>
    <td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=restart&service=$serviceName\"> $l_service_restart";?></a></td>
        <?php } else { ?>
    <td align="center"><img src="/images/state_error.gif" width="15" height="15" alt="<?php echo $l_service_status_img_ko ?>"></td>
    <td align="center"><?php $comment="l_$serviceName"; echo "<b>$serviceName</b></td><td>${$comment}" ;?> </td>
    <td width="80" align="center"><a href="<?php echo $_SERVER['PHP_SELF']."?action=start&service=$serviceName\"> $l_service_start";?></a></td>
    <td width="80" align="center">---</td>
    <td width="80" align="center">---</td>
    <?php } ?>
</tr>
<?php } ?>
</td></tr>
</table>
</body>
</html>