Compare commits

..

No commits in common. "master" and "v0.20.4" have entirely different histories.

30 changed files with 630 additions and 482 deletions

2
.gitignore vendored
View File

@ -3,5 +3,3 @@ go.mod
go.sum go.sum
go.wit.com go.wit.com
gowebd
files/

View File

@ -1,4 +0,0 @@
go.wit.com {
encode zstd gzip
reverse_proxy localhost:3000
}

View File

@ -1,75 +1,15 @@
.PHONY: build all:
git pull
VERSION = $(shell git describe --tags) echo "build it!"
BUILDTIME = $(shell date +%Y.%m.%d) GO111MODULE=off go build -v -x
su -c ./go.wit.com
all: build # su -c "setcap 'cap_net_bind_service=+ep' go.wit.com"
@echo "make build # build"
@echo "make clean # clean build files"
@echo "make run # build and run on port 2233"
@echo "make debian # will build a debian package"
@echo ""
@echo "make restart # restart the daemon"
@echo "make enable # enable daemon on boot"
@echo "make log # watch the daemon log"
build: goimports
GO111MODULE=off go build \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
verbose:
GO111MODULE=off go build -v -x \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
install:
GO111MODULE=off go install \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
prod: build
make stop
cp gowebd /usr/bin/gowebd
# allow the binary to open ports below 1024
setcap 'cap_net_bind_service=+ep' /usr/bin/gowebd
make start
make log
log:
@#systemctl status gowebd.service
journalctl -f -xeu gowebd.service
enable:
systemctl enable gowebd.service
restart:
systemctl stop gowebd.service
systemctl start gowebd.service
start:
systemctl start gowebd.service
stop:
systemctl stop gowebd.service
run: build
./gowebd --port 2233 --repomap resources/repomap --hostname test.wit.com
# setcap 'cap_net_bind_service=+ep' gowebd # allow the binary to open ports below 1024
goimports: goimports:
reset
goimports -w *.go goimports -w *.go
clean: redomod:
rm -f go.* rm -f go.*
rm -f go.wit.com GO111MODULE= go mod init
rm -f gowebd GO111MODULE= go mod tidy
go-mod-clean purge
# makes a .deb package
debian:
rm ~/incoming/gowebd*.deb
go-deb --no-gui --keep-files --repo go.wit.com/apps/gowebd
squash-the-last-3-commits-together:
git rebase -i HEAD~3
git fsck
git prune

3
README
View File

@ -1,3 +0,0 @@
makes the website go.wit.com
TODO: make it generic so it can use different DNS names

19
args.go Normal file
View File

@ -0,0 +1,19 @@
package main
/*
this parses the command line arguements
this enables command line options from other packages like 'gui' and 'log'
*/
import (
"go.wit.com/dev/alexflint/arg"
)
var args struct {
ListRepos bool `arg:"--list-repos" help:"list all repositories"`
}
func init() {
arg.MustParse(&args)
}

27
argv.go
View File

@ -1,27 +0,0 @@
package main
/*
this parses the command line arguements
this enables command line options from other packages like 'gui' and 'log'
*/
import (
"go.wit.com/dev/alexflint/arg"
)
var argv args
type args struct {
ListRepos bool `arg:"--list-repos" help:"list all repositories"`
Port int `arg:"--port" default:"2520" help:"port to run on"`
RepoMap string `arg:"--repomap" default:"/etc/gowebd/repomap" help:"repomap file"`
Hostname string `arg:"--hostname" default:"go.wit.com" help:"hostname to use"`
}
func (args) Version() string {
return "gowebd " + VERSION + " Built on " + BUILDTIME
}
func init() {
arg.MustParse(&argv)
}

16
build
View File

@ -1,16 +0,0 @@
#!/bin/bash -x
# this is the systemd control file
mkdir -p files/lib/systemd/system/
cp gowebd.service files/lib/systemd/system/
# caddy file. propose this as the dir structure caddy should use
mkdir -p files/etc/gowebd/
cp Caddyfile.go.wit.com files/etc/gowebd/
cp resources/Makefile files/etc/gowebd/
# share dir
mkdir -p files/usr/share/gowebd/
cp Makefile files/usr/share/gowebd/
cp -a resources/repomap files/usr/share/gowebd/repomap
cp -a resources files/usr/share/gowebd/

11
control
View File

@ -1,11 +0,0 @@
Source: gowebd
Build-Depends: golang
Package: gowebd
Maintainer: Jeff Carr <jcarr@wit.com>
Architecture: amd64
Depends: caddy
URL: https://go.wit.com/apps/go.wit.com
Description: the go.wit.com website integration with pkg.go.dev
generates a simple website for integration with golang's
packaging system at http://pkg.go.dev/
TODO: generalize this so other people can use it

View File

@ -10,7 +10,7 @@ import (
"go.wit.com/log" "go.wit.com/log"
) )
func dumpClient(accessf, clientf *os.File, r *http.Request) { func dumpClient(r *http.Request) {
var host, url, proto, addr, agent string var host, url, proto, addr, agent string
host = r.Host host = r.Host
@ -105,6 +105,8 @@ func registerClient(f *os.File, r *http.Request) bool {
if name == "Gopath" { if name == "Gopath" {
gopath = value gopath = value
} }
// Giturl https://git.wit.org/gui/go-gui-toolkits.git
// Headers: Gopath
} }
} }

18
exit.go
View File

@ -1,18 +0,0 @@
package main
import (
"os"
"go.wit.com/log"
)
func okExit(thing string) {
log.Info(thing, "ok")
// log.Info("Finished go-clean on", check.GetGoPath(), "ok")
os.Exit(0)
}
func badExit(err error) {
log.Info("go-gui-toolkits failed: ", err)
os.Exit(-1)
}

View File

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

200
files/index.html Normal file
View File

@ -0,0 +1,200 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="skeleton.v2.css" />
<style>
#footer {
position: fixed;
padding: 1% 0% 1% 0%; /* top left bottom right */
bottom: 0;
width: 100%;
/* Height of the footer*/
height: 40px;
background: lightgrey;
}
</style>
</head>
</html>
<body>
<div class="container">
<div class="row">
<table class="u-full-width">
<thead>
<tr>
<th>Package</th>
<th>go get</th>
<th>Authoritative sources (IPv6 only)</th>
<th>github mirror</th>
<th>Documentation</th>
</tr>
</thead>
<tbody>
<tr> <td><h5>log/ (needed for the gui)</h5></td> <td></td> <td></td> <td></td> <td></td> </tr>
<tr>
<td>log</td>
<td> <a href="//go.wit.com/log">go.wit.com/log</a></td>
<td> <a href="//git.wit.org/wit/log">git.wit.org/wit/log</a></td>
<td> <a href="//github.com/wit-go/log">github.com/wit-go/log</a></td>
<td> <a href="//pkg.go.dev/go.wit.com/log"> <img src="goReference.svg" alt="Go Reference" /> </a> </td>
</tr>
<tr> <td></td> <td></td> <td></td> <td></td> <td></td> </tr>
<tr> <td><h5>gui/ packages</h5></td> <td></td> <td></td> <td></td> <td></td> </tr>
<tr>
<td>gui/gui</td>
<td> <a href="//go.wit.com/gui/gui">go.wit.com/gui/gui</a></td>
<td> <a href="//git.wit.org/gui/gui">git.wit.org/gui/gui</a></td>
<td> <a href="//github.com/wit-go/gui">github.com/wit-go/gui</a></td>
<td> <a href="//pkg.go.dev/go.wit.com/gui/gui"> <img src="goReference.svg" alt="Go Reference" /> </a> </td>
</tr>
<tr>
<td>gui/widget</td>
<td> <a href="//go.wit.com/gui/widget">go.wit.com/gui/widget</a></td>
<td> <a href="//git.wit.org/gui/widget">git.wit.org/gui/widget</a></td>
<td> <a href="//github.com/wit-go/widget">github.com/wit-go/widget</a></td>
<td> <a href="//pkg.go.dev/go.wit.com/gui/widget"> <img src="goReference.svg" alt="Go Reference" /> </a> </td>
</tr>
<tr>
<td>gui/gadgets</td>
<td> <a href="//go.wit.com/gui/gadgets">go.wit.com/gui/gadgets</a></td>
<td> <a href="//git.wit.org/gui/gadgets">git.wit.org/gui/gadgets</a></td>
<td> <a href="//github.com/wit-go/gadgets">github.com/wit-go/gadgets</a></td>
<td> <a href="//pkg.go.dev/go.wit.com/gui/gadgets"> <img src="goReference.svg" alt="Go Reference" /> </a> </td>
</tr>
<tr>
<td>gui/toolkits</td>
<td> <a href="//go.wit.com/gui/toolkits">go.wit.com/gui/toolkits</a></td>
<td> <a href="//git.wit.org/gui/toolkits">git.wit.org/gui/toolkits</a></td>
<td> <a href="//github.com/wit-go/toolkits">github.com/wit-go/toolkits</a></td>
<td> <a href="//pkg.go.dev/go.wit.com/gui/toolkits"> <img src="goReference.svg" alt="Go Reference" /> </a> </td>
</tr>
<tr>
<td>gui/debugger</td>
<td> <a href="//go.wit.com/gui/debugger">go.wit.com/gui/debugger</a></td>
<td> <a href="//git.wit.org/gui/debugger">git.wit.org/gui/debugger</a></td>
<td> <a href="//github.com/wit-go/debugger">github.com/wit-go/debugger</a></td>
<td> <a href="//pkg.go.dev/go.wit.com/gui/debugger"> <img src="goReference.svg" alt="Go Reference" /> </a> </td>
</tr>
<tr>
<td>gui/examples</td>
<td> <a href="//go.wit.com/gui/examples">go.wit.com/gui/examples</a></td>
<td> <a href="//git.wit.org/gui/examples">git.wit.org/gui/examples</a></td>
<td> <a href="//github.com/wit-go/examples">github.com/wit-go/examples</a></td>
<td> </td>
</tr>
<tr>
<td>gui/digitalocean</td>
<td> <a href="//go.wit.com/gui/digitalocean">go.wit.com/gui/digitalocean</a></td>
<td> <a href="//git.wit.org/gui/digitalocean">git.wit.org/gui/digitalocean</a></td>
<td> </td>
<td> <a href="//pkg.go.dev/go.wit.com/gui/digitalocean"> <img src="goReference.svg" alt="Go Reference" /> </a> </td>
</tr>
<tr>
<td>gui/cloudflare</td>
<td> <a href="//go.wit.com/gui/cloudflare">go.wit.com/gui/cloudflare</a></td>
<td> <a href="//git.wit.org/gui/cloudflare">git.wit.org/gui/cloudflare</a></td>
<td> </td>
<td> <a href="//pkg.go.dev/go.wit.com/gui/cloudflare"> <img src="goReference.svg" alt="Go Reference" /> </a> </td>
</tr>
<tr> <td></td> <td></td> <td></td> <td></td> <td></td> </tr>
<tr> <td><h5>Applications</h5></td> <td></td> <td></td> <td></td> <td></td> </tr>
<tr>
<td>control-panel-dns</td>
<td> <a href="//go.wit.com/apps/control-panel-dns">go.wit.com/apps/control-panel-dns</a></td>
<td> <a href="//git.wit.org/jcarr/control-panel-dns">git.wit.org/jcarr/control-panel-dns</a></td>
<td></td>
<td> <a href="//pkg.go.dev/go.wit.com/apps/control-panels-dns"> <img src="goReference.svg" alt="Go Reference" /> </a> </td>
</tr>
<tr>
<td>control-panel-digitalocean</td>
<td> <a href="//go.wit.com/apps/control-panel-digitalocean">go.wit.com/apps/control-panel-digitalocean</a></td>
<td> <a href="//git.wit.org/wit/control-panel-digitalocean">git.wit.org/wit/control-panel-digitalocean</a></td>
<td></td>
<td> <a href="//pkg.go.dev/go.wit.com/apps/control-panel-digitalocean"> <img src="goReference.svg" alt="Go Reference" /> </a> </td>
</tr>
<tr>
<td>control-panel-cloudflare</td>
<td> <a href="//go.wit.com/apps/control-panel-cloudflare">go.wit.com/apps/control-panel-cloudflare</a></td>
<td> <a href="//git.wit.org/wit/control-panel-cloudflare">git.wit.org/wit/control-panel-cloudflare</a></td>
<td></td>
<td> <a href="//pkg.go.dev/go.wit.com/control-panels/cloudflare"> <img src="goReference.svg" alt="Go Reference" /> </a> </td>
</tr>
<!--
<tr>
<td>control-panel-cloudflare</td>
<td> <a href="//go.wit.com/control-panel-cloudflare">go.wit.com/control-panel-cloudflare</a></td>
<td> <a href="//git.wit.org/wit/control-panel-cloudflare">git.wit.org/wit/control-panel-cloudflare</a></td>
<td> <a href="//github.com/wit-go/control-panel-cloudflare">github.com/wit-go/control-panel-cloudflare</a></td>
<td> <a href="//pkg.go.dev/go.wit.com/control-panel-cloudflare"> <img src="goReference.svg" alt="Go Reference" /> </a> </td>
</tr>
-->
<tr> <td></td> <td></td> <td></td> <td></td> <td></td> </tr>
<tr> <td><h5>Support packages</h5></td> <td></td> <td></td> <td></td> <td></td> </tr>
<!--
<tr>
<td>go-arg</td>
<td> <a href="//go.wit.com/arg">go.wit.com/arg</a></td>
<td> <a href="//git.wit.org/gui/arg">git.wit.org/gui/arg</a></td>
<td> <a href="//github.com/wit-go/shell">github.com/alexflint/go-arg</a></td>
<td> <a href="//pkg.go.dev/go.wit.com/shell"> <img src="goReference.svg" alt="Go Reference" /> </a> </td>
</tr>
-->
<tr>
<td>arg</td>
<td> <a href="//go.wit.com/arg">go.wit.com/arg</a></td>
<td> <a href="//git.wit.org/wit/arg">git.wit.org/wit/arg</a></td>
<td> <a href="//github.com/wit-go/go-arg">github.com/wit-go/go-arg</a></td>
<td> <a href="//pkg.go.dev/go.wit.com/arg"> <img src="goReference.svg" alt="Go Reference" /> </a> </td>
</tr>
<tr>
<td>spew</td>
<td> <a href="//go.wit.com/spew">go.wit.com/spew</a></td>
<td> <a href="//git.wit.org/wit/spew">git.wit.org/wit/spew</a></td>
<td> <a href="//github.com/wit-go/spew">github.com/wit-go/spew</a></td>
<td> <a href="//pkg.go.dev/go.wit.com/spew"> <img src="goReference.svg" alt="Go Reference" /> </a> </td>
</tr>
<tr>
<td>dnssec</td>
<td> <a href="//go.wit.com/dnssec">go.wit.com/dnssec</a></td>
<td> <a href="//git.wit.org/wit/dnssec">git.wit.org/wit/dnssec</a></td>
<td> <a href="//github.com/wit-go/dnssec">github.com/wit-go/dnssec</a></td>
<td> <a href="//pkg.go.dev/go.wit.com/dnssec"> <img src="goReference.svg" alt="Go Reference" /> </a> </td>
</tr>
<tr>
<td>shell</td>
<td> <a href="//go.wit.com/shell">go.wit.com/shell</a></td>
<td> <a href="//git.wit.org/wit/shell">git.wit.org/wit/shell</a></td>
<td> <a href="//github.com/wit-go/shell">github.com/wit-go/shell</a></td>
<td> <a href="//pkg.go.dev/go.wit.com/shell"> <img src="goReference.svg" alt="Go Reference" /> </a> </td>
</tr>
<!--
<tr>
<td></td>
<td> <a href=""></a> </td>
<td> <a href=""> <img src="goReference.svg" alt="Go Reference" /> </a> </td>
</tr>
-->
</tbody>
</table>
</div>
</div>
<!--
<center>
<div id="footer">
simple go git repo list like <a href=http://go.uber.org/>go.uber.org</a><p>
</div>
</center>
-->
</body>
</html>

4
files/install.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash -x
#
echo "TODO: make this work"

53
files/repomap Normal file
View File

@ -0,0 +1,53 @@
# gui core packages
go.wit.com/gui git.wit.org/gui/gui The GUI API intended for Control Panels
go.wit.com/widget git.wit.org/gui/widget Primitive Definitions for Buttons, Dropdowns, etc.
# Tutorials
go.wit.com/apps/helloworld git.wit.org/gui/helloworld A simple Demo
go.wit.com/apps/basicwindow git.wit.org/jcarr/basicwindow A bit more of a Demo
go.wit.com/apps/gadgetwindow git.wit.org/jcarr/gadgetwindow A more complicated Demo used for debugging the toolkits
# Applications
go.wit.com/apps/autotypist git.wit.org/jcarr/autotypist Wrapper around 'git' and 'go' for these repos
go.wit.com/apps/guireleaser git.wit.org/jcarr/guireleaser
go.wit.com/apps/go-deb git.wit.org/jcarr/go-deb Turn a GO package into a .deb package
go.wit.com/apps/control-panel-digitalocean git.wit.org/wit/control-panel-digitalocean A simple Digital Ocean Control Panel
go.wit.com/apps/control-panel-dns git.wit.org/jcarr/control-panel-dns A DNS Control Panel
go.wit.com/apps/control-panel-cloudflare git.wit.org/wit/control-panel-cloudflare
go.wit.com/apps/control-panel-vpn git.wit.org/jcarr/control-panel-vpn
go.wit.com/apps/go.wit.com git.wit.org/jcarr/go.wit.com
go.wit.com/apps/clone-gitea git.wit.org/jcarr/clone-gitea
# gui toolkit packages
go.wit.com/toolkits/gocui git.wit.org/toolkits/gocui A console based GUI (like ncurses)
go.wit.com/toolkits/andlabs git.wit.org/toolkits/andlabs Platform Native GUI (GTK on Linux and Cocoa on MacOS, Winows needs plugin support)
go.wit.com/toolkits/nocui git.wit.org/toolkits/nocui A minimum toolkit plugin using STDIN/STDOUT
go.wit.com/toolkits/tree git.wit.org/toolkits/tree Common plugin code to talk to the GUI
go.wit.com/toolkits/debian git.wit.org/toolkits/debian make a .deb of the toolkit plugin binaries
# log/ (modified for the gui)
go.wit.com/log git.wit.org/wit/log a wrapper attempt around log for the GUI
# gui libraries
go.wit.com/lib/gadgets git.wit.org/gui/gadgets Some common collections of widgets
go.wit.com/lib/debugger git.wit.org/gui/debugger An attempt at a debugger
go.wit.com/lib/gui/repostatus git.wit.org/jcarr/repostatus used by autotypist
go.wit.com/lib/gui/hostname git.wit.org/jcarr/hostname
go.wit.com/lib/gui/linuxstatus git.wit.org/jcarr/hostname for the DNS Control Panel
go.wit.com/lib/gui/logsettings git.wit.org/jcarr/logsettings used for 'log' and debugger
go.wit.com/lib/gui/digitalocean git.wit.org/gui/digitalocean used by the DO control panel
go.wit.com/lib/gui/cloudflare git.wit.org/gui/cloudflare
go.wit.com/lib/gui/shell git.wit.org/wit/shell
go.wit.com/lib/protobuf/wit git.wit.org/wit/witProtobuf
# Support packages (forked for experiments)
go.wit.com/dev/alexflint/arg git.wit.org/jcarr/go-arg slight modifications to arg
go.wit.com/dev/alexflint/scalar git.wit.org/jcarr/go-scalar
go.wit.com/dev/andlabs/ui git.wit.org/interesting/andlabs-ui attempts to add RiscV support
go.wit.com/dev/andlabs/libui git.wit.org/interesting/libui
go.wit.com/dev/davecgh/spew git.wit.org/jcarr/go-spew

11
files/test.html Normal file
View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta name="go-import" content="go.wit.com/gui/gui git https://git.wit.org/gui/gui">
<meta name="go-source" content="go.wit.com/gui/gui https://git.wit.org/gui/gui https://git.wit.org/gui/tree/master{/dir} https://git.wit.org/gui/gui/tree/master{/dir}/{file}#L{line}">
<meta http-equiv="refresh" content="0; url=https://git.wit.org/gui/gui">
</head>
<body>
Nothing to see here. Please <a href="https://git.wit.org/gui/gui">move along</a>.
</body>
</html>

View File

@ -1,13 +0,0 @@
[Unit]
Description=gowebd
[Service]
User=root
Type=simple
ExecStart=/usr/bin/gowebd
ExecStop=killall gowebd
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target

148
http.go
View File

@ -1,148 +0,0 @@
package main
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"strings"
"go.wit.com/log"
)
// remove '?' part and trailing '/'
func cleanURL(url string) string {
url = "/" + strings.Trim(url, "/")
return url
}
func okHandler(w http.ResponseWriter, r *http.Request) {
msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte
if err != nil {
log.Info("ioutil.ReadAll() error =", err)
return
}
// fmt.Fprintln(w, "ioutil.ReadAll() msg =", len(msg))
// dumpClient(accessf, clientf, r)
var route string
// tmp = r.URL.String()
route = cleanURL(r.URL.Path)
parts := strings.Split(route, "?")
log.Info("client sent url =", route, parts)
requrl := parts[0]
url, repourl := findkey(requrl)
log.Warn("gowebd URL =", url, "REPO URL =", repourl, "REQUEST URL =", requrl, "msg =", len(msg))
if repourl != "" {
repoHTML(w, url, repourl)
return
}
if route == "/" {
indexHeader(w)
indexBodyStart(w)
indexBodyScanConfig(w)
indexDivEnd(w)
pfile, err := os.ReadFile(FOOTER)
if err == nil {
fmt.Fprint(w, string(pfile))
} else {
log.Warn(err, "no footer file found in", FOOTER)
log.Warn("falling back to the resources/footer.html")
writeFile(w, "footer.html")
}
indexBodyEnd(w)
return
}
if route == "/install.sh" {
writeFile(w, "install.sh")
return
}
if route == "/me" {
j, err := dumpJsonClient(r)
if err != nil {
fmt.Fprintln(w, "BAD ZOOT")
return
}
fmt.Fprintln(w, j)
return
}
if route == "/register" {
fname := filepath.Join(LIBDIR, "regfile.log")
regfile, _ := os.OpenFile(fname, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if registerClient(regfile, r) {
fmt.Fprintln(w, "OK")
} else {
fmt.Fprintln(w, "FAILED")
}
return
}
if route == "/lookup" {
w.Header().Set("Content-Type", "text")
fmt.Fprintf(w, "go.wit.com/apps/utils/gowebd Version: %s\n", argv.Version())
fmt.Fprintf(w, "\n")
all := forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
fmt.Fprintf(w, "Namespace=%s FullPath=%s %s\n", repo.Namespace, repo.FullPath)
}
return
}
if route == "/goReference.svg" {
writeFile(w, "goReference.svg")
return
}
if route == "/skeleton.v2.css" {
writeFile(w, "skeleton.v2.css")
return
}
if route == "/favicon.ico" {
writeFile(w, "ipv6.png")
return
}
// used for uptime monitor checking
if route == "/uptime" {
writeFile(w, "uptime.html")
return
}
log.Warn("BAD URL =", url, "REPO URL =", repourl)
badurl(w, r.URL.String())
}
func writeFile(w http.ResponseWriter, filename string) {
// fmt.Fprintln(w, "GOT TEST?")
fullname := "resources/" + filename
pfile, err := resources.ReadFile(fullname)
if err != nil {
log.Println("ERROR:", err)
// w.Write(pfile)
return
}
var repohtml string
repohtml = string(pfile)
if filename == "goReference.svg" {
w.Header().Set("Content-Type", "image/svg+xml")
}
fmt.Fprintln(w, repohtml)
log.Println("writeFile() found internal file:", filename)
}
func badurl(w http.ResponseWriter, badurl string) {
fmt.Fprintln(w, "<!DOCTYPE html>")
fmt.Fprintln(w, "<html>")
fmt.Fprintln(w, " <head>")
fmt.Fprintln(w, " <meta http-equiv=\"refresh\" content=\"3; url=https://"+HOSTNAME+"/\">")
fmt.Fprintln(w, " </head>")
fmt.Fprintln(w, " <body>")
fmt.Fprintln(w, " IPv4 IS NOT SUPPORTED<br>")
fmt.Fprintln(w, " MANY OF THESE REPOS REQUIRE IPv6.<br>")
fmt.Fprintln(w, " <br>")
fmt.Fprintln(w, " bad url", badurl, "<a href=\"https://go.wit.com/\">redirecting</a>")
fmt.Fprintln(w, " </body>")
fmt.Fprintln(w, "</html>")
}

View File

@ -3,7 +3,9 @@ package main
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"strconv"
"strings" "strings"
"time"
) )
func indexHeader(w http.ResponseWriter) { func indexHeader(w http.ResponseWriter) {
@ -37,8 +39,8 @@ func indexBodyStart(w http.ResponseWriter) {
fmt.Fprintln(w, " <th>Package (IPv6 only)</th>") fmt.Fprintln(w, " <th>Package (IPv6 only)</th>")
fmt.Fprintln(w, " <th>Documentation</th>") fmt.Fprintln(w, " <th>Documentation</th>")
fmt.Fprintln(w, " <th>Version</th>") fmt.Fprintln(w, " <th>Version</th>")
fmt.Fprintln(w, " <th>Dev Version</th>")
fmt.Fprintln(w, " <th>Age</th>") fmt.Fprintln(w, " <th>Age</th>")
fmt.Fprintln(w, " <th>Dev Version</th>")
fmt.Fprintln(w, " <th>Description</th>") fmt.Fprintln(w, " <th>Description</th>")
// fmt.Fprintln(w, " <th>Authoritative sources (IPv6 only)</th>") // fmt.Fprintln(w, " <th>Authoritative sources (IPv6 only)</th>")
// fmt.Fprintln(w, " <th></th>") // fmt.Fprintln(w, " <th></th>")
@ -97,19 +99,43 @@ func indexBodyRepo(w http.ResponseWriter, gourl string, giturl string, desc stri
// fmt.Fprintln(w, " <td>"+gourl+"</td>") // fmt.Fprintln(w, " <td>"+gourl+"</td>")
fmt.Fprintln(w, " <td> <a href=\"//"+gourl+"\">"+gourl+"</a></td>") fmt.Fprintln(w, " <td> <a href=\"//"+gourl+"\">"+gourl+"</a></td>")
fmt.Fprintln(w, " <td> <a href=\"//pkg.go.dev/"+gourl+"\"> <img src=\"goReference.svg\" alt=\"pkg.go.dev\" /> </a> </td>") fmt.Fprintln(w, " <td> <a href=\"//pkg.go.dev/"+gourl+"\"> <img src=\"goReference.svg\" alt=\"pkg.go.dev\" /> </a> </td>")
var vtime, version, dver string // for i, s := range versionMap {
// log.Println("found i =", i, "with", "s =", s)
// }
var vtime, version string
gourl = strings.TrimSpace(gourl) gourl = strings.TrimSpace(gourl)
if repo, ok := gitMap[gourl]; ok { tmp, _ := versionMap[gourl]
version = repo.GetLastTag() parts := strings.Split(tmp, " ")
age := repo.NewestAge() if len(parts) > 0 {
vtime = formatDuration(age) version = parts[0]
dver = repo.GetDevelVersion() }
if len(parts) > 1 {
vtime = parts[1]
}
if vtime != "" {
// Convert the string to an integer
gitTagTimestampInt, _ := strconv.ParseInt(vtime, 10, 64)
// Parse the Unix timestamp into a time.Time object
gitTagDate := time.Unix(gitTagTimestampInt, 0)
// Get the current time
currentTime := time.Now()
// Calculate the duration between the git tag date and the current time
duration := currentTime.Sub(gitTagDate)
vtime = formatDuration(duration)
} }
// log.Info("gopath", gourl, "dur", vtime, "version", version)
fmt.Fprintln(w, " <td>"+version+"</td>") // version fmt.Fprintln(w, " <td>"+version+"</td>") // version
fmt.Fprintln(w, " <td>"+dver+"</td>") // dev version
fmt.Fprintln(w, " <td>"+vtime+"</td>") // dev version fmt.Fprintln(w, " <td>"+vtime+"</td>") // dev version
if gourl == "go.wit.com/apps/helloworld" {
fmt.Fprintln(w, " <td><a href=\"http://mirrors.wit.com/guidemo/helloworld-demo.webm\">Video Demo</a> </td>") // dev version
} else {
fmt.Fprintln(w, " <td></td>") // dev version
}
fmt.Fprintln(w, " <td>"+desc+"</td>") fmt.Fprintln(w, " <td>"+desc+"</td>")
// fmt.Fprintln(w, " <td> <a href=\"//"+gourl+"\">"+giturl+"</a></td>") // fmt.Fprintln(w, " <td> <a href=\"//"+gourl+"\">"+giturl+"</a></td>")
fmt.Fprintln(w, " </tr>") fmt.Fprintln(w, " </tr>")

View File

@ -17,8 +17,8 @@ type RequestInfo struct {
Headers map[string][]string `json:"headers"` Headers map[string][]string `json:"headers"`
Cookies map[string]string `json:"cookies"` Cookies map[string]string `json:"cookies"`
QueryParams map[string][]string `json:"queryParams"` QueryParams map[string][]string `json:"queryParams"`
Body string `json:"body"`
// Add other fields as needed // Add other fields as needed
Body string `json:"body"`
} }
// dumpClient returns a string with JSON formatted http.Request information // dumpClient returns a string with JSON formatted http.Request information
@ -68,3 +68,41 @@ func dumpJsonClient(r *http.Request) (string, error) {
return string(formattedJSON), nil return string(formattedJSON), nil
} }
/*
package main
import (
"bytes"
"encoding/json"
"io"
"io/ioutil"
"net/http"
)
type RequestInfo struct {
// ... (other fields)
Body string `json:"body"`
// ... (other fields)
}
func dumpClient(r *http.Request) (string, error) {
// ... (rest of your code to collect other request info)
info := RequestInfo{
// ... (other fields)
Body: string(bodyBytes),
// ... (other fields)
}
// Marshal the struct to a JSON string
jsonString, err := json.Marshal(info)
if err != nil {
return "", err
}
return string(jsonString), nil
}
// ... (rest of your code)
*/

172
main.go
View File

@ -4,61 +4,167 @@ import (
"embed" "embed"
"fmt" "fmt"
"net/http" "net/http"
"os"
"strings"
"time" "time"
"go.wit.com/lib/protobuf/forgepb"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log" "go.wit.com/log"
) )
// are sent via -ldflags at buildtime //go:embed files/*
var VERSION string var htmlFiles embed.FS
var BUILDTIME string
//go:embed resources/* var accessf, clientf *os.File
var resources embed.FS
// var accessf, clientf *os.File
var repoMap map[string]string var repoMap map[string]string
var gitMap map[string]*gitpb.Repo var versionMap map[string]string
var configfile []string var configfile []string
var keysSorted []string var keysSorted []string
var forge *forgepb.Forge
var HOSTNAME string = "go.wit.com" // remove '?' part and trailing '/'
var REPOMAP string = "/etc/gowebd/repomap" func cleanURL(url string) string {
var FOOTER string = "/etc/gowebd/footer.html" url = "/" + strings.Trim(url, "/")
var LIBDIR string = "/var/lib/gowebd/" return url
}
func okHandler(w http.ResponseWriter, r *http.Request) {
dumpClient(r)
var tmp string
// tmp = r.URL.String()
tmp = cleanURL(r.URL.Path)
parts := strings.Split(tmp, "?")
log.Info("client sent url =", tmp)
log.Info("parts are:", parts)
requrl := parts[0]
url, repourl := findkey(requrl)
log.Warn("go.wit.com URL =", url, "REPO URL =", repourl, "REQUEST URL =", requrl)
if repourl != "" {
repoHTML(w, url, repourl)
return
}
if tmp == "/" {
indexHeader(w)
indexBodyStart(w)
indexBodyScanConfig(w)
indexDivEnd(w)
indexBodyEnd(w)
return
}
if tmp == "/old" {
findFile(w, "files/index.html")
return
}
if tmp == "/install.sh" {
findFile(w, "files/install.sh")
return
}
if tmp == "/me" {
j, err := dumpJsonClient(r)
if err != nil {
fmt.Fprintln(w, "BAD ZOOT")
return
}
fmt.Fprintln(w, j)
return
}
if tmp == "/update" {
return
}
if tmp == "/register" {
regfile, _ := os.OpenFile("/home/jcarr/regfile.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if registerClient(regfile, r) {
fmt.Fprintln(w, "OK")
} else {
fmt.Fprintln(w, "FAILED")
}
return
}
if tmp == "/list" {
findFile(w, "files/repomap")
return
}
if tmp == "/test" {
findFile(w, "files/test.html")
return
}
if tmp == "/goReference.svg" {
findFile(w, "files/goReference.svg")
return
}
if tmp == "/skeleton.v2.css" {
findFile(w, "files/skeleton.v2.css")
return
}
log.Warn("BAD URL =", url, "REPO URL =", repourl)
badurl(w, r.URL.String())
// fmt.Fprintln(w, "BAD", tmp)
}
func findFile(w http.ResponseWriter, filename string) {
// fmt.Fprintln(w, "GOT TEST?")
pfile, err := htmlFiles.ReadFile(filename)
if err != nil {
log.Println("ERROR:", err)
// w.Write(pfile)
return
}
var repohtml string
repohtml = string(pfile)
if filename == "files/goReference.svg" {
w.Header().Set("Content-Type", "image/svg+xml")
}
fmt.Fprintln(w, repohtml)
log.Println("findFile() found internal file:", filename)
// w.Close()
/*
filename = "/tmp/" + name + ".so"
log.Error(err, "write out file here", name, filename, len(pfile))
f, _ := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE, 0600)
f.Close()
*/
}
func main() { func main() {
if argv.RepoMap != "" { accessf, _ = os.OpenFile("/home/jcarr/accessclient.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
REPOMAP = argv.RepoMap clientf, _ = os.OpenFile("/home/jcarr/httpclient.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
} readconfigfile()
if argv.Hostname != "" { readVersionFile()
HOSTNAME = argv.Hostname
}
gitMap = make(map[string]*gitpb.Repo) // make the instructions to install be:
repoMap = make(map[string]string) // curl -sSL https://go.wit.com/install.sh | bash
forge = forgepb.Init() // build instruction:
// go install go.wit.com/apps/getgui@latest
// parse the repomap file
readRepomap()
// readVersionFile()
// for i, s := range versionMap {
// log.Println("found i =", i, "with", "s =", s)
// }
log.Println("found log =", versionMap["go.wit.com/log"])
http.HandleFunc("/", okHandler) http.HandleFunc("/", okHandler)
// go https() // use caddy instead go https()
p := fmt.Sprintf(":%d", argv.Port) err := http.ListenAndServe(":80", nil)
log.Println("HOSTNAME set to:", HOSTNAME)
log.Println("Running on port", p)
err := http.ListenAndServe(p, nil)
if err != nil { if err != nil {
log.Println("Error starting server:", err) log.Println("Error starting server:", err)
} }
} }
func badurl(w http.ResponseWriter, badurl string) {
fmt.Fprintln(w, "<!DOCTYPE html>")
fmt.Fprintln(w, "<html>")
fmt.Fprintln(w, " <head>")
fmt.Fprintln(w, " <meta http-equiv=\"refresh\" content=\"3; url=https://go.wit.com/\">")
fmt.Fprintln(w, " </head>")
fmt.Fprintln(w, " <body>")
fmt.Fprintln(w, " IPv4 IS NOT SUPPORTED<br>")
fmt.Fprintln(w, " MANY OF THESE REPOS REQUIRE IPv6.<br>")
fmt.Fprintln(w, " <br>")
fmt.Fprintln(w, " bad url", badurl, "<a href=\"https://git.wit.org/\">redirecting</a>")
fmt.Fprintln(w, " </body>")
fmt.Fprintln(w, "</html>")
}
func formatDuration(d time.Duration) string { func formatDuration(d time.Duration) string {
seconds := int(d.Seconds()) % 60 seconds := int(d.Seconds()) % 60
minutes := int(d.Minutes()) % 60 minutes := int(d.Minutes()) % 60

View File

@ -1,7 +0,0 @@
#!/bin/sh
set -e
cd /etc/gowebd/
# allow the binary to open ports below 1024
setcap 'cap_net_bind_service=+ep' /usr/bin/gowebd

118
repoHTML.go Normal file
View File

@ -0,0 +1,118 @@
package main
import (
"bufio"
"fmt"
"net/http"
"os"
"path/filepath"
"sort"
"strings"
"go.wit.com/log"
)
/*
<!DOCTYPE html>
<html>
<head>
<meta name="go-import" content="go.wit.com/gui/gui git https://git.wit.org/gui/gui">
<meta name="go-source" content="go.wit.com/gui/gui https://git.wit.org/gui/gui https://git.wit.org/gui/tree/master{/dir} https://git.wit.org/gui/gui/tree/master{/dir}/{file}#L{line}">
<meta http-equiv="refresh" content="0; url=https://git.wit.org/gui/gui">
</head>
<body>
Nothing to see here. Please <a href="https://git.wit.org/gui/gui">move along</a>.
</body>
</html>
*/
func repoHTML(w http.ResponseWriter, gourl string, realurl string) {
realurl = "https://" + realurl
log.Info("go repo =", gourl, "real url =", realurl)
fmt.Fprintln(w, "<!DOCTYPE html>")
fmt.Fprintln(w, "<html>")
fmt.Fprintln(w, "<head>")
// fmt.Fprintln(w,
fmt.Fprintln(w, "<meta name=\"go-import\" content=\"", gourl, "git", realurl+"\">")
fmt.Fprintln(w, "<meta name=\"go-source\" content=\"", gourl, realurl, realurl+"/tree/master{/dir}", realurl+"tree/master{/dir}/{file}#L{line}", "\"", ">")
fmt.Fprintln(w, "<meta http-equiv=\"refresh\" content=\"0; url="+realurl+"\">")
fmt.Fprintln(w, "</head>")
fmt.Fprintln(w, "<body>")
fmt.Fprintln(w, "Nothing to see here. Please <a href=\""+realurl+"\">move along</a>.\"")
fmt.Fprintln(w, "</body>")
fmt.Fprintln(w, "</html>")
/*
var tmp string
tmp = r.URL.String()
if tmp == "/gui" {
findFile(w)
return
}
fmt.Fprintln(w, "OK")
*/
}
func findkey(url string) (string, string) {
key := "go.wit.com" + url
if repoMap[key] != "" {
return key, repoMap[key]
}
return key, ""
// parts := strings.Split(key, "/")
}
func readconfigfile() {
repoMap = make(map[string]string)
pfile, err := htmlFiles.ReadFile("files/repomap")
if err != nil {
log.Error(err, "missing repomap in the binary")
return
}
configfile = strings.Split(string(pfile), "\n")
for _, line := range configfile {
fields := strings.Fields(line)
if len(fields) < 2 {
continue
}
repo := fields[0]
realurl := fields[1]
repoMap[repo] = realurl
// log.Info("repo =", repo, "real url =", realurl)
}
for repo, _ := range repoMap {
// log.Info("repo =", repo, "real url =", url)
keysSorted = append(keysSorted, repo)
}
log.Info("sorted:")
sort.Strings(keysSorted)
// sort.Reverse(keys)
sort.Sort(sort.Reverse(sort.StringSlice(keysSorted)))
for _, key := range keysSorted {
log.Info("repo =", key, "real url =", repoMap[key])
}
}
func readVersionFile() {
versionMap = make(map[string]string)
file, err := os.Open(filepath.Join(os.Getenv("HOME"), "go.wit.com.versions"))
if err != nil {
return
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
tmp := scanner.Text()
fields := strings.Split(tmp, " ")
if len(fields) < 2 {
continue
}
// log.Println("readVersionFile() fields[0] =", fields[0])
// log.Println("readVersionFile() fields[1:] =", fields[1:])
versionMap[fields[0]] = strings.Join(fields[1:], " ")
}
}

View File

@ -1,75 +0,0 @@
package main
// parses /etc/gowebd/repomap
// this file defines what repositories show up on go.wit.com
import (
"fmt"
"net/http"
"os"
"strings"
"go.wit.com/log"
)
// this makes the "go-source" / "go-import" page
// this redirects the go path "go.wit.com/apps/go-clone" to the git path "gitea.wit.com/wit/go-clone"
func repoHTML(w http.ResponseWriter, gourl string, realurl string) {
realurl = "https://" + realurl
log.Info("go repo =", gourl, "real url =", realurl)
fmt.Fprintln(w, "<!DOCTYPE html>")
fmt.Fprintln(w, "<html>")
fmt.Fprintln(w, "<head>")
// fmt.Fprintln(w,
fmt.Fprintln(w, "<meta name=\"go-import\" content=\"", gourl, "git", realurl+"\">")
fmt.Fprintln(w, "<meta name=\"go-source\" content=\"", gourl, realurl, realurl+"/tree/master{/dir}", realurl+"tree/master{/dir}/{file}#L{line}", "\"", ">")
fmt.Fprintln(w, "<meta http-equiv=\"refresh\" content=\"0; url="+realurl+"\">")
fmt.Fprintln(w, "</head>")
fmt.Fprintln(w, "<body>")
fmt.Fprintln(w, "Redirecting to git repo url. Please <a href=\""+realurl+"\">move along</a>.\"")
fmt.Fprintln(w, "</body>")
fmt.Fprintln(w, "</html>")
}
func findkey(url string) (string, string) {
key := "go.wit.com" + url
if repoMap[key] != "" {
return key, repoMap[key]
}
return key, ""
// parts := strings.Split(key, "/")
}
func readRepomap() {
var pfile []byte
var err error
pfile, err = os.ReadFile(REPOMAP)
if err != nil {
log.Error(err, "no repository map file found in /etc/gowebd/")
log.Error(err, "falling back to the repository map file built into the gowebd binary")
pfile, err = resources.ReadFile("resources/repomap")
if err != nil {
log.Error(err, "missing repomap in the binary")
return
}
}
configfile = strings.Split(string(pfile), "\n")
for _, line := range configfile {
fields := strings.Fields(line)
if len(fields) < 2 {
continue
}
gopath := fields[0]
giturl := fields[1]
repoMap[gopath] = giturl
repo := forge.FindByGoPath(gopath)
if repo != nil {
gitMap[gopath] = repo
} else {
log.Info("repo =", gopath, "real url =", repoMap[gopath], "not found")
}
}
}

View File

@ -1,19 +0,0 @@
all:
gowebd --version
@echo "make log # watch gowebd log"
@echo "make restart # restart gowebd"
@echo "make enable # enable gowebd on boot"
@echo "make status # show the systemd status of gowebd"
log:
@journalctl -f -xeu gowebd.service
status:
systemctl status gowebd.service
enable:
systemctl enable gowebd.service
restart:
systemctl stop gowebd.service
systemctl start gowebd.service

View File

@ -1,3 +0,0 @@
<br>
your footer here<br>
<br>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

View File

@ -1,15 +0,0 @@
# gui core packages
go.wit.com/gui gitea.wit.com/gui/gui The GUI API intended for Control Panels
go.wit.com/widget gitea.wit.com/gui/widget Primitive Definitions for Buttons, Dropdowns, etc.
# Tutorials
go.wit.com/apps/helloworld gitea.wit.com/gui/helloworld A simple Demo
go.wit.com/apps/basicwindow gitea.wit.com/jcarr/basicwindow A bit more of a Demo
go.wit.com/apps/gadgetwindow gitea.wit.com/jcarr/gadgetwindow A more complicated Demo used for debugging the toolkits
# Applications (mirrors.wit.com has .deb packages)
go.wit.com/apps/go-clone gitea.wit.com/gui/go-clone recursively 'git clone' golang packages
go.wit.com/apps/go-deb gitea.wit.com/jcarr/go-deb Turn anything into a .deb package

View File

@ -1,8 +0,0 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
OK12358
</body>
</html>