Esempio n. 1
0
def ivr_error_view(exc, request):
    response = request.response
    response.status_int = exc.http_status_code
    type, dummy, tb = sys.exc_info()
    tb_list = traceback.format_list(traceback.extract_tb(tb)[-5:])
    return {
        'info': STRING(exc),
        'exception': STRING(type),
        'traceback': tb_list
    }
Esempio n. 2
0
def failed_validation(exc, request):
    response = request.response
    response.status_int = 400
    type, dummy, tb = sys.exc_info()
    tb_list = traceback.format_list(traceback.extract_tb(tb)[-5:])
    return {
        'info': STRING(exc),
        'exception': STRING(type),
        'traceback': tb_list
    }
Esempio n. 3
0
    def add_user(self, username, password, **kwargs):
        with self._dao_context_mngr.context():
            user = self._user_dao.get_by_username(username)
            if user is not None:
                raise IVRError("Username Exist", 400)
            password = STRING(hashlib.sha256(password.encode()).hexdigest())
            user = User(username=username, password=password, **kwargs)

            self._user_dao.add(user)
            user = self._user_dao.get_by_username(username)
        return user
Esempio n. 4
0
File: user.py Progetto: dulton/IVR
    def add_user(self, username, password, **kwargs):
        with self._dao_context_mngr.context():
            user = self._user_dao.get_by_username(username)
            if user is not None:
                raise IVRError("Username Exist", 400)
            password = STRING(hashlib.sha256(password.encode()).hexdigest())
            user = User(username=username, password=password, **kwargs)

            self._user_dao.add(user)
            user = self._user_dao.get_by_username(username)
        return user
Esempio n. 5
0
File: rpc.py Progetto: dulton/IVR
 def _handle_request(self, msg):
     self._serverSeqNbr = msg['seq']
     method = msg['req']
     m = getattr(self, 'rpc_' + method, None)
     if m and callable(m):
         log.info('Received new request {0}: {1}'.format(
             method, msg.get('params')))
         try:
             if msg.get('params'):
                 result = m(msg['params'])
             else:
                 result = m()
             msg = {'seq': msg['seq'], 'resp': result}
         except Exception as e:
             msg = {
                 'seq': msg['seq'],
                 'err': {
                     'code': -1,
                     'msg': STRING(e)
                 }
             }
         self._transport.send_packet(self._encoder.marshal(msg))
     else:
         raise InvalidRPCRequest(
             "RPC request {0} not implemented".format(method))
Esempio n. 6
0
 def _generate_base64_key(byte_number):
     if sys.version_info[:1] < (3, ):
         key_bytes = bytes(
             bytearray(random.getrandbits(8) for i in range(byte_number)))
     else:
         key_bytes = bytes(
             random.getrandbits(8) for i in range(byte_number))
     return STRING(base64.urlsafe_b64encode(key_bytes))
Esempio n. 7
0
File: user.py Progetto: dulton/IVR
 def reset_password(self, username, new_password):
     with self._dao_context_mngr.context():
         user = self._user_dao.get_by_username(username)
         if user is None:
             raise IVRError("User Not Found", 404)
         user.password = STRING(hashlib.sha256(new_password.encode()).hexdigest())
         user.utime = datetime.datetime.now()
         self._user_dao.update(user)
Esempio n. 8
0
def not_found_view(exc, request):
    response = request.response
    response.status_int = exc.status_code
    type, dummy, tb = sys.exc_info()
    return {
        'info':
        'Resource {0} for method {1} is Forbidden'.format(
            request.path, request.method),
        'exception':
        STRING(type),
        'traceback': []
    }
Esempio n. 9
0
 def __init__(self, ivt, project_name, channel, streams, ip, **kwargs):
     self._ivt = ivt
     self._project_name = project_name
     self._ip = ip
     self.channel = channel
     self.name = '_'.join((self._ivt.name, STRING(self.channel)))
     self._is_online = self.STATE_ONLINE
     self.streams = {}
     for stream in streams:
         s = stream_factory(stream.pop('type'), self, stream.pop('url'),
                            stream.pop('quality'), **stream)
         if s.type in self.streams:
             self.streams[s.type][s.quality] = s
         else:
             self.streams[s.type] = {s.quality: s}
Esempio n. 10
0
def add_user(config_uri,
             username,
             password_plain,
             title="default",
             desc="",
             flags=0,
             cellphone="",
             email="",
             user_type=User.USER_TYPE_NORMAL):
    config = configparser.ConfigParser()
    config.read(config_uri)
    settings = dict(config.items("alembic"))

    engine = engine_from_config(settings, 'sqlalchemy.')

    if is_str(password_plain):
        password_plain = password_plain.encode()

    password_hex = STRING(
        binascii.hexlify(
            pbkdf2(password_plain,
                   PASSWORD_PBKDF2_HMAC_SHA256_SALT,
                   100000,
                   keylen=32,
                   prf=str('hmac-sha256'))))
    dao_context_mngr = AlchemyDaoContextMngr(engine)
    user_dao = SAUserDao(dao_context_mngr)

    user_mngr = UserManager(user_dao=user_dao,
                            project_dao=None,
                            dao_context_mngr=dao_context_mngr)
    user_mngr.add_user(username=username,
                       password=password_hex,
                       title=title,
                       desc=desc,
                       flags=flags,
                       cellphone=cellphone,
                       email=email,
                       user_type=user_type)
Esempio n. 11
0
 def request_session(self, project_name, camera_id, stream_format, stream_quality, create=True,
                     ip='', user_agent='', username='', subuser=''):
     stream = self._stream_mngr.request_stream(project_name, camera_id, stream_format, stream_quality, auto_delete=True, create=create)
     session_id = STRING(uuid4())
     if stream_format == 'hls':
         url = stream.hls_url
     else:
         url = stream.rtmp_url
     session = self._dao.add_new_user_session(
         project_name=project_name,
         uuid=session_id,
         camera_uuid=camera_id,
         stream_format=stream_format,
         stream_quality=stream.stream_quality,
         stream_id=stream.id,
         url=url,
         ip=ip,
         user_agent=user_agent,
         username=username,
         subuser=subuser,
     )
     log.info('Created {0} for {1}'.format(session, stream))
     return session.url, session_id
Esempio n. 12
0
 def request_stream(self, project_name, camera_id, stream_format='hls', stream_quality=VideoQuality.LD, auto_delete=True, create=True):
     # TODO concurrent request for the same stream maybe harmful, need to handle this situation
     # find possible existing stream
     stream = self._dao.get_stream(project_name, camera_id, stream_quality)
     if stream:
         return self._wait_util_ready(stream_format, stream)
     camera = self._camera_mngr.get_camera(project_name, camera_id)
     if not camera:
         raise IVRError('No such camera <{0}> or project <{1}>'.format(camera_id, project_name))
     if camera.is_online == camera.STATE_OFFLINE:
         raise IVRError('{0} is offline'.format(camera))
     target_quality = camera.find_possible_quality(stream_quality)
     if target_quality != stream_quality:
         stream = self._dao.get_stream(project_name, camera_id, target_quality)
         if stream:
             return self._wait_util_ready(stream_format, stream)
     # target stream does not exist, create stream
     stream_id = STRING(uuid.uuid4())
     publish_to = os.path.join(self._rtmp_publish_url_prefix, stream_id)
     stream = Stream(
         project_name=project_name,
         stream_id=stream_id,
         camera_id=camera_id,
         stream_quality=stream_quality,
         publish_to=publish_to,
         hls_url=self.calc_url('hls', stream_id),
         rtmp_url=self.calc_url('rtmp', stream_id),
         rtmp_ready=True,
     )
     self._dao.add(stream)
     self._camera_mngr.rtmp_publish_stream(project_name, camera_id, stream_id, target_quality, publish_to)
     try:
         return self._wait_util_ready(stream_format, stream)
     except Exception:
         self._dao.delete(stream_id)
         self._camera_mngr.stop_rtmp_publish(stream_id)
         raise
Esempio n. 13
0
File: ws.py Progetto: dulton/IVR
 def received_message(self, message):
     log.debug("Received message {0}".format(message))
     self._app.on_received_packet(STRING(message))