2du 3 år sedan
förälder
incheckning
d0e8413e3c

+ 220 - 220
app.py

@@ -35,229 +35,229 @@ data_db_set = class_check_json()
 
 db_data_get(data_db_set['type'])
 do_db_set(data_db_set)
-load_db = get_db_connect_old(data_db_set)
-
-conn = load_db.db_load()
-curs = conn.cursor()
-
-setup_tool = ''
-try:
-    curs.execute(db_change('select data from other where name = "ver"'))
-except:
-    setup_tool = 'init'
-
-if setup_tool != 'init':
-    ver_set_data = curs.fetchall()
-    if ver_set_data:
-        if int(version_list['beta']['c_ver']) > int(ver_set_data[0][0]):
-            setup_tool = 'update'
-        else:
-            setup_tool = 'normal'
-    else:
-        setup_tool = 'init'
-        
-if data_db_set['type'] == 'mysql':
+
+with get_db_connect() as conn:
+    curs = conn.cursor()
+
+    setup_tool = ''
     try:
-        curs.execute(db_change(
-            'create database ' + data_db_set['name'] + ' ' + \
-            'default character set utf8mb4'
-        ))
+        curs.execute(db_change('select data from other where name = "ver"'))
     except:
+        setup_tool = 'init'
+
+    if setup_tool != 'init':
+        ver_set_data = curs.fetchall()
+        if ver_set_data:
+            if int(version_list['beta']['c_ver']) > int(ver_set_data[0][0]):
+                setup_tool = 'update'
+            else:
+                setup_tool = 'normal'
+        else:
+            setup_tool = 'init'
+
+    if data_db_set['type'] == 'mysql':
         try:
             curs.execute(db_change(
-                'alter database ' + data_db_set['name'] + ' ' + \
-                'character set utf8mb4'
+                'create database ' + data_db_set['name'] + ' ' + \
+                'default character set utf8mb4'
             ))
         except:
-            pass
-
-if setup_tool != 'normal':
-    create_data = get_db_table_list()
-    for create_table in create_data:
-        for create in ['test'] + create_data[create_table]:
-            db_pass = 0
-            
             try:
-                curs.execute(db_change('select ' + create + ' from ' + create_table + ' limit 1'))
-                
-                db_pass = 1
+                curs.execute(db_change(
+                    'alter database ' + data_db_set['name'] + ' ' + \
+                    'character set utf8mb4'
+                ))
             except:
                 pass
-            
-            if db_pass == 0:
-                try:
-                    curs.execute(db_change('create table ' + create_table + '(test longtext default (""))'))
-                    
-                    db_pass = 1
-                except:
-                    pass
-            
-            if db_pass == 0:
-                try:
-                    curs.execute(db_change('create table ' + create_table + '(test longtext default "")'))
-                    
-                    db_pass = 1
-                except:
-                    pass
-                
-            if db_pass == 0:
-                try:
-                    curs.execute(db_change('create table ' + create_table + '(test longtext)'))
-                    
-                    db_pass = 1
-                except:
-                    pass
-                    
-            if db_pass == 0:
-                try:
-                    curs.execute(db_change("alter table " + create_table + " add column " + create + " longtext default ('')"))
-                    
-                    db_pass = 1
-                except:
-                    pass
-                
-            if db_pass == 0:
-                try:
-                    curs.execute(db_change("alter table " + create_table + " add column " + create + " longtext default ''"))
-                    
-                    db_pass = 1
-                except:
-                    pass
-                
-            if db_pass == 0:
+
+    if setup_tool != 'normal':
+        create_data = get_db_table_list()
+        for create_table in create_data:
+            for create in ['test'] + create_data[create_table]:
+                db_pass = 0
+
                 try:
-                    curs.execute(db_change("alter table " + create_table + " add column " + create + " longtext"))
-                    
+                    curs.execute(db_change('select ' + create + ' from ' + create_table + ' limit 1'))
+
                     db_pass = 1
                 except:
                     pass
-                
-            if db_pass == 0:
-                raise
-                    
-    if setup_tool == 'update':
-        update(int(ver_set_data[0][0]), set_data)
-    else:
-        set_init()
-
-set_init_always(version_list['beta']['c_ver'])
-
-# Init-Route
-class EverythingConverter(werkzeug.routing.PathConverter):
-    regex = r'.*?'
-
-class RegexConverter(werkzeug.routing.BaseConverter):
-    def __init__(self, url_map, *items):
-        super(RegexConverter, self).__init__(url_map)
-        self.regex = items[0]
-
-app = flask.Flask(
-    __name__, 
-    template_folder = './'
-)
-
-app.config['JSON_AS_ASCII'] = False
-app.config['JSONIFY_PRETTYPRINT_REGULAR'] = True
-
-log = logging.getLogger('waitress')
-log.setLevel(logging.ERROR)
-
-app.jinja_env.filters['md5_replace'] = md5_replace
-app.jinja_env.filters['load_lang'] = load_lang
-app.jinja_env.filters['cut_100'] = cut_100
-
-app.url_map.converters['everything'] = EverythingConverter
-app.url_map.converters['regex'] = RegexConverter
-
-curs.execute(db_change('select data from other where name = "key"'))
-sql_data = curs.fetchall()
-app.secret_key = sql_data[0][0]
-
-print('----')
-
-# Init-DB_Data
-server_set = {}
-server_set_var = get_init_set_list()
-server_set_env = {
-    'host' : os.getenv('NAMU_HOST'),
-    'port' : os.getenv('NAMU_PORT'),
-    'language' : os.getenv('NAMU_LANG'),
-    'markup' : os.getenv('NAMU_MARKUP'),
-    'encode' : os.getenv('NAMU_ENCRYPT')
-}
-for i in server_set_var:
-    curs.execute(db_change('select data from other where name = ?'), [i])
-    server_set_val = curs.fetchall()
-    if server_set_val:
-        server_set_val = server_set_val[0][0]
-    elif server_set_env[i] != None:
-        server_set_val = server_set_env[i]
-    else:
-        if 'list' in server_set_var[i]:
-            print(server_set_var[i]['display'] + ' (' + server_set_var[i]['default'] + ') [' + ', '.join(server_set_var[i]['list']) + ']' + ' : ', end = '')
-        else:
-            print(server_set_var[i]['display'] + ' (' + server_set_var[i]['default'] + ') : ', end = '')
 
-        server_set_val = input()
-        if server_set_val == '':
-            server_set_val = server_set_var[i]['default']
-        elif server_set_var[i]['require'] == 'select':
-            if not server_set_val in server_set_var[i]['list']:
-                server_set_val = server_set_var[i]['default']
+                if db_pass == 0:
+                    try:
+                        curs.execute(db_change('create table ' + create_table + '(test longtext default (""))'))
 
-        curs.execute(db_change('insert into other (name, data) values (?, ?)'), [i, server_set_val])
+                        db_pass = 1
+                    except:
+                        pass
 
-    print(server_set_var[i]['display'] + ' : ' + server_set_val)
+                if db_pass == 0:
+                    try:
+                        curs.execute(db_change('create table ' + create_table + '(test longtext default "")'))
 
-    server_set[i] = server_set_val
+                        db_pass = 1
+                    except:
+                        pass
 
-print('----')
+                if db_pass == 0:
+                    try:
+                        curs.execute(db_change('create table ' + create_table + '(test longtext)'))
 
-# Init-DB_care
-if data_db_set['type'] == 'sqlite':
-    def back_up(back_time, back_up_where):
-        print('----')
+                        db_pass = 1
+                    except:
+                        pass
 
-        try:
-            shutil.copyfile(
-                data_db_set['name'] + '.db', 
-                back_up_where
-            )
+                if db_pass == 0:
+                    try:
+                        curs.execute(db_change("alter table " + create_table + " add column " + create + " longtext default ('')"))
 
-            print('Back up : OK')
-        except:
-            print('Back up : Error')
-
-        threading.Timer(
-            60 * 60 * back_time, 
-            back_up,
-            [back_time, back_up_where]
-        ).start()
-
-    curs.execute(db_change('select data from other where name = "back_up"'))
-    back_time = curs.fetchall()
-    back_time = int(number_check(back_time[0][0])) if back_time and back_time != '' else 0
-    if back_time != 0:
-        curs.execute(db_change('select data from other where name = "backup_where"'))
-        back_up_where = curs.fetchall()
-        if back_up_where and back_up_where[0][0] != '':
-            back_up_where = back_up_where[0][0]
+                        db_pass = 1
+                    except:
+                        pass
+
+                if db_pass == 0:
+                    try:
+                        curs.execute(db_change("alter table " + create_table + " add column " + create + " longtext default ''"))
+
+                        db_pass = 1
+                    except:
+                        pass
+
+                if db_pass == 0:
+                    try:
+                        curs.execute(db_change("alter table " + create_table + " add column " + create + " longtext"))
+
+                        db_pass = 1
+                    except:
+                        pass
+
+                if db_pass == 0:
+                    raise
+
+        if setup_tool == 'update':
+            update(int(ver_set_data[0][0]), set_data)
         else:
-            back_up_where = 'back_' + data_db_set['name'] + '.db'
+            set_init()
+
+    set_init_always(version_list['beta']['c_ver'])
+
+    # Init-Route
+    class EverythingConverter(werkzeug.routing.PathConverter):
+        regex = r'.*?'
+
+    class RegexConverter(werkzeug.routing.BaseConverter):
+        def __init__(self, url_map, *items):
+            super(RegexConverter, self).__init__(url_map)
+            self.regex = items[0]
+
+    app = flask.Flask(
+        __name__, 
+        template_folder = './'
+    )
+
+    app.config['JSON_AS_ASCII'] = False
+    app.config['JSONIFY_PRETTYPRINT_REGULAR'] = True
+
+    log = logging.getLogger('waitress')
+    log.setLevel(logging.ERROR)
+
+    app.jinja_env.filters['md5_replace'] = md5_replace
+    app.jinja_env.filters['load_lang'] = load_lang
+    app.jinja_env.filters['cut_100'] = cut_100
+
+    app.url_map.converters['everything'] = EverythingConverter
+    app.url_map.converters['regex'] = RegexConverter
+
+    curs.execute(db_change('select data from other where name = "key"'))
+    sql_data = curs.fetchall()
+    app.secret_key = sql_data[0][0]
+
+    print('----')
+
+    # Init-DB_Data
+    server_set = {}
+    server_set_var = get_init_set_list()
+    server_set_env = {
+        'host' : os.getenv('NAMU_HOST'),
+        'port' : os.getenv('NAMU_PORT'),
+        'language' : os.getenv('NAMU_LANG'),
+        'markup' : os.getenv('NAMU_MARKUP'),
+        'encode' : os.getenv('NAMU_ENCRYPT')
+    }
+    for i in server_set_var:
+        curs.execute(db_change('select data from other where name = ?'), [i])
+        server_set_val = curs.fetchall()
+        if server_set_val:
+            server_set_val = server_set_val[0][0]
+        elif server_set_env[i] != None:
+            server_set_val = server_set_env[i]
+        else:
+            if 'list' in server_set_var[i]:
+                print(server_set_var[i]['display'] + ' (' + server_set_var[i]['default'] + ') [' + ', '.join(server_set_var[i]['list']) + ']' + ' : ', end = '')
+            else:
+                print(server_set_var[i]['display'] + ' (' + server_set_var[i]['default'] + ') : ', end = '')
+
+            server_set_val = input()
+            if server_set_val == '':
+                server_set_val = server_set_var[i]['default']
+            elif server_set_var[i]['require'] == 'select':
+                if not server_set_val in server_set_var[i]['list']:
+                    server_set_val = server_set_var[i]['default']
+
+            curs.execute(db_change('insert into other (name, data) values (?, ?)'), [i, server_set_val])
 
-        print('Back up state : ' + str(back_time) + ' hours')
+        print(server_set_var[i]['display'] + ' : ' + server_set_val)
 
-        back_up(back_time, back_up_where)
-    else:
-        print('Back up state : Turn off')
+        server_set[i] = server_set_val
 
-print('Now running... http://localhost:' + server_set['port'])
-conn.commit()
+    print('----')
+
+    # Init-DB_care
+    if data_db_set['type'] == 'sqlite':
+        def back_up(back_time, back_up_where):
+            print('----')
+
+            try:
+                shutil.copyfile(
+                    data_db_set['name'] + '.db', 
+                    back_up_where
+                )
+
+                print('Back up : OK')
+            except:
+                print('Back up : Error')
+
+            threading.Timer(
+                60 * 60 * back_time, 
+                back_up,
+                [back_time, back_up_where]
+            ).start()
+
+        curs.execute(db_change('select data from other where name = "back_up"'))
+        back_time = curs.fetchall()
+        back_time = int(number_check(back_time[0][0])) if back_time and back_time != '' else 0
+        if back_time != 0:
+            curs.execute(db_change('select data from other where name = "backup_where"'))
+            back_up_where = curs.fetchall()
+            if back_up_where and back_up_where[0][0] != '':
+                back_up_where = back_up_where[0][0]
+            else:
+                back_up_where = 'back_' + data_db_set['name'] + '.db'
+
+            print('Back up state : ' + str(back_time) + ' hours')
+
+            back_up(back_time, back_up_where)
+        else:
+            print('Back up state : Turn off')
+
+    print('Now running... http://localhost:' + server_set['port'])
+    
+    conn.commit()
 
 # Init-custom
 if os.path.exists('custom.py'):
     from custom import custom_run
-    custom_run(load_db.db_get(), app)
+    custom_run('error', app)
     
 # Func
 # Func-inter_wiki
@@ -307,70 +307,70 @@ app.route('/old_page')(list_old_page)
 # /list/document/acl
 @app.route('/acl_list')
 def list_acl():
-    return list_acl_2(load_db.db_get())
+    return list_acl_2()
 
 # /list/document/acl/add
 @app.route('/acl/<everything:name>', methods = ['POST', 'GET'])
 def give_acl(name = None):
-    return give_acl_2(load_db.db_get(), name)
+    return give_acl_2(name)
 
 # /list/document/need
 @app.route('/please')
 def list_please():
-    return list_please_2(load_db.db_get())
+    return list_please_2()
 
 # /list/document/all
 @app.route('/title_index')
 def list_title_index():
-    return list_title_index_2(load_db.db_get())
+    return list_title_index_2()
 
 # /list/document/long
 @app.route('/long_page')
 def list_long_page():
-    return list_long_page_2(load_db.db_get(), 'long_page')
+    return list_long_page_2('long_page')
 
 # /list/document/short
 @app.route('/short_page')
 def list_short_page():
-    return list_long_page_2(load_db.db_get(), 'short_page')
+    return list_long_page_2('short_page')
 
 # /list/file
 @app.route('/image_file_list')
 def list_image_file():
-    return list_image_file_2(load_db.db_get())
+    return list_image_file_2()
 
 # /list/admin
 # /list/admin/list
 @app.route('/admin_list')
 def list_admin():
-    return list_admin_2(load_db.db_get())
+    return list_admin_2()
 
 # /list/admin/auth_use
 @app.route('/admin_log', methods = ['POST', 'GET'])
 def list_admin_use():
-    return list_admin_use_2(load_db.db_get())
+    return list_admin_use_2()
 
 # /list/user
 @app.route('/user_log')
 def list_user():
-    return list_user_2(load_db.db_get())
+    return list_user_2()
 
 # /list/user/check
 @app.route('/check/<name>')
 def give_user_check(name = None):
-    return give_user_check_2(load_db.db_get(), name)
+    return give_user_check_2(name)
     
 # /list/user/check/delete
 @app.route('/check_delete', methods = ['POST', 'GET'])
 def give_user_check_delete():
-    return give_user_check_delete_2(load_db.db_get())
+    return give_user_check_delete_2()
 
 # Func-auth
 # /auth/give
 # /auth/give/<name>
 @app.route('/admin/<name>', methods = ['POST', 'GET'])
 def give_admin(name = None):
-    return give_admin_2(load_db.db_get(), name)
+    return give_admin_2(name)
 
 # /auth/give
 # /auth/give/<name>
@@ -382,21 +382,21 @@ app.route('/auth/give/ban_multiple', methods = ['POST', 'GET'], defaults = { 'ba
 # /auth/list
 @app.route('/admin_group')
 def list_admin_group():
-    return list_admin_group_2(load_db.db_get())
+    return list_admin_group_2()
 
 # /auth/list/add/<name>
 @app.route('/admin_plus/<name>', methods = ['POST', 'GET'])
 def give_admin_groups(name = None):
-    return give_admin_groups_2(load_db.db_get(), name)
+    return give_admin_groups_2(name)
 
 # /auth/list/delete/<name>
 @app.route('/delete_admin_group/<name>', methods = ['POST', 'GET'])
 def give_delete_admin_group(name = None):
-    return give_delete_admin_group_2(load_db.db_get(), name)
+    return give_delete_admin_group_2(name)
 
 @app.route('/app_submit', methods = ['POST', 'GET'])
 def recent_app_submit():
-    return recent_app_submit_2(load_db.db_get())
+    return recent_app_submit_2()
 
 # /auth/history
 # ongoing 반영 필요
@@ -404,7 +404,7 @@ def recent_app_submit():
 @app.route('/block_log/<regex("user"):tool>/<name>')
 @app.route('/block_log/<regex("admin"):tool>/<name>')
 def recent_block(name = 'Test', tool = 'all'):
-    return recent_block_2(load_db.db_get(), name, tool)
+    return recent_block_2(name, tool)
 
 # Func-history
 app.route('/recent_change')(recent_change)
@@ -513,13 +513,13 @@ app.route('/skin_set')(user_setting_skin_set)
 # 개편 보류중 S
 @app.route('/change/email', methods = ['POST', 'GET'])
 def user_setting_email():
-    return user_setting_email_2(load_db.db_get())
+    return user_setting_email_2()
 
 app.route('/change/email/delete')(user_setting_email_delete)
 
 @app.route('/change/email/check', methods = ['POST', 'GET'])
 def user_setting_email_check():
-    return user_setting_email_check_2(load_db.db_get())
+    return user_setting_email_check_2()
 # 개편 보류중 E
 
 # Func-login
@@ -531,27 +531,27 @@ def user_setting_email_check():
 
 @app.route('/login', methods = ['POST', 'GET'])
 def login_login():
-    return login_login_2(load_db.db_get())
+    return login_login_2()
 
 @app.route('/login/2fa', methods = ['POST', 'GET'])
 def login_login_2fa():
-    return login_login_2fa_2(load_db.db_get())
+    return login_login_2fa_2()
 
 @app.route('/register', methods = ['POST', 'GET'])
 def login_register():
-    return login_register_2(load_db.db_get())
+    return login_register_2()
 
 @app.route('/register/email', methods = ['POST', 'GET'])
 def login_register_email():
-    return login_register_email_2(load_db.db_get())
+    return login_register_email_2()
 
 @app.route('/register/email/check', methods = ['POST', 'GET'])
 def login_register_email_check():
-    return login_register_email_check_2(load_db.db_get())
+    return login_register_email_check_2()
 
 @app.route('/register/submit', methods = ['POST', 'GET'])
 def login_register_submit():
-    return login_register_submit_2(load_db.db_get())
+    return login_register_submit_2()
 
 app.route('/login/find')(login_find)
 app.route('/login/find/key', methods = ['POST', 'GET'])(login_find_key)

+ 116 - 115
route/give_acl.py

@@ -1,132 +1,133 @@
 from .tool.func import *
 
-def give_acl_2(conn, name):
-    curs = conn.cursor()
+def give_acl_2(name):
+    with get_db_connect() as conn:
+        curs = conn.cursor()
 
-    check_ok = ''
-    ip = ip_check()
+        check_ok = ''
+        ip = ip_check()
 
-    if flask.request.method == 'POST':
-        check_data = 'acl (' + name + ')'
-    else:
-        check_data = None
+        if flask.request.method == 'POST':
+            check_data = 'acl (' + name + ')'
+        else:
+            check_data = None
 
-    user_data = re.search(r'^user:(.+)$', name)
-    if user_data:
-        if check_data and ip_or_user(ip) != 0:
-            return redirect('/login')
+        user_data = re.search(r'^user:(.+)$', name)
+        if user_data:
+            if check_data and ip_or_user(ip) != 0:
+                return redirect('/login')
 
-        if user_data.group(1) != ip_check():
+            if user_data.group(1) != ip_check():
+                if admin_check(5) != 1:
+                    if check_data:
+                        return re_error('/error/3')
+                    else:
+                        check_ok = 'disabled'
+        else:
             if admin_check(5) != 1:
                 if check_data:
                     return re_error('/error/3')
                 else:
                     check_ok = 'disabled'
-    else:
-        if admin_check(5) != 1:
-            if check_data:
-                return re_error('/error/3')
+
+        if flask.request.method == 'POST':
+            acl_data = [['decu', flask.request.form.get('decu', '')]]
+            acl_data += [['dis', flask.request.form.get('dis', '')]]
+            acl_data += [['view', flask.request.form.get('view', '')]]
+            acl_data += [['why', flask.request.form.get('why', '')]]
+
+            curs.execute(db_change("select title from acl where title = ?"), [name])
+            if curs.fetchall():
+                for i in acl_data:
+                    curs.execute(db_change("update acl set data = ? where title = ? and type = ?"), [i[1], name, i[0]])
             else:
-                check_ok = 'disabled'
-
-    if flask.request.method == 'POST':
-        acl_data = [['decu', flask.request.form.get('decu', '')]]
-        acl_data += [['dis', flask.request.form.get('dis', '')]]
-        acl_data += [['view', flask.request.form.get('view', '')]]
-        acl_data += [['why', flask.request.form.get('why', '')]]
-        
-        curs.execute(db_change("select title from acl where title = ?"), [name])
-        if curs.fetchall():
-            for i in acl_data:
-                curs.execute(db_change("update acl set data = ? where title = ? and type = ?"), [i[1], name, i[0]])
+                for i in acl_data:
+                    curs.execute(db_change("insert into acl (title, data, type) values (?, ?, ?)"), [name, i[1], i[0]])
+
+            all_d = ''
+            for i in ['decu', 'dis', 'view']:
+                if flask.request.form.get(i, '') == '':
+                    all_d += 'normal'
+                    if i != 'view':
+                        all_d += ' | '
+                else:
+                    all_d += flask.request.form.get(i, '')
+                    if i != 'view':
+                        all_d += ' | '
+
+            admin_check(5, check_data + ' (' + all_d + ')')
+
+            conn.commit()
+
+            return redirect('/acl/' + url_pas(name))
         else:
-            for i in acl_data:
-                curs.execute(db_change("insert into acl (title, data, type) values (?, ?, ?)"), [name, i[1], i[0]])
-
-        all_d = ''
-        for i in ['decu', 'dis', 'view']:
-            if flask.request.form.get(i, '') == '':
-                all_d += 'normal'
-                if i != 'view':
-                    all_d += ' | '
+            data = ''
+            acl_list = get_acl_list('user') if re.search(r'^user:', name) else get_acl_list()
+            if not re.search(r'^user:', name):
+                acl_get_list = [
+                    [load_lang('document_acl'), 'decu'], 
+                    [load_lang('discussion_acl'), 'dis'], 
+                    [load_lang('view_acl'), 'view']
+                ]
             else:
-                all_d += flask.request.form.get(i, '')
-                if i != 'view':
-                    all_d += ' | '
-
-        admin_check(5, check_data + ' (' + all_d + ')')
-
-        conn.commit()
-
-        return redirect('/acl/' + url_pas(name))
-    else:
-        data = ''
-        acl_list = get_acl_list('user') if re.search(r'^user:', name) else get_acl_list()
-        if not re.search(r'^user:', name):
-            acl_get_list = [
-                [load_lang('document_acl'), 'decu'], 
-                [load_lang('discussion_acl'), 'dis'], 
-                [load_lang('view_acl'), 'view']
-            ]
-        else:
-            acl_get_list = [
-                [load_lang('document_acl'), 'decu']
-            ]
-            
-        for i in acl_get_list:
+                acl_get_list = [
+                    [load_lang('document_acl'), 'decu']
+                ]
+
+            for i in acl_get_list:
+                data += '' + \
+                    '<h2>' + i[0] + '</h2>' + \
+                    '<hr class="main_hr">' + \
+                    '<select name="' + i[1] + '" ' + check_ok + '>' + \
+                ''
+
+                curs.execute(db_change("select data from acl where title = ? and type = ?"), [name, i[1]])
+                acl_data = curs.fetchall()
+                for data_list in acl_list:
+                    check = 'selected="selected"' if acl_data and acl_data[0][0] == data_list else ''
+                    data += '<option value="' + data_list + '" ' + check + '>' + (data_list if data_list != '' else 'normal') + '</option>'
+
+                data += '</select>'
+                data += '<hr class="main_hr">'
+
+            curs.execute(db_change("select data from acl where title = ? and type = ?"), [name, 'why'])
+            acl_data = curs.fetchall()
+            acl_why = html.escape(acl_data[0][0]) if acl_data else ''
             data += '' + \
-                '<h2>' + i[0] + '</h2>' + \
                 '<hr class="main_hr">' + \
-                '<select name="' + i[1] + '" ' + check_ok + '>' + \
+                '<input value="' + acl_why + '" placeholder="' + load_lang('why') + '" name="why" type="text" ' + check_ok + '>' + \
             ''
-    
-            curs.execute(db_change("select data from acl where title = ? and type = ?"), [name, i[1]])
-            acl_data = curs.fetchall()
-            for data_list in acl_list:
-                check = 'selected="selected"' if acl_data and acl_data[0][0] == data_list else ''
-                data += '<option value="' + data_list + '" ' + check + '>' + (data_list if data_list != '' else 'normal') + '</option>'
-    
-            data += '</select>'
-            data += '<hr class="main_hr">'
-
-        curs.execute(db_change("select data from acl where title = ? and type = ?"), [name, 'why'])
-        acl_data = curs.fetchall()
-        acl_why = html.escape(acl_data[0][0]) if acl_data else ''
-        data += '' + \
-            '<hr class="main_hr">' + \
-            '<input value="' + acl_why + '" placeholder="' + load_lang('why') + '" name="why" type="text" ' + check_ok + '>' + \
-        ''
-
-        data += '''
-            <h2 id="exp">''' + load_lang('explanation') + '''</h2>
-            <ul class="inside_ul">
-                <li>normal : ''' + load_lang('unset') + '''</li>
-                <li>admin : ''' + load_lang('admin_acl') + '''</li>
-                <li>user : ''' + load_lang('member_acl') + '''</li>
-                <li>50_edit : ''' + load_lang('50_edit_acl') + '''</li>
-                <li>all : ''' + load_lang('all_acl') + '''</li>
-                <li>email : ''' + load_lang('email_acl') + '''</li>
-                <li>owner : ''' + load_lang('owner_acl') + '''</li>
-                <li>ban : ''' + load_lang('ban_acl') + '''</li>
-                <li>before : ''' + load_lang('before_acl') + '''</li>
-                <li>30_day : ''' + load_lang('30_day_acl') + '''</li>
-                <li>ban_admin : ''' + load_lang('ban_admin_acl') + '''</li>
-                <li>not_all : ''' + load_lang('not_all_acl') + '''</li>
-            </ul>
-        '''
-
-        return easy_minify(flask.render_template(skin_check(),
-            imp = [name, wiki_set(), wiki_custom(), wiki_css(['(' + load_lang('acl') + ')', 0])],
-            data = '''
-                <form method="post">
-                    <a href="/setting/acl">(''' + load_lang('main_acl_setting') + ''')</a>
-                    ''' + data + '''
-                    <button type="submit" ''' + check_ok + '''>''' + load_lang('save') + '''</button>
-                </form>
-            ''',
-            menu = [
-                ['w/' + url_pas(name), load_lang('document')], 
-                ['manager', load_lang('admin')], 
-                ['admin_log?search=' + url_pas('acl (' + name + ')'), load_lang('acl_record')]
-            ]
-        ))
+
+            data += '''
+                <h2 id="exp">''' + load_lang('explanation') + '''</h2>
+                <ul class="inside_ul">
+                    <li>normal : ''' + load_lang('unset') + '''</li>
+                    <li>admin : ''' + load_lang('admin_acl') + '''</li>
+                    <li>user : ''' + load_lang('member_acl') + '''</li>
+                    <li>50_edit : ''' + load_lang('50_edit_acl') + '''</li>
+                    <li>all : ''' + load_lang('all_acl') + '''</li>
+                    <li>email : ''' + load_lang('email_acl') + '''</li>
+                    <li>owner : ''' + load_lang('owner_acl') + '''</li>
+                    <li>ban : ''' + load_lang('ban_acl') + '''</li>
+                    <li>before : ''' + load_lang('before_acl') + '''</li>
+                    <li>30_day : ''' + load_lang('30_day_acl') + '''</li>
+                    <li>ban_admin : ''' + load_lang('ban_admin_acl') + '''</li>
+                    <li>not_all : ''' + load_lang('not_all_acl') + '''</li>
+                </ul>
+            '''
+
+            return easy_minify(flask.render_template(skin_check(),
+                imp = [name, wiki_set(), wiki_custom(), wiki_css(['(' + load_lang('acl') + ')', 0])],
+                data = '''
+                    <form method="post">
+                        <a href="/setting/acl">(''' + load_lang('main_acl_setting') + ''')</a>
+                        ''' + data + '''
+                        <button type="submit" ''' + check_ok + '''>''' + load_lang('save') + '''</button>
+                    </form>
+                ''',
+                menu = [
+                    ['w/' + url_pas(name), load_lang('document')], 
+                    ['manager', load_lang('admin')], 
+                    ['admin_log?search=' + url_pas('acl (' + name + ')'), load_lang('acl_record')]
+                ]
+            ))

+ 56 - 55
route/give_admin.py

@@ -1,67 +1,68 @@
 from .tool.func import *
 
-def give_admin_2(conn, name):
-    curs = conn.cursor()
+def give_admin_2(name):
+    with get_db_connect() as conn:
+        curs = conn.cursor()
 
-    owner = admin_check()
+        owner = admin_check()
 
-    curs.execute(db_change("select data from user_set where id = ? and name = 'acl'"), [name])
-    user_acl = curs.fetchall()
-    if not user_acl:
-        return re_error('/error/2')
-    else:
-        user_acl = user_acl[0][0]
-    
-    if owner != 1:
-        curs.execute(db_change('select name from alist where name = ? and acl = "owner"'), [user_acl])
-        if curs.fetchall():
-            return re_error('/error/3')
+        curs.execute(db_change("select data from user_set where id = ? and name = 'acl'"), [name])
+        user_acl = curs.fetchall()
+        if not user_acl:
+            return re_error('/error/2')
+        else:
+            user_acl = user_acl[0][0]
 
-        if ip_check() == name:
-            return re_error('/error/3')
+        if owner != 1:
+            curs.execute(db_change('select name from alist where name = ? and acl = "owner"'), [user_acl])
+            if curs.fetchall():
+                return re_error('/error/3')
 
-    if flask.request.method == 'POST':
-        if admin_check(7, 'admin (' + name + ')') != 1:
-            return re_error('/error/3')
+            if ip_check() == name:
+                return re_error('/error/3')
 
-        if flask.request.form.get('select', 'X') == 'X':
-            select_data = 'user'
-        else:
-            select_data = flask.request.form.get('select', 'X')
-        
-        curs.execute(db_change('select name from alist where name = ? and acl = "owner"'), [select_data])
-        if owner != 1 and curs.fetchall():
-            return re_error('/error/3')
-            
-        curs.execute(db_change("update user_set set data = ? where id = ? and name = 'acl'"), [
-            select_data, 
-            name
-        ])
+        if flask.request.method == 'POST':
+            if admin_check(7, 'admin (' + name + ')') != 1:
+                return re_error('/error/3')
 
-        conn.commit()
+            if flask.request.form.get('select', 'X') == 'X':
+                select_data = 'user'
+            else:
+                select_data = flask.request.form.get('select', 'X')
 
-        return redirect('/admin/' + url_pas(name))
-    else:
-        if admin_check(7) != 1:
-            return re_error('/error/3')
+            curs.execute(db_change('select name from alist where name = ? and acl = "owner"'), [select_data])
+            if owner != 1 and curs.fetchall():
+                return re_error('/error/3')
 
-        div = '<option value="X">X</option>'
+            curs.execute(db_change("update user_set set data = ? where id = ? and name = 'acl'"), [
+                select_data, 
+                name
+            ])
 
-        curs.execute(db_change('select distinct name from alist order by name asc'))
-        for data in curs.fetchall():
-            if user_acl == data[0]:
-                div = '<option value="' + data[0] + '">' + data[0] + '</option>' + div
-            else:
-                div += '<option value="' + data[0] + '">' + data[0] + '</option>'
+            conn.commit()
+
+            return redirect('/admin/' + url_pas(name))
+        else:
+            if admin_check(7) != 1:
+                return re_error('/error/3')
+
+            div = '<option value="X">X</option>'
+
+            curs.execute(db_change('select distinct name from alist order by name asc'))
+            for data in curs.fetchall():
+                if user_acl == data[0]:
+                    div = '<option value="' + data[0] + '">' + data[0] + '</option>' + div
+                else:
+                    div += '<option value="' + data[0] + '">' + data[0] + '</option>'
 
-        return easy_minify(flask.render_template(skin_check(),
-            imp = [name, wiki_set(), wiki_custom(), wiki_css(['(' + load_lang('authorize') + ')', 0])],
-            data =  '''
-                    <form method="post">
-                        <select name="select">''' + div + '''</select>
-                        <hr class="main_hr">
-                        <button type="submit">''' + load_lang('save') + '''</button>
-                    </form>
-                    ''',
-            menu = [['manager', load_lang('return')]]
-        ))
+            return easy_minify(flask.render_template(skin_check(),
+                imp = [name, wiki_set(), wiki_custom(), wiki_css(['(' + load_lang('authorize') + ')', 0])],
+                data =  '''
+                        <form method="post">
+                            <select name="select">''' + div + '''</select>
+                            <hr class="main_hr">
+                            <button type="submit">''' + load_lang('save') + '''</button>
+                        </form>
+                        ''',
+                menu = [['manager', load_lang('return')]]
+            ))

+ 58 - 57
route/give_admin_groups.py

@@ -1,67 +1,68 @@
 from .tool.func import *
 
-def give_admin_groups_2(conn, name):
-    curs = conn.cursor()
+def give_admin_groups_2(name):
+    with get_db_connect() as conn:
+        curs = conn.cursor()
 
-    acl_name_list = ['ban', 'nothing', 'toron', 'check', 'acl', 'hidel', 'give', 'owner']
-    
-    if flask.request.method == 'POST':
-        if admin_check(None, 'admin_plus (' + name + ')') != 1:
-            return re_error('/error/3')
-        else:
-            if name in ['owner', 'ban']:
+        acl_name_list = ['ban', 'nothing', 'toron', 'check', 'acl', 'hidel', 'give', 'owner']
+
+        if flask.request.method == 'POST':
+            if admin_check(None, 'admin_plus (' + name + ')') != 1:
                 return re_error('/error/3')
+            else:
+                if name in ['owner', 'ban']:
+                    return re_error('/error/3')
 
-        curs.execute(db_change("delete from alist where name = ?"), [name])
-        for i in acl_name_list:
-            if flask.request.form.get(i, 0) != 0:
-                curs.execute(db_change("insert into alist (name, acl) values (?, ?)"), [name, i])
+            curs.execute(db_change("delete from alist where name = ?"), [name])
+            for i in acl_name_list:
+                if flask.request.form.get(i, 0) != 0:
+                    curs.execute(db_change("insert into alist (name, acl) values (?, ?)"), [name, i])
 
-        conn.commit()
+            conn.commit()
+
+            return redirect('/admin_plus/' + url_pas(name))
+        else:
+            data = ''
+            exist_list = ['', '', '', '', '', '', '', '']
+            state = 'disabled' if admin_check() != 1 else ''
+            state = 'disabled' if name in get_default_admin_group() else ''
 
-        return redirect('/admin_plus/' + url_pas(name))
-    else:
-        data = ''
-        exist_list = ['', '', '', '', '', '', '', '']
-        state = 'disabled' if admin_check() != 1 else ''
-        state = 'disabled' if name in get_default_admin_group() else ''
+            curs.execute(db_change('select acl from alist where name = ?'), [name])
+            acl_list = curs.fetchall()
+            for go in acl_list:
+                exist_list[acl_name_list.index(go[0])] = 'checked="checked"'
 
-        curs.execute(db_change('select acl from alist where name = ?'), [name])
-        acl_list = curs.fetchall()
-        for go in acl_list:
-            exist_list[acl_name_list.index(go[0])] = 'checked="checked"'
-            
-        for i in range(0, 8):
-            if i != 1:
-                data += '' + \
-                    '<input type="checkbox" ' + \
-                            state + ' ' + \
-                            'name="' + acl_name_list[i] + '" ' + \
-                            exist_list[i] + '> ' + acl_name_list[i] + \
-                    '<hr class="main_hr">' + \
-                ''
+            for i in range(0, 8):
+                if i != 1:
+                    data += '' + \
+                        '<input type="checkbox" ' + \
+                                state + ' ' + \
+                                'name="' + acl_name_list[i] + '" ' + \
+                                exist_list[i] + '> ' + acl_name_list[i] + \
+                        '<hr class="main_hr">' + \
+                    ''
 
-        data += ''
+            data += ''
 
-        return easy_minify(flask.render_template(skin_check(),
-            imp = [name, wiki_set(), wiki_custom(), wiki_css(['(' + load_lang('admin_group') + ')', 0])],
-            data = '''
-                <form method="post">
-                    ''' + data + '''
-                    <hr class="main_hr">
-                    <h2>''' + load_lang('explanation') + '''</h2>
-                    <ul class="inside_ul">
-                        <li>ban : ''' + load_lang('ban_authority') + '''</li>
-                        <li>toron : ''' + load_lang('discussion_authority') + '''</li>
-                        <li>check : ''' + load_lang('user_check_authority') + '''</li>
-                        <li>acl : ''' + load_lang('document_acl_authority') + '''</li>
-                        <li>hidel : ''' + load_lang('history_hide_authority') + '''</li>
-                        <li>give : ''' + load_lang('authorization_authority') + '''</li>
-                        <li>owner : ''' + load_lang('owner_authority') + '''</li>
-                    </ul>
-                    <hr class="main_hr">
-                    <button ''' + state +  ''' type="submit">''' + load_lang('save') + '''</button>
-                </form>
-            ''',
-            menu = [['admin_group', load_lang('return')]]
-        ))
+            return easy_minify(flask.render_template(skin_check(),
+                imp = [name, wiki_set(), wiki_custom(), wiki_css(['(' + load_lang('admin_group') + ')', 0])],
+                data = '''
+                    <form method="post">
+                        ''' + data + '''
+                        <hr class="main_hr">
+                        <h2>''' + load_lang('explanation') + '''</h2>
+                        <ul class="inside_ul">
+                            <li>ban : ''' + load_lang('ban_authority') + '''</li>
+                            <li>toron : ''' + load_lang('discussion_authority') + '''</li>
+                            <li>check : ''' + load_lang('user_check_authority') + '''</li>
+                            <li>acl : ''' + load_lang('document_acl_authority') + '''</li>
+                            <li>hidel : ''' + load_lang('history_hide_authority') + '''</li>
+                            <li>give : ''' + load_lang('authorization_authority') + '''</li>
+                            <li>owner : ''' + load_lang('owner_authority') + '''</li>
+                        </ul>
+                        <hr class="main_hr">
+                        <button ''' + state +  ''' type="submit">''' + load_lang('save') + '''</button>
+                    </form>
+                ''',
+                menu = [['admin_group', load_lang('return')]]
+            ))

+ 22 - 21
route/give_delete_admin_group.py

@@ -1,27 +1,28 @@
 from .tool.func import *
 
-def give_delete_admin_group_2(conn, name):
-    curs = conn.cursor()
+def give_delete_admin_group_2(name):
+    with get_db_connect() as conn:
+        curs = conn.cursor()
 
-    if admin_check() != 1:
-        return re_error('/error/3')
-    
-    if flask.request.method == 'POST':
-        admin_check(None, 'alist del ' + name)
+        if admin_check() != 1:
+            return re_error('/error/3')
 
-        curs.execute(db_change("delete from alist where name = ?"), [name])
-        curs.execute(db_change("update user_set set data = 'user' where name = 'acl' and data = ?"), [name])
+        if flask.request.method == 'POST':
+            admin_check(None, 'alist del ' + name)
 
-        conn.commit()
+            curs.execute(db_change("delete from alist where name = ?"), [name])
+            curs.execute(db_change("update user_set set data = 'user' where name = 'acl' and data = ?"), [name])
 
-        return redirect('/admin_group')
-    else:
-        return easy_minify(flask.render_template(skin_check(),
-            imp = [load_lang("delete_admin_group"), wiki_set(), wiki_custom(), wiki_css(['(' + name + ')', 0])],
-            data = '''
-                <form method=post>
-                    <button type=submit>''' + load_lang('start') + '''</button>
-                </form>
-            ''',
-            menu = [['admin_group', load_lang('return')]]
-        ))  
+            conn.commit()
+
+            return redirect('/admin_group')
+        else:
+            return easy_minify(flask.render_template(skin_check(),
+                imp = [load_lang("delete_admin_group"), wiki_set(), wiki_custom(), wiki_css(['(' + name + ')', 0])],
+                data = '''
+                    <form method=post>
+                        <button type=submit>''' + load_lang('start') + '''</button>
+                    </form>
+                ''',
+                menu = [['admin_group', load_lang('return')]]
+            ))

+ 163 - 162
route/give_user_check.py

@@ -1,178 +1,179 @@
 from .tool.func import *
 
-def give_user_check_2(conn, name):
-    curs = conn.cursor()
-
-    plus_id = flask.request.args.get('plus', None)
-
-    if admin_check('all', None, name) == 1 or (plus_id and admin_check('all', None, plus_id) == 1):
-        if admin_check() != 1:
-            return re_error('/error/4')
-
-    num = int(number_check(flask.request.args.get('num', '1')))
-    sql_num = (num * 50 - 50) if num * 50 > 0 else 0
-    
-    div = ''
-    check_type = flask.request.args.get('type', '')
-
-    if admin_check(4, (check_type + ' ' if check_type != '' else '') + 'check (' + name + ')') != 1:
-        return re_error('/error/3')
-
-    if check_type == '':
-        if ip_or_user(name) == 0:
-            curs.execute(db_change("select data from user_set where name = \"approval_question\" and id = ?"), [name])
-            approval_question = curs.fetchall()
-            if approval_question and approval_question[0][0]:
-                curs.execute(db_change("select data from user_set where name = \"approval_question_answer\" and id = ?"), [name])
-                approval_question_answer = curs.fetchall()
-                if approval_question_answer and approval_question_answer[0]:
-                    div += '''
-                        <table id="main_table_set">
-                            <tbody>
-                                <tr id="main_table_top_tr">
-                                    <td>Q</td>
-                                    <td>''' + approval_question[0][0] + '''</td>
-                                    <td>A</td>
-                                    <td>''' + approval_question_answer[0][0] + '''</td>
-                                </tr>
-                            </tbody>
-                        </table>
-                        <hr class="main_hr">
-                    '''
+def give_user_check_2(name):
+    with get_db_connect() as conn:
+        curs = conn.cursor()
 
-        if plus_id:
-            plus = "or " + ('ip' if ip_or_user(plus_id) == 1 else 'name') + " = ? "
-            set_list = [name, plus_id, sql_num]
-            
-            if num == 1:
-                curs.execute(db_change("" + \
-                    "select distinct ip from ua_d " + \
-                    "where " + ('ip' if ip_or_user(name) == 1 else 'name') + " = ? or " + ('ip' if ip_or_user(plus_id) == 1 else 'name') + " = ? "
-                ""), [name, plus_id])
-                all_ip_count = len(curs.fetchall())
-                
-                curs.execute(db_change("" + \
-                    "select distinct ip from ua_d " + \
-                    "where " + ('ip' if ip_or_user(name) == 1 else 'name') + " = ?" + \
-                ""), [name])
-                a_ip_count = len(curs.fetchall())
-                
-                curs.execute(db_change("" + \
-                    "select distinct ip from ua_d " + \
-                    "where " + ('ip' if ip_or_user(plus_id) == 1 else 'name') + " = ? "
-                ""), [plus_id])
-                b_ip_count = len(curs.fetchall())
-                
-                if a_ip_count + b_ip_count != all_ip_count:
-                    div += load_lang('same_ip_exist') + '<hr class="main_hr">'    
-        else:
-            plus = ''
-            set_list = [name, sql_num]
-
-        curs.execute(db_change("" + \
-            "select name, ip, ua, today from ua_d " + \
-            "where " + ('ip' if ip_or_user(name) == 1 else 'name') + " = ? " + \
-            plus + \
-            "order by today desc limit ?, 50" + \
-        ""), set_list)
-
-        record = curs.fetchall()
-        if record:
-            if not plus_id:
-                div = '' + \
-                    '<a href="/manager/14?plus=' + url_pas(name) + '">(' + load_lang('compare') + ')</a> ' + \
-                    '<a href="/check/' + url_pas(name) + '?type=simple">(' + load_lang('simple_check') + ')</a>' + \
-                    '<hr class="main_hr">' + \
-                '' + div
+        plus_id = flask.request.args.get('plus', None)
+
+        if admin_check('all', None, name) == 1 or (plus_id and admin_check('all', None, plus_id) == 1):
+            if admin_check() != 1:
+                return re_error('/error/4')
+
+        num = int(number_check(flask.request.args.get('num', '1')))
+        sql_num = (num * 50 - 50) if num * 50 > 0 else 0
+
+        div = ''
+        check_type = flask.request.args.get('type', '')
+
+        if admin_check(4, (check_type + ' ' if check_type != '' else '') + 'check (' + name + ')') != 1:
+            return re_error('/error/3')
+
+        if check_type == '':
+            if ip_or_user(name) == 0:
+                curs.execute(db_change("select data from user_set where name = \"approval_question\" and id = ?"), [name])
+                approval_question = curs.fetchall()
+                if approval_question and approval_question[0][0]:
+                    curs.execute(db_change("select data from user_set where name = \"approval_question_answer\" and id = ?"), [name])
+                    approval_question_answer = curs.fetchall()
+                    if approval_question_answer and approval_question_answer[0]:
+                        div += '''
+                            <table id="main_table_set">
+                                <tbody>
+                                    <tr id="main_table_top_tr">
+                                        <td>Q</td>
+                                        <td>''' + approval_question[0][0] + '''</td>
+                                        <td>A</td>
+                                        <td>''' + approval_question_answer[0][0] + '''</td>
+                                    </tr>
+                                </tbody>
+                            </table>
+                            <hr class="main_hr">
+                        '''
+
+            if plus_id:
+                plus = "or " + ('ip' if ip_or_user(plus_id) == 1 else 'name') + " = ? "
+                set_list = [name, plus_id, sql_num]
+
+                if num == 1:
+                    curs.execute(db_change("" + \
+                        "select distinct ip from ua_d " + \
+                        "where " + ('ip' if ip_or_user(name) == 1 else 'name') + " = ? or " + ('ip' if ip_or_user(plus_id) == 1 else 'name') + " = ? "
+                    ""), [name, plus_id])
+                    all_ip_count = len(curs.fetchall())
+
+                    curs.execute(db_change("" + \
+                        "select distinct ip from ua_d " + \
+                        "where " + ('ip' if ip_or_user(name) == 1 else 'name') + " = ?" + \
+                    ""), [name])
+                    a_ip_count = len(curs.fetchall())
+
+                    curs.execute(db_change("" + \
+                        "select distinct ip from ua_d " + \
+                        "where " + ('ip' if ip_or_user(plus_id) == 1 else 'name') + " = ? "
+                    ""), [plus_id])
+                    b_ip_count = len(curs.fetchall())
+
+                    if a_ip_count + b_ip_count != all_ip_count:
+                        div += load_lang('same_ip_exist') + '<hr class="main_hr">'    
             else:
-                div = '' + \
-                    '<a href="/check/' + url_pas(name) + '">(' + name + ')</a> ' + \
-                    '<a href="/check/' + url_pas(plus_id) + '">(' + plus_id + ')</a>' + \
-                    '<hr class="main_hr">' + \
-                '' + div
-
-            div += '''
-                <table id="main_table_set">
-                    <tbody>
-                        <tr id="main_table_top_tr">
-                            <td id="main_table_width">''' + load_lang('name') + '''</td>
-                            <td id="main_table_width">''' + load_lang('ip') + '''</td>
-                            <td id="main_table_width">''' + load_lang('time') + '''</td>
-                        </tr>
-            '''
-
-            set_n = 0
-            for data in record:
-                if data[2]:
-                    if len(data[2]) > 300:
-                        ua = '' + \
-                            '<a href="javascript:void();" onclick="document.getElementById(\'check_' + str(set_n) + '\').style.display=\'block\';">(300+)</a>' + \
-                            '<div id="check_' + str(set_n) + '" style="display:none;">' + html.escape(data[2]) + '</div>' + \
-                        ''
-                        set_n += 1
-                    else:
-                        ua = html.escape(data[2])
+                plus = ''
+                set_list = [name, sql_num]
+
+            curs.execute(db_change("" + \
+                "select name, ip, ua, today from ua_d " + \
+                "where " + ('ip' if ip_or_user(name) == 1 else 'name') + " = ? " + \
+                plus + \
+                "order by today desc limit ?, 50" + \
+            ""), set_list)
+
+            record = curs.fetchall()
+            if record:
+                if not plus_id:
+                    div = '' + \
+                        '<a href="/manager/14?plus=' + url_pas(name) + '">(' + load_lang('compare') + ')</a> ' + \
+                        '<a href="/check/' + url_pas(name) + '?type=simple">(' + load_lang('simple_check') + ')</a>' + \
+                        '<hr class="main_hr">' + \
+                    '' + div
                 else:
-                    ua = '<br>'
+                    div = '' + \
+                        '<a href="/check/' + url_pas(name) + '">(' + name + ')</a> ' + \
+                        '<a href="/check/' + url_pas(plus_id) + '">(' + plus_id + ')</a>' + \
+                        '<hr class="main_hr">' + \
+                    '' + div
 
                 div += '''
-                    <tr>
-                        <td>
-                            <a href="/check/''' + url_pas(data[0]) + '''">''' + data[0] + '''</a>
-                            <a  href="/check_delete''' + \
-                                '''?name=''' + url_pas(data[0]) + \
-                                '''&ip=''' + url_pas(data[1]) + \
-                                '''&time=''' + url_pas(data[3].replace(' ', '').replace(':', '').replace('-', '')) + \
-                                '''&return_type=''' + ('0' if ip_or_user(name) == 0 else '1') + '''">
-                                (''' + load_lang('delete') + ''')
-                            </a>
-                        </td>
-                        <td><a href="/check/''' + url_pas(data[1]) + '''">''' + data[1] + '''</a></td>
-                        <td>''' + data[3] + '''</td>
-                    </tr>
-                    <tr>
-                        <td colspan="3">''' + ua + '''</td>
-                    </tr>
+                    <table id="main_table_set">
+                        <tbody>
+                            <tr id="main_table_top_tr">
+                                <td id="main_table_width">''' + load_lang('name') + '''</td>
+                                <td id="main_table_width">''' + load_lang('ip') + '''</td>
+                                <td id="main_table_width">''' + load_lang('time') + '''</td>
+                            </tr>
                 '''
 
-            div += '''
-                    </tbody>
-                </table>
-            '''
-            
-        div += next_fix(
-            '/check/' + url_pas(name) + ('?plus=' + plus_id + '&num=' if plus_id else '?num='), 
-            num, 
-            record
-        )
-
-        return easy_minify(flask.render_template(skin_check(),
-            imp = [load_lang('check'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
-            data = div,
-            menu = [['manager', load_lang('return')]]
-        ))
-    else:
-        curs.execute(db_change("" + \
-            "select distinct " + ('name' if ip_or_user(name) == 1 else 'ip') + " from ua_d " + \
-            "where " + ('ip' if ip_or_user(name) == 1 else 'name') + " = ? "
-            "order by today desc limit ?, 50" + \
-        ""), [name, sql_num])
-        record = curs.fetchall()
+                set_n = 0
+                for data in record:
+                    if data[2]:
+                        if len(data[2]) > 300:
+                            ua = '' + \
+                                '<a href="javascript:void();" onclick="document.getElementById(\'check_' + str(set_n) + '\').style.display=\'block\';">(300+)</a>' + \
+                                '<div id="check_' + str(set_n) + '" style="display:none;">' + html.escape(data[2]) + '</div>' + \
+                            ''
+                            set_n += 1
+                        else:
+                            ua = html.escape(data[2])
+                    else:
+                        ua = '<br>'
 
-        div = ''
-        for i in record:
-            div += '<li><a href="/check/' + url_pas(i[0]) + '?type=simple">' + i[0] + '</a></li>'
+                    div += '''
+                        <tr>
+                            <td>
+                                <a href="/check/''' + url_pas(data[0]) + '''">''' + data[0] + '''</a>
+                                <a  href="/check_delete''' + \
+                                    '''?name=''' + url_pas(data[0]) + \
+                                    '''&ip=''' + url_pas(data[1]) + \
+                                    '''&time=''' + url_pas(data[3].replace(' ', '').replace(':', '').replace('-', '')) + \
+                                    '''&return_type=''' + ('0' if ip_or_user(name) == 0 else '1') + '''">
+                                    (''' + load_lang('delete') + ''')
+                                </a>
+                            </td>
+                            <td><a href="/check/''' + url_pas(data[1]) + '''">''' + data[1] + '''</a></td>
+                            <td>''' + data[3] + '''</td>
+                        </tr>
+                        <tr>
+                            <td colspan="3">''' + ua + '''</td>
+                        </tr>
+                    '''
+
+                div += '''
+                        </tbody>
+                    </table>
+                '''
 
-        if div != '':
-            div = '<ul class="inside_ul">' + div + '</ul>'
             div += next_fix(
-                '/check/' + url_pas(name) + '?type=' + check_type + '&num=', 
+                '/check/' + url_pas(name) + ('?plus=' + plus_id + '&num=' if plus_id else '?num='), 
                 num, 
                 record
             )
 
-        return easy_minify(flask.render_template(skin_check(),
-            imp = [name, wiki_set(), wiki_custom(), wiki_css(['(' + load_lang('simple_check') + ')', 0])],
-            data = div,
-            menu = [['check/' + url_pas(name), load_lang('return')]]
-        ))
+            return easy_minify(flask.render_template(skin_check(),
+                imp = [load_lang('check'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
+                data = div,
+                menu = [['manager', load_lang('return')]]
+            ))
+        else:
+            curs.execute(db_change("" + \
+                "select distinct " + ('name' if ip_or_user(name) == 1 else 'ip') + " from ua_d " + \
+                "where " + ('ip' if ip_or_user(name) == 1 else 'name') + " = ? "
+                "order by today desc limit ?, 50" + \
+            ""), [name, sql_num])
+            record = curs.fetchall()
+
+            div = ''
+            for i in record:
+                div += '<li><a href="/check/' + url_pas(i[0]) + '?type=simple">' + i[0] + '</a></li>'
+
+            if div != '':
+                div = '<ul class="inside_ul">' + div + '</ul>'
+                div += next_fix(
+                    '/check/' + url_pas(name) + '?type=' + check_type + '&num=', 
+                    num, 
+                    record
+                )
+
+            return easy_minify(flask.render_template(skin_check(),
+                imp = [name, wiki_set(), wiki_custom(), wiki_css(['(' + load_lang('simple_check') + ')', 0])],
+                data = div,
+                menu = [['check/' + url_pas(name), load_lang('return')]]
+            ))

+ 44 - 43
route/give_user_check_delete.py

@@ -1,46 +1,47 @@
 from .tool.func import *
 
-def give_user_check_delete_2(conn):
-    curs = conn.cursor()
-    
-    if admin_check() != 1:
-        return re_error('/error/4')
-
-    user_id = flask.request.args.get('name', None)
-    user_ip = flask.request.args.get('ip', None)
-    
-    time = flask.request.args.get('time', None)
-    time_set = re.search(r'([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})', time)
-    if not time_set:
-        return redirect()
-    
-    time_set = time_set.groups()
-    time = time_set[0] + '-' + time_set[1] + '-' + time_set[2] + ' '
-    time += time_set[3] + ':' + time_set[4] + ':' + time_set[5]
-    
-    return_type = flask.request.args.get('return_type', '1')
-        
-    if user_id and user_ip and time:
-        if flask.request.method == 'POST':
-            curs.execute(db_change("delete from ua_d where name = ? and ip = ? and today = ?"), [user_id, user_ip, time])
-            conn.commit()
-            
-            return redirect('/check/' + url_pas(user_id if return_type == '0' else user_ip))
+def give_user_check_delete_2():
+    with get_db_connect() as conn:
+        curs = conn.cursor()
+
+        if admin_check() != 1:
+            return re_error('/error/4')
+
+        user_id = flask.request.args.get('name', None)
+        user_ip = flask.request.args.get('ip', None)
+
+        time = flask.request.args.get('time', None)
+        time_set = re.search(r'([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})', time)
+        if not time_set:
+            return redirect()
+
+        time_set = time_set.groups()
+        time = time_set[0] + '-' + time_set[1] + '-' + time_set[2] + ' '
+        time += time_set[3] + ':' + time_set[4] + ':' + time_set[5]
+
+        return_type = flask.request.args.get('return_type', '1')
+
+        if user_id and user_ip and time:
+            if flask.request.method == 'POST':
+                curs.execute(db_change("delete from ua_d where name = ? and ip = ? and today = ?"), [user_id, user_ip, time])
+                conn.commit()
+
+                return redirect('/check/' + url_pas(user_id if return_type == '0' else user_ip))
+            else:
+                return easy_minify(flask.render_template(skin_check(),
+                    imp = [load_lang('check'), wiki_set(), wiki_custom(), wiki_css(['(' + load_lang('delete') + ')', 0])],
+                    data = '''
+                        ''' + load_lang('name') + ''' : ''' + user_id + '''
+                        <hr class="main_hr">
+                        ''' + load_lang('ip') + ''' : ''' + user_ip + '''
+                        <hr class="main_hr">
+                        ''' + load_lang('time') + ''' : ''' + time + '''
+                        <hr class="main_hr">
+                        <form method="post">
+                            <button type="submit">''' + load_lang('delete') + '''</button>
+                        </form>
+                    ''',
+                    menu = [['check/' + url_pas(user_id if return_type == '0' else user_ip), load_lang('return')]]
+                ))
         else:
-            return easy_minify(flask.render_template(skin_check(),
-                imp = [load_lang('check'), wiki_set(), wiki_custom(), wiki_css(['(' + load_lang('delete') + ')', 0])],
-                data = '''
-                    ''' + load_lang('name') + ''' : ''' + user_id + '''
-                    <hr class="main_hr">
-                    ''' + load_lang('ip') + ''' : ''' + user_ip + '''
-                    <hr class="main_hr">
-                    ''' + load_lang('time') + ''' : ''' + time + '''
-                    <hr class="main_hr">
-                    <form method="post">
-                        <button type="submit">''' + load_lang('delete') + '''</button>
-                    </form>
-                ''',
-                menu = [['check/' + url_pas(user_id if return_type == '0' else user_ip), load_lang('return')]]
-            ))
-    else:
-        return redirect()
+            return redirect()

+ 30 - 29
route/list_acl.py

@@ -1,38 +1,39 @@
 from .tool.func import *
 
 def list_acl_2(conn):
-    curs = conn.cursor()
+    with get_db_connect() as conn:
+        curs = conn.cursor()
 
-    num = int(number_check(flask.request.args.get('num', '1')))
-    sql_num = (num * 50 - 50) if num * 50 > 0 else 0
-    div = '<ul class="inside_ul">'
+        num = int(number_check(flask.request.args.get('num', '1')))
+        sql_num = (num * 50 - 50) if num * 50 > 0 else 0
+        div = '<ul class="inside_ul">'
 
-    curs.execute(db_change(
-        "select distinct title, data, type from acl where data != '' and not title like 'user:%' order by title desc limit ?, 50"
-    ), [sql_num])
-    list_data = curs.fetchall()
-    for data in list_data:
-        curs.execute(db_change("select time from re_admin where what like ? order by time desc limit 1"), ['acl (' + data[0] + ')%'])
-        time_data = curs.fetchall()
-        time_data = (time_data[0][0] + ' | ') if time_data else ''
+        curs.execute(db_change(
+            "select distinct title, data, type from acl where data != '' and not title like 'user:%' order by title desc limit ?, 50"
+        ), [sql_num])
+        list_data = curs.fetchall()
+        for data in list_data:
+            curs.execute(db_change("select time from re_admin where what like ? order by time desc limit 1"), ['acl (' + data[0] + ')%'])
+            time_data = curs.fetchall()
+            time_data = (time_data[0][0] + ' | ') if time_data else ''
 
-        curs.execute(db_change("select data from acl where title = ? and type = 'why'"), [data[0]])
-        why_data = curs.fetchall()
-        why_data = (' | ' + why_data[0][0]) if why_data and why_data[0][0] != '' else ''
+            curs.execute(db_change("select data from acl where title = ? and type = 'why'"), [data[0]])
+            why_data = curs.fetchall()
+            why_data = (' | ' + why_data[0][0]) if why_data and why_data[0][0] != '' else ''
 
-        div += '' + \
-            '<li>' + \
-                time_data + \
-                '<a href="/acl/' + url_pas(data[0]) + '">' + html.escape(data[0]) + '</a>' + \
-                why_data + \
-            '</li>' + \
-        ''
+            div += '' + \
+                '<li>' + \
+                    time_data + \
+                    '<a href="/acl/' + url_pas(data[0]) + '">' + html.escape(data[0]) + '</a>' + \
+                    why_data + \
+                '</li>' + \
+            ''
 
-    div += '</ul>'
-    div += next_fix('/acl_list?num=', num, list_data)
+        div += '</ul>'
+        div += next_fix('/acl_list?num=', num, list_data)
 
-    return easy_minify(flask.render_template(skin_check(),
-        imp = [load_lang('acl_document_list'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
-        data = div,
-        menu = [['other', load_lang('return')]]
-    ))
+        return easy_minify(flask.render_template(skin_check(),
+            imp = [load_lang('acl_document_list'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
+            data = div,
+            menu = [['other', load_lang('return')]]
+        ))

+ 19 - 18
route/list_admin.py

@@ -1,25 +1,26 @@
 from .tool.func import *
 
-def list_admin_2(conn):
-    curs = conn.cursor()
+def list_admin_2():
+    with get_db_connect() as conn:
+        curs = conn.cursor()
 
-    div = '<ul class="inside_ul">'
+        div = '<ul class="inside_ul">'
 
-    curs.execute(db_change(
-        "select id, data from user_set where name = 'acl' and not data = 'user'"
-    ))
-    for data in curs.fetchall():
-        name = '' + \
-            ip_pas(data[0]) + ' ' + \
-            '<a href="/admin_plus/' + url_pas(data[1]) + '">(' + data[1] + ')</a>' + \
-        ''
+        curs.execute(db_change(
+            "select id, data from user_set where name = 'acl' and not data = 'user'"
+        ))
+        for data in curs.fetchall():
+            name = '' + \
+                ip_pas(data[0]) + ' ' + \
+                '<a href="/admin_plus/' + url_pas(data[1]) + '">(' + data[1] + ')</a>' + \
+            ''
 
-        div += '<li>' + name + '</li>'
+            div += '<li>' + name + '</li>'
 
-    div += '</ul>'
+        div += '</ul>'
 
-    return easy_minify(flask.render_template(skin_check(),
-        imp = [load_lang('admin_list'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
-        data = div,
-        menu = [['other', load_lang('return')]]
-    ))
+        return easy_minify(flask.render_template(skin_check(),
+            imp = [load_lang('admin_list'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
+            data = div,
+            menu = [['other', load_lang('return')]]
+        ))

+ 27 - 26
route/list_admin_group.py

@@ -1,34 +1,35 @@
 from .tool.func import *
 
-def list_admin_group_2(conn):
-    curs = conn.cursor()
+def list_admin_group_2():
+    with get_db_connect() as conn:
+        curs = conn.cursor()
 
-    list_data = '<ul class="inside_ul">'
-    org_acl_list = get_default_admin_group()
+        list_data = '<ul class="inside_ul">'
+        org_acl_list = get_default_admin_group()
 
-    curs.execute(db_change("select distinct name from alist order by name asc"))
-    for data in curs.fetchall():            
-        if  admin_check() == 1 and \
-            not data[0] in org_acl_list:
-            delete_admin_group = ' <a href="/delete_admin_group/' + url_pas(data[0]) + '">(' + load_lang("delete") + ')</a>'
-        else:
-            delete_admin_group = ''
+        curs.execute(db_change("select distinct name from alist order by name asc"))
+        for data in curs.fetchall():            
+            if  admin_check() == 1 and \
+                not data[0] in org_acl_list:
+                delete_admin_group = ' <a href="/delete_admin_group/' + url_pas(data[0]) + '">(' + load_lang("delete") + ')</a>'
+            else:
+                delete_admin_group = ''
+
+            list_data += '' + \
+                '<li>' + \
+                    '<a href="/admin_plus/' + url_pas(data[0]) + '">' + html.escape(data[0]) + '</a>' + \
+                    delete_admin_group + \
+                '</li>' + \
+            ''
 
         list_data += '' + \
-            '<li>' + \
-                '<a href="/admin_plus/' + url_pas(data[0]) + '">' + html.escape(data[0]) + '</a>' + \
-                delete_admin_group + \
-            '</li>' + \
+            '</ul>' + \
+            '<hr class="main_hr">' + \
+            '<a href="/manager/8">(' + load_lang('add') + ')</a>' + \
         ''
 
-    list_data += '' + \
-        '</ul>' + \
-        '<hr class="main_hr">' + \
-        '<a href="/manager/8">(' + load_lang('add') + ')</a>' + \
-    ''
-
-    return easy_minify(flask.render_template(skin_check(),
-        imp = [load_lang('admin_group_list'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
-        data = list_data,
-        menu = [['manager', load_lang('return')]]
-    ))    
+        return easy_minify(flask.render_template(skin_check(),
+            imp = [load_lang('admin_group_list'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
+            data = list_data,
+            menu = [['manager', load_lang('return')]]
+        ))

+ 31 - 30
route/list_admin_use.py

@@ -1,38 +1,39 @@
 from .tool.func import *
 
-def list_admin_use_2(conn):
-    curs = conn.cursor()
+def list_admin_use_2():
+    with get_db_connect() as conn:
+        curs = conn.cursor()
 
-    num = int(number_check(flask.request.args.get('num', '1')))
-    sql_num = (num * 50 - 50) if num * 50 > 0 else 0
+        num = int(number_check(flask.request.args.get('num', '1')))
+        sql_num = (num * 50 - 50) if num * 50 > 0 else 0
 
-    if flask.request.method == 'POST':
-        return redirect('/admin_log?search=' + flask.request.form.get('search', 'normal'))
-    else:
-        list_data = '<ul class="inside_ul">'
-
-        if flask.request.args.get('search', 'normal') == 'normal':
-            curs.execute(db_change("select who, what, time from re_admin order by time desc limit ?, 50"), [sql_num])
+        if flask.request.method == 'POST':
+            return redirect('/admin_log?search=' + flask.request.form.get('search', 'normal'))
         else:
-            curs.execute(db_change("select who, what, time from re_admin where what like ? order by time desc limit ?, 50"), [
-                flask.request.args.get('search', 'normal') + "%",
-                sql_num
-            ])
+            list_data = '<ul class="inside_ul">'
+
+            if flask.request.args.get('search', 'normal') == 'normal':
+                curs.execute(db_change("select who, what, time from re_admin order by time desc limit ?, 50"), [sql_num])
+            else:
+                curs.execute(db_change("select who, what, time from re_admin where what like ? order by time desc limit ?, 50"), [
+                    flask.request.args.get('search', 'normal') + "%",
+                    sql_num
+                ])
 
-        get_list = curs.fetchall()
-        for data in get_list:
-            list_data += '<li>' + ip_pas(data[0]) + ' / ' + html.escape(data[1]) + ' / ' + data[2] + '</li>'
+            get_list = curs.fetchall()
+            for data in get_list:
+                list_data += '<li>' + ip_pas(data[0]) + ' / ' + html.escape(data[1]) + ' / ' + data[2] + '</li>'
 
-        list_data += '</ul>'
-        list_data += next_fix('/admin_log?num=', num, get_list)
+            list_data += '</ul>'
+            list_data += next_fix('/admin_log?num=', num, get_list)
 
-        return easy_minify(flask.render_template(skin_check(),
-            imp = [load_lang('authority_use_list'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
-            data = '''
-                <form method="post">
-                    <input name="search" id="admin_log_search"> <button type="submit">''' + load_lang('search') + '''</button>
-                </form>
-                <hr class=\"main_hr\">
-            ''' + list_data,
-            menu = [['other', load_lang('return')]]
-        ))
+            return easy_minify(flask.render_template(skin_check(),
+                imp = [load_lang('authority_use_list'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
+                data = '''
+                    <form method="post">
+                        <input name="search" id="admin_log_search"> <button type="submit">''' + load_lang('search') + '''</button>
+                    </form>
+                    <hr class=\"main_hr\">
+                ''' + list_data,
+                menu = [['other', load_lang('return')]]
+            ))

+ 17 - 19
route/list_image_file.py

@@ -1,26 +1,24 @@
 from .tool.func import *
 
-def list_image_file_2(conn):
-    curs = conn.cursor()
+def list_image_file_2():
+    with get_db_connect() as conn:
+        curs = conn.cursor()
 
-    num = int(number_check(flask.request.args.get('num', '1')))
-    if num * 50 > 0:
-        sql_num = num * 50 - 50
-    else:
-        sql_num = 0
+        num = int(number_check(flask.request.args.get('num', '1')))
+        sql_num = (num * 50 - 50) if num * 50 > 0 else 0
 
-    list_data = '<ul class="inside_ul">'
-    back = ''
+        list_data = '<ul class="inside_ul">'
+        back = ''
 
-    curs.execute(db_change("select title from data where title like 'file:%' limit ?, 50"), [sql_num])
-    data_list = curs.fetchall()
-    for data in data_list:
-        list_data += '<li><a href="/w/' + url_pas(data[0]) + '">' + html.escape(data[0]) + '</a></li>'
+        curs.execute(db_change("select title from data where title like 'file:%' limit ?, 50"), [sql_num])
+        data_list = curs.fetchall()
+        for data in data_list:
+            list_data += '<li><a href="/w/' + url_pas(data[0]) + '">' + html.escape(data[0]) + '</a></li>'
 
-    list_data += next_fix('/image_file_list?num=', num, data_list)
+        list_data += next_fix('/image_file_list?num=', num, data_list)
 
-    return easy_minify(flask.render_template(skin_check(),
-        imp = [load_lang('image_file_list'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
-        data = list_data,
-        menu = [['other', load_lang('return')]]
-    ))    
+        return easy_minify(flask.render_template(skin_check(),
+            imp = [load_lang('image_file_list'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
+            data = list_data,
+            menu = [['other', load_lang('return')]]
+        ))

+ 18 - 17
route/list_long_page.py

@@ -1,24 +1,25 @@
 from .tool.func import *
 
-def list_long_page_2(conn, tool):
-    curs = conn.cursor()
+def list_long_page_2(tool):
+    with get_db_connect() as conn:
+        curs = conn.cursor()
 
-    curs.execute(db_change('select data from other where name = "count_all_title"'))
-    if int(curs.fetchall()[0][0]) > 30000:
-        return re_error('/error/25')
+        curs.execute(db_change('select data from other where name = "count_all_title"'))
+        if int(curs.fetchall()[0][0]) > 30000:
+            return re_error('/error/25')
 
-    div = '<ul class="inside_ul">'
-    select_data = 'desc' if tool == 'long_page' else 'asc'
-    title = 'long_page' if tool == 'long_page' else 'short_page'
+        div = '<ul class="inside_ul">'
+        select_data = 'desc' if tool == 'long_page' else 'asc'
+        title = 'long_page' if tool == 'long_page' else 'short_page'
 
-    curs.execute(db_change("select title, length(data) from data order by length(data) " + select_data + " limit 50"))
-    for data in curs.fetchall():
-        div += '<li>' + str(data[1]) + ' : <a href="/w/' + url_pas(data[0]) + '">' + html.escape(data[0]) + '</a></li>'
+        curs.execute(db_change("select title, length(data) from data order by length(data) " + select_data + " limit 50"))
+        for data in curs.fetchall():
+            div += '<li>' + str(data[1]) + ' : <a href="/w/' + url_pas(data[0]) + '">' + html.escape(data[0]) + '</a></li>'
 
-    div += '</ul>'
+        div += '</ul>'
 
-    return easy_minify(flask.render_template(skin_check(),
-        imp = [load_lang(title), wiki_set(), wiki_custom(), wiki_css([0, 0])],
-        data = div,
-        menu = [['other', load_lang('return')]]
-    ))
+        return easy_minify(flask.render_template(skin_check(),
+            imp = [load_lang(title), wiki_set(), wiki_custom(), wiki_css([0, 0])],
+            data = div,
+            menu = [['other', load_lang('return')]]
+        ))

+ 24 - 23
route/list_please.py

@@ -1,31 +1,32 @@
 from .tool.func import *
 
-def list_please_2(conn):
-    curs = conn.cursor()
+def list_please_2():
+    with get_db_connect() as conn:
+        curs = conn.cursor()
 
-    num = int(number_check(flask.request.args.get('num', '1')))
-    sql_num = (num * 50 - 50) if num * 50 > 0 else 0
+        num = int(number_check(flask.request.args.get('num', '1')))
+        sql_num = (num * 50 - 50) if num * 50 > 0 else 0
 
-    curs.execute(db_change('select data from other where name = "count_all_title"'))
-    if int(curs.fetchall()[0][0]) > 30000:
-        return re_error('/error/25')
+        curs.execute(db_change('select data from other where name = "count_all_title"'))
+        if int(curs.fetchall()[0][0]) > 30000:
+            return re_error('/error/25')
 
-    div = '<ul class="inside_ul">'
+        div = '<ul class="inside_ul">'
 
-    curs.execute(db_change("select distinct title, link from back where type = 'no' order by title asc limit ?, 50"), [sql_num])
-    data_list = curs.fetchall()
-    for data in data_list:
-        div += '' + \
-            '<li>' + \
-                '<a id="not_thing" href="/w/' + url_pas(data[0]) + '">' + html.escape(data[0]) + '</a> ' + \
-                '<a href="/w/' + url_pas(data[1]) + '">(' + html.escape(data[1]) + ')</a>' + \
-            '</li>' + \
-        ''
+        curs.execute(db_change("select distinct title, link from back where type = 'no' order by title asc limit ?, 50"), [sql_num])
+        data_list = curs.fetchall()
+        for data in data_list:
+            div += '' + \
+                '<li>' + \
+                    '<a id="not_thing" href="/w/' + url_pas(data[0]) + '">' + html.escape(data[0]) + '</a> ' + \
+                    '<a href="/w/' + url_pas(data[1]) + '">(' + html.escape(data[1]) + ')</a>' + \
+                '</li>' + \
+            ''
 
-    div += '</ul>' + next_fix('/please?num=', num, data_list)
+        div += '</ul>' + next_fix('/please?num=', num, data_list)
 
-    return easy_minify(flask.render_template(skin_check(),
-        imp = [load_lang('need_document'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
-        data = div,
-        menu = [['other', load_lang('return')]]
-    ))
+        return easy_minify(flask.render_template(skin_check(),
+            imp = [load_lang('need_document'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
+            data = div,
+            menu = [['other', load_lang('return')]]
+        ))

+ 60 - 59
route/list_title_index.py

@@ -1,78 +1,79 @@
 from .tool.func import *
 
-def list_title_index_2(conn):
-    curs = conn.cursor()
+def list_title_index_2():
+    with get_db_connect() as conn:
+        curs = conn.cursor()
 
-    page = int(number_check(flask.request.args.get('page', '1')))
-    num = int(number_check(flask.request.args.get('num', '100')))
-    sql_num = (page * num - num) if page * num > 0 else 0
+        page = int(number_check(flask.request.args.get('page', '1')))
+        num = int(number_check(flask.request.args.get('num', '100')))
+        sql_num = (page * num - num) if page * num > 0 else 0
 
-    all_list = sql_num + 1
+        all_list = sql_num + 1
 
-    if num > 1000:
-        return re_error('/error/3')
+        if num > 1000:
+            return re_error('/error/3')
 
-    data = '<a href="/title_index?num=250">(250)</a> <a href="/title_index?num=500">(500)</a> <a href="/title_index?num=1000">(1000)</a>'
+        data = '<a href="/title_index?num=250">(250)</a> <a href="/title_index?num=500">(500)</a> <a href="/title_index?num=1000">(1000)</a>'
 
-    curs.execute(db_change("select title from data order by title asc limit ?, ?"), [sql_num, num])
-    title_list = curs.fetchall()
-    if title_list:
-        data += '<hr class="main_hr"><ul class="inside_ul">'
+        curs.execute(db_change("select title from data order by title asc limit ?, ?"), [sql_num, num])
+        title_list = curs.fetchall()
+        if title_list:
+            data += '<hr class="main_hr"><ul class="inside_ul">'
 
-    for list_data in title_list:
-        data += '<li>' + str(all_list) + '. <a href="/w/' + url_pas(list_data[0]) + '">' + html.escape(list_data[0]) + '</a></li>'
-        all_list += 1
+        for list_data in title_list:
+            data += '<li>' + str(all_list) + '. <a href="/w/' + url_pas(list_data[0]) + '">' + html.escape(list_data[0]) + '</a></li>'
+            all_list += 1
 
-    if page == 1:
-        count_end = []
+        if page == 1:
+            count_end = []
 
-        curs.execute(db_change('select data from other where name = "count_all_title"'))
-        all_title = curs.fetchall()
-        if int(all_title[0][0]) < 30000:
-            curs.execute(db_change("select count(*) from data"))
-            count = curs.fetchall()
-            if count:
-                count_end += [count[0][0]]
-            else:
-                count_end += [0]
-
-            sql_list = ['category:', 'user:', 'file:']
-            for sql in sql_list:
-                curs.execute(db_change("select count(*) from data where title like ?"), [sql + '%'])
+            curs.execute(db_change('select data from other where name = "count_all_title"'))
+            all_title = curs.fetchall()
+            if int(all_title[0][0]) < 30000:
+                curs.execute(db_change("select count(*) from data"))
                 count = curs.fetchall()
                 if count:
                     count_end += [count[0][0]]
                 else:
                     count_end += [0]
 
-            count_end += [count_end[0] - count_end[1]  - count_end[2]  - count_end[3]]
+                sql_list = ['category:', 'user:', 'file:']
+                for sql in sql_list:
+                    curs.execute(db_change("select count(*) from data where title like ?"), [sql + '%'])
+                    count = curs.fetchall()
+                    if count:
+                        count_end += [count[0][0]]
+                    else:
+                        count_end += [0]
 
-            data += '''
-                </ul>
-                <hr class="main_hr">
-                <ul class="inside_ul">
-                    <li>''' + load_lang('all') + ' : ' + str(count_end[0]) + '''</li>
-                </ul>
-                <hr class="main_hr">
-                <ul class="inside_ul">
-                    <li>''' + load_lang('category') + ' : ' + str(count_end[1]) + '''</li>
-                    <li>''' + load_lang('user_document') + ' : ' + str(count_end[2]) + '''</li>
-                    <li>''' + load_lang('file') + ' : ' + str(count_end[3]) + '''</li>
-                    <li>''' + load_lang('other') + ' : ' + str(count_end[4]) + '''</li>
-            '''
-        else:
-            data += '''
-                </ul>
-                <hr class="main_hr">
-                <ul class="inside_ul">
-                    <li>''' + load_lang('all') + ' : ' + all_title[0][0] + '''</li>
-            '''
+                count_end += [count_end[0] - count_end[1]  - count_end[2]  - count_end[3]]
+
+                data += '''
+                    </ul>
+                    <hr class="main_hr">
+                    <ul class="inside_ul">
+                        <li>''' + load_lang('all') + ' : ' + str(count_end[0]) + '''</li>
+                    </ul>
+                    <hr class="main_hr">
+                    <ul class="inside_ul">
+                        <li>''' + load_lang('category') + ' : ' + str(count_end[1]) + '''</li>
+                        <li>''' + load_lang('user_document') + ' : ' + str(count_end[2]) + '''</li>
+                        <li>''' + load_lang('file') + ' : ' + str(count_end[3]) + '''</li>
+                        <li>''' + load_lang('other') + ' : ' + str(count_end[4]) + '''</li>
+                '''
+            else:
+                data += '''
+                    </ul>
+                    <hr class="main_hr">
+                    <ul class="inside_ul">
+                        <li>''' + load_lang('all') + ' : ' + all_title[0][0] + '''</li>
+                '''
 
-    data += '</ul>' + next_fix('/title_index?num=' + str(num) + '&page=', page, title_list, num)
-    sub = ' (' + str(num) + ')'
+        data += '</ul>' + next_fix('/title_index?num=' + str(num) + '&page=', page, title_list, num)
+        sub = ' (' + str(num) + ')'
 
-    return easy_minify(flask.render_template(skin_check(),
-        imp = [load_lang('all_document_list'), wiki_set(), wiki_custom(), wiki_css([sub, 0])],
-        data = data,
-        menu = [['other', load_lang('return')]]
-    ))
+        return easy_minify(flask.render_template(skin_check(),
+            imp = [load_lang('all_document_list'), wiki_set(), wiki_custom(), wiki_css([sub, 0])],
+            data = data,
+            menu = [['other', load_lang('return')]]
+        ))

+ 20 - 19
route/list_user.py

@@ -1,26 +1,27 @@
 from .tool.func import *
 
-def list_user_2(conn):
-    curs = conn.cursor()
+def list_user_2():
+    with get_db_connect() as conn:
+        curs = conn.cursor()
 
-    num = int(number_check(flask.request.args.get('num', '1')))
-    sql_num = (num * 50 - 50) if num * 50 > 0 else 0
+        num = int(number_check(flask.request.args.get('num', '1')))
+        sql_num = (num * 50 - 50) if num * 50 > 0 else 0
 
-    list_data = '<ul class="inside_ul">'
+        list_data = '<ul class="inside_ul">'
 
-    curs.execute(db_change("select id, data from user_set where name = 'date' order by data desc limit ?, 50"), [sql_num])
-    user_list = curs.fetchall()
-    for data in user_list:
-        list_data += '' + \
-            '<li>' + \
-                ip_pas(data[0]) + (' (' + data[1] + ')' if data[1] != '' else '') + \
-            '</li>' + \
-        ''
+        curs.execute(db_change("select id, data from user_set where name = 'date' order by data desc limit ?, 50"), [sql_num])
+        user_list = curs.fetchall()
+        for data in user_list:
+            list_data += '' + \
+                '<li>' + \
+                    ip_pas(data[0]) + (' (' + data[1] + ')' if data[1] != '' else '') + \
+                '</li>' + \
+            ''
 
-    list_data += '</ul>' + next_fix('/user_log?num=', num, user_list)
+        list_data += '</ul>' + next_fix('/user_log?num=', num, user_list)
 
-    return easy_minify(flask.render_template(skin_check(),
-        imp = [load_lang('member_list'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
-        data = list_data,
-        menu = [['other', load_lang('return')]]
-    ))
+        return easy_minify(flask.render_template(skin_check(),
+            imp = [load_lang('member_list'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
+            data = list_data,
+            menu = [['other', load_lang('return')]]
+        ))

+ 60 - 59
route/login_login.py

@@ -1,72 +1,73 @@
 from .tool.func import *
 
-def login_login_2(conn):
-    curs = conn.cursor()
+def login_login_2():
+    with get_db_connect() as conn:
+        curs = conn.cursor()
 
-    ip = ip_check()
-    if ip_or_user(ip) == 0:
-        return redirect('/user')
+        ip = ip_check()
+        if ip_or_user(ip) == 0:
+            return redirect('/user')
 
-    if ban_check(None, 'login') == 1:
-        return re_error('/ban')
+        if ban_check(None, 'login') == 1:
+            return re_error('/ban')
 
-    if flask.request.method == 'POST':
-        if captcha_post(flask.request.form.get('g-recaptcha-response', flask.request.form.get('g-recaptcha', ''))) == 1:
-            return re_error('/error/13')
-        else:
-            captcha_post('', 0)
+        if flask.request.method == 'POST':
+            if captcha_post(flask.request.form.get('g-recaptcha-response', flask.request.form.get('g-recaptcha', ''))) == 1:
+                return re_error('/error/13')
+            else:
+                captcha_post('', 0)
 
-        user_agent = flask.request.headers.get('User-Agent', '')
-        user_id = flask.request.form.get('id', '')
-        user_data = {}
+            user_agent = flask.request.headers.get('User-Agent', '')
+            user_id = flask.request.form.get('id', '')
+            user_data = {}
 
-        curs.execute(db_change(
-            'select name, data from user_set where id = ? and name = "pw" or name = "encode"'
-        ), [user_id])
-        sql_data = curs.fetchall()
-        if not sql_data:
-            return re_error('/error/2')
+            curs.execute(db_change(
+                'select name, data from user_set where id = ? and name = "pw" or name = "encode"'
+            ), [user_id])
+            sql_data = curs.fetchall()
+            if not sql_data:
+                return re_error('/error/2')
 
-        for i in sql_data:
-            user_data[i[0]] = i[1]
-                
-        if len(user_data) < 2:
-            return re_error('/error/2')
+            for i in sql_data:
+                user_data[i[0]] = i[1]
 
-        if pw_check(
-            flask.request.form.get('pw', ''),
-            user_data['pw'],
-            user_data['encode'],
-            user_id
-        ) != 1:
-            return re_error('/error/10')
+            if len(user_data) < 2:
+                return re_error('/error/2')
 
-        curs.execute(db_change('select data from user_set where name = "2fa" and id = ?'), [user_id])
-        fa_data = curs.fetchall()
-        if fa_data and fa_data[0][0] != '':
-            flask.session['login_id'] = user_id
+            if pw_check(
+                flask.request.form.get('pw', ''),
+                user_data['pw'],
+                user_data['encode'],
+                user_id
+            ) != 1:
+                return re_error('/error/10')
 
-            return redirect('/login/2fa')
-        else:
-            flask.session['id'] = user_id
+            curs.execute(db_change('select data from user_set where name = "2fa" and id = ?'), [user_id])
+            fa_data = curs.fetchall()
+            if fa_data and fa_data[0][0] != '':
+                flask.session['login_id'] = user_id
 
-            ua_plus(user_id, ip, user_agent, get_time())
-            conn.commit()
+                return redirect('/login/2fa')
+            else:
+                flask.session['id'] = user_id
 
-            return redirect('/user')
-    else:
-        return easy_minify(flask.render_template(skin_check(),
-            imp = [load_lang('login'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
-            data =  '''
-                    <form method="post">
-                        <input placeholder="''' + load_lang('id') + '''" name="id" type="text">
-                        <hr class="main_hr">
-                        <input placeholder="''' + load_lang('password') + '''" name="pw" type="password">
-                        <hr class="main_hr">
-                        ''' + captcha_get() + '''
-                        <button type="submit">''' + load_lang('login') + '''</button>
-                        ''' + http_warning() + '''
-                    </form>
-                    ''',
-            menu = [['user', load_lang('return')]]
-        ))
+                ua_plus(user_id, ip, user_agent, get_time())
+                conn.commit()
+
+                return redirect('/user')
+        else:
+            return easy_minify(flask.render_template(skin_check(),
+                imp = [load_lang('login'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
+                data =  '''
+                        <form method="post">
+                            <input placeholder="''' + load_lang('id') + '''" name="id" type="text">
+                            <hr class="main_hr">
+                            <input placeholder="''' + load_lang('password') + '''" name="pw" type="password">
+                            <hr class="main_hr">
+                            ''' + captcha_get() + '''
+                            <button type="submit">''' + load_lang('login') + '''</button>
+                            ''' + http_warning() + '''
+                        </form>
+                        ''',
+                menu = [['user', load_lang('return')]]
+            ))

+ 57 - 56
route/login_login_2fa.py

@@ -1,70 +1,71 @@
 from .tool.func import *
 
 def login_login_2fa_2(conn):
-    curs = conn.cursor()
+    with get_db_connect() as conn:
+        curs = conn.cursor()
 
-    # email 2fa
-    # pw 2fa
-    # q_a 2fa
-    if not (flask.session and 'login_id' in flask.session):
-        return redirect('/user')
+        # email 2fa
+        # pw 2fa
+        # q_a 2fa
+        if not (flask.session and 'login_id' in flask.session):
+            return redirect('/user')
 
-    ip = ip_check()
-    if ip_or_user(ip) == 0:
-        return redirect('/user')
+        ip = ip_check()
+        if ip_or_user(ip) == 0:
+            return redirect('/user')
 
-    if ban_check(None, 'login') == 1:
-        return re_error('/ban')
+        if ban_check(None, 'login') == 1:
+            return re_error('/ban')
 
-    if flask.request.method == 'POST':
-        if captcha_post(flask.request.form.get('g-recaptcha-response', flask.request.form.get('g-recaptcha', ''))) == 1:
-            return re_error('/error/13')
-        else:
-            captcha_post('', 0)
+        if flask.request.method == 'POST':
+            if captcha_post(flask.request.form.get('g-recaptcha-response', flask.request.form.get('g-recaptcha', ''))) == 1:
+                return re_error('/error/13')
+            else:
+                captcha_post('', 0)
 
-        user_agent = flask.request.headers.get('User-Agent', '')
-        user_id = flask.session['login_id']
+            user_agent = flask.request.headers.get('User-Agent', '')
+            user_id = flask.session['login_id']
 
-        curs.execute(db_change('select data from user_set where name = "2fa_pw" and id = ?'), [user_id])
-        user_1 = curs.fetchall()
-        if user_1:
-            curs.execute(db_change('select data from user_set where name = "2fa_pw_encode" and id = ?'), [user_id])
-            user_1 = user_1[0][0]
-            user_2 = curs.fetchall()[0][0]
+            curs.execute(db_change('select data from user_set where name = "2fa_pw" and id = ?'), [user_id])
+            user_1 = curs.fetchall()
+            if user_1:
+                curs.execute(db_change('select data from user_set where name = "2fa_pw_encode" and id = ?'), [user_id])
+                user_1 = user_1[0][0]
+                user_2 = curs.fetchall()[0][0]
 
-            pw_check_d = pw_check(
-                flask.request.form.get('pw', ''),
-                user_1,
-                user_2,
-                user_id
-            )
-            if pw_check_d != 1:
-                return re_error('/error/10')
+                pw_check_d = pw_check(
+                    flask.request.form.get('pw', ''),
+                    user_1,
+                    user_2,
+                    user_id
+                )
+                if pw_check_d != 1:
+                    return re_error('/error/10')
 
-        flask.session['id'] = user_id
+            flask.session['id'] = user_id
 
-        ua_plus(
-            user_id, 
-            ip, 
-            user_agent, 
-            get_time()
-        )
-        conn.commit()
+            ua_plus(
+                user_id, 
+                ip, 
+                user_agent, 
+                get_time()
+            )
+            conn.commit()
 
-        flask.session.pop('b_id', None)
+            flask.session.pop('b_id', None)
 
-        return redirect('/user')
-    else:
-        return easy_minify(flask.render_template(skin_check(),
-            imp = [load_lang('login'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
-            data =  '''
-                    <form method="post">
-                        <input placeholder="''' + load_lang('2fa_password') + '''" name="pw" type="password">
-                        <hr class="main_hr">
-                        ''' + captcha_get() + '''
-                        <button type="submit">''' + load_lang('login') + '''</button>
-                        ''' + http_warning() + '''
-                    </form>
-                    ''',
-            menu = [['user', load_lang('return')]]
-        ))
+            return redirect('/user')
+        else:
+            return easy_minify(flask.render_template(skin_check(),
+                imp = [load_lang('login'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
+                data =  '''
+                        <form method="post">
+                            <input placeholder="''' + load_lang('2fa_password') + '''" name="pw" type="password">
+                            <hr class="main_hr">
+                            ''' + captcha_get() + '''
+                            <button type="submit">''' + load_lang('login') + '''</button>
+                            ''' + http_warning() + '''
+                        </form>
+                        ''',
+                menu = [['user', load_lang('return')]]
+            ))

+ 119 - 118
route/login_register.py

@@ -1,128 +1,129 @@
 from .tool.func import *
 
-def login_register_2(conn):
-    curs = conn.cursor()
+def login_register_2():
+    with get_db_connect() as conn:
+        curs = conn.cursor()
 
-    if ban_check(None, 'login') == 1:
-        return re_error('/ban')
+        if ban_check(None, 'login') == 1:
+            return re_error('/ban')
 
-    ip = ip_check()
-    admin = admin_check()
-    if admin != 1 and ip_or_user(ip) == 0:
-        return redirect('/user')
+        ip = ip_check()
+        admin = admin_check()
+        if admin != 1 and ip_or_user(ip) == 0:
+            return redirect('/user')
 
-    if admin != 1:
-        curs.execute(db_change('select data from other where name = "reg"'))
-        set_d = curs.fetchall()
-        if set_d and set_d[0][0] == 'on':
-            return re_error('/ban')
+        if admin != 1:
+            curs.execute(db_change('select data from other where name = "reg"'))
+            set_d = curs.fetchall()
+            if set_d and set_d[0][0] == 'on':
+                return re_error('/ban')
 
-    if flask.request.method == 'POST':
-        # 리캡차
-        if captcha_post(flask.request.form.get('g-recaptcha-response', flask.request.form.get('g-recaptcha', ''))) == 1:
-            return re_error('/error/13')
-        else:
-            captcha_post('', 0)
-
-        user_id = flask.request.form.get('id', '')
-        user_pw = flask.request.form.get('pw', '')
-        user_repeat = flask.request.form.get('pw2', '')
-        
-        # PW 검증
-        if user_id == '' or user_pw == '':
-            return re_error('/error/27')
-
-        if user_pw != user_repeat:
-            return re_error('/error/20')
-
-        # PW 길이 제한
-        curs.execute(db_change("select data from other where name = 'password_min_length'"))
-        db_data = curs.fetchall()
-        if db_data and db_data[0][0] != '':
-            password_min_length = int(number_check(db_data[0][0]))
-            if password_min_length > len(user_pw):
-                return re_error('/error/40')
-        
-        # ID 글자 확인
-        if re.search(r'(?:[^A-Za-zㄱ-힣0-9])', user_id):
-            return re_error('/error/8')
-
-        # ID 필터
-        curs.execute(db_change('select html from html_filter where kind = "name"'))
-        set_d = curs.fetchall()
-        for i in set_d:
-            check_r = re.compile(i[0], re.I)
-            if check_r.search(user_id):
+        if flask.request.method == 'POST':
+            # 리캡차
+            if captcha_post(flask.request.form.get('g-recaptcha-response', flask.request.form.get('g-recaptcha', ''))) == 1:
+                return re_error('/error/13')
+            else:
+                captcha_post('', 0)
+
+            user_id = flask.request.form.get('id', '')
+            user_pw = flask.request.form.get('pw', '')
+            user_repeat = flask.request.form.get('pw2', '')
+
+            # PW 검증
+            if user_id == '' or user_pw == '':
+                return re_error('/error/27')
+
+            if user_pw != user_repeat:
+                return re_error('/error/20')
+
+            # PW 길이 제한
+            curs.execute(db_change("select data from other where name = 'password_min_length'"))
+            db_data = curs.fetchall()
+            if db_data and db_data[0][0] != '':
+                password_min_length = int(number_check(db_data[0][0]))
+                if password_min_length > len(user_pw):
+                    return re_error('/error/40')
+
+            # ID 글자 확인
+            if re.search(r'(?:[^A-Za-zㄱ-힣0-9])', user_id):
                 return re_error('/error/8')
 
-        # ID 길이 제한 (32글자)
-        if len(user_id) > 32:
-            return re_error('/error/7')
+            # ID 필터
+            curs.execute(db_change('select html from html_filter where kind = "name"'))
+            set_d = curs.fetchall()
+            for i in set_d:
+                check_r = re.compile(i[0], re.I)
+                if check_r.search(user_id):
+                    return re_error('/error/8')
 
-        # 중복 확인
-        curs.execute(db_change("select id from user_set where id = ?"), [user_id])
-        if curs.fetchall():
-            return re_error('/error/6')
-        
-        if admin != 1:
-            # 이메일 필요시 /register/email로 발송
-            curs.execute(db_change('select data from other where name = "email_have"'))
-            sql_data = curs.fetchall()
-            if sql_data and sql_data[0][0] != '':
-                # 임시로 세션에 저장
-                flask.session['reg_id'] = user_id
-                flask.session['reg_pw'] = user_pw
-
-                return redirect('/register/email')
-            
-            # 가입 승인 필요시 /register/submit으로 발송
-            curs.execute(db_change('select data from other where name = "requires_approval"'))
-            sql_data = curs.fetchall()
-            if sql_data and sql_data[0][0] != '':
-                flask.session['submit_id'] = user_id
-                flask.session['submit_pw'] = user_pw
-                
-                return redirect('/register/submit')
-        
-        # 전부 아니면 바로 가입 후 /login으로 발송
-        add_user(user_id, user_pw)
-        
-        conn.commit()
-        
-        return redirect('/login')
-    else:
-        curs.execute(db_change('select data from other where name = "contract"'))
-        data = curs.fetchall()
-        contract = (data[0][0] + '<hr class="main_hr">') if data and data[0][0] != '' else ''
-        
-        curs.execute(db_change("select data from other where name = 'password_min_length'"))
-        db_data = curs.fetchall()
-        if db_data and db_data[0][0] != '':
-            password_min_length = ' (' + load_lang('password_min_length') + ' : ' + db_data[0][0] + ')'
+            # ID 길이 제한 (32글자)
+            if len(user_id) > 32:
+                return re_error('/error/7')
+
+            # 중복 확인
+            curs.execute(db_change("select id from user_set where id = ?"), [user_id])
+            if curs.fetchall():
+                return re_error('/error/6')
+
+            if admin != 1:
+                # 이메일 필요시 /register/email로 발송
+                curs.execute(db_change('select data from other where name = "email_have"'))
+                sql_data = curs.fetchall()
+                if sql_data and sql_data[0][0] != '':
+                    # 임시로 세션에 저장
+                    flask.session['reg_id'] = user_id
+                    flask.session['reg_pw'] = user_pw
+
+                    return redirect('/register/email')
+
+                # 가입 승인 필요시 /register/submit으로 발송
+                curs.execute(db_change('select data from other where name = "requires_approval"'))
+                sql_data = curs.fetchall()
+                if sql_data and sql_data[0][0] != '':
+                    flask.session['submit_id'] = user_id
+                    flask.session['submit_pw'] = user_pw
+
+                    return redirect('/register/submit')
+
+            # 전부 아니면 바로 가입 후 /login으로 발송
+            add_user(user_id, user_pw)
+
+            conn.commit()
+
+            return redirect('/login')
         else:
-            password_min_length = ''
-                
-        return easy_minify(flask.render_template(skin_check(),
-            imp = [load_lang('register'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
-            data = '''
-                <form method="post">
-                    ''' + contract + '''
-                    
-                    <input placeholder="''' + load_lang('id') + '''" name="id" type="text">
-                    <hr class="main_hr">
-                    
-                    <input placeholder="''' + load_lang('password') + password_min_length + '''" name="pw" type="password">
-                    <hr class="main_hr">
-                    
-                    <input placeholder="''' + load_lang('password_confirm') + '''" name="pw2" type="password">
-                    <hr class="main_hr">
-                    
-                    ''' + captcha_get() + '''
-                    
-                    <button type="submit">''' + load_lang('save') + '''</button>
-                    
-                    ''' + http_warning() + '''
-                </form>
-            ''',
-            menu = [['user', load_lang('return')]]
-        ))
+            curs.execute(db_change('select data from other where name = "contract"'))
+            data = curs.fetchall()
+            contract = (data[0][0] + '<hr class="main_hr">') if data and data[0][0] != '' else ''
+
+            curs.execute(db_change("select data from other where name = 'password_min_length'"))
+            db_data = curs.fetchall()
+            if db_data and db_data[0][0] != '':
+                password_min_length = ' (' + load_lang('password_min_length') + ' : ' + db_data[0][0] + ')'
+            else:
+                password_min_length = ''
+
+            return easy_minify(flask.render_template(skin_check(),
+                imp = [load_lang('register'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
+                data = '''
+                    <form method="post">
+                        ''' + contract + '''
+
+                        <input placeholder="''' + load_lang('id') + '''" name="id" type="text">
+                        <hr class="main_hr">
+
+                        <input placeholder="''' + load_lang('password') + password_min_length + '''" name="pw" type="password">
+                        <hr class="main_hr">
+
+                        <input placeholder="''' + load_lang('password_confirm') + '''" name="pw2" type="password">
+                        <hr class="main_hr">
+
+                        ''' + captcha_get() + '''
+
+                        <button type="submit">''' + load_lang('save') + '''</button>
+
+                        ''' + http_warning() + '''
+                    </form>
+                ''',
+                menu = [['user', load_lang('return')]]
+            ))

+ 55 - 54
route/login_register_email.py

@@ -1,66 +1,67 @@
 from .tool.func import *
 
 def login_register_email_2(conn):
-    curs = conn.cursor()
-    
-    if not 'reg_id' in flask.session:
-        return redirect('/register')
-    
-    if flask.request.method == 'POST':
-        flask.session['reg_key'] = load_random_key(32)
+    with get_db_connect() as conn:
+        curs = conn.cursor()
 
-        user_email = re.sub(r'\\', '', flask.request.form.get('email', ''))
-        email_data = re.search(r'@([^@]+)$', user_email)
-        if email_data:
-            email_data = email_data.group(1)
-            
-            curs.execute(db_change(
-                "select html from html_filter where html = ? and kind = 'email'"
-            ), [email_data])
-            if not curs.fetchall():                
-                return redirect('/email_filter')
+        if not 'reg_id' in flask.session:
+            return redirect('/register')
 
-        curs.execute(db_change('select data from other where name = "email_title"'))
-        sql_d = curs.fetchall()
-        if sql_d and sql_d[0][0] != '':
-            t_text = html.escape(sql_d[0][0])
-        else:
-            t_text = wiki_set()[0] + ' key'
+        if flask.request.method == 'POST':
+            flask.session['reg_key'] = load_random_key(32)
 
-        curs.execute(db_change('select data from other where name = "email_text"'))
-        sql_d = curs.fetchall()
-        if sql_d and sql_d[0][0] != '':
-            i_text = html.escape(sql_d[0][0]) + '\n\nKey : ' + str(flask.session.get('reg_key'))
-        else:
-            i_text = 'Key : ' + str(flask.session.get('reg_key'))
-        
+            user_email = re.sub(r'\\', '', flask.request.form.get('email', ''))
+            email_data = re.search(r'@([^@]+)$', user_email)
+            if email_data:
+                email_data = email_data.group(1)
+
+                curs.execute(db_change(
+                    "select html from html_filter where html = ? and kind = 'email'"
+                ), [email_data])
+                if not curs.fetchall():                
+                    return redirect('/email_filter')
+
+            curs.execute(db_change('select data from other where name = "email_title"'))
+            sql_d = curs.fetchall()
+            if sql_d and sql_d[0][0] != '':
+                t_text = html.escape(sql_d[0][0])
+            else:
+                t_text = wiki_set()[0] + ' key'
 
-        curs.execute(db_change('select id from user_set where name = "email" and data = ?'), [user_email])
-        if curs.fetchall():
-            return re_error('/error/35')
+            curs.execute(db_change('select data from other where name = "email_text"'))
+            sql_d = curs.fetchall()
+            if sql_d and sql_d[0][0] != '':
+                i_text = html.escape(sql_d[0][0]) + '\n\nKey : ' + str(flask.session.get('reg_key'))
+            else:
+                i_text = 'Key : ' + str(flask.session.get('reg_key'))
 
-        if send_email(user_email, t_text, i_text) == 0:
-            return re_error('/error/18')
 
-        flask.session['reg_email'] = user_email
+            curs.execute(db_change('select id from user_set where name = "email" and data = ?'), [user_email])
+            if curs.fetchall():
+                return re_error('/error/35')
 
-        return redirect('/register/email/check')
-    else:
-        curs.execute(db_change('select data from other where name = "email_insert_text"'))
-        sql_d = curs.fetchall()
-        b_text = (sql_d[0][0] + '<hr class="main_hr">') if sql_d and sql_d[0][0] != '' else ''
+            if send_email(user_email, t_text, i_text) == 0:
+                return re_error('/error/18')
+
+            flask.session['reg_email'] = user_email
+
+            return redirect('/register/email/check')
+        else:
+            curs.execute(db_change('select data from other where name = "email_insert_text"'))
+            sql_d = curs.fetchall()
+            b_text = (sql_d[0][0] + '<hr class="main_hr">') if sql_d and sql_d[0][0] != '' else ''
 
-        return easy_minify(flask.render_template(skin_check(),
-            imp = [load_lang('email'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
-            data = '''
-                <a href="/email_filter">(''' + load_lang('email_filter_list') + ''')</a>
-                <hr class="main_hr">
-                ''' + b_text + '''
-                <form method="post">
-                    <input placeholder="''' + load_lang('email') + '''" name="email" type="text">
+            return easy_minify(flask.render_template(skin_check(),
+                imp = [load_lang('email'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
+                data = '''
+                    <a href="/email_filter">(''' + load_lang('email_filter_list') + ''')</a>
                     <hr class="main_hr">
-                    <button type="submit">''' + load_lang('save') + '''</button>
-                </form>
-            ''',
-            menu = [['user', load_lang('return')]]
-        ))
+                    ''' + b_text + '''
+                    <form method="post">
+                        <input placeholder="''' + load_lang('email') + '''" name="email" type="text">
+                        <hr class="main_hr">
+                        <button type="submit">''' + load_lang('save') + '''</button>
+                    </form>
+                ''',
+                menu = [['user', load_lang('return')]]
+            ))

+ 43 - 42
route/login_register_email_check.py

@@ -1,47 +1,48 @@
 from .tool.func import *
 
-def login_register_email_check_2(conn):
-    curs = conn.cursor()
+def login_register_email_check_2():
+    with get_db_connect() as conn:
+        curs = conn.cursor()
 
-    if not 'reg_email' in flask.session:
-        return redirect('/register')
-    
-    if  flask.request.method == 'POST':
-        input_key = flask.request.form.get('key', '')
-
-        if flask.session['reg_key'] != input_key:
+        if not 'reg_email' in flask.session:
             return redirect('/register')
 
-        curs.execute(db_change('select data from other where name = "requires_approval"'))
-        sql_data = curs.fetchall()
-        if sql_data and sql_data[0][0] != '':
-            flask.session['submit_id'] = flask.session['reg_id']
-            flask.session['submit_pw'] = flask.session['reg_pw']
-            flask.session['submit_email'] = flask.session['reg_email']
-            
-            return redirect('/register/submit')
-        
-        add_user(
-            flask.session['reg_id'],
-            flask.session['reg_pw'],
-            flask.session['reg_email']
-        )
-
-        return redirect('/login')
-    else:
-        curs.execute(db_change('select data from other where name = "check_key_text"'))
-        sql_d = curs.fetchall()
-        b_text = (sql_d[0][0] + '<hr class="main_hr">') if sql_d and sql_d[0][0] != '' else ''
-
-        return easy_minify(flask.render_template(skin_check(),
-            imp = [load_lang('check_key'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
-            data = '''
-                <form method="post">
-                    ''' + b_text + '''
-                    <input placeholder="''' + load_lang('key') + '''" name="key" type="text">
-                    <hr class="main_hr">
-                    <button type="submit">''' + load_lang('save') + '''</button>
-                </form>
-            ''',
-            menu = [['user', load_lang('return')]]
-        ))
+        if  flask.request.method == 'POST':
+            input_key = flask.request.form.get('key', '')
+
+            if flask.session['reg_key'] != input_key:
+                return redirect('/register')
+
+            curs.execute(db_change('select data from other where name = "requires_approval"'))
+            sql_data = curs.fetchall()
+            if sql_data and sql_data[0][0] != '':
+                flask.session['submit_id'] = flask.session['reg_id']
+                flask.session['submit_pw'] = flask.session['reg_pw']
+                flask.session['submit_email'] = flask.session['reg_email']
+
+                return redirect('/register/submit')
+
+            add_user(
+                flask.session['reg_id'],
+                flask.session['reg_pw'],
+                flask.session['reg_email']
+            )
+
+            return redirect('/login')
+        else:
+            curs.execute(db_change('select data from other where name = "check_key_text"'))
+            sql_d = curs.fetchall()
+            b_text = (sql_d[0][0] + '<hr class="main_hr">') if sql_d and sql_d[0][0] != '' else ''
+
+            return easy_minify(flask.render_template(skin_check(),
+                imp = [load_lang('check_key'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
+                data = '''
+                    <form method="post">
+                        ''' + b_text + '''
+                        <input placeholder="''' + load_lang('key') + '''" name="key" type="text">
+                        <hr class="main_hr">
+                        <button type="submit">''' + load_lang('save') + '''</button>
+                    </form>
+                ''',
+                menu = [['user', load_lang('return')]]
+            ))

+ 56 - 57
route/login_register_submit.py

@@ -1,61 +1,60 @@
 from .tool.func import *
 
-from .tool.func import *
+def login_register_submit_2():
+    with get_db_connect() as conn:
+        curs = conn.cursor()
+
+        if not 'submit_id' in flask.session:
+            return redirect('/register')
+
+        curs.execute(db_change('select data from other where name = "approval_question"'))
+        sql_data = curs.fetchall()
+        if not sql_data:
+            return redirect('/register')
+
+        data_que = sql_data[0][0]
+
+        if flask.request.method == 'POST':
+            curs.execute(db_change('select data from other where name = "encode"'))
+            data_encode = curs.fetchall()
+            data_encode = data_encode[0][0]
+
+            user_ip = ip_check()
+            user_agent = flask.request.headers.get('User-Agent', '')
+
+            user_app_data = {}
+            user_app_data['id'] = flask.session['submit_id']
+            user_app_data['pw'] = pw_encode(flask.session['submit_pw'])
+            user_app_data['encode'] = data_encode
+            user_app_data['question'] = data_que
+            user_app_data['answer'] = flask.request.form.get('answer', '')
+
+            if 'submit_email' in flask.session:
+                user_app_data['email'] = flask.session['submit_email']
+            else:
+                user_app_data['email'] = ''
+
+            curs.execute(db_change(
+                "insert into user_set (id, name, data) values (?, ?, ?)"
+            ), [
+                flask.session['submit_id'],
+                'application',
+                json.dumps(user_app_data)
+            ])
+            conn.commit()
 
-def login_register_submit_2(conn):
-    curs = conn.cursor()
-    
-    if not 'submit_id' in flask.session:
-        return redirect('/register')
-    
-    curs.execute(db_change('select data from other where name = "approval_question"'))
-    sql_data = curs.fetchall()
-    if not sql_data:
-        return redirect('/register')
-    
-    data_que = sql_data[0][0]
-    
-    if flask.request.method == 'POST':
-        curs.execute(db_change('select data from other where name = "encode"'))
-        data_encode = curs.fetchall()
-        data_encode = data_encode[0][0]
-        
-        user_ip = ip_check()
-        user_agent = flask.request.headers.get('User-Agent', '')
-        
-        user_app_data = {}
-        user_app_data['id'] = flask.session['submit_id']
-        user_app_data['pw'] = pw_encode(flask.session['submit_pw'])
-        user_app_data['encode'] = data_encode
-        user_app_data['question'] = data_que
-        user_app_data['answer'] = flask.request.form.get('answer', '')
-        
-        if 'submit_email' in flask.session:
-            user_app_data['email'] = flask.session['submit_email']
+            return redirect('/')
         else:
-            user_app_data['email'] = ''
-            
-        curs.execute(db_change(
-            "insert into user_set (id, name, data) values (?, ?, ?)"
-        ), [
-            flask.session['submit_id'],
-            'application',
-            json.dumps(user_app_data)
-        ])
-        conn.commit()
-        
-        return redirect('/')
-    else:
-        return easy_minify(flask.render_template(skin_check(),
-            imp = [load_lang('approval_question'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
-            data = '''
-                <form method="post">
-                    ''' + load_lang('approval_question') + ' : ' + data_que + '''
-                    <hr class="main_hr">
-                    <input placeholder="''' + load_lang('approval_question') + '''" name="answer">
-                    <hr class="main_hr">
-                    <button type="submit">''' + load_lang('save') + '''</button>
-                </form>
-            ''',
-            menu = [['user', load_lang('return')]]
-        ))
+            return easy_minify(flask.render_template(skin_check(),
+                imp = [load_lang('approval_question'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
+                data = '''
+                    <form method="post">
+                        ''' + load_lang('approval_question') + ' : ' + data_que + '''
+                        <hr class="main_hr">
+                        <input placeholder="''' + load_lang('approval_question') + '''" name="answer">
+                        <hr class="main_hr">
+                        <button type="submit">''' + load_lang('save') + '''</button>
+                    </form>
+                ''',
+                menu = [['user', load_lang('return')]]
+            ))

+ 3 - 1
route/main_sys_shutdown.py

@@ -6,9 +6,11 @@ def main_sys_shutdown():
 
     if flask.request.method == 'POST':
         admin_check(None, 'shutdown')
+        
+        conn.commit()
 
         print('----')
-        print('shutdown')
+        print('Shutdown')
 
         os._exit(os.EX_OK)
     else:

+ 138 - 137
route/recent_app_submit.py

@@ -1,145 +1,146 @@
 from .tool.func import *
 
-def recent_app_submit_2(conn):
-    curs = conn.cursor()
-
-    div = ''
-
-    curs.execute(db_change('select data from other where name = "requires_approval"'))
-    requires_approval = curs.fetchall()
-    if requires_approval and requires_approval[0][0] != 'on':
-        div += load_lang('approval_requirement_disabled')
-
-    if flask.request.method == 'GET':
-        curs.execute(db_change(
-            'select data from user_set where name = "application"'
-        ))
-        db_data = curs.fetchall()
-        if db_data:
-            div += '' + \
-                load_lang('all_register_num') + ' : ' + str(len(db_data)) + \
-                '<hr class="main_hr">' + \
-            ''
-            
-            div += '''
-                <table id="main_table_set">
-                    <tr id="main_table_top_tr">
-                        <td id="main_table_width_half">''' + load_lang('id') + '''</td>
-                        <td id="main_table_width_half">''' + load_lang('email') + '''</td>
-                    </tr>
-                    <tr id="main_table_top_tr">
-                        <td>''' + load_lang('approval_question') + '''</td>
-                        <td>''' + load_lang('answer') + '''</td>
-                    </tr>                        
-            '''
-
-            for application in db_data:
-                application = json.loads(application[0])
-                
-                if 'question' in application:
-                    question = html.escape(application['question'])
-                    question = question if question != '' else '<br>'
-                else:
-                    question = '<br>'
-                    
-                if 'answer' in application:
-                    answer = html.escape(application['answer'])
-                    answer = answer if answer != '' else '<br>'
-                else:
-                    answer = '<br>'
-                    
-                    
-                if 'email' in application:
-                    email = html.escape(application['email'])
-                    email = email if email != '' else '<br>'
-                else:
-                    email = '<br>'
-                
+def recent_app_submit_2():
+    with get_db_connect() as conn:
+        curs = conn.cursor()
+
+        div = ''
+
+        curs.execute(db_change('select data from other where name = "requires_approval"'))
+        requires_approval = curs.fetchall()
+        if requires_approval and requires_approval[0][0] != 'on':
+            div += load_lang('approval_requirement_disabled')
+
+        if flask.request.method == 'GET':
+            curs.execute(db_change(
+                'select data from user_set where name = "application"'
+            ))
+            db_data = curs.fetchall()
+            if db_data:
+                div += '' + \
+                    load_lang('all_register_num') + ' : ' + str(len(db_data)) + \
+                    '<hr class="main_hr">' + \
+                ''
+
                 div += '''
-                    <form method="post">
-                        <tr>
-                            <td>''' + application['id'] + '''</td>
-                            <td>''' + email + '''</td>
+                    <table id="main_table_set">
+                        <tr id="main_table_top_tr">
+                            <td id="main_table_width_half">''' + load_lang('id') + '''</td>
+                            <td id="main_table_width_half">''' + load_lang('email') + '''</td>
                         </tr>
-                        <tr>
-                            <td>''' + question + '''</td>
-                            <td>''' + answer + '''</td>
-                        </tr>
-                        <tr>
-                            <td colspan="3">
-                                <button type="submit" 
-                                        id="save"
-                                        name="approve" 
-                                        value="''' + application['id'] + '''">
-                                    ''' + load_lang('approve') + '''
-                                </button>
-                                <button type="submit" 
-                                        name="decline" 
-                                        value="''' + application['id'] + '''">
-                                    ''' + load_lang('decline') + '''
-                                </button>
-                            </td>
-                        </tr>
-                    </form>
+                        <tr id="main_table_top_tr">
+                            <td>''' + load_lang('approval_question') + '''</td>
+                            <td>''' + load_lang('answer') + '''</td>
+                        </tr>                        
                 '''
-                
-            div += '</table>'
-        else:
-            div += load_lang('no_applications_now')
-
-        return easy_minify(flask.render_template(skin_check(),
-            imp = [load_lang('application_list'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
-            data = div,
-            menu = [['other', load_lang('return')]]
-        ))
-    else:
-        if admin_check(None, 'app submit') != 1:
-            return re_error('/ban')
-        
-        if flask.request.form.get('approve', '') != '':
-            curs.execute(db_change(
-                'select data from user_set where id = ? and name = "application"'
-            ), [
-                flask.request.form.get('approve', '')
-            ])
-            application = curs.fetchall()
-            if not application:
-                return re_error('/error/26')
+
+                for application in db_data:
+                    application = json.loads(application[0])
+
+                    if 'question' in application:
+                        question = html.escape(application['question'])
+                        question = question if question != '' else '<br>'
+                    else:
+                        question = '<br>'
+
+                    if 'answer' in application:
+                        answer = html.escape(application['answer'])
+                        answer = answer if answer != '' else '<br>'
+                    else:
+                        answer = '<br>'
+
+
+                    if 'email' in application:
+                        email = html.escape(application['email'])
+                        email = email if email != '' else '<br>'
+                    else:
+                        email = '<br>'
+
+                    div += '''
+                        <form method="post">
+                            <tr>
+                                <td>''' + application['id'] + '''</td>
+                                <td>''' + email + '''</td>
+                            </tr>
+                            <tr>
+                                <td>''' + question + '''</td>
+                                <td>''' + answer + '''</td>
+                            </tr>
+                            <tr>
+                                <td colspan="3">
+                                    <button type="submit" 
+                                            id="save"
+                                            name="approve" 
+                                            value="''' + application['id'] + '''">
+                                        ''' + load_lang('approve') + '''
+                                    </button>
+                                    <button type="submit" 
+                                            name="decline" 
+                                            value="''' + application['id'] + '''">
+                                        ''' + load_lang('decline') + '''
+                                    </button>
+                                </td>
+                            </tr>
+                        </form>
+                    '''
+
+                div += '</table>'
             else:
-                application = json.loads(application[0][0])
-            
-            add_user(
-                application['id'], 
-                application['pw'],
-                application['email'],
-                application['encode']
-            )
+                div += load_lang('no_applications_now')
 
-            curs.execute(db_change(
-                "insert into user_set (name, id, data) values ('approval_question', ?, ?)"
-            ), [
-                application['id'], 
-                application['question']
-            ])
-            curs.execute(db_change(
-                "insert into user_set (name, id, data) values ('approval_question_answer', ?, ?)"
-            ), [
-                application['id'], 
-                application['answer']
-            ])
-            
-            curs.execute(db_change(
-                'delete from user_set where id = ? and name = "application"'
-            ), [
-                application['id']
-            ])
-            conn.commit()
-        elif flask.request.form.get('decline', '') != '':
-            curs.execute(db_change(
-                'delete from user_set where id = ? and name = "application"'
-            ), [
-                flask.request.form.get('decline', '')
-            ])
-            conn.commit()
+            return easy_minify(flask.render_template(skin_check(),
+                imp = [load_lang('application_list'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
+                data = div,
+                menu = [['other', load_lang('return')]]
+            ))
+        else:
+            if admin_check(None, 'app submit') != 1:
+                return re_error('/ban')
+
+            if flask.request.form.get('approve', '') != '':
+                curs.execute(db_change(
+                    'select data from user_set where id = ? and name = "application"'
+                ), [
+                    flask.request.form.get('approve', '')
+                ])
+                application = curs.fetchall()
+                if not application:
+                    return re_error('/error/26')
+                else:
+                    application = json.loads(application[0][0])
+
+                add_user(
+                    application['id'], 
+                    application['pw'],
+                    application['email'],
+                    application['encode']
+                )
+
+                curs.execute(db_change(
+                    "insert into user_set (name, id, data) values ('approval_question', ?, ?)"
+                ), [
+                    application['id'], 
+                    application['question']
+                ])
+                curs.execute(db_change(
+                    "insert into user_set (name, id, data) values ('approval_question_answer', ?, ?)"
+                ), [
+                    application['id'], 
+                    application['answer']
+                ])
+
+                curs.execute(db_change(
+                    'delete from user_set where id = ? and name = "application"'
+                ), [
+                    application['id']
+                ])
+                conn.commit()
+            elif flask.request.form.get('decline', '') != '':
+                curs.execute(db_change(
+                    'delete from user_set where id = ? and name = "application"'
+                ), [
+                    flask.request.form.get('decline', '')
+                ])
+                conn.commit()
 
-        return redirect('/app_submit')
+            return redirect('/app_submit')

+ 130 - 129
route/recent_block.py

@@ -1,150 +1,151 @@
 from .tool.func import *
 
-def recent_block_2(conn, name, tool):
-    curs = conn.cursor()
-
-    num = int(number_check(flask.request.args.get('num', '1')))
-    sql_num = (num * 50 - 50) if num * 50 > 0 else 0
-
-    div = '''
-        <table id="main_table_set">
-            <tbody>
-                <tr id="main_table_top_tr">
-                    <td id="main_table_width">''' + load_lang('blocked') + '''</td>
-                    <td id="main_table_width">''' + load_lang('admin') + '''</td>
-                    <td id="main_table_width">''' + load_lang('period') + '''</td>
-                </tr>
-    '''
-
-    curs.execute(db_change("update rb set ongoing = '' where end < ? and end != '' and ongoing = '1'"), [get_time()])
-    conn.commit()
+def recent_block_2(name, tool):
+    with get_db_connect() as conn:
+        curs = conn.cursor()
+
+        num = int(number_check(flask.request.args.get('num', '1')))
+        sql_num = (num * 50 - 50) if num * 50 > 0 else 0
+
+        div = '''
+            <table id="main_table_set">
+                <tbody>
+                    <tr id="main_table_top_tr">
+                        <td id="main_table_width">''' + load_lang('blocked') + '''</td>
+                        <td id="main_table_width">''' + load_lang('admin') + '''</td>
+                        <td id="main_table_width">''' + load_lang('period') + '''</td>
+                    </tr>
+        '''
 
-    get_type = flask.request.args.get('type', '')
-    sub_type = flask.request.args.get('s_type', '')
-    if tool == 'all':
-        if get_type == 'ongoing':
-            sub = ' (' + load_lang('in_progress') + ')'
+        curs.execute(db_change("update rb set ongoing = '' where end < ? and end != '' and ongoing = '1'"), [get_time()])
+        conn.commit()
+
+        get_type = flask.request.args.get('type', '')
+        sub_type = flask.request.args.get('s_type', '')
+        if tool == 'all':
+            if get_type == 'ongoing':
+                sub = ' (' + load_lang('in_progress') + ')'
+
+                if sub_type == '':
+                    div = '' + \
+                        '<a href="?type=ongoing&s_type=regex">(' + load_lang('regex') + ')</a> ' + \
+                        '<a href="?type=ongoing&s_type=normal">(' + load_lang('normal') + ')</a>' + \
+                        '<hr class="main_hr">' + \
+                    '' + div
+                    menu = [['block_log', load_lang('return')]]
+                    plus_sql = ''
+                else:
+                    menu = [['block_log?type=ongoing', load_lang('return')]]
+
+                    if sub_type == 'regex':
+                        sub += ' (' + load_lang('regex') + ')'
+                        plus_sql = 'and band = \'regex\' '
+                    else:
+                        sub += ' (' + load_lang('normal') + ')'
+                        plus_sql = 'and band = \'\' '
+
+                curs.execute(db_change("" + \
+                    "select why, block, blocker, end, today, band, ongoing from rb " + \
+                    "where ((end > ? and end like '2%') or end = '') and ongoing = '1' " + plus_sql + \
+                    "order by end desc limit ?, 50" + \
+                ""), [
+                    get_time(),
+                    sql_num
+                ])
+            else:
+                sub = 0
+                menu = 0
 
-            if sub_type == '':
                 div = '' + \
-                    '<a href="?type=ongoing&s_type=regex">(' + load_lang('regex') + ')</a> ' + \
-                    '<a href="?type=ongoing&s_type=normal">(' + load_lang('normal') + ')</a>' + \
+                    '<a href="/manager/11">(' + load_lang('blocked') + ')</a> ' + \
+                    '<a href="/manager/12">(' + load_lang('admin') + ')</a> ' + \
+                    '<a href="?type=ongoing">(' + load_lang('in_progress') + ')</a>' + \
                     '<hr class="main_hr">' + \
                 '' + div
-                menu = [['block_log', load_lang('return')]]
-                plus_sql = ''
-            else:
-                menu = [['block_log?type=ongoing', load_lang('return')]]
-                
-                if sub_type == 'regex':
-                    sub += ' (' + load_lang('regex') + ')'
-                    plus_sql = 'and band = \'regex\' '
-                else:
-                    sub += ' (' + load_lang('normal') + ')'
-                    plus_sql = 'and band = \'\' '
+
+                curs.execute(db_change("" + \
+                    "select why, block, blocker, end, today, band, ongoing " + \
+                    "from rb order by today desc limit ?, 50" + \
+                ""), [sql_num])
+        elif tool == 'user':
+            sub = ' (' + load_lang('blocked') + ')'
+            menu = [['block_log', load_lang('normal')]]
 
             curs.execute(db_change("" + \
-                "select why, block, blocker, end, today, band, ongoing from rb " + \
-                "where ((end > ? and end like '2%') or end = '') and ongoing = '1' " + plus_sql + \
-                "order by end desc limit ?, 50" + \
+                "select why, block, blocker, end, today, band, ongoing " + \
+                "from rb where block = ? order by today desc limit ?, 50" + \
             ""), [
-                get_time(),
+                name, 
                 sql_num
             ])
         else:
-            sub = 0
-            menu = 0
-
-            div = '' + \
-                '<a href="/manager/11">(' + load_lang('blocked') + ')</a> ' + \
-                '<a href="/manager/12">(' + load_lang('admin') + ')</a> ' + \
-                '<a href="?type=ongoing">(' + load_lang('in_progress') + ')</a>' + \
-                '<hr class="main_hr">' + \
-            '' + div
+            sub = ' (' + load_lang('admin') + ')'
+            menu = [['block_log', load_lang('normal')]]
 
             curs.execute(db_change("" + \
                 "select why, block, blocker, end, today, band, ongoing " + \
-                "from rb order by today desc limit ?, 50" + \
-            ""), [sql_num])
-    elif tool == 'user':
-        sub = ' (' + load_lang('blocked') + ')'
-        menu = [['block_log', load_lang('normal')]]
-
-        curs.execute(db_change("" + \
-            "select why, block, blocker, end, today, band, ongoing " + \
-            "from rb where block = ? order by today desc limit ?, 50" + \
-        ""), [
-            name, 
-            sql_num
-        ])
-    else:
-        sub = ' (' + load_lang('admin') + ')'
-        menu = [['block_log', load_lang('normal')]]
-
-        curs.execute(db_change("" + \
-            "select why, block, blocker, end, today, band, ongoing " + \
-            "from rb where blocker = ? order by today desc limit ?, 50" + \
-        ""), [
-            name, 
-            sql_num
-        ])
-
-    data_list = curs.fetchall()
-    all_ip = ip_pas([i[1] for i in data_list] + [i[2] for i in data_list])
-    for data in data_list:
-        why = '<br>' if data[0] == '' else html.escape(data[0])
-
-        if data[5] == 'regex':
-            ip = data[1]
-            if data[6] == '1':
-                ip = '<s>' + ip + '</s> <a href="/auth/give/ban_regex/' + url_pas(data[1]) + '">(' + load_lang('release') + ')</a>'
+                "from rb where blocker = ? order by today desc limit ?, 50" + \
+            ""), [
+                name, 
+                sql_num
+            ])
+
+        data_list = curs.fetchall()
+        all_ip = ip_pas([i[1] for i in data_list] + [i[2] for i in data_list])
+        for data in data_list:
+            why = '<br>' if data[0] == '' else html.escape(data[0])
+
+            if data[5] == 'regex':
+                ip = data[1]
+                if data[6] == '1':
+                    ip = '<s>' + ip + '</s> <a href="/auth/give/ban_regex/' + url_pas(data[1]) + '">(' + load_lang('release') + ')</a>'
+                else:
+                    ip += ' <a href="/auth/give/ban_regex/' + url_pas(data[1]) + '">(' + load_lang('ban') + ')</a>'
+
+                ip += ' (' + load_lang('regex') + ')'
             else:
-                ip += ' <a href="/auth/give/ban_regex/' + url_pas(data[1]) + '">(' + load_lang('ban') + ')</a>'
-                
-            ip += ' (' + load_lang('regex') + ')'
-        else:
-            ip = all_ip[data[1]]
+                ip = all_ip[data[1]]
 
-        if data[3] == '':
-            end = load_lang('limitless')
-        elif data[3] == 'release':
-            end = load_lang('release')
-        else:
-            end = data[3]
+            if data[3] == '':
+                end = load_lang('limitless')
+            elif data[3] == 'release':
+                end = load_lang('release')
+            else:
+                end = data[3]
 
-        if data[2] == '':
-            admin = ''
-        elif re.search(r'^tool:', data[2]):
-            admin = data[2]
+            if data[2] == '':
+                admin = ''
+            elif re.search(r'^tool:', data[2]):
+                admin = data[2]
+            else:
+                admin = all_ip[data[2]]
+
+            start = load_lang('start') + ' : ' + (data[4] if data[4] != '' else '0')
+            div += '''
+                <tr>
+                    <td>''' + ip + '''</td>
+                    <td>''' + admin + '''</td>
+                    <td>
+                        ''' + start + '''
+                        <br>
+                        ''' + load_lang('end') + ' : ' + end + '''
+                    </td>
+                </tr>
+                <tr>
+                    <td colspan="3">''' + why + '''</td>
+                </tr>
+            '''
+
+        div += '</tbody>'
+        div += '</table>'
+
+        if tool == 'all':
+            div += next_fix('/block_log?num=', num, data_list)
         else:
-            admin = all_ip[data[2]]
-
-        start = load_lang('start') + ' : ' + (data[4] if data[4] != '' else '0')
-        div += '''
-            <tr>
-                <td>''' + ip + '''</td>
-                <td>''' + admin + '''</td>
-                <td>
-                    ''' + start + '''
-                    <br>
-                    ''' + load_lang('end') + ' : ' + end + '''
-                </td>
-            </tr>
-            <tr>
-                <td colspan="3">''' + why + '''</td>
-            </tr>
-        '''
+            div += next_fix('/block_log/' + url_pas(tool) + '/' + url_pas(name) + '?num=', num, data_list)
 
-    div += '</tbody>'
-    div += '</table>'
-    
-    if tool == 'all':
-        div += next_fix('/block_log?num=', num, data_list)
-    else:
-        div += next_fix('/block_log/' + url_pas(tool) + '/' + url_pas(name) + '?num=', num, data_list)
-
-    return easy_minify(flask.render_template(skin_check(),
-        imp = [load_lang('recent_ban'), wiki_set(), wiki_custom(), wiki_css([sub, 0])],
-        data = div,
-        menu = menu
-    ))
+        return easy_minify(flask.render_template(skin_check(),
+            imp = [load_lang('recent_ban'), wiki_set(), wiki_custom(), wiki_css([sub, 0])],
+            data = div,
+            menu = menu
+        ))

+ 60 - 59
route/user_setting_email.py

@@ -1,75 +1,76 @@
 from .tool.func import *
 
-def user_setting_email_2(conn):
-    curs = conn.cursor()
-    
-    ip = ip_check()
-    if ip_or_user(ip) != 0:
-        return redirect('/login')
-    
-    if flask.request.method == 'POST':
-        # c_key 같은 이름 대신 한 기능에 고유 명칭 부여 필요
-        re_set_list = ['c_key']
-        flask.session['c_key'] = load_random_key(32)
+def user_setting_email_2():
+    with get_db_connect() as conn:
+        curs = conn.cursor()
 
-        user_email = re.sub(r'\\', '', flask.request.form.get('email', ''))
-        email_data = re.search(r'@([^@]+)$', user_email)
-        if email_data:
-            curs.execute(db_change("select html from html_filter where html = ? and kind = 'email'"), [email_data.group(1)])
-            if not curs.fetchall():
+        ip = ip_check()
+        if ip_or_user(ip) != 0:
+            return redirect('/login')
+
+        if flask.request.method == 'POST':
+            # c_key 같은 이름 대신 한 기능에 고유 명칭 부여 필요
+            re_set_list = ['c_key']
+            flask.session['c_key'] = load_random_key(32)
+
+            user_email = re.sub(r'\\', '', flask.request.form.get('email', ''))
+            email_data = re.search(r'@([^@]+)$', user_email)
+            if email_data:
+                curs.execute(db_change("select html from html_filter where html = ? and kind = 'email'"), [email_data.group(1)])
+                if not curs.fetchall():
+                    for i in re_set_list:
+                        flask.session.pop(i, None)
+
+                    return redirect('/email_filter')
+            else:
                 for i in re_set_list:
                     flask.session.pop(i, None)
 
-                return redirect('/email_filter')
-        else:
-            for i in re_set_list:
-                flask.session.pop(i, None)
+                return re_error('/error/36')
 
-            return re_error('/error/36')
+            curs.execute(db_change('select data from other where name = "email_title"'))
+            sql_d = curs.fetchall()
+            t_text = html.escape(sql_d[0][0]) if sql_d and sql_d[0][0] != '' else (wiki_set()[0] + ' key')
 
-        curs.execute(db_change('select data from other where name = "email_title"'))
-        sql_d = curs.fetchall()
-        t_text = html.escape(sql_d[0][0]) if sql_d and sql_d[0][0] != '' else (wiki_set()[0] + ' key')
+            curs.execute(db_change('select data from other where name = "email_text"'))
+            sql_d = curs.fetchall()
+            if sql_d and sql_d[0][0] != '':
+                i_text = html.escape(sql_d[0][0]) + '\n\nKey : ' + flask.session['c_key']
+            else:
+                i_text = 'Key : ' + flask.session['c_key']
 
-        curs.execute(db_change('select data from other where name = "email_text"'))
-        sql_d = curs.fetchall()
-        if sql_d and sql_d[0][0] != '':
-            i_text = html.escape(sql_d[0][0]) + '\n\nKey : ' + flask.session['c_key']
-        else:
-            i_text = 'Key : ' + flask.session['c_key']
-        
-        curs.execute(db_change('select id from user_set where name = "email" and data = ?'), [user_email])
-        if curs.fetchall():
-            for i in re_set_list:
-                flask.session.pop(i, None)
+            curs.execute(db_change('select id from user_set where name = "email" and data = ?'), [user_email])
+            if curs.fetchall():
+                for i in re_set_list:
+                    flask.session.pop(i, None)
 
-            return re_error('/error/35')
+                return re_error('/error/35')
 
-        if send_email(user_email, t_text, i_text) == 0:
-            for i in re_set_list:
-                flask.session.pop(i, None)
+            if send_email(user_email, t_text, i_text) == 0:
+                for i in re_set_list:
+                    flask.session.pop(i, None)
 
-            return re_error('/error/18')
+                return re_error('/error/18')
 
-        flask.session['c_email'] = user_email
+            flask.session['c_email'] = user_email
 
-        return redirect('/change/email/check')
-    else:
-        curs.execute(db_change('select data from other where name = "email_insert_text"'))
-        sql_d = curs.fetchall()
-        b_text = (sql_d[0][0] + '<hr class="main_hr">') if sql_d and sql_d[0][0] != '' else ''
+            return redirect('/change/email/check')
+        else:
+            curs.execute(db_change('select data from other where name = "email_insert_text"'))
+            sql_d = curs.fetchall()
+            b_text = (sql_d[0][0] + '<hr class="main_hr">') if sql_d and sql_d[0][0] != '' else ''
 
-        return easy_minify(flask.render_template(skin_check(),
-            imp = [load_lang('email'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
-            data = '''
-                <a href="/email_filter">(''' + load_lang('email_filter_list') + ''')</a>
-                <hr class="main_hr">
-                ''' + b_text + '''
-                <form method="post">
-                    <input placeholder="''' + load_lang('email') + '''" name="email" type="text">
+            return easy_minify(flask.render_template(skin_check(),
+                imp = [load_lang('email'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
+                data = '''
+                    <a href="/email_filter">(''' + load_lang('email_filter_list') + ''')</a>
                     <hr class="main_hr">
-                    <button type="submit">''' + load_lang('save') + '''</button>
-                </form>
-            ''',
-            menu = [['user', load_lang('return')]]
-        ))
+                    ''' + b_text + '''
+                    <form method="post">
+                        <input placeholder="''' + load_lang('email') + '''" name="email" type="text">
+                        <hr class="main_hr">
+                        <button type="submit">''' + load_lang('save') + '''</button>
+                    </form>
+                ''',
+                menu = [['user', load_lang('return')]]
+            ))

+ 43 - 42
route/user_setting_email_check.py

@@ -1,45 +1,46 @@
 from .tool.func import *
 
-def user_setting_email_check_2(conn):
-    curs = conn.cursor()
-    
-    ip = ip_check()
-    if ip_or_user(ip) != 0:
-        return redirect('/login')
-
-    re_set_list = ['c_key', 'c_email']
-    if  not 'c_key' in flask.session or \
-        not 'c_email' in flask.session:
-        for i in re_set_list:
-            flask.session.pop(i, None)
-    
-    if  flask.request.method == 'POST':
+def user_setting_email_check_2():
+    with get_db_connect() as conn:
+        curs = conn.cursor()
+
         ip = ip_check()
-        input_key = flask.request.form.get('key', '')
-        user_agent = flask.request.headers.get('User-Agent', '')
-
-        if flask.session['c_key'] == input_key:
-            curs.execute(db_change('delete from user_set where name = "email" and id = ?'), [ip])
-            curs.execute(db_change('insert into user_set (name, id, data) values ("email", ?, ?)'), [ip, flask.session['c_email']])
-
-        for i in re_set_list:
-            flask.session.pop(i, None)
-
-        return redirect('/change')
-    else:
-        curs.execute(db_change('select data from other where name = "check_key_text"'))
-        sql_d = curs.fetchall()
-        b_text = (sql_d[0][0] + '<hr class="main_hr">') if sql_d and sql_d[0][0] != '' else ''
-
-        return easy_minify(flask.render_template(skin_check(),
-            imp = [load_lang('check_key'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
-            data = '''
-                <form method="post">
-                    ''' + b_text + '''
-                    <input placeholder="''' + load_lang('key') + '''" name="key" type="text">
-                    <hr class="main_hr">
-                    <button type="submit">''' + load_lang('save') + '''</button>
-                </form>
-            ''',
-            menu = [['user', load_lang('return')]]
-        ))
+        if ip_or_user(ip) != 0:
+            return redirect('/login')
+
+        re_set_list = ['c_key', 'c_email']
+        if  not 'c_key' in flask.session or \
+            not 'c_email' in flask.session:
+            for i in re_set_list:
+                flask.session.pop(i, None)
+
+        if  flask.request.method == 'POST':
+            ip = ip_check()
+            input_key = flask.request.form.get('key', '')
+            user_agent = flask.request.headers.get('User-Agent', '')
+
+            if flask.session['c_key'] == input_key:
+                curs.execute(db_change('delete from user_set where name = "email" and id = ?'), [ip])
+                curs.execute(db_change('insert into user_set (name, id, data) values ("email", ?, ?)'), [ip, flask.session['c_email']])
+
+            for i in re_set_list:
+                flask.session.pop(i, None)
+
+            return redirect('/change')
+        else:
+            curs.execute(db_change('select data from other where name = "check_key_text"'))
+            sql_d = curs.fetchall()
+            b_text = (sql_d[0][0] + '<hr class="main_hr">') if sql_d and sql_d[0][0] != '' else ''
+
+            return easy_minify(flask.render_template(skin_check(),
+                imp = [load_lang('check_key'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
+                data = '''
+                    <form method="post">
+                        ''' + b_text + '''
+                        <input placeholder="''' + load_lang('key') + '''" name="key" type="text">
+                        <hr class="main_hr">
+                        <button type="submit">''' + load_lang('save') + '''</button>
+                    </form>
+                ''',
+                menu = [['user', load_lang('return')]]
+            ))

+ 1 - 1
version.json

@@ -1,6 +1,6 @@
 {
     "beta" : {
-        "r_ver" : "v3.4.5 (stable2) (beta3) (dev35)",
+        "r_ver" : "v3.4.5 (stable2) (beta3) (dev36)",
         "c_ver" : "3500113",
         "s_ver" : "3500110"
     }