From 94de534b6a6ef9a269b41124e4c55a21dd85ea7f Mon Sep 17 00:00:00 2001 From: JLesuperb Date: Sat, 19 Mar 2016 15:47:17 -0700 Subject: [PATCH] Added files via upload --- .htaccess | 7 +++++++ e.py | 15 +++++++++++++++ index.py | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 .htaccess create mode 100644 e.py create mode 100644 index.py diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..e61be20 --- /dev/null +++ b/.htaccess @@ -0,0 +1,7 @@ +ErrorDocument 404 /python/e.py?error=404 +ErrorDocument 403 /python/e.py?error=403 +#ErrorDocument 500 /python/e.py?error=500 + +RewriteEngine on +#RewriteRule ^([a-zA-Z0-9\-_/]*)$ index.py?cmd=$1 +RewriteRule ^([a-zA-Z0-9\-\_\/]*)$ index.py?cmd=$1 \ No newline at end of file diff --git a/e.py b/e.py new file mode 100644 index 0000000..383d8a6 --- /dev/null +++ b/e.py @@ -0,0 +1,15 @@ +#!/Programs/Python34/python + +import cgi +import os +import core.web + +WEB_ROOT = os.environ["SCRIPT_NAME"].replace("e.py", "") +ROOT = os.environ["SCRIPT_FILENAME"].replace("e.py", "") +getMethod = cgi.FieldStorage() +error = getMethod.getvalue("error") +current_url = core.web.current_url() +if error is None or error != int: + core.web.redirect_url(WEB_ROOT+"error?code=404&url="+current_url) +elif error is int: + core.web.redirect_url(WEB_ROOT+"error?code="+error+"&url="+current_url) diff --git a/index.py b/index.py new file mode 100644 index 0000000..9f3ce42 --- /dev/null +++ b/index.py @@ -0,0 +1,39 @@ +#!/Programs/Python34/python +import cgi +import os +import cgitb +import sys +from importlib.machinery import SourceFileLoader +import core.web as web + +cgitb.enable() + +WEB_ROOT = os.environ["SCRIPT_NAME"].replace("index.py", "") +ROOT = os.environ["SCRIPT_FILENAME"].replace("index.py", "") +getMethod = cgi.FieldStorage() +cmd = getMethod.getvalue("cmd") +html = "" +if cmd is None: + file = SourceFileLoader("home", "controllers/home.py").load_module() + controller = file.Controller + html = controller.index() +else: + params = getMethod.getvalue("cmd").split('/') + error_d = ROOT + "controllers/" + params[0] + ".py" + if params[0] != "" and params[0] != "error" and os.path.exists(ROOT + "controllers/" + params[0] + ".py"): + controller = params[0] + file = SourceFileLoader(params[0], "controllers/" + params[0] + ".py").load_module() + controller = file.Controller + html = controller.index() + elif params[0] != "" and params[0] != "error": + file = SourceFileLoader("special", "controllers/special.py").load_module() + controller = file.Controller + html = controller.index(params[0]) + else: + file = SourceFileLoader("error", "controllers/error.py").load_module() + controller = file.Controller(WEB_ROOT) + # controller.WEB_ROOT = WEB_ROOT + html = controller.index() + +html = html.format(bundle=web.bundles, **locals()) +print(html)