Server IP : 127.0.0.2 / Your IP : 18.117.9.230 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/lib/python2.7/dist-packages/pywebdav/lib/ |
Upload File : |
"""Authenticating HTTP Server This module builds on BaseHTTPServer and implements basic authentication """ import base64 import binascii import BaseHTTPServer DEFAULT_AUTH_ERROR_MESSAGE = """ <head> <title>%(code)s - %(message)s</title> </head> <body> <h1>Authorization Required</h1> this server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required. </body>""" def _quote_html(html): return html.replace("&", "&").replace("<", "<").replace(">", ">") class AuthRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): """ Simple handler that can check for auth headers In your subclass you have to define the method get_userinfo(user, password) which should return 1 or None depending on whether the password was ok or not. None means that the user is not authorized. """ # False means no authentiation DO_AUTH = 1 def parse_request(self): if not BaseHTTPServer.BaseHTTPRequestHandler.parse_request(self): return False if self.DO_AUTH: authorization = self.headers.get('Authorization', '') if not authorization: self.send_autherror(401, "Authorization Required") return False scheme, credentials = authorization.split() if scheme != 'Basic': self.send_error(501) return False credentials = base64.decodestring(credentials) user, password = credentials.split(':', 2) if not self.get_userinfo(user, password, self.command): self.send_autherror(401, "Authorization Required") return False return True def send_autherror(self, code, message=None): """Send and log an auth error reply. Arguments are the error code, and a detailed message. The detailed message defaults to the short entry matching the response code. This sends an error response (so it must be called before any output has been generated), logs the error, and finally sends a piece of HTML explaining the error to the user. """ try: short, long = self.responses[code] except KeyError: short, long = '???', '???' if message is None: message = short explain = long self.log_error("code %d, message %s", code, message) # using _quote_html to prevent Cross Site Scripting attacks (see bug # #1100201) content = (self.error_auth_message_format % {'code': code, 'message': _quote_html(message), 'explain': explain}) self.send_response(code, message) self.send_header('Content-Type', self.error_content_type) self.send_header('WWW-Authenticate', 'Basic realm="PyWebDAV"') self.send_header('Connection', 'close') self.end_headers() self.wfile.write(content) error_auth_message_format = DEFAULT_AUTH_ERROR_MESSAGE def get_userinfo(self, user, password, command): """Checks if the given user and the given password are allowed to access. """ # Always reject return None