Question

My english is poor. I am sorry for this.

I bought a Wİndows server with plesk panel. I load to FTP python script. because the site is written with python.

When I enter the site, I see "Authentication Required". But I want to see this window. I want that everyone can enter the site and run to cgi script.

How can I make this?

Was it helpful?

Solution

upd.you rewrite your question?

cgi prints http response to stdout. first of all you need to get headers... if header 'Authorization' is present you can decode login and password from it. if no such header or passord invalid you must: send 401 response send 'WWW-Authenticate' header that contains 'Basic realm=\"Message\"' for basic authorization. also possible Digest,Ntlm etc.

if browser gets 401 response it asks user for password (even if ajax), encodes login and password with method requsted by server, sends request again with 'Authorization' header.

not CGI code sample, decorator for HTTPServer,BaseHTTPRequestHandler

def login_required(f):
def authenticate(self,*args,**kwargs):

    if conf.get('noauth'):
        return f(self,*args,**kwargs)

    if self.headers.getheader('Authorization') :
        cred = base64.b64decode(self.headers.getheader('Authorization').split(' ')[1])


        users = conf.get('users', [])
        if cred in users:
            self.creds = cred
            return f(self,*args,**kwargs)
#else
    self.send_response(401)
    self.send_header('WWW-Authenticate', 'Basic realm=\"Meter\"')
    self.send_header('Content-type', 'text/html')
    self.end_headers()
    self.wfile.write('Not authenticated.')
    return False
return authenticate
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top