From 38a195c6e62dfebed3c0c642ec9e3fcc89516097 Mon Sep 17 00:00:00 2001 From: tjpcc Date: Tue, 10 Oct 2023 14:49:08 -0600 Subject: "cmd" modifier to override CGI executable fixes #6 --- parse.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'parse.go') diff --git a/parse.go b/parse.go index 0fe3f30..d087e95 100644 --- a/parse.go +++ b/parse.go @@ -293,6 +293,10 @@ func validateRoute(serverType string, dir *RouteDirective) error { return fmt.Errorf("titan modifier only allowed on gemini{static}") } + if dir.Modifiers.ExecCmd != "" && !(dir.Type == "cgi" || (dir.Type == "static" && dir.Modifiers.Exec)) { + return fmt.Errorf("'cmd' modifier only valid on 'cgi' and 'static...with exec' directives") + } + return nil } @@ -410,6 +414,21 @@ func parseModifiers(text string) (Modifiers, string, error) { mod.DirList = true case "exec": mod.Exec = true + case "cmd": + if sep != " " { + return mod, "", errors.New("invalid 'cmd' clause") + } + text = strings.TrimLeft(text, " \t") + idx = strings.IndexAny(text, " \t,") + if idx == 0 { + return mod, "", errors.New("invalid 'cmd' clause") + } else if idx < 0 { + mod.ExecCmd = text + text = "" + } else { + mod.ExecCmd = text[0:idx] + text = text[idx+1:] + } case "extendedgophermap": mod.ExtendedGophermap = true case "autoatom": -- cgit v1.2.3