forked from nat/sludge
add support for configuration
This commit is contained in:
parent
d7bc8243e8
commit
6175fafd20
16
src/main.py
16
src/main.py
@ -4,8 +4,12 @@ import threading
|
|||||||
import socket
|
import socket
|
||||||
import ssl
|
import ssl
|
||||||
import os
|
import os
|
||||||
|
import yaml
|
||||||
|
|
||||||
os.chdir('site')
|
with open('./config.yaml', 'r') as f:
|
||||||
|
config = yaml.safe_load(f.read())
|
||||||
|
|
||||||
|
os.chdir(config['file-dir'])
|
||||||
|
|
||||||
def handle_client(client: socket.socket, addr: Tuple[str, int]) -> None:
|
def handle_client(client: socket.socket, addr: Tuple[str, int]) -> None:
|
||||||
request = bytes()
|
request = bytes()
|
||||||
@ -22,16 +26,16 @@ def handle_client(client: socket.socket, addr: Tuple[str, int]) -> None:
|
|||||||
.send(client)
|
.send(client)
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
http_thread = threading.Thread(name='http', target=serve, args=('0.0.0.0', 6000, handle_client))
|
http_thread = threading.Thread(name='http', target=serve, args=('0.0.0.0', config['http-port'], handle_client))
|
||||||
https_thread = threading.Thread(name='https', target=serve, args=('0.0.0.0', 6001, handle_client), kwargs=dict(wrapper=lambda socket: [
|
https_thread = threading.Thread(name='https', target=serve, args=('0.0.0.0', config['https-port'], handle_client), kwargs=dict(wrapper=lambda socket: [
|
||||||
ctx:=ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER),
|
ctx:=ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER),
|
||||||
ctx.load_cert_chain(certfile='./badcert.pem', keyfile='./badkey.pem'),
|
ctx.load_cert_chain(certfile=config['ssl-cert'], keyfile=config['ssl-key']),
|
||||||
ctx.wrap_socket(socket, server_side=True)
|
ctx.wrap_socket(socket, server_side=True)
|
||||||
][-1]
|
][-1]
|
||||||
))
|
))
|
||||||
|
|
||||||
#http_thread.start()
|
http_thread.start() if config['http-port'] else None
|
||||||
https_thread.start()
|
https_thread.start() if config['https-port'] else None
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user