Adding irccat companion script
This commit is contained in:
parent
224b541230
commit
1575d9b7c1
38
README.md
38
README.md
|
@ -14,6 +14,9 @@ Obviously, the plugin is generic and could be used to a variety of things.
|
|||
It's similar to the notify plugin, but does not require the client to be on
|
||||
the same host as the supybot server.
|
||||
|
||||
Here is also a simple script which can be used to send data to a server
|
||||
running subybot with irccat
|
||||
|
||||
Dependencies
|
||||
------------
|
||||
- python-twisted (tested with 12.1)
|
||||
|
@ -33,18 +36,22 @@ Getting started
|
|||
$ git clone https://github.com/leamas/supybot-irccat Irccat
|
||||
```
|
||||
|
||||
* Restart the server and use `@list` to verify that the plugin is loaded:
|
||||
```
|
||||
<leamas> @list
|
||||
<al-bot-test> leamas: Admin, Channel, Config, Irccat, Owner, and User
|
||||
```
|
||||
|
||||
* Identify yourself for the bot in a *private window*. Creating user +
|
||||
password is part of the supybot-wizard process.
|
||||
```
|
||||
<leamas> identify al my-secret-pw
|
||||
<al-bot-test> The operation succeeded.
|
||||
```
|
||||
|
||||
* Load plugin and use `list` to verify that the plugin is loaded (still in
|
||||
private window):
|
||||
```
|
||||
<leamas> load Irccat
|
||||
<al-bot-test> The operation succeeded.
|
||||
<leamas> list
|
||||
<al-bot-test> leamas: Admin, Channel, Config, Irccat, Owner, and User
|
||||
```
|
||||
|
||||
* Define the port you want to use as listener port (still in private window):
|
||||
```
|
||||
<leamas> config plugins.irccat.port 12345
|
||||
|
@ -65,13 +72,14 @@ Getting started
|
|||
<leamas> join #al-bot-test
|
||||
```
|
||||
|
||||
* The lines sent to irccat should be formatted like
|
||||
`section;password; some text to show`. To test, send such a line using nc:
|
||||
Use the companion script to send a message...
|
||||
```
|
||||
$ echo "foo;pwfoo;footext to show" | nc --send-only localhost 12345
|
||||
$ plugins/Irccat/irccat localhost -s 12345 foo footext to show
|
||||
pwfoo
|
||||
$
|
||||
```
|
||||
In the selected channel you will see:
|
||||
|
||||
...and you will see a line in the selected channel:
|
||||
```
|
||||
*al-bot-test* footext to show
|
||||
```
|
||||
|
@ -147,7 +155,7 @@ Plugin commands:
|
|||
|
||||
* `sectionhelp`: Show help URL i. e., this file.
|
||||
|
||||
Other useful commands:
|
||||
Other useful supybot commands:
|
||||
|
||||
* `config plugins.irccat.port`: Show the TCP port irccat listens to.
|
||||
|
||||
|
@ -155,6 +163,13 @@ Other useful commands:
|
|||
|
||||
* `join #channel`: Make bot join a channel, required when feeding one.
|
||||
|
||||
Scripts:
|
||||
|
||||
* irccat [-s|-h] \<host\> \<port\> \<section\> \<text...\>.
|
||||
Sends \<text..\>. to a supybot \<host\> running irccat on \<port\> using the
|
||||
given \<section\>. Reads password from stdin when using [-s] Use
|
||||
-h/--help for details.
|
||||
|
||||
|
||||
Security
|
||||
--------
|
||||
|
@ -164,6 +179,7 @@ irc channel(s) certainly requires some precaution. The steps here are:
|
|||
|
||||
- The client must know the section and it's password as described above.
|
||||
- Managing passwords and channels requires 'owner' capability in irc.
|
||||
- Password cleartext is not saved anywhere.
|
||||
- Clients which repeatedly fails to send correct data are blacklisted for a
|
||||
while.
|
||||
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
usage = """
|
||||
Send data to IRC channel
|
||||
|
||||
usage: irccat [-s] <host> <port> <section> <text...>
|
||||
|
||||
host: supybot host running irccat plugin.
|
||||
port The port irccat plugin listen to.
|
||||
section: A section defined using the sectiondata command on the
|
||||
subybot host.
|
||||
text... Sent verbatim to subybot, which is assumed to forward it
|
||||
to the channel(s) bound to the section.
|
||||
|
||||
Options:
|
||||
-s Read password from stdin
|
||||
|
||||
Environment:
|
||||
IRCCAT_PASSWORD: If not using -s, irccat expects this to hold the
|
||||
required password.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import socket
|
||||
|
||||
sys.argv.pop(0)
|
||||
try:
|
||||
if sys.argv[0] == '-h' or sys.argv[0] == '--help':
|
||||
print usage
|
||||
sys.exit(0)
|
||||
elif sys.argv[0] == '-s':
|
||||
sys.argv.pop(0)
|
||||
pw = sys.stdin.readline().strip()
|
||||
elif 'IRCCAT_PASSWORD' in os.environ:
|
||||
pw = os.environ['IRCCAT_PASSWORD']
|
||||
else:
|
||||
print usage
|
||||
sys.exit(1)
|
||||
host = sys.argv.pop(0)
|
||||
port = int(sys.argv.pop(0))
|
||||
section = sys.argv.pop(0)
|
||||
except (IndexError, ValueError):
|
||||
print usage
|
||||
sys.exit(1)
|
||||
text = ' '.join(sys.argv)
|
||||
if not text:
|
||||
print usage
|
||||
sys.exit(1)
|
||||
|
||||
s = socket.create_connection((host, port))
|
||||
s.send('%s;%s;%s\n' % (section, pw, text))
|
||||
s.close()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
37
test.py
37
test.py
|
@ -105,6 +105,43 @@ class IrccatTestCopy(ChannelPluginTestCase):
|
|||
self.assertRegexp(' ', 'No such section.*')
|
||||
|
||||
|
||||
class IrccatTestIrccat(ChannelPluginTestCase):
|
||||
plugins = ('Irccat', 'User')
|
||||
channel = '#test'
|
||||
cmd_tmpl = "echo '%s' | nc --send-only localhost 23456"
|
||||
|
||||
def setUp(self, nick='test'): # pylint: disable=W0221
|
||||
clear_sections(self)
|
||||
ChannelPluginTestCase.setUp(self)
|
||||
self.assertNotError('reload Irccat', private = True)
|
||||
self.assertNotError('register suptest suptest', private = True)
|
||||
self.assertNotError('sectiondata ivar ivarpw #test', private = True)
|
||||
|
||||
def testIrccatEnvPw(self):
|
||||
cmd = 'IRCCAT_PASSWORD=ivarpw plugins/Irccat/irccat' \
|
||||
' localhost 23456 ivar ivar data'
|
||||
subprocess.check_call(cmd, shell = True)
|
||||
self.assertResponse(' ', 'ivar data')
|
||||
|
||||
def testIrccatStdinPw(self):
|
||||
cmd = 'plugins/Irccat/irccat -s localhost 23456 ivar ivar data'
|
||||
p = subprocess.Popen(cmd, shell = True, stdin = subprocess.PIPE)
|
||||
p.communicate('ivarpw\n')
|
||||
self.assertResponse(' ', 'ivar data')
|
||||
|
||||
def testIrccatBadCmdline(self):
|
||||
cmd = 'IRCCAT_PASSWORD=ivarpw plugins/Irccat/irccat' \
|
||||
' localhost 23456'
|
||||
with self.assertRaises(subprocess.CalledProcessError):
|
||||
subprocess.check_output(cmd, shell = True)
|
||||
|
||||
def testIrccatBadPort(self):
|
||||
cmd = 'IRCCAT_PASSWORD=ivarpw plugins/Irccat/irccat' \
|
||||
' localhost 23456xx ivar ivar data'
|
||||
with self.assertRaises(subprocess.CalledProcessError):
|
||||
subprocess.check_output(cmd, shell = True)
|
||||
|
||||
|
||||
class IrccatTestData(PluginTestCase):
|
||||
plugins = ('Irccat', 'User')
|
||||
|
||||
|
|
Loading…
Reference in New Issue