#!/usr/bin/env lua5.1

require "cosmo"

math.randomseed(os.time())

function make_salt(length)
   local CHARACTERS = 
   	"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
   local buffer = ""
   local num_chars = CHARACTERS:len()
   local r
   for i=1, (length or 40) do
      r = math.random(num_chars)
      buffer = buffer..CHARACTERS:sub(r,r)
   end
   return buffer
end

SCRIPT_TEMPLATE = [[
#! /usr/bin/env lua5.1

require 'sputnik'

local conf = {
   -- These random strings were genereted for you by sputnik-mk-cgi,
   -- you don't need to change them
   --
   PASSWORD_SALT  = '$password_salt',
   TOKEN_SALT     = '$token_salt',

   -- For a brief introduction to the configuration of sputnik, please
   -- read /usr/share/doc/sputnik/README.Debian.gz

   -- These are required parameters, remember to make the wiki data directory
   -- writeable to the user that will run the web server (www-data)
   --
   VERSIUM_PARAMS = { '/var/www/wiki-data/' },
   BASE_URL       = '/wiki.cgi',
}

return sputnik.new_wsapi_run_fn(conf)
]]

content = cosmo.f(SCRIPT_TEMPLATE) {
	password_salt = make_salt(),
	token_salt = make_salt(),
}

print(content)
