crafty-4/app/classes/web/http_handler.py

57 lines
1.6 KiB
Python
Raw Normal View History

import sys
import json
import logging
import tornado.web
import tornado.escape
import requests
from app.classes.shared.helpers import helper
from app.classes.web.base_handler import BaseHandler
from app.classes.shared.console import console
2021-09-08 22:01:10 +00:00
from app.classes.shared.main_models import Users, fn
logger = logging.getLogger(__name__)
try:
import bleach
except ModuleNotFoundError as e:
logger.critical("Import Error: Unable to load {} module".format(e.name), exc_info=True)
console.critical("Import Error: Unable to load {} module".format(e.name))
sys.exit(1)
class HTTPHandler(BaseHandler):
def get(self):
url = str(self.request.host)
port = 443
url_list = url.split(":")
if url_list[0] != "":
url = 'https://' + url_list[0]
else:
url = 'https://' + url
db_port = helper.get_setting('https_port')
try:
resp = requests.get(url + ":" + str(port))
resp.raise_for_status()
except Exception as err:
port = db_port
self.redirect(url+":"+str(port))
class HTTPHandlerPage(BaseHandler):
def get(self, page):
url = str(self.request.host)
port = 443
url_list = url.split(":")
if url_list[0] != "":
url = 'https://' + url_list[0]
else:
url = 'https://' + url
db_port = helper.get_setting('https_port')
try:
resp = requests.get(url + ":" + str(port))
resp.raise_for_status()
except Exception as err:
port = db_port
self.redirect(url+":"+str(port))