Project

General

Profile

Getting access to files in directory

Added by fanatic about 5 years ago

Hi, can someone help me with an lighttpd config problem?
I would like to make /system/sdcard/DCIM/motion accesible to view the pics and videos via browser.
I tried to do it by adding the config between BEGIN and END to lighttpd.conf and rebooting without success:

server.document-root = "/system/sdcard/www" 

server.port = 80

# uncomment to allow more exotic hostnames e.g. with underscores
#server.http-parseopt-host-strict = "disable" 

mimetype.assign = (
  ".html" => "text/html",
  ".txt" => "text/plain",
  ".jpg" => "image/jpeg",
  ".png" => "image/png",
  ".css" => "text/css",
  ".js" => "text/javascript",
  ".mp4" => "video/mp4",

# make the default mime type application/octet-stream
  "" => "application/octet-stream" 
)
index-file.names = ( "index.html" )
server.modules = ("mod_auth",
                  "mod_authn_file",
                  "mod_redirect",
                  "mod_rewrite",
                  "mod_cgi",
                  "mod_fastcgi",
                  "mod_dirlisting",
                  "mod_staticfile",
                  "mod_accesslog",
                  "mod_openssl")

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

$SERVER["socket"] == ":443" {
  ssl.engine = "enable" 
  ssl.pemfile = "/system/sdcard/config/lighttpd.pem" 
}

# Support letsencrypt SSL cert paths
# (we don't want to upgrade to SSL nor auth' this path)
$HTTP["url"] !~ "^/.well-known/(.*)" {

    auth.backend                = "htdigest" 
    auth.backend.htdigest.userfile = "/system/sdcard/config/lighttpd.user" 
    auth.require = ( "/" => ("method" => "basic", "realm" => "all", "require" => "user=root"))

    $HTTP["scheme"] == "http" {
        # capture vhost name with regex conditiona -> %0 in redirect pattern
        # must be the most inner block to the redirect rule
        $HTTP["host"] =~ ".*" {
            url.redirect = (".*" => "https://%0$0")
        }
    }
}

#BEGIN: Make motion pictures and videos accessible
$HTTP["url"] =~ "^/motion($|/)" {

  server.document-root = "/system/sdcard/DCIM/motion" 
  url.rewrite = ("^/motion(.*)" => "/$1")
  dir-listing.activate = "enable" 
    dir-listing.hide-dotfiles = "enable" 
    dir-listing.encoding = "utf-8" 
  auth.backend                = "htdigest" 
  auth.backend.htdigest.userfile = "/system/sdcard/config/lighttpd.user" 
  auth.require = ( "/" => ("method" => "basic", "realm" => "all", "require" => "user=root"))

  $HTTP["scheme"] == "http" {
      # capture vhost name with regex conditiona -> %0 in redirect pattern
      # must be the most inner block to the redirect rule
      $HTTP["host"] =~ ".*" {
          url.redirect = (".*" => "https://%0$0")
      }
  }
}
#END: Make motion pictures and videos accessible

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

## where to send error-messages to
server.errorlog             = "/tmp/lighttpd-error.log" 

## CGI (etc) stderr log
server.breakagelog = "/tmp/lighttpd-cgi-stderr.log" 

## accesslog module
accesslog.filename          = "/tmp/lighttpd-access.log" 

What am I doing wrong?

Thanks
fanatic


Replies (5)

RE: Getting access to files in directory - Added by fanatic about 5 years ago

OS: Linux ISA_VERSION=5.5.1.243
Version: lighttpd/1.4.50-devel-lighttpd-1.4.49-7-g26fb8d3e (ssl)

RE: Getting access to files in directory - Added by gstrauss about 5 years ago

url.rewrite = ("^/motion(.*)" => "/$1")

When you rewrite the URL, the config processing runs again, and this time does not match /motion.

I think you might want to look at mod_alias alias.url instead of your url.rewrite

RE: Getting access to files in directory - Added by fanatic about 5 years ago

I think you might want to look at mod_alias alias.url instead of your url.rewrite

lighttpd is running on an ip-camera firmware.

If I add mod_alias to
server.modules = ("mod_alias",
"mod_auth",
...
the webserver cannot be used anymore and I don't get an entry in the logs

I also cannot enable the mod with lighty-enable-mod, because it is not available on the camera firmware.

Is there any other possibility to access the dir?

Maybe with symlinks in document root /system/sdcard/www?
What do I have to change in the config?

Thanks
fanatic

RE: Getting access to files in directory - Added by fanatic about 5 years ago

Symlinks are not possible:
[root@DAFANG:motion]# ln -s /system/sdcard/DCIM/motion/stills .
ln: ./stills: Operation not permitted

Is there any other possibility with the available mods form config?

RE: Getting access to files in directory - Added by gstrauss about 5 years ago

If I add mod_alias to
server.modules = ("mod_alias",
"mod_auth",
...
the webserver cannot be used anymore and I don't get an entry in the logs

Why don't you troubleshoot and fix that problem?
Run a preflight test of the config and look at the error output:
lighttpd -tt -f /etc/lighttpd/lighttpd.conf

    (1-5/5)