Exemple #1
0
def main(parser, args):
    import meyectl

    options = parse_options(parser, args)

    meyectl.configure_logging('webhook', options.log_to_file)
    meyectl.configure_tornado()

    logging.debug('hello!')
    logging.debug('method = %s' % options.method)
    logging.debug('url = %s' % options.url)

    if options.method == 'POST':
        parts = urlparse.urlparse(options.url)
        data = parts.query

    else:
        data = None

    request = urllib2.Request(options.url, data)
    try:
        urllib2.urlopen(request, timeout=settings.REMOTE_REQUEST_TIMEOUT)
        logging.debug('webhook successfully called')

    except Exception as e:
        logging.error('failed to call webhook: %s' % e)

    logging.debug('bye!')
Exemple #2
0
def main(parser, args):
    import meyectl
    
    options = parse_options(parser, args)
    
    meyectl.configure_logging('webhook', options.log_to_file)
    meyectl.configure_tornado()

    logging.debug('hello!')
    logging.debug('method = %s' % options.method)
    logging.debug('url = %s' % options.url)
    
    if options.method == 'POST':
        parts = urlparse.urlparse(options.url)
        data = parts.query

    else:
        data = None

    request = urllib2.Request(options.url, data)
    try:
        urllib2.urlopen(request, timeout=settings.REMOTE_REQUEST_TIMEOUT)
        logging.debug('webhook successfully called')
    
    except Exception as e:
        logging.error('failed to call webhook: %s' % e)

    logging.debug('bye!')
Exemple #3
0
def main(parser, args):
    import meyectl

    options = parse_options(parser, args)

    meyectl.configure_logging('sendmail', options.log_to_file)
    meyectl.configure_tornado()

    logging.debug('hello!')

    options.port = int(options.port)
    options.tls = options.tls.lower() == 'true'
    options.timespan = int(options.timespan)
    message = messages.get(options.msg_id)
    subject = subjects.get(options.msg_id)
    options.moment = datetime.datetime.strptime(options.moment,
                                                '%Y-%m-%dT%H:%M:%S')

    logging.debug('server = %s' % options.server)
    logging.debug('port = %s' % options.port)
    logging.debug('account = %s' % options.account)
    logging.debug('password = ******')
    logging.debug('server = %s' % options.server)
    logging.debug('tls = %s' % str(options.tls).lower())
    logging.debug('to = %s' % options.to)
    logging.debug('msg_id = %s' % options.msg_id)
    logging.debug('camera_id = %s' % options.camera_id)
    logging.debug('moment = %s' % options.moment.strftime('%Y-%m-%d %H:%M:%S'))
    logging.debug('smtp timeout = %d' % settings.SMTP_TIMEOUT)
    logging.debug('timespan = %d' % options.timespan)

    to = [t.strip() for t in re.split('[,;| ]', options.to)]
    to = [t for t in to if t]

    io_loop = IOLoop.instance()

    def on_message(subject, message, files):
        try:
            send_mail(options.server, options.port, options.account,
                      options.password, options.tls, options.to, subject,
                      message, files)
            logging.info('email sent')

        except Exception as e:
            logging.error('failed to send mail: %s' % e, exc_info=True)

        io_loop.stop()

    def ioloop_timeout():
        io_loop.stop()

    make_message(subject, message, options.camera_id, options.moment,
                 options.timespan, on_message)

    io_loop.add_timeout(datetime.timedelta(seconds=settings.SMTP_TIMEOUT),
                        ioloop_timeout)
    io_loop.start()

    logging.debug('bye!')
Exemple #4
0
def main(parser, args):
    import meyectl
    
    options = parse_options(parser, args)
    
    meyectl.configure_logging('sendmail', options.log_to_file)
    meyectl.configure_tornado()

    logging.debug('hello!')

    options.port = int(options.port) 
    options.tls = options.tls.lower() == 'true'
    options.timespan = int(options.timespan)
    message = messages.get(options.msg_id)
    subject = subjects.get(options.msg_id)
    options.moment = datetime.datetime.strptime(options.moment, '%Y-%m-%dT%H:%M:%S')
    
    logging.debug('server = %s' % options.server)
    logging.debug('port = %s' % options.port)
    logging.debug('account = %s' % options.account)
    logging.debug('password = ******')
    logging.debug('server = %s' % options.server)
    logging.debug('tls = %s' % str(options.tls).lower())
    logging.debug('to = %s' % options.to)
    logging.debug('msg_id = %s' % options.msg_id)
    logging.debug('camera_id = %s' % options.camera_id)
    logging.debug('moment = %s' % options.moment.strftime('%Y-%m-%d %H:%M:%S'))
    logging.debug('smtp timeout = %d' % settings.SMTP_TIMEOUT)
    logging.debug('timespan = %d' % options.timespan)
    
    to = [t.strip() for t in re.split('[,;| ]', options.to)]
    to = [t for t in to if t]

    io_loop = IOLoop.instance()
    
    def on_message(subject, message, files):
        try:
            send_mail(options.server, options.port, options.account, options.password,
                    options.tls, options.to, subject, message, files)
            logging.info('email sent')

        except Exception as e:
            logging.error('failed to send mail: %s' % e, exc_info=True)

        io_loop.stop()
    
    def ioloop_timeout():
        io_loop.stop()
    
    make_message(subject, message, options.camera_id, options.moment, options.timespan, on_message)

    io_loop.add_timeout(datetime.timedelta(seconds=settings.SMTP_TIMEOUT), ioloop_timeout)
    io_loop.start()

    logging.debug('bye!')
Exemple #5
0
def main(parser, args):
    import meyectl
    
    options = parse_options(parser, args)
    
    meyectl.configure_logging('shell', options.log_to_file)
    meyectl.configure_tornado()

    logging.debug('hello!')
    
    code.interact(local=locals())

    logging.debug('bye!')
Exemple #6
0
def main(parser, args):
    import meyectl

    options = parse_options(parser, args)

    meyectl.configure_logging('relayevent', options.log_to_file)
    meyectl.configure_tornado()

    logging.debug('hello!')
    logging.debug('event = %s' % options.event)
    logging.debug('thread_id = %s' % options.thread_id)
    if options.filename:
        logging.debug('filename = %s' % options.filename)

    admin_username, admin_password = get_admin_credentials()

    data = {
        '_username': admin_username,
        'thread_id': options.thread_id,
        'event': options.event
    }

    if options.filename:
        data['filename'] = options.filename

    path = '/_relay_event/'
    body = json.dumps(data)

    signature = utils.compute_signature('POST', path, body, admin_password)

    url = 'http://127.0.0.1:%(port)s' + path + '?_signature=' + signature
    url = url % {'port': settings.PORT}

    request = urllib2.Request(url,
                              data=body,
                              headers={'Content-Type': 'application/json'})

    try:
        response = urllib2.urlopen(request)
        response = json.load(response)
        if response.get('error'):
            raise Exception(response['error'])

        logging.debug('event successfully relayed')

    except Exception as e:
        logging.error('failed to relay event: %s' % e)

    logging.debug('bye!')
Exemple #7
0
def main(parser, args):
    import meyectl
    
    options = parse_options(parser, args)
    
    meyectl.configure_logging('relayevent', options.log_to_file)
    meyectl.configure_tornado()

    logging.debug('hello!')
    logging.debug('event = %s' % options.event)
    logging.debug('thread_id = %s' % options.thread_id)
    if options.filename:
        logging.debug('filename = %s' % options.filename)
    
    admin_username, admin_password = get_admin_credentials()
    
    data = {
        '_username': admin_username,
        'thread_id': options.thread_id,
        'event': options.event
    }
    
    if options.filename:
        data['filename'] = options.filename
    
    path = '/_relay_event/'
    body = json.dumps(data)
    
    signature = utils.compute_signature('POST', path, body, admin_password)
    
    url = 'http://127.0.0.1:%(port)s' + path + '?_signature=' + signature
    url = url % {'port': settings.PORT}
    
    request = urllib2.Request(url, data=body, headers={'Content-Type': 'application/json'})
    
    try:
        response = urllib2.urlopen(request)
        response = json.load(response)
        if response.get('error'):
            raise Exception(response['error'])
        
        logging.debug('event successfully relayed')
    
    except Exception as e:
        logging.error('failed to relay event: %s' % e)

    logging.debug('bye!')
Exemple #8
0
def main(parser, args):
    import meyectl
    import utils
    
    options = parse_options(parser, args)
    
    meyectl.configure_logging('webhook', options.log_to_file)
    meyectl.configure_tornado()

    logging.debug('hello!')
    logging.debug('method = %s' % options.method)
    logging.debug('url = %s' % options.url)
    
    headers = {}    
    parts = urlparse.urlparse(options.url)
    url = options.url
    data = None

    if options.method == 'POST':
        headers['Content-Type'] = 'text/plain'
        data = ''

    elif options.method == 'POSTf': # form url-encoded
        headers['Content-Type'] = 'application/x-www-form-urlencoded'
        data = parts.query
        url = options.url.split('?')[0]

    elif options.method == 'POSTj': # json
        headers['Content-Type'] = 'application/json'
        data = urlparse.parse_qs(parts.query)
        data = {k: v[0] for (k, v) in data.iteritems()}
        data = json.dumps(data)
        url = options.url.split('?')[0]

    else: # GET
        pass

    request = urllib2.Request(url, data, headers=headers)
    try:
        utils.urlopen(request, timeout=settings.REMOTE_REQUEST_TIMEOUT)
        logging.debug('webhook successfully called')

    except Exception as e:
        logging.error('failed to call webhook: %s' % e)

    logging.debug('bye!')
Exemple #9
0
def main(parser, args):
    import meyectl
    import utils

    options = parse_options(parser, args)

    meyectl.configure_logging('webhook', options.log_to_file)
    meyectl.configure_tornado()

    logging.debug('hello!')
    logging.debug('method = %s' % options.method)
    logging.debug('url = %s' % options.url)

    headers = {}
    parts = urllib.parse.urlparse(options.url)
    url = options.url
    data = None

    if options.method == 'POST':
        headers['Content-Type'] = 'text/plain'
        data = ''

    elif options.method == 'POSTf':  # form url-encoded
        headers['Content-Type'] = 'application/x-www-form-urlencoded'
        data = parts.query
        url = options.url.split('?')[0]

    elif options.method == 'POSTj':  # json
        headers['Content-Type'] = 'application/json'
        data = urllib.parse.parse_qs(parts.query)
        data = {k: v[0] for (k, v) in data.items()}
        data = json.dumps(data)
        url = options.url.split('?')[0]

    else:  # GET
        pass

    request = urllib.request.Request(url, data, headers=headers)
    try:
        utils.urlopen(request, timeout=settings.REMOTE_REQUEST_TIMEOUT)
        logging.debug('webhook successfully called')

    except Exception as e:
        logging.error('failed to call webhook: %s' % e)

    logging.debug('bye!')
Exemple #10
0
def main(parser, args, command):
    import meyectl

    options = parse_options(parser, args)

    meyectl.configure_logging("motioneye", options.background or options.log_to_file)
    meyectl.configure_tornado()

    if command == "start":
        if options.background:
            daemon = Daemon(pid_file=os.path.join(settings.RUN_PATH, _PID_FILE), run_callback=run)
            daemon.start()

        else:
            run()

    elif command == "stop":
        daemon = Daemon(pid_file=os.path.join(settings.RUN_PATH, _PID_FILE))
        daemon.stop()
Exemple #11
0
def main(parser, args, command):
    import meyectl
    
    options = parse_options(parser, args)
    
    meyectl.configure_logging('motioneye', options.background or options.log_to_file)
    meyectl.configure_tornado()

    if command == 'start':
        if options.background:
            daemon = Daemon(
                    pid_file=os.path.join(settings.RUN_PATH, _PID_FILE),
                    run_callback=run)
            daemon.start()
            
        else:
            run()

    elif command == 'stop':
        daemon = Daemon(pid_file=os.path.join(settings.RUN_PATH, _PID_FILE))
        daemon.stop()
Exemple #12
0
def main(parser, args):
    import meyectl

    options = parse_options(parser, args)

    meyectl.configure_logging('relayevent', options.log_to_file)
    meyectl.configure_tornado()

    logging.debug('hello!')
    logging.debug('event = %s' % options.event)
    logging.debug('thread_id = %s' % options.thread_id)

    admin_username, admin_password = get_admin_credentials()

    uri = '/_relay_event/?event=%(event)s&thread_id=%(thread_id)s&_username=%(username)s' % {
        'username': admin_username,
        'thread_id': options.thread_id,
        'event': options.event
    }

    signature = utils.compute_signature('POST', uri, '', admin_password)

    url = 'http://127.0.0.1:%(port)s' + uri + '&_signature=' + signature
    url = url % {'port': settings.PORT}

    try:
        response = urllib.urlopen(url, data='')
        response = json.load(response)
        if response.get('error'):
            raise Exception(response['error'])

        logging.debug('event successfully relayed')

    except Exception as e:
        logging.error('failed to relay event: %s' % e)

    logging.debug('bye!')
Exemple #13
0
def main(parser, args):
    import meyectl

    options = parse_options(parser, args)

    meyectl.configure_logging("relayevent", options.log_to_file)
    meyectl.configure_tornado()

    logging.debug("hello!")
    logging.debug("event = %s" % options.event)
    logging.debug("thread_id = %s" % options.thread_id)

    admin_username, admin_password = get_admin_credentials()

    path = "/_relay_event/?event=%(event)s&thread_id=%(thread_id)s&_username=%(username)s" % {
        "username": admin_username,
        "thread_id": options.thread_id,
        "event": options.event,
    }

    signature = utils.compute_signature("POST", path, "", admin_password)

    url = "http://127.0.0.1:%(port)s" + path + "&_signature=" + signature
    url = url % {"port": settings.PORT}

    try:
        response = urllib.urlopen(url, data="")
        response = json.load(response)
        if response.get("error"):
            raise Exception(response["error"])

        logging.debug("event successfully relayed")

    except Exception as e:
        logging.error("failed to relay event: %s" % e)

    logging.debug("bye!")
Exemple #14
0
def main(parser, args):
    import meyectl
    
    options = parse_options(parser, args)
    
    meyectl.configure_logging('relayevent', options.log_to_file)
    meyectl.configure_tornado()

    logging.debug('hello!')
    logging.debug('event = %s' % options.event)
    logging.debug('thread_id = %s' % options.thread_id)
    
    admin_username, admin_password = get_admin_credentials()

    uri = '/_relay_event/?event=%(event)s&thread_id=%(thread_id)s&_username=%(username)s' % {
            'username': admin_username,
            'thread_id': options.thread_id,
            'event': options.event}
    
    signature = utils.compute_signature('POST', uri, '', admin_password)
    
    url = 'http://127.0.0.1:%(port)s' + uri + '&_signature=' + signature
    url = url % {'port': settings.PORT}
    
    try:
        response = urllib.urlopen(url, data='')
        response = json.load(response)
        if response.get('error'):
            raise Exception(response['error'])
        
        logging.debug('event successfully relayed')
    
    except Exception as e:
        logging.error('failed to relay event: %s' % e)

    logging.debug('bye!')