module Main where

import Network.CGI
import Data.Maybe

import DB

main = runCGI $ handleErrors cgiMain

cgiMain = do
    msg_digest <- getInput "digest"
    let digest = fromJust msg_digest
    ciphertext <- liftIO $ db_firstvalue $ "SELECT ciphertext FROM messages WHERE msg_digest LIKE '" ++ digest ++ "'"
    setHeader "Content-Type" "text/plain"
    output $ ciphertext
