server.modules = (
 "mod_access",
 "mod_cgi",
 "mod_accesslog",
 "mod_rewrite",
 "mod_alias",
 "mod_auth",
 "mod_setenv",
 "mod_proxy",
)

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

$HTTP["host"] != "superglue.local" {
  accesslog.filename = "/www/log/access.log"
}

dir-listing.activate =   "enable"
dir-listing.hide-dotfiles = "enable"

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

cgi.assign = (
    ".sh"   =>  "/bin/bash",
    ".cgi"  =>  "",
)

url.access-deny = ( "~", ".inc", ".htaccess", ".htpasswd", "htpasswd", "/tmp/" )

auth.backend = "htdigest"
auth.backend.htdigest.userfile = "/etc/lighttpd/htpasswd"

$HTTP["url"] =~ "^/admin$|^/admin/(.*)|^/log/(.*)$" {                                                 
  auth.require = ( "" => (    
    "method"  =>  "digest",
    "realm"   =>  "superglue",
    "require" =>  "valid-user"
    )
  )
}

$HTTP["request-method"] == "POST" {
  auth.require = ( "" => (    
    "method"  =>  "digest",
    "realm"   =>  "superglue",
    "require" =>  "valid-user"
    )
  )
}

## defines var.superglueVersion from /etc/superglue_version
include_shell "/etc/lighttpd/vars.sh"
setenv.add-response-header += ( "X-Superglue-Version" => var.superglueVersion )

$HTTP["request-method"] == "GET" {
  url.rewrite = (
    "^/resources/(.*)$" =>  "resources/$1",
    "^/devTools/(.*)$"  =>  "devTools/$1",
    "^/templates/(.*)$" =>  "templates/$1",
    "^/extension/(.*)$" =>  "extension/$1"
  ),
  alias.url = (
    "/resources"  =>  "/opt/lib/resources",
    "/devTools"   =>  "/opt/lib/devTools",
    "/templates"  =>  "/opt/lib/templates",
    "/extension"  =>  "/opt/lib/extension"
  )
  ## override content and mime type for dotless files to text/html
  $HTTP["url"] !~ "(\.)" {
    $HTTP["url"] !~ "(^/admin)" {
      setenv.add-response-header += (
        "X-Superglue-Dotless" => "text/html Content-Type was forced",
        "Content-Type" => "text/html"
      )
    }
  }
}

$HTTP["url"] =~ "(^/admin)" {   
  proxy.server  = ( "" => ("admin" => ( "host" => "127.0.0.1", "port" => 81 ))) 
}

$HTTP["request-method"] == "POST" {
  alias.url = (
    ""          =>  "/opt/lib/cgi/post.cgi"
  )
}

## can use this? per 
## https://dev.openwrt.org/browser/packages/net/lighttpd/files/lighttpd.conf?rev=38469
# include_shell "cat /etc/lighttpd/conf.d/*.conf"

## reads optional conf files
include_shell "/etc/lighttpd/opts.sh mime.conf compress.conf"
