Version 11 of tclhttpd 2ch-forums

Updated 2006-04-10 15:20:10

Tips for creating NiChannel[L1 ] style forum software implemented in TclHttpd.


Generating captcha images (http://www.captcha.net ) for anti-spam purposes.

Using ImageMagick convert routine, where the captcha code is RKS876:

   convert captcha.png -gravity center -pointsize 24 -fill white -annotate 0 'RKS876' -swirl 90 captcha-done.png

Using a random sequence of numbers and letters for the captcha code.

   proc randomCode {size} {
      set data [list 1 2 3 4 5 6 7 8 9 0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z]
      set code [list]
      for {set n 0} {$n < $size} {incr n} {
        lappend code [lindex $data [expr {int(rand()*[llength $data])}]]
      }
      return [join $code ""]
    }

Generating the captcha image:

  proc genCaptcha {code} {
    set target captcha-$code-[clock seconds].png
    set key $code
    set stamp [clock seconds]
    exec convert captcha.png -gravity center -pointsize 24 -fill white -annotate 0 '$code' -swirl 90 png:$target
    mk::row append db.captchas key $key stamp $stamp
    return $target
  }

I could store the image inside of a metakit database, but I'm uncertain how to use that in a tml page.

  mk::file open db data.dat
  mk::view layout db.captchas {key stamp data:B}

  mk::row append db.captchas key $key stamp $stamp data [exec convert captcha.png -gravity center -pointsize 24 -fill white -annotate 0 '$code' -swirl 90 png:-]

CJL added: The source image ('captcha.png') doesn't need to exist as a file, e.g.:

  exec convert -size 120x60 xc:black -gravity center -pointsize 24 -fill white -annotate 0 '$code' -swirl 90 png:$target

That's even better. Add the plasma as part of the convert and eliminate actual files altogether. Just store the result in the MK database. I still need to figure out how to display the image out of the database into the resulting web page. The following would add the plasma effect (which is what the captcha.png was) in order to further "obscure" the code from any OCR type spammers.

  exec convert -size 100x50 plasma: -gravity center -pointsize 24 -fill white -annotate 0 '$code' -swirl 90 png:$target

Storing threads/posts in metakit.

Metakit seems like a perfectly designed system for separate "boards" storing their own data? I.e. layout of {board {threads {title posts {subject stamp post}}}} ???