require 'time'
require 'sqlite3'
-require_relative '../b'
+Dir.chdir(File.join(File.dirname(__FILE__), '..'))
+
+require '../b'
include B
+
# constanty things
DEBUG = true
CAPTCHA = -> {
def do_captcha
captcha_q = CAPTCHA.sample[0]
puts "Content-type: text/html\n\n"
- puts skel('comment.rb', "#{DN}/captcha", <<EOF, ' / <a href="/blog.html">blog</a> / comment-captcha')
+ puts skel("#{DN}/captcha", <<EOF, header: ' / <a href="/blog.html">blog</a> / captcha')
<p>Hello friend. I haven't read a post from #{IP}, and I only remember for a few months, so:</p>
<p>#{captcha_q}</p>
-<form action="/comment.rb" method="post">
+<form action="/cgi/comment" method="post">
<input class="misc" type="text" name="url">
<input name="goto" type="hidden" value="#{GOTO}">
<input name="question" type="hidden" value="#{captcha_q}">
end
def redir
- File.write('/tmp/x', GOTO)
puts 'Status: 302 Found'
puts "Location: #{GOTO}#comment-section\n\n"
exit(0)
GOTO = cgi['goto']
else
GOTO = '/'
- fail['redir to /']
+ fail('redir to /')
end
if (cgi.has_key?('url') && cgi['url'] != "") || ! cgi.has_key?('comment')
- fail["comment not in form or url in form. cgi.params: #{cgi.params}"]
+ fail("comment not in form or url in form. cgi.params: #{cgi.params}")
end
COMMENT_TXT = cgi["comment"]
if COMMENT_TXT.length > 1000 or GOTO.length > 150
- fail['length of comment or goto is too great']
+ fail('length of comment or goto is too great')
end
found = false
Dir.foreach('blog') do |entry|
next if ['.','..'].any? { |f| f == entry }
- if GOTO == 'blog/' + entry
+ if GOTO == '/blog/' + entry
found = true
break
end
end
- fail['goto entry not found'] unless found
+ fail('goto entry not found') unless found
}[]
######### end error checking & arg parsing ########
unless state
older_date = NOW - DAY*2
- last_moderated = $db.execute(<<-SQL, [older_date])[-1][0]
+ last_moderated = $db.execute(<<-SQL, [older_date])[-1]
select date from c
where ip = '#{IP}' and (
state = 'moderated' or
(date < ? and (state = 'timed' or state = 'known')))
SQL
- last_good = $db.execute(<<-SQL, [older_date])[-1][0]
+ last_moderated = last_moderated[0] if last_moderated
+ last_good = $db.execute(<<-SQL, [older_date])[-1]
select date from c
where ip = '#{IP}' and (
state = 'picked' or
(date < ? and (state = 'timed' or state = 'known')))
SQL
+ last_good = last_good[0] if last_good
if last_moderated && last_good
if last_good > last_moderated
state = 'known'