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 ;
$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 ()) {
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>' ;
}
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 >
< dl id = " botmon__today__botips " ></ 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 >
< dl ></ dl >
< dl ></ dl >
2025-09-10 14:44:08 +02:00
< dl ></ 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 " >
< img src = " ' . $pluginPath . '/img/spinner.svg " id = " botmon__today__busy " width = " 12 " height = " 12 " alt = " busy indicator " >
< 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
}
}