From 0edf1a5674fab8bbda861d077231c188a562e705 Mon Sep 17 00:00:00 2001 From: Sascha Leib Date: Wed, 15 Oct 2025 20:12:42 +0200 Subject: [PATCH] Reorg --- action.php | 2 +- admin.css | 36 ++++++++++++++++++++++---- admin.js | 17 ++++++++----- admin.php | 32 ++++++++++++++++-------- config/known-ipranges.json | 1 + helper.php | 50 +++++++++++++++++++++++++++++++++++++ img/addr.png | Bin 2016 -> 2135 bytes script.js | 1 + style.less | 1 + 9 files changed, 118 insertions(+), 22 deletions(-) create mode 100644 helper.php create mode 100644 script.js create mode 100644 style.less 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

+
    '; + + /* 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 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 1a46134e4ace13b4cec90983743909c574ed726c..b44ca7906c57815c550626eaa4df22db9e9563fc 100644 GIT binary patch delta 1885 zcmV-j2cr1k57!WoNeUtW02U$v8y13(kyBOy0+Fg83q>*l0O$h%07WtakNwaZ1IN?#a^(B^2HhzKRY&5 zG*(bhu~%Z}mm)z$R1hMdVnYQ(uppvXu|Cg~Wp;LUcb45R{_#!Txn*X~x#yO1&z;?N zg#-p%aK-r~EpXGIqJDf1hmRP4I{2orSSS<~AiNjJgs{{wdZA>ZnWTc-NX~+D;I-B* z1ulUb!`o4CwiU~GiLgSH&gbUHC|?(75R~y~m`zw9u)=a5*g2@EAG6>%TK`X2j1(Y$cy*Ek;qsQ7 zfM4N@C|cMK;fGRq2o@bwlc19Rj=><k?UgWXOMSssvwYAX&pGlUW2Y;-MALY8E`g24j>KD+Oi>k*Vo~BK{7VhioPtb0=s1tbm2V?yV3F$;SS`r_6L}Wyb40JwzzND$Mc~c;AZ#; zEO8G>zz*pgRa22>Ajc~@5AQ`?_ z!!-K;s3;$zwPj0xu3N+XgK{{n2Zq@tsBa8PaR}@i(J>eYN5B#+y@DabUVzUB3}?|C z^3#KR2~<+>A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