summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimeon Simeonov2015-04-18 21:12:03 +0200
committerSimeon Simeonov2015-04-18 21:12:03 +0200
commit34846014399f8756962051df02d251b91b65bb0c (patch)
treec3659df8e9ab10713d40cb17343bfa9f2e8d37d9
parent5d19e4e05f8fcd44e6a596f5e919fb91e45e54b7 (diff)
Update documentation changelog and examples. Final touches
-rw-r--r--Changelog11
-rw-r--r--INSTALL17
-rw-r--r--README17
-rw-r--r--beinc_config_sample.json46
-rw-r--r--beinc_config_sample.json.readme19
-rwxr-xr-xbeinc_server.py14
-rw-r--r--beinc_weechat.py33
7 files changed, 99 insertions, 58 deletions
diff --git a/Changelog b/Changelog
new file mode 100644
index 0000000..f678c6e
--- /dev/null
+++ b/Changelog
@@ -0,0 +1,11 @@
1v2.0:
2 - replace charrypy with TwistedWeb as beinc_server.py backend
3 - use XMLRPC instead of HTTP POST for a cleaner and more robust API
4 - several ssl options like ssl_version and ssl_ciphers added
5 - bugfixes
6
7v1.1:
8 - when beinc_poller.py fetches several messages from a queue it won't let the last one to completely overwrite the previous ones
9
10v1.0
11 - Initial version
diff --git a/INSTALL b/INSTALL
index d00a3d9..f26a6f9 100644
--- a/INSTALL
+++ b/INSTALL
@@ -9,16 +9,16 @@ Installing the dependencies
9~~~~~~~~~~~~~~~~~~~~~~~~~~~ 9~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 10
11 11
12Gentoo GNU/Linux 2013, 2014 12Gentoo GNU/Linux 2014, 2015
13.......................... 13..........................
14 14
15# emerge -va dev-python/pyopenssl dev-python/cherrypy dev-python/notify-python dev-python/pyosd 15# emerge -va dev-python/pyopenssl dev-python/twisted-web dev-python/notify-python dev-python/pyosd
16 16
17 17
18Ubuntu GNU/Linux 18Ubuntu GNU/Linux
19................ 19................
20 20
21# apt-get install python-openssl python-cherrypy python-notify2 python-pyosd 21# apt-get install python-openssl python-twisted-web python-notify2 python-pyosd
22 22
23 23
24FreeBSD 9, 10 24FreeBSD 9, 10
@@ -27,7 +27,7 @@ FreeBSD 9, 10
27# cd /usr/ports/security/py-openssl 27# cd /usr/ports/security/py-openssl
28# make install clean 28# make install clean
29 29
30# cd /usr/ports/www/py-cherrypy 30# cd /usr/ports/www/py-twistedWeb
31# make install clean 31# make install clean
32 32
33# cd /usr/ports/devel/py-notify 33# cd /usr/ports/devel/py-notify
@@ -45,7 +45,7 @@ This is where virtualenv may become handy (provided that it has been installed):
45$ virtualenv beinc_installation 45$ virtualenv beinc_installation
46$ cd beinc_installation 46$ cd beinc_installation
47$ source bin/activate 47$ source bin/activate
48$ pip install cherrypy 48$ pip install Twisted
49$ pip install pyopenssl 49$ pip install pyopenssl
50$ cd beinc-<version> 50$ cd beinc-<version>
51$ ./beinc_server.py -h 51$ ./beinc_server.py -h
@@ -71,13 +71,14 @@ Create a configuration file based on beinc_config_sample.json, defining your ins
71Start the BEINC server: 71Start the BEINC server:
72$ ./beinc_server.py -H 10.0.0.44 -p 9678 72$ ./beinc_server.py -H 10.0.0.44 -p 9678
73The example loads the server listening on 10.0.0.44, port 9678 using the default 73The example loads the server listening on 10.0.0.44, port 9678 using the default
74~/.beinc_server.json as a configuration file and usually gives you the cherrypy console 74~/.beinc_server.json as a configuration file and usually gives you the Twisted
75log console
75 76
76beinc_poller.py: 77beinc_poller.py:
77$ ./beinc_poller.py -h 78$ ./beinc_poller.py -h
78The example lists all available command options 79The example lists all available command options
79$ ./beinc_poller.py -t 10 -f 7 --cert-file /home/sgs/weechat_cert.crt \ 80$ ./beinc_poller.py -n weechat -t 10 -f 7 --cert-file /home/sgs/weechat_cert.crt \
80 -P /home/sgs/.weechat_beinc_passwd https://10.0.0.44:9678/pull/weechat 81 -p /home/sgs/.weechat_beinc_passwd https://10.0.0.44:9678
81Starts polling from the instance (target) defined above, 82Starts polling from the instance (target) defined above,
82defining an OSD timeout of 10 seconds, polling frequency of 7 seconds, 83defining an OSD timeout of 10 seconds, polling frequency of 7 seconds,
83checking whether the server's SSL certificate was signed (issued) by /home/sgs/weechat_cert.crt, 84checking whether the server's SSL certificate was signed (issued) by /home/sgs/weechat_cert.crt,
diff --git a/README b/README
index 492e892..f3e241e 100644
--- a/README
+++ b/README
@@ -80,25 +80,24 @@ There are 2 operations that can be done on an instance:
80 A pull is available only for instances defined for queueing. 80 A pull is available only for instances defined for queueing.
81 (read beinc_config_sample.json.readme for details!) 81 (read beinc_config_sample.json.readme for details!)
82Example: 82Example:
83If you defined a beinc_server.py instance with SSL-support called "beinc_test", 83If you defined a beinc_server.py instance with SSL-support,
84your URL for pushing will be: https://hostname:port/push/beinc_test 84your URL will be: https://hostname:port
85and for polling: https://hostname:port/pull/beinc_test
86 85
87 86
88Supported systems & requirements 87Supported systems & requirements
89-------------------------------- 88--------------------------------
90Any system running the software required for the selected components. 89Any system running the software required for the selected components.
91All components tested on: Gentoo GNU/Linux 2013,2014, 90All components tested on: Gentoo GNU/Linux 2014,2015,
92 Ubuntu GNU/Linux 14.4,13.10, 91 Ubuntu GNU/Linux 14.4,14.10,
93 FreeBSD 9.x 92 FreeBSD 10.x
94 93
95 94
96Requirements: 95Requirements:
97All components: Python 2.7.* 96All components: Python 2.7.* (for TLS1.1 and TLS1.2 client support you ned Python>=2.7.9)
98beinc_server.py: cherrypy >= 3.2.0, pyopenssl >= 0.13.0 (opntional (ssl support)), 97beinc_server.py: Twisted Web >= 14.0, pyopenssl >= 0.13.0,
99 pynotify >= 0.1 (optional), pyosd >= 0.2 (optional) 98 pynotify >= 0.1 (optional), pyosd >= 0.2 (optional)
100beinc_weechat.py: Weechat >= 0.4.0 99beinc_weechat.py: Weechat >= 0.4.0
101beinc_poller.py: pynotify >= 0.1 (optional), pyosd >= 0.2 (optional) 100beinc_poller.py: pynotify >= 0.1 or pyosd >= 0.2
102beinc_generic_client.py: No additional software required 101beinc_generic_client.py: No additional software required
103 102
104Read INSTALL in this very same folder for more details about installing the requirements! 103Read INSTALL in this very same folder for more details about installing the requirements!
diff --git a/beinc_config_sample.json b/beinc_config_sample.json
index 046e3fa..ecfe9bb 100644
--- a/beinc_config_sample.json
+++ b/beinc_config_sample.json
@@ -1,23 +1,35 @@
1{ 1{
2 "server": { 2 "server": {
3 "general": { 3 "general": {
4 "ssl_private_key": "key.pem", 4 "ssl_private_key": "/home/user/.key.pem",
5 "ssl_certificate": "cert.crt", 5 "ssl_certificate": "/home/user/.cert.pem",
6 "ssl_acceptable_ciphers": "auto", 6 "ssl_version": "TLSv1_2",
7 "ssl_version": "auto" 7 "ssl_ciphers": "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384"
8 }, 8 },
9 "instances": [ 9 "instances": [
10 { 10 {
11 "name": "test", 11 "name": "instance1",
12 "password": "changeme",
13 "osd_system": "pynotify",
14 "osd_timeout": 5
15 },
16 {
17 "name": "instance2",
12 "password": "changeme", 18 "password": "changeme",
13 "osd_system": "pyosd", 19 "osd_system": "pyosd",
14 "osd_timeout": 5, 20 "osd_timeout": 6,
15 "pyosd_font": "", 21 "pyosd_font": "-adobe-courier-bold-o-normal--24-240-75-75-m-150-iso8859-1",
16 "pyosd_vertical_offset": 120, 22 "pyosd_vertical_offset": 120,
17 "pyosd_horizontal_offset": 30, 23 "pyosd_horizontal_offset": 30,
18 "pyosd_align": "left", 24 "pyosd_align": "left",
19 "pyosd_position": "bottom", 25 "pyosd_position": "top",
20 "pyosd_color": "blue", 26 "pyosd_color": "blue"
27 },
28 {
29 "name": "instance3",
30 "password": "changeme",
31 "osd_system": "none",
32 "osd_timeout": 5,
21 "queue_size": 4 33 "queue_size": 4
22 } 34 }
23 ] 35 ]
@@ -29,26 +41,28 @@
29 "name": "weechat_main", 41 "name": "weechat_main",
30 "target_url": "https://10.0.0.2:9898", 42 "target_url": "https://10.0.0.2:9898",
31 "target_password": "changeme", 43 "target_password": "changeme",
32 "target_cert_file": "", 44 "target_cert_file": "/home/user/.ca_cert.pem",
33 "target_timestamp_format": "%H:%M:%S", 45 "target_timestamp_format": "%H:%M:%S",
34 "socket_timeout": 30, 46 "ssl_version": "TLSv1_2",
47 "ssl_ciphers": "auto",
48 "disable-hostname-check": 0,
49 "socket_timeout": 2,
35 "pm_title_template": "%s @ %S", 50 "pm_title_template": "%s @ %S",
36 "pm_message_template": "%m", 51 "pm_message_template": "%m",
37 "cm_title_template": "%c @ %S", 52 "cm_title_template": "%c @ %S",
38 "cm_message_template": "%s -> %m", 53 "cm_message_template": "%s -> %m",
39 "nm_title_template": "%c @ %S", 54 "nm_title_template": "%c @ %S",
40 "nm_message_template": "%s -> %m", 55 "nm_message_template": "%s -> %m",
41 "channel_list": ["RedpillLinpro.#python", 56 "channel_list": ["Freenode.#python",
42 "Exile.#test", 57 "Exile.#test",
43 "RedpillLinpro.#adult", 58 "Freenode.#gentoo",
44 "Exile.#pichove"], 59 "Exile.#pichove"],
45 "nick_list": ["Exile.Blackmore"], 60 "nick_list": ["Exile.Blackmore"],
46 "channel_messages_policy": 2, 61 "channel_messages_policy": 2,
47 "private_messages_policy": 1, 62 "private_messages_policy": 1,
48 "notifications_policy": 1, 63 "notifications_policy": 1,
49 "debug": 1, 64 "debug": 0,
50 "enabled": 1, 65 "enabled": 1
51 "socket_timeout": 3
52 } 66 }
53 ] 67 ]
54 }, 68 },
diff --git a/beinc_config_sample.json.readme b/beinc_config_sample.json.readme
index 9c5aecc..edf5845 100644
--- a/beinc_config_sample.json.readme
+++ b/beinc_config_sample.json.readme
@@ -30,7 +30,7 @@ documentation to better illustrate the comments.
30 30
31 # Encryption method for the BEINC server 31 # Encryption method for the BEINC server
32 # Possible values: 32 # Possible values:
33 # "auto" - Let Twisted decide (use the newest possible method) 33 # "" or "auto" - Let Twisted decide (use the newest possible method)
34 # "SSLv3" - SSLv3 (weak) 34 # "SSLv3" - SSLv3 (weak)
35 # "TLSv1" - TLSv1.0 35 # "TLSv1" - TLSv1.0
36 # "TLSv1_1" - TLSv1.1 36 # "TLSv1_1" - TLSv1.1
@@ -98,16 +98,17 @@ documentation to better illustrate the comments.
98 "targets": [ 98 "targets": [
99 { 99 {
100 # Unique name for the defined target 100 # Unique name for the defined target
101 # Default: 4 characters random string 101 # Default: "" (making the target useless)
102 # Defining your own name will make life easier for you 102 # The name should match the name of the server instance you
103 # want to connect to
103 "name": "weechat_main", 104 "name": "weechat_main",
104 105
105 # Target URL. 106 # Target URL.
106 # Default: None (making the target useless) 107 # Default: "" (making the target useless)
107 "target_url": "https://10.0.0.2:9998", 108 "target_url": "https://10.0.0.2:9998",
108 109
109 # Password corresponding to the target BEINC instance 110 # Password corresponding to the target BEINC instance
110 # Default: None 111 # Default: ""
111 "target_password": "beincpasswd", 112 "target_password": "beincpasswd",
112 113
113 # The filename of the SSL certificate authority (CA) used to 114 # The filename of the SSL certificate authority (CA) used to
@@ -118,11 +119,11 @@ documentation to better illustrate the comments.
118 "target_cert_file": "", 119 "target_cert_file": "",
119 120
120 # A list of preferred ciphers for this target 121 # A list of preferred ciphers for this target
121 # Default: "" (use the OpenSSL default ciphers) 122 # Default: "auto" or "" (use the OpenSSL default ciphers)
122 "ssl_ciphers": "ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384", 123 "ssl_ciphers": "ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384",
123 124
124 # Don't check whether the target's hostname matches the server's 125 # Don't check whether the target's hostname matches the server's
125 # certificate. (Only Python >= 2.7.9) 126 # certificate. (Only for Python >= 2.7.9)
126 # Default: 0 127 # Default: 0
127 "disable-hostname-check": 0, 128 "disable-hostname-check": 0,
128 129
@@ -168,9 +169,9 @@ documentation to better illustrate the comments.
168 169
169 # Channel list 170 # Channel list
170 # Default: [] (empty) 171 # Default: [] (empty)
171 "channel_list": ["RedpillLinpro.#python", 172 "channel_list": ["Freenode.#python",
172 "Exile.#test", 173 "Exile.#test",
173 "RedpillLinpro.#adult", 174 "Freenode.#gentoo",
174 "Exile.#pichove"], 175 "Exile.#pichove"],
175 176
176 # Nick list 177 # Nick list
diff --git a/beinc_server.py b/beinc_server.py
index 53f12c5..84f7a82 100755
--- a/beinc_server.py
+++ b/beinc_server.py
@@ -59,6 +59,8 @@ BEINC_OSD_TYPE_NONE = 0
59BEINC_OSD_TYPE_PYNOTIFY = 1 59BEINC_OSD_TYPE_PYNOTIFY = 1
60BEINC_OSD_TYPE_PYOSD = 2 60BEINC_OSD_TYPE_PYOSD = 2
61 61
62BEINC_CURRENT_CONFIG_VERSION = 2
63
62BEINC_SSL_METHODS = {'SSLv3': OpenSSL.SSL.SSLv3_METHOD, 64BEINC_SSL_METHODS = {'SSLv3': OpenSSL.SSL.SSLv3_METHOD,
63 'TLSv1': OpenSSL.SSL.TLSv1_METHOD} 65 'TLSv1': OpenSSL.SSL.TLSv1_METHOD}
64try: 66try:
@@ -351,11 +353,15 @@ def main():
351 e)) 353 e))
352 sys.exit(errno.EIO) 354 sys.exit(errno.EIO)
353 try: 355 try:
354 if config_dict.get('config_version') != 2: 356 if config_dict.get('config_version') != BEINC_CURRENT_CONFIG_VERSION:
355 sys.stderr.write( 357 sys.stderr.write(
356 'Incompatible or missing config-file version for {0}\n'.format( 358 'WARNING: The version of the config-file: {0} ({1}) '
357 args.config_file)) 359 'does not correspond to the latest version supported '
358 sys.exit(1) 360 'by this program ({2})\nCheck beinc_config_sample.json '
361 'for the newest features!\n'.format(
362 args.config_file,
363 config_dict.get('config_version', 'Not set'),
364 BEINC_CURRENT_CONFIG_VERSION))
359 ssl_certificate = config_dict['server']['general'].get( 365 ssl_certificate = config_dict['server']['general'].get(
360 'ssl_certificate') 366 'ssl_certificate')
361 ssl_private_key = config_dict['server']['general'].get( 367 ssl_private_key = config_dict['server']['general'].get(
diff --git a/beinc_weechat.py b/beinc_weechat.py
index 52e83b6..1e8afb8 100644
--- a/beinc_weechat.py
+++ b/beinc_weechat.py
@@ -120,11 +120,15 @@ class WeechatTarget(object):
120 """ 120 """
121 target_dict: the config-dictionary node that represents this instance 121 target_dict: the config-dictionary node that represents this instance
122 """ 122 """
123 self.__name = target_dict.get( 123 self.__name = target_dict.get('name', '')
124 'name', 124 if self.__name == '':
125 ''.join([chr(random.randrange(97, 123)) for x in range(4)])) 125 beinc_prnt('WARNING: Adding a target with no name '
126 self.__url = target_dict.get('target_url') 126 'will make the target useless')
127 self.__password = target_dict.get('target_password') 127 self.__url = target_dict.get('target_url', '')
128 if self.__url == '':
129 beinc_prnt('WARNING: Adding a target with no URL '
130 'will make the target useless')
131 self.__password = target_dict.get('target_password', '')
128 self.__pm_title_template = target_dict.get('pm_title_template', 132 self.__pm_title_template = target_dict.get('pm_title_template',
129 '%s @ %S') 133 '%s @ %S')
130 self.__pm_message_template = target_dict.get('pm_message_template', 134 self.__pm_message_template = target_dict.get('pm_message_template',
@@ -158,6 +162,7 @@ class WeechatTarget(object):
158 self.__disable_hostname_check = bool( 162 self.__disable_hostname_check = bool(
159 target_dict.get('disable-hostname-check', False)) 163 target_dict.get('disable-hostname-check', False))
160 self.__ssl_version = target_dict.get('ssl_version', 'auto') 164 self.__ssl_version = target_dict.get('ssl_version', 'auto')
165 self.__last_message = None # datetime.datetime instance
161 self.__connection = None # xmlrpclib.ServerProxy instance 166 self.__connection = None # xmlrpclib.ServerProxy instance
162 self.__connection_setup() 167 self.__connection_setup()
163 168
@@ -227,11 +232,14 @@ class WeechatTarget(object):
227 def __repr__(self): 232 def __repr__(self):
228 """ 233 """
229 """ 234 """
235 last_message = 'never'
236 if self.__last_message is not None:
237 last_message = self.__last_message.strftime('%Y-%m-%d %H:%M:%S')
230 return ('name: {0}\nurl: {1}\nenabled: {2}\nchannel_list: {3}\n' 238 return ('name: {0}\nurl: {1}\nenabled: {2}\nchannel_list: {3}\n'
231 'nick_list: {4}\nchannel_messages_policy: {5}\n' 239 'nick_list: {4}\nchannel_messages_policy: {5}\n'
232 'private_messages_policy: {6}\nnotifications_policy: {7}\n' 240 'private_messages_policy: {6}\nnotifications_policy: {7}\n'
233 'connected: {8}\nsocket timeout: {9}\nssl-version: {10}\n' 241 'last message: {8}\nsocket timeout: {9}\nssl-version: {10}\n'
234 'ciphers: {11}\ndisable_hostname_check: {12}\n' 242 'ciphers: {11}\ndisable hostname check: {12}\n'
235 'debug: {13}\n\n'.format( 243 'debug: {13}\n\n'.format(
236 self.__name, 244 self.__name,
237 self.__url, 245 self.__url,
@@ -241,11 +249,11 @@ class WeechatTarget(object):
241 self.__chan_messages_policy, 249 self.__chan_messages_policy,
242 self.__priv_messages_policy, 250 self.__priv_messages_policy,
243 self.__notifications_policy, 251 self.__notifications_policy,
244 'no' if self.__connection is None else 'yes', 252 last_message,
245 self.__socket_timeout, 253 self.__socket_timeout,
246 self.__ssl_version, 254 self.__ssl_version,
247 self.__ssl_ciphers or 'default', 255 self.__ssl_ciphers or 'auto',
248 'yes' if self.__disable_hostname_check else 'no' 256 'yes' if self.__disable_hostname_check else 'no',
249 'yes' if self.__debug else 'no')) 257 'yes' if self.__debug else 'no'))
250 258
251 def send_private_message_notification(self, values): 259 def send_private_message_notification(self, values):
@@ -357,7 +365,7 @@ class WeechatTarget(object):
357 self.__cert_file)) 365 self.__cert_file))
358 context.check_hostname = bool( 366 context.check_hostname = bool(
359 not self.__disable_hostname_check) 367 not self.__disable_hostname_check)
360 if self.__ssl_ciphers: 368 if self.__ssl_ciphers and self.__ssl_ciphers != 'auto':
361 context.set_ciphers(self.__ssl_ciphers) 369 context.set_ciphers(self.__ssl_ciphers)
362 transport = xmlrpclib.SafeTransport(context=context) 370 transport = xmlrpclib.SafeTransport(context=context)
363 else: 371 else:
@@ -368,7 +376,7 @@ class WeechatTarget(object):
368 ssl_options['ca_certs'] = os.path.expanduser( 376 ssl_options['ca_certs'] = os.path.expanduser(
369 self.__cert_file) 377 self.__cert_file)
370 ssl_options['cert_reqs'] = ssl.CERT_REQUIRED 378 ssl_options['cert_reqs'] = ssl.CERT_REQUIRED
371 if self.__ssl_ciphers: 379 if self.__ssl_ciphers and self.__ssl_ciphers != 'auto':
372 ssl_options['ciphers'] = self.__ssl_ciphers 380 ssl_options['ciphers'] = self.__ssl_ciphers
373 transport = BEINCCustomSafeTransport( 381 transport = BEINCCustomSafeTransport(
374 custom_ssl_options=ssl_options) 382 custom_ssl_options=ssl_options)
@@ -432,6 +440,7 @@ class WeechatTarget(object):
432 message) 440 message)
433 if self.__debug: 441 if self.__debug:
434 beinc_prnt('BEINC DEBUG: Server responded: {0}'.format(result)) 442 beinc_prnt('BEINC DEBUG: Server responded: {0}'.format(result))
443 self.__last_message = datetime.datetime.now()
435 return True 444 return True
436 except xmlrpclib.Fault as fault: 445 except xmlrpclib.Fault as fault:
437 if self.__debug: 446 if self.__debug: