Web Stats Access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cox3100
    Junior Member
    • Jun 2006
    • 10

    Web Stats Access

    Is there a direct link to access web stats in cPanel so the client does not have to go through cPanel?
  • Elite
    Senior Member
    • Apr 2004
    • 168

    #2
    I think you'll need to install your own version: http://forums.dathorn.com/showthread...hlight=awstats

    Comment

    • Frank Hagan
      Senior Member
      • Mar 2004
      • 724

      #3
      There was a script provided a while back in these forums that I use. I don't remember the original author, but its worked great. You do have to be careful because it allows you to email the stats, and any form that does a "post" like that can be compromised. Maybe someone can edit it so it won't email. Anyway, here it is. You would copy this into a plain text file, name it something like "mystats.php" and then access it by loading "http://www.yourdomain.tld/mystats.php" in your browser.

      Code:
      <?php 
      /* Enter your base url below: 
         eg. if you baseURL is [url]http://www.mydomain.com[/url], the awstats images are located at [url]http://www.mydomain.com/images/awstats[/url] 
      */ 
      $baseURL = 'http://www.mydomain.tld'; 
      
      /**************************************************  * 
      You probably don't need to edit anything below here! 
      **************************************************  */ 
      
      $printBody = 0; 
      if (isset($_POST['submit'])) { 
      // FORM HAS BEEN SUBMITTED 
          $username = $_POST['username'];      // cpanel username 
          $password = $_POST['password'];      // cpanel password 
          $domainName = $_POST['domainName'];     // domain name to get stats for (eg mydomain.com). usually without www. 
          $emailTo = $_POST['emailTo'];         // email address to send stats to 
          $emailFrom = $_POST['emailFrom'];    // email address to send the stats from (eg MyName <me@mydomain.com) 
           
          $hostname = "http://$username:$password@$domainName:2082"; 
          $month = $_POST['month']; 
          $year = $_POST['year']; 
          $monthnames = array("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); 
          $wordMonth = $monthnames[(int) $month]; 
          $emailSubject = "$wordMonth $year Web Site Statistics for $domainName"; 
          if ((@$fp = fopen("$hostname/awstats.pl?month=$month&year=$year&output=main&config=$domainName&lang=en&framename=mainright", 'r'))) { 
              //file opened successfully if we have reached here 
              $i = 1; 
              $body = ""; 
              while (!feof($fp)) { 
                  $chunk = fgets($fp); // Read file line by line 
                   
                  if ($i == 5) { // Add html code to head section 
                      $body .= '<base href="' . $baseURL . '">'; 
                  } 
                  if (($i <= 47) || $i >= 90) { 
                      // Save line contents 
                      $body .= $chunk; 
                  } 
                  $i++; 
              } 
              fclose($fp); 
               
              // Remove all links in the HTML file received: 
              $body = preg_replace("/<a(.*?)a>/i", "", $body); 
               
              //email contents: 
              function sendHTMLMail($to, $subject, $body, $from = '') { 
                $from = trim($from); 
                $rp     = 'ReturnNonWorkingHere@MySite.net'; 
                $org    = 'YourCopmany'; 
                $mailer = 'YourCompany Mailer'; 
                $head  = ''; 
                $head  .= "MIME-Version: 1.0\r\n"; 
                $head  .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
                $head  .= "Date: ". date('r'). " \r\n"; 
                $head  .= "Return-Path: $rp \r\n"; 
                $head  .= "From: $from \r\n"; 
                $head  .= "Sender: $from \r\n"; 
                $head  .= "Reply-To: $from \r\n"; 
                $head  .= "Organization: $org \r\n"; 
                $head  .= "X-Sender: $from \r\n"; 
                $head  .= "X-Priority: 3 \r\n"; 
                $head  .= "X-Mailer: $mailer \r\n"; 
                $body  = str_replace("\r\n", "\n", $body); 
                $body  = str_replace("\n", "\r\n", $body); 
                return mail($to, $subject, $body, $head); 
              } 
              if (isset($_POST['sendEmail'])) sendHTMLMail($emailTo, $emailSubject, $body, $emailFrom); 
              echo ("<hr>Statistics successfully generated for $domainName for $wordMonth $year."); 
              if (isset($_POST['sendEmail'])) echo ("<br>Statistics emailed to $emailTo."); 
              echo ('<hr>'); 
              $printBody = 1; 
          } else { //Error opening file 
              echo ("<font color=\"#FF0000\"><strong>Error opening statistics file. Please check your login details and try again.</strong></font>"); 
              $printBody = 0; 
          } 
      } 
      ?> 
      <form name="stats" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"> 
        <table  border="0" cellpadding="5"> 
          <tr> 
            <td width="150" align="left" valign="top" nowrap><strong>cPanel Username: </strong></td> 
            <td align="left"><input name="username" type="text" id="username" value="<?php if (isset($_POST['submit'])) echo $username; ?>" size="45" maxlength="8">        <font size="1"><br> 
            (The cPanel username of the domain that you wish to generate statistics for) </font></td> 
          </tr> 
          <tr> 
            <td width="150" align="left" valign="top" nowrap><strong>cPanel Password: </strong></td> 
            <td align="left"><input name="password" type="text" id="password" value="<?php if (isset($_POST['submit'])) echo $password; ?>" size="45"> 
              <font size="1"><br> 
            (The cPanel password of the domain that you wish to generate statistics for) </font></td> 
          </tr> 
          <tr> 
            <td width="150" align="left" valign="top" nowrap><strong>Domain Name: </strong></td> 
            <td align="left"><input name="domainName" type="text" id="domainName" value="<?php if (isset($_POST['submit'])) echo $domainName; ?>" size="45"> 
            <font size="1"><br> 
            (Usually excluding [url]www.)[/url] </font></td> 
          </tr> 
          <tr> 
            <td width="150" align="left" valign="top" nowrap><strong>Email To:</strong></td> 
            <td align="left"><input name="emailTo" type="text" id="emailTo" value="<?php if (isset($_POST['submit'])) echo $emailTo; ?>" size="45"> 
              <br> 
            <font size="1">(Email address that the stats will be sent to. Separate multiple addresses with a comma) </font></td> 
          </tr> 
          <tr> 
            <td width="150" align="left" valign="top" nowrap><strong>Email From: </strong></td> 
            <td align="left"><input name="emailFrom" type="text" id="emailFrom" value="<?php if (isset($_POST['submit'])) echo $emailFrom; ?>" size="45"> 
            <font size="1"><br> 
            (eg &nbsp;&nbsp;YourCompany &lt;sales@yourcompany.com&gt; ) </font></td> 
          </tr> 
          <tr> 
            <td width="150" align="left" valign="top" nowrap><strong>Date (Month/Year): </strong></td> 
            <td align="left"><input name="month" type="text" id="month" value="<?php if (isset($_POST['submit'])) echo $month; else echo date('m'); ?>" size="4"> 
      / 
      <input name="year" type="text" id="year" value="<?php if (isset($_POST['submit'])) echo $year; else echo date('Y'); ?>" size="6"> 
      <font size="1"><br> 
      (The month that the statistics should be generated from) </font></td> 
          </tr> 
          <tr> 
            <td width="150" align="left" valign="top"><strong>Send Email?</strong> </td> 
            <td align="left"><input name="sendEmail" type="checkbox" id="sendEmail" value="1"<?php if (isset($_POST['sendEmail'])) echo(' checked'); ?>> 
              <br> 
              <font size="1">(Tick to send the generated statistics to the email to address specified above) </font></td> 
          </tr> 
          <tr align="center"> 
            <td colspan="2"><input name="submit" type="submit" id="submit" value="Generate Statistics"></td> 
          </tr> 
        </table> 
      </form> 
      <?php 
      if ($printBody == 1) { 
          echo '<hr>The generated statistics are shown below:<hr>' . $body; } 
      ?>

      Comment

      Working...