from .tool.func import *
def topic_2(conn, topic_num):
curs = conn.cursor()
admin = admin_check(3)
topic_num = str(topic_num)
if flask.request.method == 'POST':
name = flask.request.form.get('topic', 'test')
sub = flask.request.form.get('title', 'test')
else:
curs.execute(db_change("select title, sub from rd where code = ?"), [topic_num])
name = curs.fetchall()
if name:
sub = name[0][1]
name = name[0][0]
else:
return redirect('/')
ban = acl_check(name, 'topic', topic_num)
if flask.request.method == 'POST':
if flask.request.form.get('content', 'Test') == '':
return redirect('/thread/' + topic_num)
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)
ip = ip_check()
today = get_time()
if ban == 1:
return re_error('/ban')
curs.execute(db_change("select id from topic where code = ? order by id + 0 desc limit 1"), [topic_num])
old_num = curs.fetchall()
if old_num:
num = int(old_num[0][0]) + 1
else:
num = 1
num = str(num)
match = re.search(r'^user:([^/]+)', name)
if match:
y_check = 0
if ip_or_user(match.group(1)) == 1:
curs.execute(db_change("select ip from history where ip = ? limit 1"), [match.group(1)])
u_data = curs.fetchall()
if u_data:
y_check = 1
else:
curs.execute(db_change("select ip from topic where ip = ? limit 1"), [match.group(1)])
u_data = curs.fetchall()
if u_data:
y_check = 1
else:
curs.execute(db_change("select id from user where id = ?"), [match.group(1)])
u_data = curs.fetchall()
if u_data:
y_check = 1
if y_check == 1:
curs.execute(db_change('insert into alarm (name, data, date) values (?, ?, ?)'), [
match.group(1),
ip + ' | ' + name + ' | ' + sub + ' | #' + num + '',
today
])
cate_re = re.compile(r'\[\[((?:분류|category):(?:(?:(?!\]\]).)*))\]\]', re.I)
data = cate_re.sub('[br]', flask.request.form.get('content', 'Test').replace('\r', ''))
for rd_data in re.findall(r"(?: |\n|^)(#(?:[0-9]+))(?: |\n|$)", data):
curs.execute(db_change("select ip from topic where code = ? and id = ?"), [topic_num, rd_data])
ip_data = curs.fetchall()
if ip_data and ip_or_user(ip_data[0][0]) == 0:
curs.execute(db_change('insert into alarm (name, data, date) values (?, ?, ?)'), [
ip_data[0][0],
ip + ' | ' + name + ' | ' + sub + ' | #' + num + '',
today
])
for rd_data in re.findall(r"(?: |\n|^)@((?:[^ ]+))(?: |\n|$)", data):
curs.execute(db_change("select ip from history where ip = ? limit 1"), [rd_data])
ip_data = curs.fetchall()
if not ip_data:
curs.execute(db_change("select ip from topic where ip = ? limit 1"), [rd_data])
ip_data = curs.fetchall()
if ip_data and ip_or_user(ip_data[0][0]) == 0:
curs.execute(db_change('insert into alarm (name, data, date) values (?, ?, ?)'), [
ip_data[0][0],
ip + ' | ' + name + ' | ' + sub + ' | #' + num + '',
today
])
data = re.sub(r"( |\n|^)(#(?:[0-9]+))( |\n|$)", '\g<1>