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...
This commit is contained in:
Olen
2017-06-05 23:45:18 +02:00
committed by Neil Lathwood
parent c67424b4ef
commit 127c4b84bd
3 changed files with 37 additions and 11 deletions

View File

@@ -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) {

View File

@@ -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.
### <a name="commands">IRC-Commands</a>

View File

@@ -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;