コード例 #1
0
 def wrapper(handler, *args, **kwargs):
     admin_userpass_file = Options.admin_userpass_file()
     if admin_userpass_file == "yes":
         return func(handler, *args, **kwargs)
     if admin_userpass_file == "no":
         handler.send_error(403)
         return False
     auth_header = handler.request.headers.get('Authorization')
     if auth_header is not None and auth_header.startswith('Basic '):
         tmp = auth_header.encode('ascii')
         auth_decoded = base64.decodestring(tmp[6:])
         basicauth_user, basicauth_pass = auth_decoded.decode(
             'utf-8').split(':', 2)
         try:
             with open(admin_userpass_file, "r") as f:
                 lines = f.readlines()
                 for line in lines:
                     username, password = line.strip().split(":", 1)
                     if (basicauth_user == username) and (basicauth_pass
                                                          == password):
                         return func(handler, *args, **kwargs)
         except:
             handler.send_error(500, message="bad admin userpass file")
             return False
     handler.set_status(401)
     handler.set_header('WWW-Authenticate', 'Basic realm=Restricted')
     handler.finish()
     return False
コード例 #2
0
 def wrapper(handler, *args, **kwargs):
     admin_userpass_file = Options.admin_userpass_file()
     if admin_userpass_file == "yes":
         return func(handler, *args, **kwargs)
     if admin_userpass_file == "no":
         handler.send_error(403)
         return False
     auth_header = handler.request.headers.get('Authorization')
     if auth_header is not None and auth_header.startswith('Basic '):
         tmp = auth_header.encode('ascii')
         auth_decoded = base64.decodestring(tmp[6:])
         basicauth_user, basicauth_pass = auth_decoded.decode('utf-8').split(':', 2)
         try:
             with open(admin_userpass_file, "r") as f:
                 lines = f.readlines()
                 for line in lines:
                     username, password = line.strip().split(":", 1)
                     if (basicauth_user == username) and (basicauth_pass == password):
                         return func(handler, *args, **kwargs)
         except:
             handler.send_error(500, message="bad admin userpass file")
             return False
     handler.set_status(401)
     handler.set_header('WWW-Authenticate', 'Basic realm=Restricted')
     handler.finish()
     return False
コード例 #3
0
def main():
    '''
    @summary: main function (starts the daemon)
    '''
    application = get_app()
    tornado.options.parse_command_line()
    server = HTTPServer(application)
    server.listen(Options.port())
    iol = get_ioloop()
    iol.add_callback(log_is_ready)
    signal.signal(signal.SIGTERM, lambda s, f: sigterm_handler(server, iol, s, f))
    try:
        iol.start()
    except KeyboardInterrupt:
        stop_server(server, None)
    logging.info("RDLM daemon is stopped !")