Problem: You need to read webalizer output on a daily basis securely.
Answer:In order to read webalizer from inside drupal safely and securely do the following. This assumes that you have unix/linux level access to your host server.

1. Create a folder named “usage” (without quotes) under root folder of your site. It will be a folder /path/to/drupal/sites/YourSite.com/usage.
2. Copy default webalizer.conf to this folder from /etc/webalizer and configure it properly to use YourSite’s access log. Read Webalizer documentation to know more about configuration.
3. Go the /path/to/drupal/sites/YourSite.com/usage folder and run webalizer command without any arguments. This will process YourSite’s access log and create the output file including an index.html.
4. Make sure you can look at the webalizer output from outside by going to www.YourSite.com/usage . If you get “Access Denied” error then you may have to make changes to .htaccess file to allow access to this folder. Once you are able see webalizer output, undo your changes or make changes to disable access to the usage folder via .htaccess. This is very important to ensure no one can look at the usage folder from outside using www.YourSite.com/usage.
5. Log into YourSite.com and Add a role “Administrator” using Administer/User Management/Roles
6. Create a menu “Admin Pages” using Administer/Menu/Add.
7. Make the menu visible to “Administrator” only using Administer/Blocks/Configure
8. Add a node using php input type. Add the following code in the page and save. Do not “Publish” this page. This will ensure only you as Administrator has access to this page.
####################################################

 </p>
<p>$script_url = "/node/NodeNumber?file=";<br />
$usage_folder = "sites/Yoursite.com/usage/";<br />
$index_file_name = "index.html";<br />
$index_url = '&lt; href="'.$script_url.$usage_folder.$index_file_name.'"&gt; YourSite Usage Statistics</a>';</p>
<p>print $index_url;</p>
<p>$file = $_GET['file']; </p>

<p>if ($file) {<br />
$file_handle = fopen($file, "r");<br />
while (!feof($file_handle)) {<br />
$line_of_text = fgets($file_handle);</p>
<p>$search = "/usage(.*)html/";<br />
$replace_with = "usage$1html";</p>
<p>$replace= $script_url.$usage_folder.$replace_with;</p>
<p>$line_of_text2 = preg_replace ($search, $replace, $line_of_text );<br />
print $line_of_text2 ;<br />

}</p>
<p>fclose($file_handle);<br />
}<br />

####################################################
9. Note down the node number from the url. If you have pathauto enabled then note down the nodepath name.
10. Edit the node again and replace “NodeNumber” with node number or node name of the page.
11. Replace “YourSite” with domain name of your site.
12. Save the page. Notice a url linking to webalizer index.html.

Click on it and you will see webalizer output.
13. Add this page to you newly added "Admin Pages" menu. Configure the menu to be shown on right or left block.

Read more on www.toolerp.com.

Comments

nick_wayne’s picture

I would like to create a module for this sometime if I get time. Let me know if someone would like to collaborate.
Nick.
TooLERP - Best Small Business ERP Accounting Software

nick_wayne’s picture

There is a typo in the above code. The correct code for link is :

$index_url = '<a href="'.$script_url.$usage_folder.$index_file_name.'"> YourSite Usage </a>'

TooLERP - Best Small Business ERP Accounting Software

munroe_richard’s picture

For D5 at the moment. I have it ticking over (generating configuration files and processing logs) and should be [more or less] done in the next couple of weeks depending on my load at work (of which this is actually a part).

Best,

Dick Munroe

munroe_richard’s picture

You can find more details here: http://drupal.org/project/webalizer_integration

Support for D5 and D6 is provided.

Best,

Dick Munroe