caddy icon indicating copy to clipboard operation
caddy copied to clipboard

Feature Request: Enhancement or Alternative to Hide Directive

Open ghost opened this issue 5 years ago • 8 comments

I briefly popped into an issue a long time ago here: https://github.com/caddyserver/caddy/issues/370#issuecomment-459136699

Copy and paste of relevant bits:


Let's say this is my Caddyfile:

open.example.com {
  root /var/www/opendirectory
  browse
}

Inside of /var/www/opendirectory let's say we have Folder1, Folder2, and Folder3. As of this moment, browse will list all 3 folders if you went to open.example.com in a browser.

What fancyindex_ignore does with nginx is allow you to set a folder (or files) to be ignored so when the webpage is generated, a certain folder is not listed.

Let's say we had the following:

fancyindex_ignore Folder2

On the open.example.com page, you would then only see Folder1 and Folder3 listed, but if someone manually went to open.example.com/Folder2 they'd still see the contents of that folder.

I was hoping that something like that could be accomplished with a theoretical Caddyfile like so:

open.example.com {
  root /var/www/opendirectory
  browse {
    ignore "Folder2"
  }
}

The idea behind this is to keep folders/files easily accessible if linked to someone, but not openly advertised. It's really just basic cosmetic filtering. I think the same thing could be accomplished using text/template, but I'm not entirely sure yet.


Obviously some of the above is different now, requiring file_server and such, but the core idea is still the same. I'm looking to have Caddy mimic nginx's fancyindex_ignore. It's been suggested in the past to take a look at golang's text/template docs. While this is an excellent suggestion, it does little to help someone not well versed in intricacies of either Caddy or golang, unfortunately.

So I humbly request either:

  • An addition to the hide directive that would allow "partial hiding" as described above, or
  • A separate directive that performs "partial hiding" as described above

ghost avatar Sep 15 '20 23:09 ghost

I'm pretty sure the changes in https://github.com/caddyserver/caddy/commit/0ee4378227cf3019dcbaddeb3977ddd28e58429a do exactly this.

Could you try the latest from master to confirm whether it behaves the way you expect?

francislavoie avatar Sep 16 '20 00:09 francislavoie

Sorry for the delay. Finally took the time to build from master with xcaddy, I believe.

Version output:

v2.2.0-rc.1.0.20200915183741-309c1fec622c h1:uqTphfl/ofkjPHmpoc31bVBxQ7GecYOTI6gXkQI+8eI=

Unfortunately, hide still seems to behave as before. If I hide a folder, I still cannot view the contents by manually browsing to that path.

ghost avatar Sep 16 '20 03:09 ghost

That commit does something different. @xnaas is asking for a way to hide files from browse only, but still let them be directly accessed.

I'm not really convinced this is useful since it doesn't actually hide the files (they're still accessible), and as you said, I think this can be done using a custom template. The point of hiding in Caddy's file server is to actually hide the files, which is a separate concept from unlisting them.

Are you the only one who needs this behavior? If so, I think it'd be best to just use a custom template for now. Are there more compelling needs for this? I want to make sure the user base justifies the added complexity this will introduce.

mholt avatar Sep 16 '20 18:09 mholt

Unfortunately, I have no way to query active Caddy users or nginx users "unable to migrate" because of this.

I guess I'll continue asking around to see if anyone can provide a solution to leveraging text/template to unlist a folder.

ghost avatar Sep 16 '20 21:09 ghost

Unfortunately, I have no way to query active Caddy users or nginx users "unable to migrate" because of this.

Usually, users who need a feature will chime in either here or on the forum. That's much more feasible than doing it the other way around. ;)

Right now, I think yours is the only request. Definitely share what you come up with in our wiki though! That will help give us a gauge for its demand/popularity as well.

mholt avatar Sep 16 '20 21:09 mholt

Sorry for bumping an ancient thread here, but I do want the same feature as OP. My use case is a simple mirror site that doesn't have a real homepage. The folder list on a mirror site (like mine at https://mirrors.wsyu.edu.cn/) is usually self-explanatory enough to provide an overview of what it provides.

I don't want to confuse end-users with the existence of folders like ".well-known" but accessing through a direct URL is surely okay. (I just want the default behavior in nginx of hiding unix hidden files in browse mode, which matches the behavior of most desktop file manager applications without enabling an option like "show hidden files".)

I have asked around on social media and I did find others having the same need. Hopefully this could be reconsidered :)

Please let me know if I should open a new thread instead.

felixonmars avatar Dec 22 '23 17:12 felixonmars

Ok. Maybe an unlinked or unlisted (like YouTube) option that works the same as hide except it only hides it from the browse listing.

mholt avatar Dec 24 '23 22:12 mholt

Had another request for this today: https://caddy.community/t/creating-a-new-custom-browse-template/22751

mholt avatar Feb 15 '24 04:02 mholt