def add_python_logging(app):
	# log to stdout in development mode
	if app.debug:
		log_level = logging.DEBUG
		log_handler = logging.StreamHandler()

	# log to syslog in production mode
	else:
		import utils
		log_level = logging.INFO
		log_handler = utils.create_syslog_handler()
		
	logging.basicConfig(level=log_level, handlers=[])
	log_handler.setLevel(log_level)
	log_handler.addFilter(AuthLogFilter(
		app.debug,
		get_session_username
	))
	log_handler.setFormatter(AuthLogFormatter())
	log = logging.getLogger('')
	log.addHandler(log_handler)
Example #2
0
	# /usr/lib/munin/cgi/munin-cgi-graph returns both headers and binary png when successful.
	# A double-Windows-style-newline always indicates the end of HTTP headers.
	headers, image_bytes = binout.split(b'\r\n\r\n', 1)
	response = make_response(image_bytes)
	for line in headers.splitlines():
		name, value = line.decode("utf8").split(':', 1)
		response.headers[name] = value
	if 'Status' in response.headers and '404' in response.headers['Status']:
		app.logger.warning("munin_cgi: munin-cgi-graph returned 404 status code. PATH_INFO=%s", env['PATH_INFO'])
	return response

# APP

if __name__ == '__main__':
	if "DEBUG" in os.environ: app.debug = True
	if "APIKEY" in os.environ: auth_service.key = os.environ["APIKEY"]

	if not app.debug:
		app.logger.addHandler(utils.create_syslog_handler())

	# For testing on the command line, you can use `curl` like so:
	#    curl --user $(</var/lib/mailinabox/api.key): http://localhost:10222/mail/users
	auth_service.write_key()

	# For testing in the browser, you can copy the API key that's output to the
	# debug console and enter that as the username
	app.logger.info('API key: ' + auth_service.key)

	# Start the application server. Listens on 127.0.0.1 (IPv4 only).
	app.run(port=10222)
Example #3
0
    return utils.shell("check_output", ["/usr/bin/apt-get", "-y", "upgrade"],
                       env={"DEBIAN_FRONTEND": "noninteractive"})


@app.route('/system/backup/status')
@authorized_personnel_only
def backup_status():
    from backup import backup_status
    return json_response(backup_status(env))


# APP

if __name__ == '__main__':
    if "DEBUG" in os.environ: app.debug = True
    if "APIKEY" in os.environ: auth_service.key = os.environ["APIKEY"]

    if not app.debug:
        app.logger.addHandler(utils.create_syslog_handler())

    # For testing on the command line, you can use `curl` like so:
    #    curl --user $(</var/lib/mailinabox/api.key): http://localhost:10222/mail/users
    auth_service.write_key()

    # For testing in the browser, you can copy the API key that's output to the
    # debug console and enter that as the username
    app.logger.info('API key: ' + auth_service.key)

    # Start the application server. Listens on 127.0.0.1 (IPv4 only).
    app.run(port=10222)