Apache Status - Accesses

Started by ejsolutions, February 15, 2020, 02:10:42 PM

Previous topic - Next topic

Apache Staus - Access

Useful: should be added to main menus
2 (50%)
Nope: will never use it
1 (25%)
Where's the Tylenol?
1 (25%)
None of the above
0 (0%)

Total Members Voted: 4

Voting closed: April 15, 2020, 02:12:36 PM

ejsolutions

Following my feature request, I have now integrated it in CWP, so for the benefit of others..

1. Create /usr/local/cwpsrv/htdocs/resources/admin/modules/apache_status.php with the following contents (I use vi but you may prefer nano or File Manager)
<?php
$apache_status 
= shell_exec("/usr/local/apache/bin/apachectl fullstatus | grep \"GET\" | grep -v \"server-status\" | sed 's/[[:space:]]*$//' | cut -d\" \" -f\"5,14-\" " );
echo 
"<h3>Apache Status - Accesses</h3>";
echo 
"<pre>".$apache_status."</pre>";
?>




2. Append (add to the end) the following to /usr/local/cwpsrv/htdocs/resources/admin/include/3rdparty.php
<li><a href="index.php?module=apache_status"><span class="icon16 icomoon-icon-arrow-right-3"></span>Apache Status - Accesses</a></li>


3. Refresh your CWP admin screen.

ejsolutions

#1
Updated module, with column headers and improved the output.
I'm sure developers could do a neater job of this.  ???

<?php
// Apache Status - Accesses v0.3
$apache_status = shell_exec("/usr/local/apache/bin/apachectl fullstatus | grep \"GET\" | grep -v \"127.0.0.1\" | sed 's/[[:space:]]*$//' | cut -d\" \" -f\"5,14-\" | sort -r -k1" );
echo 
"<h3>Apache Status - Accesses</h3>";
echo 
"<p>&nbsp;CPU&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Child&nbsp;&nbsp;&nbsp;&nbsp;Slot";
echo 
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IP&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
echo 
"Domain&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Request</p>";                     
echo 
"<pre>".$apache_status."</pre>";
echo 
"<p>";
echo 
"CPU   CPU usage, number of seconds<br>";
echo 
"Child Megabytes transferred this child<br>";
echo 
"Slot  Total megabytes transferred this slot<br>";
echo 
"</p>";
?>




Typical application: periodically monitor activity and spot the rogue crawlers/hackers IP addresses. Then use CSF to block 'em, or complete subnets/Countries. Use an IP checker and make sure you don't block customers and/or the (more) useful search engines.

rcschaff

#2
To Add under webservers instead of Developer Options
/usr/local/cwpsrv/htdocs/resources/admin/include/3rdparty.php
<script type="text/javascript">
        $(document).ready(function() {
                var newButtons = ''
                +' <li>'
                +' <a href="?module=apache_status"><span aria-hidden="true" class="icon16 icomoon-icon-switch"></span>Apache Status - Accesses</span></a>'
                +'</li>';
                $("ul#mn-3-sub").prepend(newButtons);
        });
</script>
Google Hangouts:  rcschaff82@gmail.com

ejsolutions


ejsolutions

Warning: it looks as though posting this is against the rules!

Sandeep

its not against rule developing module/themes are not prohibited, you can't modify CWP scripts and packages which comes with it, package configs can be modified.

PiotrE

tried this but et 404 files not found
issuing command
#/usr/local/apache/bin/apachectl fullstatus
give me 404 ngnix error

I configure webserver with ngnix/varnish/apache

leisegang

This would be better and show more info:


<?php
// Apache Status - Accesses v0.4

$url = "http://localhost/server-status";
$ch_session = curl_init();
curl_setopt($ch_session, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch_session, CURLOPT_URL, $url);
$result_url = curl_exec($ch_session);
echo 
$result_url;

?>

cyberspace

In case the server is configured to use the webserver config like: Nginx+Apache, Nginx+Varnish+Apache then the script must be changed to:

<?php
// Apache Status - Accesses v0.4

$url = "http://localhost:8181/server-status";
$ch_session = curl_init();
curl_setopt($ch_session, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch_session, CURLOPT_URL, $url);
$result_url = curl_exec($ch_session);
echo 
$result_url;

?>


Additionally, to see the reals IPs of the visitors the module mod_rpaf should be replaced with the module mod_remoteip in the main apache config and configured accordingly. In other case the main IP address of the server will be shown as the visitor's IP.

diogo-plta

I have enabled the mod_remoteip, only uncommented the  line "LoadModule remoteip_module modules/mod_remoteip.so" on httpd.conf

but how to configure it to show the real remote ip? the /apache-status is only showing the local server ip

cyberspace

Put the following content into the file:

/usr/local/apache/conf.d/remoteip.conf

RemoteIPHeader X-Forwarded-For
RemoteIPProxiesHeader CF-Connecting-IP
RemoteIPInternalProxy 127.0.0.1 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 XXX.XXX.XXX.XXX

RemoteIPTrustedProxy 173.245.48.0/20
RemoteIPTrustedProxy 103.21.244.0/22
RemoteIPTrustedProxy 103.22.200.0/22
RemoteIPTrustedProxy 103.31.4.0/22
RemoteIPTrustedProxy 141.101.64.0/18
RemoteIPTrustedProxy 108.162.192.0/18
RemoteIPTrustedProxy 190.93.240.0/20
RemoteIPTrustedProxy 188.114.96.0/20
RemoteIPTrustedProxy 197.234.240.0/22
RemoteIPTrustedProxy 198.41.128.0/17
RemoteIPTrustedProxy 162.158.0.0/15
RemoteIPTrustedProxy 104.16.0.0/13
RemoteIPTrustedProxy 104.24.0.0/14
RemoteIPTrustedProxy 172.64.0.0/13
RemoteIPTrustedProxy 131.0.72.0/22


Replace XXX.XXX.XXX.XXX with the main IP address of your server/VPS.

Please note it will show the real IP addresses of the visitors if some site is configured to be proxied via CloudFlare.

diogo-plta

As I don't use CloudFlare:


RemoteIPHeader X-Forwarded-For
RemoteIPInternalProxy xxx.xxx.xxx.xxx


and worked!

thank you @cyberspace