Skip to content
Browse files

Eclipse+Goclipse support. Cleaner folders.

  • Loading branch information...
1 parent c8e3a4b commit cabec805132ce2e6f543d81103334850cd514d99 @dcposch committed Nov 18, 2013
View
5 .gitignore
@@ -1,5 +1,8 @@
.*.swp
static/doc/*.html
-scramble
scramble.sql
build
+bin/
+pkg/
+.settings/
+src/*.*/
View
17 .project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>scramble</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.googlecode.goclipse.goBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>goclipse.goNature</nature>
+ </natures>
+</projectDescription>
View
19 Makefile
@@ -1,16 +1,19 @@
+GOPATH := $(shell pwd)
+
run: build
- $(GOPATH)/bin/scramble
+ ./static/bin/scramble
-build: doc $(shell find . -name '*.go')
- go get .
- go install .
- cp $(GOPATH)/bin/scramble static/bin/scramble
+build: doc $(shell find . -name '*.go') $(shell find . -name '*.js')
+ go get scramble
+ mkdir -p bin
+ go build -o bin/scramble src/cmd/scramble/*.go
+ cp bin/scramble static/bin/scramble
-test:
- go test
+test: $(shell find . -name '*.go') $(shell find . -name '*.js')
+ go test scramble
cat static/js/stubs.js static/js/sugar.min.js static/js/openpgp.js static/js/scrypt.js static/js/app.js static/js/test.js | node
-lint:
+lint:
go get github.com/golang/lint/golint
$(GOPATH)/bin/golint *.go
View
14 src/cmd/scramble/main.go
@@ -0,0 +1,14 @@
+package main
+
+import (
+ "scramble"
+)
+
+func main() {
+ // HTTP Static Files + REST API
+ scramble.StartHTTPServer()
+
+ // SMTP Incoming Messages
+ scramble.StartSMTPServer()
+ scramble.StartSMTPSaver()
+}
View
2 auth.go → src/scramble/auth.go
@@ -1,4 +1,4 @@
-package main
+package scramble
import (
"errors"
View
44 config.go → src/scramble/config.go
@@ -1,14 +1,14 @@
-package main
+package scramble
import (
"encoding/json"
+ "errors"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
- "errors"
)
// All configuration for a Scramble server+notary.
@@ -35,16 +35,36 @@ type Config struct {
}
func validateConfig(cfg *Config) error {
- if cfg.DbServer == "" { return errors.New("DbServer must be set") }
- if cfg.DbUser == "" { return errors.New("DbUser must be set") }
- if cfg.DbCatalog == "" { return errors.New("DbCatalog must be set") }
- if cfg.SMTPMxHost == "" { return errors.New("SMTPMxHost must be set") }
- if cfg.SMTPPort == 0 { return errors.New("SMTPPort must be set") }
- if cfg.MaxEmailSize == 0 { return errors.New("MaxEmailSize must be set") }
- if cfg.HTTPPort == 0 { return errors.New("HTTPPort must be set") }
- if len(cfg.Notaries) == 0 { return errors.New("Notaries must be set") }
- if len(cfg.ReservedNames) == 0 { return errors.New("ReservedNames must be set") }
- if cfg.AncestorIDsMaxBytes == 0 { return errors.New("AncestorIDsMaxBytes must be set") }
+ if cfg.DbServer == "" {
+ return errors.New("DbServer must be set")
+ }
+ if cfg.DbUser == "" {
+ return errors.New("DbUser must be set")
+ }
+ if cfg.DbCatalog == "" {
+ return errors.New("DbCatalog must be set")
+ }
+ if cfg.SMTPMxHost == "" {
+ return errors.New("SMTPMxHost must be set")
+ }
+ if cfg.SMTPPort == 0 {
+ return errors.New("SMTPPort must be set")
+ }
+ if cfg.MaxEmailSize == 0 {
+ return errors.New("MaxEmailSize must be set")
+ }
+ if cfg.HTTPPort == 0 {
+ return errors.New("HTTPPort must be set")
+ }
+ if len(cfg.Notaries) == 0 {
+ return errors.New("Notaries must be set")
+ }
+ if len(cfg.ReservedNames) == 0 {
+ return errors.New("ReservedNames must be set")
+ }
+ if cfg.AncestorIDsMaxBytes == 0 {
+ return errors.New("AncestorIDsMaxBytes must be set")
+ }
return nil
}
View
2 crypto.go → src/scramble/crypto.go
@@ -1,4 +1,4 @@
-package main
+package scramble
import (
"bytes"
View
2 crypto_test.go → src/scramble/crypto_test.go
@@ -1,4 +1,4 @@
-package main
+package scramble
import "testing"
View
8 email.go → src/scramble/email.go
@@ -1,10 +1,10 @@
-package main
+package scramble
import (
- "log"
- "strings"
"crypto/rand"
"encoding/hex"
+ "log"
+ "strings"
)
type EmailAddress struct {
@@ -77,7 +77,7 @@ func ParseAngledEmailAddressesSmart(addrList string) EmailAddresses {
}
addrs := EmailAddresses{}
for _, addr := range found {
- addrs = append(addrs, &EmailAddress{addr[1],addr[2]})
+ addrs = append(addrs, &EmailAddress{addr[1], addr[2]})
}
return addrs
}
View
47 server.go → src/scramble/handlers.go
@@ -1,15 +1,14 @@
-package main
+package scramble
import (
"fmt"
"log"
"net/http"
"runtime/debug"
- "strings"
"time"
)
-func main() {
+func StartHTTPServer() {
// Rest API
http.HandleFunc("/user/", userHandler) // create users, look up hash->pubkey
http.HandleFunc("/publickeys/notary", notaryHandler) // this notary & default client notaries
@@ -27,10 +26,6 @@ func main() {
// Resources
http.HandleFunc("/", staticHandler) // html, js, css
- // SMTP Incoming Messages
- StartSMTPServer()
- StartSMTPSaver()
-
// Serve HTTP on localhost only. Let Nginx terminate HTTPS for us.
address := fmt.Sprintf("127.0.0.1:%d", GetConfig().HTTPPort)
log.Printf("Listening on http://%s\n", address)
@@ -60,7 +55,7 @@ func auth(handler func(http.ResponseWriter, *http.Request, *UserID)) http.Handle
func recoverAndLogHandler(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Wrap the ResponseWriter to remember the status
- rww := &ResponseWriterWrapper{-1, w}
+ rww := &responseWriterWrapper{200, w}
begin := time.Now()
defer func() {
@@ -75,9 +70,6 @@ func recoverAndLogHandler(handler http.Handler) http.Handler {
// Finally, log.
durationMS := time.Since(begin).Nanoseconds() / 1000000
- if rww.Status == -1 {
- rww.Status = 200
- }
log.Printf("%s %s %v %v %s", r.RemoteAddr, r.Method, rww.Status, durationMS, r.URL)
}()
@@ -86,41 +78,12 @@ func recoverAndLogHandler(handler http.Handler) http.Handler {
}
// Remember the status for logging
-type ResponseWriterWrapper struct {
+type responseWriterWrapper struct {
Status int
http.ResponseWriter
}
-func (w *ResponseWriterWrapper) WriteHeader(status int) {
+func (w *responseWriterWrapper) WriteHeader(status int) {
w.Status = status
w.ResponseWriter.WriteHeader(status)
}
-
-// Stick it as a deferred statement in gouroutines to prevent the program from crashing.
-// Catches panics and emails a report to the configured AdminEmails
-func Recover() {
- if e := recover(); e != nil {
- stack := string(debug.Stack())
- errorString := fmt.Sprintf("%s:\n%s", e, stack)
- log.Println("<!> " + errorString)
- messageID := GenerateMessageID().String()
- if len(GetConfig().AdminEmails) > 0 {
- go smtpSendSafe(&OutgoingEmail{
- Email: Email{
- EmailHeader: EmailHeader{
- MessageID: messageID,
- ThreadID: messageID,
- UnixTime: time.Now().Unix(),
- From: "daemon@" + GetConfig().SMTPMxHost,
- To: strings.Join(GetConfig().AdminEmails, ","),
- },
- },
- IsPlaintext: true,
- PlaintextSubject: "Panic from Scramble server " + GetConfig().SMTPMxHost,
- PlaintextBody: errorString,
- })
- } else {
- log.Printf("Set AdminEmails: ['your_email@host',...] in config to receive alerts")
- }
- }
-}
View
16 handlers.go → src/scramble/handlers_rest.go
@@ -1,4 +1,4 @@
-package main
+package scramble
import (
"encoding/json"
@@ -16,20 +16,6 @@ import (
)
//
-// SERVE HTML, CSS, JS
-//
-
-func staticHandler(w http.ResponseWriter, r *http.Request) {
- var path string
- if strings.HasSuffix(r.URL.Path, "/") {
- path = r.URL.Path + "index.html"
- } else {
- path = r.URL.Path
- }
- http.ServeFile(w, r, "static/"+path)
-}
-
-//
// USER ROUTE
//
View
20 src/scramble/handlers_static.go
@@ -0,0 +1,20 @@
+package scramble
+
+import (
+ "net/http"
+ "strings"
+)
+
+//
+// SERVE HTML, CSS, JS
+//
+
+func staticHandler(w http.ResponseWriter, r *http.Request) {
+ var path string
+ if strings.HasSuffix(r.URL.Path, "/") {
+ path = r.URL.Path + "index.html"
+ } else {
+ path = r.URL.Path
+ }
+ http.ServeFile(w, r, "static/"+path)
+}
View
4 handlers_test.go → src/scramble/handlers_test.go
@@ -1,4 +1,4 @@
-package main
+package scramble
import (
"encoding/json"
@@ -78,7 +78,7 @@ func TestPublicKeysHandler(t *testing.T) {
"POST", "publickeys/query",
url.Values{
"needResolution": {tUser.EmailAddress},
- "needPubKey": {tUser.EmailAddress+",doesnotexist@"+GetConfig().SMTPMxHost},
+ "needPubKey": {tUser.EmailAddress + ",doesnotexist@" + GetConfig().SMTPMxHost},
"notaries": {GetConfig().SMTPMxHost},
},
)
View
2 migrations.go → src/scramble/migrations.go
@@ -1,4 +1,4 @@
-package main
+package scramble
import (
"database/sql"
View
2 models.go → src/scramble/models.go
@@ -1,4 +1,4 @@
-package main
+package scramble
// User represents a single user, email address, and key pair
// The email address is <public key hash>@<host>
View
5 notary.go → src/scramble/notary.go
@@ -1,6 +1,6 @@
// See: https://github.com/dcposch/scramble/wiki/Addr-Resolution-via-Notaries
-package main
+package scramble
import (
"code.google.com/p/go.crypto/openpgp"
@@ -87,6 +87,9 @@ func loadNotaries() {
for notaryHost, filename := range notaryFiles {
pubKeyBytes, err := ioutil.ReadFile(filename)
if err != nil {
+ pubKeyBytes, err = ioutil.ReadFile(os.Getenv("GOPATH") + "/" + filename)
+ }
+ if err != nil {
panic(err)
}
notaries[notaryHost] = string(pubKeyBytes)
View
38 src/scramble/recover.go
@@ -0,0 +1,38 @@
+package scramble
+
+import (
+ "fmt"
+ "log"
+ "runtime/debug"
+ "strings"
+ "time"
+)
+
+// Stick it as a deferred statement in gouroutines to prevent the program from crashing.
+// Catches panics and emails a report to the configured AdminEmails
+func Recover() {
+ if e := recover(); e != nil {
+ stack := string(debug.Stack())
+ errorString := fmt.Sprintf("%s:\n%s", e, stack)
+ log.Println("<!> " + errorString)
+ messageID := GenerateMessageID().String()
+ if len(GetConfig().AdminEmails) > 0 {
+ go smtpSendSafe(&OutgoingEmail{
+ Email: Email{
+ EmailHeader: EmailHeader{
+ MessageID: messageID,
+ ThreadID: messageID,
+ UnixTime: time.Now().Unix(),
+ From: "daemon@" + GetConfig().SMTPMxHost,
+ To: strings.Join(GetConfig().AdminEmails, ","),
+ },
+ },
+ IsPlaintext: true,
+ PlaintextSubject: "Panic from Scramble server " + GetConfig().SMTPMxHost,
+ PlaintextBody: errorString,
+ })
+ } else {
+ log.Printf("Set AdminEmails: ['your_email@host',...] in config to receive alerts")
+ }
+ }
+}
View
2 repo.go → src/scramble/repo.go
@@ -1,4 +1,4 @@
-package main
+package scramble
import "database/sql"
import _ "github.com/go-sql-driver/mysql"
View
2 smtp_client.go → src/scramble/smtp_client.go
@@ -1,4 +1,4 @@
-package main
+package scramble
import (
"errors"
View
2 smtp_saver.go → src/scramble/smtp_saver.go
@@ -7,7 +7,7 @@
* public key before storing.
*/
-package main
+package scramble
import (
"bytes"
View
2 smtp_server.go → src/scramble/smtp_server.go
@@ -16,7 +16,7 @@ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER I
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-package main
+package scramble
import (
"bufio"
View
2 smtp_test.go → src/scramble/smtp_test.go
@@ -2,7 +2,7 @@
// > go test -run TestSendEmail -server hashed.im -v
// also see http://qmail.jms1.net/test-auth.shtml
-package main
+package scramble
import (
"flag"
View
10 validate.go → src/scramble/validate.go
@@ -1,4 +1,4 @@
-package main
+package scramble
import (
"log"
@@ -7,16 +7,16 @@ import (
// Parts of regular expressions
var atom = "[A-Z0-9!#$%&'*+\\-/=?^_`{|}~]+"
-var dotAtom = atom+`(?:\.`+atom+`)*`
+var dotAtom = atom + `(?:\.` + atom + `)*`
var domain = `[A-Z0-9.-]+\.[A-Z]{2,4}`
var regexHex = regexp.MustCompile("^(?i)[a-f0-9]+$")
var regexPassHash = regexp.MustCompile("^(?i)[a-f0-9]{40}$")
var regexHash = regexp.MustCompile("^(?i)[a-f0-9]{40}|[a-z2-7]{16}$")
var regexToken = regexp.MustCompile("^(?i)[a-z0-9]{3}[a-z0-9]*$")
-var regexAddress = regexp.MustCompile(`^(?i)(`+dotAtom+`)@(`+dotAtom+`)$`)
-var regexAngledAddress = regexp.MustCompile(`(?i)<(`+dotAtom+`)@(`+dotAtom+`)>`)
-var regexHost = regexp.MustCompile(`^(?i)(`+domain+`)$`)
+var regexAddress = regexp.MustCompile(`^(?i)(` + dotAtom + `)@(` + dotAtom + `)$`)
+var regexAngledAddress = regexp.MustCompile(`(?i)<(` + dotAtom + `)@(` + dotAtom + `)>`)
+var regexHost = regexp.MustCompile(`^(?i)(` + domain + `)$`)
var regexPublicKeyArmor = regexp.MustCompile(`^(?s)-----BEGIN PGP PUBLIC KEY BLOCK-----.*?-----END PGP PUBLIC KEY BLOCK-----`)
var regexMessageArmor = regexp.MustCompile(`^(?s)-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----`)
var regexSignatureArmor = regexp.MustCompile(`^(?s)-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----`)
View
2 validate_test.go → src/scramble/validate_test.go
@@ -1,4 +1,4 @@
-package main
+package scramble
import (
"log"

0 comments on commit cabec80

Please sign in to comment.
Something went wrong with that request. Please try again.