2025-08-29 23:14:10 +03:00
< ? php
use dokuwiki\Extension\AdminPlugin ;
/**
2025-09-01 16:25:25 +02:00
* Bot Monitoring Plugin
2025-08-29 23:14:10 +03:00
*
* @ license GPL 2 ( http :// www . gnu . org / licenses / gpl . html )
* @ author Sascha Leib < ad @ hominem . info >
*/
/**
* All DokuWiki plugins to extend the admin function
* need to inherit from this class
**/
2025-09-01 16:25:25 +02:00
class admin_plugin_botmon extends AdminPlugin {
2025-08-29 23:14:10 +03:00
/**
* Return the path to the icon being displayed in the main admin menu .
*
* @ return string full path to the icon file
**/
public function getMenuIcon () {
$plugin = $this -> getPluginName ();
return DOKU_PLUGIN . $plugin . '/img/admin.svg' ;
}
/**
* output appropriate html
*/
public function html () {
2025-09-01 18:55:56 +02:00
global $conf ;
2025-09-12 15:38:28 +02:00
// spinner animation as SVG image:
$svg = '<svg width="12" height="12" viewBox="0 0 50 50" xmlns="http://www.w3.org/2000/svg" id="botmon__today__busy"><defs><linearGradient id="gradient" x1="0%" y1="0%" x2="100%" y2="100%"><stop offset="0%" stop-color="#666"></stop><stop offset="100%" stop-color="#666"></stop></linearGradient></defs><circle cx="25" cy="25" r="20" fill="none" stroke="url(#gradient)" stroke-width="8" stroke-dasharray="31.4 31.4"><animateTransform attributeName="transform" type="rotate" from="0 25 25" to="360 25 25" dur="1s" repeatCount="indefinite"></animateTransform></circle></svg>' ;
2025-09-01 18:55:56 +02:00
$pluginPath = $conf [ 'basedir' ] . 'lib/plugins/' . $this -> getPluginName ();
2025-08-29 23:14:10 +03:00
/* Plugin Headline */
2025-09-10 00:02:42 +02:00
echo ' < div id = " botmon__admin " >
< h1 > Bot Monitoring Plugin </ h1 >
< nav id = " botmon__tabs " >
< ul class = " tabs " role = " tablist " >
< li role = " presentation " class = " active " >< a role = " tab " href = " #botmon__panel1 " aria - controls = " botmon__panel1 " id = " botmon__tab1 " aria - selected = " true " > Today </ a ></ li >
</ ul >
</ nav > ' ;
2025-08-29 23:14:10 +03:00
2025-09-10 00:02:42 +02:00
if ( $this -> hasOldLogFiles ()) {
2025-09-12 15:38:28 +02:00
echo '<div class="info"><strong>Note:</strong> There are old log files that can be deleted. <a href="' . $pluginPath . '/cleanup.php" target="_blank">Click here</a> to run a delete script, or use <em>cron</em> to automatically delete them.</div>' ;
2025-09-10 00:02:42 +02:00
}
echo ' < article role = " tabpanel " id = " botmon__today " " >
< h2 class = " a11y " > Today </ h2 >
< header id = " botmon__today__title " > Loading & nbsp ; & hellip ; </ header >
< div id = " botmon__today__content " >
< details id = " botmon__today__overview " open >
2025-09-10 14:44:08 +02:00
< summary > Bot overview ( page views ) </ summary >
< div class = " botmon_overview_grid " >
2025-09-10 00:02:42 +02:00
< dl id = " botmon__today__botsvshumans " ></ dl >
< dl id = " botmon__botslist " ></ dl >
2025-09-10 14:44:08 +02:00
< dl id = " botmon__today__countries " ></ dl >
2025-09-10 00:02:42 +02:00
</ div >
</ details >
< details id = " botmon__today__webmetrics " >
< summary > Web metrics </ summary >
2025-09-10 14:44:08 +02:00
< div class = " botmon_overview_grid " >
2025-09-10 00:02:42 +02:00
< dl id = " botmon__today__wm_overview " ></ dl >
2025-09-10 23:07:51 +02:00
< dl id = " botmon__today__wm_clients " ></ dl >
< dl id = " botmon__today__wm_platforms " ></ dl >
2025-09-10 00:02:42 +02:00
</ div >
</ details >
< details id = " botmon__today__visitors " >
< summary > Visitor logs </ summary >
< div id = " botmon__today__visitorlists " ></ div >
</ details >
</ div >
< footer aria - live = " polite " >
2025-09-12 15:38:28 +02:00
< span > ' . $svg . ' </ span >
2025-09-10 00:02:42 +02:00
< span id = " botmon__today__status " > Initialising & nbsp ; & hellip ; </ span >
</ footer >
</ article >
</ div ><!-- End of BotMon Admin Tool --> ' ;
2025-08-29 23:14:10 +03:00
2025-09-10 00:02:42 +02:00
}
/**
* Check if there are old log files that can be deleted .
*
* @ return bool true if there are old log files , false otherwise
*/
private function hasOldLogFiles () {
$today = gmdate ( 'Y-m-d' );
$yesterday = gmdate ( 'Y-m-d' , time () - 86400 );
2025-09-01 18:55:56 +02:00
2025-09-10 00:02:42 +02:00
// scan the log directory and delete all files except for today and yesterday:
$dir = scandir ( getcwd () . '/lib/plugins/botmon/logs' );
foreach ( $dir as $file ) {
$fName = pathinfo ( $file , PATHINFO_BASENAME );
$bName = strtok ( $fName , '.' );
2025-08-29 23:14:10 +03:00
2025-09-10 00:02:42 +02:00
if ( $bName == '' || $bName == 'logfiles' ) {
// ignore
} else if ( $bName == $today || $bName == $yesterday ) {
// skip
} else {
return true ;
}
}
return false ;
2025-08-29 23:14:10 +03:00
}
}