Bläddra i källkod

add private wiki func

2du 4 år sedan
förälder
incheckning
33e196d60e

+ 6 - 0
emergency_tool.py

@@ -38,6 +38,7 @@ print('14. Delete Main <HEAD>')
 print('15. Give owner')
 print('16. Delete 2FA password')
 print('17. Change markup')
+print('18. Change wiki access password')
 
 print('----')
 what_i_do = input('Select : ')
@@ -215,6 +216,11 @@ elif what_i_do == '17':
     markup = input('Markup name : ')
 
     curs.execute(db_change("update other set data = ? where name = 'markup'"), [markup])
+elif what_i_do == '18':
+    print('----')
+    wiki_access_password = input('Password : ')
+
+    curs.execute(db_change("update other set data = ? where name = 'wiki_access_password'"), [wiki_access_password])
 else:
     raise ValueError(what_i_do)
 

+ 1 - 0
lang/en-US.json

@@ -467,6 +467,7 @@
             "error_edit_send_request" : "Entering a reason is required.",
             "error_title_length_too_long" : "Documents title or Discussion topic length is too long. Maximum number of characters : ",
             "error_password_length_too_short" : "Password length is too short. Minimum number of characters : ",
+            "error_password_require_for_wiki_access" : "A password is required to access the wiki.",
         "_comment_3.2_" : "Warning",
             "http_warning" : "Warning: If you are not on HTTPS connection, your information can be leaked. The users themselves have responsibility to any problems that happen because of this.",
             "user_head_warning" : "User data will be deleted if you close the browser or when you sign in.",

+ 2 - 1
lang/ko-KR.json

@@ -449,5 +449,6 @@
     "password_min_length": "비밀번호 최소 길이",
     "error_password_length_too_short": "비밀번호 길이가 너무 짧습니다. 최소 글자 수 : ",
     "phrase_user_page_admin": "관리자인 사용자 문서 문구",
-    "phrase_user_page_owner": "소유자인 사용자 문서 문구"
+    "phrase_user_page_owner": "소유자인 사용자 문서 문구",
+    "error_password_require_for_wiki_access": "위키에 접속하려면 비밀번호가 필요합니다."
 }

+ 13 - 2
route/main_func_setting_main.py

@@ -31,7 +31,9 @@ def main_func_setting_main(db_set):
             27 : ['http_select', 'http'],
             28 : ['title_max_length', ''],
             29 : ['title_topic_max_length', ''],
-            30 : ['password_min_length', '']
+            30 : ['password_min_length', ''],
+            31 : ['wiki_access_password_need', ''],
+            32 : ['wiki_access_password', '']
         }
 
         if flask.request.method == 'POST':
@@ -74,7 +76,7 @@ def main_func_setting_main(db_set):
                 else:
                     tls_select += '<option value="' + tls_select_one + '">' + tls_select_one + '</option>'
 
-            check_box_div = ['', '', '', '', '', '', '', '']
+            check_box_div = ['', '', '', '', '', '', '', '', '']
             for i in range(0, len(check_box_div)):
                 if i == 0:
                     acl_num = 7
@@ -90,6 +92,8 @@ def main_func_setting_main(db_set):
                     acl_num = 25
                 elif i == 7:
                     acl_num = 26
+                elif i == 8:
+                    acl_num = 31
 
                 if d_list[acl_num]:
                     check_box_div[i] = 'checked="checked"'
@@ -150,6 +154,13 @@ def main_func_setting_main(db_set):
                         <span>''' + load_lang('encryption_method') + '''</span>
                         <hr class="main_hr">
                         <select name="encode">''' + encode_select + '''</select>
+                        <hr class="main_hr">
+                        
+                        <input type="checkbox" name="wiki_access_password_need" ''' + check_box_div[8] + '''> ''' + load_lang('set_wiki_access_password_need') + ''' (''' + load_lang('restart_required') + ''') (''' + load_lang('beta') + ''')
+                        <hr class="main_hr">
+                        <span>''' + load_lang('set_wiki_access_password') + ''' (''' + load_lang('restart_required') + ''') (''' + load_lang('beta') + ''')</span>
+                        <hr class="main_hr">
+                        <input type="password" name="wiki_access_password" value="''' + html.escape(d_list[32]) + '''">
 
                         <h3>1.1. ''' + load_lang('communication_set') + '''</h3>
                         <input type="checkbox" name="enable_comment" ''' + check_box_div[5] + '''> ''' + load_lang('enable_comment_function') + ''' (''' + load_lang('not_working') + ''')

+ 24 - 2
route/tool/func.py

@@ -653,6 +653,8 @@ def update(ver_num, set_data):
     print('Update completed')
 
 def set_init_always(ver_num):
+    global global_wiki_set
+    
     curs = conn.cursor()
 
     curs.execute(db_change('delete from other where name = "ver"'))
@@ -675,6 +677,14 @@ def set_init_always(ver_num):
     curs.execute(db_change('select data from other where name = "count_all_title"'))
     if not curs.fetchall():
         curs.execute(db_change('insert into other (name, data) values ("count_all_title", "0")'))
+        
+    curs.execute(db_change('select data from other where name = "wiki_access_password_need"'))
+    db_data = curs.fetchall()
+    if db_data and db_data[0][0] != '':
+        curs.execute(db_change('select data from other where name = "wiki_access_password"'))
+        db_data = curs.fetchall()
+        if db_data:
+            global_wiki_set['wiki_access_password'] = db_data[0][0]
     
     conn.commit()
     
@@ -924,8 +934,20 @@ def pw_check(data, data2, type_d = 'no', id_d = ''):
 # Func-skin
 def easy_minify(data, tool = None):
     # without_DB
-
-    return data
+    if 'wiki_access_password' in global_wiki_set:
+        access_password = global_wiki_set['wiki_access_password']
+        input_password = flask.request.cookies.get('opennamu_wiki_access', ' ')
+        if url_pas(access_password) == input_password:
+            return data
+            
+        return '''
+            <script src="/views/main_css/js/route/wiki_access_password.js"></script>
+            <h2>''' + load_lang('error_password_require_for_wiki_access') + '''</h2>
+            <input type="password" id="wiki_access">
+            <input type="submit" onclick="opennamu_do_wiki_access();">
+        '''
+    else:
+        return data
 
 def load_lang(data, safe = 0):
     curs = conn.cursor()

+ 9 - 0
views/main_css/js/route/wiki_access_password.js

@@ -0,0 +1,9 @@
+"use strict";
+
+function opennamu_do_wiki_access() {
+    let password = document.getElementById('wiki_access').value;
+    
+    document.cookie = 'opennamu_wiki_access=' + encodeURIComponent(password) + '; path=/;';
+    
+    history.go(0);
+}