def _on_connect(self):
        logging.debug(
            'mjpg client for camera %(camera_id)s connected on port %(port)s' %
            {
                'port': self._port,
                'camera_id': self._camera_id
            })

        if self._auth_mode == 'basic':
            logging.debug('mjpg client using basic authentication')

            auth_header = utils.build_basic_header(self._username,
                                                   self._password)
            self.write(
                'GET / HTTP/1.1\r\nAuthorization: %s\r\nConnection: close\r\n\r\n'
                .encode("utf-8") % auth_header).encode("utf-8")

        elif self._auth_mode == 'digest':  # in digest auth mode, the header is built upon receiving 401
            self.write('GET / HTTP/1.1\r\n\r\n'.encode("utf-8"))

        else:  # no authentication
            # vector fix me: self.write('GET / HTTP/1.1\r\nConnection: close\r\n\r\n')
            self.write(
                'GET / HTTP/1.1\r\nConnection: close\r\n\r\n'.encode("utf-8"))

        self._seek_http()
Exemple #2
0
    def _on_www_authenticate(self, data):
        if self._check_error():
            return
        
        m = re.match('Basic\s*realm="([a-zA-Z0-9\-\s]+)"', data.strip())
        if m:
            logging.debug('mjpg client using basic authentication')
            
            auth_header = utils.build_basic_header(self._username, self._password)
            self.write('GET / HTTP/1.0\r\n\r\nAuthorization: %s\r\n\r\n' % auth_header)
            self._seek_http()

            return

        m = re.match('Digest\s*realm="([a-zA-Z0-9\-\s]+)",\s*nonce="([a-zA-Z0-9]+)"', data.strip())
        if m:
            logging.debug('mjpg client using digest authentication')

            realm, nonce = m.groups()
            self._auth_digest_state['realm'] = realm
            self._auth_digest_state['nonce'] = nonce
    
            auth_header = utils.build_digest_header('GET', '/', self._username, self._password, self._auth_digest_state)
            self.write('GET / HTTP/1.0\r\n\r\nAuthorization: %s\r\n\r\n' % auth_header)
            self._seek_http()
            
            return

        logging.error('mjpg client unknown authentication header: "%s"' % data)
        self._seek_content_length()
    def _on_www_authenticate(self, data):
        if self._check_error():
            return

        data = data.strip()

        m = re.match('Basic\s*realm="([a-zA-Z0-9\-\s]+)"', data)
        if m:
            logging.debug('mjpg client using basic authentication')

            auth_header = utils.build_basic_header(self._username, self._password)
            self.write('GET / HTTP/1.1\r\nAuthorization: %s\r\nConnection: close\r\n\r\n' % auth_header)
            self._seek_http()

            return

        if data.startswith('Digest'):
            logging.debug('mjpg client using digest authentication')

            parts = data[7:].split(',')
            parts_dict = dict(p.split('=', 1) for p in parts)
            parts_dict = {p[0]: p[1].strip('"') for p in parts_dict.items()}

            self._auth_digest_state = parts_dict

            auth_header = utils.build_digest_header('GET', '/', self._username, self._password, self._auth_digest_state)
            self.write('GET / HTTP/1.1\r\nAuthorization: %s\r\nConnection: close\r\n\r\n' % auth_header)
            self._seek_http()

            return

        logging.error('mjpg client unknown authentication header: "%s"' % data)
        self._seek_content_length()
Exemple #4
0
    def _on_connect(self):
        logging.debug('mjpg client for camera %(camera_id)s connected on port %(port)s' % {
                'port': self._port, 'camera_id': self._camera_id})
        
        if self._username:
            auth_header = utils.build_basic_header(self._username, self._password)
            self.write('GET / HTTP/1.0\r\n\r\nAuthorization: %s\r\n\r\n' % auth_header)
            
        else:
            self.write('GET / HTTP/1.0\r\n\r\n')

        self._seek_http()
Exemple #5
0
    def _on_connect(self):
        logging.debug('mjpg client for camera %(camera_id)s connected on port %(port)s' % {
                'port': self._port, 'camera_id': self._camera_id})

        if self._auth_mode == 'basic':
            logging.debug('mjpg client using basic authentication')

            auth_header = utils.build_basic_header(self._username, self._password)
            self.write('GET / HTTP/1.0\r\n\r\nAuthorization: %s\r\n\r\n' % auth_header)
            
        else: # in digest auth mode, the header is built upon receiving 401
            self.write('GET / HTTP/1.0\r\n\r\n')

        self._seek_http()
Exemple #6
0
    def _on_connect(self):
        logging.debug(
            'mjpg client for camera %(camera_id)s connected on port %(port)s' %
            {
                'port': self._port,
                'camera_id': self._camera_id
            })

        if self._username:
            auth_header = utils.build_basic_header(self._username,
                                                   self._password)
            self.write('GET / HTTP/1.0\r\n\r\nAuthorization: %s\r\n\r\n' %
                       auth_header)

        else:
            self.write('GET / HTTP/1.0\r\n\r\n')

        self._seek_http()
Exemple #7
0
    def _on_www_authenticate(self, data):
        if self._check_error():
            return

        m = re.match('Basic\s*realm="([a-zA-Z0-9\-\s]+)"', data.strip())
        if m:
            logging.debug('mjpg client using basic authentication')

            auth_header = utils.build_basic_header(self._username,
                                                   self._password)
            self.write('GET / HTTP/1.0\r\n\r\nAuthorization: %s\r\n\r\n' %
                       auth_header)
            self._seek_http()

            return

        m = re.match(
            'Digest\s*realm="([a-zA-Z0-9\-\s]+)",\s*nonce="([a-zA-Z0-9]+)"',
            data.strip())
        if m:
            logging.debug('mjpg client using digest authentication')

            realm, nonce = m.groups()
            self._auth_digest_state['realm'] = realm
            self._auth_digest_state['nonce'] = nonce

            auth_header = utils.build_digest_header('GET', '/', self._username,
                                                    self._password,
                                                    self._auth_digest_state)
            self.write('GET / HTTP/1.0\r\n\r\nAuthorization: %s\r\n\r\n' %
                       auth_header)
            self._seek_http()

            return

        logging.error('mjpg client unknown authentication header: "%s"' % data)
        self._seek_content_length()