Subversion Repositories ALCASAR

Rev

Rev 2817 | Rev 2853 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log

<?php
# Welcome page (sysinfo)
# by Rexy
// request database
function request ($texte) {
                $strResult = 0;
                // Déclaration des paramètres de connexion
                $host = "localhost";
                $DB_USER = "radius";
                $DB_RADIUS = "radius";
                $radiuspwd = "";
                // Connexion au serveur
                $mysqli = new mysqli($host, $DB_USER, $radiuspwd, $DB_RADIUS);
                if ($texte == 'user') {$query = "SELECT UserName FROM userinfo";}
                else { $query = "SELECT GroupName FROM radusergroup GROUP BY GroupName";}
                $result = $mysqli->query($query);
                // Recuperation des resultats
                $strResult = $result->num_rows;
                // Deconnexion de la base de donnees
                $mysqli->close();
                return $strResult;
 }

// Internet test
function internetTest() {
        $host  = 'www.google.com';
        $host2 = 'www.alcasar.net';
        $port = 80;

        $sock = @fsockopen($host, $port, $errno, $errstr, 2);
        if ($sock) {
                fclose($sock);
                return true;
        }

        $sock = @fsockopen($host2, $port, $errno, $errstr, 2);
        if ($sock) {
                fclose($sock);
                return true;
        }

        return false;
}

// filtering test
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;
}

$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_title = "Bienvenue dans l'ACC (ALCASAR Control Center)";
        $l_internet_link = "Connexion Internet";
        $l_enable = "Active";
        $l_disable = "Désactivée";
        $l_version = "Version instalée";
        $l_available = "Version disponible";
        $l_users = "Nombre d'utilisateurs / connectés";
        $l_groups = "Nombre de groupes";
        $l_bl_version = "Date de la blacklist";
}
else {
        $l_title = "Welcome in ACC (ALCASAR Control Center)";
        $l_internet_link = "Internet connection";
        $l_enable = "Enabled";
        $l_disable = "Disabled";
        $l_version = "Installed version";
        $l_available = "Available version";
        $l_users = "Number of users / connected.";
        $l_groups = "Number of groups";
        $l_bl_version = "Blacklist date";
}
?>
<!DOCTYPE html>
<html>
<head>
        <link rel="stylesheet" href="/css/acc.css">
</head>
<body>  
        <div class="panel">
                <div class="panel-header"><?= $l_title ?></div>
                <div class ="panel-row">
                        <div class="panel-cell">
<?
// Read CONF_FILE
define ('CONF_FILE', '/usr/local/etc/alcasar.conf');
$file_conf = fopen(CONF_FILE, 'r');
if (!$file_conf) {
        exit('Error opening the file '.CONF_FILE);}
while (!feof($file_conf)) {
        $buffer = fgets($file_conf, 4096);
        if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
                $tmp = explode('=', $buffer, 2);
                $conf[trim($tmp[0])] = trim($tmp[1]);
        }
}
fclose($file_conf);
// Get current version
$INSTALLEDVERSION = $conf['VERSION'];
$VERSIONBL = date ("F d Y", filemtime ('/etc/e2guardian/lists/blacklists/README'));
$nb_users = request ('user');
$nb_groups  = request ('group');
$nb_online_users = exec ("sudo /usr/sbin/chilli_query list | cut -d\" \" -f5 | grep \"1\" | wc -l");
if ((filtrageTest("/var/www/html/index.php","/network_pb = false/")) && (internetTest())) {
        $internet_status =  "<img src='/images/state_ok.gif'>".$l_enable;
        $version = dns_get_record("version.alcasar.net",DNS_TXT);
        $AVAILABLEDVERSION = $version[0]['txt'];
} else {
        $internet_status =  "<img src='/images/state_error.gif'>".$l_disable;
        $AVAILABLEDVERSION = "-";
}
echo $l_internet_link." : ".$internet_status."<br>\n";
echo $l_version."       : ".$INSTALLEDVERSION."<br>\n";
echo $l_available."     : ".$AVAILABLEDVERSION."<br>\n";
echo "</div><div class=\"panel-cell\">";
echo $l_users."         : ".$nb_users." / ".$nb_online_users."<br>\n";
echo $l_groups."        : ".$nb_groups."<br>\n";
echo $l_bl_version."    : ".$VERSIONBL."<br>\n";
?>
                        </div>
                </div>
        </div>
        <div class="panel">
                <iframe class="panel-iframe" src="phpsysinfo/">
                </iframe>
        </div>
</body>
</html>