Browse Source

mimetypes fix

Danja Vasiliev 10 years ago
parent
commit
21283f3db3

+ 74 - 25
openwrt/common/etc/lighttpd/lighttpd.conf

@@ -7,6 +7,7 @@ server.modules = (
  "mod_alias",
  "mod_auth",
  "mod_setenv",
+ "mod_dirlisting",
 # "mod_status",
 # "mod_alias",
 # "mod_redirect",
@@ -22,6 +23,9 @@ server.username = "httpd"
 server.groupname = "nogroup"
 server.port = 80
 
+dir-listing.activate = "enable"
+dir-listing.hide-dotfiles = "enable"
+
 ## defines var.superglueVersion from /etc/superglue_version
 include_shell "/etc/lighttpd/vars.sh"
 
@@ -40,52 +44,97 @@ 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" )
+compress.cache-dir = "/www/htdocs/tmp/compress"
+compress.max-filesize = "1024" 
+compress.filetype = (
+    "application/atom+xml",
+    "application/javascript",
+    "application/json",
+    "application/rss+xml",
+    "application/vnd.ms-fontobject",
+    "application/x-font-ttf",
+    "application/x-web-app-manifest+json",
+    "application/xhtml+xml",
+    "application/xml",
+    "application/font-sfnt",
+    "font/opentype",
+    "image/svg+xml",
+    "image/x-icon",
+    "text/css",
+    "text/html",
+    "text/plain",
+    "text/x-component",
+    "text/xml",
+)
 
-index-file.names = ( "index.html", "default.html" )
+index-file.names = (
+    "index.html", 
+    "default.html"
+)
 
-cgi.assign = ( ".sh" => "/bin/bash",
-                ".cgi" => "" )
+cgi.assign = (
+    ".sh"   =>  "/bin/bash",
+    ".cgi"  =>  "",
+)
 
-url.access-deny = ( "~", ".inc", ".htaccess", ".htpasswd", "htpasswd")
+url.access-deny = ( "~", ".inc", ".htaccess", ".htpasswd", "htpasswd", "/tmp/" )
 
 $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" )
+  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"
+  )
+  ## override content and mime type for dotless files to text/html  
+  $HTTP["url"] !~ "(\.)" {                                                                 
+    setenv.add-response-header = (                                                         
+      "X-Superglue-Dotless" => "text/html Content-Type was forced",                        
+      "Content-Type" => "text/html"                                                        
+    )                                                                                      
+  }
 }
 
 $HTTP["request-method"] == "POST" {
 #  url.rewrite = ( "^(/(?!admin).*)" => "post.cgi",
-  url.rewrite = ( "^(/(?!admin).*)" => "post.sh",
-                  "^(/(admin).*)" => "admin.sh" 
+  url.rewrite = (
+    "^(/(?!admin).*)" =>  "post.sh",
+    "^(/(admin).*)"   =>  "admin.sh" 
   )
 #  $HTTP["url"] =~ "^/post.cgi" {
   $HTTP["url"] =~ "^/post.sh" {
     server.document-root = "/www/lib/cgi"
-  }
+  },
   $HTTP["url"] =~ "^/admin.sh" {
     server.document-root = "/www/lib/admin"
-   }
+  }
 }
 
 auth.require = ( 
 #  "/post.cgi" => ( "method" => "digest", 
 #                  "realm" => "superglue", 
 #                  "require" => "valid-user" ),
-  "/post.sh" => ( "method" => "digest", 
-                  "realm" => "superglue", 
-                  "require" => "valid-user" ),
-  "/admin" => ( "method" => "digest", 
-                  "realm" => "superglue", 
-                  "require" => "valid-user" )
+  "/post.sh" => (
+    "method"  =>  "digest", 
+    "realm"   =>  "superglue", 
+    "require" =>  "valid-user"
+  ),
+  "/admin"  => (
+    "method"  =>  "digest", 
+    "realm"   =>  "superglue", 
+    "require" =>  "valid-user"
+  ),
+  "/logs"  => (
+    "method"  =>  "digest", 
+    "realm"   =>  "superglue", 
+    "require" =>  "valid-user"
+  )
 )
 
 include "/etc/lighttpd/mime.conf"

+ 71 - 64
openwrt/common/etc/lighttpd/mime.conf

@@ -1,82 +1,89 @@
-#######################################################################
-##
-##  MimeType handling
-## -------------------
-##
-## http://www.lighttpd.net/documentation/configuration.html#mimetypes
-##
-## Use the "Content-Type" extended attribute to obtain mime type if
-## possible
-##
 mimetype.use-xattr        = "disable"
 
-##
-## mimetype mapping
-##
+## Superglue mimetype mapping
+## Dotless files are handled as text/html using ULR matching,
+## see lightttpd.conf
 mimetype.assign             = (
-  ".pdf"          =>      "application/pdf",
-  ".sig"          =>      "application/pgp-signature",
-  ".spl"          =>      "application/futuresplash",
+  ".appcache"     =>      "text/cache-manifest" ,
+  ".asc"          =>      "text/plain",
+  ".asf"          =>      "video/x-ms-asf",
+  ".asx"          =>      "video/x-ms-asf",
+  ".avi"          =>      "video/x-msvideo",
+  ".bz2"          =>      "application/x-bzip",
   ".class"        =>      "application/octet-stream",
-  ".ps"           =>      "application/postscript",
-  ".torrent"      =>      "application/x-bittorrent",
+  ".conf"         =>      "text/plain",
+  ".cpp"          =>      "text/plain",
+  ".crx"          =>      "application/x-chrome-extension",
+  ".css"          =>      "text/css",
+  ".c"            =>      "text/plain",
+  ".dtd"          =>      "text/xml",
   ".dvi"          =>      "application/x-dvi",
-  ".gz"           =>      "application/x-gzip",
-  ".pac"          =>      "application/x-ns-proxy-autoconfig",
-  ".swf"          =>      "application/x-shockwave-flash",
-  ".tar.gz"       =>      "application/x-tgz",
-  ".tgz"          =>      "application/x-tgz",
-  ".tar"          =>      "application/x-tar",
-  ".zip"          =>      "application/zip",
-  ".mp3"          =>      "audio/mpeg",
-  ".m3u"          =>      "audio/x-mpegurl",
-  ".wma"          =>      "audio/x-ms-wma",
-  ".wax"          =>      "audio/x-ms-wax",
-  ".ogg"          =>      "application/ogg",
-  ".wav"          =>      "audio/x-wav",
+  ".eot"          =>      "application/vnd.ms-fontobject",
   ".gif"          =>      "image/gif",
-  ".jpg"          =>      "image/jpeg",
-  ".jpeg"         =>      "image/jpeg",
-  ".png"          =>      "image/png",
-  ".xbm"          =>      "image/x-xbitmap",
-  ".xpm"          =>      "image/x-xpixmap",
-  ".xwd"          =>      "image/x-xwindowdump",
-  ".css"          =>      "text/css",
+  ".gz"           =>      "application/x-gzip",
+  ".htc"          =>      "text/x-component",
   ".html"         =>      "text/html",
   ".htm"          =>      "text/html",
+  ".ico"          =>      "image/x-icon",
+  ".jar"          =>      "application/x-java-archive",
+  ".jpeg"         =>      "image/jpeg",
+  ".jpg"          =>      "image/jpeg",
+  ".json"         =>      "application/json",
   ".js"           =>      "text/javascript",
-  ".asc"          =>      "text/plain",
-  ".c"            =>      "text/plain",
-  ".cpp"          =>      "text/plain",
   ".log"          =>      "text/plain",
-  ".conf"         =>      "text/plain",
-  ".text"         =>      "text/plain",
-  ".txt"          =>      "text/plain",
-  ".spec"         =>      "text/plain",
-  ".dtd"          =>      "text/xml",
-  ".xml"          =>      "text/xml",
-  ".mpeg"         =>      "video/mpeg",
-  ".mpg"          =>      "video/mpeg",
+  ".m3u"          =>      "audio/x-mpegurl",
+  ".manifest"     =>      "text/cache-manifest" ,
   ".mov"          =>      "video/quicktime",
-  ".qt"           =>      "video/quicktime",
-  ".avi"          =>      "video/x-msvideo",
-  ".asf"          =>      "video/x-ms-asf",
-  ".asx"          =>      "video/x-ms-asf",
-  ".wmv"          =>      "video/x-ms-wmv",
-  ".bz2"          =>      "application/x-bzip",
-  ".tbz"          =>      "application/x-bzip-compressed-tar",
-  ".tar.bz2"      =>      "application/x-bzip-compressed-tar",
-  ".rpm"          =>      "application/x-rpm",
+  ".mp3"          =>      "audio/mpeg",
   ".mp4"          =>      "video/mp4",
-  ".webm"         =>      "video/webm; codecs='vorbis'",
+  ".mpeg"         =>      "video/mpeg",
+  ".mpg"          =>      "video/mpeg",
+  ".oex"          =>      "application/x-opera-extension",
+  ".oga"          =>      "audio/ogg",
+  ".ogg"          =>      "application/ogg",
   ".ogv"          =>      "video/ogg",
-  ".ttf"          =>  	  "application/font-sfnt",
   ".otf"          =>  	  "application/font-sfnt",
+  ".pac"          =>      "application/x-ns-proxy-autoconfig",
+  ".pdf"          =>      "application/pdf",
+  ".pem"          =>      "x-pem-file",    
+  ".png"          =>      "image/png",
+  ".ps"           =>      "application/postscript",
+  ".qt"           =>      "video/quicktime",
+  ".rpm"          =>      "application/x-rpm",
+  ".safariextz"   =>      "application/octet-stream",
+  ".sig"          =>      "application/pgp-signature",
+  ".spec"         =>      "text/plain",
+  ".spl"          =>      "application/futuresplash",
   ".svg"          =>      "image/svg+xml",
-  ""              =>      "text/html"
- )
-
+  ".swf"          =>      "application/x-shockwave-flash",
+  ".tar"          =>      "application/x-tar",
+  ".tar.bz2"      =>      "application/x-bzip-compressed-tar",
+  ".tar.gz"       =>      "application/x-tgz",
+  ".tbz"          =>      "application/x-bzip-compressed-tar",
+  ".text"         =>      "text/plain",
+  ".tgz"          =>      "application/x-tgz",
+  ".torrent"      =>      "application/x-bittorrent",
+  ".ttc"          =>      "application/x-font-ttf",
+  ".ttf"          =>  	  "application/font-sfnt",
+  ".txt"          =>      "text/plain",
+  ".vcf"          =>      "text/x-vcard",
+  ".vtt"          =>      "text/vtt",
+  ".wav"          =>      "audio/x-wav",
+  ".wax"          =>      "audio/x-ms-wax",
+  ".webapp"       =>      "application/x-web-app-manifest+json",
+  ".webm"         =>      "video/webm; codecs='vorbis'",
+  ".webp"         =>      "image/webp",
+  ".wma"          =>      "audio/x-ms-wma",
+  ".wmv"          =>      "video/x-ms-wmv",
+  ".woff"         =>      "application/font-woff",
+  ".xbm"          =>      "image/x-xbitmap",
+  ".xml"          =>      "text/xml",
+  ".xpi"          =>      "application/x-xpinstall",
+  ".xpm"          =>      "image/x-xpixmap",
+  ".xwd"          =>      "image/x-xwindowdump",
+  ".zip"          =>      "application/zip",
+  ""              =>      "application/octet-stream"
+)
 
-#
 #######################################################################
 

+ 15 - 19
openwrt/common/etc/rc.local

@@ -23,32 +23,28 @@ mountpoint -q $_SG && (
 
   ## check if index.html is present
   [ -e $_SG/index.html ] || (
-    cp /www/lib/resources/index.html $_SG/default.html
-    chown httpd $_SG/default.html
+      cp /www/lib/resources/index.html $_SG/default.html
+      chown httpd $_SG/default.html
     )
 
   ## check for log directory
-  [ -e $_SG/logs ] || ( mkdir $_SG/logs
-    chown httpd $_SG/logs
+  [ -e $_SG/logs ] || (
+      mkdir $_SG/logs
+      chown httpd $_SG/logs
+      /etc/init.d/lighttpd reload
     )
 
   ## check for tmp directory
-  [ -e $_SG/tmp ] || ( mkdir $_SG/tmp
-    chown httpd $_SG/tmp
+  [ -e $_SG/tmp ] || (
+      mkdir $_SG/tmp
+      chown httpd $_SG/tmp
     )
 
-  ## check symlinking
-#  for i in devTools resources templates; do
-#    [ -L $_SG/$i ] || ln -s /www/lib/$i $_SG/$i
-#  done
-
-  ## if /www/tmp does not exist
-#  [ -d $_SG/tmp ] || (
-#    mkdir $_SG/tmp && chown httpd $_SG/tmp
-#    )
-
-## needed to make lighty use mounted location for logs
-  /etc/init.d/lighttpd restart
-)&
+  ## check for favicon
+  [ -e $_SG/favicon.ico ] || (
+      cp /www/lib/resources/img/favicon.ico $_SG/favicon.ico
+      chown httpd $_SG/favicon.ico
+    )
+)
 
 exit 0