-
Notifications
You must be signed in to change notification settings - Fork 0
/
customRoutes.py
executable file
·151 lines (128 loc) · 4.05 KB
/
customRoutes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import logging
import nfty.db as db
import nfty.njson as json
import nfty.receipts as rcpt
import nfty.urls as shortner
from bottle import (
Bottle,
get,
request,
abort,
route,
template,
redirect,
)
import nfty.constants as constants
from api.clients import qry as sqlclient, search, Client
from api._config import systemoptions
from api.users import User
logger = logging.getLogger("AppLogger")
cRoute = Bottle()
brand = systemoptions["rootname"]
@get("/app")
@get("/app/<filepath:path>")
@route("/login", method=["GET", "POST"])
@route("/sign-up", method=["GET", "POST"])
@route("/signup", method=["GET", "POST"])
@route("/sso", method=["GET", "POST"])
@route("/verify-email", method=["GET", "POST"])
def _app(filepath=""):
logger.debug("app, login, sign-up, sso or verify-email called")
vue = "dist/index.html"
return template(vue)
@get("/report/<formname>")
@get("/reports/<formname>")
@get("/report/<formname>/<option>")
@get("/reports/<formname>/<option>")
@get("/report/<formname>/<option>/<option2>")
@get("/reports/<formname>/<option>/<option2>")
def _reporthandler(formname=None, option="", option2=""):
u = User()
if u.utype != constants.ADMIN:
redirect("/login")
payload = dict(request.query.decode())
tpl = "templates/reports/%s.tpl" % (str(formname).strip().lower())
if option:
option, client = search(option, name_search=False)
else:
option, client = search(list(u.clients.keys())[0], name_search=False)
return template(
tpl,
title="DUMPSTERFIRE {}".format(formname),
user=u,
db=db,
formname=formname,
apikey=u.apikey or constants.API_KEY_LOGIN,
tk=json,
pl=payload,
option=option,
option2=option2,
msg=dict(request.query.decode()),
url=(request.urlparts.netloc, request.urlparts.path),
client=client,
c=Client,
)
@get("/admin/<formname>")
@get("/admin/<formname>/<option>")
@get("/admin/<formname>/<option>/<option2>")
def _admin(formname=None, option=None, option2=None):
from api.clients import get_all_clients as clients
logger.debug("Create link called")
u = User()
payload = dict(request.query.decode())
logger.info(f"admin form called with payload: {payload}")
tpl = "templates/reports/%s.tpl" % (str(formname).strip().lower())
return template(
tpl,
title="TRIPLE {}".format(formname),
user=u,
db=db,
formname=formname,
apikey=u.apikey or constants.API_KEY_LOGIN,
tk=json,
pl=payload,
option=option,
option2=option2,
msg=dict(request.query.decode()),
url=(request.urlparts.netloc, request.urlparts.path),
clients=clients(),
)
@route("/logout", method=["GET", "POST"])
def logout_submit():
logger.debug("Logout called")
user = User()
user.logout()
return template("templates/logout.tpl")
@get("/receipt/<id>")
@get("/ticket/<id>")
def receipt(id=""):
logger.debug("receipt or ticket called")
pl = json.merge_dicts(dict(request.forms), dict(request.query.decode()))
return rcpt.Generator(id).generate(pl or {"output": "link"})
@get("/importfile")
@get("/importfile/<method>")
def importfile(method=None):
u = User()
if not u.id:
abort(403, 'Not logged in.')
return template("templates/fileupload/importfiles.tpl", method=method or "DUMPSTERFIRE", title=method )
@get("/download/<id>")
def download(id=""):
logger.debug(f"download called with id: {id}")
from nfty.docs import Document
logger.info(f"Downloading Document Id: {id}")
return Document({}, {}).download(id)
@get("/file")
@get("/file/<clientid>")
def importfile(clientid=None):
logger.debug("import file called")
u = User()
if not clientid and u.clientid:
clientid = u.clientid
if not clientid and not u.clientid:
redirect("/login")
c = Client(clientid)
return template("templates/fileupload/clientupload.tpl", c=c, title=c.name)
@get("/url/<id>")
def shorter(id=""):
redirect(shortner.get(id))