-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
80 lines (62 loc) · 1.9 KB
/
main.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
from flask import Flask
from flask import request
from flask import Response
import random
import lorem
import dominate
import datetime
from dominate.tags import *
app = Flask(__name__)
link_min=0
link_max=50
keyword_prob=0.6
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def hello_world(path):
host = request.headers.get("Host")
print(host)
if path == "robots.txt":
return ""
if path.startswith("sitemap"):
return sitemap(host)
has_keyword = random.random() < keyword_prob
page = gen_page(host, path, has_keyword)
return Response(page, mimetype='text/html')
def sitemap(host):
sitemap = """<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://%s/123.html</loc>
<lastmod>2005-01-01</lastmod>
<changefreq>monthly</changefreq>
<priority>0.8</priority>
</url>
</urlset> """ % host
return sitemap
def gen_page(host, path, has_keyword):
doc = dominate.document(title="fakenet")
#with doc.head:
# link(rel="canonical", href="http://"+host+"/real_"+path)
with doc:
with div(id='menu').add(ul(id='links')):
for l in gen_links():
li(a(l, href=l))
with div(id='content'):
with div():
attr(cls='article')
delta = random.randint(0, 10) * -1
now = datetime.datetime.now().date()
d = now + datetime.timedelta(delta)
span(d.isoformat(), cls='date')
if has_keyword:
p("attack")
[p(lorem.paragraph()) for i in range(10)]
return doc.__str__()
def gen_links():
links = []
for i in range(random.randint(link_min,link_max)):
l = random.randint(0, 1000)
links.append("/%d.html" % l)
return links
if __name__ == '__main__':
app.run()