server.modules = (
 "mod_access",
 "mod_cgi",
 "mod_compress",
 "mod_accesslog",
 "mod_rewrite",
 "mod_alias",
 "mod_auth",
 "mod_setenv",
# "mod_status",
# "mod_alias",
# "mod_redirect",
# "mod_debug"
)

server.document-root = "/www/htdocs"
server.upload-dirs = ( "/tmp" )
server.errorlog = "/tmp/lighttpd-error.log"
accesslog.filename = "/tmp/lighttpd-access.log"
server.pid-file = "/var/run/lighttpd.pid"
server.username = "httpd"
server.groupname = "nogroup"
server.port = 80

## defines var.superglueVersion from /etc/superglue_version
include_shell "/etc/lighttpd/vars.sh"

setenv.add-response-header = ( "X-SuperGlue-Version" => var.superglueVersion )

#debug.log-request-handling = "enable"
#debug.log-request-header = "enable"
#debug.log-file-not-found	= "enable"
#debug.log-request-header-on-error = "enable"
#debug.log-response-header = "enable"
#debug.log-condition-handling	= "enable"

auth.backend = "htdigest"
auth.backend.htdigest.userfile = "/www/lib/admin/htpasswd"
#auth.debug = 2

#setenv.add-response-header = ( "Access-Control-Allow-Origin" => "*" )
compress.cache-dir = "/tmp/lighttpd/compress"
compress.filetype = ( "application/x-javascript", "text/css", "text/html", "text/plain" )

index-file.names = ( "index.html, default.html" )

cgi.assign = ( ".sh" => "/bin/bash" )
url.access-deny = ( "~", ".inc", ".htaccess", ".htpasswd", "htpasswd")

$HTTP["request-method"] == "GET" {
  url.rewrite = ( "^/resources/(.*)$" => "resources/$1",
                  "^/devTools/(.*)$" => "devTools/$1",
                  "^/templates/(.*)$" => "templates/$1",
                  "^/admin/(.*)$" => "admin/admin.sh" )

  alias.url = ( "/resources" => "/www/lib/resources",
                "/devTools" => "/www/lib/devTools",
                "/templates" => "/www/lib/templates",
                "/admin" => "/www/lib/admin" )
}

$HTTP["request-method"] == "POST" {
  url.rewrite = ( "^(/(?!admin).*)" => "post.sh",
                  "^(/(admin).*)" => "admin.sh" 
  )
  $HTTP["url"] =~ "^/post.sh" {
    server.document-root = "/www/lib/cgi"
  }
  $HTTP["url"] =~ "^/admin.sh" {
    server.document-root = "/www/lib/admin"
   }
}

auth.require = ( 
  "/post.sh" => ( "method" => "digest", 
                  "realm" => "superglue", 
                  "require" => "valid-user" ),
  "/admin" => ( "method" => "digest", 
                  "realm" => "superglue", 
                  "require" => "valid-user" )
  )

include "/etc/lighttpd/mime.conf"
