Commit graph

41 commits

Author SHA1 Message Date
novokrest
50173c105b botserver: Read bot's config from config section with bot's name.
This commit changes the default behavior for a hypothetical bot
named 'bot_one' to the following with the config file:

1. Find and load section named 'bot_one', else...
2. Find and load the first section, else...
3. Exit with error message.

Also, we now gracefully show missing options in a config section
instead of printing the whole stacktrace of the exception.
2018-07-12 20:49:10 +05:30
Robert Hönig
242bcdbadc botserver: Add specific error message for unedited zuliprcs.
Previously, when a user tried to run the Botserver with a
zuliprc but forgot to set the bot name, they were told to
edit the botserverrc file. However, the recommended approach
is to specify the botname with the -b option. This commit
adds an error message specific for this case. It recognizes
zuliprc files by their section header `api`.
2018-06-04 10:14:17 -07:00
Robert Hönig
3ddc8f9b5d botserver: Make bot-name-not-found error more user-friendly.
Previously, when a bot name wasn't found, the Botserver threw
an ImportError with an error message. This results in an
intimidating traceback which is in most cases not helpful to
the user. This commit replaces the ImportError with sys.exit.
2018-06-04 10:14:17 -07:00
Robert Hönig
c85b42be9f botserver: Exit with helpful output if botserverrc is invalid.
If the botserverrc file contains empty section headers, it
is very likely that the user forgot to edit the file. This
reminds them to do so.
2018-06-04 10:14:17 -07:00
Robert Hönig
3d05b88cc2 botserver: Rename zulip-bot-server to zulip-botserver.
This is consistent with the correct prose "Botserver"
(instead of "Bot-server").
2018-06-04 10:14:17 -07:00
Robert Hönig
f4e0808a87 botserver: Validate token before accepting message.
Previously, the botserver would accept any message sent
to it. This was a security hazard, since an attacker could
impersonate arbitrary users with arbitrary messages. We only
want the Zulip instance where a bot is registered to be able
to send out messages for that bot. To do this, this commits
adds a check for the security token associated with each
outgoing webhook bot. For each bot, its token is stored in
the botserverrc file. The server sends the token along with
each message.
2018-05-30 09:37:33 -04:00
Robert Hönig
64a1306e39 Consistently use Botserver instead of botserver or bot server. 2018-05-29 10:58:37 +02:00
Robert Hönig
762118bbea Rename flaskbotrc to botserverrc. 2018-05-29 10:19:50 +02:00
Robert Hönig
3859bef05f botserver: Make handle_bot logic more concise. 2018-05-29 10:05:32 +02:00
Robert Hönig
e6ef34a964 botserver: Strip messages like we do in zulip-run-bot.
Previously, messages weren't stripped at all. This
caused most bots to break and send replies similar to
"I didn't understand your command". Nobody noticed,
because the tests were only validating that replies
were sent, but not the content in them. Thus, this
commit also adds tests to avoid further regressions.
2018-05-29 10:05:19 +02:00
Robert Hönig
f1bcf3b9a4 botserver: Remove redundant message check.
Previously, the botserver `handle_bot` routine did two checks
on an incoming message:
* First, it checked if the bot email matches
an email in the flaskbotrc.
* Second, it checked if the bot name that corresponds to an email
has a lib module loaded. However, this must be the case, because
all lib modules for all emails are loaded on initialization. Thus,
this commit removes the second check.
2018-05-29 09:52:14 +02:00
Robert Hönig
6a8cb2965c zulip_botserver: Handle all requests from the root / endpoint.
Previously, the Botserver determined which bot to run by dispatching on
a unique URL endpoint /bots/<botname> for each bot.
Now, instead, the Botserver determines which bot to run by the section
header of the bot in the flaskbotrc.
2018-05-28 15:09:39 +02:00
dkvasov
a06fb98f21 zulip_bots and zulip_botserver: Extract common function. 2018-05-17 17:35:09 +03:00
dkvasov
86ab26d2ba zulip_botserver: Get rid of last global variable. 2018-05-16 10:58:09 -07:00
dkvasov
a5d6286d85 zulip_botserver: Better message for single bot mode. 2018-05-16 10:58:09 -07:00
dkvasov
b06ebdecef zulip_botserver: Add option to test third party configs 2018-05-16 10:50:43 -07:00
dkvasov
a8665aaac8 zulip_botserver: Add option to set third party configs for bots. 2018-05-16 10:50:43 -07:00
dkvasov
6542f8c867 zulip_botserver: Add parameter to set custom bot name (for single-bot mode). 2018-05-16 17:41:22 +03:00
dkvasov
aa193c1298 zulip_botserver: Extract input parameters. 2018-05-16 17:40:40 +03:00
Guitar1st
f90913d54c zulip_botserver: Get rid of some global variables. 2018-05-15 12:32:57 -07:00
Tim Abbott
7b6da265ea zulip_botserver: Reorder imports. 2018-05-15 12:32:45 -07:00
Tim Abbott
70dd05e5a6 zulip_botserver: Enforce that port argument is an int. 2018-05-15 12:32:45 -07:00
Tim Abbott
5ef224f2a2 zulip_botserver: Eliminate the bots_config global variable.
It's easy to just pass it around to the one function that needs it.
2018-05-15 12:32:44 -07:00
Tim Abbott
1e5c0fec1f zulip_botserver: Fix long line for ImportError. 2018-05-15 12:23:40 -07:00
Tim Abbott
9eda19d6cc zulip_botserver: Get rid of old six.moves for configparser. 2018-05-15 12:23:10 -07:00
Guitar1st
2ba6f75fb3 zulip_botserver: Change style of type annotations to python3 2018-05-14 20:00:44 +00:00
Guitar1st
641665c338 zulip_botserver: Remove unused imports and do some other cleanup. 2018-05-14 20:00:44 +00:00
Tim Abbott
b1ab308c26 botserver: Fix mypy error. 2018-05-14 10:07:02 -07:00
Tim Abbott
7124f9dc14 bot_server: Call the bot server initialization code. 2018-05-14 08:50:52 -07:00
Steve Howell
536ba1843a Add a command line option to run.py for bot config files.
Before this change, we were looking for config files in
default locations in source control, which is not a good
place to look for them.  Now `run.py` and friends have a
command line argument where users can specify the config
files.

Note that the change to server.py is only a partial fix
to make it so that bots that don't use third party config
files won't crash.  That program needs an overhaul, anyway.
2017-11-28 10:52:13 -08:00
Steve Howell
8a15452525 bots: Require bots_details in ExternalBotHandler.
This parameter was defaulting to a dictionary, which is
a classic Python pitfall.
2017-11-28 10:52:13 -08:00
derAnfaenger
bf72a8994a zulip_botserver: Raise exception on wrong flaskbotrc file. 2017-11-10 18:36:20 -08:00
derAnfaenger
bcc8bd7d38 zulip_botserver: Don't reinstantiate ExternalBotHandlers.
Fixes #147.
2017-11-07 05:06:12 -08:00
derAnfaenger
e5576388dd botserver: Remove obsolete state_handler param from handle_message(). 2017-10-31 12:24:10 +01:00
Alena Volkova
ed51cabf1b mypy: zulip_botserver: Fix errors in zulip_botserver/server.py. 2017-10-27 00:56:16 -04:00
derAnfaenger
9d683e4669 api: Ensure automatic tilde expansion. 2017-08-29 14:20:48 -07:00
derAnfaenger
6c026c84aa flaskserver: Load json python 3 compatible. 2017-08-15 06:38:50 -07:00
Eeshan Garg
de23a1b32f zulip_botserver: Migrate from optparse to argparse. 2017-07-29 00:17:43 -02:30
vaibhav
c4876dddae bot server: Raise BadRequest when bot code can't be imported.
This adds support to check and raise a BadRequest when either the
configuration of bot couldn't be found or the BotHandler code of bot
couldn't be fetched. There can be cases where flaskbotrc contains config
details of a bot, but the user hasn't added it's handler class code. This
fixes server to handle such cases, by reporting it to user.
This also fixes the response of bot server to make it possible to skip
the response message.
2017-07-27 11:03:33 -07:00
derAnfaenger
f3eaa381f6 bots: Audit filesystem access.
This adds a safe function for opening files via
ExternalBotHandler. This restricts open calls to a bot's
local directory.

Finalizes #9
2017-07-26 20:01:17 +02:00
Eeshan Garg
928d5ca16d flask_server: Move the server to its own package. 2017-07-18 01:31:54 -02:30