Subversion Repositories ALCASAR

Rev

Rev 356 | Rev 361 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log

<?php
/* written by steweb57 */

# 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_network_title        = "Configuration réseau";
        $l_main_services        = "Services réseau pricipaux";
        $l_opt_services         = "Services réseau optionnels";
        $l_eth0_legend          = "Eth0 (Interface connectée à Internet)";
        $l_eth1_legend          = "Eth1 (Réseau de consultation)";
        $l_internet_legend      = "INTERNET";
        $l_ip_adr               = "Adresse IP";
        $l_ip_mask              = "Masque";
        $l_ip_router            = "Passerelle";
        $l_ip_public            = "Adresse IP public";
        $l_ip_dns1              = "DNS1";
        $l_ip_dns2              = "DNS2";
        $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_action       = "Actions";
        $l_enable               = "actif";
        $l_disable              = "inactif";
        $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 de données usager";
        $l_squid                = "Serveur de cache WEB";
        $l_dnsmasq              = "Serveur DNS et filtre de domaine";
        $l_httpd                = "Serveur WEB (Centre de Gestion d'ALCASAR)";
        $l_havp                 = "Filtre antivirus WEB";
        $l_sshd                 = "Accès sécurisée à distance";
        $l_freshclam            = "Mise à jour de l'antivirus toutes les 2 heures";
        $l_ntpd                 = "Service de mise à l'heure réseau";
} else {
        $l_network_title        = "Network configuration";
        $l_main_services        = "Main network services";
        $l_opt_services         = "Optional network services";
        $l_eth0_legend          = "Eth0 (Internet connected interface)";
        $l_eth1_legend          = "Eth1 (Private network)";
        $l_internet_legend      = "INTERNET";
        $l_ip_adr               = "IP Address";
        $l_ip_mask              = "Mask";
        $l_ip_router            = "Router";
        $l_ip_public            = "Public IP address";
        $l_ip_dns1              = "DNS1 :";
        $l_ip_dns2              = "DNS2";
        $l_service_title        = "Service name";
        $l_service_start        = "Start";
        $l_service_stop         = "Stop";
        $l_service_restart      = "Restart";
        $l_service_status       = "Status";
        $l_service_action       = "Actions";
        $l_enable               = "enable";
        $l_disable              = "disable";
        $l_radiusd              = "Authentication and authorisation serveur";
        $l_chilli               = "Interception gateway";
        $l_dansguardian         = "URL and WEB content filter";
        $l_mysqld               = "User database server";
        $l_squid                = "Proxy Cache WEB";
        $l_dnsmasq              = "DNS and domain name filter";
        $l_httpd                = "WEB server (ALCASAR Control Center)";
        $l_havp                 = "WEB antivirus filter";
        $l_sshd                 = "Secure remote access";
        $l_freshclam            = "WEB antivirus update (every 2 hours)";
        $l_ntpd                 = "Network time";
}

/********************************************************************
*       CONSTANTES AVEC CHEMINS DES FICHIERS DE CONFIGURATION                   *
*********************************************************************/

define ("ALCASAR_CHILLI", "/etc/chilli.conf");
define ("ALCASAR_ETH0", "/etc/sysconfig/network-scripts/default-ifcfg-eth0");
define ("ALCASAR_ETH1", "/etc/sysconfig/network-scripts/ifcfg-eth1");

/********************************************************************
*                               TEST DES FICHIERS DE CONFIGURATION                                      *
*********************************************************************/

//Test de présence et des droits en lecture des fichiers de configuration.
if (!file_exists(ALCASAR_CHILLI)){
        exit("Fichier de configuration ".ALCASAR_CHILLI." non présent");
}
if (!file_exists(ALCASAR_ETH0)){
        exit("Fichier de configuration ".ALCASAR_ETH0." non présent");
}
if (!file_exists(ALCASAR_ETH1)){
        exit("Fichier de configuration ".ALCASAR_ETH1." non présent");
}
if (!is_readable(ALCASAR_ETH0)){
        exit("Vous n'avez pas les droits de lecture sur le fichier ".ALCASAR_ETH0);
}
if (!is_readable(ALCASAR_ETH1)){
        exit("Vous n'avez pas les droits de lecture sur le fichier ".ALCASAR_ETH1);
}

//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","dnsmasq","httpd","havp","sshd","freshclam","ntpd");
$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","pid");
$MainServiceStatus['chilli'] = checkServiceStatus("chilli","pid");
$MainServiceStatus['dansguardian'] = checkServiceStatus("dansguardian","pid");
$MainServiceStatus['mysqld'] = checkServiceStatus("mysqld","OK");
$MainServiceStatus['squid'] = checkServiceStatus("squid","pid");
$MainServiceStatus['dnsmasq'] = checkServiceStatus("dnsmasq","pid");
$MainServiceStatus['httpd'] = checkServiceStatus("httpd","pid");
$MainServiceStatus['havp'] = checkServiceStatus("havp","pid");

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

// Fonction de test de connectivité internet
function internetTest(){
        $host = "74.125.230.83"; #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;
        }
}
/********************************************************************
*                       Lecture du fichier ALCASAR_CHILLI                                               *
*********************************************************************/
$ouvre=fopen(ALCASAR_CHILLI,"r");
if ($ouvre){
        while (!feof ($ouvre))
        {
                $tampon = fgets($ouvre, 4096);
                if (strpos($tampon,"=")!==false){
                        $tmp = explode("=",$tampon);
                        $chilli[$tmp[0]] = $tmp[1];
                }
        }
}else{
        exit("Erreur d'ouverture du fichier ".ALCASAR_CHILLI);
}
fclose($ouvre);

/********************************************************************
*                       Lecture du fichier ALCASAR_ETH0                                                 *
*********************************************************************/
$ouvre=fopen(ALCASAR_ETH0,"r");
if ($ouvre){
        while (!feof ($ouvre))
        {
                $tampon = fgets($ouvre, 4096);
                if (strpos($tampon,"=")!==false){
                        $tmp = explode("=",$tampon);
                        $eth0[$tmp[0]] = $tmp[1];
                }
        }
}else{
        exit("Erreur d'ouverture du fichier ".ALCASAR_ETH0);
}
fclose($ouvre);

/********************************************************************
*                       Lecture du fichier ALCASAR_ETH1                                                 *
*********************************************************************/
$ouvre=fopen(ALCASAR_ETH1,"r");
if ($ouvre){
        while (!feof ($ouvre))
        {
                $tampon = fgets($ouvre, 4096);
                if (strpos($tampon,"=")!==false){
                        $tmp = explode("=",$tampon);
                        $eth1[$tmp[0]] = $tmp[1];
                }
        }
}else{
        exit("Erreur d'ouverture du fichier ".ALCASAR_ETH1);
}
fclose($ouvre);

/************************
*       TO DO           *
*************************/
//modification de la conf réseau, cmd : ifconfig eth0 .....
//synchro de la modification réseau dans les différentes couches d'alcasar
//gestion du dhcp (affichage,modification, ajout @static)

?><!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_network_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_network_title; ?></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">
        <fieldset>
        <legend><?php echo $l_internet_legend;
        if (InternetTest()){
                echo " <img src='/images/state_ok.gif'> $l_enable";
                $IP_PUB = exec ("wget http://checkip.dyndns.org/ -O - -o /dev/null | cut -d: -f 2 | cut -d\< -f 1");}
        else    {
                echo " <img src='/images/state_error.gif'> $l_disable";
                $IP_PUB = "-.-.-.-";}
        ?></legend>
        <table>
                <tr><td><?php echo $l_ip_public." : </td><td>".$IP_PUB;?></td></tr>
                <tr><td><?php echo $l_ip_dns1." : </td><td>".$eth0["DNS1"];?></td></tr>
                <tr><td><?php echo $l_ip_dns2." : </td><td>".$eth0["DNS2"];?></td></tr>
        </table>
        </fieldset>
        </td><td>
        <fieldset>
        <legend><?php echo $l_eth0_legend; ?></legend>
        <table>
                <tr><td><?php echo $l_ip_adr." : </td><td>".$eth0["IPADDR"];?></td></tr>
                <tr><td><?php echo $l_ip_mask." : </td><td>".$eth0["NETMASK"];?></td></tr>
                <tr><td><?php echo $l_ip_router." : </td><td>".$eth0["GATEWAY"];?></td></tr>
        </table>
        </fieldset>
        </td><td>
        <fieldset>
        <legend><?php echo $l_eth1_legend; ?></legend>
        <table>
                <tr><td><?php echo $l_ip_adr." : </td><td>".$eth1["IPADDR"];?></td></tr>
                <tr><td><?php echo $l_ip_mask." : </td><td>".$eth1["NETMASK"];?></td></tr>
        </table>
        </fieldset>
        </td></tr>
</table>
<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"><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>