6 Commits

Author SHA1 Message Date
idk
91a6049575 git compatibility read only 2019-10-14 00:57:55 -04:00
idk
2f101752fd git compatibility read only 2019-10-14 00:49:47 -04:00
idk
d4e8455e95 git compatibility read only 2019-10-14 00:47:59 -04:00
idk
071895b67e git compatibility read only 2019-10-14 00:44:16 -04:00
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
4 changed files with 27 additions and 3 deletions

View File

@@ -12,7 +12,7 @@ echo:
USER_GH=eyedeekay
packagename=eephttpd
VERSION=0.0.8
VERSION=0.0.95
tag:
gothub release -s $(GITHUB_TOKEN) -u $(USER_GH) -r $(packagename) -t v$(VERSION) -d "I2P Tunnel Management tool for Go applications"

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
@@ -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,6 +91,12 @@ func NewEepHttpdFromOptions(opts ...func(*EepHttpd) error) (*EepHttpd, error) {
}
s.SAMForwarder.Config().SaveFile = true
l, e := s.Load()
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

2
go.mod
View File

@@ -23,7 +23,9 @@ require (
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

View File

@@ -14,6 +14,10 @@ import (
func (f *EepHttpd) ServeHTTP(rw http.ResponseWriter, rq *http.Request) {
rp := f.checkURL(rq)
if strings.HasPrefix(rq.Header.Get("User-Agent"), "git") {
f.HandleGit(rw, rq)
return
}
if strings.HasSuffix(rp, ".md") {
f.HandleMarkdown(rw, rq)
return
@@ -46,8 +50,8 @@ func (f *EepHttpd) checkURL(rq *http.Request) string {
}
if !FileExists(filepath.Join(f.ServeDir, p)) {
p = filepath.Join(rq.URL.Path, "index.tengo")
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)
@@ -84,6 +88,11 @@ 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) {
log.Println("Handling Git")
f.Server.ServeHTTP(rw, rq)
}
func (f *EepHttpd) HandleFile(rw http.ResponseWriter, rq *http.Request) {
path := f.checkURL(rq)
bytes, err := ioutil.ReadFile(path)