__main__.py 1.99 KB
Newer Older
1
#!/usr/bin/env python3
2
import logging
3 4 5
import os
import ssl
import threading
6

7 8 9
logging.basicConfig(level=logging.DEBUG, format="%(message)s")
from http.server import HTTPServer
from xvfbwrapper import Xvfb
10
# import ipdb; ipdb.set_trace()
11

12 13 14
from .lib.config import Config
from .lib.controller.server import Server
from .lib.controller.api import Api
15

16
# assure the logging dir
17 18 19
if not os.path.exists(Config.LOG_DIR):
    os.makedirs(Config.LOG_DIR)

20
# server setup
21
Api.reset()
22 23
address = '0.0.0.0'
httpd = HTTPServer((address, Config.APP_PORT), Server)
24 25
httpd.socket = ssl.wrap_socket(httpd.socket,
                               server_side=True,
26 27
                               # together private + cert, http://stackoverflow.com/questions/19705785/python-3-https-webserver
                               certfile=Config.DIR + 'cert-mdmaug.pem',
28
                               ssl_version=ssl.PROTOCOL_TLSv1)
29 30
display = Xvfb()
display.start()
31
try:
32
    print(f'Listening at https://{address}:{Config.APP_PORT}')
33
    for _ in range(Config.profileCount):
34 35
        threading.Thread(target=httpd.serve_forever).start()
except (KeyboardInterrupt, SystemExit):
36
    display.stop()
37 38

'''
39
XX TO BE DELETED:
40
How to debug mysql:
41 42 43
conn = pymysql.connect(host='localhost', user='root', passwd='lopuch', db='mdmaug', charset='utf8')
cur = conn.cursor()
cur.execute("""SELECT name from turris JOIN status ON status.id = turris.status WHERE ip = %s""", (ip,))
44
vote = self.cur.fetchone()[0]
45
logging.debug(vote)
46
exit()
47 48 49 50 51 52 53 54 55 56 57 58 59

from lib.model.dbp import Status, Export, Turris, Whitelist
url = "http://stat.cz"
logging.debug(Whitelist.select().count())
quit()
#ip = "112.78.117.153"
#logging.debug(Turris.select().join(Status, on=(Status.id == Turris.status)).where(Turris.ip == ip).limit(1).get().id)
#status = Turris.select().join(Status, on=(Status.id == Turris.status)).where(Turris.ip == ip).limit(1).get().status
#logging.debug(status)
#Turris.select().where(Turris.id == 5).count()
#from urllib.parse import parse_qs
#from urllib.parse import urlparse
#quit()
60
'''