Procházet zdrojové kódy

중간 수정 업로드

2DU před 9 roky
rodič
revize
26123a745b
5 změnil soubory, kde provedl 161 přidání a 10 odebrání
  1. 61 6
      app.py
  2. 19 2
      static/style.css
  3. 1 1
      templates/edit.html
  4. 1 1
      templates/index.html
  5. 79 0
      templates/recentchanges.html

+ 61 - 6
app.py

@@ -4,6 +4,8 @@ app = Flask(__name__)
 from urllib import parse
 import json
 import pymysql
+import time
+import base64
 
 json_data=open('set.json').read()
 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')
 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('/w/')
 def redirect():
     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>')
 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()
     if(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:
-        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'])
 def edit(name = None):
     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) + '" />'
     else:
-        curs.execute("select * from data where title = '" + name + "'")
+        curs.execute("select * from data where title = '" + parse.quote(name) + "'")
         rows = curs.fetchall()
         if(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:
             return render_template('edit.html', title = name, logo = data['name'], page = parse.quote(name), data = '')
 
@@ -51,4 +106,4 @@ def setup():
     return '문제 없음'
 
 if __name__ == '__main__':
-    app.run()
+    app.run(host = '0.0.0.0', port = 3000)

+ 19 - 2
static/style.css

@@ -13,12 +13,13 @@
 #log {
     line-height: 32px;
     width: 20px;
-    height: 42.2px;
+    height: 36px;
     font-size: 16px;
     color: white;
     float: left;
     margin-right: 10px;
     padding: 5px;
+	margin-top: 9px;
 }
 #log:hover, #log:focus {
     color: #d1bd6b;
@@ -214,6 +215,7 @@ s:hover, strike:hover, del:hover {
     width: 250px;
     float: right;
 	padding: 5px;
+	margin-bottom: 0;
 }
 
 #logo {
@@ -230,6 +232,10 @@ s:hover, strike:hover, del:hover {
 	position: relative;
 }
 
+.btn {
+    height: 34px;
+}
+
 .scroll-buttons a:link, .scroll-buttons a:visited {
     color: white;
 }
@@ -298,6 +304,14 @@ div.scroll-buttons {
     position: relative;
 }
 
+#is_mobile {
+    margin-left: 5px;
+}
+
+.scroll-buttons .fa {
+    margin-top: 5px;
+}
+
 @media (max-width: 939px) {
 	#search {
 		float: right;
@@ -307,6 +321,7 @@ div.scroll-buttons {
 	#search {
 		float: left;
 		width: 100%;
+		margin-bottom: 5px;
 	}
 	.input-group {
 		width: 100%;
@@ -326,7 +341,7 @@ body {
 #RecentChanges {
 	line-height: 32px;
     width: 100px;
-    height: 42.2px;
+    height: 45px;
     font-size: 16px;
     color: white;
     float: left;
@@ -339,6 +354,8 @@ body {
 	#RecentChanges {
 		width: 20px;
 		margin-right: 10px;
+		margin-top: 9px;
+		height: 36px;
 	}
 }
 

+ 1 - 1
templates/edit.html

@@ -23,7 +23,7 @@
 				</div>
 				<form method="POST" action="/search" id="search">
 					<div class="input-group">
-						<input class="form-control" name="name" type="text">
+						<input class="form-control" name="search" type="text">
 						<span class="input-group-button"><button class="btn"><i class="fa fa-long-arrow-left" aria-hidden="true"></i></button></span>
 					</div>
 				</form>

+ 1 - 1
templates/index.html

@@ -23,7 +23,7 @@
 				</div>
 				<form method="POST" action="/search" id="search">
 					<div class="input-group">
-						<input class="form-control" name="name" type="text">
+						<input class="form-control" name="search" type="text">
 						<span class="input-group-button"><button class="btn"><i class="fa fa-long-arrow-left" aria-hidden="true"></i></button></span>
 					</div>
 				</form>

+ 79 - 0
templates/recentchanges.html

@@ -0,0 +1,79 @@
+<html>
+	<head>
+		<title>{{title}}</title>
+		<link rel="stylesheet" href="{{url_for('static', filename='primer.css')}}">
+		<link rel="stylesheet" href="{{url_for('static', filename='style.css')}}">
+		<link rel="stylesheet" href="{{url_for('static', filename='font-awesome/css/font-awesome.min.css')}}">
+		<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.5.1/katex.min.css">
+		<script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.5.1/katex.min.js"></script>
+		<link rel="shortcut icon" href="{{url_for('static', filename='images/on.ico')}}">
+		<meta name="viewport" content="width=device-width, initial-scale=1">
+	</head>
+	<body>
+		<br>
+		<div class="one-fifth column">
+			<div id="top">
+				<a href="/" id="logo">{{logo}}</a>
+				<div>
+					<a href="/RecentChanges" id="RecentChanges"><i class="fa fa-refresh" aria-hidden="true"></i><span id="is_mobile">최근 변경</span></a>
+					<a href="/RecentChanges" id="RecentChanges"><i class="fa fa-comment" aria-hidden="true"></i><span id="is_mobile">최근 토론</span></a>
+					<a href="/random" id="log"><i class="fa fa-random" aria-hidden="true"></i></a>
+					<a href="/user" id="log"><i class="fa fa-user" aria-hidden="true"></i></a>
+					<a href="/other" id="log"><i class="fa fa-cogs" aria-hidden="true"></i></a>
+				</div>
+				<form method="POST" action="/search" id="search">
+					<div class="input-group">
+						<input class="form-control" name="search" type="text">
+						<span class="input-group-button"><button class="btn"><i class="fa fa-long-arrow-left" aria-hidden="true"></i></button></span>
+					</div>
+				</form>
+			</div>
+		</div>
+		<div class="scroll-buttons">
+			<a class="scroll-toc" href="#toc"><i class="fa fa-list-alt" aria-hidden="true"></i></a>
+			<a class="scroll-button" href="#top" id="left"><i class="fa fa-arrow-up" aria-hidden="true"></i></a>
+			<a class="scroll-bottom" href="#powered" id="right"><i class="fa fa-arrow-down" aria-hidden="true"></i></a>
+		</div>
+		<div id="left_bar">
+			<a href="#">맨 위로</a>
+			<br>
+			<br>
+			<!-- 내용 넣는 자리 -->
+		</div>
+		<div class="four-fifths column">
+			<h1 class="title">최근 변경내역</h1>
+			<table style="width: 100%;">
+				<tbody>
+					<tr>
+						<td style="text-align: center;width:33.33%;font-size: 13px;">문서명</td>
+						<td style="text-align: center;width:33.33%;font-size: 13px;">기여자</td>
+						<td style="text-align: center;width:33.33%;font-size: 13px;">시간</td>
+					</tr>
+				</tbody>
+			</table>
+			{% for row in rows %}
+			<table style="width: 100%;">
+				<tbody>
+					<tr>
+						<td style="text-align: center;width:33.33%;font-size: 13px;"><a href="/w/{{row['title']}}">{{row['title']}}</a></td>
+						<td style="text-align: center;width:33.33%;font-size: 13px;">{{row['ip']}}</td>
+						<td style="text-align: center;width:33.33%;font-size: 13px;">{{row['date']}}</td>
+					</tr>
+					<tr>
+						{% if row['send'] %}
+						<td colspan="3" style="text-align: center;width:100%;font-size: 13px;">{{row['send']}}</td>
+						{% else %}
+						<td colspan="3" style="text-align: center;width:100%;font-size: 13px;"><br></td>
+						{% endif %}
+					</tr>
+				</tbody>
+			</table>
+			{% endfor %}
+			<hr id="last">
+			<p>{{license}}</p>
+			<div id="powered">
+				<a href="https://github.com/2DU/Ownet"><img src="{{url_for('static', filename='images/on2.png')}}" width="100px"></a>
+			</div>
+		</div>
+	</body>
+</html>