The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Awstats reports via email

Discussion in 'E-mail Discussions' started by oldlock, Jun 5, 2013.

  1. oldlock

    oldlock Well-Known Member

    Joined:
    Sep 19, 2008
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    6
    I have a client that would like to view his awstats info. However the user is a little, well 'clueless' and is as likely as not to delete his entire site if given access to his cpanel.

    So - is there any way to get the awstats reports emailed on a regular basis ?
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,762
    Likes Received:
    662
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
  3. oldlock

    oldlock Well-Known Member

    Joined:
    Sep 19, 2008
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    6
    Seems a fair bit of discussion in those threads but no solutions. I've seen some threads on other sites regarding custom scripts but am naturally reluctant to use such scripts without knowing what else they might do !
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,762
    Likes Received:
    662
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    The only manual workarounds I have seen have been in regards to viewing the interface without cPanel access, as opposed to emailing data from Awstats to specific users. There are links to these workarounds in the thread mentioned in my last response. You may want to add your feedback and vote for that feature request to encourage it's implementation so a supported solution is available.

    Thank you.
     
  5. rclocher3

    rclocher3 Registered

    Joined:
    Jan 14, 2014
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    I have two websites on an inexpensive shared hosting account with cPanel, a personal site and a business site. I probably will go with Google Analytics for the business site, but that's too intrusive for my personal site, which is just for hosting articles I wrote. Awstats is exactly what I need for the personal site. However, I'm so busy that I rarely remember to periodically check my awstats for the personal site. If I could have a report emailed to me every two weeks, that would be ideal. Just being able to see the report without logging in is only half the solution; I'd also want the report pushed to me periodically.

    If the link to the awstats page were static then I could probably whip up a simple script to generate and email such a report myself, but the URL seems to include a session ID in the middle, which makes that idea sound much too complicated to be worthwhile. I imagine the dynamic link is a security precaution.
     
  6. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,762
    Likes Received:
    662
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
  7. HostedPro

    HostedPro Member

    Joined:
    Sep 8, 2006
    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    East Texas
    cPanel Access Level:
    Root Administrator
    Hi Folks, just bumping this old thread...

    I've been using a script for this for years. I keep the script in the root so it's not publicly accesible and I copy all the aw images to the public images dir. Just changes the variables & run it through cron. Here's the script.

    Code:
    <?
    include('Mail.php');
    include('Mail/mime.php');
    
    // Setup some variables
    $cpusername = 'accountname';                         //Your cPanel user name
    $cppassword = 'accountpassword';                     // Your cPanel password
    $domainName = 'mydomain.com';                 // Your domain name (no 'www')
    $sender = 'user@mydomain.com';                  // Your email address
    $recipient = 'Whatever <user@mydomain.com>';         // The Recipients name and email address
    $baseURL = 'http://www.mydomain.com';          // Your base URL
    $smtphost = 'mail.mydomain.com';               // Your outbound (SMTP) mail server (MTA)
    $smtpport = '25';                             // Your SMTP post (usually 25, could be different)
    $smtpauth = true;                             // This should always be set to true
    $smtpuname = 'userl@mydomain.com';                // Your SMTP username
    $smtppass = 'smtpuserpassword';                       // Your SMTP password
    
    // Don't edit anything in the following function
    Function get_stats()
    	{
    	global $cpusername, $cppassword, $domainName, $baseURL;
    
    	//$printOutput = 0;     // set to 0 if you do not want the script to output anything (eg for use with a cron job)
    
    	/*     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.hostedpro.com';
    
    
    	/*****************************************
    	You probably don't have to edit below here
    	*****************************************/
    
    	$hostname = "http://$cpusername:$cppassword@$domainName:2082";
    	$day = date('j');
    	$month = date('F');
    	$year = date('Y');
    	$subject = "$month $day, $year Web Site Statistics for $domainName";
    	$month = date('m')-0;
    		if (!(@$fp = fopen("$hostname/awstats.pl?config=$domainName&lang=en&framename=mainright&update=1", 'r'))) {
        		if ($printOutput == 1) die("<strong>Error opening statistics file.</strong>");
        			else exit();
    		}
    
    	//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);
    
    	return $body;
    }
    // End function
    			  
    // Constructing the email
    // Building the subject line
    $day = date('j');
    $month = date('F');
    $year = date('Y');
    $subject = "$month $day, $year Web Site Statistics for $domainName";	// Subject for the email
    $html = get_stats();      // Grabs the AWS data from the function for the body
    $crlf = "\n";
    $headers = array(
    	'From'          => $sender,
    	'Return-Path'   => $sender,
    	'To'			=> $recipient,
    	'Subject'       => $subject
    	);
    
    // Creating the Mime message
    $mime = new Mail_mime($crlf);
    
    // Setting the body of the email
    $mime->setHTMLBody($html);
    
    // Set body and headers ready for base mail class
    $body = $mime->get();
    $headers = $mime->headers($headers);
    
    // SMTP authentication params
    $smtp_params["host"]     = $smtphost;
    $smtp_params["port"]     = $smtpport;
    $smtp_params["auth"]     = $smtpauth;
    $smtp_params["username"] = $smtpuname;
    $smtp_params["password"] = $smtppass;
    
    // Sending the email using smtp
    $mail =& Mail::factory("smtp", $smtp_params);
    $result = $mail->send($recipient, $headers, $body);
    	if($result == 1)
    		{
    		echo("Your message has been sent!");
    		}
    	else
    		{
    		echo("Your message was not sent: " . $result);
    		}
    ?>
    


    I forget know where I found the original code or I'd give credit, it was many years ago.

    You do have to install the Mail & Mail_Mime PEAR packages but that's easy enough though WHM. The AW images need to me copied from the 3rdparty dir (or download new) & setup with proper ownership & permissions.

    My problem right now is that I setup a new cloud server for a client that was growing out of shared hosting and I can't get the page to send. I can see the php fire in a cron report but no love on the report. It seems to fail silently.

    Hope this helps someone and I hope it's not a huge security risk, I've never had a hack on it.

    Any ideas on why it's not working on the cloud server, please let me know. IT's working on other servers I have it on and I can't seem to find differences in configurations between them.

    Thanks
    Karl
     
Loading...

Share This Page