| 1 |
Administration |
| 2 |
============== |
| 3 |
|
| 4 |
This document describes how to configure, administer and interact with errbot. |
| 5 |
|
| 6 |
|
| 7 |
Configuration |
| 8 |
------------- |
| 9 |
|
| 10 |
There is a split between two types of configuration within errbot. |
| 11 |
On the one hand there is "setup" information, |
| 12 |
such as the (chat network) backend to use, storage selection |
| 13 |
and other settings related to how errbot should run. |
| 14 |
These settings are all configured through the `config.py` configuration file as explained in |
| 15 |
:ref:`configuration <configuration>`. |
| 16 |
|
| 17 |
The other type of configuration is the "runtime" configuration such as the plugin settings. |
| 18 |
Plugins can be dynamically configured through chatting with the bot by using the :code:`!plugin config <plugin name>` command. |
| 19 |
|
| 20 |
There are a few other commands which adjust the runtime configuration, |
| 21 |
such as the :code:`!plugin blacklist <plugin>` command to unload and blacklist a specific plugin. |
| 22 |
|
| 23 |
You can view a list of all these commands and their help documentation by using the built-in help function. |
| 24 |
|
| 25 |
|
| 26 |
.. _builtin_help_function: |
| 27 |
|
| 28 |
The built-in help function |
| 29 |
^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 30 |
|
| 31 |
To get a list of all available commands, you can issue:: |
| 32 |
|
| 33 |
!help |
| 34 |
|
| 35 |
If you just wish to know more about a specific command you can issue:: |
| 36 |
|
| 37 |
!help <command> |
| 38 |
|
| 39 |
|
| 40 |
Installing plugins |
| 41 |
------------------ |
| 42 |
|
| 43 |
Errbot plugins can be installed via these methods |
| 44 |
|
| 45 |
* `!repos install` bot command |
| 46 |
* Cloning a `GitHub <http://github.com/>`_ repository |
| 47 |
* Extracting a tar/zip file |
| 48 |
* Using pip |
| 49 |
|
| 50 |
|
| 51 |
Using a bot command |
| 52 |
^^^^^^^^^^^^^^^^^^^ |
| 53 |
|
| 54 |
Plugins installed via the :code:`!repos` command are managed by errbot itself and stored inside the `BOT_DATA_DIR` you set in `config.py`. |
| 55 |
|
| 56 |
We periodically crawl GitHub for errbot plugin repositories and `publish the results <https://errbot.io/repos.json>`_ for people to browse. |
| 57 |
|
| 58 |
You can have your bot display the same list of repos by issuing:: |
| 59 |
|
| 60 |
!repos |
| 61 |
|
| 62 |
Searching can be done by specifying one or more keywords, |
| 63 |
for example:: |
| 64 |
|
| 65 |
!repos search hello |
| 66 |
|
| 67 |
To install a plugin from the list, issue:: |
| 68 |
|
| 69 |
!repos install <name of plugin> |
| 70 |
|
| 71 |
You aren't limited to installing public plugins though. |
| 72 |
You can install plugins from any git repository you have access to, |
| 73 |
whether public or private, hosted on GitHub, BitBucket or elsewhere. |
| 74 |
The `!repos install` command can take any git URI as argument. |
| 75 |
|
| 76 |
If you're unhappy with a plugin and no longer want it, |
| 77 |
you can always uninstall a plugin again with:: |
| 78 |
|
| 79 |
!repos uninstall <plugin> |
| 80 |
|
| 81 |
You will probably also want to update your plugins periodically. |
| 82 |
This can be done with:: |
| 83 |
|
| 84 |
!repos update all |
| 85 |
|
| 86 |
|
| 87 |
Cloning a repository or tar/zip install |
| 88 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 89 |
|
| 90 |
Using a git repository or tar/zip file to install plugins is setting up your plugins to be managed manually. |
| 91 |
|
| 92 |
Plugins installed from cloning a repository need to be placed inside the `BOT_EXTRA_PLUGIN_DIR` path specified in the `config.py` file. |
| 93 |
|
| 94 |
Assuming `BOT_EXTRA_PLUGIN_DIR` is set to `/opt/plugins`:: |
| 95 |
|
| 96 |
$ git clone https://github.com/errbotio/err-helloworld /opt/plugins/err-helloworld |
| 97 |
$ tar -zxvf err-helloworld.tar.gz -C /opt/plugins/ |
| 98 |
|
| 99 |
.. note:: |
| 100 |
If a repo is cloned and the git remote information is present, updating the plugin may be possible via `!repos update` |
| 101 |
|
| 102 |
|
| 103 |
Using pip for plugins |
| 104 |
^^^^^^^^^^^^^^^^^^^^^ |
| 105 |
|
| 106 |
Plugins published to to pypi.org can be installed using pip.:: |
| 107 |
|
| 108 |
$ pip install errbot-plugin-helloworld |
| 109 |
|
| 110 |
As part of the packaging configuration for the plugin, it should install all necessary dependencies for the plugin to work. |
| 111 |
|
| 112 |
|
| 113 |
Dependencies |
| 114 |
^^^^^^^^^^^^ |
| 115 |
|
| 116 |
Please pay attention when you install a plugin as it may have additional dependencies. |
| 117 |
If the plugin contains a `requirements.txt` file then Errbot will automatically check the requirements listed within and warn you when you are missing any. |
| 118 |
|
| 119 |
Additionally, if you set :code:`AUTOINSTALL_DEPS` to :code:`True` in your **config.py**, Errbot will use pip to install any missing dependencies automatically. |
| 120 |
If you have installed Errbot in a virtualenv, this will run the equivalent of :code:`pip install -r requirements.txt`. |
| 121 |
If no virtualenv is detected, the equivalent of :code:`pip install --user -r requirements.txt` is used to ensure the package(s) is/are only installed for the user running Err. |
| 122 |
|
| 123 |
|
| 124 |
.. _disabling_plugins: |
| 125 |
|
| 126 |
Disabling plugins |
| 127 |
----------------- |
| 128 |
|
| 129 |
You have a number of options available to you if you need to disable a plugin for any reason. |
| 130 |
Plugins can be temporarily disabled by using the :code:`!plugin deactivate <plugin name>` command, which deactivates the plugin until the bot is restarted (or activated again via :code:`!plugin activate <plugin name>`. |
| 131 |
|
| 132 |
If you want to prevent a plugin from being loaded at all during bot startup, the :code:`!plugin blacklist <plugin name>` command may be used. |
| 133 |
|
| 134 |
It's also possible to strip errbot down even further by disabling some of its core plugins which are otherwise activated by default. |
| 135 |
You may for example want to this if you're building a very specialized bot for a specific purpose. |
| 136 |
|
| 137 |
Disabling core plugins can be done by setting the `CORE_PLUGINS` setting in `config.py`. |
| 138 |
For example, setting `CORE_PLUGINS = ()` would disable all of the core plugins which even removes the plugin and repository management commands described above. |
| 139 |
|
| 140 |
|
| 141 |
.. _access_controls: |
| 142 |
|
| 143 |
Restricting access |
| 144 |
------------------ |
| 145 |
|
| 146 |
Errbot features a number of options to limit and restrict access to commands of your bot. |
| 147 |
All of these are configured through the `config.py` file as explained in |
| 148 |
:ref:`configuration <configuration>`. |
| 149 |
|
| 150 |
The first of these is `BOT_ADMINS`, which sets up the administrators for your bot. |
| 151 |
Some commands are hardcoded to be admin-only so the people listed here will be given access to those commands |
| 152 |
(the users listed here will also receive warning messages generated by the :func:`~errbot.botplugin.BotPlugin.warn_admins` plugin function). |
| 153 |
|
| 154 |
More advanced access controls can be set up using the `ACCESS_CONTROLS` and `ACCESS_CONTROLS_DEFAULT` options which allow you to set up sophisticated rules. |
| 155 |
|
| 156 |
Access controls, allowing commands to be restricted to specific users/rooms. |
| 157 |
Available filters (you can omit a filter or set it to None to disable it): |
| 158 |
|
| 159 |
* `allowusers`: Allow command from these users only |
| 160 |
* `denyusers`: Deny command from these users |
| 161 |
* `allowrooms`: Allow command only in these rooms (and direct messages) |
| 162 |
* `denyrooms`: Deny command in these rooms |
| 163 |
* `allowargs`: Allow a command's argument from these users only |
| 164 |
* `denyargs`: Deny a command's argument from these users |
| 165 |
* `allowprivate`: Allow command from direct messages to the bot |
| 166 |
* `allowmuc`: Allow command inside rooms |
| 167 |
|
| 168 |
Rules listed in `ACCESS_CONTROLS_DEFAULT` are applied by default and merged with any commands found in `ACCESS_CONTROLS`. |
| 169 |
|
| 170 |
The options allowusers, denyusers, allowrooms and denyrooms, allowargs, denyargs support unix-style globbing similar to `BOT_ADMINS`. |
| 171 |
|
| 172 |
Command names also support unix-style globs and can optionally be restricted to a specific plugin by prefixing the command with the name of a plugin, separated by a colon. For example, `Health:status` will match the `!status` command of the `Health` plugin and `Health:*` will match all commands defined by the `Health` plugin. |
| 173 |
|
| 174 |
.. note:: |
| 175 |
The first command match found will be used so if you have overlapping patterns you must used an OrderedDict instead of a regular dict: https://docs.python.org/3/library/collections.html#collections.OrderedDict |
| 176 |
|
| 177 |
Example:: |
| 178 |
|
| 179 |
ACCESS_CONTROLS_DEFAULT = {} # Allow everyone access by default |
| 180 |
ACCESS_CONTROLS = { |
| 181 |
"status": { |
| 182 |
"allowrooms": ("[email protected]",) |
| 183 |
}, |
| 184 |
"about": { |
| 185 |
"denyusers": ("*@evilhost",), |
| 186 |
"allowrooms": ("[email protected]", "[email protected]") |
| 187 |
}, |
| 188 |
"uptime": {"allowusers": BOT_ADMINS}, |
| 189 |
"help": {"allowmuc": False}, |
| 190 |
"ChatRoom:*": {"allowusers": BOT_ADMINS}, |
| 191 |
} |
| 192 |
|
| 193 |
The example :download:`config.py <config-template.py>` file contains this information about the format of these options. |
| 194 |
|
| 195 |
If you don't like encoding access controls into the config file, a member of the errbot community has also created a `dynamic ACL module <https://github.com/shengis/err-profiles>`_ which can be administered through chat commands instead. |
| 196 |
|
| 197 |
Another community solution allows LDAP groups to be checked for membership before allowing the command to be executed. `LDAP ACL module <https://github.com/marksull/err-ldap>`_ is practical for managing large groups. This module functions by decorating bot commands directly in the plugin code, which differs from configuration based ACLs. |
| 198 |
|
| 199 |
.. note:: |
| 200 |
Different backends have different formats to identify users. |
| 201 |
Refer to the backend-specific notes at the end of the :ref:`configuration <configuration>` chapter to see which format you should use. |
| 202 |
|
| 203 |
|
| 204 |
Command filters |
| 205 |
--------------- |
| 206 |
|
| 207 |
If our built-in access controls don't fit your needs, you can always create your own easily using *command filters*. |
| 208 |
Command filters are functions which are called automatically by errbot whenever a user executes a command. |
| 209 |
They allow the command to be allowed, blocked or even modified based on logic you implement yourself. |
| 210 |
In fact, the restrictions enforced by `BOT_ADMINS` and `ACCESS_CONTROLS` above are implemented using a command filter themselves |
| 211 |
so they can serve as a good :mod:`example <errbot.core_plugins.acls>` (be sure to view the module source). |
| 212 |
|
| 213 |
You can add command filters to your bot by including them as part of any regular errbot plugin, |
| 214 |
it will find and register them automatically when your plugin is loaded. |
| 215 |
Any method in your plugin which is decorated by :func:`~errbot.cmdfilter` will then act as a command filter. |
| 216 |
|
| 217 |
|
| 218 |
Overriding CommandNotFoundFilter |
| 219 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 220 |
|
| 221 |
In some cases, it may be necessary to run other filters before the `CommandNotFoundFilter`. Since the `CommandNotFoundFilter` is part of the core plugin list loaded by errbot, it can not be directly overridden from another plugin. |
| 222 |
Instead, to prevent `CommandNotFoundFilter` from being called before other filters, exclude the `CommandNotFoundFilter` plugin in the `CORE_PLUGINS` setting in `config.py` and explicitly call the `CommandNotFoundFilter` function from the overriding filter. |