forked from solderpunk/molly-brown
move shlex parsing to server startup time
This commit is contained in:
parent
c9838f3f29
commit
50f9d49e6c
13
config.go
13
config.go
|
@ -6,6 +6,8 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/google/shlex"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
|
@ -30,6 +32,8 @@ type Config struct {
|
|||
DirectorySort string
|
||||
DirectoryReverse bool
|
||||
DirectoryTitles bool
|
||||
|
||||
cgiCommandArgs []string
|
||||
}
|
||||
|
||||
type MollyFile struct {
|
||||
|
@ -95,6 +99,15 @@ func getConfig(filename string) (Config, error) {
|
|||
}
|
||||
config.CGIPaths = cgiPaths
|
||||
|
||||
if config.CGICommand != "" {
|
||||
spl, err := shlex.Split(config.CGICommand)
|
||||
if err != nil {
|
||||
return config, err
|
||||
}
|
||||
config.CGICommand = spl[0]
|
||||
config.cgiCommandArgs = spl[1:]
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -13,8 +13,6 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/google/shlex"
|
||||
)
|
||||
|
||||
func handleCGI(config Config, path string, cgiPath string, URL *url.URL, log *LogEntry, errorLog *log.Logger, conn net.Conn) {
|
||||
|
@ -52,12 +50,7 @@ func handleCGI(config Config, path string, cgiPath string, URL *url.URL, log *Lo
|
|||
// Use the CGICommand if provided
|
||||
var script []string
|
||||
if config.CGICommand != "" {
|
||||
spl, err := shlex.Split(config.CGICommand)
|
||||
if err != nil {
|
||||
errorLog.Printf("Failed to split CGICommand: %s\n", err.Error())
|
||||
return
|
||||
}
|
||||
script = spl
|
||||
script = append([]string{config.CGICommand}, config.cgiCommandArgs...)
|
||||
} else {
|
||||
script = []string{scriptPath}
|
||||
}
|
||||
|
|
Reference in New Issue