Forráskód Böngészése

Merge pull request #616 from 2du/master

등등
잉여강화기 (SPUP) 7 éve
szülő
commit
4c0f250ac6

+ 8 - 75
app.py

@@ -8,7 +8,7 @@ for i_data in os.listdir("route"):
 
         exec("from route." + f_src + " import *")
 
-r_ver = 'v3.0.9-stable'
+r_ver = 'v3.0.9-stable-04'
 c_ver = '400000'
 
 print('Version : ' + r_ver)
@@ -226,14 +226,12 @@ if not rep_data:
 else:
     rep_key = rep_data[0][0]
 
-
 curs.execute('select data from other where name = "adsense"')
 adsense_result = curs.fetchall()
 if not adsense_result:
     curs.execute('insert into other (name, data) values ("adsense", "False")')
     curs.execute('insert into other (name, data) values ("adsense_code", "")')
 
-
 curs.execute('delete from other where name = "ver"')
 curs.execute('insert into other (name, data) values ("ver", ?)', [c_ver])
 
@@ -370,12 +368,7 @@ def search():
 
 @app.route('/goto', methods=['POST'])
 def goto():
-    curs.execute("select title from data where title = ?", [flask.request.form.get('search', 'test')])
-    data = curs.fetchall()
-    if data:
-        return redirect('/w/' + url_pas(flask.request.form.get('search', 'test')))
-    else:
-        return redirect('/search/' + url_pas(flask.request.form.get('search', 'test')))
+    return goto_2(conn)
 
 @app.route('/search/<everything:name>')
 def deep_search(name = ''):
@@ -452,7 +445,7 @@ def close_topic_list(name = None, tool = None):
 def login():
     return login_2(conn)
 
-@app.route('/oauth/<regex("discord|naver|facebook"):platform>/<regex("init|callback"):func>', methods=['GET', 'POST'])
+@app.route('/oauth/<regex("discord|naver|facebook|kakao"):platform>/<regex("init|callback"):func>', methods=['GET', 'POST'])
 def login_oauth(platform = None, func = None):
     return login_oauth_2(conn, platform, func)
                 
@@ -544,12 +537,7 @@ def count_edit(name = None):
         
 @app.route('/random')
 def title_random():
-    curs.execute("select title from data order by random() limit 1")
-    data = curs.fetchall()
-    if data:
-        return redirect('/w/' + url_pas(data[0][0]))
-    else:
-        return redirect()
+    return title_random_2(conn)
 
 @app.route('/skin_set')
 def skin_set():
@@ -557,74 +545,19 @@ def skin_set():
     
 @app.route('/api/w/<everything:name>')
 def api_w(name = ''):
-    curs.execute("select data from data where title = ?", [name])
-    data = curs.fetchall()
-    if data:
-        json_data = { "title" : name, "data" : render_set(title = name, data = data[0][0]) }
-    
-        return flask.jsonify(json_data)
-    else:
-        return flask.jsonify({})
+    return api_w_2(conn, name)
     
 @app.route('/api/raw/<everything:name>')
 def api_raw(name = ''):
-    curs.execute("select data from data where title = ?", [name])
-    data = curs.fetchall()
-    if data:
-        json_data = { "title" : name, "data" : render_set(title = name, data = data[0][0], s_data = 1) }
-    
-        return flask.jsonify(json_data)
-    else:
-        return flask.jsonify({})
+    return api_raw_2(conn, name)
 
 @app.route('/api/topic/<everything:name>/sub/<sub>')
 def api_topic_sub(name = '', sub = '', time = ''):
-    if flask.request.args.get('time', None):
-        curs.execute("select id, data, ip from topic where title = ? and sub = ? and date >= ? order by id + 0 asc", [name, sub, flask.request.args.get('time', None)])
-    else:
-        curs.execute("select id, data, ip from topic where title = ? and sub = ? order by id + 0 asc", [name, sub])
-    data = curs.fetchall()
-    if data:
-        json_data = {}
-        for i in data:
-            json_data[i[0]] =   {
-                "data" : i[1],
-                "id" : i[2]
-            }
-
-        return flask.jsonify(json_data)
-    else:
-        return flask.jsonify({})
+    return api_topic_sub_2(conn, name, sub, time)
     
 @app.route('/views/<everything:name>')
 def views(name = None):
-    if re.search('\/', name):
-        m = re.search('^(.*)\/(.*)$', name)
-        if m:
-            n = m.groups()
-            plus = '/' + n[0]
-            rename = n[1]
-        else:
-            plus = ''
-            rename = name
-    else:
-        plus = ''
-        rename = name
-
-    m = re.search('\.(.+)$', name)
-    if m:
-        g = m.groups()
-    else:
-        g = ['']
-
-    if g == 'css':
-        return easy_minify(flask.send_from_directory('./views' + plus, rename), 'css')   
-    elif g == 'js':
-        return easy_minify(flask.send_from_directory('./views' + plus, rename), 'js')
-    elif g == 'html':
-        return easy_minify(flask.send_from_directory('./views' + plus, rename))   
-    else:
-        return flask.send_from_directory('./views' + plus, rename)
+    return views_2(conn, name)
 
 @app.route('/<data>')
 def main_file(data = None):

+ 5 - 1
data/oauthsettings.json

@@ -2,7 +2,7 @@
     "_README" : {
         "en" : "To use the oAuth login feature, you must set the 'publish_url' value to a domain address that includes the HTTPS protocol, and actually support HTTPS connections.",
         "ko" : "oAuth 로그인 기능을 사용하려면 'publish_url' 값을 HTTPS 프로토콜을 포함한 도메인 주소로 설정하고, 실제로 HTTPS 연결을 지원해야 합니다.",
-        "support" : ["discord", "facebook", "naver"]
+        "support" : ["discord", "facebook", "naver", "kakao"]
     },
     "publish_url" : "https://",
     "discord" : {
@@ -16,5 +16,9 @@
     "naver" : {
         "client_id" : "",
         "client_secret" : ""
+    },
+    "kakao" : {
+        "client_id" : "",
+        "client_secret" : ""
     }
 }

+ 1 - 0
language/en-US.json

@@ -122,6 +122,7 @@
         "oauth_signin_facebook" : "Sign-in with Facebook",
         "oauth_signin_naver" : "Sign-in with NAVER",
         "oauth_signin_discord" : "Sign-in with Discord",
+        "oauth_signin_kakao" : "Sign-in with Kakao",
         "connection" : "Connection",
         "new_connection" : "Connect...",
         "user_setting" : "User settings",

+ 1 - 0
language/ko-KR.json

@@ -122,6 +122,7 @@
         "oauth_signin_facebook" : "Facebook 아이디로 로그인",
         "oauth_signin_naver" : "네이버 아이디로 로그인",
         "oauth_signin_discord" : "디스코드 아이디로 로그인",
+        "oauth_signin_kakao" : "카카오톡 아이디로 로그인",
         "connection" : "연결",
         "new_connection" : "연결...",
         "user_setting" : "사용자 설정",

+ 13 - 0
route/api_raw.py

@@ -0,0 +1,13 @@
+from .tool.func import *
+
+def api_raw_2(conn, name):
+    curs = conn.cursor()
+
+    curs.execute("select data from data where title = ?", [name])
+    data = curs.fetchall()
+    if data:
+        json_data = { "title" : name, "data" : render_set(title = name, data = data[0][0], s_data = 1) }
+    
+        return flask.jsonify(json_data)
+    else:
+        return flask.jsonify({})

+ 21 - 0
route/api_topic_sub.py

@@ -0,0 +1,21 @@
+from .tool.func import *
+
+def api_topic_sub_2(conn, name, sub, time):
+    curs = conn.cursor()
+
+    if flask.request.args.get('time', None):
+        curs.execute("select id, data, ip from topic where title = ? and sub = ? and date >= ? order by id + 0 asc", [name, sub, flask.request.args.get('time', None)])
+    else:
+        curs.execute("select id, data, ip from topic where title = ? and sub = ? order by id + 0 asc", [name, sub])
+    data = curs.fetchall()
+    if data:
+        json_data = {}
+        for i in data:
+            json_data[i[0]] =   {
+                "data" : i[1],
+                "id" : i[2]
+            }
+
+        return flask.jsonify(json_data)
+    else:
+        return flask.jsonify({})

+ 13 - 0
route/api_w.py

@@ -0,0 +1,13 @@
+from .tool.func import *
+
+def api_w_2(conn, name):
+    curs = conn.cursor()
+
+    curs.execute("select data from data where title = ?", [name])
+    data = curs.fetchall()
+    if data:
+        json_data = { "title" : name, "data" : render_set(title = name, data = data[0][0]) }
+    
+        return flask.jsonify(json_data)
+    else:
+        return flask.jsonify({})

+ 7 - 2
route/change_password.py

@@ -86,6 +86,12 @@ def change_password_2(conn, server_init):
             
             oauth_content += '</ul>'
 
+            forwarded_protocol = flask.request.headers.get('X-Forwarded-Proto', None)
+            if forwarded_protocol == 'http':
+                http_warring = '<hr class=\"main_hr\"><span>' + load_lang('http_warring') + '</span>'
+            else:
+                http_warring = ''
+
             return easy_minify(flask.render_template(skin_check(),    
                 imp = [load_lang('user_setting'), wiki_set(), custom(), other2([0, 0])],
                 data =  '''
@@ -110,8 +116,7 @@ def change_password_2(conn, server_init):
                             ''' + oauth_content + '''
                             <hr class=\"main_hr\">
                             <button type="submit">''' + load_lang('save') + '''</button>
-                            <hr class=\"main_hr\">
-                            <span>''' + load_lang('http_warring') + '''</span>
+                            ''' + http_warring + '''
                         </form>
                         ''',
                 menu = [['user', load_lang('return')]]

+ 11 - 0
route/goto.py

@@ -0,0 +1,11 @@
+from .tool.func import *
+
+def goto_2(conn):
+    curs = conn.cursor()
+
+    curs.execute("select title from data where title = ?", [flask.request.form.get('search', 'test')])
+    data = curs.fetchall()
+    if data:
+        return redirect('/w/' + url_pas(flask.request.form.get('search', 'test')))
+    else:
+        return redirect('/search/' + url_pas(flask.request.form.get('search', 'test')))

+ 29 - 19
route/login.py

@@ -48,28 +48,40 @@ def login_2(conn):
         
         return redirect('/user')  
     else:
-        oauth_content = '<link rel="stylesheet" href="/views/main_css/oauth.css"><div class="oauth-wrapper"><ul class="oauth-list">'
+        oauth_check = 0
+        oauth_content = '<link rel="stylesheet" href="/views/main_css/oauth.css"><hr class=\"main_hr\"><div class="oauth-wrapper"><ul class="oauth-list">'
         oauth_supported = load_oauth('_README')['support']
         for i in range(len(oauth_supported)):
             oauth_data = load_oauth(oauth_supported[i])
             if oauth_data['client_id'] != '' and oauth_data['client_secret'] != '':
-                oauth_content +=    '''
-                                    <li>
-                                        <a href="/oauth/{}/init">
-                                            <div class="oauth-btn oauth-btn-{}">
-                                                <div class="oauth-btn-logo oauth-btn-{}"></div>
-                                                {}
-                                            </div>
-                                        </a>
-                                    </li>
-                                    '''.format(
-                                        oauth_supported[i], 
-                                        oauth_supported[i], 
-                                        oauth_supported[i], 
-                                        load_lang('oauth_signin_' + oauth_supported[i])
-                                    )
+                oauth_content += '''
+                    <li>
+                        <a href="/oauth/{}/init">
+                            <div class="oauth-btn oauth-btn-{}">
+                                <div class="oauth-btn-logo oauth-btn-{}"></div>
+                                {}
+                            </div>
+                        </a>
+                    </li>
+                '''.format(
+                    oauth_supported[i], 
+                    oauth_supported[i], 
+                    oauth_supported[i], 
+                    load_lang('oauth_signin_' + oauth_supported[i])
+                )
+
+                oauth_check = 1
         
         oauth_content += '</ul></div>'
+
+        if oauth_check == 0:
+            oauth_content = ''
+
+        forwarded_protocol = flask.request.headers.get('X-Forwarded-Proto', None)
+        if forwarded_protocol == 'http':
+            http_warring = '<hr class=\"main_hr\"><span>' + load_lang('http_warring') + '</span>'
+        else:
+            http_warring = ''
         
         return easy_minify(flask.render_template(skin_check(),    
             imp = [load_lang('login'), wiki_set(), custom(), other2([0, 0])],
@@ -81,10 +93,8 @@ def login_2(conn):
                         <hr class=\"main_hr\">
                         ''' + captcha_get() + '''
                         <button type="submit">''' + load_lang('login') + '''</button>
-                        <hr class=\"main_hr\">
                         ''' + oauth_content + '''
-                        <hr class=\"main_hr\">
-                        <span>''' + load_lang('http_warring') + '''</span>
+                        ''' + http_warring + '''
                     </form>
                     ''',
             menu = [['user', load_lang('return')]]

+ 46 - 2
route/login_oauth.py

@@ -25,6 +25,10 @@ def login_oauth_2(conn, platform, func):
         api_url['redirect'] = 'https://www.facebook.com/v3.1/dialog/oauth'
         api_url['token'] = 'https://graph.facebook.com/v3.1/oauth/access_token'
         api_url['profile'] = 'https://graph.facebook.com/me'
+    elif platform == 'kakao':
+        api_url['redirect'] = 'https://kauth.kakao.com/oauth/authorize'
+        api_url['token'] = 'https://kauth.kakao.com/oauth/token'
+        api_url['profile'] = 'https://kapi.kakao.com/v2/user/me'
 
     if func == 'init':
         if oauth_data['client_id'] == '' or oauth_data['client_secret'] == '':
@@ -69,6 +73,11 @@ def login_oauth_2(conn, platform, func):
                 data['redirect_uri'], 
                 data['state']
             ))
+        elif platform == 'kakao':
+            return redirect(api_url['redirect'] + '?client_id={}&redirect_uri={}&response_type=code'.format(
+                data['client_id'], 
+                data['redirect_uri']
+            ))
 
     elif func == 'callback':
         code = flask.request.args.get('code')
@@ -95,7 +104,7 @@ def login_oauth_2(conn, platform, func):
                 'User-Agent': 'Mozilla/5.0'
             }
             token_exchange = urllib.request.Request(
-                'https://discordapp.com/api/oauth2/token',
+                api_url['token'],
                 data = bytes(urllib.parse.urlencode(data).encode()),
                 headers = headers
             )
@@ -107,7 +116,7 @@ def login_oauth_2(conn, platform, func):
                 'Authorization' : 'Bearer ' + token_json['access_token']
             }
             profile_exchange = urllib.request.Request(
-                'https://discordapp.com/api/users/@me',
+                api_url['profile'],
                 headers = headers
             )
             profile_result =  urllib.request.urlopen(profile_exchange).read().decode('utf-8')
@@ -159,6 +168,41 @@ def login_oauth_2(conn, platform, func):
                 'name': profile_result_json['name'], 
                 'picture': profile_result_json['picture']['data']['url']
             }
+        elif platform == 'kakao':
+            data = {
+                'client_id'     : data['client_id'],
+                'client_secret' : data['client_secret'],
+                'grant_type'    : 'authorization_code',
+                'redirect_uri'  : data['redirect_uri'],
+                'code'          : code
+            }
+            headers = {
+                'Content-Type': 'application/x-www-form-urlencoded',
+                'User-Agent': 'Mozilla/5.0'
+            }
+            token_exchange = urllib.request.Request(
+                api_url['token'],
+                data = bytes(urllib.parse.urlencode(data).encode()),
+                headers = headers
+            )
+            token_result = urllib.request.urlopen(token_exchange).read()
+            token_json = json.loads(token_result)
+
+            headers = {
+                'User-Agent'    : 'Mozilla/5.0',
+                'Authorization' : 'Bearer ' + token_json['access_token']
+            }
+            profile_exchange = urllib.request.Request(
+                api_url['profile'],
+                headers = headers
+            )
+            profile_result =  urllib.request.urlopen(profile_exchange).read().decode('utf-8')
+            profile_result_json = json.loads(profile_result)
+            stand_json = {
+                'id'        : profile_result_json['id'], 
+                'name'      : profile_result_json['properties']['nickname'],
+                'picture'   : profile_result_json['properties']['profile_image']
+            }
         
         if flask.session['referrer'][0:6] == 'change':
             curs.execute('select * from oauth_conn where wiki_id = ? and provider = ?', [flask.session['id'], platform])

+ 7 - 2
route/register.py

@@ -87,6 +87,12 @@ def register_2(conn):
         data = curs.fetchall()
         if data and data[0][0] != '':
             contract = data[0][0] + '<hr class=\"main_hr\">'
+        
+        forwarded_protocol = flask.request.headers.get('X-Forwarded-Proto', None)
+        if forwarded_protocol == 'http':
+            http_warring = '<hr class=\"main_hr\"><span>' + load_lang('http_warring') + '</span>'
+        else:
+            http_warring = ''
 
         return easy_minify(flask.render_template(skin_check(),    
             imp = [load_lang('register'), wiki_set(), custom(), other2([0, 0])],
@@ -101,8 +107,7 @@ def register_2(conn):
                         <hr class=\"main_hr\">
                         ''' + captcha_get() + '''
                         <button type="submit">''' + load_lang('save') + '''</button>
-                        <hr class=\"main_hr\">
-                        <span>''' + load_lang('http_warring') + '''</span>
+                        ''' + http_warring + '''
                     </form>
                     ''',
             menu = [['user', load_lang('return')]]

+ 11 - 0
route/title_random.py

@@ -0,0 +1,11 @@
+from .tool.func import *
+
+def title_random_2(conn):
+    curs = conn.cursor()
+
+    curs.execute("select title from data order by random() limit 1")
+    data = curs.fetchall()
+    if data:
+        return redirect('/w/' + url_pas(data[0][0]))
+    else:
+        return redirect()

+ 2 - 2
route/tool/func.py

@@ -475,7 +475,7 @@ def diff(seqm):
     end = end.replace('\r\n', '\n')
     sub = ''
 
-    if not re.search('\n', end):
+    if not re.search('\n$', end):
         end += '\n'
 
     num = 0
@@ -972,4 +972,4 @@ def re_error(data):
                 menu = 0
             ))
         else:
-            return redirect('/')
+            return redirect('/')

+ 32 - 0
route/views.py

@@ -0,0 +1,32 @@
+from .tool.func import *
+
+def views_2(conn, name):
+    curs = conn.cursor()
+
+    if re.search('\/', name):
+        m = re.search('^(.*)\/(.*)$', name)
+        if m:
+            n = m.groups()
+            plus = '/' + n[0]
+            rename = n[1]
+        else:
+            plus = ''
+            rename = name
+    else:
+        plus = ''
+        rename = name
+
+    m = re.search('\.(.+)$', name)
+    if m:
+        g = m.groups()
+    else:
+        g = ['']
+
+    if g == 'css':
+        return easy_minify(flask.send_from_directory('./views' + plus, rename), 'css')   
+    elif g == 'js':
+        return easy_minify(flask.send_from_directory('./views' + plus, rename), 'js')
+    elif g == 'html':
+        return easy_minify(flask.send_from_directory('./views' + plus, rename))   
+    else:
+        return flask.send_from_directory('./views' + plus, rename)

+ 8 - 0
views/main_css/oauth.css

@@ -37,6 +37,10 @@
 .oauth-btn.oauth-btn-discord {
     background-color: #2C2F33;
 }
+.oauth-btn.oauth-btn-kakao {
+    background-color: #ffde00;
+    color: #3c1e1e;
+}
 
 .oauth-btn-logo {
     position: absolute;
@@ -61,4 +65,8 @@
 
 .oauth-btn-logo.oauth-btn-discord {
     background-image: url(data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB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