Jelajahi Sumber

일부 코드 다듬기, 가입자 정보 수집 끄기 기능

Surplus_Up (2DU) 5 tahun lalu
induk
melakukan
7da1a564b4

+ 2 - 1
language/en-US.json

@@ -267,6 +267,7 @@
                 "requires_approval" : "Requires approval for register",
                 "approval_question": "Registeration questions",
                 "backup_where" : "Backup location",
+                "ua_get_off" : "Turn off members information collection",
             "_comment_2.2.3_" : "Text",
                 "register_text" : "Terms of sign-up",
                 "non_login_alert" : "Non-login alert",
@@ -337,7 +338,7 @@
             "before_acl" : "Only those who have edited this document before",
             "ban_acl" : "Include blocked users",
             "ban_admin_acl" : "Blocked users and administrators",
-            "30_day_acl" : "Only members 30 days after register",
+            "30_day_acl" : "Only members 30 days after sign up",
             "_comment_2.6_1_" : "Set",
                 "document_acl" : "Document ACL",
                 "discussion_acl" : "Discussion(s) ACL",

+ 2 - 1
language/ko-KR.json

@@ -399,5 +399,6 @@
     "same_email_error" : "동일한 이메일을 사용하는 사용자가 있습니다.",
     "input_email_error" : "입력 값에 문제가 있습니다.",
     "short_page" : "짧은 문서 목록",
-    "long_page" : "긴 문서 목록"
+    "long_page" : "긴 문서 목록",
+    "ua_get_off" : "가입자 정보 수집 끄기"
 }

+ 17 - 19
route/applications.py

@@ -4,9 +4,8 @@ def applications_2(conn):
     curs = conn.cursor()
 
     div = ''
-    admin = admin_check()
 
-    if admin != 1:
+    if admin_check() != 1:
         return re_error('/ban')
 
     curs.execute(db_change('select data from other where name = "requires_approval"'))
@@ -26,10 +25,13 @@ def applications_2(conn):
                 email = application[5]
                 if not question:
                     question = ''
+
                 if not answer:
                     answer = ''
+                
                 if not email:
                     email = ''
+                
                 div += '''
                     <form method=\"post\">
                         <table>
@@ -41,7 +43,7 @@ def applications_2(conn):
                                     <td>''' + load_lang('application_time') + '''</td><td>''' + application[1] + '''</td>
                                 </tr>
                                 <tr>
-                                    <td>''' + load_lang('approval_question') + '''</td><td>''' + question + '''</td>
+                                    <td>''' + load_lang('approval_question') + '''</td><td>''' + html.escape(question) + '''</td>
                                 </tr>
                                 <tr>
                                     <td>''' + load_lang('answer') + '''</td><td>''' + html.escape(answer) + '''</td>
@@ -62,9 +64,17 @@ def applications_2(conn):
                 '''
         else:
             div += load_lang('no_applications_now')
+
+        return easy_minify(flask.render_template(skin_check(),
+            imp = [load_lang('application_list'), wiki_set(), custom(), other2([0, 0])],
+            data = div,
+            menu = [['other', load_lang('return')]]
+        ))
     else:
         if flask.request.form.get('approve', '') != '':
-            curs.execute(db_change('select id, pw, date, encode, question, answer, ip, ua, email from user_application where token = ?'), [flask.request.form.get('approve', '')])
+            curs.execute(db_change('select id, pw, date, encode, question, answer, ip, ua, email from user_application where token = ?'), [
+                flask.request.form.get('approve', '')
+            ])
             application = curs.fetchall()
             if not application:
                 return re_error('/error/26')
@@ -83,26 +93,14 @@ def applications_2(conn):
             ])
             curs.execute(db_change("insert into user_set (name, id, data) values ('approval_question', ?, ?)"), [application[0], application[4]])
             curs.execute(db_change("insert into user_set (name, id, data) values ('approval_question_answer', ?, ?)"), [application[0], application[5]])
-            curs.execute(db_change("insert into ua_d (name, ip, ua, today, sub) values (?, ?, ?, ?, '')"), [
-                application[0], 
-                application[6], 
-                application[7], 
-                application[2]
-            ])
+            ua_plus(application[0], application[6], application[7], application[2])
             if application[8] and application[8] != '':
                 curs.execute(db_change("insert into user_set (name, id, data) values ('email', ?, ?)"), [application[0], application[8]])
+            
             curs.execute(db_change('delete from user_application where token = ?'), [flask.request.form.get('approve', '')])
- 
-
             conn.commit()
         elif flask.request.form.get('decline', '') != '':
             curs.execute(db_change('delete from user_application where token = ?'), [flask.request.form.get('decline', '')])
             conn.commit()
 
-        return redirect('/applications')
-
-    return easy_minify(flask.render_template(skin_check(),
-        imp = [load_lang('application_list'), wiki_set(), custom(), other2([0, 0])],
-        data = div,
-        menu = [['other', load_lang('return')]]
-    ))
+        return redirect('/applications')

+ 2 - 5
route/func_title_random.py

@@ -5,11 +5,8 @@ def func_title_random_2(conn):
 
     curs.execute(db_change("" + \
         "select title from data " + \
-        "where title not like 'user:%' and title not like 'category:%' and title not like 'file:%'" + \
+        "where title not like 'user:%' and title not like 'category:%' and title not like 'file:%' " + \
         "order by random() limit 1" + \
     ""))
     data = curs.fetchall()
-    if data:
-        return redirect('/w/' + url_pas(data[0][0]))
-    else:
-        return redirect()
+    return redirect('/w/' + url_pas(data[0][0])) if data else redirect()

+ 2 - 7
route/login.py

@@ -16,7 +16,7 @@ def login_2(conn):
         else:
             captcha_post('', 0)
 
-        agent = flask.request.headers.get('User-Agent')
+        user_agent = flask.request.headers.get('User-Agent', '')
         user_id = flask.request.form.get('id', '')
 
         curs.execute(db_change("select pw, encode from user where id = ?"), [user_id])
@@ -47,12 +47,7 @@ def login_2(conn):
             flask.session['head'] = css_data[0][0] if css_data else ''
             flask.session['id'] = user_id
 
-            curs.execute(db_change("insert into ua_d (name, ip, ua, today, sub) values (?, ?, ?, ?, '')"), [
-                user_id, 
-                ip, 
-                agent, 
-                get_time()
-            ])
+            ua_plus(user_id, ip, user_agent, get_time())
             conn.commit()
 
             return redirect('/user')

+ 2 - 7
route/login_2fa.py

@@ -19,7 +19,7 @@ def login_2fa_2(conn):
         else:
             captcha_post('', 0)
 
-        agent = flask.request.headers.get('User-Agent')
+        user_agent = flask.request.headers.get('User-Agent', '')
         user_id = flask.session['b_id']
 
         curs.execute(db_change('select data from user_set where name = "2fa_pw" and id = ?'), [user_id])
@@ -41,12 +41,7 @@ def login_2fa_2(conn):
         flask.session['head'] = flask.session['b_head']
         flask.session['id'] = user_id
 
-        curs.execute(db_change("insert into ua_d (name, ip, ua, today, sub) values (?, ?, ?, ?, '')"), [
-            user_id, 
-            ip, 
-            agent, 
-            get_time()
-        ])
+        ua_plus(user_id, ip, user_agent, get_time())
         conn.commit()
 
         flask.session.pop('b_id', None)

+ 1 - 7
route/login_check_key.py

@@ -10,7 +10,6 @@ def login_check_key_2(conn, tool):
         input_key = flask.request.form.get('key', '')
         user_agent = flask.request.headers.get('User-Agent', '')
 
-
         if  'c_type' in flask.session and \
             flask.session['c_type'] == 'pass_find' and \
             flask.session['c_key'] == input_key:
@@ -100,12 +99,7 @@ def login_check_key_2(conn, tool):
                     flask.session['c_id'],
                     flask.session['c_email']
                 ])
-                curs.execute(db_change("insert into ua_d (name, ip, ua, today, sub) values (?, ?, ?, ?, '')"), [
-                    flask.session['c_id'],
-                    ip,
-                    user_agent,
-                    get_time()
-                ])
+                ua_plus(flask.session['c_id'], ip, user_agent, get_time())
 
                 flask.session['id'] = flask.session['c_id']
                 flask.session['head'] = ''

+ 11 - 16
route/login_pw_change.py

@@ -11,8 +11,11 @@ def login_pw_change_2(conn):
         return redirect('/login')
 
     if flask.request.method == 'POST':
-        if flask.request.form.get('pw4', None) and flask.request.form.get('pw2', None):
-            if flask.request.form.get('pw2', None) != flask.request.form.get('pw3', None):
+        now_pw = flask.request.form.get('pw4', None)
+        new_pw = flask.request.form.get('pw2', None)
+        re_pw = flask.request.form.get('pw3', None)
+        if now_pw and new_pw and re_pw:
+            if new_pw != re_pw:
                 return re_error('/error/20')
 
             curs.execute(db_change("select pw, encode from user where id = ?"), [flask.session['id']])
@@ -20,31 +23,23 @@ def login_pw_change_2(conn):
             if not user:
                 return re_error('/error/2')
 
-            pw_check_d = pw_check(
-                flask.request.form.get('pw4', ''),
-                user[0][0],
-                user[0][1],
-                ip
-            )
-            if pw_check_d != 1:
+            if pw_check(now_pw, user[0][0], user[0][1], ip) != 1:
                 return re_error('/error/10')
 
-            hashed = pw_encode(flask.request.form.get('pw2', None))
+            curs.execute(db_change("update user set pw = ? where id = ?"), [pw_encode(new_pw), ip])
 
-            curs.execute(db_change("update user set pw = ? where id = ?"), [hashed, ip])
-
-            return redirect('/user')
+        return redirect('/user')
     else:
         return easy_minify(flask.render_template(skin_check(),
             imp = [load_lang('password_change'), wiki_set(), custom(), other2([0, 0])],
             data = '''
                 <form method="post">
                     <input placeholder="''' + load_lang('now_password') + '''" name="pw4" type="password">
-                    <hr class=\"main_hr\">
+                    <hr class="main_hr">
                     <input placeholder="''' + load_lang('new_password') + '''" name="pw2" type="password">
-                    <hr class=\"main_hr\">
+                    <hr class="main_hr">
                     <input placeholder="''' + load_lang('password_confirm') + '''" name="pw3" type="password">
-                    <hr class=\"main_hr\">
+                    <hr class="main_hr">
                     <button type="submit">''' + load_lang('save') + '''</button>
                 </form>
             ''',

+ 14 - 11
route/setting.py

@@ -50,7 +50,8 @@ def setting_2(conn, num, db_set):
             19 : 'slow_edit',
             20 : 'requires_approval',
             21 : 'backup_where',
-            22 : 'domain'
+            22 : 'domain',
+            23 : 'ua_get'
         }
         n_list = {
             0 : 'Wiki',
@@ -70,7 +71,8 @@ def setting_2(conn, num, db_set):
             19 : '0',
             20 : '',
             21 : '',
-            22 : flask.request.host_url
+            22 : flask.request.host_url,
+            23 : ''
         }
 
         if flask.request.method == 'POST':
@@ -108,16 +110,18 @@ def setting_2(conn, num, db_set):
                 else:
                     acl_div[0] += '<option value="' + acl_data + '">' + acl_data + '</option>'
 
-            check_box_div = ['', '', '', '']
-            for i in range(0, 4):
+            check_box_div = ['', '', '', '', '']
+            for i in range(0, len(check_box_div)):
                 if i == 0:
                     acl_num = 7
                 elif i == 1:
                     acl_num = 8
                 elif i == 2:
                     acl_num = 13
-                else:
+                elif i == 3:
                     acl_num = 20
+                else:
+                    acl_num = 23
 
                 if d_list[acl_num]:
                     check_box_div[i] = 'checked="checked"'
@@ -130,10 +134,7 @@ def setting_2(conn, num, db_set):
                 else:
                     branch_div += '<option value="' + i + '">' + i + '</option>'
 
-            if db_set != 'sqlite':
-                sqlite_only = 'style="display:none;"'
-            else:
-                sqlite_only = ''
+            sqlite_only = 'style="display:none;"' if db_set != 'sqlite' else ''
 
             return easy_minify(flask.render_template(skin_check(),
                 imp = [load_lang('main_setting'), wiki_set(), custom(), other2([0, 0])],
@@ -179,6 +180,8 @@ def setting_2(conn, num, db_set):
                         <hr class="main_hr">
                         <input type="checkbox" name="requires_approval" ''' + check_box_div[3] + '''> ''' + load_lang('requires_approval') + '''
                         <hr class="main_hr">
+                        <input type="checkbox" name="ua_get" ''' + check_box_div[4] + '''> ''' + load_lang('ua_get_off') + '''
+                        <hr class="main_hr">
                         <span>''' + load_lang('wiki_host') + '''</span>
                         <hr class="main_hr">
                         <input name="host" value="''' + html.escape(d_list[16]) + '''">
@@ -310,7 +313,7 @@ def setting_2(conn, num, db_set):
                         <hr class="main_hr">
                         <textarea rows="3" name="''' + i_list[11] + '''">''' + html.escape(d_list[11]) + '''</textarea>
                         <hr class="main_hr">
-                        <span>''' + load_lang('approval_question') + '''</span><sup><a href="#rfn-1" id="fn-1">(1)</a></sup>
+                        <span>''' + load_lang('approval_question') + '''</span><sup><a href="#note_1_end" id="note_1">(1)</a></sup>
                         <hr class="main_hr">
                         <textarea rows="3" name="''' + i_list[12] + '''">''' + html.escape(d_list[12]) + '''</textarea>
                         <hr class="main_hr">
@@ -329,7 +332,7 @@ def setting_2(conn, num, db_set):
                         <button id="save" type="submit">''' + load_lang('save') + '''</button>
                         <hr class="main_hr">
                         <ul id="footnote_data">
-                            <li><a href="#fn-1" id="rfn-1">(1)</a> <span>''' + load_lang('approval_question_visible_only_when_approval_on') + '''</span></li>
+                            <li><a href="#note_1" id="note_1_end">(1)</a> <span>''' + load_lang('approval_question_visible_only_when_approval_on') + '''</span></li>
                         </ul>
                     </form>
                 ''',

+ 12 - 6
route/tool/func.py

@@ -333,7 +333,7 @@ def set_init():
         for i in [['smtp_server', 'smtp.gmail.com'], ['smtp_port', '587'], ['smtp_security', 'starttls']]:
             curs.execute(db_change("insert into other (name, data) values (?, ?)"), [i[0], i[1]])
 
-def pw_encode(data, data2 = '', type_d = ''):
+def pw_encode(data, type_d = ''):
     if type_d == '':
         curs.execute(db_change('select data from other where name = "encode"'))
         set_data = curs.fetchall()
@@ -360,11 +360,7 @@ def pw_check(data, data2, type_d = 'no', id_d = ''):
     else:
         set_data = db_data[0][0]
 
-    if pw_encode(data = data, type_d = set_data) == data2:
-        re_data = 1
-    else:
-        re_data = 0
-
+    re_data = 1 if pw_encode(data, set_data) == data2 else 0
     if db_data[0][0] != set_data and re_data == 1 and id_d != '':
         curs.execute(db_change("update user set pw = ?, encode = ? where id = ?"), [pw_encode(data), db_data[0][0], id_d])
 
@@ -429,6 +425,14 @@ def captcha_post(re_data, num = 1):
     else:
         pass
 
+def ua_plus(id, ip, ua, time):
+    curs.execute(db_change("select data from other where name = 'ua_get'"))
+    rep_data = curs.fetchall()
+    if rep_data and rep_data[0][0] != '':
+        pass
+    else:
+        curs.execute(db_change("insert into ua_d (name, ip, ua, today, sub) values (?, ?, ?, ?, '')"), [id, ip, ua, time])
+
 def load_lang(data, num = 2, safe = 0):
     global global_lang
 
@@ -643,6 +647,8 @@ def wiki_set(num = 1):
         curs.execute(db_change('select data from other where name = "upload"'))
         db_data = curs.fetchall()
         data_list = db_data[0][0] if db_data and db_data[0][0] != '' else '2'
+    else:
+        data_list = ''
 
     return data_list
 

+ 26 - 41
route/topic.py

@@ -2,8 +2,6 @@ from .tool.func import *
 
 def topic_2(conn, topic_num):
     curs = conn.cursor()
-
-    admin = admin_check(3)
     topic_num = str(topic_num)
 
     if flask.request.method == 'POST':
@@ -37,34 +35,30 @@ def topic_2(conn, topic_num):
 
         curs.execute(db_change("select id from topic where code = ? order by id + 0 desc limit 1"), [topic_num])
         old_num = curs.fetchall()
-        if old_num:
-            num = int(old_num[0][0]) + 1
-        else:
-            num = 1
-
-        num = str(num)
+        num = str((int(old_num[0][0]) + 1) if old_num else 1)
 
         match = re.search(r'^user:([^/]+)', name)
         if match:
+            match = match.group(1)
             y_check = 0
-            if ip_or_user(match.group(1)) == 1:
-                curs.execute(db_change("select ip from history where ip = ? limit 1"), [match.group(1)])
+            if ip_or_user(match) == 1:
+                curs.execute(db_change("select ip from history where ip = ? limit 1"), [match])
                 u_data = curs.fetchall()
                 if u_data:
                     y_check = 1
                 else:
-                    curs.execute(db_change("select ip from topic where ip = ? limit 1"), [match.group(1)])
+                    curs.execute(db_change("select ip from topic where ip = ? limit 1"), [match])
                     u_data = curs.fetchall()
                     if u_data:
                         y_check = 1
             else:
-                curs.execute(db_change("select id from user where id = ?"), [match.group(1)])
+                curs.execute(db_change("select id from user where id = ?"), [match])
                 u_data = curs.fetchall()
                 if u_data:
                     y_check = 1
 
             if y_check == 1:
-                add_alarm(match.group(1), ip + ' | <a href="/thread/' + topic_num + '#' + num + '">' + name + ' | ' + sub + ' | #' + num + '</a>')
+                add_alarm(match, ip + ' | <a href="/thread/' + topic_num + '#' + num + '">' + name + ' | ' + sub + ' | #' + num + '</a>')
 
         cate_re = re.compile(r'\[\[((?:분류|category):(?:(?:(?!\]\]).)*))\]\]', re.I)
         data = cate_re.sub('[br]', flask.request.form.get('content', 'Test').replace('\r', ''))
@@ -100,37 +94,28 @@ def topic_2(conn, topic_num):
 
         return redirect('/thread/' + topic_num + '#' + num)
     else:
-        data = ''
-
-        if ban == 1:
-            display = 'display: none;'
-        else:
-            display = ''
-
-        data += '''
-            <div id="top_topic"></div>
-            <div id="main_topic"></div>
-            <div id="plus_topic"></div>
-            <script>topic_top_load("''' + topic_num + '''");</script>
-            <a href="/thread/''' + topic_num + '/tool">(' + load_lang('topic_tool') + ''')</a>
-            <hr class=\"main_hr\">
-            <form style="''' + display + '''" method="post">
-                <textarea id="content" class="topic_content" placeholder="''' + load_lang('content') + '''" name="content"></textarea>
-                <hr class=\"main_hr\">
-                ''' + captcha_get() + (ip_warring() if display == '' else '') + '''
-                <input style="display: none;" name="topic" value="''' + name + '''">
-                <input style="display: none;" name="title" value="''' + sub + '''">
-                <button id="save" type="submit">''' + load_lang('send') + '''</button>
-                <button id="preview" type="button" onclick="load_preview(\'\')">''' + load_lang('preview') + '''</button>
-            </form>
-            <hr class=\"main_hr\">
-            <div id="see_preview"></div>
-        '''
-
+        display = 'display: none;' if ban == 1 else ''
         return easy_minify(flask.render_template(skin_check(),
             imp = [name, wiki_set(), custom(), other2(['(' + load_lang('discussion') + ')', 0])],
             data = '''
                 <h2 id="topic_top_title">''' + html.escape(sub) + '''</h2>
-                ''' + data,
+                <div id="top_topic"></div>
+                <div id="main_topic"></div>
+                <div id="plus_topic"></div>
+                <script>topic_top_load("''' + topic_num + '''");</script>
+                <a href="/thread/''' + topic_num + '/tool">(' + load_lang('topic_tool') + ''')</a>
+                <hr class="main_hr">
+                <form style="''' + display + '''" method="post">
+                    <textarea id="content" class="topic_content" placeholder="''' + load_lang('content') + '''" name="content"></textarea>
+                    <hr class="main_hr">
+                    ''' + captcha_get() + (ip_warring() if display == '' else '') + '''
+                    <input style="display: none;" name="topic" value="''' + name + '''">
+                    <input style="display: none;" name="title" value="''' + sub + '''">
+                    <button id="save" type="submit">''' + load_lang('send') + '''</button>
+                    <button id="preview" type="button" onclick="load_preview(\'\')">''' + load_lang('preview') + '''</button>
+                </form>
+                <hr class="main_hr">
+                <div id="see_preview"></div>
+            ''',
             menu = [['topic/' + url_pas(name), load_lang('list')]]
         ))

+ 1 - 1
version.json

@@ -1,6 +1,6 @@
 {
     "beta" : {
-        "r_ver" : "v3.2.0-stable-13 (beta-44) (dev-2020-10-27-02)",
+        "r_ver" : "v3.2.0-stable-13 (beta-45) (dev-2020-11-02-01)",
         "c_ver" : "3203400",
         "s_ver" : "10"
     }