Closed kenneth558 closed 4 years ago
It's the old-school syntax w/single brackets you can use a single "=" in there. If relative/absolute doesn't matter are you saying that the links don't work for you? This project was meant to be very hackable so plz feel free, I haven't worked on this in a while but if you find something wrong I'll fix it. Thanks
I learned a new thing, thank you.
Line 15 mostly: This following inelegant code hack to bashttpd allows drilling down in directories, but coming back up has to be down with the browser's "back" button, so it's usefulness is limited to where entry is always made from a directory closest to root. Plus, (and this is why I run this past you) I am totally unsure if there is a better way to obtain the current directory than using ${line}${dir#/}:
1. function serve_dir_with_tree() {
2. local dir="$1" tree_vers tree_opts basehref x
3. ## HTML 5 compatible way to avoid tree html from generating favicon
4. ## requests in certain browsers, such as browsers in android smartwatches. =)
5. local no_favicon=" <link href=\"data:image/x-icon;base64,${FAVICON}\" rel=\"icon\" type=\"image/x-icon\" />"
6. local tree_page=""
7. local base_server_path="/${2%/}"
8. local navigation_aid="<h1>Tips:</h1><h3>Video snippets are in /var/www/camera_streams/, event snapshots are in /camera_snapshots/ \
9. <br>The most recent video will never play since it is not finished recording</h3>"
10. [ "$base_server_path" = "/" ] && base_server_path=".."
11. local tree_opts="--du -h -a --dirsfirst"
12. add_response_header "Content-Type" "text/html"
13. # The --du option was added in 1.6.0. "/${2%/*}"
14. read _ tree_vers x < <(tree --version)
15. if [[ -z "${dir#/}" ]];then tree_page=$(echo "$navigation_aid";tree -H "${line}" -L 1 "${tree_opts}" -D "${dir}" )
16. else tree_page=$(echo "$navigation_aid";echo "<h3>Use the browser back arrow to navigate upward to the higher directory</h3>";tree -H "${line}${dir#/}" -L 1 "${tree_opts}" -D "${dir}");fi
17. tree_page=$(sed "5 i ${no_favicon}" <<< "${tree_page}")
18. [[ "${tree_vers}" == v1.6* ]]
19. send_response_ok_exit <<< "${tree_page}"
20. }
21.
I recommend you fork a new branch on GitHub and let me know when you've got it working the way you think it should. I'll then clone it and try it out and if I agree with the improvements I'll merge it into my branch. I appreciate your interest in this project, I still use this quite frequently to easily access files on my LAN.
On Mon, Oct 19, 2020 at 7:45 AM Kenneth L Anderson notifications@github.com wrote:
I learned a new thing, thank you.
This following inelegant code hack to bashttpd allows drilling down in directories, but coming back up has to be down with the browser's "back" button, so it's usefulness is limited to where entry is always made from a directory closest to root. Plus, (and this is why I run this past you) I am totally unsure if there is a better way to obtain the current directory than using ${line}${dir#/}:
function serve_dir_with_tree() { local dir="$1" tree_vers tree_opts basehref x
HTML 5 compatible way to avoid tree html from generating favicon
## requests in certain browsers, such as browsers in android smartwatches. =)
local no_favicon=" <link href=\"data:image/x-icon;base64,${FAVICON}\" rel=\"icon\" type=\"image/x-icon\" />" local tree_page="" local base_server_path="/${2%/}" local navigation_aid="
Tips:
Video snippets are in /var/www/camera_streams/, event snapshots are in /camera_snapshots/ \
" [ "$base_server_path" = "/" ] && base_server_path=".." local tree_opts="--du -h -a --dirsfirst" add_response_header "Content-Type" "text/html"
The most recent video will never play since it is not finished recordingThe --du option was added in 1.6.0. "/${2%/*}"
read _ tree_vers x < <(tree --version) if [[ -z "${dir#/}" ]];then tree_page=$(echo "$navigation_aid";tree -H "${line}" -L 1 "${tree_opts}" -D "${dir}" ) else tree_page=$(echo "$navigation_aid";echo "
Use the browser back arrow to navigate upward to the higher directory
";tree -H "${line}${dir#/}" -L 1 "${tree_opts}" -D "${dir}");fi tree_page=$(sed "5 i ${no_favicon}" <<< "${tree_page}") [[ "${tree_vers}" == v1.6* ]] send_response_ok_exit <<< "${tree_page}END at ${dir#/}" }— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/AdamDanischewski/bashttpd/issues/1#issuecomment-712100946, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACNPZ56GPJTTLPL63AFFPF3SLQREBANCNFSM4SVTU47Q .
--
Adam Michael Danischewski
"Cotidie Validiorem"
Software Engineer
55 Austin Place Apt 4P
Staten Island, NY 10304
Phone: (929) 308-9674 • Email: adam.danischewski@gmail.com
OK, I've uploaded what I'm doing while trying to make it clear that I'm appealing for help to avoid having to use the browser "back" button for navigating root-ward. If that can be accomplished, the user would not have to be careful to enter the root-most directory as their first page.
The ball is in your court, now. Thank you! (I've never done this forking thing before, so forgive me if I'm not doing something right)
[ "$base_server_path" = "/" ] && base_server_path=".."
As you can see above, you would not assign (single = sign) to contents of a variable (the $ sign precedes the variable name). I'm sure you want a the = sign to be doubled:
[ "$base_server_path" == "/" ] && base_server_path=".."
(And while I'm submitting an issue, let me just ask how one can go about prepending the proper path to the links that tree makes once you've changed to a new directory by clicking one of them in a browser? What I need is to retrieve the browser's entire address line with the new directory included and have the tree command use it next with the -H option. I've not had any luck making absolute reference links so far, so I'm about to try relative... )