8 Commits

Author SHA1 Message Date
idk
f0fc381076 git compatibility read only 2019-10-14 00:59:36 -04:00
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
idk
a6e994c43f look for index in sub-directories too 2019-10-13 21:38:48 -04:00
4 changed files with 34 additions and 13 deletions

View File

@@ -12,7 +12,7 @@ echo:
USER_GH=eyedeekay
packagename=eephttpd
VERSION=0.0.7
VERSION=0.0.96
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

6
go.mod
View File

@@ -23,14 +23,12 @@ 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/html v0.0.0-20180917080848-cfaf75183c4a // indirect
gitlab.com/golang-commonmark/linkify v0.0.0-20180917065525-c22b7bdb1179 // indirect
gitlab.com/golang-commonmark/markdown v0.0.0-20181102083822-772775880e1f
gitlab.com/golang-commonmark/mdurl v0.0.0-20180912090424-e5bce34c34f2 // indirect
gitlab.com/golang-commonmark/puny v0.0.0-20180912090636-2cd490539afe // indirect
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

View File

@@ -13,11 +13,16 @@ 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("User-Agent"), "git") {
f.HandleFile(rw, rq)
return
}
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
}
@@ -37,16 +42,16 @@ func FileExists(filename string) bool {
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 = "/README.md"
p = filepath.Join(rq.URL.Path, "README.md")
}
if !FileExists(filepath.Join(f.ServeDir, p)) {
if FileExists(filepath.Join(f.ServeDir, "/index.tengo")) {
p = "/index.tengo"
p = filepath.Join(rq.URL.Path, "index.tengo")
if !FileExists(filepath.Join(f.ServeDir, p)) {
p = rq.URL.Path
}
}
log.Println(p)
@@ -83,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)