Beispiel #1
0
    def _verify_github_signature(self):
        """Verify GitHub signature"""
        if self._secret_token:
            payload = request.body.read()
            signature = request.headers.get('X-Hub-Signature', '')
            mac = hmac.new(self._secret_token, msg=payload, digestmod=hashlib.sha1)

            if not hmac.compare_digest('sha1=' + mac.hexdigest(), signature):
                logger.error('Invalid GitHub secret token')
                abort('403', 'Invalid GitHub secret token')
Beispiel #2
0
    def broadcast_msg(self):
        """
        Send private message to every user in roster.
        """
        msg = request.forms.get('msg', None)

        if not msg:
            logger.warning('Missing msg parameter in broadcast request')
            abort(400, 'Missing msg parameter')

        return 'Message sent (%dx)' % self.xmpp.msg_broadcast(msg)
Beispiel #3
0
    def roomtalk(self):
        """
        Send message to chat room.
        """
        msg = request.forms.get('msg', None)

        if not msg:
            logger.warning('Missing msg parameter in room request')
            abort(400, 'Missing msg parameter')

        self.xmpp.msg_send(self.xmpp.room, msg, mtype='groupchat')

        return 'Message sent'
Beispiel #4
0
    def roomtalk(self):
        """
        Send message to chat room.
        """
        msg = request.forms.get('msg', None)

        if not msg:
            logger.warning('Missing msg parameter in room request')
            abort(400, 'Missing msg parameter')

        self.xmpp.msg_send(self.xmpp.room, msg, mtype='groupchat')

        return 'Message sent'
Beispiel #5
0
    def send_msg(self):
        """
        Send xmpp message to user/room.
        """
        jid = request.forms.get('jid', None)

        if not jid:
            abort(400, 'Missing JID in message request')

        msg = request.forms.get('msg', '')

        try:
            return self._message_send(jid, msg)
        except CommandError as e:
            abort(400, str(e))
Beispiel #6
0
    def gitlab_web_hook(self):
        event = request.headers.get('X-Gitlab-Event', None)
        logger.info('Incoming GitLab Event: %s', event)

        self._verify_secret_token()

        data = request.json
        logger.debug('GitLab %s payload: %s', event, data)

        if event == 'Push Hook':
            return self._event_push(data)
        elif event == 'Tag Push Hook':
            return self._event_tag_push(data)

        logger.error('Unsupported GitLab Web Hook request (%s)', event)
        abort(400, 'Unsupported GitLab Web Hook request (%s)' % event)
Beispiel #7
0
    def doorman_update(self):
        """
        Webhook to receive updates from Doorman service if sensor status change.
        """
        user = request.forms.get('user', None)
        msg = request.forms.get('msg', None)

        if not user:
            abort(400, 'Missing user parameter in request')

        if not msg:
            abort(400, 'Missing msg parameter in request')

        self.xmpp.msg_send(user, msg)

        return 'Message sent'
Beispiel #8
0
    def github_web_hook(self):
        event = request.headers.get('X-GitHub-Event', None)
        logger.info('Incoming GitHub Event: %s', event)
        self._verify_github_signature()

        data = request.json
        logger.debug('GitHub %s payload: %s', event, data)

        if event == 'push':
            return self._event_push(data)
        elif event == 'issues':
            return self._event_issue_handler(data)
        elif event == 'issue_comment':
            return self._event_issue_comment(data)
        elif event == 'fork':
            return self._event_repo_fork(data)
        elif event == 'ping':
            self._room_message(['**[GitHub]** Ping received!'])
            return 'OK'

        logger.error('Unsupported GitHub Web Hook request (%s)', event)
        abort(400, 'Unsupported GitHub Web Hook request (%s)' % event)
Beispiel #9
0
 def _verify_secret_token(self):
     if self._secret_token and self._secret_token != request.headers.get('X-Gitlab-Token', None):
         logger.error('Invalid GitLab secret token')
         abort('403', 'Invalid GitLab secret token')