Subversion Repositories ALCASAR

Rev

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 529 2011-04-05 18:28:37Z franck $

// xml_utilisateur()

function request ($texte) {
                $strResult = 0;
                // Déclaration des paramètres de connexion
                $host = "localhost";
                $DB_USER = "radius";
                $DB_RADIUS = "radius";
                $radiuspwd = "X01WDItQ";
                // Connexion au serveur
                mysql_connect($host, $DB_USER,$radiuspwd) or die("erreur de connexion au serveur");
                mysql_select_db($DB_RADIUS) or die("erreur de connexion a la base de donnees");
                // Creation et envoi de la requete
                if ($texte == 'user') {$query = "SELECT UserName FROM userinfo";}
                else { $query = "SELECT GroupName FROM radusergroup GROUP BY GroupName";}
                $result = mysql_query($query);
                // Recuperation des resultats
                $strResult = mysql_num_rows($result);
                // Deconnexion de la base de donnees
                 mysql_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.alcasar.info";
        $host2 = "74.125.230.83";  #www.google.fr
        $port = "80";
        //var $num;     //non utilisé
        //var $error;   //non utilisé

        if (! $sock = @fsockopen($host, $port, $num, $error, 2)) {
                if (! $sock = @fsockopen($host2, $port, $num, $error, 3)) {
                        return false;
                } else {
                        fclose($sock);
                        return true;
                }
        } else {
                fputs($sock,"GET http://$host/images/M_images/weblink.png HTTP/1.0\n\n");
                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;

        $file_version = "/var/www/html/VERSION";
        $handle = fopen ($file_version, "r");
        $INSTALLEDVERSION = fread ($handle, filesize ($file_version));
        fclose ($handle);
        $file_bl = "/var/www/html/VERSION-BL";
        $handle = fopen ($file_bl, "r");
        $VERSIONBL = fread ($handle, filesize ($file_bl));
        fclose ($handle);
        $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("/usr/local/bin/alcasar-iptables.sh", "/^FILTERING=\"yes\"/")){
                $network_filter_status = $text['enable'];}
        else {  $network_filter_status = $text['disable'];}
        if (filtrageTest("/etc/dansguardian/dansguardian.conf","/^reportinglevel = 3/")){
                $web_filter_status = $text['enable'];}
        else {  $web_filter_status = $text['disable'];}
        if (filtrageTest("/etc/dansguardian/dansguardian.conf","/^proxyport = 8090/")){
                $web_antivir_status = $text['enable'];}
        else {  $web_antivir_status = $text['disable'];}
        if (InternetTest()){
                $internet_status =  "<img src='/images/state_ok.gif'>".$text['enable'];
                $version = dns_get_record("version.alcasar.info",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['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['net_filter'] . "</font></td>\n"
                . "    <td><font size=\"-1\">" . $network_filter_status . "</font></td>\n"
                . "  </tr>\n"
                . "  <tr>\n"
                . "    <td valign=\"top\"><font size=\"-1\">" . $text['web_filter'] . "</font></td>\n"
                . "    <td><font size=\"-1\">antivirus : " . $web_antivir_status . ", domain/url : " . $web_filter_status . "</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"
                . "  <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"
                . "</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;
}
?>