Initial commit
This commit is contained in:
commit
412bf79941
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
fonts/
|
||||
screenshot-*.png
|
||||
map-*.json
|
21
LICENSE.md
Normal file
21
LICENSE.md
Normal file
|
@ -0,0 +1,21 @@
|
|||
# The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2018 Noah Petherbridge
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
34
Makefile
Normal file
34
Makefile
Normal file
|
@ -0,0 +1,34 @@
|
|||
SHELL := /bin/bash
|
||||
|
||||
VERSION=$(shell grep -e 'Version' main.go | head -n 1 | cut -d '"' -f 2)
|
||||
BUILD=$(shell git describe --always)
|
||||
CURDIR=$(shell curdir)
|
||||
|
||||
# Inject the build version (commit hash) into the executable.
|
||||
LDFLAGS := -ldflags "-X main.Build=$(BUILD)"
|
||||
|
||||
# `make setup` to set up a new environment, pull dependencies, etc.
|
||||
.PHONY: setup
|
||||
setup: clean
|
||||
go get -u ./...
|
||||
|
||||
# `make build` to build the binary.
|
||||
.PHONY: build
|
||||
build:
|
||||
gofmt -w .
|
||||
go build $(LDFLAGS) -i -o ./dethnote main.go
|
||||
|
||||
# `make run` to run it in debug mode.
|
||||
.PHONY: run
|
||||
run:
|
||||
go run main.go -debug
|
||||
|
||||
# `make test` to run unit tests.
|
||||
.PHONY: test
|
||||
test:
|
||||
go test ./...
|
||||
|
||||
# `make clean` cleans everything up.
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -rf bin dist
|
103
main.go
Normal file
103
main.go
Normal file
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
Dethnote is a web app that stores secure encrypted notes which can only be
|
||||
unlocked 72 hours after the correct passphrase has been entered.
|
||||
*/
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
dethnote "git.kirsle.net/apps/dethnote/src"
|
||||
"git.kirsle.net/go/log"
|
||||
)
|
||||
|
||||
// Version of the app.
|
||||
var (
|
||||
Version = "0.1.0"
|
||||
Build = "n/a"
|
||||
)
|
||||
|
||||
// CLI flags.
|
||||
var (
|
||||
// -debug: enable debug mode for local dev
|
||||
debug bool
|
||||
|
||||
// -root <path>: directory on disk where the secure notes will be stored.
|
||||
// -r <path> The default is to write to a directory called "notes"
|
||||
// in the current working directory.
|
||||
root string
|
||||
rootDefault = "./notes"
|
||||
|
||||
// -listen <address>: listen on an HTTP port at this address.
|
||||
// -l <address>
|
||||
listen string
|
||||
listenDefault = ":1987"
|
||||
|
||||
// -open: directly open a note via the server local command line.
|
||||
// The passphrase can be provided as CLI arguments.
|
||||
cmdOpen bool
|
||||
|
||||
// -delete: delete a note via the server local command line, looking the
|
||||
// note up by its passphrase. The CLI arguments are the passphrase.
|
||||
cmdDelete bool // deleting a document via the CLI.
|
||||
)
|
||||
|
||||
// Log is a pretty ANSI color logger.
|
||||
var Log *log.Logger
|
||||
|
||||
func init() {
|
||||
Log = log.GetLogger("dethnote")
|
||||
Log.Configure(&log.Config{
|
||||
Level: log.InfoLevel,
|
||||
Colors: log.ExtendedColor,
|
||||
Theme: log.DarkTheme,
|
||||
})
|
||||
|
||||
flag.BoolVar(&debug, "debug", false, "Enable debug mode for local dev")
|
||||
flag.StringVar(&root, "root", rootDefault, "Directory to store the secure notes on disk")
|
||||
flag.StringVar(&root, "r", rootDefault, "Directory to store the secure notes on disk (shorthand)")
|
||||
flag.StringVar(&listen, "listen", listenDefault, "HTTP address to listen on")
|
||||
flag.StringVar(&listen, "l", listenDefault, "HTTP address to listen on (shorthand)")
|
||||
flag.BoolVar(&cmdOpen, "open", false, "Immediately open and print a secure note. The passphrase is provided via CLI arguments.")
|
||||
flag.BoolVar(&cmdDelete, "delete", false, "Immediately delete a secure note. The passphrase is provided via CLI arguments.")
|
||||
flag.Usage = func() {
|
||||
fmt.Fprintf(os.Stderr,
|
||||
"Usage: dethnote [options] [-r rootdir] [passphrase]\n\n"+
|
||||
"By default the web server will be started. However, there are options\n"+
|
||||
"to interact with the encrypted message storage directly, via the\n"+
|
||||
"server local command line, as a last resort option to open a note\n"+
|
||||
"when access to e-mail sending is down or it's a time-sensitive matter.\n\n"+
|
||||
"Examples:\n\n"+
|
||||
" To run the web server and provide a directory where the notes\n"+
|
||||
" are to be stored on disk:\n"+
|
||||
" $ dethnote -root /var/lib/dethnote/notes\n"+
|
||||
" $ dethnote -r /var/lib/dethnote/notes\n\n"+
|
||||
" To immediately decrypt and open a note with its passphrase:\n"+
|
||||
" $ dethnote -open <passphrase>\n"+
|
||||
" $ dethnote -open correct horse battery staple\n"+
|
||||
" $ dethnote -open \"correct horse battery staple\"\n\n"+
|
||||
" To delete a secure note using its passphrase:\n"+
|
||||
" $ dethnote -delete <passphrase>\n"+
|
||||
" $ dethnote -delete correct horse battery staple\n\n"+
|
||||
"Options:\n\n",
|
||||
)
|
||||
flag.PrintDefaults()
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
if debug {
|
||||
Log.Config.Level = log.DebugLevel
|
||||
}
|
||||
|
||||
if cmdOpen && cmdDelete {
|
||||
Log.Error("-open and -delete are mutually exclusive options.")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
app := dethnote.NewServer(root, debug)
|
||||
app.Run(listen)
|
||||
}
|
10
src/logging.go
Normal file
10
src/logging.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
package dethnote
|
||||
|
||||
import "git.kirsle.net/go/log"
|
||||
|
||||
// Log for the app.
|
||||
var Log *log.Logger
|
||||
|
||||
func init() {
|
||||
Log = log.GetLogger("dethnote")
|
||||
}
|
40
src/server.go
Normal file
40
src/server.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
package dethnote
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/urfave/negroni"
|
||||
)
|
||||
|
||||
// Server is the master struct for the web app.
|
||||
type Server struct {
|
||||
root string
|
||||
debug bool
|
||||
|
||||
n *negroni.Negroni
|
||||
r *mux.Router
|
||||
}
|
||||
|
||||
// NewServer initializes the server struct.
|
||||
func NewServer(root string, debug bool) *Server {
|
||||
return &Server{
|
||||
root: root,
|
||||
debug: debug,
|
||||
}
|
||||
}
|
||||
|
||||
// SetupHTTP configures the HTTP server.
|
||||
func (s *Server) SetupHTTP() {
|
||||
// Set up the router.
|
||||
r := mux.NewRouter()
|
||||
s.r = r
|
||||
|
||||
n := negroni.Classic()
|
||||
n.UseHandler(r)
|
||||
}
|
||||
|
||||
// Run the server.
|
||||
func (s *Server) Run(addr string) {
|
||||
http.ListenAndServe(addr, s.r)
|
||||
}
|
Loading…
Reference in New Issue
Block a user