aboutsummaryrefslogtreecommitdiff
path: root/cgi
diff options
context:
space:
mode:
Diffstat (limited to 'cgi')
-rw-r--r--cgi/api.py15
-rw-r--r--cgi/manage.py59
-rw-r--r--cgi/post.py7
-rw-r--r--cgi/template.py13
-rw-r--r--cgi/templates/board.html3
-rw-r--r--cgi/templates/board.jp.html3
-rw-r--r--cgi/templates/txt_archive.html7
-rw-r--r--cgi/templates/txt_board.en.html7
-rw-r--r--cgi/templates/txt_board.html7
-rw-r--r--cgi/templates/txt_thread.html3
-rw-r--r--cgi/templates/txt_threadlist.html2
-rwxr-xr-xcgi/weabot.py9
12 files changed, 97 insertions, 38 deletions
diff --git a/cgi/api.py b/cgi/api.py
index 129da97..ffc9e39 100644
--- a/cgi/api.py
+++ b/cgi/api.py
@@ -75,7 +75,7 @@ def api_process(self, path_split):
if limit > 50:
raise APIError("Maximum limit is 50")
- sql = "SELECT posts.id, boards.dir, timestamp, timestamp_formatted, posts.name, tripcode, email, posts.subject, posts.message, file, file_size, image_height, image_width, thumb, thumb_width, thumb_height, parentid FROM posts INNER JOIN boards ON boardid = boards.id WHERE timestamp > %d AND IS_DELETED = 0 AND boards.secret = 0 ORDER BY timestamp DESC LIMIT %d" % (
+ sql = "SELECT posts.id, boards.dir, timestamp, timestamp_formatted, posts.name, tripcode, email, posterid, posts.subject, posts.message, file, file_size, image_height, image_width, thumb, thumb_width, thumb_height, parentid FROM posts INNER JOIN boards ON boardid = boards.id WHERE timestamp > %d AND IS_DELETED = 0 AND boards.secret = 0 ORDER BY timestamp DESC LIMIT %d" % (
since, limit)
values['posts'] = FetchAll(sql)
@@ -89,6 +89,7 @@ def api_process(self, path_split):
post['thumb_width'] = post['thumb_width']
post['thumb_height'] = post['thumb_height']
post['message'] = post['message']
+
elif method == 'lastage':
data_limit = formdata.get('limit')
data_time = formdata.get('time', 0)
@@ -110,6 +111,7 @@ def api_process(self, path_split):
values['threads'] = threads
else:
values['threads'] = []
+
elif method == 'list':
data_board = formdata.get('dir')
data_offset = formdata.get('offset')
@@ -146,15 +148,14 @@ def api_process(self, path_split):
board = setBoard(data_board)
#sql = "SELECT id, timestamp, bumped, timestamp_formatted, name, tripcode, email, subject, message, file, thumb FROM posts WHERE boardid = %s AND parentid = 0 AND IS_DELETED = 0 ORDER BY bumped DESC LIMIT %d" % (board['id'], limit)
- sql = "SELECT p.id, p.timestamp, p.bumped, p.expires, p.expires_formatted, p.timestamp_formatted, p.name, p.tripcode, p.email, p.subject, p.message, p.file, p.file_size, p.image_width, p.image_height, p.thumb, p.thumb_height, p.thumb_width, p.locked, coalesce(x.count,0) AS total_replies, coalesce(x.files,0) AS total_files FROM `posts` AS p LEFT JOIN (SELECT parentid, count(1) as count, count(nullif(file, '')) as files FROM `posts` WHERE boardid = %(board)s GROUP BY parentid) AS x ON p.id=x.parentid WHERE p.parentid = 0 AND p.boardid = %(board)s AND p.IS_DELETED = 0 ORDER BY `bumped` DESC LIMIT %(limit)d OFFSET %(offset)d" % {
+ sql = "SELECT p.id, p.timestamp, p.bumped, p.expires, p.expires_formatted, p.timestamp_formatted, p.name, p.tripcode, p.email, p.posterid, p.subject, p.message, p.file, p.file_size, p.image_width, p.image_height, p.thumb, p.thumb_height, p.thumb_width, p.locked, coalesce(x.count,0) AS total_replies, coalesce(x.files,0) AS total_files FROM `posts` AS p LEFT JOIN (SELECT parentid, count(1) as count, count(nullif(file, '')) as files FROM `posts` WHERE boardid = %(board)s GROUP BY parentid) AS x ON p.id=x.parentid WHERE p.parentid = 0 AND p.boardid = %(board)s AND p.IS_DELETED = 0 ORDER BY `bumped` DESC LIMIT %(limit)d OFFSET %(offset)d" % {
'board': board["id"], 'limit': limit, 'offset': offset}
threads = FetchAll(sql)
if numreplies:
for thread in threads:
- lastreplies = FetchAll("SELECT id, timestamp, timestamp_formatted, name, tripcode, email, subject, message, file, file_size, image_height, image_width, thumb, thumb_width, thumb_height, IS_DELETED FROM `posts` WHERE parentid = %s AND boardid = %s ORDER BY `timestamp` DESC LIMIT %s",
- (thread['id'], board['id'], numreplies))
+ lastreplies = FetchAll("SELECT id, timestamp, timestamp_formatted, name, tripcode, email, posterid, subject, message, file, file_size, image_height, image_width, thumb, thumb_width, thumb_height, IS_DELETED FROM `posts` WHERE parentid = %s AND boardid = %s ORDER BY `timestamp` DESC LIMIT %s", (thread['id'], board['id'], numreplies))
lastreplies = lastreplies[::-1]
thread['id'] = thread['id']
thread['timestamp'] = thread['timestamp']
@@ -193,6 +194,7 @@ def api_process(self, path_split):
thread['replies'].append(post)
values['threads'] = threads
+
elif method == 'thread':
data_board = formdata.get('dir')
data_threadid = formdata.get('id')
@@ -257,7 +259,7 @@ def api_process(self, path_split):
values['total_replies'] = total_replies
- sql = "SELECT id, parentid, timestamp, timestamp_formatted, name, tripcode, email, subject, message, file, file_size, image_width, image_height, thumb, thumb_width, thumb_height, IS_DELETED FROM posts WHERE boardid = %s AND (parentid = %s OR id = %s) ORDER BY id ASC LIMIT %s OFFSET %s"
+ sql = "SELECT id, parentid, timestamp, timestamp_formatted, name, tripcode, email, posterid, subject, message, file, file_size, image_width, image_height, thumb, thumb_width, thumb_height, IS_DELETED FROM posts WHERE boardid = %s AND (parentid = %s OR id = %s) ORDER BY id ASC LIMIT %s OFFSET %s"
sqlv = (board['id'], values['id'], values['id'], limit, offset)
posts = FetchAll(sql, sqlv)
@@ -288,6 +290,7 @@ def api_process(self, path_split):
post['message'] = re.compile(
r"<[^>]*?>", re.DOTALL | re.IGNORECASE).sub("", post['message'])
values['posts'].append(post)
+
elif method == 'get':
data_board = formdata.get('dir')
data_parentid = formdata.get('thread')
@@ -308,7 +311,7 @@ def api_process(self, path_split):
except ValueError:
raise APIError("Post ID must be numeric")
- post = FetchOne("SELECT id, parentid, timestamp, timestamp_formatted, name, tripcode, email, subject, message, file, file_size, image_width, image_height, thumb, thumb_width, thumb_height, IS_DELETED FROM posts WHERE `id` = %s AND boardid = %s"
+ post = FetchOne("SELECT id, parentid, timestamp, timestamp_formatted, name, tripcode, email, posterid, subject, message, file, file_size, image_width, image_height, thumb, thumb_width, thumb_height, IS_DELETED FROM posts WHERE `id` = %s AND boardid = %s"
(postid, board["id"]))
if not post:
diff --git a/cgi/manage.py b/cgi/manage.py
index 79a94de..e3d7704 100644
--- a/cgi/manage.py
+++ b/cgi/manage.py
@@ -527,14 +527,17 @@ def manage(self, path_split):
if post['name'] == oldboardname:
post['name'] = board['anonymous']
- # fix date and (re)add post ID if necessary
+ # fix date
post['timestamp_formatted'] = formatTimestamp(post['timestamp'])
+
+ #(re)add post ID if necessary
if board["useid"] != '0':
if post["parentid"]:
tym = parent_time
else:
tym = post["timestamp"]
- post['timestamp_formatted'] += ' ID:' + iphash(post['ip'], post, tym, board["useid"], False, '', False, False, (board["countrycode"] in [1, 2]))
+
+ post['posterid'] = iphash(post['ip'], post, tym, board["useid"], False, '', False, False, (board["countrycode"] in [1, 2]))
# insert new post and get its new ID
new_id = post.insert()
@@ -1450,27 +1453,55 @@ def manage(self, path_split):
self.output = "done"
return
+ elif path_split[2] == 'sepid':
+ if not administrator:
+ return
+
+ #sql = 'update posts set posterid = \'\''
+ #UpdateDb(sql)
+
+ board = setBoard(path_split[3])
+ #posts = FetchAll('SELECT * FROM `posts` WHERE `boardid` = %s LIMIT 5' % board['id'])
+ #for post in posts:
+ # self.output += str(post)
+
+ #return
+
+ posts = FetchAll('SELECT * FROM `posts` WHERE `boardid` = %s' % board['id'])
+
+ for post in posts:
+ if not post['posterid']:
+ splitted = post['timestamp_formatted'].split(' ID:')
+
+ self.output += splitted[0] + '<br>'
+
+ idhash = ''
+ if len(splitted) > 1:
+ self.output += splitted[1]
+ idhash = splitted[1]
+
+ self.output += '<hr>'
+
+ sql = "update posts set timestamp_formatted = '%s', posterid = '%s' where boardid = '%s' and id = '%s'" % (splitted[0], idhash, board['id'], post['id'])
+ UpdateDb(sql)
+
+ return
+
elif path_split[2] == 'fixid':
if not administrator:
return
board = setBoard(path_split[3])
- posts = FetchAll(
- 'SELECT * FROM `posts` WHERE `boardid` = %s' % board['id'])
- self.output = "total: %d<br />" % len(posts)
+ posts = FetchAll('SELECT id, email, posterid, message, parentid, INET6_NTOA(ip) AS ip FROM posts WHERE boardid = %s', (board['id'],) )
for post in posts:
- new_timestamp_formatted = formatTimestamp(
- post['timestamp'])
tim = 0
if board["useid"] != 0:
- new_timestamp_formatted += ' ID:' + \
- iphash(post['ip'], '', tim, 1,
- False, False, False, 0)
- self.output += "%s - %s <br />" % (
- post['id'], new_timestamp_formatted)
- query = "UPDATE `posts` SET timestamp_formatted = '%s' WHERE boardid = '%s' AND id = '%s'" % (
- new_timestamp_formatted, board['id'], post['id'])
+ new_hash = iphash(post['ip'], post, tim, board["useid"], False, '', False, False, (board["countrycode"] in [1, 2]))
+ self.output += "%s - %s <br />" % (post['id'], new_hash)
+ query = "UPDATE `posts` SET posterid = '%s' WHERE boardid = '%s' AND id = '%s'" % (new_hash, board['id'], post['id'])
UpdateDb(query)
+
+ self.output = "total: %d<br />" % len(posts)
return
elif path_split[2] == 'fixname':
return
diff --git a/cgi/post.py b/cgi/post.py
index 96b7cab..a34bb39 100644
--- a/cgi/post.py
+++ b/cgi/post.py
@@ -22,6 +22,7 @@ class Post(object):
"name": "",
"tripcode": "",
"email": "",
+ "posterid": "",
"subject": "",
"message": "",
"password": "",
@@ -137,7 +138,7 @@ def getThread(postid=0, mobile=False, timestamp=0):
#thread = {"id": op_post["id"], "posts": [op_post], "omitted": 0, "omitted_img": 0}
total_bytes += len(op_post["message"])+80
- replies = FetchAll("SELECT IS_DELETED, email, file, file_size, id, image_height, image_width, message, name, subject, thumb, thumb_height, thumb_width, timestamp_formatted, tripcode, parentid, locked, expires, expires_alert, expires_formatted, timestamp FROM `posts` WHERE `parentid` = %s AND `boardid` = %s ORDER BY `id` ASC", (op_post["id"], board["id"]))
+ replies = FetchAll("SELECT IS_DELETED, email, posterid, file, file_size, id, image_height, image_width, message, name, subject, thumb, thumb_height, thumb_width, timestamp_formatted, tripcode, parentid, locked, expires, expires_alert, expires_formatted, timestamp FROM `posts` WHERE `parentid` = %s AND `boardid` = %s ORDER BY `id` ASC", (op_post["id"], board["id"]))
thread["length"] = 1
if replies:
for reply in replies:
@@ -408,7 +409,6 @@ def threadList(mode=0):
timestamps = []
for thread in full_threads:
if board['board_type'] == 1:
- thread["timestamp_formatted"] = thread["timestamp_formatted"].split(" ")[0]
timestamps.append([thread["last"], formatTimestamp(thread["last"])])
if mobile:
timestamps[-1][1] = re.compile(r"\(.{1,3}\)", re.DOTALL | re.IGNORECASE).sub(" ", timestamps[-1][1])
@@ -1193,7 +1193,6 @@ def regenerateTrash():
posts = FetchAll("SELECT posts.id AS id, timestamp_formatted, posts.message AS message, boards.name AS board FROM `posts` INNER JOIN `boards` ON boardid = boards.id WHERE IS_DELETED = 2 AND timestamp > %s ORDER BY `timestamp` DESC", (int(time.time()) - 31557600*3,) )
for i in range(len(posts)):
- posts[i]["timestamp_formatted"] = posts[i]["timestamp_formatted"].split()[0]
posts[i]["message"] = formatting.remove_html(posts[i]["message"])
template_values = {'posts': posts}
@@ -1306,7 +1305,7 @@ def archiveThread(postid):
with open(Settings.ROOT_DIR + board["dir"] + "/kako/" + str(thread['timestamp']) + ".html", "w") as f:
f.write(page)
- thread['keys'] = ['num', 'IS_DELETED', 'name', 'tripcode', 'email', 'message', 'timestamp_formatted']
+ thread['keys'] = ['num', 'IS_DELETED', 'name', 'tripcode', 'email', 'message', 'timestamp_formatted', 'posterid']
thread['posts'] = [[row[key] for key in thread['keys']] for row in thread['posts']]
try:
with open(Settings.ROOT_DIR + board["dir"] + "/kako/" + str(thread['timestamp']) + ".json", "w") as f:
diff --git a/cgi/template.py b/cgi/template.py
index ca47db8..6d0c085 100644
--- a/cgi/template.py
+++ b/cgi/template.py
@@ -46,12 +46,13 @@ def renderTemplate(template, template_values={}, mobile=False, noindex=False):
# if board:
if template in ["board.html", "threadlist.html", "catalog.html", "kako.html", "paint.html"] or template[0:3] == "txt":
# TODO HACK
- if board['dir'] == 'world' and not mobile and template == 'txt_board.html':
- template = template[:-4] + 'en.html'
- elif board['dir'] == '2d' and template == 'board.html' and not mobile:
- template = template[:-4] + 'jp.html'
- elif board['dir'] == '0' and template == 'board.html' and not mobile:
- template = template[:-4] + '0.html'
+ if not mobile:
+ if board['dir'] == 'world' and template == 'txt_board.html':
+ template = template[:-4] + 'en.html'
+ elif board['dir'] == '2d' and template == 'board.html':
+ template = template[:-4] + 'jp.html'
+ elif board['dir'] == '0' and template == 'board.html':
+ template = template[:-4] + '0.html'
try:
banners = Settings.banners[board['dir']]
diff --git a/cgi/templates/board.html b/cgi/templates/board.html
index 4a94dc4..ee0ae59 100644
--- a/cgi/templates/board.html
+++ b/cgi/templates/board.html
@@ -195,6 +195,9 @@
</span>
<?py #endif ?>
<span class="date" data-unix="#{post['timestamp']}">#{post['timestamp_formatted']}</span>
+ <?py if post['posterid']: ?>
+ <span class="hash">ID:#{post['posterid']}</span>
+ <?py #endif ?>
<?py if replythread: ?>
<span class="reflink"><a href="##{post['id']}">No.</a><a href="#" class="num">#{post['id']}</a></span>
<?py else: ?>
diff --git a/cgi/templates/board.jp.html b/cgi/templates/board.jp.html
index 0c013ae..db24cc1 100644
--- a/cgi/templates/board.jp.html
+++ b/cgi/templates/board.jp.html
@@ -197,6 +197,9 @@
</span>
<?py #endif ?>
<span class="date" data-unix="#{post['timestamp']}">#{post['timestamp_formatted']}</span>
+ <?py if post['posterid']: ?>
+ <span class="hash">ID:#{post['posterid']}</span>
+ <?py #endif ?>
<?py if replythread: ?>
<span class="reflink"><a href="##{post['id']}">No.</a><a href="#" class="num">#{post['id']}</a></span>
<?py else: ?>
diff --git a/cgi/templates/txt_archive.html b/cgi/templates/txt_archive.html
index 6a30375..cf7077b 100644
--- a/cgi/templates/txt_archive.html
+++ b/cgi/templates/txt_archive.html
@@ -64,7 +64,12 @@
<?py else: ?>
<span class="name"><b>#{post['name']}</b></span>
<?py #endif ?>
- <?py #endif ?> : <span class="date">#{post['timestamp_formatted']}</span></h4>
+ <?py #endif ?>
+ : <span class="date">#{post['timestamp_formatted']}</span>
+ <?py if post['posterid']: ?>
+ <span class="hash">ID:#{post['posterid']}</span>
+ <?py #endif ?>
+ </h4>
<div class="msg">#{post['message']}</div>
</div>
<?py #endif ?>
diff --git a/cgi/templates/txt_board.en.html b/cgi/templates/txt_board.en.html
index 75f548a..55d78ab 100644
--- a/cgi/templates/txt_board.en.html
+++ b/cgi/templates/txt_board.en.html
@@ -66,7 +66,12 @@
<?py else: ?>
<span class="name"><b>#{post['name']}</b></span>
<?py #endif ?>
- <?py #endif ?> : <span class="date" data-unix="#{post['timestamp']}">#{post['timestamp_formatted']}</span></h4>
+ <?py #endif ?>
+ : <span class="date" data-unix="#{post['timestamp']}">#{post['timestamp_formatted']}</span>
+ <?py if post['posterid']: ?>
+ <span class="hash">ID:#{post['posterid']}</span>
+ <?py #endif ?>
+ </h4>
<?py if post['file']: ?>
<a href="/#{board}/src/#{post['file']}" target="_blank" class="thumb">
<img src="#{'/static/' if post['thumb'].startswith('mime') else ('/'+board+'/thumb/')}#{post['thumb']}" width="#{post['thumb_width']}" height="#{post['thumb_height']}" title="${post['file']}-(${post['file_size']} B)" />
diff --git a/cgi/templates/txt_board.html b/cgi/templates/txt_board.html
index 4e8d820..0d386f1 100644
--- a/cgi/templates/txt_board.html
+++ b/cgi/templates/txt_board.html
@@ -70,7 +70,12 @@
<?py else: ?>
<span class="name"><b>#{post['name']}</b></span>
<?py #endif ?>
- <?py #endif ?> : <span class="date" data-unix="#{post['timestamp']}">#{post['timestamp_formatted']}</span></h4>
+ <?py #endif ?>
+ : <span class="date" data-unix="#{post['timestamp']}">#{post['timestamp_formatted']}</span>
+ <?py if post['posterid']: ?>
+ <span class="hash">ID:#{post['posterid']}</span>
+ <?py #endif ?>
+ </h4>
<?py if post['file']: ?>
<a href="/#{board}/src/#{post['file']}" target="_blank" class="thumb">
<img src="#{'/static/' if post['thumb'].startswith('mime') else ('/'+board+'/thumb/')}#{post['thumb']}" width="#{post['thumb_width']}" height="#{post['thumb_height']}" title="${post['file']}-(${post['file_size']} B)" />
diff --git a/cgi/templates/txt_thread.html b/cgi/templates/txt_thread.html
index 98f4567..77c3101 100644
--- a/cgi/templates/txt_thread.html
+++ b/cgi/templates/txt_thread.html
@@ -49,6 +49,9 @@
<span class="name"><b>#{post['name']}</b></span>
<?py #endif ?>
<?py #endif ?> : <span class="date" data-unix="#{post['timestamp']}">#{post['timestamp_formatted']}</span>
+ <?py if post['posterid']: ?>
+ <span class="hash">ID:#{post['posterid']}</span>
+ <?py #endif ?>
<span class="del"><a href="#{cgi_url}report/#{board}/#{post['id']}/#{post['num']}">rep</a> <a href="#">del</a></span></h4>
<?py if post['file']: ?>
<a href="/#{board}/src/#{post['file']}" target="_blank" class="thumb"><img src="#{'/static/' if post['thumb'].startswith('mime') else ('/'+board+'/thumb/')}#{post['thumb']}" width="#{post['thumb_width']}" height="#{post['thumb_height']}" title="${post['file']}-(${post['file_size']} B)" /></a>
diff --git a/cgi/templates/txt_threadlist.html b/cgi/templates/txt_threadlist.html
index 315b34f..8cbd693 100644
--- a/cgi/templates/txt_threadlist.html
+++ b/cgi/templates/txt_threadlist.html
@@ -2,7 +2,7 @@
<body class="mainpage" data-brd="#{board}">
<div id="main_nav"><a href="/" target="_top">Bienvenido a Internet</a> | <?py include('templates/navbar.html') ?></div>
<?py if banner_url: ?>
- <img class="banner" src="#{banner_url}" style="width:#{banner_width}px;height:#{banner_height}px;" />
+ <img id="banner" src="#{banner_url}" style="width:#{banner_width}px;height:#{banner_height}px;" />
<?py #endif ?>
<div id="titlebox" class="outerbox">
<div class="innerbox">
diff --git a/cgi/weabot.py b/cgi/weabot.py
index c1bc1a3..eaf4477 100755
--- a/cgi/weabot.py
+++ b/cgi/weabot.py
@@ -478,7 +478,9 @@ class weabot(object):
# use fields only if enabled
if not board["disable_name"]:
post["name"] = cleanString(name)
+
post["email"] = cleanString(email, quote=True)
+
if not board["disable_subject"]:
post["subject"] = cleanString(subject)
@@ -592,7 +594,7 @@ class weabot(object):
# make ID hash
if board["useid"]:
- post["timestamp_formatted"] += ' ID:' + iphash(ip, post, tim, board["useid"], mobile,
+ post["posterid"] = iphash(ip, post, tim, board["useid"], mobile,
self.environ["HTTP_USER_AGENT"], cap_id, hide_end, (board["countrycode"] in [1, 2]))
# use for future file checks
@@ -729,14 +731,13 @@ class weabot(object):
hosts = host.split('.')
if len(hosts) > 2:
if hosts[-2] in ['ne', 'net', 'com', 'co']:
- host = '.'.join(
- (hosts[-3], hosts[-2], hosts[-1]))
+ host = '.'.join((hosts[-3], hosts[-2], hosts[-1]))
else:
host = '.'.join((hosts[-2], hosts[-1]))
host = '*.' + host
elif ':' in ip:
iprs = ip.split(':')
- host = '%s:%s:*:*:*.*.*.*' % (iprs[0], iprs[1])
+ host = '%s:%s:%s:*:*.*.*.*' % (iprs[0], iprs[1], iprs[2])
else:
iprs = ip.split('.')
host = '%s.%s.*.*' % (iprs[0], iprs[1])