Commit e5d63f12 authored by Ghost User's avatar Ghost User Committed by zauberstuhl

Implement ActivityPub

parent 346a0811
......@@ -19,8 +19,10 @@ stages:
- deploy
before_script:
- export VERSION=$(git tag -l --sort=-v:refname |head -n1)
- mkdir -p $GOPATH/src/git.feneas.org/ganggo
- ln -s $(pwd) $GOPATH/src/git.feneas.org/ganggo/ganggo
- export PROJECT_PATH=$GOPATH/src/git.feneas.org/ganggo
- mkdir -p $PROJECT_PATH
- ln -s $(pwd) $PROJECT_PATH/ganggo
- cd $PROJECT_PATH/ganggo
- make install
run unit tests:
stage: test
......
......@@ -4,8 +4,8 @@
[[projects]]
name = "cloud.google.com/go"
packages = ["civil"]
revision = "aad3f485ee528456e0768f20397b4d9dd941e755"
version = "v0.25.0"
revision = "c728a003b238b26cef9ab6753a5dc424b331c3ad"
version = "v0.27.0"
[[projects]]
branch = "master"
......@@ -15,13 +15,34 @@
"app/controllers",
"app/helpers"
]
revision = "f4932ab8362e8e2a4e63aa88f07d17bed21f7134"
revision = "2fb8ead5ef0fe4b57dbbbdf147e848fca6486480"
[[projects]]
branch = "master"
name = "git.feneas.org/ganggo/federation"
packages = [
".",
"helpers"
]
revision = "76129a9a4da34965bb2cce23e5e5808a5437c2a6"
[[projects]]
name = "git.feneas.org/ganggo/gorm"
packages = [
".",
"dialects/mssql",
"dialects/mysql",
"dialects/postgres",
"dialects/sqlite"
]
revision = "c5bf88f4a1f896b106734023e9e8d68bcf9ca5ba"
version = "v1.9.3"
[[projects]]
branch = "ecdsa"
name = "git.feneas.org/ganggo/httpsignatures"
packages = ["."]
revision = "59eaaf5c998263705f44bc1706686515b5f028f5"
revision = "3ee9f28e5cf7db6ee603059334e87eacb08ddee9"
[[projects]]
name = "github.com/PuerkitoBio/goquery"
......@@ -82,8 +103,8 @@
"service/s3",
"service/sts"
]
revision = "9e9afa0895e9daff556cc18f90dc53eb91f41ffd"
version = "v1.14.26"
revision = "71a2a92b0063297b055b6f5a014d441c142da2ce"
version = "v1.15.32"
[[projects]]
name = "github.com/certifi/gocertifi"
......@@ -104,7 +125,7 @@
".",
"internal/cp"
]
revision = "242fa5aa1b45aeb9fcdfeee88822982e3f548e22"
revision = "1eb28afdf9b6e56cf673badd47545f844fe81103"
[[projects]]
name = "github.com/fatih/structs"
......@@ -112,17 +133,65 @@
revision = "a720dfa8df582c51dee1b36feabb906bde1588bd"
version = "v1.0"
[[projects]]
branch = "master"
name = "github.com/getlantern/byteexec"
packages = ["."]
revision = "4cfb26ec74f460fda433dc06fddfbad7ddee3072"
[[projects]]
branch = "master"
name = "github.com/getlantern/context"
packages = ["."]
revision = "624d99b1798d7c5375ea1d3ca4c5b04d58f7c775"
[[projects]]
branch = "master"
name = "github.com/getlantern/errors"
packages = ["."]
revision = "e24b7f4ff7c70be59bbefca6b7695d68cda8b399"
[[projects]]
branch = "master"
name = "github.com/getlantern/filepersist"
packages = ["."]
revision = "c5f0cd24e7991579ba6f5f1bd20a1ad2c9f06cd4"
[[projects]]
branch = "master"
name = "github.com/getlantern/golog"
packages = ["."]
revision = "cca714f7feb5df8e455f409b549d384441ac4578"
[[projects]]
branch = "master"
name = "github.com/getlantern/hex"
packages = ["."]
revision = "083fba3033ad473db3dd31c9bb368473d37581a7"
[[projects]]
branch = "master"
name = "github.com/getlantern/hidden"
packages = ["."]
revision = "d52a649ab33af200943bb599898dbdcfdbc94cb7"
[[projects]]
branch = "master"
name = "github.com/getlantern/ops"
packages = ["."]
revision = "37353306c90844c8e0591956f56611f46299d202"
[[projects]]
branch = "master"
name = "github.com/getsentry/raven-go"
packages = ["."]
revision = "ed7bcb39ff10f39ab08e317ce16df282845852fa"
revision = "084a9de9eb0361fbd5ded14b55c84e5493a5d7f6"
[[projects]]
name = "github.com/go-ini/ini"
packages = ["."]
revision = "358ee7663966325963d4e8b2e1fbd570c5195153"
version = "v1.38.1"
revision = "5cf292cae48347c2490ac1a58fe36735fb78df7e"
version = "v1.38.2"
[[projects]]
name = "github.com/go-sql-driver/mysql"
......@@ -130,11 +199,17 @@
revision = "d523deb1b23d913de5bdada721a6071e71283618"
version = "v1.4.0"
[[projects]]
name = "github.com/go-stack/stack"
packages = ["."]
revision = "2fee6af1a9795aafbe0253a0cfbdf668e1fb8a9a"
version = "v1.8.0"
[[projects]]
name = "github.com/inconshreveable/log15"
packages = ["term"]
revision = "0decfc6c20d9ca0ad143b0e89dcaa20f810b4fb3"
version = "v2.13"
revision = "67afb5ed74ec82fd7ac8f49d27c509ac6f991970"
version = "v2.14"
[[projects]]
branch = "master"
......@@ -156,12 +231,24 @@
]
revision = "9891188db5a5bdae87416218253ac3a5ed4aed8a"
[[projects]]
name = "github.com/jteeuwen/go-bindata"
packages = ["."]
revision = "bbd0c6e271208dce66d8fda4bc536453cd27fc4a"
version = "v3.0.7"
[[projects]]
branch = "master"
name = "github.com/kardianos/osext"
packages = ["."]
revision = "ae77be60afb1dcacde03767a8c37337fad28ac14"
[[projects]]
branch = "master"
name = "github.com/kballard/go-shellquote"
packages = ["."]
revision = "95032a82bc518f77982ea72343cc1ade730072f0"
[[projects]]
name = "github.com/klauspost/compress"
packages = [
......@@ -179,14 +266,14 @@
version = "v1.1"
[[projects]]
branch = "master"
name = "github.com/lib/pq"
packages = [
".",
"hstore",
"oid"
]
revision = "90697d60dd844d5ef6ff15135d0203f65d2f53b8"
revision = "4ded0e9383f75c197b3a2aaa6d590ac52df6fd79"
version = "v1.0.0"
[[projects]]
name = "github.com/mattn/go-colorable"
......@@ -197,8 +284,8 @@
[[projects]]
name = "github.com/mattn/go-isatty"
packages = ["."]
revision = "0360b2af4f38e8d38c7fce2a9f4e702702d73a39"
version = "v0.0.3"
revision = "6ca4dbf54d38eea1a992b3c722a76a5d1c4cb25c"
version = "v0.0.4"
[[projects]]
name = "github.com/mattn/go-sqlite3"
......@@ -212,6 +299,18 @@
packages = ["."]
revision = "9520e82c474b0a04dd04f8a40959027271bab992"
[[projects]]
name = "github.com/microcosm-cc/bluemonday"
packages = ["."]
revision = "82c7118e8ccf7403d4860175d97bb635e8e28239"
version = "v1.0.1"
[[projects]]
branch = "master"
name = "github.com/oxtoacart/bpool"
packages = ["."]
revision = "4e1c5567d7c2dd59fa4c7c83d34c2f3528b025d6"
[[projects]]
name = "github.com/pkg/errors"
packages = ["."]
......@@ -224,8 +323,8 @@
"harness",
"revel"
]
revision = "95d6366c0d8d727ca62767848fb0801268b49ea6"
version = "v0.14.1"
revision = "97ec1422620f1a83cd13738708a109fe092364ca"
version = "v0.19.0"
[[projects]]
name = "github.com/revel/config"
......@@ -278,6 +377,8 @@
name = "github.com/shaoshing/train"
packages = [
".",
"cmd",
"command",
"interpreter"
]
revision = "c76b6fe70b70a926afe20cf76df0e237e59f4655"
......@@ -296,7 +397,7 @@
"blowfish",
"md4"
]
revision = "a49355c7e3f8fe157a85be2f77e6e269a0f89602"
revision = "0e37d006457bf46f9e6692014ba72ef82c33022c"
[[projects]]
branch = "master"
......@@ -306,13 +407,13 @@
"html/atom",
"websocket"
]
revision = "d0887baf81f4598189d4e12a37c6da86f0bba4d0"
revision = "161cd47e91fd58ac17490ef4d742dc98bb4cf60e"
[[projects]]
branch = "master"
name = "golang.org/x/sys"
packages = ["unix"]
revision = "1b2967e3c290b7c545b3db0deeda16e9be4f98a2"
revision = "d0be0721c37eeb5299f245a996a483160fc36940"
[[projects]]
name = "google.golang.org/appengine"
......@@ -327,8 +428,8 @@
"core",
"terminal"
]
revision = "17861e192dc11fd2f5081df1932c94cce262fa1e"
version = "v1.6.1"
revision = "f30c5d1830c892f533140f29a1de89141dc217f5"
version = "v1.6.2"
[[projects]]
name = "gopkg.in/fsnotify/fsnotify.v1"
......@@ -338,13 +439,7 @@
[[projects]]
name = "gopkg.in/ganggo/gorm.v2"
packages = [
".",
"dialects/mssql",
"dialects/mysql",
"dialects/postgres",
"dialects/sqlite"
]
packages = ["."]
revision = "4cacfdfb7921a87c774cbf21382714e07ca0b44f"
version = "v2.0"
......@@ -363,6 +458,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "04468b6173142c89caa5e22e90c6af57fdf861768634cf0be4a8f5d8815e1b6d"
inputs-digest = "84a0b763da99a39b3502dcb0d1a79d9093c73b01ef7997e9319e561bfd56d285"
solver-name = "gps-cdcl"
solver-version = 1
......@@ -4,7 +4,11 @@
# for detailed Gopkg.toml documentation.
#
required = ["github.com/revel/cmd/revel"]
required = [
"github.com/revel/cmd/revel",
"github.com/shaoshing/train/cmd",
"github.com/kevinburke/go-bindata",
]
[[override]]
version = "0.19.0"
......@@ -15,7 +19,7 @@ required = ["github.com/revel/cmd/revel"]
name = "github.com/revel/revel"
[[override]]
version = "0.14.1"
version = "0.19.0"
name = "github.com/revel/cmd"
[[override]]
......@@ -38,10 +42,14 @@ required = ["github.com/revel/cmd/revel"]
branch = "master"
name = "github.com/revel/log15"
[[override]]
branch = "ecdsa"
name = "git.feneas.org/ganggo/httpsignatures"
[[constraint]]
name = "gopkg.in/AlecAivazis/survey.v1"
version = "1.4.1"
[[constraint]]
name = "gopkg.in/ganggo/gorm.v2"
version = "2.0.0"
name = "git.feneas.org/ganggo/gorm"
version = "1.9.3"
......@@ -22,15 +22,20 @@ define version_info
endef
define install-tools
# go dependencies
# go dependency tool
go get -u github.com/golang/dep/cmd/dep
# download all dependencies
cd $(srcdir) && dep ensure
# web framework
go get -u github.com/revel/cmd/revel
cd $(srcdir)/vendor/github.com/revel/cmd/revel && \
go build -o $$GOPATH/bin/revel
# asset compilation
go get -u github.com/shaoshing/train/cmd
go build -o $$GOPATH/bin/train github.com/shaoshing/train/cmd
cd $(srcdir)/vendor/github.com/shaoshing/train/cmd && \
go build -o $$GOPATH/bin/train
# embedding binary data e.g. assets
go get -u github.com/jteeuwen/go-bindata/...
cd $(srcdir)/vendor/github.com/kevinburke/go-bindata/go-bindata && \
go build -o $$GOPATH/bin/go-bindata
rm -r $(srcdir)/vendor/github.com/kevinburke/go-bindata/testdata
endef
install: clean install-deps
......@@ -46,8 +51,6 @@ ifndef godep
endif
# Install CSS and Javascript dependencies
cd $(srcdir) && npm install --prefix .
# ganggo dependencies
cd $(srcdir) && dep ensure
clean:
rm -r tmp vendor node_modules \
......
......@@ -25,4 +25,8 @@
location.reload();
});
}
$('#stream-editor-link').click(function() {
$('#stream-editor').toggle();
});
})();
......@@ -30,7 +30,9 @@ body {
}
.nav.nav-tabs {
overflow: auto;
overflow-x: auto;
overflow-y: hidden;
flex-wrap: nowrap;
}
.card img {
......@@ -50,7 +52,7 @@ body {
}
footer {
height: 2.5rem;
height: auto;
position: absolute;
bottom: 0;
width: 100%;
......
......@@ -19,11 +19,11 @@ package controllers
import (
"net/http"
"encoding/xml"
"github.com/revel/revel"
"git.feneas.org/ganggo/ganggo/app/models"
"git.feneas.org/ganggo/ganggo/app/helpers"
federation "git.feneas.org/ganggo/federation"
fhelpers "git.feneas.org/ganggo/federation/helpers"
"git.feneas.org/ganggo/federation"
"strings"
)
......@@ -58,37 +58,32 @@ func (f Fetch) Index(shareable, guid string) revel.Result {
}
if user, ok := post.IsLocal(); ok {
privKey, err := federation.ParseRSAPrivateKey(
privKey, err := fhelpers.ParseRSAPrivateKey(
[]byte(user.SerializedPrivateKey))
if err != nil {
f.Log.Error("Fetch parse key error", "err", err)
return f.NotFound("record not found")
}
entity := federation.EntityStatusMessage{
Text: post.Text,
Author: post.Person.Author,
Guid: post.Guid,
ProviderName: post.ProviderName,
Public: post.Public,
}
entity.CreatedAt.New(post.CreatedAt)
entityXml, err := xml.Marshal(entity)
entity, err := federation.NewMessagePost(federation.DiasporaProtocol)
if err != nil {
f.Log.Error("Fetch marshal error", "err", err)
return f.RenderError(err)
f.Log.Error("Fetch message error", "err", err)
return f.NotFound("record not found")
}
entity.SetText(post.Text)
entity.SetAuthor(post.Person.Author)
entity.SetGuid(post.Guid)
entity.SetProvider(post.ProviderName)
entity.SetPublic(post.Public)
entity.SetCreatedAt(post.CreatedAt)
payload, err = federation.MagicEnvelope(
privKey, user.Person.Author, entityXml,
)
payload, err = entity.Marshal(privKey, nil)
if err != nil {
f.Log.Error("Fetch magic envelope error", "err", err)
return f.RenderError(err)
}
} else {
_, host, err := helpers.ParseAuthor(post.Person.Author)
host, err := helpers.ParseHost(post.Person.Author)
if err != nil {
f.Log.Error("Fetch parse author error", "err", err)
return f.RenderError(err)
......
......@@ -20,7 +20,8 @@ package controllers
import (
"net/http"
"github.com/revel/revel"
federation "git.feneas.org/ganggo/federation"
helpers "git.feneas.org/ganggo/federation/helpers"
"git.feneas.org/ganggo/federation"
run "github.com/revel/modules/jobs/app/jobs"
"git.feneas.org/ganggo/ganggo/app/models"
"git.feneas.org/ganggo/ganggo/app/jobs"
......@@ -51,26 +52,18 @@ func (r Receiver) Public() revel.Result {
// in case it succeeds reply with status 202
r.Response.Status = http.StatusAccepted
msg, entity, err := federation.ParseDecryptedRequest(content)
msg, err := federation.DiasporaParse(content)
if err != nil {
r.Log.Error("Cannot parse decrypted request", "error", err)
// NOTE Send accept code even tho the entity is not
// known otherwise the sender pod will throw an error
//r.Response.Status = http.StatusNotAcceptable
return r.Render()
r.Log.Error("Cannot parse content", err.Error(), err)
} else {
run.Now(jobs.Receiver{Message: msg})
}
run.Now(jobs.Receiver{
Message: msg,
Entity: entity,
})
return r.Render()
}
func (r Receiver) Private() revel.Result {
var (
guid string
wrapper federation.AesWrapper
person models.Person
user models.User
)
......@@ -82,11 +75,10 @@ func (r Receiver) Private() revel.Result {
}
defer db.Close()
r.Params.BindJSON(&wrapper)
r.Params.Bind(&guid, "guid")
r.Response.Status = http.StatusAccepted
r.Log.Debug("AES request", "message", wrapper)
r.Log.Debug("received privately", "message", string(r.Params.JSON))
err = db.Where("guid like ?", guid).First(&person).Error
if err != nil {
......@@ -102,7 +94,7 @@ func (r Receiver) Private() revel.Result {
return r.Render()
}
privKey, err := federation.ParseRSAPrivateKey(
privKey, err := helpers.ParseRSAPrivateKey(
[]byte(user.SerializedPrivateKey))
if err != nil {
r.Log.Error(err.Error())
......@@ -110,19 +102,11 @@ func (r Receiver) Private() revel.Result {
return r.Render()
}
msg, entity, err := federation.ParseEncryptedRequest(wrapper, privKey)
msg, err := federation.DiasporaParseEncrypted(r.Params.JSON, privKey)
if err != nil {
r.Log.Error("Cannot parse encrypted request", "error", err)
// NOTE Send accept code even tho the entity is not
// known otherwise the sender pod will throw an error
//r.Response.Status = http.StatusNotAcceptable
return r.Render()
r.Log.Error("Cannot parse content", err.Error(), err)
} else {
run.Now(jobs.Receiver{Message: msg, Guid: guid})
}
run.Now(jobs.Receiver{
Message: msg,
Entity: entity,
Guid: guid,
})
return r.Render()
}
......@@ -36,6 +36,7 @@ func (s Search) Index(text string) revel.Result {
func (s Search) IndexPagination(text string, page uint) revel.Result {
var offset uint = ((page - 1) * 10)
text = strings.Replace(text, "'", "", -1)
text = strings.Replace(text, "\"", "", -1)
user, err := models.CurrentUser(s.Controller)
if err != nil {
......@@ -59,17 +60,22 @@ func (s Search) IndexPagination(text string, page uint) revel.Result {
}
func (s Search) Create(search string) revel.Result {
_, _, err := helpers.ParseAuthor(search)
_, err := helpers.ParseUsername(search)
if err != nil {
s.Log.Debug("Cannot parse handle author", "error", err)
return s.Redirect("/search/%s", search)
}
user, err := models.CurrentUser(s.Controller)
if err == nil {
s.ViewArgs["currentUser"] = user
}
fetchAuthor := jobs.FetchAuthor{Author: search}
fetchAuthor.Run()
if fetchAuthor.Err != nil {
s.Log.Error("Cannot fetch author", "error", fetchAuthor.Err)
return s.RenderError(fetchAuthor.Err)
return s.NotFound(fetchAuthor.Err.Error())
}
guid := fetchAuthor.Person.Guid
......
......@@ -18,6 +18,7 @@ package controllers
//
import (
"regexp"
"github.com/revel/revel"
"github.com/dchest/captcha"
"git.feneas.org/ganggo/ganggo/app/models"
......@@ -64,6 +65,13 @@ func (u User) Create() revel.Result {
return u.Redirect(User.Index)
}
// only allow alphabet, numeric and dash characters
validUsername := regexp.MustCompile(`^[a-zA-Z0-9_]+$`)
if !validUsername.MatchString(username) {
u.Flash.Error(u.Message("flash.errors.username"))
return u.Redirect(User.Index)
}
if !db.Where("username = ?", username).First(&user).RecordNotFound() {
u.Flash.Error(u.Message("flash.errors.username"))
return u.Redirect(User.Index)
......
......@@ -20,8 +20,10 @@ package controllers
import (
"net/http"
"github.com/revel/revel"
api "git.feneas.org/ganggo/api/app"
"git.feneas.org/ganggo/ganggo/app/models"
federation "git.feneas.org/ganggo/federation"
helpers "git.feneas.org/ganggo/federation/helpers"
"errors"
)
......@@ -56,7 +58,7 @@ func (c Webfinger) Webfinger() revel.Result {
return c.RenderError(errors.New("No address config found"))
}
username, err := federation.ParseWebfingerHandle(resource)
username, err := helpers.ParseWebfingerHandle(resource)
if err != nil {
c.Response.Status = http.StatusNotFound
c.Log.Error("Cannot parse webfinger handle", "error", err)
......@@ -96,12 +98,19 @@ func (c Webfinger) Webfinger() revel.Result {
federation.WebfingerDataLink {
Rel: "http://webfinger.net/rel/profile-page",
Type: "text/html",
Href: proto + address + "/u/" + username,
Href: proto + address + "/profiles/" + person.Guid,
},