git.sophuwu.com > manhttpd
some tidying
sophuwu sophie@sophuwu.com
Wed, 16 Jul 2025 19:05:07 +0200
commit

e0d8eb8af340a8617d04a4d0d8e5e790190a5c60

parent

5e03728a4a65a3792f7211e4264121f5d6644c25

M CFG/CFG.goCFG/CFG.go

@@ -4,13 +4,13 @@ import (

"context" "errors" "fmt" + "git.sophuwu.com/manhttpd/neterr" "golang.org/x/sys/unix" "log" "net/http" "os" "os/exec" "os/signal" - "sophuwu.site/manhttpd/neterr" "strings" )
M README.mdREADME.md

@@ -46,7 +46,7 @@ ## Compiling The Binary

```sh # download the source code -git clone "https://sophuwu.site/manhttpd" && cd manhttpd +git clone "https://git.sophuwu.com/manhttpd" && cd manhttpd # build the binary with go go build -ldflags="-s -w" -trimpath -o build/manhttpd

@@ -65,10 +65,9 @@

### Variables in the service file: Environment Variables:\ -`HOSTNAME`: Used for http proxying.\ +`HOSTNAME`: Used for displaying the hostname on the webpage.\ `ListenPort`: If unset, the server will default to 8082.\ `ListenAddr`: This should be changed if you are on a public network.\ -`MANDOCPATH`: Path to the mandoc executable. If unset, the server will attempt to find it in the PATH. ### System Variables:
M embeds/embeds.goembeds/embeds.go

@@ -4,12 +4,12 @@ import (

"embed" _ "embed" "fmt" + "git.sophuwu.com/manhttpd/CFG" + "git.sophuwu.com/manhttpd/neterr" "html/template" "io/fs" "net/http" "path/filepath" - "sophuwu.site/manhttpd/CFG" - "sophuwu.site/manhttpd/neterr" ) //go:embed template/index.html

@@ -89,12 +89,12 @@ f, ok := files[name]

return &f, ok } -func WriteError(w http.ResponseWriter, r *http.Request, err neterr.NetErr) { +func WriteError(w http.ResponseWriter, r *http.Request, err neterr.NetErr, q string) { p := Page{ Title: err.Error().Title(), Hostname: CFG.HttpHostname(r), Content: template.HTML(err.Error().Content()), - Query: r.URL.RawQuery, + Query: q, } t.ExecuteTemplate(w, "index.html", p) }
M extra/manhttpd.serviceextra/manhttpd.service

@@ -1,9 +1,9 @@

[Unit] -Description=front end service for parsing man into html over http +Description=manhttpd - HTTP server for serving manual pages After=network.target [Service] -ExecStart=/usr/bin/manhttpd /etc/manhttpd/manhttpd.conf +ExecStart=/usr/bin/manhttpd WorkingDirectory=/var/lib/manhttpd Type=simple
M extra/nfpm.yamlextra/nfpm.yaml

@@ -26,7 +26,7 @@ - Full regex name and description search

It is useful for serving manpages over a network, or for browsing them in a web browser. vendor: "sophuwu.site" -homepage: "https://sophuwu.site/manhttpd" +homepage: "https://git.sophuwu.com/manhttpd" license: "MIT" changelog: "" contents:
M extra/postinstall.shextra/postinstall.sh

@@ -1,19 +1,16 @@

#!/bin/bash -if [[ -f /etc/manhttpd.service ]]; then - mv /etc/manhttpd.service /etc/manhttpd/manhttpd.service +if [ -f /etc/manhttpd/manhttpd.service ]; then + ln -sf /etc/manhttpd/manhttpd.service /etc/systemd/system/manhttpd.service fi -if [[ -f /etc/manhttpd/manhttpd.service ]]; then - ln -s /etc/manhttpd/manhttpd.service /etc/systemd/system/manhttpd.service -fi -if [[ ! -d /var/lib/manhttpd ]]; then + +if [ ! -d /var/lib/manhttpd ]; then mkdir -p /var/lib/manhttpd fi -chown manhttpd:manhttpd /var/lib/manhttpd -if [[ -f /etc/manhttpd/manhttpd.conf ]]; then - mv /etc/manhttpd/manhttpd.conf /etc/manhttpd/manhttpd.conf.bak - printf "%s %s\n" "hostname" "$(hostname)" >> /etc/manhttpd/manhttpd.conf +if [ -d /var/lib/manhttpd ]; then + chown manhttpd:manhttpd /var/lib/manhttpd + chmod 755 /var/lib/manhttpd fi systemctl daemon-reload
M extra/preinst.shextra/preinst.sh

@@ -1,24 +1,24 @@

#!/bin/bash getent group manhttpd > /dev/null -if [[ $? -ne 0 ]]; then +if [ $? -ne 0 ]; then addgroup --system manhttpd fi getent passwd manhttpd > /dev/null -if [[ $? -ne 0 ]]; then +if [ $? -ne 0 ]; then adduser --system --disabled-password --home /var/lib/manhttpd --no-create-home --group manhttpd manhttpd fi - - -if [[ ! -d /var/lib/manhttpd ]]; then +if [ ! -d /var/lib/manhttpd ]; then mkdir -p /var/lib/manhttpd +fi + +if [ -d /var/lib/manhttpd ]; then chown manhttpd:manhttpd /var/lib/manhttpd - chmod 755 /var/lib/manhttpd + chmod 0775 /var/lib/manhttpd fi -# Create the configuration directory for manhttpd -if [[ ! -d /etc/manhttpd ]]; then +if [ ! -d /etc/manhttpd ]; then mkdir -p /etc/manhttpd fi
M go.modgo.mod

@@ -1,4 +1,4 @@

-module sophuwu.site/manhttpd +module git.sophuwu.com/manhttpd go 1.23.0
M main.gomain.go

@@ -2,13 +2,13 @@ package main

import ( "fmt" + "git.sophuwu.com/manhttpd/CFG" + "git.sophuwu.com/manhttpd/embeds" + "git.sophuwu.com/manhttpd/manpage" + "git.sophuwu.com/manhttpd/neterr" "net/http" "os/exec" "regexp" - "sophuwu.site/manhttpd/CFG" - "sophuwu.site/manhttpd/embeds" - "sophuwu.site/manhttpd/manpage" - "sophuwu.site/manhttpd/neterr" "strings" )

@@ -27,7 +27,7 @@

func SearchHandler(w http.ResponseWriter, r *http.Request) { err := r.ParseForm() if neterr.Err400.Is(err) { - embeds.WriteError(w, r, neterr.Err400) + embeds.WriteError(w, r, neterr.Err400, r.Form.Get("q")) return } q := r.Form.Get("q")

@@ -60,7 +60,7 @@

cmd := exec.Command(CFG.DbCmd, args...) b, e := cmd.Output() if len(b) < 1 || e != nil { - embeds.WriteError(w, r, neterr.Err404) + embeds.WriteError(w, r, neterr.Err404, q) return } var output string

@@ -103,7 +103,7 @@ if name != "" {

man := manpage.New(name) html, nerr = man.Html() if nerr != nil { - embeds.WriteError(w, r, nerr) + embeds.WriteError(w, r, nerr, name) return } title = man.Name
M manpage/manpage.gomanpage/manpage.go

@@ -2,10 +2,10 @@ package manpage

import ( "fmt" + "git.sophuwu.com/manhttpd/CFG" + "git.sophuwu.com/manhttpd/neterr" "os/exec" "regexp" - "sophuwu.site/manhttpd/CFG" - "sophuwu.site/manhttpd/neterr" "strings" )

@@ -44,7 +44,7 @@ })

return html, nil } -var ManDotName = regexp.MustCompile(`^([a-zA-Z0-9_\-]+)(?:\.([0-9a-z]+))?$`) +var ManDotName = regexp.MustCompile(`^([^ ]+)(?:\.([0-9a-z]+))?$`) func New(s string) (m ManPage) { name := ManDotName.FindStringSubmatch(s)