mirror of
https://code.rocketnine.space/tslocum/twins.git
synced 2024-11-27 14:38:14 +01:00
Rename ListDirectory as List
This commit is contained in:
parent
7ed7291c6b
commit
be89b61596
6 changed files with 41 additions and 30 deletions
|
@ -120,9 +120,9 @@ When enabled, symbolic links may be accessed. This attribute is disabled by defa
|
||||||
When enabled, hidden files and directories may be accessed. This attribute is
|
When enabled, hidden files and directories may be accessed. This attribute is
|
||||||
disabled by default.
|
disabled by default.
|
||||||
|
|
||||||
##### ListDirectory
|
##### List
|
||||||
|
|
||||||
When enabled, directories without an index file will serve a list their
|
When enabled, directories without an index file will serve a list of their
|
||||||
contents. This attribute is disabled by default.
|
contents. This attribute is disabled by default.
|
||||||
|
|
||||||
##### Input
|
##### Input
|
||||||
|
@ -143,7 +143,19 @@ specific content type for a path.
|
||||||
Forward requests to [FastCGI](https://en.wikipedia.org/wiki/FastCGI) server at
|
Forward requests to [FastCGI](https://en.wikipedia.org/wiki/FastCGI) server at
|
||||||
specified address or path.
|
specified address or path.
|
||||||
|
|
||||||
A `Root` attribute must also be specified to use `FastCGI`.
|
A `Root` attribute must also be specified.
|
||||||
|
|
||||||
|
Connect via Unix socket:
|
||||||
|
|
||||||
|
```
|
||||||
|
unix:///var/run/php.sock
|
||||||
|
```
|
||||||
|
|
||||||
|
Connect via TCP:
|
||||||
|
|
||||||
|
```
|
||||||
|
tcp://127.0.0.1:9000
|
||||||
|
```
|
||||||
|
|
||||||
## End-of-line indicator
|
## End-of-line indicator
|
||||||
|
|
||||||
|
@ -188,7 +200,7 @@ hosts:
|
||||||
path: /sites
|
path: /sites
|
||||||
root: /home/geminirocks/data
|
root: /home/geminirocks/data
|
||||||
cache: 604800 # Cache for 1 week
|
cache: 604800 # Cache for 1 week
|
||||||
listdirectory: true
|
list: true # Enable directory listing
|
||||||
-
|
-
|
||||||
path: ^/(help|info)$
|
path: ^/(help|info)$
|
||||||
root: /home/geminirocks/data/help
|
root: /home/geminirocks/data/help
|
||||||
|
|
|
@ -37,8 +37,8 @@ type pathConfig struct {
|
||||||
// Serve hidden files and directories
|
// Serve hidden files and directories
|
||||||
HiddenFiles bool
|
HiddenFiles bool
|
||||||
|
|
||||||
// List directory entries
|
// List directory
|
||||||
ListDirectory bool
|
List bool
|
||||||
|
|
||||||
// Content type
|
// Content type
|
||||||
Type string
|
Type string
|
||||||
|
@ -156,8 +156,8 @@ func readconfig(configPath string) error {
|
||||||
if defaultPath.HiddenFiles {
|
if defaultPath.HiddenFiles {
|
||||||
serve.HiddenFiles = defaultPath.HiddenFiles
|
serve.HiddenFiles = defaultPath.HiddenFiles
|
||||||
}
|
}
|
||||||
if defaultPath.ListDirectory {
|
if defaultPath.List {
|
||||||
serve.ListDirectory = defaultPath.ListDirectory
|
serve.List = defaultPath.List
|
||||||
}
|
}
|
||||||
if defaultPath.Cache != "" && serve.Cache == "" {
|
if defaultPath.Cache != "" && serve.Cache == "" {
|
||||||
serve.Cache = defaultPath.Cache
|
serve.Cache = defaultPath.Cache
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -6,6 +6,6 @@ require (
|
||||||
github.com/h2non/filetype v1.1.0
|
github.com/h2non/filetype v1.1.0
|
||||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
|
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
|
||||||
github.com/yookoala/gofast v0.4.1-0.20201013050739-975113c54107
|
github.com/yookoala/gofast v0.4.1-0.20201013050739-975113c54107
|
||||||
golang.org/x/tools v0.0.0-20201112185108-eeaa07dd7696 // indirect
|
golang.org/x/tools v0.0.0-20201116165547-1a2739ce1bfb // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
|
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
|
||||||
)
|
)
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -34,8 +34,8 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
|
||||||
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.0.0-20200908211811-12e1bf57a112/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE=
|
golang.org/x/tools v0.0.0-20200908211811-12e1bf57a112/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE=
|
||||||
golang.org/x/tools v0.0.0-20201112185108-eeaa07dd7696 h1:Bfazo+enXJET5SbHeh95NtxabJF6fJ9r/jpfRJgd3j4=
|
golang.org/x/tools v0.0.0-20201116165547-1a2739ce1bfb h1:QEy3Xa/NrmW1ReQDWZq9JhNZaS2eWWumNV6RAEKnQzQ=
|
||||||
golang.org/x/tools v0.0.0-20201112185108-eeaa07dd7696/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
golang.org/x/tools v0.0.0-20201116165547-1a2739ce1bfb/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
|
2
main.go
2
main.go
|
@ -19,7 +19,7 @@ func main() {
|
||||||
log.SetFlags(0)
|
log.SetFlags(0)
|
||||||
|
|
||||||
configFile := flag.String("config", "", "path to configuration file")
|
configFile := flag.String("config", "", "path to configuration file")
|
||||||
flag.BoolVar(&verbose, "verbose", false, "print request and response information")
|
flag.BoolVar(&verbose, "verbose", false, "print request log")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if *configFile == "" {
|
if *configFile == "" {
|
||||||
|
|
21
server.go
21
server.go
|
@ -25,6 +25,8 @@ const (
|
||||||
urlMaxLength = 1024
|
urlMaxLength = 1024
|
||||||
|
|
||||||
geminiType = "text/gemini; charset=utf-8"
|
geminiType = "text/gemini; charset=utf-8"
|
||||||
|
|
||||||
|
logTimeFormat = "2006-01-02 15:04:05"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -214,7 +216,7 @@ func servePath(c *tls.Conn, request *url.URL, serve *pathConfig) (int, int64) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_, err := os.Stat(path.Join(filePath, "index.gemini"))
|
_, err := os.Stat(path.Join(filePath, "index.gemini"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if serve.ListDirectory {
|
if serve.List {
|
||||||
return serveDirList(c, serve, request, filePath), -1
|
return serveDirList(c, serve, request, filePath), -1
|
||||||
}
|
}
|
||||||
return writeStatus(c, statusNotFound), -1
|
return writeStatus(c, statusNotFound), -1
|
||||||
|
@ -387,6 +389,12 @@ func handleConn(c *tls.Conn) {
|
||||||
|
|
||||||
func logEntry(request *url.URL, status int, size int64, elapsed time.Duration) []byte {
|
func logEntry(request *url.URL, status int, size int64, elapsed time.Duration) []byte {
|
||||||
hostFormatted := "-"
|
hostFormatted := "-"
|
||||||
|
pathFormatted := "-"
|
||||||
|
sizeFormatted := "-"
|
||||||
|
if request != nil {
|
||||||
|
if request.Path != "" {
|
||||||
|
pathFormatted = request.Path
|
||||||
|
}
|
||||||
if request.Hostname() != "" {
|
if request.Hostname() != "" {
|
||||||
hostFormatted = request.Hostname()
|
hostFormatted = request.Hostname()
|
||||||
if request.Port() != "" {
|
if request.Port() != "" {
|
||||||
|
@ -395,20 +403,11 @@ func logEntry(request *url.URL, status int, size int64, elapsed time.Duration) [
|
||||||
hostFormatted += ":1965"
|
hostFormatted += ":1965"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
timeFormatted := time.Now().Format("2006-01-02 15:04:05")
|
|
||||||
|
|
||||||
pathFormatted := request.Path
|
|
||||||
if pathFormatted == "" {
|
|
||||||
pathFormatted = "-"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sizeFormatted := "-"
|
|
||||||
if size >= 0 {
|
if size >= 0 {
|
||||||
sizeFormatted = strconv.FormatInt(size, 10)
|
sizeFormatted = strconv.FormatInt(size, 10)
|
||||||
}
|
}
|
||||||
|
return []byte(fmt.Sprintf(`%s - - - [%s] "GET %s Gemini" %d %s %.4f`, hostFormatted, time.Now().Format(logTimeFormat), pathFormatted, status, sizeFormatted, elapsed.Seconds()))
|
||||||
return []byte(fmt.Sprintf(`%s - - - [%s] "GET %s Gemini" %d %s %.4f`, hostFormatted, timeFormatted, pathFormatted, status, sizeFormatted, elapsed.Seconds()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleListener(l net.Listener) {
|
func handleListener(l net.Listener) {
|
||||||
|
|
Loading…
Reference in a new issue