Exemplo n.º 1
0
 def unsubscribe(self, channel_name, name, send_hook=False):
     if not self.server.exists_channel(channel_name):
         raise ExpectedException("Channel %s doesn't exist" %
                                 (channel_name, ))
     if not self.server.exists_user(name):
         raise ExpectedException("User %s doesn't exist" % (name, ))
     channel = self.server.get_channel(None, channel_name)
     user = self.server.get_user(name)
     channel.unsubscribe(user, needs_auth=send_hook)
Exemplo n.º 2
0
 def frame_LOGIN(self, id, args):
     if self.logged_in:
         raise ExpectedException("Already logged in")
     if not self.config['admin_password'] or self.config[
             'admin_password'] != args['password']:
         raise ExpectedException("Invalid admin password")
     self.logged_in = True
     self._admin_app.login(self)
     self.send_frame("CONNECTED", {'version': hookbox.__version__})
     self.start_loop('overview')
Exemplo n.º 3
0
    def render_subscribe(self, form, start_response):
        channel_name = form.get('channel_name', None)
        if not channel_name:
            raise ExpectedException("Missing channel_name")
        name = form.get('name', None)
        if not name:
            raise ExpectedException("Missing name")
        send_hook = form.get('send_hook', '0') == '1'

        self.api.subscribe(channel_name, name, send_hook)
        start_response('200 Ok', [])
        return json.dumps([True, {}])
Exemplo n.º 4
0
 def render_set_channel_options(self, form, start_response):
     channel_name = form.pop('channel_name', None)
     if not channel_name:
         raise ExpectedException("Missing channel_name")
     for key, val in form.items():
         try:
             form[key] = json.loads(val)
         except:
             raise ExpectedException("Invalid json value for option %s" % (key,))
     self.api.set_channel_options(channel_name, form)
     start_response('200 Ok', [])
     return json.dumps([True, {}])
Exemplo n.º 5
0
    def render_message(self, form, start_response):
        sender_name = form.get('sender_name', None)
        if not sender_name:
            raise ExpectedException("Missing sender_name")
        recipient_name = form.get('recipient_name', None)
        if not recipient_name:
            raise ExpectedException("Missing recipient_name")
        payload = form.get('payload', 'null')
        send_hook = form.get('send_hook', '0') == '1'

        self.api.message(sender_name, recipient_name, payload, send_hook)
        start_response('200 Ok', [])
        return json.dumps([True, {}])
Exemplo n.º 6
0
 def render_state_set_key(self, form, start_response):
     channel_name = form.pop('channel_name', None)
     if not channel_name:
         raise ExpectedException("Missing channel_name")
     if 'key' not in form:
         raise ExpectedExcpetion("Missing 'key' argument")
     if 'val' not in form:
         raise ExpectedException("Missing 'val' argument")
     try:
         val = json.loads(form['val'])
     except:
         raise ExpectedException('Invalid json: "%s"' % (val, ))
     self.api.state_set_key(channel_name, form['key'], val)
     start_response('200 Ok', [])
     return json.dumps([True, {}])
Exemplo n.º 7
0
 def render_get_channel_info(self, form, start_response):
     channel_name = form.get('channel_name', None)
     if not channel_name:
         raise ExpectedException("Missing channel_name")
     info = self.api.get_channel_info(channel_name)
     start_response('200 Ok', [])
     return json.dumps([True, info])
Exemplo n.º 8
0
 def create_channel(self, channel_name, options, send_hook=False):
     if self.server.exists_channel(channel_name):
         raise ExpectedException("Channel %s already exists" %
                                 (channel_name, ))
     self.server.create_channel(None,
                                channel_name,
                                options,
                                needs_auth=send_hook)
Exemplo n.º 9
0
 def message(self,
             sender_name,
             recipient_name,
             payload='null',
             send_hook=False):
     if not self.server.exists_user(sender_name):
         raise ExpectedException("User %s doesn't exist" % (sender_name, ))
     sender = self.server.get_user(sender_name)
     sender.send_message(recipient_name, payload, needs_auth=send_hook)
Exemplo n.º 10
0
 def render_state_delete_key(self, form, start_response):
     channel_name = form.pop('channel_name', None)
     if not channel_name:
         raise ExpectedException("Missing channel_name")
     if 'key' not in form:
         raise ExpectedExcpetion("Missing 'key' argument")
     self.api.state_delete_key(channel_name, key)
     start_response('200 Ok', [])
     return json.dumps([True, {}])
Exemplo n.º 11
0
Arquivo: web.py Projeto: zorun/hookbox
 def render_publish(self, form, start_response):
     channel_name = form.get('channel_name', None)
     if not channel_name:
         raise ExpectedException("Missing channel_name")
     payload = form.get('payload', 'null')
     originator = form.get('originator', None)
     send_hook = form.get('send_hook', '0') == '1'
     self.api.publish(channel_name, payload, originator, send_hook)
     start_response('200 Ok', [])
     return json.dumps([True, {}])
Exemplo n.º 12
0
 def render_set_config(self, form, start_response):
     
     for key in form:
         try:
             form[key] = json.loads(form[key])
         except:
             raise ExpectedException("Invalid json value for form key '%s'" % (key,))
     self.api.set_config(form)
     start_response('200 Ok', [])
     return json.dumps([True, {}])
Exemplo n.º 13
0
 def render_publish_multi(self, form, start_response):
     channel_names = form.get('channel_names', None)
     assert(isinstance(channel_names, str))
     if not channel_names:
         raise ExpectedException("Missing channel_names")
     channel_name_list = channel_names.split(',')
     payload = form.get('payload', 'null')
     originator = form.get('originator', None)
     send_hook = form.get('send_hook', '0') == '1'
     self.api.publish_multi(channel_name_list, payload, originator, send_hook)
     start_response('200 Ok', [])
     return json.dumps([True, {}])
Exemplo n.º 14
0
 def publish(self,
             channel_name,
             payload='null',
             originator=None,
             send_hook=False):
     if not self.server.exists_channel(channel_name):
         if not self.config.ignore_publish_non_existing_channels:
             raise ExpectedException("Channel %s doesn't exist" %
                                     (channel_name, ))
         else:
             return
     channel = self.server.get_channel(None, channel_name)
     channel.publish(self,
                     payload,
                     needs_auth=send_hook,
                     originator=originator)
Exemplo n.º 15
0
 def destroy_channel(self, channel_name, send_hook=False):
     # NOTE: "already exists" errors will be raised as necessary by this method call
     if not self.server.exists_channel(channel_name):
         raise ExpectedException("Channel %s doesn't exist" %
                                 (channel_name, ))
     self.server.destroy_channel(channel_name, needs_auth=send_hook)
Exemplo n.º 16
0
 def set_channel_options(self, channel_name, options):
     if not self.server.exists_channel(channel_name):
         raise ExpectedException("Channel %s doesn't exists" %
                                 (channel_name, ))
     channel = self.server.get_channel(None, channel_name)
     channel.update_options(**options)
Exemplo n.º 17
0
 def get_channel_info(self, channel_name):
     if not self.server.exists_channel(channel_name):
         raise ExpectedException("Channel %s doesn't exists" %
                                 (channel_name, ))
     channel = self.server.get_channel(None, channel_name)
     return channel.serialize()
Exemplo n.º 18
0
 def state_delete_key(self, channel_name, key):
     if not self.server.exists_channel(channel_name):
         raise ExpectedException("Channel %s doesn't exists" %
                                 (channel_name, ))
     channel = self.server.get_channel(None, channel_name)
     channel.state_del(key)
Exemplo n.º 19
0
 def get_user_info(self, user_name):
     if not self.server.exists_user(user_name):
         raise ExpectedException("User %s doesn't exists" % (user_name, ))
     user = self.server.get_user(user_name)
     return user.serialize()
Exemplo n.º 20
0
 def set_user_options(self, user_name, options):
     if not self.server.exists_user(user_name):
         raise ExpectedException("User %s doesn't exists" % (user_name, ))
     user = self.server.get_user(user_name)
     user.update_options(**options)
Exemplo n.º 21
0
 def disconnect_user(self, name):
     raise ExpectedException("Not Implemented")
     if not self.server.exists_user(name):
         raise ExpectedException("User %s doesn't exist" % (name, ))
     user = self.server.get_user(name)
Exemplo n.º 22
0
 def disconnect(self, identifier):
     raise ExpectedException("Not Implemented")
Exemplo n.º 23
0
 def authorize(self, secret):
     if secret != self.config['api_security_token']:
         raise ExpectedException("Invalid Security Token")