sophuwu.site > manhttpd
search handler
sophuwu sophie@skisiel.com
Thu, 11 Jan 2024 04:01:18 +0100
commit

8eb118266cd1f2bb607801ac9b7bfe6a9e947806

parent

62138c6265b4736d768b7e5cbbe594c5503a436e

1 files changed, 16 insertions(+), 2 deletions(-)

jump to
M main.gomain.go

@@ -12,6 +12,8 @@ "os/exec"

"strings" ) +var m2h = "/home/sophuwu/Documents/project/manpages/build/mh.2" + //go:embed index.html var index []byte

@@ -106,7 +108,7 @@ err := ReadFh(&buff, m.Path)

if err != nil { return err } - cmd := exec.Command("/home/sophuwu/Documents/project/manpages/build/mh.2", "-H", CFG.Hostname+":"+CFG.ListenPort, "-M", "/", "-") + cmd := exec.Command(m2h, "-H", CFG.Hostname+":"+CFG.ListenPort, "-M", "/", "-") cmd.Stdin = &buff b, e := cmd.Output() if e != nil {

@@ -150,7 +152,19 @@ return m.FindPath()

} func searchHandler(w http.ResponseWriter, r *http.Request) { - + r.ParseForm() + args := "-l\n-" + strings.Join(r.Form["arg"], "\n-") + search := strings.ReplaceAll(r.Form["search"][0], "\r", "") + args += "\n" + search + cmd := exec.Command("apropos", strings.Split(args, "\n")...) + cmd.Env = append(cmd.Env, os.Environ()...) + cmd.Env = append(cmd.Env, "MANPATH="+CFG.MANPATH) + b, e := cmd.Output() + if e != nil { + } + w.Header().Set("Content-Type", "text/html; charset=utf-8") + w.WriteHeader(http.StatusOK) + w.Write(b) } func indexHandler(w http.ResponseWriter, r *http.Request) {