summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--beinc_config_sample.json3
-rw-r--r--beinc_config_sample.json.readme134
-rw-r--r--beinc_weechat.py14
3 files changed, 140 insertions, 11 deletions
diff --git a/beinc_config_sample.json b/beinc_config_sample.json
index 6266589..f9423a2 100644
--- a/beinc_config_sample.json
+++ b/beinc_config_sample.json
@@ -47,7 +47,8 @@
47 "private_messages_policy": 1, 47 "private_messages_policy": 1,
48 "notifications_policy": 1, 48 "notifications_policy": 1,
49 "debug": 1, 49 "debug": 1,
50 "enabled": 1 50 "enabled": 1,
51 "socket_timeout": 3
51 } 52 }
52 ] 53 ]
53 }, 54 },
diff --git a/beinc_config_sample.json.readme b/beinc_config_sample.json.readme
index 7cfe23b..12a1b2d 100644
--- a/beinc_config_sample.json.readme
+++ b/beinc_config_sample.json.readme
@@ -13,7 +13,7 @@ documentation to better illustrate the comments.
13 13
14{ 14{
15 "server": { # This whole section is used by the server only. 15 "server": { # This whole section is used by the server only.
16 # It is only used by beinc_server.py and ignore by all other 16 # It is only used by beinc_server.py and ignored by all other
17 # components 17 # components
18 18
19 "general": { # Applies to the whole server (cherrypy) For more info: 19 "general": { # Applies to the whole server (cherrypy) For more info:
@@ -28,49 +28,167 @@ documentation to better illustrate the comments.
28 # The filename of the SSL certificate to use 28 # The filename of the SSL certificate to use
29 "ssl_certificate": "/home/user/certs/cert.crt" # default: None 29 "ssl_certificate": "/home/user/certs/cert.crt" # default: None
30 }, 30 },
31
32 # A list of instances. Check README for general information about them!
31 "instances": [ 33 "instances": [
32 { 34 {
33 "name": "test", 35 # A *unique* name that identifies the instance
34 "password": "changeme", 36 "name": "beinc_name",
37
38 # The password that the client must provide in order to be able
39 # to push to / pull from the instance
40 "password": "beincpasswd",
41
42 # Possible values:
43 # "none" - the instance will serve for queueing
44 # "pynotify" - OSD implemented using pynotify (libnotify)
45 # "pyosd" - OSD implemented using pyosd (xosd)
35 "osd_system": "pynotify", 46 "osd_system": "pynotify",
47
48 # OSD timeout in seconds
49 # The amount of time the OSD message will remain in the screen
36 "osd_timeout": 5, 50 "osd_timeout": 5,
51
52 # Specify a custom font for the pyosd - backend
53 # "xfontsel" can be used to obtain a list of available fonts
37 "pyosd_font": "", 54 "pyosd_font": "",
55
56 # Vertical offset (in pixels) for the pyosd - backend
38 "pyosd_vertical_offset": 120, 57 "pyosd_vertical_offset": 120,
58
59 # Horizontal offset (in pixels) for the pyosd - backend
39 "pyosd_horizontal_offset": 30, 60 "pyosd_horizontal_offset": 30,
61
62 # Text horizontal alignment for the pyosd - backend
63 # Possible values:
64 # "left", "center", "right"
40 "pyosd_align": "left", 65 "pyosd_align": "left",
66
67 # Text vertical position for the pyosd - backend
68 # Possible values:
69 # "top", "middle", "bottom"
41 "pyosd_position": "bottom", 70 "pyosd_position": "bottom",
71
72 # Font color for the pyosd - backend
73 # See "rgb.txt" in the X11 distribution of a list of colors
42 "pyosd_color": "blue", 74 "pyosd_color": "blue",
75
76 # How many entries to be kept in the queue
77 # (when "osd_system": "none")
43 "queue_size": 4 78 "queue_size": 4
44 } 79 }
45 ] 80 ]
46 }, 81 },
47 "irc_client": { 82 "irc_client": { # This whole section is used by the weechat client only
48 "use_current_buffer": 0, 83 # It is used only by beinc_weechat.py and ignored by all
84 # other components
85 "use_current_buffer": 0, # Show weechat-message in the current buffer
86 # instead of the system-buffer
87 # A list of targets. Check README for general information about them!
49 "targets": [ 88 "targets": [
50 { 89 {
90 # Unique name for the defined target
91 # Default: 4 characters random string
92 # Defining your own name will make life easier for you
51 "name": "weechat_main", 93 "name": "weechat_main",
94
95 # Target URL.
96 # Default: None (making the target useless)
52 "target_url": "https://10.0.0.2:9898/push/secondtest", 97 "target_url": "https://10.0.0.2:9898/push/secondtest",
53 "target_password": "changeme", 98
99 # Password corresponding to the target BEINC instance
100 # Default: None
101 "target_password": "beincpasswd",
102
103 # The filename of the SSL certificate authority (CA) used to
104 # sign the SSL certificate used by the BEINC server
105 # Default: "" (don't verify the certificate)
106 # It is *highly recommended* to use an SSL connection as well as
107 # to verify the server's certificate
54 "target_cert_file": "", 108 "target_cert_file": "",
109
110 # The timestamp-format used by the BEINC weechat client
111 # See
112 # https://docs.python.org/2.7/library/datetime.html#strftime-strptime-behavior
113 # for more details
55 "target_timestamp_format": "%H:%M:%S", 114 "target_timestamp_format": "%H:%M:%S",
115
116 # Supported macros:
117 # %c - channel name for chan. messages / your nick for prv. msgs
118 # %m - the message
119 # %n - your nick
120 # %p - program name (BEINC)
121 # %S - server name (as defined in Weechat)
122 # %s - source nick
123 # %t - timestamp as defined above
124 # ###
125
126 # Title (top OSD line) template for private messages
56 "pm_title_template": "%s @ %S", 127 "pm_title_template": "%s @ %S",
128
129 # Message (bottom OSD line) template for private messages
57 "pm_message_template": "%m", 130 "pm_message_template": "%m",
131
132 # Title (top OSD line) template for channel messages
58 "cm_title_template": "%c @ %S", 133 "cm_title_template": "%c @ %S",
134
135 # Message (bottom OSD line) template for channel messages
59 "cm_message_template": "%s -> %m", 136 "cm_message_template": "%s -> %m",
137
138 # Title (top OSD line) template for notification messages
60 "nm_title_template": "%c @ %S", 139 "nm_title_template": "%c @ %S",
140
141 # Message (bottom OSD line) template for notification messages
61 "nm_message_template": "%s -> %m", 142 "nm_message_template": "%s -> %m",
143
144 # Channel list
145 # Default: [] (empty)
62 "channel_list": ["RedpillLinpro.#python", 146 "channel_list": ["RedpillLinpro.#python",
63 "Exile.#test", 147 "Exile.#test",
64 "RedpillLinpro.#adult", 148 "RedpillLinpro.#adult",
65 "Exile.#pichove"], 149 "Exile.#pichove"],
150
151 # Nick list
152 # Default: [] (empty)
66 "nick_list": ["Exile.Blackmore"], 153 "nick_list": ["Exile.Blackmore"],
154
155 # Supported policy values:
156 #
157 # 0 - don't display any messages of the given category
158 # 1 - display all messages of the given category
159 # 2 - display only messages from channels/nicks that are
160 # present in the channel_list / nick_list
161
162 # Policy for channel messages
67 "channel_messages_policy": 2, 163 "channel_messages_policy": 2,
164
165 # Policy for private messages
68 "private_messages_policy": 1, 166 "private_messages_policy": 1,
167
168 # Policy for notification messages
69 "notifications_policy": 1, 169 "notifications_policy": 1,
70 "debug": 1, 170
71 "enabled": 1 171 # Produce debug messages for this target
172 "debug": 0,
173
174 # Enable this target by default
175 "enabled": 1,
176
177 # Timeout for this target's socket in seconds
178 # If the target host is not available
179 # (not returning ICMP packets), Weechat will block during the
180 # timeout, creating inconvenience.
181 # 2 seconds is a recommended value if you have a decent line
182 # between the beinc_weechat and beinc_server.
183 "socket_timeout": 3
72 } 184 }
73 ] 185 ]
74 }, 186 },
187 # The version of this config file
188 # Default: 1 (you should really never leave it undefined)
189 # Used by beinc_server and beinc_weechat to check whether
190 # the config (.json) file is outdated.
191 # Every future version of BEINC will be shipped with
192 # beinc_config_sample.json and beinc_config_sample.json.readme
75 "config_version": 1 193 "config_version": 1
76} 194}
diff --git a/beinc_weechat.py b/beinc_weechat.py
index a8082b7..71d4b10 100644
--- a/beinc_weechat.py
+++ b/beinc_weechat.py
@@ -44,6 +44,7 @@ global_values = dict()
44BEINC_POLICY_NONE = 0 44BEINC_POLICY_NONE = 0
45BEINC_POLICY_ALL = 1 45BEINC_POLICY_ALL = 1
46BEINC_POLICY_LIST_ONLY = 2 46BEINC_POLICY_LIST_ONLY = 2
47BEINC_CURRENT_CONFIG_VERSION = 1
47 48
48 49
49class ValidHTTPSConnection(httplib.HTTPConnection): 50class ValidHTTPSConnection(httplib.HTTPConnection):
@@ -117,7 +118,7 @@ class WeechatTarget(object):
117 '%H:%M:%S') 118 '%H:%M:%S')
118 self.__debug = bool(target_dict.get('debug', False)) 119 self.__debug = bool(target_dict.get('debug', False))
119 self.__enabled = bool(target_dict.get('enabled', True)) 120 self.__enabled = bool(target_dict.get('enabled', True))
120 self.__socket_timeout = int(target_dict.get('socket_timeout', 30)) 121 self.__socket_timeout = int(target_dict.get('socket_timeout', 3))
121 122
122 @property 123 @property
123 def name(self): 124 def name(self):
@@ -396,7 +397,7 @@ def beinc_command(data, buffer_obj, args):
396 elif args == 'reload': 397 elif args == 'reload':
397 beinc_prnt('Reloading BEINC...') 398 beinc_prnt('Reloading BEINC...')
398 beinc_init() 399 beinc_init()
399 elif cmd_tokens[0] == 'broadcast': 400 elif cmd_tokens[0] in ('broadcast', 'test'):
400 return beinc_cmd_broadcast_handler(cmd_tokens[1:]) 401 return beinc_cmd_broadcast_handler(cmd_tokens[1:])
401 elif cmd_tokens[0] == 'target': 402 elif cmd_tokens[0] == 'target':
402 return beinc_cmd_target_handler(cmd_tokens[1:]) 403 return beinc_cmd_target_handler(cmd_tokens[1:])
@@ -515,6 +516,15 @@ def beinc_init():
515 global_values['use_current_buffer'] = bool( 516 global_values['use_current_buffer'] = bool(
516 config_dict['irc_client'].get( 517 config_dict['irc_client'].get(
517 'use_current_buffer', False)) 518 'use_current_buffer', False))
519 if config_dict.get('config_version',
520 0) != BEINC_CURRENT_CONFIG_VERSION:
521 beinc_prnt('WARNING: The version of the config-file: {0} ({1}) '
522 'does not correspond to the latest version supported '
523 'by this program ({2})\nCheck beinc_config_sample.json '
524 'for the newest features!'.format(
525 beinc_config_file_str,
526 config_dict.get('config_version', 0),
527 BEINC_CURRENT_CONFIG_VERSION))
518 for target in config_dict['irc_client']['targets']: 528 for target in config_dict['irc_client']['targets']:
519 try: 529 try:
520 new_target = WeechatTarget(target) 530 new_target = WeechatTarget(target)