diff --git a/Makefile b/Makefile
index 500b419..2d70a32 100644
--- a/Makefile
+++ b/Makefile
@@ -4,23 +4,29 @@ VERSION=$(shell cat VERSION)
GCFLAGS=-gcflags '-e'
LDFLAGS=-ldflags '-X main.version=$(VERSION) -s -w'
PROGRAM=gowiki
-ENV=CGO_ENABLED=0
+ENV=CGO_ENABLED=0 GO111MODULE=on
all: $(PROGRAM)
setup:
- $(CC) get github.com/client9/misspell
+ $(CC) get -u github.com/client9/misspell
-vendor: clean codeqa
- $(ENV) $(CC) $(BUILD) -mod=vendor $(LDFLAGS)
+release: clean generate gofmt codeqa
+ $(ENV) $(CC) $(BUILD) $(GCFLAGS) $(LDFLAGS)
-$(PROGRAM): clean codeqa
- $(ENV) $(CC) $(BUILD) $(LDFLAGS)
+release-vendor: clean generate gofmt codeqa
+ $(ENV) $(CC) $(BUILD) -mod=vendor $(GCFLAGS) $(LDFLAGS)
+
+vendor: clean generate gofmt
+ $(ENV) $(CC) $(BUILD) -mod=vendor $(GCFLAGS) $(LDFLAGS)
+
+$(PROGRAM): clean generate gofmt
+ $(ENV) $(CC) $(BUILD) $(GCFLAGS) $(LDFLAGS)
clean:
$(CC) clean -x
-codeqa: generate gofmt misspell golint test
+codeqa: misspell golint test
generate:
$(CC) generate
@@ -32,8 +38,7 @@ golint:
$(GOPATH)/bin/golint .
misspell:
- # ignore misspellings from vendor/
- $(GOPATH)/bin/misspell -i functionallity,avaliable,HALP,halp,agains,becuase,Christiaan,compatiblity,conjuction,frequence,inital,inot,occurance,overriden,pervious,preceeded,preceeds,precendence,PROPOGATE,reamining,represenation,soley,substract,supression,whcih,preceed *
+ $(GOPATH)/bin/misspell pkg/* templates/* main.go Makefile README.md sri.sh templates.sh
test:
ifeq ($(shell go env GOARCH), $(shell go env GOHOSTARCH))
@@ -46,4 +51,4 @@ else
$(info skipping tests of other platforms)
endif
-.PHONY: setup vendor build clean codeqa generate gofmt golint misspell test
+.PHONY: setup release release-vendor vendor build clean codeqa generate gofmt golint misspell test
diff --git a/README.md b/README.md
index eb96770..d635de5 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,10 @@
## Building
+**Requirenments:**
+
+* Go (golang) >= 1.12
+
Linux:
```
@@ -25,3 +29,19 @@ GOOS=openbsd make vendor
## Install
See the `scripts/` directory on how to install gowiki on Linux or OpenBSD.
+
+## Config
+
+```
+{
+ "data_dir": "/var/lib/gowiki", // running directory. data will be stored here
+ "user": "wiki", // drop privileges to user
+ "group": "wiki", // drop privileges to group
+ "listen_addr": "127.0.0.1:8080", // listening
:
+ "log_file": "gowiki.log", // log file (use - for stdout, this only works in combination with 'foreground: true')
+ "secret": "", // static hmac secret (at least 64 chars, used for JWT signing)
+ "foreground": false, // do not fork into the background
+ "secure_cookie": false, // enable secure cookie flag
+ "debug": false // enable debugging
+}
+```
diff --git a/go.mod b/go.mod
index ff547fb..3e3fd52 100644
--- a/go.mod
+++ b/go.mod
@@ -1,47 +1,36 @@
module git.giftfish.de/ston1th/gowiki
+go 1.12
+
require (
git.giftfish.de/ston1th/godrop/v2 v2.1.0
git.giftfish.de/ston1th/jwt/v3 v3.2.0
- github.com/RoaringBitmap/roaring v0.4.16 // indirect
+ github.com/RoaringBitmap/roaring v0.4.17 // indirect
github.com/Smerity/govarint v0.0.0-20150407073650-7265e41f48f1 // indirect
github.com/blevesearch/bleve v0.7.0
github.com/blevesearch/blevex v0.0.0-20180227211930-4b158bb555a3 // indirect
- github.com/blevesearch/go-porterstemmer v0.0.0-20141230013033-23a2c8e5cf1f // indirect
+ github.com/blevesearch/go-porterstemmer v1.0.2 // indirect
github.com/blevesearch/segment v0.0.0-20160915185041-762005e7a34f // indirect
github.com/boltdb/bolt v1.3.1
github.com/boombuler/barcode v1.0.0 // indirect
- github.com/couchbase/vellum v0.0.0-20180910213445-01d5c56e6095 // indirect
- github.com/cznic/b v0.0.0-20180115125044-35e9bbe41f07 // indirect
- github.com/cznic/mathutil v0.0.0-20180504122225-ca4c9f2c1369 // indirect
- github.com/cznic/strutil v0.0.0-20171016134553-529a34b1c186 // indirect
+ github.com/couchbase/vellum v0.0.0-20190328134517-462e86d8716b // indirect
+ github.com/cznic/b v0.0.0-20181122101859-a26611c4d92d // indirect
+ github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548 // indirect
+ github.com/cznic/strutil v0.0.0-20181122101858-275e90344537 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
- github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712 // indirect
+ github.com/edsrzf/mmap-go v1.0.0 // indirect
github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51 // indirect
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 // indirect
github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870 // indirect
- github.com/glycerine/go-unsnap-stream v0.0.0-20180323001048-9f0cb55181dd // indirect
- github.com/glycerine/goconvey v0.0.0-20180728074245-46e3a41ad493 // indirect
- github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db // indirect
- github.com/gopherjs/gopherjs v0.0.0-20180825215210-0210a2f0f73c // indirect
- github.com/gorilla/context v0.0.0-20160226214623-1ea25387ff6f // indirect
- github.com/gorilla/mux v1.6.2
- github.com/jmhodges/levigo v0.0.0-20161115193449-c42d9e0ca023 // indirect
- github.com/jtolds/gls v4.2.1+incompatible // indirect
- github.com/mschoch/smat v0.0.0-20160514031455-90eadee771ae // indirect
- github.com/onsi/gomega v1.4.2 // indirect
- github.com/philhofer/fwd v1.0.0 // indirect
- github.com/pmezard/go-difflib v1.0.0 // indirect
- github.com/pquerna/otp v1.0.1-0.20180621002613-b34af480c0a4
+ github.com/golang/protobuf v1.3.1 // indirect
+ github.com/gorilla/mux v1.7.1
+ github.com/jmhodges/levigo v1.0.0 // indirect
+ github.com/pquerna/otp v1.1.0
+ github.com/remyoudompheng/bigfft v0.0.0-20190512091148-babf20351dd7 // indirect
github.com/russross/blackfriday v1.5.2
- github.com/smartystreets/assertions v0.0.0-20180820201707-7c9eb446e3cf // indirect
- github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a // indirect
github.com/steveyen/gtreap v0.0.0-20150807155958-0abe01ef9be2 // indirect
- github.com/stretchr/testify v1.2.2 // indirect
- github.com/syndtr/goleveldb v0.0.0-20180815032940-ae2bd5eed72d // indirect
- github.com/tecbot/gorocksdb v0.0.0-20180907100951-214b6b7bc0f0 // indirect
- github.com/tinylib/msgp v1.0.2 // indirect
- github.com/urfave/cli v1.19.1
- github.com/willf/bitset v1.1.9 // indirect
- golang.org/x/crypto v0.0.0-20161031180806-9477e0b78b9a
+ github.com/syndtr/goleveldb v1.0.0 // indirect
+ github.com/tecbot/gorocksdb v0.0.0-20181010114359-8752a9433481 // indirect
+ github.com/urfave/cli v1.20.0
+ golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734
)
diff --git a/go.sum b/go.sum
index 3297e59..83ebcb9 100644
--- a/go.sum
+++ b/go.sum
@@ -2,34 +2,35 @@ git.giftfish.de/ston1th/godrop/v2 v2.1.0 h1:vR4aWVeMGJ+tHQH0p44esZrSl5dYJzuCmZqh
git.giftfish.de/ston1th/godrop/v2 v2.1.0/go.mod h1:z8KA3HP/vB04wddLXZfYVKURYDxBGau9hlHtV61x9mM=
git.giftfish.de/ston1th/jwt/v3 v3.2.0 h1:V6Lh7OjXn4D3HPd/LoDf7w5N7cyiSXEPAQCIfSVZ05c=
git.giftfish.de/ston1th/jwt/v3 v3.2.0/go.mod h1:jDALrW7OKeIaqYuMxs3GWyPRnQZmk/R+Lu9p/Em3Ziw=
-github.com/RoaringBitmap/roaring v0.4.16 h1:NholfewybRLOwACgfqfzn/N5xa6keKNs4fP00t0cwLo=
-github.com/RoaringBitmap/roaring v0.4.16/go.mod h1:8khRDP4HmeXns4xIj9oGrKSz7XTQiJx2zgh7AcNke4w=
+github.com/RoaringBitmap/roaring v0.4.17 h1:oCYFIFEMSQZrLHpywH7919esI1VSrQZ0pJXkZPGIJ78=
+github.com/RoaringBitmap/roaring v0.4.17/go.mod h1:D3qVegWTmfCaX4Bl5CrBE9hfrSrrXIr8KVNvRsDi1NI=
github.com/Smerity/govarint v0.0.0-20150407073650-7265e41f48f1 h1:G/NOANWMQev0CftoyxQwtRakdyNNNMB3qxkt/tj1HGs=
github.com/Smerity/govarint v0.0.0-20150407073650-7265e41f48f1/go.mod h1:o80NPAib/LOl8Eysqppjj7kkGkqz++eqzYGlvROpDcQ=
github.com/blevesearch/bleve v0.7.0 h1:znyZ3zjsh2Scr60vszs7rbF29TU6i1q9bfnZf1vh0Ac=
github.com/blevesearch/bleve v0.7.0/go.mod h1:Y2lmIkzV6mcNfAnAdOd+ZxHkHchhBfU/xroGIp61wfw=
github.com/blevesearch/blevex v0.0.0-20180227211930-4b158bb555a3 h1:U6vnxZrTfItfiUiYx0lf/LgHjRSfaKK5QHSom3lEbnA=
github.com/blevesearch/blevex v0.0.0-20180227211930-4b158bb555a3/go.mod h1:WH+MU2F4T0VmSdaPX+Wu5GYoZBrYWdOZWSjzvYcDmqQ=
-github.com/blevesearch/go-porterstemmer v0.0.0-20141230013033-23a2c8e5cf1f h1:J9ZVHbB2X6JNxbKw/f3Y4E9Xq+Ro+zPiivzgmi3RTvg=
-github.com/blevesearch/go-porterstemmer v0.0.0-20141230013033-23a2c8e5cf1f/go.mod h1:haWQqFT3RdOGz7PJuM3or/pWNJS1pKkoZJWCkWu0DVA=
+github.com/blevesearch/go-porterstemmer v1.0.2 h1:qe7n69gBd1OLY5sHKnxQHIbzn0LNJA4hpAf+5XDxV2I=
+github.com/blevesearch/go-porterstemmer v1.0.2/go.mod h1:haWQqFT3RdOGz7PJuM3or/pWNJS1pKkoZJWCkWu0DVA=
github.com/blevesearch/segment v0.0.0-20160915185041-762005e7a34f h1:kqbi9lqXLLs+zfWlgo1PIiRQ86n33K1JKotjj4rSYOg=
github.com/blevesearch/segment v0.0.0-20160915185041-762005e7a34f/go.mod h1:IInt5XRvpiGE09KOk9mmCMLjHhydIhNPKPPFLFBB7L8=
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/boombuler/barcode v1.0.0 h1:s1TvRnXwL2xJRaccrdcBQMZxq6X7DvsMogtmJeHDdrc=
github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
-github.com/couchbase/vellum v0.0.0-20180910213445-01d5c56e6095 h1:dh7mqP7LS9voSd1Wx515giC2lPjPVduBpujISaftHrc=
-github.com/couchbase/vellum v0.0.0-20180910213445-01d5c56e6095/go.mod h1:prYTC8EgTu3gwbqJihkud9zRXISvyulAplQ6exdCo1g=
-github.com/cznic/b v0.0.0-20180115125044-35e9bbe41f07 h1:UHFGPvSxX4C4YBApSPvmUfL8tTvWLj2ryqvT9K4Jcuk=
-github.com/cznic/b v0.0.0-20180115125044-35e9bbe41f07/go.mod h1:URriBxXwVq5ijiJ12C7iIZqlA69nTlI+LgI6/pwftG8=
-github.com/cznic/mathutil v0.0.0-20180504122225-ca4c9f2c1369 h1:XNT/Zf5l++1Pyg08/HV04ppB0gKxAqtZQBRYiYrUuYk=
-github.com/cznic/mathutil v0.0.0-20180504122225-ca4c9f2c1369/go.mod h1:e6NPNENfs9mPDVNRekM7lKScauxd5kXTr1Mfyig6TDM=
-github.com/cznic/strutil v0.0.0-20171016134553-529a34b1c186 h1:0rkFMAbn5KBKNpJyHQ6Prb95vIKanmAe62KxsrN+sqA=
-github.com/cznic/strutil v0.0.0-20171016134553-529a34b1c186/go.mod h1:AHHPPPXTw0h6pVabbcbyGRK1DckRn7r/STdZEeIDzZc=
+github.com/couchbase/vellum v0.0.0-20190328134517-462e86d8716b h1:WgO2yt0pCXyPgU3K/pnY1qO/8FP8TxBAaYXqa+BQpx0=
+github.com/couchbase/vellum v0.0.0-20190328134517-462e86d8716b/go.mod h1:prYTC8EgTu3gwbqJihkud9zRXISvyulAplQ6exdCo1g=
+github.com/cznic/b v0.0.0-20181122101859-a26611c4d92d h1:SwD98825d6bdB+pEuTxWOXiSjBrHdOl/UVp75eI7JT8=
+github.com/cznic/b v0.0.0-20181122101859-a26611c4d92d/go.mod h1:URriBxXwVq5ijiJ12C7iIZqlA69nTlI+LgI6/pwftG8=
+github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548 h1:iwZdTE0PVqJCos1vaoKsclOGD3ADKpshg3SRtYBbwso=
+github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548/go.mod h1:e6NPNENfs9mPDVNRekM7lKScauxd5kXTr1Mfyig6TDM=
+github.com/cznic/strutil v0.0.0-20181122101858-275e90344537 h1:MZRmHqDBd0vxNwenEbKSQqRVT24d3C05ft8kduSwlqM=
+github.com/cznic/strutil v0.0.0-20181122101858-275e90344537/go.mod h1:AHHPPPXTw0h6pVabbcbyGRK1DckRn7r/STdZEeIDzZc=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712 h1:aaQcKT9WumO6JEJcRyTqFVq4XUZiUcKR2/GI31TOcz8=
-github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
+github.com/edsrzf/mmap-go v1.0.0 h1:CEBF7HpRnUCSJgGUb5h1Gm7e3VkmVDrR8lvWVLtrOFw=
+github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51 h1:0JZ+dUmQeA8IIVUMzysrX4/AKuQwWhV2dYQuPZdvdSQ=
github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64=
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 h1:JWuenKqqX8nojtoVVWjGfOF9635RETekkoH6Cc9SX0A=
@@ -38,68 +39,81 @@ github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870 h1:E2s37DuLxFhQD
github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870/go.mod h1:5tD+neXqOorC30/tWg0LCSkrqj/AR6gu8yY8/fpw1q0=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
-github.com/glycerine/go-unsnap-stream v0.0.0-20180323001048-9f0cb55181dd h1:r04MMPyLHj/QwZuMJ5+7tJcBr1AQjpiAK/rZWRrQT7o=
-github.com/glycerine/go-unsnap-stream v0.0.0-20180323001048-9f0cb55181dd/go.mod h1:/20jfyN9Y5QPEAprSgKAUr+glWDY39ZiUEAYOEv5dsE=
+github.com/glycerine/go-unsnap-stream v0.0.0-20181221182339-f9677308dec2 h1:Ujru1hufTHVb++eG6OuNDKMxZnGIvF6o/u8q/8h2+I4=
+github.com/glycerine/go-unsnap-stream v0.0.0-20181221182339-f9677308dec2/go.mod h1:/20jfyN9Y5QPEAprSgKAUr+glWDY39ZiUEAYOEv5dsE=
github.com/glycerine/goconvey v0.0.0-20180728074245-46e3a41ad493 h1:OTanQnFt0bi5iLFSdbEVA/idR6Q2WhCm+deb7ir2CcM=
github.com/glycerine/goconvey v0.0.0-20180728074245-46e3a41ad493/go.mod h1:Ogl1Tioa0aV7gstGFO7KhffUsb9M4ydbEbbxpcEDc24=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
+github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
-github.com/gopherjs/gopherjs v0.0.0-20180825215210-0210a2f0f73c h1:16eHWuMGvCjSfgRJKqIzapE78onvvTbdi1rMkU00lZw=
-github.com/gopherjs/gopherjs v0.0.0-20180825215210-0210a2f0f73c/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
-github.com/gorilla/context v0.0.0-20160226214623-1ea25387ff6f h1:9oNbS1z4rVpbnkHBdPZU4jo9bSmrLpII768arSyMFgk=
-github.com/gorilla/context v0.0.0-20160226214623-1ea25387ff6f/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
-github.com/gorilla/mux v1.6.2 h1:Pgr17XVTNXAk3q/r4CpKzC5xBM/qW1uVLV+IhRZpIIk=
-github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
+github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
+github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
+github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
+github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
+github.com/gorilla/mux v1.7.1 h1:Dw4jY2nghMMRsh1ol8dv1axHkDwMQK2DHerMNJsIpJU=
+github.com/gorilla/mux v1.7.1/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
-github.com/jmhodges/levigo v0.0.0-20161115193449-c42d9e0ca023 h1:y5P5G9cANJZt3MXlMrgELo5mNLZPXH8aGFFFG7IzPU0=
-github.com/jmhodges/levigo v0.0.0-20161115193449-c42d9e0ca023/go.mod h1:Q6Qx+uH3RAqyK4rFQroq9RL7mdkABMcfhEI+nNuzMJQ=
-github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE=
-github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
+github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U=
+github.com/jmhodges/levigo v1.0.0/go.mod h1:Q6Qx+uH3RAqyK4rFQroq9RL7mdkABMcfhEI+nNuzMJQ=
+github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
+github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/mschoch/smat v0.0.0-20160514031455-90eadee771ae h1:VeRdUYdCw49yizlSbMEn2SZ+gT+3IUKx8BqxyQdz+BY=
github.com/mschoch/smat v0.0.0-20160514031455-90eadee771ae/go.mod h1:qAyveg+e4CE+eKJXWVjKXM4ck2QobLqTDytGJbLLhJg=
github.com/onsi/ginkgo v1.6.0 h1:Ix8l273rp3QzYgXSR+c8d1fTG7UPgYkOSELPhiY/YGw=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
-github.com/onsi/gomega v1.4.2 h1:3mYCb7aPxS/RU7TI1y4rkEn1oKmPRjNJLNEXgw7MH2I=
-github.com/onsi/gomega v1.4.2/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
+github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
+github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
+github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
+github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/philhofer/fwd v1.0.0 h1:UbZqGr5Y38ApvM/V/jEljVxwocdweyH+vmYvRPBnbqQ=
github.com/philhofer/fwd v1.0.0/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/pquerna/otp v1.0.1-0.20180621002613-b34af480c0a4 h1:lbSlZWuJMojTqzfawNo4MWd7pO6rts5uB72B8be+l9Q=
-github.com/pquerna/otp v1.0.1-0.20180621002613-b34af480c0a4/go.mod h1:Zad1CMQfSQZI5KLpahDiSUX4tMMREnXw98IvL1nhgMk=
+github.com/pquerna/otp v1.1.0 h1:q2gMsMuMl3JzneUaAX1MRGxLvOG6bzXV51hivBaStf0=
+github.com/pquerna/otp v1.1.0/go.mod h1:Zad1CMQfSQZI5KLpahDiSUX4tMMREnXw98IvL1nhgMk=
+github.com/remyoudompheng/bigfft v0.0.0-20190512091148-babf20351dd7 h1:FUL3b97ZY2EPqg2NbXKuMHs5pXJB9hjj1fDHnF2vl28=
+github.com/remyoudompheng/bigfft v0.0.0-20190512091148-babf20351dd7/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
-github.com/smartystreets/assertions v0.0.0-20180820201707-7c9eb446e3cf h1:6V1qxN6Usn4jy8unvggSJz/NC790tefw8Zdy6OZS5co=
-github.com/smartystreets/assertions v0.0.0-20180820201707-7c9eb446e3cf/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
-github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a h1:JSvGDIbmil4Ui/dDdFBExb7/cmkNjyX5F97oglmvCDo=
-github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s=
+github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
+github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
+github.com/smartystreets/goconvey v0.0.0-20190306220146-200a235640ff h1:86HlEv0yBCry9syNuylzqznKXDK11p6D0DT596yNMys=
+github.com/smartystreets/goconvey v0.0.0-20190306220146-200a235640ff/go.mod h1:KSQcGKpxUMHk3nbYzs/tIBAM2iDooCn0BmttHOJEbLs=
github.com/steveyen/gtreap v0.0.0-20150807155958-0abe01ef9be2 h1:JNEGSiWg6D3lcBCMCBqN3ELniXujt+0QNHLhNnO0w3s=
github.com/steveyen/gtreap v0.0.0-20150807155958-0abe01ef9be2/go.mod h1:mjqs7N0Q6m5HpR7QfXVBZXZWSqTjQLeTujjA/xUp2uw=
-github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
-github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
-github.com/syndtr/goleveldb v0.0.0-20180815032940-ae2bd5eed72d h1:4J9HCZVpvDmj2tiKGSTUnb3Ok/9CEQb9oqu9LHKQQpc=
-github.com/syndtr/goleveldb v0.0.0-20180815032940-ae2bd5eed72d/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0=
-github.com/tecbot/gorocksdb v0.0.0-20180907100951-214b6b7bc0f0 h1:EEAoIgdGCLu3zSryPb/VFHaIGxDlgku3BflSZAtvJD0=
-github.com/tecbot/gorocksdb v0.0.0-20180907100951-214b6b7bc0f0/go.mod h1:ahpPrc7HpcfEWDQRZEmnXMzHY03mLDYMCxeDzy46i+8=
-github.com/tinylib/msgp v1.0.2 h1:DfdQrzQa7Yh2es9SuLkixqxuXS2SxsdYn0KbdrOGWD8=
-github.com/tinylib/msgp v1.0.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE=
-github.com/urfave/cli v1.19.1 h1:0mKm4ZoB74PxYmZVua162y1dGt1qc10MyymYRBf3lb8=
-github.com/urfave/cli v1.19.1/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
-github.com/willf/bitset v1.1.9 h1:GBtFynGY9ZWZmEC9sWuu41/7VBXPFCOAbCbqTflOg9c=
-github.com/willf/bitset v1.1.9/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
-golang.org/x/crypto v0.0.0-20161031180806-9477e0b78b9a h1:Esnda2KnXoH6s+xVTf9zaZg3o4p6d9C25WBNxxDHwOU=
-golang.org/x/crypto v0.0.0-20161031180806-9477e0b78b9a/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
+github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
+github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
+github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
+github.com/tecbot/gorocksdb v0.0.0-20181010114359-8752a9433481 h1:HOxvxvnntLiPn123Fk+twfUhCQdMDaqmb0cclArW0T0=
+github.com/tecbot/gorocksdb v0.0.0-20181010114359-8752a9433481/go.mod h1:ahpPrc7HpcfEWDQRZEmnXMzHY03mLDYMCxeDzy46i+8=
+github.com/tinylib/msgp v1.1.0 h1:9fQd+ICuRIu/ue4vxJZu6/LzxN0HwMds2nq/0cFvxHU=
+github.com/tinylib/msgp v1.1.0/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE=
+github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
+github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
+github.com/willf/bitset v1.1.10 h1:NotGKqX0KwQ72NUzqrjZq5ipPNDQex9lo3WpaS8L2sc=
+github.com/willf/bitset v1.1.10/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
+golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734 h1:p/H982KKEjUnLJkM3tt/LemDnOc1GiZL5FCVlORJ5zo=
+golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
+golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181026144532-2772b66316d2 h1:W7CqTdBJ1CmxLKe7LptKDnBYV6PHrVLiGnoyBjaG/JQ=
golang.org/x/sys v0.0.0-20181026144532-2772b66316d2/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
+golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
diff --git a/main.go b/main.go
index ff3a7bc..68cc741 100644
--- a/main.go
+++ b/main.go
@@ -2,6 +2,8 @@
//go:generate ./templates.sh
+// +build go1.12
+
package main
import "git.giftfish.de/ston1th/gowiki/pkg/cmd"
diff --git a/pkg/cmd/cmd.go b/pkg/cmd/cmd.go
index c19d9d2..757db0e 100644
--- a/pkg/cmd/cmd.go
+++ b/pkg/cmd/cmd.go
@@ -135,6 +135,7 @@ func Run(version string) {
if err = loadConfig(); err != nil {
stdlog.Fatal("dump: ", err)
}
+ log.Stderr()
if dumpFile != "-" {
file, err = os.OpenFile(dumpFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0640)
if err != nil {
diff --git a/pkg/core/const.go b/pkg/core/const.go
index 135d9f0..df69460 100644
--- a/pkg/core/const.go
+++ b/pkg/core/const.go
@@ -12,4 +12,8 @@ const (
LogoutURI = "/logout"
TotpURI = "/totp"
SectionsURI = "/sections"
+
+ BootstrapCSS = "/bootstrap.css"
+ CustomCSS = "/custom.css"
+ Favicon = "/favicon.ico"
)
diff --git a/pkg/db/page.go b/pkg/db/page.go
index 93991fb..7be2f54 100644
--- a/pkg/db/page.go
+++ b/pkg/db/page.go
@@ -187,7 +187,7 @@ func (db *DB) UpdatePage(title, section, markdown, username string, p core.Permi
if err != nil {
return
}
- if !db.WritePerm(title, username, page.Perm) {
+ if !db.WritePerm(section, username, page.Perm) {
return errPermissionDenied
}
diff --git a/pkg/index/index.go b/pkg/index/index.go
index 33ef34c..fe614c5 100644
--- a/pkg/index/index.go
+++ b/pkg/index/index.go
@@ -7,11 +7,16 @@ import (
"git.giftfish.de/ston1th/godrop/v2"
"git.giftfish.de/ston1th/gowiki/pkg/core"
"github.com/blevesearch/bleve"
+ "github.com/blevesearch/bleve/mapping"
"html/template"
"os"
)
-const maxSearchResult = 101
+const (
+ maxSearchResult = 101
+
+ docType = "page"
+)
type indexPage struct {
Title string `json:"title"`
@@ -19,6 +24,10 @@ type indexPage struct {
Search string `json:"search"`
}
+func (*indexPage) Type() string {
+ return docType
+}
+
type Index struct {
i bleve.Index
}
@@ -30,8 +39,22 @@ func NewIndex(path string) (i *Index, err error) {
return
}
if _, err = os.Stat(path); os.IsNotExist(err) {
- mapping := bleve.NewIndexMapping()
- bi, err = bleve.New(path, mapping)
+ err = os.Mkdir(path, 0700)
+ if err != nil {
+ err = errors.New("index: " + err.Error())
+ return
+ }
+ err = godrop.Unveil(path, "rwc")
+ if err != nil {
+ return
+ }
+ var m *mapping.IndexMappingImpl
+ m, err = createMapping()
+ if err != nil {
+ err = errors.New("mapping: " + err.Error())
+ return
+ }
+ bi, err = bleve.New(path, m)
if err != nil {
err = errors.New("index: " + err.Error())
return
@@ -59,7 +82,7 @@ func (i *Index) Add(title, storeTitle, search string) error {
return err
}
}
- return i.i.Index(storeTitle, indexPage{title, storeTitle, search})
+ return i.i.Index(storeTitle, &indexPage{title, storeTitle, search})
}
func (i *Index) Delete(storeTitle string) error {
@@ -67,7 +90,7 @@ func (i *Index) Delete(storeTitle string) error {
}
func (i *Index) Search(search string) (results []core.Result, err error) {
- req := bleve.NewSearchRequest(bleve.NewQueryStringQuery("title:" + search + " search:" + search))
+ req := bleve.NewSearchRequest(bleve.NewQueryStringQuery(search))
req.Highlight = bleve.NewHighlightWithStyle("html")
req.Size = maxSearchResult
res, err := i.i.Search(req)
diff --git a/pkg/index/mapping.go b/pkg/index/mapping.go
new file mode 100644
index 0000000..aa13d60
--- /dev/null
+++ b/pkg/index/mapping.go
@@ -0,0 +1,51 @@
+// Copyright (C) 2019 Marius Schellenberger
+
+package index
+
+import (
+ "github.com/blevesearch/bleve"
+ "github.com/blevesearch/bleve/analysis/analyzer/custom"
+ "github.com/blevesearch/bleve/analysis/token/edgengram"
+ "github.com/blevesearch/bleve/analysis/token/lowercase"
+ "github.com/blevesearch/bleve/analysis/tokenizer/unicode"
+ "github.com/blevesearch/bleve/mapping"
+)
+
+func createMapping() (m *mapping.IndexMappingImpl, err error) {
+ m = bleve.NewIndexMapping()
+
+ err = m.AddCustomTokenFilter("bigram_tokenfilter", map[string]interface{}{
+ "type": edgengram.Name,
+ "side": edgengram.FRONT,
+ "min": 3.0,
+ "max": 25.0,
+ })
+ if err != nil {
+ return
+ }
+ err = m.AddCustomAnalyzer("fulltext_ngram", map[string]interface{}{
+ "type": custom.Name,
+ "tokenizer": unicode.Name,
+ "token_filters": []string{
+ lowercase.Name,
+ "bigram_tokenfilter",
+ },
+ })
+ if err != nil {
+ return
+ }
+
+ doc := bleve.NewDocumentMapping()
+ ti := bleve.NewTextFieldMapping()
+ ti.Analyzer = "fulltext_ngram"
+ doc.AddFieldMappingsAt("title", ti)
+ st := bleve.NewTextFieldMapping()
+ st.Analyzer = "fulltext_ngram"
+ doc.AddFieldMappingsAt("store_title", st)
+ s := bleve.NewTextFieldMapping()
+ s.Analyzer = "fulltext_ngram"
+ doc.AddFieldMappingsAt("search", s)
+
+ m.AddDocumentMapping(docType, doc)
+ return
+}
diff --git a/pkg/log/log.go b/pkg/log/log.go
index 6c148c7..ac5ca61 100644
--- a/pkg/log/log.go
+++ b/pkg/log/log.go
@@ -15,6 +15,10 @@ var (
debug = false
)
+func Stderr() {
+ log = stdlog.New(os.Stderr, "", stdlog.LstdFlags)
+}
+
func InitLogger(cfg core.Config) {
debug = cfg.Debug
if cfg.LogFile == "-" {
diff --git a/pkg/server/context.go b/pkg/server/context.go
index 57be0d0..d178070 100644
--- a/pkg/server/context.go
+++ b/pkg/server/context.go
@@ -27,53 +27,19 @@ const (
refererClaim = "referer"
)
-func newContext(w http.ResponseWriter, r *http.Request, s *HTTPServer) (ctx *Context) {
+func newContext(w http.ResponseWriter, r *http.Request, s *HTTPServer) *Context {
h := w.Header()
h.Set("X-Frame-Options", "DENY")
h.Set("X-Content-Type-Options", "nosniff")
h.Set("X-XSS-Protection", "1; mode=block")
h.Set("Content-Security-Policy", "default-src 'none';style-src 'self';img-src 'self' https: data:;connect-src 'self';frame-ancestors 'none'")
h.Set("Referrer-Policy", "same-origin")
- ctx = &Context{
+ return &Context{
Request: r,
Response: w,
Srv: s,
Time: time.Now(),
}
- path := ctx.Path()
- if path == "/bootstrap.css" || path == "/custom.css" {
- return
- }
-
- if c, err := r.Cookie(cookieName); err == nil {
- t, err := jwt.DecodeToken(c.Value)
- if err != nil {
- ctx.LogSetCookie("DecodeToken:", err)
- return
- }
- if err = s.JWT.Verify(t); err != nil {
- ctx.LogSetCookie("VerifyToken:", err)
- return
- }
- if t.Claims.GetString(totpClaim) != "" {
- if path == core.TotpURI || path == core.LoginURI || path == core.LogoutURI {
- ctx.Token = *t
- return
- }
- ctx.Redirect(core.TotpURI, http.StatusFound)
- return nil
-
- }
- if !s.DB.LockedOut(t.Claims.GetString(userClaim), t.Claims.GetString(userCreatedClaim)) {
- ctx.Token = *t
- return
- }
- if err = s.JWT.Invalidate(t); err != nil {
- log.Println("Invalidate:", err)
- }
- }
- ctx.SetCookie(nil, 0)
- return
}
type Context struct {
@@ -132,7 +98,10 @@ func (c *Context) Exec() {
c.Err = errors.New("template is nil")
return
}
- c.Data.Token = newXsrf(c.Token.RawSig()[:keySize])
+ sig := c.Token.RawSig()
+ if len(sig) >= keySize {
+ c.Data.Token = newXsrf(sig[:keySize])
+ }
c.Data.Version = c.Srv.Config.Version
if c.Data.BodyTitle == "" {
diff --git a/pkg/server/handler.go b/pkg/server/handler.go
index 65cc6c6..4c82dd5 100644
--- a/pkg/server/handler.go
+++ b/pkg/server/handler.go
@@ -20,6 +20,43 @@ func (nf *notFoundHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
newContext(w, r, nf.s).NotFound()
}
+func jwtHandler(h ctxHandler) ctxHandler {
+ return func(ctx *Context) {
+ if c, err := ctx.Request.Cookie(cookieName); err == nil {
+ t, err := jwt.DecodeToken(c.Value)
+ if err != nil {
+ ctx.LogSetCookie("DecodeToken:", err)
+ return
+ }
+ if err = ctx.Srv.JWT.Verify(t); err != nil {
+ ctx.LogSetCookie("VerifyToken:", err)
+ return
+ }
+ if t.Claims.GetString(totpClaim) != "" {
+ path := ctx.Path()
+ if path == core.TotpURI || path == core.LoginURI || path == core.LogoutURI {
+ ctx.Token = *t
+ h(ctx)
+ return
+ }
+ ctx.Redirect(core.TotpURI, http.StatusFound)
+ return
+
+ }
+ if !ctx.Srv.DB.LockedOut(t.Claims.GetString(userClaim), t.Claims.GetString(userCreatedClaim)) {
+ ctx.Token = *t
+ h(ctx)
+ return
+ }
+ if err = ctx.Srv.JWT.Invalidate(t); err != nil {
+ log.Println("Invalidate:", err)
+ }
+ }
+ ctx.SetCookie(nil, 0)
+ h(ctx)
+ }
+}
+
func totpAuthHandler(h ctxHandler) ctxHandler {
return func(ctx *Context) {
if ctx.Totp() != "" {
@@ -69,11 +106,11 @@ func staticHandler(ctx *Context) {
ctx.SetHeader("Content-Type", "text/css; charset=utf-8")
ctx.SetHeader("Expires", time.Now().UTC().Add(max).Format(http.TimeFormat))
switch ctx.Path() {
- case "/bootstrap.css":
+ case core.BootstrapCSS:
err = ctx.Write(ctx.Srv.res["bootstrap.css"])
- case "/custom.css":
+ case core.CustomCSS:
err = ctx.Write(ctx.Srv.res["custom.css"])
- case "/favicon.ico":
+ case core.Favicon:
ctx.SetHeader("Content-Type", "image/x-icon")
err = ctx.Write(ctx.Srv.res["favicon.ico"])
}
@@ -458,8 +495,8 @@ func pageHandler(ctx *Context) {
return
}
ctx.Data.Data = page
- ctx.Data.Title = page.Title
- ctx.Data.BodyTitle = page.Title
+ ctx.Data.Title = section + " | " + page.Title
+ ctx.Data.BodyTitle = section
ctx.Exec()
}
diff --git a/pkg/server/routes.go b/pkg/server/routes.go
index 26c4094..d4b5f75 100644
--- a/pkg/server/routes.go
+++ b/pkg/server/routes.go
@@ -2,167 +2,197 @@
package server
+import "git.giftfish.de/ston1th/gowiki/pkg/core"
+
type route struct {
Path string
Handler ctxHandler
Methods []string
}
+var static = []route{
+ {
+ core.Favicon,
+ staticHandler,
+ []string{"GET"},
+ },
+ {
+ core.BootstrapCSS,
+ staticHandler,
+ []string{"GET"},
+ },
+ {
+ core.CustomCSS,
+ staticHandler,
+ []string{"GET"},
+ },
+}
+
var routes = []route{
{
"/",
- indexHandler,
- []string{"GET"},
- },
- {
- "/favicon.ico",
- staticHandler,
- []string{"GET"},
- },
- {
- "/bootstrap.css",
- staticHandler,
- []string{"GET"},
- },
- {
- "/custom.css",
- staticHandler,
+ jwtHandler(
+ indexHandler),
[]string{"GET"},
},
{
"/sections",
- sectionsHandler,
+ jwtHandler(
+ sectionsHandler),
[]string{"GET"},
},
{
"/section/new",
- adminAuthHandler(
- sectionNewHandler),
+ jwtHandler(
+ adminAuthHandler(
+ sectionNewHandler)),
[]string{"GET", "POST"},
},
{
"/section/edit/{section:[a-zA-Z0-9]+$}",
- adminAuthHandler(
- sectionEditHandler),
+ jwtHandler(
+ adminAuthHandler(
+ sectionEditHandler)),
[]string{"GET", "POST"},
},
{
"/section/del/{section:[a-zA-Z0-9]+$}",
- adminAuthHandler(
- sectionDelHandler),
+ jwtHandler(
+ adminAuthHandler(
+ sectionDelHandler)),
[]string{"GET", "POST"},
},
{
"/search",
- searchHandler,
+ jwtHandler(
+ searchHandler),
[]string{"GET", "POST"},
},
{
"/new",
- authHandler(
- pageNewHandler),
+ jwtHandler(
+ authHandler(
+ pageNewHandler)),
[]string{"GET", "POST"},
},
{
"/login",
- loginHandler,
+ jwtHandler(
+ loginHandler),
[]string{"GET", "POST"},
},
{
"/totp",
- totpAuthHandler(
- loginTotpHandler),
+ jwtHandler(
+ totpAuthHandler(
+ loginTotpHandler)),
[]string{"GET", "POST"},
},
{
"/blacklist",
- authHandler(
- pageBlacklistHandler),
+ jwtHandler(
+ authHandler(
+ pageBlacklistHandler)),
[]string{"GET", "POST"},
},
{
"/users",
- adminAuthHandler(
- usersHandler),
+ jwtHandler(
+ adminAuthHandler(
+ usersHandler)),
[]string{"GET"},
},
{
"/user/new",
- adminAuthHandler(
- userNewHandler),
+ jwtHandler(
+ adminAuthHandler(
+ userNewHandler)),
[]string{"GET", "POST"},
},
{
"/user/edit/{user:[a-zA-Z0-9]+$}",
- userAuthHandler(
- userEditHandler),
+ jwtHandler(
+ userAuthHandler(
+ userEditHandler)),
[]string{"GET", "POST"},
},
{
"/user/del/{user:[a-zA-Z0-9]+$}",
- userAuthHandler(
- userDelHandler),
+ jwtHandler(
+ userAuthHandler(
+ userDelHandler)),
[]string{"GET", "POST"},
},
{
"/user/totp/{user:[a-zA-Z0-9]+$}",
- userAuthHandler(
- userTotpHandler),
+ jwtHandler(
+ userAuthHandler(
+ userTotpHandler)),
[]string{"GET", "POST"},
},
{
"/user/unlock/{user:[a-zA-Z0-9]+$}",
- adminAuthHandler(
- userUnlockHandler),
+ jwtHandler(
+ adminAuthHandler(
+ userUnlockHandler)),
[]string{"POST"},
},
{
"/logout",
- logoutHandler,
+ jwtHandler(
+ logoutHandler),
[]string{"GET", "POST"},
},
{
"/view/{key}",
- pageHandler,
+ jwtHandler(
+ pageHandler),
[]string{"GET"},
},
{
"/view/{key}/md",
- pageMDHandler(
- pageHandler),
+ jwtHandler(
+ pageMDHandler(
+ pageHandler)),
[]string{"GET"},
},
{
"/{section:[a-zA-Z0-9]+}",
- sectionHandler,
+ jwtHandler(
+ sectionHandler),
[]string{"GET"},
},
{
"/{section:[a-zA-Z0-9]+}/{title:[a-zA-Z0-9+-]+}",
- pageHandler,
- []string{"GET"},
- },
- {
- "/{section:[a-zA-Z0-9]+}/{title:[a-zA-Z0-9+-]+}/md",
- pageMDHandler(
+ jwtHandler(
pageHandler),
[]string{"GET"},
},
+ {
+ "/{section:[a-zA-Z0-9]+}/{title:[a-zA-Z0-9+-]+}/md",
+ jwtHandler(
+ pageMDHandler(
+ pageHandler)),
+ []string{"GET"},
+ },
{
"/{section:[a-zA-Z0-9]+}/{title:[a-zA-Z0-9+-]+}/share",
- pageShareHandler,
+ jwtHandler(
+ pageShareHandler),
[]string{"GET", "POST"},
},
{
"/{section:[a-zA-Z0-9]+}/{title:[a-zA-Z0-9+-]+}/edit",
- authHandler(
- pageEditHandler),
+ jwtHandler(
+ authHandler(
+ pageEditHandler)),
[]string{"GET", "POST"},
},
{
"/{section:[a-zA-Z0-9]+}/{title:[a-zA-Z0-9+-]+}/del",
- authHandler(
- pageDelHandler),
+ jwtHandler(
+ authHandler(
+ pageDelHandler)),
[]string{"GET", "POST"},
},
}
diff --git a/pkg/server/server.go b/pkg/server/server.go
index 8bfb4e6..371aab0 100644
--- a/pkg/server/server.go
+++ b/pkg/server/server.go
@@ -19,7 +19,7 @@ import (
)
const (
- cookieName = "gosession"
+ cookieName = "gowiki_session"
)
type HTTPServer struct {
@@ -81,6 +81,9 @@ func (s *HTTPServer) Stop() error {
func (s *HTTPServer) buildRoutes() http.Handler {
m := mux.NewRouter()
m.NotFoundHandler = ¬FoundHandler{s}
+ for _, v := range static {
+ m.HandleFunc(v.Path, s.contextWrapper(v.Handler)).Methods(v.Methods...)
+ }
for _, v := range routes {
m.HandleFunc(v.Path, s.contextWrapper(v.Handler)).Methods(v.Methods...)
}
@@ -88,10 +91,6 @@ func (s *HTTPServer) buildRoutes() http.Handler {
}
func (s *HTTPServer) contextWrapper(h ctxHandler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
- ctx := newContext(w, r, s)
- if ctx == nil {
- return
- }
- h(ctx)
+ h(newContext(w, r, s))
}
}
diff --git a/pkg/server/templates.go b/pkg/server/templates.go
index ce21ebf..ffd0fc8 100644
--- a/pkg/server/templates.go
+++ b/pkg/server/templates.go
@@ -35,8 +35,8 @@ const (
GoWiki | {{.Title}}
-
-
+
+
@@ -251,9 +251,25 @@ const (
{{end}}`
page = `{{define "body"}}
-