diff --git a/action.php b/action.php index 319d45d..a3c4c8a 100644 --- a/action.php +++ b/action.php @@ -84,7 +84,7 @@ class action_plugin_botmon extends DokuWiki_Action_Plugin { public function insertAdminHeader(Event $event, $param) { $event->data['link'][] = ['rel' => 'stylesheet', 'href' => DOKU_BASE.'lib/plugins/botmon/admin.css', 'defer' => 'defer']; - $event->data['script'][] = ['href' => DOKU_BASE.'lib/plugins/botmon/admin.js', 'defer' => 'defer', '_data' => '']; + $event->data['script'][] = ['src' => DOKU_BASE.'lib/plugins/botmon/admin.js', 'defer' => 'defer', '_data' => '']; } diff --git a/admin.css b/admin.css index b11cdff..047a8d4 100644 --- a/admin.css +++ b/admin.css @@ -389,7 +389,6 @@ background-size: 20px; } - /* grid layout for the overview: */ .botmon_bots_grid, .botmon_webmetrics_grid, .botmon_traffic_grid { & { @@ -435,7 +434,7 @@ } /* the "today" tab: */ - #botmon__today { + #botmon__latest { /* item header */ header { @@ -747,13 +746,40 @@ } } } + + /* the log tab: */ + #botmon__log { + + #botmon__loglist { + & { + border: #999 solid 1px; + background-color: #F0F0F0; + margin: 0; padding: .5em; + border-radius: .5em 1pt 1pt .5em; + list-style: none inside; + display: block; + min-height: 24rem; + max-height: 32rem; + overflow: hidden auto + } + li { + &:nth-child(even) { + background-color: #DFDFDF; + } + &.info { color: #626262; font-style: italic;} + &.success { color: #217121; } + &.error { color: #bb2929; } + } + } + + } } /* dark mode overrides */ @media (prefers-color-scheme: dark) { body.darkmode.mode_admin #botmon__admin { - #botmon__today { + #botmon__latest { header { background-color: #0c0c0d; @@ -844,7 +870,7 @@ } /* layout overrides for narrow screens: */ @media (max-width: 800px) { - #botmon__admin #botmon__today #botmon__today__visitorlists { + #botmon__admin #botmon__latest #botmon__today__visitorlists { dl.visitor_details { & { display: block; @@ -865,7 +891,7 @@ } @media (max-width: 670px) { - #botmon__admin #botmon__today { + #botmon__admin #botmon__latest { .botmon_bots_grid, .botmon_webmetrics_grid, .botmon_traffic_grid { & { grid-template-columns: 1fr !important; diff --git a/admin.js b/admin.js index 14da250..776f5d6 100644 --- a/admin.js +++ b/admin.js @@ -32,8 +32,7 @@ const BotMon = { //console.info('BotMon.init()'); // find the plugin basedir: - this._baseDir = document.currentScript.src.substring(0, document.currentScript.src.indexOf('/exe/')) - + '/plugins/botmon/'; + this._baseDir = document.currentScript.src.substring(0, document.currentScript.src.lastIndexOf('/')+1); // read the page language from the DOM: this._lang = document.getRootNode().documentElement.lang || this._lang; @@ -186,7 +185,7 @@ const BotMon = { /* everything specific to the "Latest" tab is self-contained in the "live" object: */ BotMon.live = { init: function() { - //console.info('BotMon.live.init()'); + console.info('BotMon.live.init()'); // set the title: const tDiff = 'UTC ' + (BotMon._timeDiff != '' ? ` (offset: ${BotMon._timeDiff}` : '' ) + ')'; @@ -1011,6 +1010,10 @@ BotMon.live = { const me = BotMon.live.data.analytics; const ipRanges = BotMon.live.data.ipRanges; + // Number of IP address segments to look at: + const kIP4Segments = 1; + const kIP6Segments = 2; + let isp = 'null'; // default ISP id let name = 'Unknown'; // default ISP name @@ -1691,7 +1694,7 @@ BotMon.live = { // assign the columns to an object: const data = {}; cols.forEach( (colVal,i) => { - colName = columns[i] || `col${i}`; + const colName = columns[i] || `col${i}`; const colValue = (colName == 'ts' ? new Date(colVal) : colVal.trim()); data[colName] = colValue; }); @@ -1729,10 +1732,12 @@ BotMon.live = { gui: { init: function() { - // init the lists view: - this.lists.init(); + console.log('BotMon.live.gui.init()'); + // init sub-objects: + BotMon.t._callInit(this); }, + /* The Overview / web metrics section of the live tab */ overview: { /** diff --git a/admin.php b/admin.php index 79b249f..54ddf0a 100644 --- a/admin.php +++ b/admin.php @@ -35,6 +35,8 @@ class admin_plugin_botmon extends AdminPlugin { // display GeoIP data? $geoIPconf = $this->getConf('geoiplib'); + $hasOldLogFiles = $this->hasOldLogFiles(); + // spinner animation as SVG image: $svg = ''; @@ -45,15 +47,11 @@ class admin_plugin_botmon extends AdminPlugin {

Bot Monitoring Plugin

'; - - if ($this->hasOldLogFiles()) { - echo '
Note: There are old log files that can be deleted. Click here to run a delete script, or use cron to automatically delete them.
'; - } - - echo '
+ +

Latest data

Loading …
@@ -92,12 +90,26 @@ class admin_plugin_botmon extends AdminPlugin { Initialising …
-'; +
+

Process log

+
'; } /** - * Check if there are old log files that can be deleted. + * Check if there are old log files to be handled * * @return bool true if there are old log files, false otherwise */ diff --git a/config/known-ipranges.json b/config/known-ipranges.json index 415b6cf..732183f 100644 --- a/config/known-ipranges.json +++ b/config/known-ipranges.json @@ -5,6 +5,7 @@ {"id": "amazon-microsoft", "name": "Amazon or Microsoft"}, {"id": "brasilnet", "name": "BrasilNet"}, {"id": "charter", "name": "Charter Communications Inc."}, + {"id": "chinanet", "name": "Chinanet"}, {"id": "cnisp", "name": "China ISP"}, {"id": "cnmob", "name": "China Mobile Communications Corp."}, {"id": "google", "name": "Google LLC"}, diff --git a/helper.php b/helper.php new file mode 100644 index 0000000..fa3587f --- /dev/null +++ b/helper.php @@ -0,0 +1,50 @@ + + */ + +use dokuwiki\Extension\Plugin; + +class helper_plugin_botmon extends Plugin { + + /** + * Constructor + */ + public function __construct() { + echo "
  • Processing logfiles …
  • \n"; + } + + /** + * Cleanup function + */ + public function cleanup() { + + // exclude the following two dates: + $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(DOKU_PLUGIN . 'botmon/logs'); + foreach($dir as $file) { + $fName = pathinfo($file, PATHINFO_BASENAME); + $bName = strtok($fName, '.'); + + if ($bName == '' || $bName == 'logfiles' || $bName == 'empty' || $fName == '.htaccess') { + // echo "File “{$fName}” ignored.\n"; + } else if ($bName == $today || $bName == $yesterday) { + echo "
  • File “{$fName}” skipped.
  • \n"; + } else { + if (unlink(DOKU_PLUGIN . 'botmon/logs/' . $file)) { + echo "
  • File “{$fName}” deleted.
  • \n"; + } else { + echo "
  • File “{$fName}” could not be deleted!
  • \n"; + } + } + } + echo "
  • Done.
  • \n"; + } + +} \ No newline at end of file diff --git a/img/addr.png b/img/addr.png index 1a46134..b44ca79 100644 Binary files a/img/addr.png and b/img/addr.png differ diff --git a/script.js b/script.js new file mode 100644 index 0000000..5484c2f --- /dev/null +++ b/script.js @@ -0,0 +1 @@ +/* This file is no longer in use */ \ No newline at end of file diff --git a/style.less b/style.less new file mode 100644 index 0000000..5484c2f --- /dev/null +++ b/style.less @@ -0,0 +1 @@ +/* This file is no longer in use */ \ No newline at end of file