Subversion Repositories ALCASAR

Rev

Rev 2521 | Go to most recent revision | Blame | Last modification | View Log

<?php
/***************************************************************************
 *   Copyright (C) 2006 by phpSysInfo - A PHP System Information Script    *
 *   http://phpsysinfo.sourceforge.net/                                    *
 *   addons by 3abtux & Rexy for ALCASAR                                   *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

// $Id: portail.php 2607 2018-08-20 00:16:04Z tom.houdayer $

// xml_utilisateur()

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;
 }

function xml_portail () {
        global $sysinfo;

        $_text = "  <Portail>\n"
//              . "    <Utilisateur>" . htmlspecialchars( request('user'), ENT_QUOTES ) . "</Utilisateur>\n"
                . "    <Utilisateur>" . "</Utilisateur>\n"
                . "    <Groupe>" . "</Groupe>\n";
//              . "    <Groupe>" . htmlspecialchars( trim( request('group') ), ENT_QUOTES ) . "</Groupe>\n";
        $_text .= "  </Portail>\n";

        return $_text;
}
// Fonction de test de connectivité internet
function internetTest() {
        $host  = 'www.google.com';
        $host2 = 'www.alcasar.net';
        $port = 80;

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

        $sock = fsockopen($host2, $port, $errno, $errstr, 2);
        if (!$sock) {
                return false;
        }
        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;
}
// html_portail()
function html_portail () {
        global $webpath;
        global $XPath;
        global $text;

        // 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'));
        $nbr_user = request ('user');
        $nbr_grp  = request ('group');
        $nbr_user_online = 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'>".$text['enable'];
                $version = dns_get_record("version.alcasar.net",DNS_TXT);
                $AVAILABLEDVERSION = $version[0]['txt'];
        } else {
                $internet_status =  "<img src='/images/state_error.gif'>".$text['disable'];
                $AVAILABLEDVERSION = "-";
        }
        $_text = "<table border=\"0\" width=\"100%\" align=\"center\">\n"
                . "  <tr>\n"
                . "    <td valign=\"top\"><font size=\"-1\">" . $text['internet_link'] . "</font></td>\n"
                . "    <td><font size=\"-1\">" . $internet_status . "</font></td>\n"
                . "  </tr>\n"
                . "  <tr>\n"
                . "    <td valign=\"top\"><font size=\"-1\">" . $text['portail-version'] . "</font></td>\n"
                . "    <td><font size=\"-1\">" . $INSTALLEDVERSION . "</font></td>\n"
                . "  </tr>\n"
                . "  <tr>\n"
                . "    <td valign=\"top\"><font size=\"-1\">" . $text['portail-disp'] . "</font></td>\n"
                . "    <td><font size=\"-1\">" . $AVAILABLEDVERSION . "</font></td>\n"
                . "  </tr>\n"
                . "  <tr>\n"
                . "    <td valign=\"top\"><font size=\"-1\">" . $text['utilisateur'] . "</font></td>\n"
                . "    <td><font size=\"-1\">" . $nbr_user_online . " / " . $nbr_user . "</font></td>\n"
                . "  </tr>\n"
                . "  <tr>\n"
                . "    <td valign=\"top\"><font size=\"-1\">" . $text['groupe'] . "</font></td>\n"
                . "    <td><font size=\"-1\">" . $nbr_grp . "</font></td>\n"
                . "  </tr>\n"
                . "  <tr>\n"
                . "    <td valign=\"top\"><font size=\"-1\">" . $text['bl-version'] . "</font></td>\n"
                . "    <td><font size=\"-1\">" . $VERSIONBL . "</font></td>\n"
                . "  </tr>\n"
                . "</table>\n";
        return $_text;
}

function wml_portail () {
        global $XPath;
        global $text;

        $_text = "<card id=\"vitals\" title=\"" . $text['vitals']  . "\">\n"
                . "<p>" . $text['hostname'] . ":<br/>\n"
                . "-&nbsp;" . $XPath->getData( "/phpsysinfo/Vitals/Hostname" ) . "</p>\n"
                . "<p>" . $text['ip'] . ":<br/>\n"
                . "-&nbsp;" . $XPath->getData( "/phpsysinfo/Vitals/IPAddr" ) . "</p>\n"
                . "<p>" . $text['kversion'] . ":<br/>\n"
                . "-&nbsp;" . $XPath->getData( "/phpsysinfo/Vitals/Kernel" ) . "</p>\n"
                . "<p>" . $text['uptime'] . ":<br/>\n"
                . "-&nbsp;" . uptime( $XPath->getData( "/phpsysinfo/Vitals/Uptime" ) ) . "</p>\n"
                . "<p>" . $text['users'] . ":<br/>"
                . "-&nbsp;" . $XPath->getData( "/phpsysinfo/Vitals/Users" ) . "</p>\n"
                . "<p>" . $text['loadavg'] . ":<br/>"
                . "-&nbsp;" . $XPath->getData( "/phpsysinfo/Vitals/LoadAvg" ) . "</p>\n"
                . "</card>\n";

        return $_text;
}
?>