Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
513326387a | ||
![]() |
9beecead2f | ||
![]() |
a6e994c43f | ||
![]() |
a566642ce3 | ||
![]() |
0ee3e39cd0 | ||
![]() |
82c09da166 |
6
Makefile
6
Makefile
@@ -12,11 +12,15 @@ echo:
|
|||||||
|
|
||||||
USER_GH=eyedeekay
|
USER_GH=eyedeekay
|
||||||
packagename=eephttpd
|
packagename=eephttpd
|
||||||
VERSION=0.0.5
|
VERSION=0.0.9
|
||||||
|
|
||||||
tag:
|
tag:
|
||||||
gothub release -s $(GITHUB_TOKEN) -u $(USER_GH) -r $(packagename) -t v$(VERSION) -d "I2P Tunnel Management tool for Go applications"
|
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:
|
fmt:
|
||||||
find . -name '*.go' -exec gofmt -w -s {} \;
|
find . -name '*.go' -exec gofmt -w -s {} \;
|
||||||
|
|
||||||
|
13
eephttpd.go
13
eephttpd.go
@@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/eyedeekay/sam-forwarder/interface"
|
"github.com/eyedeekay/sam-forwarder/interface"
|
||||||
"github.com/eyedeekay/sam-forwarder/tcp"
|
"github.com/eyedeekay/sam-forwarder/tcp"
|
||||||
|
"github.com/sosedoff/gitkit"
|
||||||
"gitlab.com/golang-commonmark/markdown"
|
"gitlab.com/golang-commonmark/markdown"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -13,6 +14,7 @@ import (
|
|||||||
//a local service to i2p over the SAM API.
|
//a local service to i2p over the SAM API.
|
||||||
type EepHttpd struct {
|
type EepHttpd struct {
|
||||||
*samforwarder.SAMForwarder
|
*samforwarder.SAMForwarder
|
||||||
|
*gitkit.Server
|
||||||
ServeDir string
|
ServeDir string
|
||||||
up bool
|
up bool
|
||||||
mark *markdown.Markdown
|
mark *markdown.Markdown
|
||||||
@@ -72,10 +74,15 @@ func NewEepHttpd(host, port string) (*EepHttpd, error) {
|
|||||||
return NewEepHttpdFromOptions(SetHost(host), SetPort(port))
|
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
|
//NewEepHttpdFromOptions makes a new SAM forwarder with default options, accepts host:port arguments
|
||||||
func NewEepHttpdFromOptions(opts ...func(*EepHttpd) error) (*EepHttpd, error) {
|
func NewEepHttpdFromOptions(opts ...func(*EepHttpd) error) (*EepHttpd, error) {
|
||||||
var s EepHttpd
|
var s EepHttpd
|
||||||
s.SAMForwarder = &samforwarder.SAMForwarder{}
|
s.SAMForwarder = &samforwarder.SAMForwarder{}
|
||||||
|
s.Server = &gitkit.Server{}
|
||||||
log.Println("Initializing eephttpd")
|
log.Println("Initializing eephttpd")
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
if err := o(&s); err != nil {
|
if err := o(&s); err != nil {
|
||||||
@@ -84,6 +91,12 @@ func NewEepHttpdFromOptions(opts ...func(*EepHttpd) error) (*EepHttpd, error) {
|
|||||||
}
|
}
|
||||||
s.SAMForwarder.Config().SaveFile = true
|
s.SAMForwarder.Config().SaveFile = true
|
||||||
l, e := s.Load()
|
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())
|
//log.Println("Options loaded", s.Print())
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return nil, e
|
return nil, e
|
||||||
|
36
go.mod
36
go.mod
@@ -3,12 +3,40 @@ module github.com/eyedeekay/eephttpd
|
|||||||
go 1.12
|
go 1.12
|
||||||
|
|
||||||
require (
|
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/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/sam-forwarder v0.0.0-20190928041036-d2f767dbe008
|
||||||
github.com/eyedeekay/sam3 v0.0.0-20190730185140-f8d54526ea25
|
github.com/eyedeekay/sam3 v0.0.0-20190730185140-f8d54526ea25
|
||||||
gitlab.com/golang-commonmark/html v0.0.0-20180917080848-cfaf75183c4a // indirect
|
github.com/google/go-cmp v0.3.1 // indirect
|
||||||
gitlab.com/golang-commonmark/linkify v0.0.0-20180917065525-c22b7bdb1179 // 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
|
gitlab.com/golang-commonmark/markdown v0.0.0-20181102083822-772775880e1f
|
||||||
gitlab.com/golang-commonmark/mdurl v0.0.0-20180912090424-e5bce34c34f2 // indirect
|
go.uber.org/multierr v1.2.0 // indirect
|
||||||
gitlab.com/golang-commonmark/puny v0.0.0-20180912090636-2cd490539afe // 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
|
||||||
)
|
)
|
||||||
|
24
serve.go
24
serve.go
@@ -13,11 +13,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (f *EepHttpd) ServeHTTP(rw http.ResponseWriter, rq *http.Request) {
|
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)
|
f.HandleMarkdown(rw, rq)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if strings.HasSuffix(rq.URL.Path, ".tengo") {
|
if strings.HasSuffix(rp, ".tengo") {
|
||||||
f.HandleScript(rw, rq)
|
f.HandleScript(rw, rq)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -37,16 +41,16 @@ func FileExists(filename string) bool {
|
|||||||
|
|
||||||
func (f *EepHttpd) checkURL(rq *http.Request) string {
|
func (f *EepHttpd) checkURL(rq *http.Request) string {
|
||||||
p := rq.URL.Path
|
p := rq.URL.Path
|
||||||
if rq.URL.Path == "/" {
|
if strings.HasSuffix(rq.URL.Path, "/") {
|
||||||
p = "/index.html"
|
p = filepath.Join(rq.URL.Path, "index.html")
|
||||||
}
|
}
|
||||||
if !FileExists(filepath.Join(f.ServeDir, p)) {
|
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, p)) {
|
||||||
if FileExists(filepath.Join(f.ServeDir, "/index.tengo")) {
|
p = filepath.Join(rq.URL.Path, "index.tengo")
|
||||||
p = "/index.tengo"
|
if !FileExists(filepath.Join(f.ServeDir, p)) {
|
||||||
|
p = rq.URL.Path
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Println(p)
|
log.Println(p)
|
||||||
@@ -83,6 +87,10 @@ func (f *EepHttpd) HandleMarkdown(rw http.ResponseWriter, rq *http.Request) {
|
|||||||
f.mark.Render(rw, bytes)
|
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) {
|
func (f *EepHttpd) HandleFile(rw http.ResponseWriter, rq *http.Request) {
|
||||||
path := f.checkURL(rq)
|
path := f.checkURL(rq)
|
||||||
bytes, err := ioutil.ReadFile(path)
|
bytes, err := ioutil.ReadFile(path)
|
||||||
|
Reference in New Issue
Block a user