From 127c4b84bd79cde895b526f4c942d573d37164c6 Mon Sep 17 00:00:00 2001 From: Olen Date: Mon, 5 Jun 2017 23:45:18 +0200 Subject: [PATCH] feature: Added Irc ctcp support to IRCBot (#6766) * Handle basic CTCP-support * Add an option to toggle ctcp on and off in the config * Fix whitespace-issue * Fix null/NULL * Updating docs, default config and fixing a few whitespace-issues * Fixing the last whitespace-issues. Now with "pre-commit.php" as a standard... --- LibreNMS/IRCBot.php | 22 ++++++++++++++++++++++ doc/Extensions/IRC-Bot.md | 2 ++ includes/defaults.inc.php | 24 +++++++++++++----------- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/LibreNMS/IRCBot.php b/LibreNMS/IRCBot.php index 9236c25485..1737ef5382 100644 --- a/LibreNMS/IRCBot.php +++ b/LibreNMS/IRCBot.php @@ -296,6 +296,28 @@ class IRCBot } } + if (($this->config['irc_ctcp']) && (preg_match("/^:".chr(1).".*/", $ex[3]))) { + // Handle CTCP + $ctcp = trim(preg_replace("/[^A-Z]/", "", $ex[3])); + $ctcp_reply = null; + $this->log("Received irc CTCP: ".$ctcp." from ".$this->getUser($this->data)); + switch ($ctcp) { + case 'VERSION': + $ctcp_reply = chr(1)."$ctcp ".$this->config['irc_ctcp_version'].chr(1); + break; + case 'PING': + $ctcp_reply = chr(1)."$ctcp ".$ex[4]. " ".$ex[5].chr(1); + break; + case 'TIME': + $ctcp_reply = chr(1)."$ctcp ".date('c').chr(1); + break; + } + if ($ctcp_reply !== null) { + $this->log("Sending irc CTCP: ".'NOTICE '.$this->getUser($this->data)." :".$ctcp_reply); + return $this->ircRaw('NOTICE '.$this->getUser($this->data)." :".$ctcp_reply); + } + } + if (($ex[1] == 'NICK') && (preg_replace("/^:/", "", $ex[2]) == $this->nick)) { // Nickname changed successfully if ($this->debug) { diff --git a/doc/Extensions/IRC-Bot.md b/doc/Extensions/IRC-Bot.md index d37a219313..619ad4256e 100644 --- a/doc/Extensions/IRC-Bot.md +++ b/doc/Extensions/IRC-Bot.md @@ -34,6 +34,8 @@ Option | Default-Value | Notes `$config['irc_nick']` | `LibreNMS` | Optional; `$config['irc_pass']` | | Optional; This sends the IRC-PASS Sequence to IRC-Servers that require Password on Connect `$config['irc_port']` | `6667` | Required; To enable SSL append a `+` before the Port. (Example: `+6697`) +`$config['irc_ctcp']` | `false` | Optional; Enable/disable ctcp-replies from the bot (currently VERSION, PING and TIME). +`$config['irc_ctcp_version']` | `LibreNMS IRCbot. https://www.librenms.org/` | Optional: Reply-string to CTCP VERSION requests `$config['irc_auth']` | | Optional: Array of hostmasks that are automatically authenticated. ### IRC-Commands diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index 55996b3acf..eff0e8a21f 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -566,17 +566,19 @@ $config['device_traffic_descr'][] = '/null/'; $config['device_traffic_descr'][] = '/dummy/'; // IRC Bot configuration -$config['irc_host'] = ''; -$config['irc_port'] = ''; -$config['irc_maxretry'] = 3; -$config['irc_nick'] = $config['project_name']; -$config['irc_chan'][] = '##'.$config['project_id']; -$config['irc_pass'] = ''; -$config['irc_external'] = ''; -$config['irc_authtime'] = 3; -$config['irc_debug'] = false; -$config['irc_alert'] = false; -$config['irc_alert_utf8'] = false; +$config['irc_host'] = ''; +$config['irc_port'] = ''; +$config['irc_maxretry'] = 3; +$config['irc_nick'] = $config['project_name']; +$config['irc_chan'][] = '##'.$config['project_id']; +$config['irc_pass'] = ''; +$config['irc_external'] = ''; +$config['irc_authtime'] = 3; +$config['irc_debug'] = false; +$config['irc_alert'] = false; +$config['irc_alert_utf8'] = false; +$config['irc_ctcp'] = false; +$config['irc_ctcp_version'] = "LibreNMS IRCbot. https://www.librenms.org/"; // Authentication $config['allow_unauth_graphs'] = false;