Compare commits

..

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

28 changed files with 594 additions and 594 deletions

2
.gitignore vendored
View File

@ -3,5 +3,3 @@ go.mod
go.sum
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,16 @@
.PHONY: build
VERSION = $(shell git describe --tags)
BUILDTIME = $(shell date +%Y.%m.%d)
all: build
@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
all:
echo "build it!"
# GO111MODULE=off go get -u -v .
GO111MODULE=off go build -v -x
# sudo setcap 'cap_net_bind_service=+ep' go.wit.com
./go.wit.com
@# ./myrepos >/tmp/myrepos.stderr 2>&1
goimports:
reset
goimports -w *.go
clean:
redomod:
rm -f go.*
rm -f go.wit.com
rm -f gowebd
go-mod-clean purge
GO111MODULE= go mod init
GO111MODULE= go mod tidy
# 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

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

@ -4,13 +4,12 @@ import (
"fmt"
"io/ioutil"
"net/http"
"os"
"time"
"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
host = r.Host
@ -69,80 +68,3 @@ func dumpClient(accessf, clientf *os.File, r *http.Request) {
}
}
}
func registerClient(f *os.File, r *http.Request) bool {
var host, url, proto, addr, agent string
var giturl, gopath string
host = r.Host
url = r.URL.String()
proto = r.Proto
addr = r.RemoteAddr
agent = r.UserAgent()
log.Warn(host, proto, addr, url, agent)
fmt.Fprintln(f, time.Now(), host, proto, addr, url, agent)
// return
fmt.Fprintln(f)
fmt.Fprintln(f, time.Now())
// Basic request information
fmt.Fprintln(f, "Method:", r.Method)
fmt.Fprintln(f, "URL:", r.URL)
fmt.Fprintln(f, "Protocol:", r.Proto)
fmt.Fprintln(f, "Host:", r.Host)
fmt.Fprintln(f, "Remote Address:", r.RemoteAddr)
// Headers
fmt.Fprintln(f, "Headers:")
for name, values := range r.Header {
for _, value := range values {
fmt.Fprintln(f, "Headers:", name, value)
if name == "Giturl" {
giturl = value
}
if name == "Gopath" {
gopath = value
}
}
}
// Query parameters
fmt.Fprintln(f, "Query Parameters:")
for param, values := range r.URL.Query() {
for _, value := range values {
fmt.Fprintln(f, "Query:", param, value)
}
}
// User-Agent
fmt.Fprintln(f, "User-Agent:", r.UserAgent())
// Content Length
fmt.Fprintln(f, "Content Length:", r.ContentLength)
// Cookies
fmt.Fprintln(f, "Cookies:")
for _, cookie := range r.Cookies() {
fmt.Fprintln(f, cookie.Name, cookie.Value)
}
// Request Body (if applicable)
if r.Body != nil {
body, err := ioutil.ReadAll(r.Body)
if err == nil {
fmt.Fprintln(f, "Body:", string(body))
}
}
fmt.Fprintln(f, "gopath =", gopath, "giturl =", giturl)
if gopath == "" {
return false
}
if giturl == "" {
return false
}
fmt.Fprintln(f, "Sent back OK")
return true
}

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)
}

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>

48
files/repomap Normal file
View File

@ -0,0 +1,48 @@
# log/ (needed for the gui)
go.wit.com/log git.wit.org/wit/log
# gui core packages
go.wit.com/widget git.wit.org/gui/widget
go.wit.com/gui git.wit.org/gui/gui
# gui toolkit packages
go.wit.com/toolkits/tree git.wit.org/toolkits/tree
go.wit.com/toolkits/nocui git.wit.org/toolkits/nocui
go.wit.com/toolkits/gocui git.wit.org/toolkits/gocui
go.wit.com/toolkits/andlabs git.wit.org/toolkits/andlabs
go.wit.com/toolkits/debian git.wit.org/toolkits/debian
# gui libraries
go.wit.com/lib/gadgets git.wit.org/gui/gadgets
go.wit.com/lib/debugger git.wit.org/gui/debugger
go.wit.com/lib/gui/repostatus git.wit.org/jcarr/repostatus
go.wit.com/lib/gui/hostname git.wit.org/jcarr/hostname
go.wit.com/lib/gui/linuxstatus git.wit.org/jcarr/hostname
go.wit.com/lib/gui/logsettings git.wit.org/jcarr/logsettings
go.wit.com/lib/gui/digitalocean git.wit.org/gui/digitalocean
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
# Applications
go.wit.com/apps/helloworld git.wit.org/gui/helloworld
go.wit.com/apps/basicwindow git.wit.org/jcarr/basicwindow
go.wit.com/apps/gadgetwindow git.wit.org/jcarr/gadgetwindow
go.wit.com/apps/autotypist git.wit.org/jcarr/autotypist
go.wit.com/apps/guireleaser git.wit.org/jcarr/guireleaser
go.wit.com/apps/control-panel-dns git.wit.org/jcarr/control-panel-dns
go.wit.com/apps/control-panel-digitalocean git.wit.org/wit/control-panel-digitalocean
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
# Support packages
go.wit.com/dev/alexflint/arg git.wit.org/jcarr/go-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
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,11 @@ package main
import (
"fmt"
"net/http"
"strconv"
"strings"
"time"
"go.wit.com/log"
)
func indexHeader(w http.ResponseWriter) {
@ -34,14 +38,14 @@ func indexBodyStart(w http.ResponseWriter) {
fmt.Fprintln(w, " <table class=\"u-full-width\">")
// fmt.Fprintln(w, " <thead>")
fmt.Fprintln(w, " <tr>")
fmt.Fprintln(w, " <th>Package (IPv6 only)</th>")
fmt.Fprintln(w, " <th>Documentation</th>")
fmt.Fprintln(w, " <th>Package</th>")
fmt.Fprintln(w, " <th>Version</th>")
fmt.Fprintln(w, " <th>Dev Version</th>")
fmt.Fprintln(w, " <th>Age</th>")
fmt.Fprintln(w, " <th>Description</th>")
// fmt.Fprintln(w, " <th>Authoritative sources (IPv6 only)</th>")
// fmt.Fprintln(w, " <th></th>")
fmt.Fprintln(w, " <th>Dev Version</th>")
fmt.Fprintln(w, " <th>go get</th>")
fmt.Fprintln(w, " <th>Authoritative sources (IPv6 only)</th>")
fmt.Fprintln(w, " <th></th>")
fmt.Fprintln(w, " <th>Documentation</th>")
fmt.Fprintln(w, " </tr>")
// fmt.Fprintln(w, " </thead>")
fmt.Fprintln(w, " <tbody>")
@ -49,12 +53,12 @@ func indexBodyStart(w http.ResponseWriter) {
}
func insertHTMLnote(w http.ResponseWriter, i int, parts []string) {
// log.Info("comment # line:", i, strings.Join(parts, " "))
log.Info("comment # line:", i, strings.Join(parts, " "))
fmt.Fprintln(w, " <tr> <td><h3>", strings.Join(parts, " "), "</h3></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr>")
}
func indexBodyScanConfig(w http.ResponseWriter) {
// log.Info("indexBodyScanConfig() START")
log.Info("indexBodyScanConfig() START")
for i, line := range configfile {
// log.Info("config file line:", i, line)
fields := strings.Fields(line)
@ -67,51 +71,62 @@ func indexBodyScanConfig(w http.ResponseWriter) {
continue
}
if len(fields) == 2 {
// log.Info("short file line:", i, line)
log.Info("short file line:", i, line)
gourl := fields[0]
giturl := fields[1]
indexBodyRepo(w, gourl, giturl, "")
continue
}
if len(fields) > 2 {
// log.Info("short file line:", i, line)
gourl := fields[0]
giturl := fields[1]
desc := strings.Join(fields[2:], " ")
desc = strings.TrimSpace(desc)
indexBodyRepo(w, gourl, giturl, desc)
continue
}
// log.Info("config file line:", i, line)
log.Info("config file line:", i, line)
}
// log.Info("indexBodyScanConfig() END")
log.Info("indexBodyScanConfig() END")
}
func indexBodyRepo(w http.ResponseWriter, gourl string, giturl string, desc string) {
// skip displaying packages without a desc
if desc == "" {
return
}
func indexBodyRepo(w http.ResponseWriter, gourl string, giturl string, github string) {
// fmt.Fprintln(w, " <tr> <td><h5>log/ (needed for the gui)</h5></td> <td></td> <td></td> <td></td> <td></td> </tr>")
fmt.Fprintln(w, " <tr>")
// fmt.Fprintln(w, " <td>"+gourl+"</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>")
var vtime, version, dver string
gourl = strings.TrimSpace(gourl)
if repo, ok := gitMap[gourl]; ok {
version = repo.GetLastTag()
age := repo.NewestAge()
vtime = formatDuration(age)
dver = repo.GetDevelVersion()
fmt.Fprintln(w, " <td>"+gourl+"</td>")
for i, s := range versionMap {
log.Println("found i =", i, "with", "s =", s)
}
var vtime, version string
gourl = strings.TrimSpace(gourl)
tmp, _ := versionMap[gourl]
parts := strings.Split(tmp, " ")
if len(parts) > 0 {
version = parts[0]
}
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>"+dver+"</td>") // dev version
fmt.Fprintln(w, " <td>"+vtime+"</td>") // dev version
fmt.Fprintln(w, " <td>"+desc+"</td>")
// fmt.Fprintln(w, " <td> <a href=\"//"+gourl+"\">"+giturl+"</a></td>")
fmt.Fprintln(w, " <td>"+ vtime +"</td>") // dev version
fmt.Fprintln(w, " <td></td>") // dev version
fmt.Fprintln(w, " <td> <a href=\"//"+gourl+"\">"+gourl+"</a></td>")
fmt.Fprintln(w, " <td> <a href=\"//"+gourl+"\">"+giturl+"</a></td>")
if github == "" {
fmt.Fprintln(w, " <td></td>")
} else {
fmt.Fprintln(w, " <td> <a href=\"//github.com/wit-go/log\">github.com/wit-go/log</a></td>")
}
fmt.Fprintln(w, " <td> <a href=\"//pkg.go.dev/"+gourl+"\"> <img src=\"goReference.svg\" alt=\"pkg.go.dev docs\" /> </a> </td>")
fmt.Fprintln(w, " </tr>")
fmt.Fprintln(w, "")
}

View File

@ -17,8 +17,8 @@ type RequestInfo struct {
Headers map[string][]string `json:"headers"`
Cookies map[string]string `json:"cookies"`
QueryParams map[string][]string `json:"queryParams"`
Body string `json:"body"`
// Add other fields as needed
Body string `json:"body"`
}
// 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
}
/*
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)
*/

147
main.go
View File

@ -4,61 +4,138 @@ import (
"embed"
"fmt"
"net/http"
"os"
"strings"
"time"
"go.wit.com/lib/protobuf/forgepb"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
// are sent via -ldflags at buildtime
var VERSION string
var BUILDTIME string
//go:embed files/*
var htmlFiles embed.FS
//go:embed resources/*
var resources embed.FS
// var accessf, clientf *os.File
var accessf, clientf *os.File
var repoMap map[string]string
var gitMap map[string]*gitpb.Repo
var versionMap map[string]string
var configfile []string
var keysSorted []string
var forge *forgepb.Forge
var HOSTNAME string = "go.wit.com"
var REPOMAP string = "/etc/gowebd/repomap"
var FOOTER string = "/etc/gowebd/footer.html"
var LIBDIR string = "/var/lib/gowebd/"
// remove '?' part and trailing '/'
func cleanURL(url string) string {
url = "/" + strings.Trim(url, "/")
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 == "/me" {
j, err := dumpJsonClient(r)
if err != nil {
fmt.Fprintln(w, "BAD ZOOT")
return
}
fmt.Fprintln(w, j)
return
}
if tmp == "/list" {
findFile(w, "files/repomap")
return
}
if tmp == "/test" {
findFile(w, "files/test.html")
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)
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() {
if argv.RepoMap != "" {
REPOMAP = argv.RepoMap
accessf, _ = os.OpenFile("/home/jcarr/accessclient.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
clientf, _ = os.OpenFile("/home/jcarr/httpclient.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
readconfigfile()
readVersionFile()
for i, s := range versionMap {
log.Println("found i =", i, "with", "s =", s)
}
if argv.Hostname != "" {
HOSTNAME = argv.Hostname
}
gitMap = make(map[string]*gitpb.Repo)
repoMap = make(map[string]string)
forge = forgepb.Init()
// parse the repomap file
readRepomap()
// readVersionFile()
log.Println("found log =", versionMap["go.wit.com/log"])
http.HandleFunc("/", okHandler)
// go https() // use caddy instead
p := fmt.Sprintf(":%d", argv.Port)
log.Println("HOSTNAME set to:", HOSTNAME)
log.Println("Running on port", p)
err := http.ListenAndServe(p, nil)
go https()
err := http.ListenAndServe(":80", nil)
if err != nil {
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 {
seconds := int(d.Seconds()) % 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>

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 6.3 KiB

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>