1<?php 2 3use dokuwiki\Extension\AdminPlugin; 4 5/** 6 * Bot Monitoring Plugin 7* 8* @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 9* @author Sascha Leib <ad@hominem.info> 10*/ 11 12/** 13 * All DokuWiki plugins to extend the admin function 14 * need to inherit from this class 15**/ 16class admin_plugin_botmon extends AdminPlugin { 17 18 /** 19 * Return the path to the icon being displayed in the main admin menu. 20 * 21 * @return string full path to the icon file 22 **/ 23 public function getMenuIcon() { 24 $plugin = $this->getPluginName(); 25 return DOKU_PLUGIN . $plugin . '/img/admin.svg'; 26 } 27 28 /** 29 * output appropriate html 30 */ 31 public function html() { 32 33 global $conf; 34 35 $pluginPath = $conf['basedir'] . 'lib/plugins/' . $this->getPluginName(); 36 37 /* Plugin Headline */ 38 echo '<div id="botmon__admin"> 39 <h1>Bot Monitoring Plugin</h1> 40 <nav id="botmon__tabs"> 41 <ul class="tabs" role="tablist"> 42 <li role="presentation" class="active"><a role="tab" href="#botmon__panel1" aria-controls="botmon__panel1" id="botmon__tab1" aria-selected="true">Today</a></li> 43 </ul> 44 </nav>'; 45 46 if ($this->hasOldLogFiles()) { 47 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>'; 48 } 49 50 echo '<article role="tabpanel" id="botmon__today""> 51 <h2 class="a11y">Today</h2> 52 <header id="botmon__today__title">Loading …</header> 53 <div id="botmon__today__content"> 54 <details id="botmon__today__overview" open> 55 <summary>Bot overview (page views)</summary> 56 <div class="botmon_overview_grid"> 57 <dl id="botmon__today__botsvshumans"></dl> 58 <dl id="botmon__botslist"></dl> 59 <dl id="botmon__today__botips"></dl> 60 <dl id="botmon__today__countries"></dl> 61 </div> 62 </details> 63 <details id="botmon__today__webmetrics"> 64 <summary>Web metrics</summary> 65 <div class="botmon_overview_grid"> 66 <dl id="botmon__today__wm_overview"></dl> 67 <dl></dl> 68 <dl></dl> 69 <dl></dl> 70 </div> 71 </details> 72 <details id="botmon__today__visitors"> 73 <summary>Visitor logs</summary> 74 <div id="botmon__today__visitorlists"></div> 75 </details> 76 </div> 77 <footer aria-live="polite"> 78 <img src="' . $pluginPath . '/img/spinner.svg" id="botmon__today__busy" width="12" height="12" alt="busy indicator"> 79 <span id="botmon__today__status">Initialising …</span> 80 </footer> 81 </article> 82</div><!-- End of BotMon Admin Tool -->'; 83 84 } 85 86 /** 87 * Check if there are old log files that can be deleted. 88 * 89 * @return bool true if there are old log files, false otherwise 90 */ 91 private function hasOldLogFiles() { 92 93 $today = gmdate('Y-m-d'); 94 $yesterday = gmdate('Y-m-d', time() - 86400); 95 96 // scan the log directory and delete all files except for today and yesterday: 97 $dir = scandir(getcwd() . '/lib/plugins/botmon/logs'); 98 foreach($dir as $file) { 99 $fName = pathinfo($file, PATHINFO_BASENAME); 100 $bName = strtok($fName, '.'); 101 102 if ($bName == '' || $bName == 'logfiles') { 103 // ignore 104 } else if ($bName == $today || $bName == $yesterday) { 105 // skip 106 } else { 107 return true; 108 } 109 } 110 return false; 111 } 112}