Location: PHPKode > projects > AWStats Access > awstats-access/stats/index.php
<?
/************************************************************************/
/*  AWStats Access 3.0: Provides access to AWStats outside of cPanel    */
/*  ============================================                        */
/*  Created for and by members of TotalChoiceHosting.com                */
/*  Copyright © 2006 by TotalChoiceHosting.com                        */
/*                                                                      */
/*  This file is part of AWStats Access.                                */
/*  AWStats Access 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.                 */
/*                                                                      */
/*  AWStats Access 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 Foobar; if not, write to                                 */
/*  Free Software Foundation, Inc.                                      */
/*  59 Temple Place, Suite 330                                          */
/*  Boston, MA  02111-1307  USA                                         */
/************************************************************************/

require("config.php");

if(!isset($_SERVER["PHP_AUTH_USER"]))
{
    header("WWW-Authenticate: Basic realm=\"Site Statistics\"");
    header("HTTP/1.0 401 Unauthorized");
    echo "Authorization Required.";
    exit;
} 
else if(isset($_SERVER["PHP_AUTH_USER"]))
{
    if(($_SERVER["PHP_AUTH_USER"] != $username) || ($_SERVER["PHP_AUTH_PW"] != $password))
    {
        header("WWW-Authenticate: Basic realm=\"Site Statistics\"");
        header("HTTP/1.0 401 Unauthorized");
        echo "Authorization Required.";
        exit;
    }
    else
    {
        if(isset($Image))
        {
            $Curl = curl_init();

            curl_setopt($Curl, CURLOPT_SSL_VERIFYPEER, 0);
            curl_setopt($Curl, CURLOPT_SSL_VERIFYHOST, 0);
            curl_setopt($Curl, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($Curl, CURLOPT_URL, "https://$site:2083/" . $Image);
            curl_setopt($Curl, CURLOPT_USERPWD, $cpnlusername . ":" . $cpnlpassword);
            curl_setopt($Curl, CURLOPT_RETURNTRANSFER, 1);

            $Output = curl_exec($Curl);

            if(curl_errno($Curl) > 0)
            {
                curl_close($Curl);

                exit;
            }

            curl_close($Curl);
        }
        else
        {
            if(empty($framename))
            {
                $Config = "?config=$site";
            }
            else
            {
                $Config = "?" . $_SERVER["QUERY_STRING"];
            }

            $Curl = curl_init();

            curl_setopt($Curl, CURLOPT_SSL_VERIFYPEER, 0);
            curl_setopt($Curl, CURLOPT_SSL_VERIFYHOST, 0);
            curl_setopt($Curl, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($Curl, CURLOPT_URL, "https://$site:2083/awstats.pl" . $Config);
            curl_setopt($Curl, CURLOPT_USERPWD, $cpnlusername . ":" . $cpnlpassword);
            curl_setopt($Curl, CURLOPT_RETURNTRANSFER, 1);

            $Output = curl_exec($Curl);

            if(curl_errno($Curl) > 0)
            {
                echo curl_error($Curl);
                curl_close($Curl);

                exit;
            }

            curl_close($Curl);

            if(empty($framename) || ($framename == "index"))
            {
                $Output = str_replace("src=\"", "src=\"" . $_SERVER["PHP_SELF"] . "?", $Output);
            }
            else
            {
                $Output = str_replace("src=\"/", "src=\"" . $_SERVER["PHP_SELF"] . "?Image=", $Output);
            }

            $Output = str_replace("<form", "<form method=\"get\"", $Output);
            $Output = str_replace("action=\"", "action=\"" . $_SERVER["PHP_SELF"] . "?", $Output);
            $Output = str_replace("href=\"", "href=\"" . $_SERVER["PHP_SELF"] . "?", $Output);
            $Output = str_replace("href=\"" . $_SERVER["PHP_SELF"] . "?http://", "href=\"http://", $Output);
            $Output = str_replace("awstats.pl?", "", $Output);
        }

        echo $Output;
    }
}
?>
Return current item: AWStats Access