clean up
sophuwu sophie@sophuwu.com
Mon, 21 Jul 2025 22:21:50 +0200
3 files changed,
44 insertions(+),
34 deletions(-)
M
extra/manhttpd-passwd
→
extra/manhttpd-passwd
@@ -7,22 +7,57 @@ echo "This script must be run as root or with sudo" 1>&2
exit 1 fi -if [[ "$1" == "" ]]; then - echo 'usage: manhttpd-passwd <username>' +helpMenu() { + echo 'usage: manhttpd-passwd [-c /path/to/manhttpd.conf] <username>' + echo ' -c: specify the path to the manhttpd.conf file, otherwise the default' + echo ' will be used (/etc/manhttpd/manhttpd.conf)' + echo + echo ' if the username already exists, the password for that user will be changed' + echo ' if the username does not exist, a new user will be created' + echo ' if a username exists and no password is given, the user will be deleted' +} + +if [[ "$1" == "" || "$#" == "0" ]] ]]; then + helpMenu exit 1 fi if [[ "$1" == "--help" || "$1" == "-h" || "$1" == "-?" || "$1" == "help" ]]; then - sudo -u manhttpd /usr/bin/manhttpd --help + helpMenu exit 0 fi -declare runing="no" + +manhttpd_running() { + echo "manhttpd is running" + echo "Please stop all instances of manhttpd before running this script." +} + +echo "Checking if manhttpd is running..." systemctl is-active manhttpd >/dev/null 2>&1 if [[ "$?" == "0" ]]; then - runing="yes" - systemctl stop manhttpd + manhttpd_running + exit 1 +fi +ps x | grep -E '/.*bin.*/manhttpd$' > /dev/null 2>&1 +if [[ "$?" == "0" ]]; then + manhttpd_running + exit 1 fi -sudo -u manhttpd /usr/bin/manhttpd -pu $@ -if [[ "$runing" == "yes" ]]; then - systemctl start manhttpd + +confFile="/etc/manhttpd/manhttpd.conf" +if [[ "$#" == "3" && "$1" == "-c" ]]; then + if [[ ! "$2" == *".conf" || ! -f "$2" ]]; then + echo "File $2 does not exist or is not a conf file." + exit 1 + fi + confFile="$2" + username="$3" +elif [[ "$#" == "1" ]]; then + username="$1" +else + helpMenu + exit 1 fi +sudo -u manhttpd /usr/bin/manhttpd -c "$confFile" -pu "$username" + +
M
main.go
→
main.go
@@ -163,18 +163,6 @@ }
PageHandler.ServeHTTP(w, r) }) -type ManHandler struct { - h http.Handler -} - -func (m ManHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if r.URL.Query().Has("static") { - StaticHandler(w, r) - return - } - m.h.ServeHTTP(w, r) -} - func StaticHandler(w http.ResponseWriter, r *http.Request) { q := r.URL.Query().Get("static") if f, ok := embeds.StaticFile(q); ok {
M
manpage/manpage.go
→
manpage/manpage.go
@@ -86,16 +86,3 @@ }
embeds.WriteHtml(w, r, m.Title(), html, q, m.Url()) return true } - -// var ManDotName = regexp.MustCompile(`^([^ ]+?)(?:\.([0-9a-z]+))?$`) -// -// func New(s string) (m ManPage) { -// name := ManDotName.FindStringSubmatch(s) -// if len(name) >= 2 { -// m.Name = name[1] -// } -// if len(name) >= 3 { -// m.Section = name[2] -// } -// return -// }