|
@@ -4,6 +4,8 @@ app = Flask(__name__)
|
|
|
from urllib import parse
|
|
from urllib import parse
|
|
|
import json
|
|
import json
|
|
|
import pymysql
|
|
import pymysql
|
|
|
|
|
+import time
|
|
|
|
|
+import base64
|
|
|
|
|
|
|
|
json_data=open('set.json').read()
|
|
json_data=open('set.json').read()
|
|
|
data = json.loads(json_data)
|
|
data = json.loads(json_data)
|
|
@@ -11,31 +13,84 @@ data = json.loads(json_data)
|
|
|
conn = pymysql.connect(host = data['host'], user = data['user'], password = data['pw'], db = data['db'], charset = 'utf8')
|
|
conn = pymysql.connect(host = data['host'], user = data['user'], password = data['pw'], db = data['db'], charset = 'utf8')
|
|
|
curs = conn.cursor(pymysql.cursors.DictCursor)
|
|
curs = conn.cursor(pymysql.cursors.DictCursor)
|
|
|
|
|
|
|
|
|
|
+def getip(request):
|
|
|
|
|
+ if request.headers.getlist("X-Forwarded-For"):
|
|
|
|
|
+ ip = request.headers.getlist("X-Forwarded-For")[0]
|
|
|
|
|
+ else:
|
|
|
|
|
+ ip = request.remote_addr
|
|
|
|
|
+ return ip
|
|
|
|
|
+
|
|
|
|
|
+def getnow():
|
|
|
|
|
+ now = time.localtime()
|
|
|
|
|
+ s = "%04d-%02d-%02d %02d:%02d:%02d" % (now.tm_year, now.tm_mon, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec)
|
|
|
|
|
+ return s
|
|
|
|
|
+
|
|
|
|
|
+def recent(title, ip, today, send):
|
|
|
|
|
+ curs.execute("insert into rc (title, date, ip, send, leng, back) value ('" + title + "', '" + today + "', '" + ip + "', '" + send + "', '', '')")
|
|
|
|
|
+ conn.commit()
|
|
|
|
|
+
|
|
|
|
|
+def history(number, title, data, date, ip, send, leng):
|
|
|
|
|
+ curs.execute("insert into history (id, title, data, date, ip, send, leng) value ()")
|
|
|
|
|
+ conn.commit()
|
|
|
|
|
+
|
|
|
@app.route('/')
|
|
@app.route('/')
|
|
|
@app.route('/w/')
|
|
@app.route('/w/')
|
|
|
def redirect():
|
|
def redirect():
|
|
|
return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']) + '" />'
|
|
return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']) + '" />'
|
|
|
|
|
|
|
|
|
|
+@app.route('/RecentChanges')
|
|
|
|
|
+@app.route('/recentchanges')
|
|
|
|
|
+def recentchanges():
|
|
|
|
|
+ i = 0
|
|
|
|
|
+ curs.execute("select * from rc order by date desc limit 50")
|
|
|
|
|
+ rows = curs.fetchall()
|
|
|
|
|
+ if(rows):
|
|
|
|
|
+ return render_template('recentchanges.html', logo = data['name'], rows = rows)
|
|
|
|
|
+ else:
|
|
|
|
|
+ return render_template('recentchanges.html', logo = data['name'], rows = '')
|
|
|
|
|
+
|
|
|
|
|
+@app.route('/search', methods=['POST', 'GET'])
|
|
|
|
|
+def search():
|
|
|
|
|
+ if(request.method == 'POST'):
|
|
|
|
|
+ print(request.form["search"])
|
|
|
|
|
+ return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(request.form["search"]) + '" />'
|
|
|
|
|
+ else:
|
|
|
|
|
+ return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(data['frontpage']) + '" />'
|
|
|
|
|
+
|
|
|
@app.route('/w/<name>')
|
|
@app.route('/w/<name>')
|
|
|
def w(name = None):
|
|
def w(name = None):
|
|
|
- curs.execute("select * from data where title = '" + name + "'")
|
|
|
|
|
|
|
+ curs.execute("select * from data where title = '" + parse.quote(name) + "'")
|
|
|
rows = curs.fetchall()
|
|
rows = curs.fetchall()
|
|
|
if(rows):
|
|
if(rows):
|
|
|
for row in rows:
|
|
for row in rows:
|
|
|
- return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name), data = row['data'])
|
|
|
|
|
|
|
+ return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name), data = parse.unquote(row['data']), license = data['license'])
|
|
|
else:
|
|
else:
|
|
|
- return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name), data = '문서 없음')
|
|
|
|
|
|
|
+ return render_template('index.html', title = name, logo = data['name'], page = parse.quote(name), data = '문서 없음', license = data['license'])
|
|
|
|
|
|
|
|
@app.route('/edit/<name>', methods=['POST', 'GET'])
|
|
@app.route('/edit/<name>', methods=['POST', 'GET'])
|
|
|
def edit(name = None):
|
|
def edit(name = None):
|
|
|
if(request.method == 'POST'):
|
|
if(request.method == 'POST'):
|
|
|
|
|
+ curs.execute("select * from data where title = '" + parse.quote(name) + "'")
|
|
|
|
|
+ rows = curs.fetchall()
|
|
|
|
|
+ if(rows):
|
|
|
|
|
+ ip = getip(request)
|
|
|
|
|
+ today = getnow()
|
|
|
|
|
+ recent(name, ip, today, request.form["send"])
|
|
|
|
|
+ curs.execute("update data set data = '" + parse.quote(request.form["content"]) + "' where title = '" + parse.quote(name) + "'")
|
|
|
|
|
+ conn.commit()
|
|
|
|
|
+ else:
|
|
|
|
|
+ ip = getip(request)
|
|
|
|
|
+ today = getnow()
|
|
|
|
|
+ recent(name, ip, today, request.form["send"])
|
|
|
|
|
+ curs.execute("insert into data (title, data, acl) value ('" + parse.quote(name) + "', '" + parse.quote(request.form["content"]) + "', '')")
|
|
|
|
|
+ conn.commit()
|
|
|
return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name) + '" />'
|
|
return '<meta http-equiv="refresh" content="0;url=/w/' + parse.quote(name) + '" />'
|
|
|
else:
|
|
else:
|
|
|
- curs.execute("select * from data where title = '" + name + "'")
|
|
|
|
|
|
|
+ curs.execute("select * from data where title = '" + parse.quote(name) + "'")
|
|
|
rows = curs.fetchall()
|
|
rows = curs.fetchall()
|
|
|
if(rows):
|
|
if(rows):
|
|
|
for row in rows:
|
|
for row in rows:
|
|
|
- return render_template('edit.html', title = name, logo = data['name'], page = parse.quote(name), data = row['data'])
|
|
|
|
|
|
|
+ return render_template('edit.html', title = name, logo = data['name'], page = parse.quote(name), data = parse.unquote(row['data']))
|
|
|
else:
|
|
else:
|
|
|
return render_template('edit.html', title = name, logo = data['name'], page = parse.quote(name), data = '')
|
|
return render_template('edit.html', title = name, logo = data['name'], page = parse.quote(name), data = '')
|
|
|
|
|
|
|
@@ -51,4 +106,4 @@ def setup():
|
|
|
return '문제 없음'
|
|
return '문제 없음'
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
|
- app.run()
|
|
|
|
|
|
|
+ app.run(host = '0.0.0.0', port = 3000)
|