12 Commits

Author SHA1 Message Date
idk
513326387a git compatibility read only 2019-10-14 00:38:22 -04:00
idk
9beecead2f skip markdown and scripts when encountering a git user agent 2019-10-13 23:51:37 -04:00
idk
a6e994c43f look for index in sub-directories too 2019-10-13 21:38:48 -04:00
idk
a566642ce3 update go modules 2019-10-13 19:21:48 -04:00
idk
0ee3e39cd0 update go modules 2019-10-13 19:16:47 -04:00
idk
82c09da166 update go modules 2019-10-13 19:16:03 -04:00
idk
78d3702851 update go modules 2019-10-13 18:59:13 -04:00
idk
5658dab81e update go modules 2019-10-13 18:58:34 -04:00
idk
921c0f7cef update go modules 2019-10-13 18:54:50 -04:00
idk
14b861da99 be less insistent about index.tengo 2019-10-13 15:51:22 -04:00
idk
2c879fcff9 add missing import 2019-10-13 15:48:33 -04:00
idk
157ace32bd If no index is found, try a readme. If an index.tengo file exists, use that. 2019-10-13 15:39:23 -04:00
4 changed files with 95 additions and 7 deletions

View File

@@ -12,11 +12,15 @@ echo:
USER_GH=eyedeekay
packagename=eephttpd
VERSION=0.0.1
VERSION=0.0.9
tag:
gothub release -s $(GITHUB_TOKEN) -u $(USER_GH) -r $(packagename) -t v$(VERSION) -d "I2P Tunnel Management tool for Go applications"
mod:
go get -u github.com/$(USER_GH)/$(packagename)@v$(VERSION)
fmt:
find . -name '*.go' -exec gofmt -w -s {} \;

View File

@@ -6,6 +6,7 @@ import (
"github.com/eyedeekay/sam-forwarder/interface"
"github.com/eyedeekay/sam-forwarder/tcp"
"github.com/sosedoff/gitkit"
"gitlab.com/golang-commonmark/markdown"
)
@@ -13,6 +14,7 @@ import (
//a local service to i2p over the SAM API.
type EepHttpd struct {
*samforwarder.SAMForwarder
*gitkit.Server
ServeDir string
up bool
mark *markdown.Markdown
@@ -44,7 +46,7 @@ func (f *EepHttpd) Serve() error {
}
func (f *EepHttpd) Up() bool {
return f.up
return f.up
}
//Close shuts the whole thing down.
@@ -72,10 +74,15 @@ func NewEepHttpd(host, port string) (*EepHttpd, error) {
return NewEepHttpdFromOptions(SetHost(host), SetPort(port))
}
func Never(gitkit.Credential, *gitkit.Request) (bool, error) {
return false, nil
}
//NewEepHttpdFromOptions makes a new SAM forwarder with default options, accepts host:port arguments
func NewEepHttpdFromOptions(opts ...func(*EepHttpd) error) (*EepHttpd, error) {
var s EepHttpd
s.SAMForwarder = &samforwarder.SAMForwarder{}
s.Server = &gitkit.Server{}
log.Println("Initializing eephttpd")
for _, o := range opts {
if err := o(&s); err != nil {
@@ -84,7 +91,13 @@ func NewEepHttpdFromOptions(opts ...func(*EepHttpd) error) (*EepHttpd, error) {
}
s.SAMForwarder.Config().SaveFile = true
l, e := s.Load()
//log.Println("Options loaded", s.Print())
s.Server = gitkit.New(gitkit.Config{
Dir: s.ServeDir,
AutoCreate: true,
Auth: true, // Turned off by default
})
s.Server.AuthFunc = Never
//log.Println("Options loaded", s.Print())
if e != nil {
return nil, e
}

42
go.mod Normal file
View File

@@ -0,0 +1,42 @@
module github.com/eyedeekay/eephttpd
go 1.12
require (
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
github.com/andybalholm/cascadia v1.1.0 // indirect
github.com/creack/pty v1.1.9 // indirect
github.com/cryptix/go v1.5.0 // indirect
github.com/d5/tengo v1.24.3
github.com/eyedeekay/outproxy v0.0.0-20190913044809-33f1668ccb7d // indirect
github.com/eyedeekay/sam-forwarder v0.0.0-20190928041036-d2f767dbe008
github.com/eyedeekay/sam3 v0.0.0-20190730185140-f8d54526ea25
github.com/google/go-cmp v0.3.1 // indirect
github.com/gorilla/sessions v1.2.0 // indirect
github.com/juju/errors v0.0.0-20190930114154-d42613fe1ab9 // indirect
github.com/juju/testing v0.0.0-20191001232224-ce9dec17d28b // indirect
github.com/julienschmidt/httprouter v1.3.0 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/kr/pty v1.1.8 // indirect
github.com/miolini/datacounter v0.0.0-20190724021726-aa48df3a02c1 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
github.com/prometheus/common v0.7.0 // indirect
github.com/prometheus/procfs v0.0.5 // indirect
github.com/satori/go.uuid v1.2.0 // indirect
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect
github.com/sosedoff/gitkit v0.2.0
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.2.0 // indirect
gitlab.com/golang-commonmark/markdown v0.0.0-20181102083822-772775880e1f
go.uber.org/multierr v1.2.0 // indirect
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect
golang.org/x/net v0.0.0-20191011234655-491137f69257 // indirect
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect
golang.org/x/sys v0.0.0-20191010194322-b09406accb47 // indirect
golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0 // indirect
golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a // indirect
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v2 v2.2.4 // indirect
)

View File

@@ -5,6 +5,7 @@ import (
"io/ioutil"
"log"
"net/http"
"os"
"path/filepath"
"strings"
@@ -12,21 +13,45 @@ import (
)
func (f *EepHttpd) ServeHTTP(rw http.ResponseWriter, rq *http.Request) {
if strings.HasSuffix(rq.URL.Path, ".md") {
rp := f.checkURL(rq)
if strings.HasPrefix(rq.Header.Get("X-User-Agent"), "git") {
f.HandleGit(rw, rq)
}
if strings.HasSuffix(rp, ".md") {
f.HandleMarkdown(rw, rq)
return
}
if strings.HasSuffix(rq.URL.Path, ".tengo") {
if strings.HasSuffix(rp, ".tengo") {
f.HandleScript(rw, rq)
return
}
f.HandleFile(rw, rq)
}
func FileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
if info != nil {
return !info.IsDir()
}
return false
}
func (f *EepHttpd) checkURL(rq *http.Request) string {
p := rq.URL.Path
if rq.URL.Path == "/" {
p = "/index.html"
if strings.HasSuffix(rq.URL.Path, "/") {
p = filepath.Join(rq.URL.Path, "index.html")
}
if !FileExists(filepath.Join(f.ServeDir, p)) {
p = filepath.Join(rq.URL.Path, "README.md")
}
if !FileExists(filepath.Join(f.ServeDir, p)) {
p = filepath.Join(rq.URL.Path, "index.tengo")
if !FileExists(filepath.Join(f.ServeDir, p)) {
p = rq.URL.Path
}
}
log.Println(p)
return filepath.Join(f.ServeDir, p)
@@ -62,6 +87,10 @@ func (f *EepHttpd) HandleMarkdown(rw http.ResponseWriter, rq *http.Request) {
f.mark.Render(rw, bytes)
}
func (f *EepHttpd) HandleGit(rw http.ResponseWriter, rq *http.Request) {
f.Server.ServeHTTP(rw, rq)
}
func (f *EepHttpd) HandleFile(rw http.ResponseWriter, rq *http.Request) {
path := f.checkURL(rq)
bytes, err := ioutil.ReadFile(path)