示例#1
0
def get_jpg(camera_id):
    if not motionctl.running():
        return None
    
    if camera_id not in MjpgClient.clients:
        # mjpg client not started yet for this camera
        
        logging.debug('creating mjpg client for camera %(camera_id)s' % {
                'camera_id': camera_id})
        
        camera_config = config.get_camera(camera_id)
        if not camera_config['@enabled'] or not utils.local_motion_camera(camera_config):
            logging.error('could not start mjpg client for camera id %(camera_id)s: not enabled or not local' % {
                    'camera_id': camera_id})
            
            return None
        
        port = camera_config['stream_port']
        username, password = None, None
        if camera_config.get('stream_auth_method') > 0:
            username, password = camera_config.get('stream_authentication', ':').split(':')

        client = MjpgClient(camera_id, port, username, password)
        client.connect()

    MjpgClient.last_access[camera_id] = datetime.datetime.utcnow()
    
    return MjpgClient.last_jpgs.get(camera_id)
示例#2
0
def _run_server():
    import cleanup
    import motionctl
    import thumbnailer
    import tornado.ioloop
    import server

    server.application.listen(settings.PORT, settings.LISTEN)
    logging.info("server started")

    tornado.ioloop.IOLoop.instance().start()

    logging.info("server stopped")

    if thumbnailer.running():
        thumbnailer.stop()
        logging.info("thumbnailer stopped")

    if cleanup.running():
        cleanup.stop()
        logging.info("cleanup stopped")

    if motionctl.running():
        motionctl.stop()
        logging.info("motion stopped")

    if settings.SMB_SHARES:
        smbctl.umount_all()
        logging.info("SMB shares unmounted")
示例#3
0
def run():
    import cleanup
    import motionctl
    import motioneye
    import smbctl
    import thumbnailer
    import tornado.ioloop

    configure_signals()
    logging.info('hello! this is motionEye server %s' % motioneye.VERSION)

    test_requirements()

    if settings.SMB_SHARES:

        stop, start = smbctl.update_mounts()  # @UnusedVariable
        if start:
            start_motion()

    else:
        start_motion()

    start_cleanup()
    start_wsswitch()

    if settings.THUMBNAILER_INTERVAL:
        start_thumbnailer()

    template.add_context('static_path', settings.BASE_PATH + '/static/')
    
    application = Application(handler_mapping, debug=False, log_function=_log_request,
            static_path=settings.STATIC_PATH, static_url_prefix='/static/')
    
    application.listen(settings.PORT, settings.LISTEN)
    logging.info('server started')
    
    tornado.ioloop.IOLoop.instance().start()

    logging.info('server stopped')
    
    if thumbnailer.running():
        thumbnailer.stop()
        logging.info('thumbnailer stopped')

    if cleanup.running():
        cleanup.stop()
        logging.info('cleanup stopped')

    if motionctl.running():
        motionctl.stop()
        logging.info('motion stopped')
    
    if settings.SMB_SHARES:
        smbctl.umount_all()
        logging.info('SMB shares unmounted')

    logging.info('bye!')
示例#4
0
def _check_ws():
    # schedule the next call
    ioloop = tornado.ioloop.IOLoop.instance()
    ioloop.add_timeout(datetime.timedelta(seconds=10), _check_ws)

    if not motionctl.running():
        return

    now = datetime.datetime.now()
    for camera_id in config.get_camera_ids():
        camera_config = config.get_camera(camera_id)
        if not utils.local_motion_camera(camera_config):
            continue

        working_schedule = camera_config.get('@working_schedule')
        motion_detection = camera_config.get('@motion_detection')
        working_schedule_type = camera_config.get(
            '@working_schedule_type') or 'outside'

        if not working_schedule:  # working schedule disabled, motion detection left untouched
            continue

        if not motion_detection:  # motion detection explicitly disabled
            continue

        now_during = _during_working_schedule(now, working_schedule)
        must_be_enabled = (now_during and working_schedule_type
                           == 'during') or (not now_during and
                                            working_schedule_type == 'outside')

        currently_enabled = motionctl.get_motion_detection(camera_id)
        if currently_enabled is None:  # could not detect current status
            logging.warn(
                'skipping motion detection status update for camera with id %(id)s'
                % {'id': camera_id})
            continue

        if currently_enabled and not must_be_enabled:
            logging.debug(
                'must disable motion detection for camera with id %(id)s (%(what)s working schedule)'
                % {
                    'id': camera_id,
                    'what': working_schedule_type
                })

            motionctl.set_motion_detection(camera_id, False)

        elif not currently_enabled and must_be_enabled:
            logging.debug(
                'must enable motion detection for camera with id %(id)s (%(what)s working schedule)'
                % {
                    'id': camera_id,
                    'what': working_schedule_type
                })

            motionctl.set_motion_detection(camera_id, True)
示例#5
0
def _check_ws():
    # schedule the next call
    io_loop = IOLoop.instance()
    io_loop.add_timeout(datetime.timedelta(seconds=10), _check_ws)

    if not motionctl.running():
        return

    def on_motion_detection_status(camera_id, must_be_enabled, working_schedule_type, enabled=None, error=None):
        if error:  # could not detect current status
            return logging.warn("skipping motion detection status update for camera with id %(id)s" % {"id": camera_id})

        if enabled and not must_be_enabled:
            logging.debug(
                "must disable motion detection for camera with id %(id)s (%(what)s working schedule)"
                % {"id": camera_id, "what": working_schedule_type}
            )

            motionctl.set_motion_detection(camera_id, False)

        elif not enabled and must_be_enabled:
            logging.debug(
                "must enable motion detection for camera with id %(id)s (%(what)s working schedule)"
                % {"id": camera_id, "what": working_schedule_type}
            )

            motionctl.set_motion_detection(camera_id, True)

    now = datetime.datetime.now()
    for camera_id in config.get_camera_ids():
        camera_config = config.get_camera(camera_id)
        if not utils.local_motion_camera(camera_config):
            continue

        working_schedule = camera_config.get("@working_schedule")
        motion_detection = camera_config.get("@motion_detection")
        working_schedule_type = camera_config.get("@working_schedule_type") or "outside"

        if not working_schedule:  # working schedule disabled, motion detection left untouched
            continue

        if not motion_detection:  # motion detection explicitly disabled
            continue

        now_during = _during_working_schedule(now, working_schedule)
        must_be_enabled = (now_during and working_schedule_type == "during") or (
            not now_during and working_schedule_type == "outside"
        )

        motionctl.get_motion_detection(
            camera_id, functools.partial(on_motion_detection_status, camera_id, must_be_enabled, working_schedule_type)
        )
示例#6
0
def run():
    import cleanup
    import motionctl
    import motioneye
    import smbctl
    import thumbnailer
    import tornado.ioloop

    configure_signals()
    logging.info('hello! this is motionEye server %s' % motioneye.VERSION)

    test_requirements()

    if settings.SMB_SHARES:

        stop, start = smbctl.update_mounts()  # @UnusedVariable
        if start:
            start_motion()

    else:
        start_motion()

    start_cleanup()
    start_wsswitch()

    if settings.THUMBNAILER_INTERVAL:
        start_thumbnailer()

    application.listen(settings.PORT, settings.LISTEN)
    logging.info('server started')
    
    tornado.ioloop.IOLoop.instance().start()

    logging.info('server stopped')
    
    if thumbnailer.running():
        thumbnailer.stop()
        logging.info('thumbnailer stopped')

    if cleanup.running():
        cleanup.stop()
        logging.info('cleanup stopped')

    if motionctl.running():
        motionctl.stop()
        logging.info('motion stopped')
    
    if settings.SMB_SHARES:
        smbctl.umount_all()
        logging.info('SMB shares unmounted')

    logging.info('bye!')
示例#7
0
def run():
    import cleanup
    import motionctl
    import motioneye
    import smbctl
    import thumbnailer
    import tornado.ioloop

    configure_signals()
    logging.info('hello! this is motionEye server %s' % motioneye.VERSION)

    test_requirements()

    if settings.SMB_SHARES:

        stop, start = smbctl.update_mounts()  # @UnusedVariable
        if start:
            start_motion()

    else:
        start_motion()

    start_cleanup()
    start_wsswitch()

    if settings.THUMBNAILER_INTERVAL:
        start_thumbnailer()

    application.listen(settings.PORT, settings.LISTEN)
    logging.info('server started')
    
    tornado.ioloop.IOLoop.instance().start()

    logging.info('server stopped')
    
    if thumbnailer.running():
        thumbnailer.stop()
        logging.info('thumbnailer stopped')

    if cleanup.running():
        cleanup.stop()
        logging.info('cleanup stopped')

    if motionctl.running():
        motionctl.stop()
        logging.info('motion stopped')
    
    if settings.SMB_SHARES:
        smbctl.umount_all()
        logging.info('SMB shares unmounted')

    logging.info('bye!')
示例#8
0
    def checker():
        if ioloop._stopped:
            return

        if not motionctl.running() and motionctl.started() and config.has_local_enabled_cameras():
            try:
                logging.error("motion not running, starting it")
                motionctl.start()

            except Exception as e:
                logging.error("failed to start motion: %(msg)s" % {"msg": unicode(e)}, exc_info=True)

        ioloop.add_timeout(datetime.timedelta(seconds=settings.MOTION_CHECK_INTERVAL), checker)
示例#9
0
    def checker():
        if io_loop._stopped:
            return
            
        if not motionctl.running() and motionctl.started() and config.get_enabled_local_motion_cameras():
            try:
                logging.error('motion not running, starting it')
                motionctl.start()
            
            except Exception as e:
                logging.error('failed to start motion: %(msg)s' % {
                        'msg': unicode(e)}, exc_info=True)

        io_loop.add_timeout(datetime.timedelta(seconds=settings.MOTION_CHECK_INTERVAL), checker)
示例#10
0
def _check_ws():
    # schedule the next call
    ioloop = tornado.ioloop.IOLoop.instance()
    ioloop.add_timeout(datetime.timedelta(seconds=10), _check_ws)

    if not motionctl.running():
        return

    now = datetime.datetime.now()
    for camera_id in config.get_camera_ids():
        camera_config = config.get_camera(camera_id)
        if not utils.local_motion_camera(camera_config):
            continue
        
        working_schedule = camera_config.get('@working_schedule')
        motion_detection = camera_config.get('@motion_detection')
        working_schedule_type = camera_config.get('@working_schedule_type') or 'outside'
        
        if not working_schedule: # working schedule disabled, motion detection left untouched
            continue
        
        if not motion_detection: # motion detection explicitly disabled
            continue
        
        now_during = _during_working_schedule(now, working_schedule)
        must_be_enabled = (now_during and working_schedule_type == 'during') or (not now_during and working_schedule_type == 'outside')
        
        currently_enabled = motionctl.get_motion_detection(camera_id)
        if currently_enabled is None: # could not detect current status
            logging.warn('skipping motion detection status update for camera with id %(id)s' % {'id': camera_id})
            continue
            
        if currently_enabled and not must_be_enabled:
            logging.debug('must disable motion detection for camera with id %(id)s (%(what)s working schedule)' % {
                    'id': camera_id,
                    'what': working_schedule_type})
            
            motionctl.set_motion_detection(camera_id, False)

        elif not currently_enabled and must_be_enabled:
            logging.debug('must enable motion detection for camera with id %(id)s (%(what)s working schedule)' % {
                    'id': camera_id,
                    'what': working_schedule_type})
            
            motionctl.set_motion_detection(camera_id, True)
示例#11
0
    def checker():
        #vector fix me: print ("Type:",type(io_loop))
        if not io_loop:
            #if io_loop._stopped:
            print("Return...")
            return

        if not motionctl.running() and motionctl.started(
        ) and config.get_enabled_local_motion_cameras():
            try:
                logging.error('motion not running, starting it')
                motionctl.start()

            except Exception as e:
                logging.error('failed to start motion: %(msg)s' %
                              {'msg': str(e)},
                              exc_info=True)

        io_loop.add_timeout(
            datetime.timedelta(seconds=settings.MOTION_CHECK_INTERVAL),
            checker)
示例#12
0
def run():
    import cleanup
    import mjpgclient
    import motionctl
    import motioneye
    import smbctl
    import tasks
    import wsswitch

    configure_signals()
    logging.info('hello! this is motionEye server %s' % motioneye.VERSION)

    test_requirements()
    make_media_folders()

    if settings.SMB_SHARES:
        stop, start = smbctl.update_mounts()  # @UnusedVariable
        if start:
            start_motion()

    else:
        start_motion()

    if settings.CLEANUP_INTERVAL:
        cleanup.start()
        logging.info('cleanup started')

    wsswitch.start()
    logging.info('wsswitch started')

    tasks.start()
    logging.info('tasks started')

    if settings.MJPG_CLIENT_TIMEOUT:
        mjpgclient.start()
        logging.info('mjpg client garbage collector started')

    if settings.SMB_SHARES:
        smbctl.start()
        logging.info('smb mounts started')

    template.add_context('static_path', settings.BASE_PATH + '/static/')

    application = Application(handler_mapping,
                              debug=False,
                              log_function=_log_request,
                              static_path=settings.STATIC_PATH,
                              static_url_prefix='/static/')

    application.listen(settings.PORT, settings.LISTEN)
    logging.info('server started')

    io_loop = IOLoop.instance()
    io_loop.start()

    logging.info('server stopped')

    tasks.stop()
    logging.info('tasks stopped')

    if cleanup.running():
        cleanup.stop()
        logging.info('cleanup stopped')

    if motionctl.running():
        motionctl.stop()
        logging.info('motion stopped')

    if settings.SMB_SHARES:
        smbctl.stop()
        logging.info('smb mounts stopped')

    logging.info('bye!')
示例#13
0
def run():
    import cleanup
    import mjpgclient
    import motionctl
    import motioneye
    import smbctl
    import thumbnailer
    import wsswitch

    configure_signals()
    logging.info('hello! this is motionEye server %s' % motioneye.VERSION)

    test_requirements()

    if settings.SMB_SHARES:
        stop, start = smbctl.update_mounts()  # @UnusedVariable
        if start:
            start_motion()

    else:
        start_motion()

    if settings.CLEANUP_INTERVAL:
        cleanup.start()
        logging.info('cleanup started')
        
    wsswitch.start()
    logging.info('wsswitch started')

    if settings.THUMBNAILER_INTERVAL:
        thumbnailer.start()
        logging.info('thumbnailer started')

    if settings.MJPG_CLIENT_TIMEOUT:
        mjpgclient.start()
        logging.info('mjpg client garbage collector started')

    if settings.SMB_SHARES:
        smbctl.start()
        logging.info('smb mounts started')

    template.add_context('static_path', settings.BASE_PATH + '/static/')
    
    application = Application(handler_mapping, debug=False, log_function=_log_request,
            static_path=settings.STATIC_PATH, static_url_prefix='/static/')
    
    application.listen(settings.PORT, settings.LISTEN)
    logging.info('server started')
    
    IOLoop.instance().start()

    logging.info('server stopped')
    
    if thumbnailer.running():
        thumbnailer.stop()
        logging.info('thumbnailer stopped')

    if cleanup.running():
        cleanup.stop()
        logging.info('cleanup stopped')

    if motionctl.running():
        motionctl.stop()
        logging.info('motion stopped')
    
    if settings.SMB_SHARES:
        smbctl.stop()
        logging.info('smb mounts stopped')

    logging.info('bye!')
示例#14
0
def _check_ws():
    # schedule the next call
    io_loop = IOLoop.instance()
    io_loop.add_timeout(datetime.timedelta(seconds=10), _check_ws)

    if not motionctl.running():
        return

    def on_motion_detection_status(camera_id,
                                   must_be_enabled,
                                   working_schedule_type,
                                   enabled=None,
                                   error=None):
        if error:  # could not detect current status
            return logging.warn(
                'skipping motion detection status update for camera with id %(id)s: %(error)s'
                % {
                    'id': camera_id,
                    'error': error
                })

        if enabled and not must_be_enabled:
            logging.debug(
                'must disable motion detection for camera with id %(id)s (%(what)s working schedule)'
                % {
                    'id': camera_id,
                    'what': working_schedule_type
                })

            motionctl.set_motion_detection(camera_id, False)

        elif not enabled and must_be_enabled:
            logging.debug(
                'must enable motion detection for camera with id %(id)s (%(what)s working schedule)'
                % {
                    'id': camera_id,
                    'what': working_schedule_type
                })

            motionctl.set_motion_detection(camera_id, True)

    now = datetime.datetime.now()
    for camera_id in config.get_camera_ids():
        camera_config = config.get_camera(camera_id)
        if not utils.is_local_motion_camera(camera_config):
            continue

        working_schedule = camera_config.get('@working_schedule')
        motion_detection = camera_config.get('@motion_detection')
        working_schedule_type = camera_config.get(
            '@working_schedule_type') or 'outside'

        if not working_schedule:  # working schedule disabled, motion detection left untouched
            continue

        if not motion_detection:  # motion detection explicitly disabled
            continue

        now_during = _during_working_schedule(now, working_schedule)
        must_be_enabled = ((now_during and working_schedule_type == 'during')
                           or (not now_during
                               and working_schedule_type == 'outside'))

        motionctl.get_motion_detection(
            camera_id,
            functools.partial(on_motion_detection_status, camera_id,
                              must_be_enabled, working_schedule_type))
示例#15
0
def _check_ws():
    # schedule the next call
    io_loop = IOLoop.instance()
    io_loop.add_timeout(datetime.timedelta(seconds=10), _check_ws)

    if not motionctl.running():
        return

    def on_motion_detection_status(camera_id,
                                   must_be_enabled,
                                   working_schedule_type,
                                   enabled=None,
                                   error=None):
        if error:  # could not detect current status
            return logging.warn(
                'skipping motion detection status update for camera with id %(id)s: %(error)s'
                % {
                    'id': camera_id,
                    'error': error
                })

        if enabled and not must_be_enabled:
            logging.debug(
                'must disable motion detection for camera with id %(id)s (%(what)s working schedule)'
                % {
                    'id': camera_id,
                    'what': working_schedule_type
                })

            motionctl.set_motion_detection(camera_id, False)

        elif not enabled and must_be_enabled:
            logging.debug(
                'must enable motion detection for camera with id %(id)s (%(what)s working schedule)'
                % {
                    'id': camera_id,
                    'what': working_schedule_type
                })

            motionctl.set_motion_detection(camera_id, True)

    now = datetime.datetime.now()
    for camera_id in config.get_camera_ids():
        camera_config = config.get_camera(camera_id)
        if not utils.is_local_motion_camera(camera_config):
            continue

        working_schedule = camera_config.get('@working_schedule')
        motion_detection = camera_config.get('@motion_detection')
        working_schedule_type = camera_config.get(
            '@working_schedule_type') or 'outside'

        geofence_enabled = camera_config.get('@geofence_enabled')
        ips = camera_config.get('@geofence_ips')

        if not working_schedule:  # working schedule disabled, motion detection left untouched
            continue

        if not motion_detection:  # motion detection explicitly disabled
            continue

        must_be_enabled = True

        now_during = True
        if working_schedule:
            now_during = _during_working_schedule(now, working_schedule)

        if geofence_enabled and (now_during
                                 or working_schedule_type != 'outside'):
            for ip in ips.split(','):
                try:
                    ip = ip.strip()
                    socket.inet_aton(ip)
                except socket.error as e:
                    logging.warning('geofence ip error: \'%s\' msg: %s' %
                                    (ip, e.message))
                    continue

                try:
                    subprocess.check_call(['ping', '-c1', ip],
                                          stdout=open(os.devnull, 'w'))
                    must_be_enabled = False
                    break
                except:
                    pass

        motionctl.get_motion_detection(
            camera_id,
            functools.partial(on_motion_detection_status, camera_id,
                              must_be_enabled, working_schedule_type))
示例#16
0
def run():
    import cleanup
    import motionctl
    import motioneye
    import smbctl
    import thumbnailer
    import tornado.ioloop

    configure_signals()
    logging.info("hello! this is motionEye server %s" % motioneye.VERSION)

    test_requirements()

    if settings.SMB_SHARES:

        stop, start = smbctl.update_mounts()  # @UnusedVariable
        if start:
            start_motion()

    else:
        start_motion()

    start_cleanup()
    start_wsswitch()

    if settings.THUMBNAILER_INTERVAL:
        start_thumbnailer()

    template.add_context("static_path", settings.BASE_PATH + "/static/")

    application = Application(
        handler_mapping,
        debug=False,
        log_function=_log_request,
        static_path=settings.STATIC_PATH,
        static_url_prefix="/static/",
    )

    application.listen(settings.PORT, settings.LISTEN)
    logging.info("server started")

    tornado.ioloop.IOLoop.instance().start()

    logging.info("server stopped")

    if thumbnailer.running():
        thumbnailer.stop()
        logging.info("thumbnailer stopped")

    if cleanup.running():
        cleanup.stop()
        logging.info("cleanup stopped")

    if motionctl.running():
        motionctl.stop()
        logging.info("motion stopped")

    if settings.SMB_SHARES:
        smbctl.umount_all()
        logging.info("SMB shares unmounted")

    logging.info("bye!")
示例#17
0
def run():
    import cleanup
    import mjpgclient
    import motionctl
    import motioneye
    import smbctl
    import tasks
    import wsswitch

    configure_signals()
    logging.info('hello! this is motionEye server %s' % motioneye.VERSION)

    test_requirements()
    make_media_folders()

    if settings.SMB_SHARES:
        stop, start = smbctl.update_mounts()  # @UnusedVariable
        if start:
            start_motion()

    else:
        start_motion()

    if settings.CLEANUP_INTERVAL:
        cleanup.start()
        logging.info('cleanup started')

    wsswitch.start()
    logging.info('wsswitch started')

    tasks.start()
    logging.info('tasks started')

    if settings.MJPG_CLIENT_TIMEOUT:
        mjpgclient.start()
        logging.info('mjpg client garbage collector started')

    if settings.SMB_SHARES:
        smbctl.start()
        logging.info('smb mounts started')

    template.add_context('static_path', 'static/')

    application = Application(handler_mapping,
                              debug=False,
                              log_function=_log_request,
                              static_path=settings.STATIC_PATH,
                              static_url_prefix='/static/')

    if settings.SSL_PORT > 0:
        application.listen(settings.SSL_PORT,
                           settings.LISTEN,
                           ssl_options={
                               "certfile": settings.SSL_CERT,
                               "keyfile": settings.SSL_KEY,
                           })
        logging.info('https server started on port: %s' % settings.SSL_PORT)

    application.listen(settings.PORT, settings.LISTEN)
    logging.info('http server started ono port: %s' % settings.PORT)

    io_loop = IOLoop.instance()
    # we need to reset the loop's PID to fix PID checks when running in daemon mode
    io_loop._pid = os.getpid()
    io_loop.start()

    logging.info('server stopped')

    tasks.stop()
    logging.info('tasks stopped')

    if cleanup.running():
        cleanup.stop()
        logging.info('cleanup stopped')

    if motionctl.running():
        motionctl.stop()
        logging.info('motion stopped')

    if settings.SMB_SHARES:
        smbctl.stop()
        logging.info('smb mounts stopped')

    logging.info('bye!')