What's new

Fun with /www/user :)

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

redhat27

Very Senior Member
We all know that you can see the syslog from the web UI. However if you have relocated syslog somewhere else (or even if you haven't), here is an alternate way.

Symlinks from /tmp/syslog.log will still work, but if you use some non-standard logging, just change the DEFAULT_LOG to your log that you'd like to see on the browser

Run the script, and it creates a symlink from your /www/user directory to point to your syslog.log or any log defined on the DEFAULT_LOG.
Note that this change is not permanent (will not survive router boot, as /www/user resides on tmpfs)
 
Here's another one: Say you want to publish a directory listing of any directory/mount that is accessible on your router. You can then use this script to do so.

Save the script to /jffs/scripts, chmod +x it and then run it with the directory you's want to list on the browser: Say you name the script html-dir.sh, then
Code:
/jffs/scripts/html-dir.sh /mnt/NAS/public
/jffs/scripts/html-dir.sh /jffs
/jffs/scripts/html-dir.sh /jffs/scripts
/jffs/scripts/html-dir.sh /opt/var/log
Could be possible ways of calling the script. Those directories are just examples, of course.

What the script does is create a html file in /www/user with the last directory in the tree specified, for example specifying /jffs/scripts as the parameter would create /www/user/scripts.html

Now, the router's built-in webserver is quite limited in what it can serve up, so I've also included a "nag" text to install lighttpd if you do not already have it installed and running.

If you do have lighttpd, it would chose to create the directory listing there and the files will appear as links, it would also create a symlink to the hosting directory location from the document-root of lighttpd. It will list out what it created and also spit out a handy rm -f command to undo the changes it did. Note that lighttpd also supports directory browsing, but you'd need to make some additional changes in order to make that happen (wont be supported out of the box) but using the script will make that happen without enabling any of those settings.

Of course, if you choose to go the lighttpd route, you can also port forward your lighttpd server port so that you can also access the files from outside your local network.

AND goes without saying, if you are exposing your files (especially with the port forward), I'd assume you know the implications of having your files exposed to the world ;)
 
Last edited:
Two thumbs up! I like it. :)
 
Uploaded a second script to display the directory and all subdirectory listing of any directory specified.
Description on post #2
 
Both scripts should now display the final url string correctly, even if you have your router's httpd or httpds running on non-standard ports (for example httpds running on 8443)

No change in the html generation code.
 
Here's another one: Say you want to publish a directory listing of any directory/mount that is accessible on your router. You can then use this script to do so.

Save the script to /jffs/scripts, chmod +x it and then run it with the directory you's want to list on the browser: Say you name the script html-dir.sh, then
Code:
/jffs/scripts/html-dir.sh /mnt/NAS/public
/jffs/scripts/html-dir.sh /jffs
/jffs/scripts/html-dir.sh /jffs/scripts
/jffs/scripts/html-dir.sh /opt/var/log
Could be possible ways of calling the script. Those directories are just examples, of course.

What the script does is create a html file in /www/user with the last directory in the tree specified, for example specifying /jffs/scripts as the parameter would create /www/user/scripts.html

Now, the router's built-in webserver is quite limited in what it can serve up, so I've also included a "nag" text to install lighttpd if you do not already have it installed and running.

If you do have lighttpd, it would chose to create the directory listing there and the files will appear as links, it would also create a symlink to the hosting directory location from the document-root of lighttpd. It will list out what it created and also spit out a handy rm -f command to undo the changes it did. Note that lighttpd also supports directory browsing, but you'd need to make some additional changes in order to make that happen (wont be supported out of the box) but using the script will make that happen without enabling any of those settings.

Of course, if you choose to go the lighttpd route, you can also port forward your lighttpd server port so that you can also access the files from outside your local network.

AND goes without saying, if you are exposing your files (especially with the port forward), I'd assume you know the implications of having your files exposed to the world ;)

Thanks @redhat27, I had some time to try the script. I installed lighttpd first, then ran the script. When I went to the webpage link, I got the message:

Code:
This page would work so much better if you had lighttpd installed and running. If you have entware, you can install it with opkg install lighttpd

It was my understanding I did not need to do any other configuration with lighttpd. Please let me know. Thank you!
 
I suspect the lighttpd is not running, even though it is installed. Can you post:
Code:
ps | grep [l]ighttpd
If you get no output, it means its not running and the page you saw was served by the routers builtin webserver.

If it is not running, you can first try to manually start it with
Code:
/opt/etc/init.d/S80lighttpd start

Did you just install lighttpd? If that is the case, it would probably need a reboot. It should autostart everytime your router boots.
If you had lighttpd from before, it would be worth checking whether /opt/etc/init.d/S80lighttpd has the execute flag on
 
I suspect the lighttpd is not running, even though it is installed. Can you post:
Code:
ps | grep [l]ighttpd
If you get no output, it means its not running and the page you saw was served by the routers builtin webserver.

If it is not running, you can first try to manually start it with
Code:
/opt/etc/init.d/S80lighttpd start

Did you just install lighttpd? If that is the case, it would probably need a reboot. It should autostart everytime your router boots.
If you had lighttpd from before, it would be worth checking whether /opt/etc/init.d/S80lighttpd has the execute flag on
It was not started. I followed the instructions on this link https://www.hqt.ro/lighttpd-web-server-with-php-support-through-entware-ng/, steps 1 thru 6 to get lighttpd working. I now see links on the file names on the webpage. I get the option to save, save as or cancel when I click on them. Would be nice if the contents would display in a new browser tab. Maybe there is an option for that one. More reading..

I will need to reboot after wife 1.0 is done surfing the web to see if lighttpd starts up automatically. If not, I will add the following to services-start per this old thread: https://www.snbforums.com/threads/t...server-with-php-support-through-entware.9310/

Code:
sleep 10
/opt/etc/init.d/S80lighttpd restart

Thanks again for your very kewl and helpful scripts! I am grateful!
 
@Xentrk All you need to do after the lighttpd install is just to start it with:
Code:
/opt/etc/init.d/S80lighttpd start
OR reboot your router.
Nothing else is needed, no PHP or other added installs.

Note that the script will also work without lighttpd, only files will not display as links. That's the fun with /www/user part ;)

The options that you see on clicking the files (with lighttpd running) are totally dependent on your browser: Scripts and other files without extension may offer to download, while pictures and text files may open in the browser. You can almost always right click and save the files. More read on MIME types here
after wife 1.0 is done surfing the web
LOL :D I hope you never need to upgrade :p
Thanks again for your very kewl and helpful scripts! I am grateful!
Thank you for your kind words :)
 
Last edited:
All is good @redhat27! As you said, each browser has different behavior with the file name links on the browser web page.
  1. Edge - gives option to save, save as, or cancel
  2. Chrome - clicking on the link opens up contents in new window. Right click gives the same options as above and more
  3. Firefox - clicking on the link opens up a window with options to open with preferred app (e.g. wordpad) or save file. Right click gives even more options.
 
Very minor formatting changes on html-dir.sh uploaded on github. It will put a line break after each directory, which I think looks better. I will not be making any further changes to this simple script.
 
Code:
# nano /jffs/scripts/html-dir.sh
paste and save..

# chmod 700 /jffs/scripts/*

# /jffs/scripts/html-dir.sh /jffs
sed: br0: No such file or directory
sed: br0: No such file or directory
ln: /jffs/jffs: File exists
Created symlink /jffs and /jffs.html
Please remove [rm -f /jffs /jffs.html] to undo the changes!
/jffs/scripts/html-dir.sh: line 33: can't create /jffs.html: Read-only file system
/jffs/scripts/html-dir.sh: line 40: can't create /jffs.html: Read-only file system
/jffs/scripts/html-dir.sh: line 40: can't create /jffs.html: Read-only file system
........
/jffs/scripts/html-dir.sh: line 40: can't create /jffs.html: Read-only file system
/jffs/scripts/html-dir.sh: line 41: can't create /jffs.html: Read-only file system
You can now see the listing of /jffs from http://router.asus.com:/jffs.htm

# opkg info lighttpd
Package: lighttpd
Version: 1.4.45-1
Depends: libc, libssp, librt, libpthread, libopenssl, libpcre, libpthread
Status: unknown ok not-installed
Section: net
Architecture: armv7soft
MD5Sum: b557801cc6f263d74e6315504b468c3f
Size: 112473
Filename: lighttpd_1.4.45-1_armv7soft.ipk
Description: A flexible and lightweight web server

# opkg update
Downloading http://pkg.entware.net/binaries/armv7/Packages.gz
Updated list of available packages in /opt/var/opkg-lists/packages

# opkg install lighttpd
Installing lighttpd (1.4.45-3) to root...
Downloading http://pkg.entware.net/binaries/armv7/lighttpd_1.4.45-3_armv7soft.ipk
Installing libpcre (8.40-2) to root...
Downloading http://pkg.entware.net/binaries/armv7/libpcre_8.40-2_armv7soft.ipk
Configuring libpcre.
Configuring lighttpd.

# ll /opt/etc/init.d
-rwxr-xr-x    1 admin    root           215 Apr 19 21:03 S80lighttpd*
-rwxr-xr-x    1 admin    root           204 Apr 24 19:52 S81dropbear-offenders*
-rwxr-xr-x    1 admin    root           269 Apr  9 13:01 S88transmission*
-rw-r--r--    1 admin    root          2822 Feb 11 13:26 rc.func
-rwxr-xr-x    1 admin    root           927 Feb 11 13:26 rc.unslung*

# /opt/etc/init.d/S80lighttpd start
 Starting lighttpd...              already running.

# reboot

# /jffs/scripts/html-dir.sh /jffs
sed: br0: No such file or directory
sed: br0: No such file or directory
ln: /jffs/jffs: File exists
Created symlink /jffs and /jffs.html
Please remove [rm -f /jffs /jffs.html] to undo the changes!
/jffs/scripts/html-dir.sh: line 33: can't create /jffs.html: Read-only file system
/jffs/scripts/html-dir.sh: line 40: can't create /jffs.html: Read-only file system
/jffs/scripts/html-dir.sh: line 40: can't create /jffs.html: Read-only file system
......
You can now see the listing of /jffs from http://router.asus.com:/jffs.html

# ps | grep [l]ighttpd
  509 admin    13856 S    /usr/sbin/lighttpd -f /tmp/lighttpd.conf -D
  510 admin    10468 S    /usr/sbin/lighttpd-monitor
  822 admin    10844 S    /usr/sbin/lighttpd-arpping -f br0

same messages above.

browse to http://router.asus.com:/jffs.html

404 Not Found
File not found.

I don't know what is my problem.
 
@Cat Thank you for the diagnostic output. Can you edit your /opt/etc/init.d/S80lighttpd and make sure there are no "-D" parameter in ARGS= line? Also redownload the script from my github. I made a change to grep just the lighttpd process, and not the monitor and arpping
 
There is not "-D" in S80lighttpd created after lighttpd installation. I didn't touch it.
To confirm it, I tried to remove and install lighttpd pkg again.

I am a linux novice. and then.. I can supply only detailed output info.
I can't understand most of linux scripts, and don't know what's going on.

I don't really need the functionality of this script, not in a hurry. you don't need to hurry for me. Just as you contribute to someone, I also want to contribute.

Code:
# opkg remove lighttpd
Removing package lighttpd from root..

# ll /opt/etc/init.d/S80lighttpd
ls: /opt/etc/init.d/S80lighttpd: No such file or directory

# opkg update
Downloading http://pkg.entware.net/binaries/armv7/Packages.gz
Updated list of available packages in /opt/var/opkg-lists/packages

# opkg install lighttpd
Installing lighttpd (1.4.45-3) to root...
Downloading http://pkg.entware.net/binaries/armv7/lighttpd_1.4.45-3_armv7soft.ipk
Configuring lighttpd.

# ll /opt/etc/init.d/S80lighttpd
-rwxr-xr-x    1 admin    root           215 Apr 19 21:03 /opt/etc/init.d/S80lighttpd*

# nano /opt/etc/init.d/S80lighttpd
-------------------
#!/bin/sh

ENABLED=yes
PROCS=lighttpd
ARGS="-f /opt/etc/lighttpd/lighttpd.conf"
PREARGS=""
DESC=$PROCS
PATH=/opt/sbin:/opt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

. /opt/etc/init.d/rc.func
-------------------

# /jffs/scripts/html-dir.sh /jffs
sed: invalid option -- D
BusyBox v1.25.1 (2017-03-29 00:40:13 EDT) multi-call binary.

Usage: sed [-inrE] [-f FILE]... [-e CMD]... [FILE]...
or: sed [-inrE] CMD [FILE]...

    -e CMD    Add CMD to sed commands to be executed
    -f FILE    Add FILE contents to sed commands to be executed
    -i[SFX]    Edit files in-place (otherwise sends to stdout)
        Optionally back files up, appending SFX
    -n    Suppress automatic printing of pattern space
    -r,-E    Use extended regex syntax

If no -e or -f, the first non-option argument is the sed command string.
Remaining arguments are input files (stdin if none).
sed: invalid option -- D
BusyBox v1.25.1 (2017-03-29 00:40:13 EDT) multi-call binary.

Usage: sed [-inrE] [-f FILE]... [-e CMD]... [FILE]...
or: sed [-inrE] CMD [FILE]...

    -e CMD    Add CMD to sed commands to be executed
    -f FILE    Add FILE contents to sed commands to be executed
    -i[SFX]    Edit files in-place (otherwise sends to stdout)
        Optionally back files up, appending SFX
    -n    Suppress automatic printing of pattern space
    -r,-E    Use extended regex syntax

If no -e or -f, the first non-option argument is the sed command string.
Remaining arguments are input files (stdin if none).
ln: /jffs/jffs: File exists
Created symlink /jffs and /jffs.html
Please remove [rm -f /jffs /jffs.html] to undo the changes!
/jffs/scripts/html-dir.sh: line 33: can't create /jffs.html: Read-only file system
/jffs/scripts/html-dir.sh: line 40: can't create /jffs.html: Read-only file system
/jffs/scripts/html-dir.sh: line 40: can't create /jffs.html: Read-only file system
many error msg lines for line 40.... (omitted)
/jffs/scripts/html-dir.sh: line 40: can't create /jffs.html: Read-only file system
/jffs/scripts/html-dir.sh: line 41: can't create /jffs.html: Read-only file system

# lighttpd -h
lighttpd/1.4.45 (ssl) (Apr 19 2017 20:19:31) - a light and fast webserver
usage:
 -f <name>  filename of the config-file
 -m <name>  module directory (default: /opt/lib/lighttpd)
 -i <secs>  graceful shutdown after <secs> of inactivity
 -1         process single (one) request on stdin socket, then exit
 -p         print the parsed config-file in internal form, and exit
 -t         test config-file syntax, then exit
 -tt        test config-file syntax, load and init modules, then exit
 -D         don't go to background (default: go to background)
 -v         show version
 -V         show compile-time features
 -h         show this help

Code:
# /opt/etc/init.d/S80lighttpd stop
 Checking lighttpd...              alive.
 Shutting down lighttpd...              failed.

# /opt/etc/init.d/S80lighttpd stop
 Checking lighttpd...              alive.
 Shutting down lighttpd...              done.

# /opt/etc/init.d/S80lighttpd start
 Starting lighttpd...              already running.

# find / -name lighttpd*
find: ‘/proc/22688’: No such file or directory
find: ‘/proc/22689’: No such file or directory
/tmp/lighttpd.conf
/tmp/lighttpd
/tmp/lighttpd/lighttpd-arpping.pid
/tmp/lighttpd/lighttpd.pid
/tmp/lighttpd/lighttpd-monitor.pid
/tmp/mnt/sda1/entware-ng.arm/etc/lighttpd
/tmp/mnt/sda1/entware-ng.arm/etc/lighttpd/lighttpd.conf
/tmp/mnt/sda1/entware-ng.arm/lib/opkg/info/lighttpd.conffiles
/tmp/mnt/sda1/entware-ng.arm/lib/opkg/info/lighttpd.control
/tmp/mnt/sda1/entware-ng.arm/lib/opkg/info/lighttpd.list
/tmp/mnt/sda1/entware-ng.arm/lib/upgrade/keep.d/lighttpd
/tmp/mnt/sda1/entware-ng.arm/lib/lighttpd
/tmp/mnt/sda1/entware-ng.arm/sbin/lighttpd
/tmp/mnt/sda1/entware-ng.arm/var/log/lighttpd
/usr/lighttpd
/usr/sbin/lighttpd
/usr/sbin/lighttpd-arpping
/usr/sbin/lighttpd-monitor

# cat /tmp/lighttpd.conf
server.modules+=("mod_aicloud_invite")
server.modules+=("mod_aicloud_auth")
server.modules+=("mod_alias")
server.modules+=("mod_aidisk_access")
server.modules+=("mod_aicloud_sharelink")
server.modules+=("mod_query_field_json")
server.modules+=("mod_webdav")
server.modules+=("mod_smbdav")
server.modules+=("mod_compress")
server.modules+=("mod_access")
server.modules+=("mod_auth")
server.port=8082
server.document-root="/tmp/lighttpd/www"
server.upload-dirs=("/tmp/lighttpd/uploads")
server.errorlog="/tmp/lighttpd/err.log"
server.pid-file="/tmp/lighttpd/lighttpd.pid"
server.arpping-interface="br0"
server.errorfile-prefix="/usr/lighttpd/css/status-"
dir-listing.activate="disable"
server.syslog="/tmp/lighttpd/syslog.log"
mimetype.assign = (
".html" => "text/html",
".htm" => "text/html",
".css" => "text/css",
".js" => "text/javascript",
".swf" => "application/x-shockwave-flash",
"" => "application/x-octet-stream")
index-file.names = ( "index.php", "index.html",
"index.htm", "default.htm",
 " index.lighttpd.html" )
 url.access-deny             = ( "~", ".inc" )
 static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
compress.cache-dir          = "/tmp/lighttpd/compress/"
compress.filetype           = ( "application/x-javascript", "text/css", "text/html", "text/plain" )
aicloud.max-sharelink             = 15
$SERVER["socket"]==":8082"{
   url.aicloud-auth-deny = ("query_field.json")
   $HTTP["url"]=~"^/RT-AC68P($|/)"{
       server.document-root = "/"
       alias.url=("/RT-AC68P"=>"/mnt")
       webdav.activate="enable"
       webdav.is-readonly="disable"
       webdav.sqlite-db-name="/tmp/lighttpd/webdav.db"
   }
    else $HTTP["url"]=~"^/smb($|/)"{
        server.document-root = "/"
        alias.url=("/smb"=>"/usr/lighttpd")
        smbdav.auth_ntlm = ("Microsoft-WebDAV","xxBitKinex","WebDrive")
        webdav.activate="enable"
        webdav.is-readonly="disable"
    }
    else $HTTP["url"] =~ "^/favicon.ico$"{
        server.document-root = "/"
        alias.url = ( "/favicon.ico" => "/usr/lighttpd/css/favicon.ico" )
        webdav.activate = "enable"
        webdav.is-readonly = "enable"
    }
    else $HTTP["url"] !~ "^/smb($|/|.)" {
        server.document-root = "smb://"
        smbdav.activate = "enable"
        smbdav.is-readonly = "disable"
        smbdav.always-auth = "enable"
        smbdav.sqlite-db-name = "/tmp/lighttpd/smbdav.db"
        usertrack.cookie-name = "SMBSESSID"
    }
}
$SERVER["socket"]==":443"{
    ssl.pemfile="/etc/server.pem"
    ssl.engine="enable"
   ssl.use-compression="disable"
   ssl.use-sslv2="disable"
   ssl.use-sslv3="disable"
   ssl.honor-cipher-order="enable"
   ssl.cipher-list="ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:AES256-GCM-SHA384:AES256-SHA256:AES256-SHA:AES128-GCM-SHA256:AES128-SHA256:AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;"
   url.aicloud-auth-deny = ("query_field.json")
    $HTTP["url"]=~"^/RT-AC68P($|/)"{
       server.document-root = "/"
       alias.url=("/RT-AC68P"=>"/mnt")
        webdav.activate="enable"
        webdav.is-readonly="disable"
        webdav.sqlite-db-name="/tmp/lighttpd/webdav.db"
    }
    else $HTTP["url"]=~"^/smb($|/)"{
        server.document-root = "/"
        alias.url=("/smb"=>"/usr/lighttpd")
        smbdav.auth_ntlm = ("Microsoft-WebDAV","xxBitKinex","WebDrive")
        webdav.activate="enable"
        webdav.is-readonly="disable"
    }
    else $HTTP["url"] =~ "^/favicon.ico$"{
        server.document-root = "/"
        alias.url = ( "/favicon.ico" => "/usr/lighttpd/css/favicon.ico" )
        webdav.activate = "enable"
        webdav.is-readonly = "enable"
    }
   else $HTTP["url"] =~ "^/aicloud.crt$"{
       server.document-root = "/"
       alias.url = ( "/aicloud.crt" => "/etc/cert.pem" )
       webdav.activate = "enable"
       webdav.is-readonly = "enable"
   }
    else $HTTP["url"] !~ "^/smb($|/|.)" {
        server.document-root = "smb://"
        smbdav.activate = "enable"
        smbdav.is-readonly = "disable"
        smbdav.always-auth = "enable"
        smbdav.sqlite-db-name = "/tmp/lighttpd/smbdav.db"
        usertrack.cookie-name = "SMBSESSID"
    }
}
debug.log-request-header="disable"
debug.log-response-header="disable"
debug.log-request-handling="disable"
debug.log-file-not-found="disable"
debug.log-condition-handling="disable"
 
Last edited:
Code:
# nano /jffs/scripts/html-dir.sh
paste and save..

# chmod 700 /jffs/scripts/*

I prefer chmod 755 /jffs/scripts/* You may need *.* for files with extensions (e.g. html-dir.sh)
 
@Cat I re-upped a new version that should work for you. Please re-download the script and see if that works for you.
 

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top