mirror of
https://tildegit.org/solderpunk/molly-brown.git
synced 2025-04-13 09:29:46 +00:00
Allow to disable directory listing
Signed-off-by: Solderpunk <solderpunk@posteo.net>
This commit is contained in:
parent
64a4ff72f0
commit
2068c3b02a
4 changed files with 9 additions and 1 deletions
|
@ -262,6 +262,8 @@ instead of the default "Directory listing" title.
|
|||
The following options allow users to configure various aspects of the
|
||||
directory listing:
|
||||
|
||||
* `DirectoryListing` (boolean): if true, enable directory listing; if false,
|
||||
return 51 Not found (default value true)
|
||||
* `DirectorySort`: A string specifying how to sort files in
|
||||
automatically generated directory listings. Must be one of "Name",
|
||||
"Size" or "Time" (default value "Name").
|
||||
|
|
|
@ -36,6 +36,7 @@ type UserConfig struct {
|
|||
PermRedirects map[string]string
|
||||
MimeOverrides map[string]string
|
||||
CertificateZones map[string][]string
|
||||
DirectoryListing bool
|
||||
DirectorySort string
|
||||
DirectorySubdirsFirst bool
|
||||
DirectoryReverse bool
|
||||
|
@ -70,6 +71,7 @@ func getConfig(filename string) (SysConfig, UserConfig, error) {
|
|||
userConfig.DefaultEncoding = ""
|
||||
userConfig.TempRedirects = make(map[string]string)
|
||||
userConfig.PermRedirects = make(map[string]string)
|
||||
userConfig.DirectoryListing = true
|
||||
userConfig.DirectorySort = "Name"
|
||||
userConfig.DirectorySubdirsFirst = false
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#
|
||||
## Directory listing
|
||||
#
|
||||
#DirectoryListing = true
|
||||
#DirectorySort = "Time"
|
||||
#DirectorySubdirsFirst = false
|
||||
#DirectoryReverse = true
|
||||
|
|
|
@ -318,7 +318,7 @@ func serveDirectory(URL *url.URL, path string, logEntry *LogEntry, conn net.Conn
|
|||
if err == nil && uint64(index_info.Mode().Perm())&0444 == 0444 {
|
||||
serveFile(index_path, index_info, logEntry, conn, config)
|
||||
// Serve a generated listing
|
||||
} else {
|
||||
} else if config.DirectoryListing {
|
||||
listing, err := generateDirectoryListing(URL, path, config)
|
||||
if err != nil {
|
||||
log.Println("Error generating listing for directory " + path + ": " + err.Error())
|
||||
|
@ -329,6 +329,9 @@ func serveDirectory(URL *url.URL, path string, logEntry *LogEntry, conn net.Conn
|
|||
conn.Write([]byte("20 text/gemini\r\n"))
|
||||
logEntry.Status = 20
|
||||
conn.Write([]byte(listing))
|
||||
} else {
|
||||
conn.Write([]byte("51 Not found!\r\n"))
|
||||
logEntry.Status = 51
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue