Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vue #3

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: Unlicense

node_moduels
node_modules
ssb-go-room-secrets
ssb-go-room-secrets/**/*
.git
Expand Down
1 change: 1 addition & 0 deletions .env_example
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@

HTTPS_DOMAIN=yourhttpsdomainhere
ALIASES_AS_SUBDOMAINS=true
EXTERNAL_CONTENT_SRC=http://localhost:4000/graphql
# uncomment variable if you want to store data in a custom directory (required for default docker-compose setup)
# REPO=/ssb-go-room-secrets
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ dist/
# secrets and config
ssb-go-room-secrets/
.env

# vue frontend files
web/app/

.DS_STORE
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ For an in-depth codebase walkthrough, see the [development.md](./docs/developmen
## License

MIT

25 changes: 16 additions & 9 deletions cmd/insert-user/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func main() {
var (
role roomdb.Role = roomdb.RoleAdmin
repoPath string
password string
)

flag.StringVar(&repoPath, "repo", filepath.Join(u.HomeDir, ".ssb-go-room"), "[optional] where the locally stored files of the room are located")
Expand All @@ -51,6 +52,8 @@ func main() {

return nil
})
flag.StringVar(&password, "password", "", "[optional] specify a password using -password, or be prompted to set the password instead")

flag.Parse()

if _, err := os.Stat(repoPath); err != nil {
Expand All @@ -76,17 +79,21 @@ func main() {
check(err)
defer db.Close()

fmt.Fprintln(os.Stderr, "Choose a password to be able to log into the web frontend: ")
bytePassword, err := terminal.ReadPassword(int(syscall.Stdin))
check(err)
bytePassword := password

fmt.Fprintln(os.Stderr, "Repeat Password: ")
bytePasswordRepeat, err := terminal.ReadPassword(int(syscall.Stdin))
check(err)
if bytePassword == "" {
fmt.Fprintln(os.Stderr, "Choose a password to be able to log into the web frontend: ")
bytePassword, err := terminal.ReadPassword(int(syscall.Stdin))
check(err)

if !bytes.Equal(bytePassword, bytePasswordRepeat) {
fmt.Fprintln(os.Stderr, "Passwords didn't match")
os.Exit(1)
fmt.Fprintln(os.Stderr, "Repeat Password: ")
bytePasswordRepeat, err := terminal.ReadPassword(int(syscall.Stdin))
check(err)

if !bytes.Equal(bytePassword, bytePasswordRepeat) {
fmt.Fprintln(os.Stderr, "Passwords didn't match")
os.Exit(1)
}
}

ctx := context.Background()
Expand Down
10 changes: 8 additions & 2 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ var (
listenAddrShsMux string
listenAddrHTTP string

httpsDomain string
httpsDomain string
externalContentSrc string

bypassInvitesToken string

Expand Down Expand Up @@ -107,6 +108,7 @@ func initFlags() {
flag.StringVar(&logToFile, "logs", "", "where to write debug output to (default is just stderr)")

flag.StringVar(&httpsDomain, "https-domain", "", "which domain to use for TLS and AllowedHosts checks")
flag.StringVar(&externalContentSrc, "external-content-src", "", "domain allowed as an external source for CSP config")

flag.StringVar(&bypassInvitesToken, "bypass-invites-token", "", "magic token which always allows the users to register")

Expand Down Expand Up @@ -157,6 +159,10 @@ func runroomsrv() error {
httpsDomain = "localhost"
}

if externalContentSrc == "" {
return fmt.Errorf("external-content-src can't be empty. See '%s -h' for a full list of options", os.Args[0])
}

// validate listen addresses to bail out on invalid flag input before doing anything else
_, muxrpcPortStr, err := net.SplitHostPort(listenAddrShsMux)
if err != nil {
Expand Down Expand Up @@ -344,7 +350,7 @@ func runroomsrv() error {

// See for more https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP
// helpful: https://report-uri.com/home/generate
ContentSecurityPolicy: "default-src 'self'; img-src 'self' data:", // enforce no external content
ContentSecurityPolicy: fmt.Sprintf("default-src 'self'; img-src 'self' %s data: ; connect-src 'self' %s", externalContentSrc, externalContentSrc),

BrowserXssFilter: true,
FrameDeny: true,
Expand Down
4 changes: 0 additions & 4 deletions internal/network/mocked/endpoints.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions roomdb/mockdb/aliases.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions roomdb/mockdb/auth.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions roomdb/mockdb/auth_fallback.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions roomdb/mockdb/denied.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions roomdb/mockdb/fixed_pages.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions roomdb/mockdb/invites.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions roomdb/mockdb/members.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions roomdb/mockdb/pages.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions roomdb/mockdb/roomconfig.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions roomdb/privacymode_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions roomdb/role_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
# SPDX-License-Identifier: CC0-1.0

[[ -f ".env" ]] && source .env
./cmd/server/server -https-domain="${HTTPS_DOMAIN}" -repo="${REPO:-~/.ssb-go-room-secrets}" -aliases-as-subdomains="${ALIASES_AS_SUBDOMAINS}"
./cmd/server/server -https-domain="${HTTPS_DOMAIN}" -repo="${REPO:-~/.ssb-go-room-secrets}" -aliases-as-subdomains="${ALIASES_AS_SUBDOMAINS}" -external-content-src="${EXTERNAL_CONTENT_SRC}" -bypass-invites-token="${MAGIC_TOKEN}"
27 changes: 27 additions & 0 deletions web/app_fs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package web

import (
"errors"
"io/fs"
"os"
)

type appFS struct {
app fs.FS
assets fs.FS
}

func newAppFS(app fs.FS, assets fs.FS) (fs.FS, error) {
return &appFS{
app: app,
assets: assets,
}, nil
}

func (a appFS) Open(name string) (fs.File, error) {
v, err := a.app.Open(name)
if errors.Is(err, os.ErrNotExist) {
return a.assets.Open(name)
}
return v, err
}
2 changes: 1 addition & 1 deletion web/assets/style.css

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion web/embedded_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
//
// SPDX-License-Identifier: MIT

//go:build dev
// +build dev

package web

import (
"log"
"net/http"
"os"
"path/filepath"

"go.mindeco.de/goutils"
Expand All @@ -20,4 +23,15 @@ var pkgDir = goutils.MustLocatePackage("github.com/ssbc/go-ssb-room/v2/web")

var Templates = http.Dir(filepath.Join(pkgDir, "templates"))

var Assets = http.Dir(filepath.Join(pkgDir, "assets"))
var Assets http.FileSystem

func init() {
assetsDir := os.DirFS(filepath.Join(pkgDir, "assets"))
appDir := os.DirFS(filepath.Join(pkgDir, "app"))

prefixedAssets, err := newAppFS(appDir, assetsDir)
if err != nil {
log.Fatal(err)
}
Assets = http.FS(prefixedAssets)
}
16 changes: 15 additions & 1 deletion web/embedded_prod.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//
// SPDX-License-Identifier: MIT

//go:build !dev
// +build !dev

package web
Expand All @@ -25,7 +26,17 @@ var (
func init() {
var err error

prefixedAssets, err := fs.Sub(embedAssets, "assets")
prefixedEmbeddedApp, err := fs.Sub(embedApp, "app")
if err != nil {
log.Fatal(err)
}

prefixedEmbeddedAssets, err := fs.Sub(embedAssets, "assets")
if err != nil {
log.Fatal(err)
}

prefixedAssets, err := newAppFS(prefixedEmbeddedApp, prefixedEmbeddedAssets)
if err != nil {
log.Fatal(err)
}
Expand All @@ -43,3 +54,6 @@ var embedTemplates embed.FS

//go:embed assets/*
var embedAssets embed.FS

//go:embed app/*
var embedApp embed.FS
31 changes: 15 additions & 16 deletions web/handlers/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

"github.com/gorilla/csrf"
"github.com/gorilla/sessions"
"github.com/russross/blackfriday/v2"
"go.mindeco.de/http/auth"
"go.mindeco.de/http/render"
"go.mindeco.de/log/level"
Expand Down Expand Up @@ -311,21 +310,21 @@ func New(
})

// landing page
m.Get(router.CompleteIndex).Handler(r.HTML("landing/index.tmpl", func(w http.ResponseWriter, req *http.Request) (interface{}, error) {
// TODO: try websocket upgrade (issue #)

notice, err := dbs.PinnedNotices.Get(req.Context(), roomdb.NoticeDescription, "en-GB")
if err != nil {
return nil, fmt.Errorf("failed to find description: %w", err)
}
markdown := blackfriday.Run([]byte(notice.Content), blackfriday.WithNoExtensions())
return noticeShowData{
ID: notice.ID,
Title: notice.Title,
Content: template.HTML(markdown),
Language: notice.Language,
}, nil
}))
// m.Get(router.CompleteIndex).Handler(r.HTML("landing/index.tmpl", func(w http.ResponseWriter, req *http.Request) (interface{}, error) {
// // TODO: try websocket upgrade (issue #)

// notice, err := dbs.PinnedNotices.Get(req.Context(), roomdb.NoticeDescription, "en-GB")
// if err != nil {
// return nil, fmt.Errorf("failed to find description: %w", err)
// }
// markdown := blackfriday.Run([]byte(notice.Content), blackfriday.WithNoExtensions())
// return noticeShowData{
// ID: notice.ID,
// Title: notice.Title,
// Content: template.HTML(markdown),
// Language: notice.Language,
// }, nil
// }))

// notices (the mini-CMS)
var nh = noticeHandler{
Expand Down
Loading