File: frontend.py

package info (click to toggle)
pyatem 0.13.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,776 kB
  • sloc: python: 15,193; xml: 435; ansic: 256; sh: 26; makefile: 20
file content (22 lines) | stat: -rw-r--r-- 852 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import base64
from http.server import BaseHTTPRequestHandler


class AuthRequestHandler(BaseHTTPRequestHandler):
    def verify_auth(self):
        if self.config['auth']:
            ok = False
            if 'Authorization' in self.headers:
                auth = base64.b64encode(f'{self.config["username"]}:{self.config["password"]}'.encode()).decode()
                correct = f'Basic {auth}'
                if self.headers['Authorization'] == correct:
                    ok = True

            if not ok:
                self.send_response(401)
                self.send_header('WWW-Authenticate', 'Basic realm="OpenSwitcher"')
                self.send_header('Content-type', 'text/html')
                self.end_headers()
                self.wfile.write('Authentication required'.encode())
                return False
        return True