# Init
import os
import sys
import platform
import smtplib
import shutil
import json
import datetime
import ipaddress
import subprocess
import email.mime.text
import email.utils
import email.header
# Init-Version
with open('version.json', encoding = 'utf8') as file_data:
version_list = json.loads(file_data.read())
print('Version : ' + version_list['beta']['r_ver'])
print('DB set version : ' + version_list['beta']['c_ver'])
print('Skin set version : ' + version_list['beta']['s_ver'])
# Init-PIP_Install
data_up_date = 1
if os.path.exists(os.path.join('data', 'version.json')):
with open(os.path.join('data', 'version.json'), encoding = 'utf8') as file_data:
data_load_ver = file_data.read()
if data_load_ver == version_list['beta']['r_ver']:
data_up_date = 0
if data_up_date == 1:
with open(os.path.join('data', 'version.json'), 'w', encoding = 'utf8') as f:
f.write(version_list['beta']['r_ver'])
if platform.system() in ('Linux', 'Windows'):
python_ver = ''
python_ver = str(sys.version_info.major) + '.' + str(sys.version_info.minor)
run_list = [sys.executable, 'python' + python_ver, 'python3', 'python', 'py -' + python_ver]
for exe_name in run_list:
try:
subprocess.check_call([exe_name, "-m", "pip", "install", "--upgrade", "--user", "-r", "requirements.txt"])
try:
os.execl(exe_name, sys.executable, *sys.argv)
except:
pass
try:
os.execl(exe_name, '"' + sys.executable + '"', *sys.argv)
except:
pass
try:
os.execl(exe_name, os.path.abspath(__file__), *sys.argv)
except:
pass
except:
pass
else:
print('Error : automatic installation is not supported.')
print('Help : try "python3 -m pip install -r requirements.txt"')
else:
print('Error : automatic installation is not supported.')
print('Help : try "python3 -m pip install -r requirements.txt"')
else:
print('PIP check pass')
# Init-Load
from .func_tool import *
from .func_render import class_do_render
from diff_match_patch import diff_match_patch
import werkzeug.routing
import werkzeug.debug
import flask
import asyncio
import requests
from PIL import Image
try:
import mysqlclient as pymysql
except:
import pymysql
if sys.version_info < (3, 6):
import sha3
# Func
# Func-main
original_render_template = flask.render_template
def custom_render_template(template_name_or_list, **context):
context['data'] = '
' + context['data'] + '
'
return original_render_template(template_name_or_list, **context)
flask.render_template = custom_render_template
def do_db_set(db_set):
with class_temp_db() as m_conn:
m_curs = m_conn.cursor()
m_curs.execute('drop table if exists temp')
m_curs.execute('create table if not exists temp(name text, data text)')
for for_a in db_set:
m_curs.execute('insert into temp (name, data) values (?, ?)', ['db_' + for_a, db_set[for_a]])
def python_to_golang_sync(func_name, other_set = {}):
if other_set == {}:
other_set = '{}'
else:
other_set = orjson.dumps(other_set)
if platform.system() == 'Linux':
if platform.machine() in ["AMD64", "x86_64"]:
cmd = [os.path.join(".", "route_go", "bin", "main.amd64.bin"), func_name, other_set]
else:
cmd = [os.path.join(".", "route_go", "bin", "main.arm64.bin"), func_name, other_set]
else:
if platform.machine() in ["AMD64", "x86_64"]:
cmd = [os.path.join(".", "route_go", "bin", "main.amd64.exe"), func_name, other_set]
else:
cmd = [os.path.join(".", "route_go", "bin", "main.arm64.exe"), func_name, other_set]
process = subprocess.Popen(
cmd,
stdout = subprocess.PIPE,
stderr = asyncio.subprocess.PIPE
)
stdout, stderr = process.communicate()
data = ''
while data == '':
data = stdout.decode('utf8')
err = stderr.decode('utf8')
if err != '':
if 'database is locked' in err:
pass
else:
print(err)
break
time.sleep(0.01)
if data == '':
data = '{}'
return data
async def python_to_golang(func_name, other_set = {}):
if other_set == {}:
other_set = '{}'
else:
other_set = orjson.dumps(other_set)
if platform.system() == 'Linux':
if platform.machine() in ["AMD64", "x86_64"]:
cmd = [os.path.join(".", "route_go", "bin", "main.amd64.bin"), func_name, other_set]
else:
cmd = [os.path.join(".", "route_go", "bin", "main.arm64.bin"), func_name, other_set]
else:
if platform.machine() in ["AMD64", "x86_64"]:
cmd = [os.path.join(".", "route_go", "bin", "main.amd64.exe"), func_name, other_set]
else:
cmd = [os.path.join(".", "route_go", "bin", "main.arm64.exe"), func_name, other_set]
process = await asyncio.create_subprocess_exec(
*cmd,
stdout = asyncio.subprocess.PIPE,
stderr = asyncio.subprocess.PIPE
)
stdout, stderr = await process.communicate()
data = ''
while data == '':
data = stdout.decode('utf8')
err = stderr.decode('utf8')
if err != '':
if 'database is locked' in err:
pass
else:
print(err)
break
await asyncio.sleep(0.01)
if data == '':
data = '{}'
return data
# Func-init
def get_init_set_list(need = 'all'):
init_set_list = {
'host' : {
'display' : 'Host',
'require' : 'conv',
'default' : '0.0.0.0'
}, 'port' : {
'display' : 'Port',
'require' : 'conv',
'default' : '3000'
}, 'language' : {
'display' : 'Language',
'require' : 'select',
'default' : 'ko-KR',
'list' : ['ko-KR', 'en-US']
}, 'markup' : {
'display' : 'Markup',
'require' : 'select',
'default' : 'namumark',
'list' : ['namumark', 'namumark_beta', 'markdown', 'custom', 'raw']
}, 'encode' : {
'display' : 'Encryption method',
'require' : 'select',
'default' : 'sha3',
'list' : ['sha3', 'sha3-salt', 'sha3-512', 'sha3-512-salt']
}
}
if need == 'all':
return init_set_list
else:
return init_set_list[need]
class get_db_connect:
def __init__(self, db_type = '', init_mode = False):
with class_temp_db() as m_conn:
m_curs = m_conn.cursor()
self.db_set = {}
self.init_mode = init_mode
m_curs.execute('select name, data from temp where name in ("db_type", "db_name")')
db_data = m_curs.fetchall()
for for_a in db_data:
self.db_set[for_a[0]] = for_a[1]
if db_type != '':
self.db_set['db_type'] = db_type
if self.db_set['db_type'] == 'mysql':
m_curs.execute('select name, data from temp where name in ("db_mysql_host", "db_mysql_user", "db_mysql_pw", "db_mysql_port")')
db_data = m_curs.fetchall()
for for_a in db_data:
self.db_set[for_a[0]] = for_a[1]
def __enter__(self):
if self.db_set['db_type'] == 'sqlite':
self.conn = sqlite3.connect(
self.db_set['db_name'] + '.db',
check_same_thread = False,
isolation_level = None
)
else:
if self.init_mode:
self.conn = pymysql.connect(
host = self.db_set['db_mysql_host'],
user = self.db_set['db_mysql_user'],
password = self.db_set['db_mysql_pw'],
charset = 'utf8mb4',
port = int(self.db_set['db_mysql_port']),
autocommit = True
)
else:
self.conn = pymysql.connect(
host = self.db_set['db_mysql_host'],
user = self.db_set['db_mysql_user'],
password = self.db_set['db_mysql_pw'],
charset = 'utf8mb4',
port = int(self.db_set['db_mysql_port']),
autocommit = True,
db = self.db_set['db_name']
)
return self.conn
def __exit__(self, exc_type, exc_value, traceback):
self.conn.commit()
self.conn.close()
# class get_whoosh_connect:
class class_check_json:
def do_check_set_json(self):
if os.getenv('NAMU_DB') or os.getenv('NAMU_DB_TYPE'):
set_data = {}
set_data['db'] = os.getenv('NAMU_DB') if os.getenv('NAMU_DB') else 'data'
set_data['db_type'] = os.getenv('NAMU_DB_TYPE') if os.getenv('NAMU_DB_TYPE') else 'sqlite'
else:
if os.path.exists(os.path.join('data', 'set.json')):
db_set_list = ['db', 'db_type']
with open(os.path.join('data', 'set.json'), encoding = 'utf8') as file_data:
set_data = orjson.loads(file_data.read())
for i in db_set_list:
if not i in set_data:
os.remove(os.path.join('data', 'set.json'))
break
if not os.path.exists(os.path.join('data', 'set.json')):
set_data = {}
normal_db_type = ['sqlite', 'mysql']
print('DB type (' + normal_db_type[0] + ') [' + ', '.join(normal_db_type) + '] : ', end = '')
data_get = str(input())
if data_get == '' or not data_get in normal_db_type:
set_data['db_type'] = 'sqlite'
else:
set_data['db_type'] = data_get
all_src = []
if set_data['db_type'] == 'sqlite':
for i_data in os.listdir("."):
f_src = re.search(r"(.+)\.db$", i_data)
if f_src:
all_src += [f_src.group(1)]
print('DB name (data) [' + ', '.join(all_src) + '] : ', end = '')
data_get = str(input())
if data_get == '':
set_data['db'] = 'data'
else:
set_data['db'] = data_get
with open(os.path.join('data', 'set.json'), 'w', encoding = 'utf8') as f:
f.write(orjson.dumps(set_data).decode('utf-8'))
print('DB name : ' + set_data['db'])
print('DB type : ' + set_data['db_type'])
data_db_set = {}
data_db_set['name'] = set_data['db']
data_db_set['type'] = set_data['db_type']
return data_db_set
def do_check_mysql_json(self, data_db_set):
if os.path.exists(os.path.join('data', 'mysql.json')):
db_set_list = ['user', 'password', 'host', 'port']
with open(os.path.join('data', 'mysql.json'), encoding = 'utf8') as file_data:
set_data = orjson.loads(file_data.read())
for i in db_set_list:
if not i in set_data:
os.remove(os.path.join('data', 'mysql.json'))
break
set_data_mysql = set_data
if not os.path.exists(os.path.join('data', 'mysql.json')):
set_data_mysql = {}
print('DB user ID : ', end = '')
set_data_mysql['user'] = str(input())
print('DB password : ', end = '')
set_data_mysql['password'] = str(input())
print('DB host (localhost) : ', end = '')
set_data_mysql['host'] = str(input())
if set_data_mysql['host'] == '':
set_data_mysql['host'] = 'localhost'
print('DB port (3306) : ', end = '')
set_data_mysql['port'] = str(input())
if set_data_mysql['port'] == '':
set_data_mysql['port'] = '3306'
with open(
os.path.join('data', 'mysql.json'),
'w',
encoding = 'utf8'
) as f:
f.write(orjson.dumps(set_data_mysql).decode('utf-8'))
data_db_set['mysql_user'] = set_data_mysql['user']
data_db_set['mysql_pw'] = set_data_mysql['password']
if 'host' in set_data_mysql:
data_db_set['mysql_host'] = set_data_mysql['host']
else:
data_db_set['mysql_host'] = 'localhost'
if 'port' in set_data_mysql:
data_db_set['mysql_port'] = set_data_mysql['port']
else:
data_db_set['mysql_port'] = '3306'
return data_db_set
def __init__(self):
self.data_db_set = {}
def __new__(cls):
instance = super().__new__(cls)
cls.data_db_set = instance.do_check_set_json()
if cls.data_db_set['type'] == 'mysql':
cls.data_db_set = instance.do_check_mysql_json(cls.data_db_set)
return cls.data_db_set
def get_db_table_list():
# DB table
# Init-Create_DB
# --이거 개편한다더니 도대체 언제?--
create_data = {}
# 폐지 예정 (data_set으로 통합)
create_data['data_set'] = ['doc_name', 'doc_rev', 'set_name', 'set_data']
create_data['data'] = ['title', 'data', 'type']
create_data['history'] = ['id', 'title', 'data', 'date', 'ip', 'send', 'leng', 'hide', 'type']
create_data['rc'] = ['id', 'title', 'date', 'type']
create_data['acl'] = ['title', 'data', 'type']
# 개편 예정 (data_link로 변경)
create_data['back'] = ['title', 'link', 'type', 'data']
# 폐지 예정 (topic_set으로 통합) [가장 시급]
create_data['topic_set'] = ['thread_code', 'set_name', 'set_id', 'set_data']
create_data['rd'] = ['title', 'sub', 'code', 'date', 'band', 'stop', 'agree', 'acl']
create_data['topic'] = ['id', 'data', 'date', 'ip', 'block', 'top', 'code']
# 폐지 예정 (user_set으로 통합)
create_data['rb'] = ['block', 'end', 'today', 'blocker', 'why', 'band', 'login', 'ongoing']
# 개편 예정 (wiki_set과 wiki_filter과 wiki_vote으로 변경)
create_data['other'] = ['name', 'data', 'coverage']
create_data['html_filter'] = ['html', 'kind', 'plus', 'plus_t']
create_data['vote'] = ['name', 'id', 'subject', 'data', 'user', 'type', 'acl']
# 개편 예정 (auth와 auth_log로 변경)
create_data['alist'] = ['name', 'acl']
create_data['re_admin'] = ['who', 'what', 'time']
# 개편 예정 (user_notice와 user_agent로 변경)
create_data['ua_d'] = ['name', 'ip', 'ua', 'today', 'sub']
create_data['user_set'] = ['name', 'id', 'data']
create_data['user_notice'] = ['id', 'name', 'data', 'date', 'readme']
create_data['bbs_set'] = ['set_name', 'set_code', 'set_id', 'set_data']
create_data['bbs_data'] = ['set_name', 'set_code', 'set_id', 'set_data']
return create_data
def update(conn, ver_num, set_data):
curs = conn.cursor()
# 업데이트 하위 호환 유지 함수
if ver_num < 3160027:
print('Add init set')
set_init(conn)
if ver_num < 3170002:
curs.execute(db_change("select html from html_filter where kind = 'extension'"))
if not curs.fetchall():
for i in ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg']:
curs.execute(db_change("insert into html_filter (html, kind) values (?, 'extension')"), [i])
if ver_num < 3170400:
curs.execute(db_change("select title, sub, code from topic where id = '1'"))
for i in curs.fetchall():
curs.execute(db_change("update topic set code = ? where title = ? and sub = ?"), [i[2], i[0], i[1]])
curs.execute(db_change("update rd set code = ? where title = ? and sub = ?"), [i[2], i[0], i[1]])
if ver_num < 3171800:
curs.execute(db_change("select data from other where name = 'recaptcha'"))
change_rec = curs.fetchall()
if change_rec and change_rec[0][0] != '':
new_rec = re.search(r'data-sitekey="([^"]+)"', change_rec[0][0])
if new_rec:
curs.execute(db_change("update other set data = ? where name = 'recaptcha'"), [new_rec.group(1)])
else:
curs.execute(db_change("update other set data = '' where name = 'recaptcha'"))
curs.execute(db_change("update other set data = '' where name = 'sec_re'"))
if ver_num < 3172800 and set_data['type'] == 'mysql':
get_data_mysql = orjson.loads(open('data/mysql.json', encoding = 'utf8').read())
with open('data/mysql.json', 'w') as f:
f.write('{ "user" : "' + get_data_mysql['user'] + '", "password" : "' + get_data_mysql['password'] + '", "host" : "localhost" }')
if ver_num < 3183603:
curs.execute(db_change("select block from ban where band = 'O'"))
for i in curs.fetchall():
curs.execute(db_change("update ban set block = ?, band = 'regex' where block = ? and band = 'O'"), ['^' + i[0].replace('.', '\\.'), i[0]])
curs.execute(db_change("select block from rb where band = 'O'"))
for i in curs.fetchall():
curs.execute(db_change("update rb set block = ?, band = 'regex' where block = ? and band = 'O'"), ['^' + i[0].replace('.', '\\.'), i[0]])
if ver_num < 3190201:
today_time = get_time()
curs.execute(db_change("select block, end, why, band, login from ban"))
for i in curs.fetchall():
curs.execute(db_change("insert into rb (block, end, today, why, band, login, ongoing) values (?, ?, ?, ?, ?, ?, ?)"), [i[0], i[1], today_time, i[2], i[3], i[4], '1'])
if ver_num < 3191301:
curs.execute(db_change('select id, title, date from history where not title like "user:%" order by date desc limit 50'))
data_list = curs.fetchall()
for get_data in data_list:
curs.execute(db_change("insert into rc (id, title, date, type) values (?, ?, ?, 'normal')"), [get_data[0], get_data[1], get_data[2]])
if ver_num < 3202400:
curs.execute(db_change("select data from other where name = 'update'"))
get_data = curs.fetchall()
if get_data and get_data[0][0] == 'master':
curs.execute(db_change("update other set data = 'beta' where name = 'update'"), [])
if ver_num < 3202600:
curs.execute(db_change("select name, regex, sub from filter"))
for i in curs.fetchall():
curs.execute(db_change("insert into html_filter (html, kind, plus, plus_t) values (?, 'regex_filter', ?, ?)"), [i[0], i[1], i[2]])
curs.execute(db_change("select title, link, icon from inter"))
for i in curs.fetchall():
curs.execute(db_change("insert into html_filter (html, kind, plus, plus_t) values (?, 'inter_wiki', ?, ?)"), [i[0], i[1], i[2]])
if ver_num < 3203400:
curs.execute(db_change("select user, css from custom"))
for i in curs.fetchall():
curs.execute(db_change("insert into user_set (name, id, data) values ('custom_css', ?, ?)"), [re.sub(r' \(head\)$', '', i[0]), i[1]])
if ver_num < 3205500:
curs.execute(db_change("select title, decu, dis, view, why from acl"))
for i in curs.fetchall():
curs.execute(db_change("insert into acl (title, data, type) values (?, ?, ?)"), [i[0], i[1], 'decu'])
curs.execute(db_change("insert into acl (title, data, type) values (?, ?, ?)"), [i[0], i[2], 'dis'])
curs.execute(db_change("insert into acl (title, data, type) values (?, ?, ?)"), [i[0], i[3], 'view'])
curs.execute(db_change("insert into acl (title, data, type) values (?, ?, ?)"), [i[0], i[4], 'why'])
if ver_num < 3300101:
# 캐시 초기화
curs.execute(db_change('delete from cache_data'))
if ver_num < 3300301:
# regex_filter 오류 해결
curs.execute(db_change('delete from html_filter where kind = "regex_filter" and html is null'))
if ver_num < 3302302:
# user이랑 user_set 테이블의 통합
curs.execute(db_change('select id, pw, acl, date, encode from user'))
for i in curs.fetchall():
curs.execute(db_change("insert into user_set (name, id, data) values (?, ?, ?)"), ['pw', i[0], i[1]])
curs.execute(db_change("insert into user_set (name, id, data) values (?, ?, ?)"), ['acl', i[0], i[2]])
curs.execute(db_change("insert into user_set (name, id, data) values (?, ?, ?)"), ['date', i[0], i[3]])
curs.execute(db_change("insert into user_set (name, id, data) values (?, ?, ?)"), ['encode', i[0], i[4]])
if ver_num < 3400101:
# user_set이랑 user_application 테이블의 통합
curs.execute(db_change('select id, pw, date, encode, question, answer, ip, ua, email from user_application'))
for i in curs.fetchall():
sql_data = {}
sql_data['id'] = i[0]
sql_data['pw'] = i[1]
sql_data['date'] = i[2]
sql_data['encode'] = i[3]
sql_data['question'] = i[4]
sql_data['answer'] = i[5]
sql_data['ip'] = i[6]
sql_data['ua'] = i[7]
sql_data['email'] = i[8]
curs.execute(db_change("insert into user_set (name, id, data) values (?, ?, ?)"), ['application', i[0], orjson.dumps(sql_data).decode('utf-8')])
if ver_num < 3500105:
curs.execute(db_change('delete from acl where title like "file:%" and data = "admin" and type like "decu%"'))
if ver_num < 3500106:
curs.execute(db_change("select data from other where name = 'domain'"))
db_data = curs.fetchall()
if db_data and db_data[0][0] != '':
db_data = db_data[0][0]
db_data = re.match(r'[^/]+\/\/([^/]+)', db_data)
if db_data:
db_data = db_data.group(1)
curs.execute(db_change("update other set data = ? where name = 'domain'"), [db_data])
else:
curs.execute(db_change("update other set data = '' where name = 'domain'"))
if ver_num < 3500107:
db_table_list = get_db_table_list()
for for_a in db_table_list:
for for_b in db_table_list[for_a]:
curs.execute(db_change("update " + for_a + " set " + for_b + " = '' where " + for_b + " is null"))
if ver_num < 3500113:
db_table_list = get_db_table_list()
for for_a in db_table_list:
for for_b in db_table_list[for_a]:
curs.execute(db_change("update " + for_a + " set " + for_b + " = '' where " + for_b + " is null"))
if ver_num < 3500114:
curs.execute(db_change('delete from alarm'))
if ver_num < 3500354:
curs.execute(db_change("select data from other where name = 'robot'"))
db_data = curs.fetchall()
if db_data:
robot_default = '' + \
'User-agent: *\n' + \
'Disallow: /\n' + \
'Allow: /$\n' + \
'Allow: /image/\n' + \
'Allow: /views/\n' + \
'Allow: /w/' + \
''
if db_data[0][0] == robot_default:
curs.execute(db_change("insert into other (name, data, coverage) values ('robot_default', 'on', '')"))
if ver_num < 3500355:
# other coverage 오류 해결
curs.execute(db_change("update other set coverage = '' where coverage is null"))
if ver_num < 3500358:
curs.execute(db_change("drop index history_index"))
curs.execute(db_change("create index history_index on history (title, ip)"))
if ver_num < 3500360:
# 마지막 편집 따로 기록하도록
# create_data['data_set'] = ['doc_name', 'doc_rev', 'set_name', 'set_data']
print("Update 3500360...")
curs.execute(db_change('delete from data_set where set_name = "last_edit"'))
curs.execute(db_change("select title from data"))
db_data = curs.fetchall()
for for_a in db_data:
curs.execute(db_change("select date from history where title = ? order by date desc limit 1"), [for_a[0]])
db_data_2 = curs.fetchall()
if db_data_2:
curs.execute(db_change("insert into data_set (doc_name, doc_rev, set_name, set_data) values (?, '', 'last_edit', ?)"), [for_a[0], db_data_2[0][0]])
curs.execute(db_change('delete from acl where title like "file:%" and data = "admin" and type like "decu%"'))
print("Update 3500360 complete")
if ver_num < 3500361:
# curs.execute(db_change('select id from user_set where name = "email" and data = ?'), [user_email])
curs.execute(db_change('select id from user_set where name = "email"'))
for db_data in curs.fetchall():
if ip_or_user(db_data[0]) == 1:
curs.execute(db_change('delete from user_set where id = ? and name = "email"'), [db_data[0]])
# create_data['history'] = ['id', 'title', 'data', 'date', 'ip', 'send', 'leng', 'hide', 'type']
# create_data['rc'] = ['id', 'title', 'date', 'type']
if ver_num == 3500362:
curs.execute(db_change("drop index history_index"))
curs.execute(db_change("create index history_index on history (title, ip)"))
if ver_num < 3500365:
curs.execute(db_change("update back set data = '' where data is null"))
if ver_num < 3500371:
curs.execute(db_change("delete from user_notice"))
user_alarm_count = {}
curs.execute(db_change("select name, data, date from alarm"))
for db_data in curs.fetchall():
if db_data[0] in user_alarm_count:
user_alarm_count[db_data[0]] += 1
else:
user_alarm_count[db_data[0]] = 1
curs.execute(db_change('insert into user_notice (id, name, data, date, readme) values (?, ?, ?, ?, "")'), [str(user_alarm_count[db_data[0]]), db_data[0], db_data[1], db_data[2]])
if ver_num < 3500372:
# ID 글자 확인 호환용
curs.execute(db_change('insert into html_filter (html, kind, plus, plus_t) values (?, ?, ?, ?)'), [r'(?:[^A-Za-zㄱ-힣0-9])', 'name', '', ''])
if ver_num < 3500373:
select_data = {}
curs.execute(db_change("select name, id, data from user_set where name = 'application'"))
for db_data in curs.fetchall():
select_data[db_data[1]] = db_data
curs.execute(db_change("delete from user_set where name = 'application'"))
for db_data in select_data:
curs.execute(db_change("insert into user_set (id, name, data) values (?, ?, ?)"), [select_data[db_data][1], select_data[db_data][0], select_data[db_data][2]])
if ver_num < 3500374:
# ban 오류 해결
curs.execute(db_change("update rb set ongoing = '' where ongoing is null"))
curs.execute(db_change("update rb set login = '' where login is null"))
if ver_num < 3500375:
curs.execute(db_change("select title, type, user from scan"))
for for_a in curs.fetchall():
type_data = 'watchlist' if for_a[1] == '' else 'star_doc'
curs.execute(db_change("insert into user_set (id, name, data) values (?, ?, ?)"), [for_a[2], type_data, for_a[0]])
if ver_num < 3500376:
curs.execute(db_change("select doc_name, doc_rev from data_set where set_name = 'edit_request_data'"))
for for_a in curs.fetchall():
curs.execute(db_change("select id from history where title = ? order by id + 0 desc limit 1"), [for_a[0]])
get_data = curs.fetchall()
if get_data and (int(get_data[0][0]) + 1) == int(for_a[1]):
curs.execute(db_change("insert into data_set (doc_name, doc_rev, set_name, set_data) values (?, ?, 'edit_request_doing', '1')"), [for_a[0], for_a[1]])
if ver_num < 3500377 and set_data['type'] == 'sqlite':
conn.execute('pragma journal_mode = delete')
if ver_num < 3500378:
curs.execute(db_change("select title from data where title like 'category:%' or title like 'user:%' or title like 'file:%'"))
for for_a in curs.fetchall():
mode = ''
if re.search('^user:', for_a[0]):
mode = 'user'
elif re.search('^file:', for_a[0]):
mode = 'file'
elif re.search('^category:', for_a[0]):
mode = 'category'
curs.execute(db_change('delete from data_set where doc_name = ? and set_name = "doc_type"'), [for_a[0]])
curs.execute(db_change("insert into data_set (doc_name, doc_rev, set_name, set_data) values (?, '', 'doc_type', ?)"), [for_a[0], mode])
if ver_num < 3500379:
curs.execute(db_change("select distinct doc_name from data_set where doc_rev = 'not_exist' or doc_rev = ''"))
for for_a in curs.fetchall():
data_set_exist = ''
curs.execute(db_change("select title from data where title = ?"), [for_a[0]])
if not curs.fetchall():
data_set_exist = 'not_exist'
curs.execute(db_change("update data_set set doc_rev = ? where doc_name = ? and (doc_rev = '' or doc_rev = 'not_exist')"), [data_set_exist, for_a[0]])
if ver_num < 20240513:
curs.execute(db_change("update user_set set data = '☑️' where name = 'user_title' and data = '✅'"))
if ver_num < 20240732:
curs.execute(db_change("select distinct name from alist where acl = 'owner'"))
for for_a in curs.fetchall():
curs.execute(db_change("select distinct id from user_set where name = 'acl' and data = ?"), [for_a[0]])
for for_b in curs.fetchall():
lang_name = get_lang_name(conn, tool = 'inter')
if lang_name == 'ko-KR':
add_alarm(for_b[0], 'tool:system', '메인 ACL이 권한으로 개편되면서 기존 설정 값이 날라갔으니 권한으로 재설정 해주세요.')
else:
add_alarm(for_b[0], 'tool:system', 'As the main ACL has been reorganized into the auth, the existing setting values have been lost, so please reset it to the auth.')
print('Update completed')
def set_init_always(conn, ver_num, run_mode):
with class_temp_db() as m_conn:
m_curs = m_conn.cursor()
curs = conn.cursor()
# 버전 기입
curs.execute(db_change('delete from other where name = "ver"'))
curs.execute(db_change('insert into other (name, data, coverage) values ("ver", ?, "")'), [ver_num])
# 기본 권한 그룹 설정
curs.execute(db_change('delete from alist where name = "owner"'))
curs.execute(db_change('insert into alist (name, acl) values ("owner", "owner")'))
curs.execute(db_change("select name from alist where name = 'user' limit 1"))
if not curs.fetchall():
curs.execute(db_change('insert into alist (name, acl) values ("user", "user")'))
curs.execute(db_change("select name from alist where name = 'ip' limit 1"))
if not curs.fetchall():
curs.execute(db_change('insert into alist (name, acl) values ("ip", "ip")'))
curs.execute(db_change("select name from alist where name = 'ban' limit 1"))
if not curs.fetchall():
curs.execute(db_change('insert into alist (name, acl) values ("ban", "view")'))
# 이미지 폴더 없으면 생성
if not os.path.exists(load_image_url(conn)):
os.makedirs(load_image_url(conn))
# 비밀키 없으면 생성
curs.execute(db_change('select data from other where name = "key"'))
if not curs.fetchall():
curs.execute(db_change('insert into other (name, data, coverage) values ("key", ?, "")'), [load_random_key()])
# 솔트키 없으면 생성
curs.execute(db_change('select data from other where name = "salt_key"'))
if not curs.fetchall():
curs.execute(db_change('insert into other (name, data, coverage) values ("salt_key", ?, "")'), [load_random_key(4)])
# 문서 전체 갯수 없으면 생성
curs.execute(db_change('select data from other where name = "count_all_title"'))
if not curs.fetchall():
curs.execute(db_change('insert into other (name, data, coverage) values ("count_all_title", "0", "")'))
# 위키 접근 비밀번호 있으면 temp DB로 넘겨줌
curs.execute(db_change('select data from other where name = "wiki_access_password_need"'))
db_data = curs.fetchall()
if db_data and db_data[0][0] != '':
curs.execute(db_change('select data from other where name = "wiki_access_password"'))
db_data = curs.fetchall()
if db_data:
m_curs.execute('insert into temp (name, data) values ("wiki_access_password", ?)', [db_data[0][0]])
curs.execute(db_change('select data from other where name = "load_ip_select"'))
db_data = curs.fetchall()
if db_data and db_data[0][0] != '':
m_curs.execute('insert into temp (name, data) values ("load_ip_select", ?)', [db_data[0][0]])
# OS마다 실행 파일 설정
exe_type = linux_exe_chmod()
if run_mode == '':
exe_path = os.path.join('.', 'route_go', 'bin')
for for_a in os.listdir(exe_path):
if for_a != exe_type:
os.remove(os.path.join(exe_path, for_a))
def linux_exe_chmod():
exe_type = ''
if platform.system() == 'Linux':
if platform.machine() in ["AMD64", "x86_64"]:
exe_type = 'main.amd64.bin'
else:
exe_type = 'main.arm64.bin'
else:
if platform.machine() in ["AMD64", "x86_64"]:
exe_type = 'main.amd64.exe'
else:
exe_type = 'main.arm64.exe'
if platform.system() == 'Linux':
os.system('chmod +x ./route_go/bin/' + exe_type)
return exe_type
def set_init(conn):
curs = conn.cursor()
# 초기값 설정 함수
curs.execute(db_change("select html from html_filter where kind = 'email'"))
if not curs.fetchall():
for i in ['naver.com', 'gmail.com', 'daum.net', 'kakao.com']:
curs.execute(db_change("insert into html_filter (html, kind, plus, plus_t) values (?, 'email', '', '')"), [i])
curs.execute(db_change("select html from html_filter where kind = 'extension'"))
if not curs.fetchall():
for i in ['jpg', 'jpeg', 'png', 'gif', 'webp']:
curs.execute(db_change("insert into html_filter (html, kind, plus, plus_t) values (?, 'extension', '', '')"), [i])
curs.execute(db_change('select data from other where name = "smtp_server" or name = "smtp_port" or name = "smtp_security"'))
if not curs.fetchall():
for i in [['smtp_server', 'smtp.gmail.com'], ['smtp_port', '587'], ['smtp_security', 'starttls']]:
curs.execute(db_change("insert into other (name, data, coverage) values (?, ?, '')"), [i[0], i[1]])
curs.execute(db_change('insert into html_filter (html, kind, plus, plus_t) values (?, ?, ?, ?)'), [r'(?:[^A-Za-zㄱ-힣0-9])', 'name', '', ''])
# Func-simple
## Func-simple-without_DB
def get_default_admin_group():
return ['owner', 'user', 'ip', 'ban']
def get_default_robots_txt(conn):
data = '' + \
'User-agent: *\n' + \
'Disallow: /\n' + \
'Allow: /$\n' + \
'Allow: /w/\n' + \
'Allow: /bbs/w/\n' + \
'Allow: /sitemap.xml$\n' + \
'Allow: /sitemap_*.xml$' + \
''
if os.path.exists('sitemap.xml'):
data += '' + \
'\n' + \
'Sitemap: ' + load_domain(conn, 'full') + '/sitemap.xml' + \
''
return data
def load_random_key(long = 128):
return ''.join(random.choice("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") for _ in range(long))
def http_warning(conn):
return '''
''' + get_lang(conn, 'http_warning') + '''
'''
def get_next_page_bottom(conn, link, num, page, end = 50):
list_data = ''
if num == 1:
if len(page) == end:
list_data += '' + \
'' + \
'(' + get_lang(conn, 'next') + ')' + \
''
elif len(page) != end:
list_data += '' + \
'' + \
'(' + get_lang(conn, 'previous') + ')' + \
''
else:
list_data += '' + \
'' + \
'(' + get_lang(conn, 'previous') + ') ' + \
'(' + get_lang(conn, 'next') + ')' + \
''
return list_data
def next_fix(conn, link, num, page, end = 50):
list_data = ''
if num == 1:
if len(page) == end:
list_data += '' + \
'' + \
'(' + get_lang(conn, 'next') + ')' + \
''
elif len(page) != end:
list_data += '' + \
'' + \
'(' + get_lang(conn, 'previous') + ')' + \
''
else:
list_data += '' + \
'' + \
'(' + get_lang(conn, 'previous') + ')(' + get_lang(conn, 'next') + ')' + \
''
return list_data
def leng_check(A, B):
# B -> new
# A -> old
return '0' if A == B else (('-' + str(A - B)) if A > B else ('+' + str(B - A)))
def number_check(data, f = 0):
try:
float(data) if f == 1 else int(data)
return data
except:
return '1'
def redirect(conn, data = '/'):
return flask.redirect(load_domain(conn, 'full') + data)
# Golang 의존
def get_acl_list(type_data = 'normal'):
if type_data == 'user':
type_data = 'user_document'
other_set = {}
other_set['type'] = type_data
data_str = python_to_golang_sync('api_list_acl', other_set)
data = orjson.loads(data_str)
return data["data"]
## Func-simple-with_DB
def get_user_title_list(conn, ip = ''):
curs = conn.cursor()
ip = ip_check() if ip == '' else ip
# default
user_title = {
'' : get_lang(conn, 'default'),
'🌳' : '🌳 newbie',
}
curs.execute(db_change('select name from user_set where id = ? and name = ?'), [ip, 'get_🥚'])
if curs.fetchall():
user_title['🥚'] = '🥚 easter_egg'
curs.execute(db_change('select data from user_set where name = ? and id = ?'), ['challenge_first_contribute', ip])
if curs.fetchall():
user_title['🔰'] = '🔰 first_contribute'
curs.execute(db_change('select data from user_set where name = ? and id = ?'), ['challenge_tenth_contribute', ip])
if curs.fetchall():
user_title['📝'] = '📝 tenth_contribute'
curs.execute(db_change('select data from user_set where name = ? and id = ?'), ['challenge_hundredth_contribute', ip])
if curs.fetchall():
user_title['🖊️'] = '🖊️ hundredth_contribute'
curs.execute(db_change('select data from user_set where name = ? and id = ?'), ['challenge_thousandth_contribute', ip])
if curs.fetchall():
user_title['🏅'] = '🏅 thousandth_contribute'
curs.execute(db_change('select data from user_set where name = ? and id = ?'), ['challenge_first_discussion', ip])
if curs.fetchall():
user_title['💬'] = '💬 first_discussion'
curs.execute(db_change('select data from user_set where name = ? and id = ?'), ['challenge_tenth_discussion', ip])
if curs.fetchall():
user_title['💡'] = '💡 tenth_discussion'
curs.execute(db_change('select data from user_set where name = ? and id = ?'), ['challenge_hundredth_discussion', ip])
if curs.fetchall():
user_title['📢'] = '📢 hundredth_discussion'
curs.execute(db_change('select data from user_set where name = ? and id = ?'), ['challenge_thousandth_discussion', ip])
if curs.fetchall():
user_title['📜'] = '📜 thousandth_discussion'
curs.execute(db_change('select data from user_set where name = ? and id = ?'), ['challenge_admin', ip])
if curs.fetchall():
user_title['☑️'] = '☑️ before_admin'
if acl_check(tool = 'all_admin_auth') != 1:
user_title['✅'] = '✅ admin'
return user_title
def load_image_url(conn):
curs = conn.cursor()
curs.execute(db_change('select data from other where name = "image_where"'))
image_where = curs.fetchall()
image_where = image_where[0][0] if image_where else os.path.join('data', 'images')
return image_where
def load_domain(conn, data_type = 'normal'):
curs = conn.cursor()
domain = ''
try:
sys_host = flask.request.host
except:
sys_host = ''
if data_type == 'full':
curs.execute(db_change("select data from other where name = 'http_select'"))
db_data = curs.fetchall()
domain += db_data[0][0] if db_data and db_data[0][0] != '' else 'http'
domain += '://'
curs.execute(db_change("select data from other where name = 'domain'"))
db_data = curs.fetchall()
domain += db_data[0][0] if db_data and db_data[0][0] != '' else sys_host
else:
curs.execute(db_change("select data from other where name = 'domain'"))
db_data = curs.fetchall()
domain += db_data[0][0] if db_data and db_data[0][0] != '' else sys_host
return domain
def get_tool_js_safe(data):
data = data.replace('\n', '\\\\n')
data = data.replace('\\', '\\\\')
data = data.replace("'", "\\'")
data = data.replace('"', '\\"')
return data
def edit_button(conn):
curs = conn.cursor()
insert_list = []
curs.execute(db_change("select html, plus from html_filter where kind = 'edit_top'"))
db_data = curs.fetchall()
for get_data in db_data:
insert_list += [[get_data[1], get_data[0]]]
data = ''
for insert_data in insert_list:
data += '(' + html.escape(insert_data[1]) + ') '
data += (' ' if data != '' else '') + '(' + get_lang(conn, 'add') + ')'
data += ''
return data
def ip_warning(conn):
curs = conn.cursor()
if ip_or_user() != 0:
curs.execute(db_change('select data from other where name = "no_login_warning"'))
data = curs.fetchall()
if data and data[0][0] != '':
text_data = '' + \
'' + data[0][0] + '' + \
'' + \
''
else:
text_data = '' + \
'' + get_lang(conn, 'no_login_warning') + '' + \
'' + \
''
else:
text_data = ''
return text_data
# Func-login
def pw_encode(conn, data, db_data_encode = ''):
curs = conn.cursor()
if db_data_encode == '':
curs.execute(db_change('select data from other where name = "encode"'))
db_data = curs.fetchall()
db_data_encode = db_data[0][0] if db_data else 'sha3'
if db_data_encode == 'sha256':
return hashlib.sha256(bytes(data, 'utf-8')).hexdigest()
elif db_data_encode == 'sha3':
return hashlib.sha3_256(bytes(data, 'utf-8')).hexdigest()
elif db_data_encode == 'sha3-512':
return hashlib.sha3_512(bytes(data, 'utf-8')).hexdigest()
else:
curs.execute(db_change('select data from other where name = "salt_key"'))
db_data = curs.fetchall()
db_data_salt = db_data[0][0] if db_data else ''
if db_data_encode == 'sha3-salt':
return hashlib.sha3_256(bytes(data + db_data_salt, 'utf-8')).hexdigest()
else:
return hashlib.sha3_512(bytes(data + db_data_salt, 'utf-8')).hexdigest()
def pw_check(conn, data, data2, type_d = 'no', id_d = ''):
curs = conn.cursor()
curs.execute(db_change('select data from other where name = "encode"'))
db_data = curs.fetchall()
load_set_data = db_data[0][0] if db_data and db_data[0][0] != '' else 'sha3'
set_data = load_set_data
if type_d != 'no':
set_data = 'sha3' if type_d == '' else type_d
re_data = 1 if pw_encode(conn, data, set_data) == data2 else 0
if load_set_data != set_data and re_data == 1 and id_d != '':
curs.execute(db_change("update user_set set data = ? where id = ? and name = 'pw'"), [pw_encode(conn, data), id_d])
curs.execute(db_change("update user_set set data = ? where id = ? and name = 'encode'"), [load_set_data, id_d])
return re_data
# Func-skin
def easy_minify(conn, data, tool = None):
return data
def get_lang_name(conn, tool = ''):
curs = conn.cursor()
if tool != 'inter':
ip = ip_check()
if ip_or_user(ip) == 0:
curs.execute(db_change('select data from user_set where name = "lang" and id = ?'), [ip])
rep_data = curs.fetchall()
elif 'lang' in flask.session:
rep_data = [[flask.session['lang']]]
else:
curs.execute(db_change("select data from other where name = 'language'"))
rep_data = curs.fetchall()
else:
curs.execute(db_change("select data from other where name = 'language'"))
rep_data = curs.fetchall()
if not rep_data or rep_data[0][0] in ('', 'default'):
curs.execute(db_change("select data from other where name = 'language'"))
rep_data = curs.fetchall()
if rep_data:
lang_name = rep_data[0][0]
else:
lang_name = 'en-US'
return lang_name
def get_lang(conn, data, safe = 0):
with class_temp_db() as m_conn:
m_curs = m_conn.cursor()
lang_name = get_lang_name(conn)
m_curs.execute('select data from temp where name = ?', ['lang_' + lang_name + '_' + data])
db_data = m_curs.fetchall()
if db_data:
if safe == 1:
return db_data[0][0]
else:
return html.escape(db_data[0][0])
else:
lang_list = os.listdir('lang')
if (lang_name + '.json') in lang_list:
lang = orjson.loads(open(os.path.join('lang', lang_name + '.json'), encoding = 'utf8').read())
else:
lang = {}
if data in lang:
m_curs.execute('insert into temp (name, data) values (?, ?)', ['lang_' + lang_name + '_' + data, lang[data]])
if safe == 1:
return lang[data]
else:
return html.escape(lang[data])
print(data + ' (' + lang_name + ')')
return html.escape(data + ' (' + lang_name + ')')
# 하위 호환용
def load_lang(data, safe = 0):
with get_db_connect() as conn:
return get_lang(conn, data, safe)
def skin_check(conn, set_n = 0):
curs = conn.cursor()
# 개편 필요?
skin_list = load_skin(conn, 'ringo', 1)
skin = skin_list[0]
ip = ip_check()
user_need_skin = ''
if ip_or_user(ip) == 0:
curs.execute(db_change('select data from user_set where name = "skin" and id = ?'), [ip])
skin_exist = curs.fetchall()
if skin_exist:
user_need_skin = skin_exist[0][0]
else:
if 'skin' in flask.session:
user_need_skin = flask.session['skin']
user_need_skin = '' if user_need_skin == 'default' else user_need_skin
if user_need_skin == '':
curs.execute(db_change('select data from other where name = "skin"'))
skin_exist = curs.fetchall()
if skin_exist:
user_need_skin = skin_exist[0][0]
if user_need_skin != '' and user_need_skin in skin_list:
skin = user_need_skin
if set_n == 0:
return './views/' + skin + '/index.html'
else:
return skin
def cache_v():
return '.cache_v275'
def wiki_css(data):
with class_temp_db() as m_conn:
m_curs = m_conn.cursor()
# without_DB
data += ['' for _ in range(0, 4 - len(data))]
data_css = ''
data_css_dark = ''
data_css_ver = cache_v()
m_curs.execute('select data from temp where name = "main_css"')
db_data = m_curs.fetchall()
if db_data:
data_css = db_data[0][0]
else:
data_css += ''
# External JS
data_css += ''
data_css += ''
data_css += ''
data_css += ''
data_css += ''
# Func JS
data_css += ''
data_css += ''
data_css += ''
data_css += ''
data_css += ''
data_css += ''
data_css += ''
data_css += ''
data_css += ''
# Main CSS
data_css += ''
# External CSS
data_css += ''
data_css += ''
data_css += ''
m_curs.execute('insert into temp (name, data) values ("main_css", ?)', [data_css])
# Darkmode
m_curs.execute('select data from temp where name = "dark_main_css"')
db_data = m_curs.fetchall()
if db_data:
data_css_dark = db_data[0][0]
else:
# Main CSS
data_css_dark += ''
# External CSS
data_css_dark += ''
m_curs.execute('insert into temp (name, data) values ("dark_main_css", ?)', [data_css_dark])
data = data[0:2] + ['', data_css] + data[2:3] + [data_css_dark] + data[3:]
return data
def cut_100(data):
return ''
def wiki_set(conn):
curs = conn.cursor()
ip = ip_check()
skin_name = skin_check(conn, 1)
data_list = []
curs.execute(db_change('select data from other where name = ?'), ['name'])
db_data = curs.fetchall()
data_list += [db_data[0][0]] if db_data and db_data[0][0] != '' else ['Wiki']
curs.execute(db_change('select data from other where name = "license"'))
db_data = curs.fetchall()
data_list += [db_data[0][0]] if db_data and db_data[0][0] != '' else ['ARR']
data_list += ['', '']
curs.execute(db_change('select data from other where name = "logo" and coverage = ?'), [skin_name])
db_data = curs.fetchall()
if db_data and db_data[0][0] != '':
data_list += [db_data[0][0]]
else:
curs.execute(db_change('select data from other where name = "logo" and coverage = ""'))
db_data = curs.fetchall()
data_list += [db_data[0][0]] if db_data and db_data[0][0] != '' else [data_list[0]]
head_data = ''
curs.execute(db_change("select data from other where name = 'head' and coverage = ''"))
db_data = curs.fetchall()
head_data += db_data[0][0] if db_data and db_data[0][0] != '' else ''
curs.execute(db_change("select data from other where name = 'head' and coverage = ?"), [skin_name])
db_data = curs.fetchall()
head_data += db_data[0][0] if db_data and db_data[0][0] != '' else ''
darkmode = flask.request.cookies.get('main_css_darkmode', '0')
if darkmode == '1':
curs.execute(db_change("select data from other where name = 'head' and coverage = ?"), [skin_name + '-cssdark'])
db_data = curs.fetchall()
head_data += db_data[0][0] if db_data and db_data[0][0] != '' else ''
data_list += [head_data]
curs.execute(db_change("select data from other where name = 'top_menu'"))
db_data = curs.fetchall()
db_data = db_data[0][0] if db_data else ''
db_data = db_data.replace('\r', '')
curs.execute(db_change("select data from user_set where name = 'top_menu' and id = ?"), [ip])
db_data_2 = curs.fetchall()
db_data_2 = db_data_2[0][0] if db_data_2 else ''
db_data_2 = db_data_2.replace('\r', '')
if db_data_2 != '' and db_data != '':
db_data += '\n' + db_data_2
elif db_data_2 != '':
db_data += db_data_2
if db_data != '':
db_data = db_data.split('\n')
if len(db_data) % 2 != 0:
db_data += ['']
db_data = [[db_data[for_a], db_data[for_a + 1]] for for_a in range(0, len(db_data), 2)]
data_list += [db_data]
template_var = []
for for_a in range(1, 4):
curs.execute(db_change("select data from other where name = ?"), ['template_var_' + str(for_a)])
db_data = curs.fetchall()
template_var += [db_data[0][0]] if db_data else ['']
data_list += [template_var]
return data_list
def wiki_custom(conn):
curs = conn.cursor()
ip = ip_check()
skin_name = '_' + skin_check(conn, 1)
if ip_or_user(ip) == 0:
user_icon = 1
user_name = ip
if 'head' in flask.session:
user_head = flask.session['head']
else:
curs.execute(db_change("select data from user_set where id = ? and name = 'custom_css'"), [ip])
db_data = curs.fetchall()
user_head = db_data[0][0] if db_data else ''
flask.session['head'] = db_data[0][0] if db_data else ''
if 'head' + skin_name in flask.session:
user_head += flask.session['head' + skin_name]
else:
curs.execute(db_change("select data from user_set where id = ? and name = ?"), [ip, 'custom_css' + skin_name])
db_data = curs.fetchall()
user_head += db_data[0][0] if db_data else ''
flask.session['head' + skin_name] = db_data[0][0] if db_data else ''
curs.execute(db_change('select data from user_set where name = "email" and id = ?'), [ip])
email = curs.fetchall()
email = email[0][0] if email else ''
if acl_check(tool = 'all_admin_auth') != 1:
user_admin = '1'
curs.execute(db_change("select data from user_set where id = ? and name = 'acl'"), [ip])
curs.execute(db_change('select acl from alist where name = ?'), [curs.fetchall()[0][0]])
user_acl = curs.fetchall()
user_acl_list = [for_a[0] for for_a in user_acl]
user_acl_list = user_acl_list if user_acl_list != [] else '0'
else:
user_admin = '0'
user_acl_list = '0'
curs.execute(db_change("select count(*) from user_notice where name = ? and readme = ''"), [ip])
count = curs.fetchall()
user_notice = str(count[0][0]) if count else '0'
else:
user_icon = 0
user_name = get_lang(conn, 'user')
email = ''
user_admin = '0'
user_acl_list = '0'
user_notice = '0'
user_head = flask.session['head'] if 'head' in flask.session else ''
user_head += flask.session['head' + skin_name] if 'head' + skin_name in flask.session else ''
curs.execute(db_change("select title from rd where title = ? and stop = '' limit 1"), ['user:' + ip])
user_topic = '1' if curs.fetchall() else '0'
split_path = flask.request.path.split('/')
split_path = split_path[1:] if len(split_path) > 1 else 0
return [
'',
'',
user_icon,
user_head,
email,
user_name,
user_admin,
str(ban_check()[0]),
user_notice,
user_acl_list,
ip,
user_topic,
split_path,
level_check(conn, ip)
]
def load_skin(conn, data = '', set_n = 0, default = 0):
# without_DB
# data -> 가장 앞에 있을 스킨 이름
# set_n == 0 -> 스트링으로 반환
# set_n == 1 -> 리스트로 반환
# default == 0 -> 디폴트 미포함
# default == 1 -> 디폴트 포함
skin_return_data = []
skin_return_data_str = ''
skin_list_get = os.listdir('views')
if default == 1:
skin_list_get = ['default'] + skin_list_get
for skin_data in skin_list_get:
if skin_data != 'default':
see_data = skin_data
else:
see_data = get_lang(conn, 'default')
if skin_data != 'main_css':
if set_n == 0:
if skin_data == data:
skin_return_data_str = '' + \
'' + \
'' + skin_return_data_str
else:
skin_return_data_str += '' + \
'' + \
''
else:
if skin_data == data:
skin_return_data = [skin_data] + skin_return_data
else:
skin_return_data += [skin_data]
if set_n == 0:
return skin_return_data_str
else:
return skin_return_data
# Func-markup
def render_set(conn, doc_name = '', doc_data = '', data_type = 'view', markup = ''):
curs = conn.cursor()
# data_type in ['view', 'from', 'thread', 'api_view', 'api_thread', 'api_include', 'backlink']
# data_type을 list 형식으로 개편 필요할 듯
return_type = True
if data_type in ['api_from', 'api_view', 'api_thread', 'api_include']:
return_type = False
if data_type == '':
data_type = 'view'
elif data_type == 'api_view':
data_type = 'view'
elif data_type == 'api_from':
data_type = 'from'
elif data_type == 'api_thread':
data_type = 'thread'
elif data_type == 'api_include':
data_type = 'include'
doc_data = '' if doc_data == None else doc_data
ip = ip_check()
render_lang_data = {
'toc' : get_lang(conn, 'toc'),
'category' : get_lang(conn, 'category')
}
curs.execute(db_change('select data from other where name = "category_text"'))
db_data = curs.fetchall()
if db_data and db_data[0][0] != '':
render_lang_data['category'] = db_data[0][0]
get_class_render = class_do_render(conn, render_lang_data, markup).do_render(doc_name, doc_data, data_type)
if data_type == 'backlink':
return ''
get_class_render[0] = '
' + end,
menu = 0
)), 401
else:
title = get_lang(conn, 'error')
sub_title = title
return_code = 400
num = data
if num == 1:
data = get_lang(conn, 'no_login_error')
elif num == 2:
data = get_lang(conn, 'no_exist_user_error')
elif num == 3:
data = get_lang(conn, 'authority_error')
elif num == 4:
data = get_lang(conn, 'no_admin_block_error')
elif num == 5:
data = get_lang(conn, 'error_skin_set')
elif num == 8:
data = '' + \
get_lang(conn, 'long_id_error') + ' ' + \
get_lang(conn, 'id_char_error') + ' (' + get_lang(conn, 'id_filter_list') + ') ' + \
get_lang(conn, 'same_id_exist_error') + \
''
elif num == 9:
data = get_lang(conn, 'file_exist_error')
elif num == 10:
data = get_lang(conn, 'password_error')
elif num == 11:
data = get_lang(conn, 'topic_long_error')
elif num == 12:
data = get_lang(conn, 'email_error')
elif num == 13:
data = get_lang(conn, 'recaptcha_error')
elif num == 14:
data = get_lang(conn, 'file_extension_error') + ' (' + get_lang(conn, 'extension_filter_list') + ')'
elif num == 15:
data = get_lang(conn, 'edit_record_error')
elif num == 16:
data = get_lang(conn, 'same_file_error')
elif num == 17:
curs.execute(db_change('select data from other where name = "upload"'))
db_data = curs.fetchall()
file_max = number_check(db_data[0][0]) if db_data and db_data[0][0] != '' else '2'
data = get_lang(conn, 'file_capacity_error') + file_max
elif num == 18:
data = get_lang(conn, 'email_send_error')
elif num == 19:
data = get_lang(conn, 'move_error')
elif num == 20:
data = get_lang(conn, 'password_diffrent_error')
elif num == 21:
data = get_lang(conn, 'edit_filter_error')
elif num == 22:
data = get_lang(conn, 'file_name_error')
elif num == 23:
data = get_lang(conn, 'regex_error')
elif num == 24:
curs.execute(db_change("select data from other where name = 'slow_edit'"))
db_data = curs.fetchall()
db_data = '' if not db_data else db_data[0][0]
data = get_lang(conn, 'fast_edit_error') + db_data
elif num == 25:
data = get_lang(conn, 'too_many_dec_error')
elif num == 26:
data = get_lang(conn, 'application_not_found')
elif num == 27:
data = get_lang(conn, "invalid_password_error")
elif num == 28:
data = get_lang(conn, 'watchlist_overflow_error')
elif num == 29:
data = get_lang(conn, 'copyright_disagreed')
elif num == 30:
data = get_lang(conn, 'ie_wrong_callback')
elif num == 33:
data = get_lang(conn, 'restart_fail_error')
elif num == 34:
data = get_lang(conn, "update_error") + ' (Github)'
elif num == 35:
data = get_lang(conn, 'same_email_error')
elif num == 36:
data = get_lang(conn, 'input_email_error')
elif num == 37:
data = get_lang(conn, 'error_edit_send_request')
elif num == 38:
curs.execute(db_change("select data from other where name = 'title_max_length'"))
db_data = curs.fetchall()
db_data = '' if not db_data else db_data[0][0]
data = get_lang(conn, 'error_title_length_too_long') + db_data
elif num == 39:
curs.execute(db_change("select data from other where name = 'title_topic_max_length'"))
db_data = curs.fetchall()
db_data = '' if not db_data else db_data[0][0]
data = get_lang(conn, 'error_title_length_too_long') + db_data
elif num == 40:
curs.execute(db_change("select data from other where name = 'password_min_length'"))
db_data = curs.fetchall()
password_min_length = '' if not db_data else db_data[0][0]
data = get_lang(conn, 'error_password_length_too_short') + password_min_length
elif num == 41:
curs.execute(db_change("select data from other where name = 'edit_timeout'"))
db_data = curs.fetchall()
db_data = '' if not db_data else db_data[0][0]
data = get_lang(conn, 'timeout_error') + db_data
elif num == 42:
curs.execute(db_change("select data from other where name = 'slow_thread'"))
db_data = curs.fetchall()
db_data = '' if not db_data else db_data[0][0]
data = get_lang(conn, 'fast_edit_error') + db_data
elif num == 43:
title = get_lang(conn, 'application_submitted')
sub_title = title
data = get_lang(conn, 'waiting_for_approval')
elif num == 44:
curs.execute(db_change("select data from other where name = 'document_content_max_length'"))
db_data = curs.fetchall()
db_data = '' if not db_data else db_data[0][0]
data = get_lang(conn, 'error_content_length_too_long') + db_data
elif num == 45:
data = get_lang(conn, 'cidr_error')
elif num == 46:
data = get_lang(conn, 'func_404_error')
title = '404'
return_code = 404
elif num == 47:
data = get_lang(conn, 'still_use_auth_error')
elif num == 48:
data = get_lang(conn, 'xss_data_include_error')
else:
data = '???'
if num == 5:
if flask.request.path != '/skin_set':
data += ' ' + get_lang(conn, 'error_skin_set_old') + ' (' + get_lang(conn, 'go') + ')'
return easy_minify(conn, flask.render_template(skin_check(conn),
imp = [get_lang(conn, 'skin_set'), wiki_set(conn), wiki_custom(conn), wiki_css([0, 0])],
data = '' + \
'