*/
/**
* All DokuWiki plugins to extend the admin function
* need to inherit from this class
**/
class admin_plugin_botmon extends AdminPlugin {
/**
* 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() {
global $conf;
// display GeoIP data?
$geoIPconf = $this->getConf('geoiplib');
$hasOldLogFiles = $this->hasOldLogFiles();
// spinner animation as SVG image:
$svg = '';
$pluginPath = $conf['basedir'] . 'lib/plugins/' . $this->getPluginName();
/* Plugin Headline */
echo '
Bot Monitoring Plugin
Latest data
Loading …
Overview
Humans overview
Web traffic (humans only)
Visitor logs
Process log
';
/* proces old logs */
if ($hasOldLogFiles) {
$helper = $this->loadHelper('botmon', true);
$helper->cleanup();
} else {
echo '
No files to process.
';
}
echo '
';
}
/**
* Check if there are old log files to be handled
*
* @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);
// 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, '.');
if ($bName == '' || $bName == 'logfiles' || $bName == 'empty' || $fName == '.htaccess') {
// ignore
} else if ($bName == $today || $bName == $yesterday) {
// skip
} else {
return true;
}
}
return false;
}
}