Ver código fonte

리캡차 v3 지원

Surplus_Up (2DU) 6 anos atrás
pai
commit
ff742cef87
3 arquivos alterados com 59 adições e 20 exclusões
  1. 15 4
      route/setting.py
  2. 42 14
      route/tool/func.py
  3. 2 2
      version.json

+ 15 - 4
route/setting.py

@@ -465,7 +465,8 @@ def setting_2(conn, num):
             'smtp_port',
             'smtp_security',
             'smtp_email',
-            'smtp_pass'
+            'smtp_pass',
+            'recaptcha_ver'
         ]
 
         if flask.request.method == 'POST':
@@ -502,19 +503,29 @@ def setting_2(conn, num):
             for i in ['tls', 'starttls', 'plain']:
                 security_radios += '<input name="smtp_security" type="radio" value="' + i + '" ' + ('checked' if d_list[4] == i else '') + '>' + i + '<hr class="main_hr">'
 
+            re_ver = ''
+            if d_list[7] == '':
+                re_ver += '<option value="">v2</option><option value="v3">v3</option>'
+            else:
+                re_ver += '<option value="v3">v3</option><option value="">v2</option>'
+
             return easy_minify(flask.render_template(skin_check(),
                 imp = ['Google', wiki_set(), custom(), other2([0, 0])],
                 data = '''
                     <form method="post">
                         <h2><a href="https://www.google.com/recaptcha/admin">''' + load_lang('recaptcha') + '''</a></h2>
-                        <span>HTML</span>
+                        <span>''' + load_lang('public_key') + '''</span>
+                        <hr class=\"main_hr\">
+                        <input name="recaptcha" value="''' + html.escape(d_list[0]) + '''">
                         <hr class=\"main_hr\">
-                        <input name="recaptcha" placeholder='&lt;div class="g-recaptcha" data-sitekey="''' + load_lang('public_key') + '''"&gt;&lt;/div&gt;' value="''' + html.escape(d_list[0]) + '''">
-                        <hr>
                         <span>''' + load_lang('secret_key') + '''</span>
                         <hr class=\"main_hr\">
                         <input name="sec_re" value="''' + html.escape(d_list[1]) + '''">
                         <hr class=\"main_hr\">
+                        <select>
+                            ''' + re_ver + '''
+                        </select>
+                        <hr class=\"main_hr\">
                         <h2>''' + load_lang('smtp_setting') + ' (' + load_lang('restart_required') + ''')</h1>
                         <span>''' + load_lang('smtp_server') + '''</span>
                         <hr class=\"main_hr\">

+ 42 - 14
route/tool/func.py

@@ -166,20 +166,6 @@ def render_set(title = '', data = '', num = 0, s_data = 0, include = None):
         else:
             return 'HTTP Request 404'
 
-def captcha_get():
-    data = ''
-
-    if ip_or_user() != 0:
-        curs.execute(db_change('select data from other where name = "recaptcha"'))
-        recaptcha = curs.fetchall()
-        if recaptcha and recaptcha[0][0] != '':
-            curs.execute(db_change('select data from other where name = "sec_re"'))
-            sec_re = curs.fetchall()
-            if sec_re and sec_re[0][0] != '':
-                data += '<script src="https://www.google.com/recaptcha/api.js" async defer></script>' + recaptcha[0][0] + '<hr class=\"main_hr\">'
-
-    return data
-
 def update(ver_num):
     print('----')
     # 업데이트 하위 호환 유지 함수
@@ -204,6 +190,17 @@ def update(ver_num):
     if ver_num < 3171600:
         curs.execute(db_change('delete from cache_data'))
 
+    if ver_num < 3171800:
+        curs.execute(db_change("select data from other where name = 'recaptcha'"))
+        change_rec = curs.fetchall()
+        if change_rec and change_rec[0][0] != '':
+            new_rec = re.search('data-sitekey="([^"]+)"', change_rec[0][0])
+            if new_rec:
+                curs.execute(db_change("update other set data = ? where name = 'recaptcha'"), [new_rec.groups()[0]])
+            else:
+                curs.execute(db_change("update other set data = '' where name = 'recaptcha'"))
+                curs.execute(db_change("update other set data = '' where name = 'sec_re'"))
+
     conn.commit()
     print('Update pass')
     print('----')
@@ -284,6 +281,37 @@ def pw_check(data, data2, type_d = 'no', id_d = ''):
 
     return re_data
 
+def captcha_get():
+    data = ''
+
+    if ip_or_user() != 0:
+        curs.execute(db_change('select data from other where name = "recaptcha"'))
+        recaptcha = curs.fetchall()
+        if recaptcha and recaptcha[0][0] != '':
+            curs.execute(db_change('select data from other where name = "sec_re"'))
+            sec_re = curs.fetchall()
+            if sec_re and sec_re[0][0] != '':
+                curs.execute(db_change('select data from other where name = "recaptcha_ver"'))
+                if not curs.fetchall() or curs.fetchall()[0][0] == '':
+                    data += '' + \
+                        '<script src="https://www.google.com/recaptcha/api.js" async defer></script>' + \
+                        '<div class="g-recaptcha" data-sitekey="' + recaptcha[0][0] + '"></div>' + \
+                        '<hr class=\"main_hr\">' + \
+                    ''
+                else:
+                    data += '' + \
+                        '<input type="hidden" id="g-recaptcha" name="g-recaptcha">' + \
+                        '<script type="text/javascript">' + \
+                            'grecaptcha.ready(function() {' + \
+                                'grecaptcha.execute(\'' + recaptcha[0][0] + '\', {action: \'homepage\'}).then(function(token) {' + \
+                                    'document.getElementById(\'g-recaptcha\').value = token;' + \
+                                '});' + \
+                            '});' + \
+                        '</script>' + \
+                    ''
+
+    return data
+
 def captcha_post(re_data, num = 1):
     if num == 1:
         curs.execute(db_change('select data from other where name = "sec_re"'))

+ 2 - 2
version.json

@@ -1,7 +1,7 @@
 {
     "master" : {
-        "r_ver" : "v3.1.7-master-17",
-        "c_ver" : "3171600",
+        "r_ver" : "v3.1.7-master-18",
+        "c_ver" : "3171800",
         "s_ver" : "7"
     }, "stable" : {
         "r_ver" : "v3.1.6-stable-05",