summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhorus_arch2015-03-20 23:16:27 +0100
committerhorus_arch2015-03-20 23:16:27 +0100
commit491462e033ae78a5b5c4f93ed8d5663e4da0a9e3 (patch)
treecdc82ee4c600a86ba6bc7b92a589b129a01c7429
parent17bea88eb3f6e2bc5f63641437a997cc8bd32881 (diff)
downloadfreemail-491462e033ae78a5b5c4f93ed8d5663e4da0a9e3.tar.gz
Fix bug which prevented creating a new entry.
-rw-r--r--Makefile2
-rw-r--r--domain.go21
-rw-r--r--domain_test.go7
-rwxr-xr-xenv.sh2
-rw-r--r--handler.go32
-rwxr-xr-xmailerbin11874821 -> 12001936 bytes
-rw-r--r--main.go1
-rw-r--r--server.go18
-rw-r--r--utilities_test.go5
-rw-r--r--views/register.html51
10 files changed, 103 insertions, 36 deletions
diff --git a/Makefile b/Makefile
index 6f3925b..cb4c7db 100644
--- a/Makefile
+++ b/Makefile
@@ -130,3 +130,5 @@ gen_config: _test_build
echo "export FREEMAIL_SMTP_PASSWORD=$(FREEMAIL_SMTP_PASSWORD)" >> _env.sh
echo "export FREEMAIL_SMTP_ADRESS=$(FREEMAIL_SMTP_ADRESS)" >> _env.sh
@chmod +x _env.sh
+
+restart: kill build run
diff --git a/domain.go b/domain.go
index 501351b..aa0ce40 100644
--- a/domain.go
+++ b/domain.go
@@ -33,12 +33,13 @@ func (vD VirtualDomain) CreateDomain() bool {
}
func (vD VirtualDomain) ValidateDomain(ref string) bool {
+ log.Println("Validating " + vD.Name)
if vD.Name == "" {
return false
}
addr, err := net.LookupIP(vD.Name)
if err != nil {
- log.Println(err)
+ log.Println(vD.Name + " " + err.Error())
return false
}
if len(addr) == 0 {
@@ -46,23 +47,35 @@ func (vD VirtualDomain) ValidateDomain(ref string) bool {
}
serverIP, err := net.LookupIP(ref)
if err != nil {
- log.Println(err)
+ log.Println(ref + " " + err.Error())
return false
}
return reflect.DeepEqual(serverIP, addr)
}
func (vD VirtualDomain) ValidateDomainMX(ref string) bool {
+ log.Println("Validating MX " + vD.Name)
if vD.Name == "" {
+ log.Println("Empty domain.")
return false
}
mx, err := net.LookupMX(vD.Name)
if err != nil {
- log.Println(err)
+ log.Println("Lookup error " + vD.Name + " " + err.Error())
return false
}
match := false
+
+ serverIP, err := net.LookupIP(ref)
+ if err != nil {
+ log.Println("Lookup error for server " + ref + " " + err.Error())
+ return false
+ }
for _, v := range mx {
- if v.Host == ref {
+ mxIP, err := net.LookupIP(v.Host)
+ if err != nil {
+ log.Println(err)
+ }
+ if reflect.DeepEqual(serverIP, mxIP) {
match = true
}
}
diff --git a/domain_test.go b/domain_test.go
index 20d927a..1560d55 100644
--- a/domain_test.go
+++ b/domain_test.go
@@ -43,7 +43,8 @@ func TestValidateDomain(t *testing.T) {
if d.ValidateDomain("wikipedia.de") {
t.Fatal("'" + d.Name + "' and wikipedia.de do not share IPs.")
}
- if !d.ValidateDomain("google.com") {
+ d.Name = "localhost"
+ if !d.ValidateDomain("localhost") {
t.Fatal("'" + d.Name + "' is a valid domain.")
}
}
@@ -52,9 +53,9 @@ func TestValidateDomainMX(t *testing.T) {
if testing.Short() || !*testExternal {
t.Skip("Skipping test to avoid external network.")
}
- d := VirtualDomain{Name: "heise.de"}
+ d := VirtualDomain{Name: "google.com"}
if d.ValidateDomainMX(os.Getenv("FREEMAIL_SMTP_MAILER_MX")) {
- t.Fatal("heise.de MX record doesn't point to this server.")
+ t.Fatal("google.cm MX record doesn't point to this server.")
}
d.Name = "iamfabulous.de"
if !d.ValidateDomainMX(os.Getenv("FREEMAIL_SMTP_MAILER_MX")) {
diff --git a/env.sh b/env.sh
index 15983eb..20d5dd3 100755
--- a/env.sh
+++ b/env.sh
@@ -17,7 +17,7 @@ export FREEMAIL_HTTP_IP=127.0.0.1
export FREEMAIL_HTTP_PORT=8080
# SMTP
-export FREEMAIL_SMTP_MAILER_MX="mx.example.org"
+export FREEMAIL_SMTP_MAILER_MX=mx.iamfabulous.de
#export FREEMAIL_SMTP_MAILER="smtp.example.org:25"
#export FREEMAIL_SMTP_PASSWORD="password"
#export FREEMAIL_SMTP_ADRESS="foo@example.org"
diff --git a/handler.go b/handler.go
index 4e077db..dd761e4 100644
--- a/handler.go
+++ b/handler.go
@@ -16,11 +16,39 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
flash.Success = session.Flashes("success")
session.Save(r, w)
- index := mainTempl.Lookup("index.html")
+ /*
+ index := mainTempl.Lookup("index.html")
- err = index.ExecuteTemplate(w, "index.html", flash)
+ err = index.ExecuteTemplate(w, "index.html", flash)
+ if err != nil {
+ log.Println(err)
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+ */
+
+ err = ExecTemplate("index.html", w, flash)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ session.Save(r, w)
+}
+
+func RegisterHandler(w http.ResponseWriter, r *http.Request) {
+ session, err := store.Get(r, "_SID")
if err != nil {
log.Println(err)
+ }
+
+ flash := Flash{}
+ flash.Error = session.Flashes("error")
+ flash.Success = session.Flashes("success")
+ session.Save(r, w)
+
+ err = ExecTemplate("register.html", w, flash)
+ if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
diff --git a/mailer b/mailer
index 03b8fcd..940dff0 100755
--- a/mailer
+++ b/mailer
Binary files differ
diff --git a/main.go b/main.go
index 23e15b4..d73587b 100644
--- a/main.go
+++ b/main.go
@@ -33,6 +33,7 @@ func main() {
r := mux.NewRouter()
r.HandleFunc("/", IndexHandler)
+ r.HandleFunc("/register", RegisterHandler)
r.HandleFunc("/create", CreateNewEntryHandler).Methods("POST")
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))
diff --git a/server.go b/server.go
index 66e3a94..746ac92 100644
--- a/server.go
+++ b/server.go
@@ -2,10 +2,13 @@ package main
import (
"errors"
+ "log"
+ "net/http"
"os"
)
func CreateNewEntry(email, password string) error {
+ serverIP := os.Getenv("FREEMAIL_SMTP_MAILER_MX")
if !ValidateEmail(email) {
return errors.New("This doesn't look like a mail adress.")
}
@@ -19,10 +22,10 @@ func CreateNewEntry(email, password string) error {
vD := VirtualDomain{}
vD.Name = GetDomain(vU.Email)
- if !vD.ValidateDomainMX(os.Getenv("FREEMAIL_SMTP_MAILER_MX")) {
+ if !vD.ValidateDomainMX(serverIP) {
return errors.New("The MX record doesn't point to this server.")
}
- if !vD.ValidateDomain(os.Getenv("FREEMAIL_SMTP_MAILER_MX")) {
+ if !vD.ValidateDomain(serverIP) {
return errors.New("This doesn't look like a good domain. Host not found.")
}
@@ -39,3 +42,14 @@ func CreateNewEntry(email, password string) error {
}
return nil
}
+
+func ExecTemplate(template string, w http.ResponseWriter, flash Flash) error {
+ index := mainTempl.Lookup(template)
+
+ err := index.ExecuteTemplate(w, template, flash)
+ if err != nil {
+ log.Println(err)
+ return err
+ }
+ return nil
+}
diff --git a/utilities_test.go b/utilities_test.go
index 6e4d31c..4776323 100644
--- a/utilities_test.go
+++ b/utilities_test.go
@@ -1,5 +1,3 @@
-// +build all general
-
package main
import (
@@ -23,6 +21,3 @@ func TestCompareStrings(t *testing.T) {
t.Fatal("Strings are not equal. Exptected false")
}
}
-
-func TestCompareIPs(t *testing.T) {
-}
diff --git a/views/register.html b/views/register.html
index b1481fc..71bb035 100644
--- a/views/register.html
+++ b/views/register.html
@@ -1,40 +1,53 @@
{{template "header.html"}}
{{template "navbar.html"}}
+
+{{if .Error}}
<div class="container">
<div class="row">
-{{range .Error}}
-<h4 class="col-md-4 col-md-offset-4 alert alert-danger alert-dismissible" role="alert">
- <button type="button" class="close" data-dismiss="alert" aria-label="close"><span aria-hidden="true">&times;</span></button>
- {{.}}
-</h4>
-{{end}}
-{{range .Success}}
-<h4 class="col-md-4 col-md-offset-4 alert alert-success alert-dismissible" role="alert">
- <button type="button" class="close" data-dismiss="alert" aria-label="close"><span aria-hidden="true">&times;</span></button>
+ {{range .Error}}
+ <p id="dd-alert-danger" class="col-md-4 col-md-offset-4 alert alert-danger alert-dismissible shadow-z-2" role="alert">
+ <button type="button" class="close" data-dismiss="alert" aria-label="close"><span aria-hidden="true">&times;</span></button>
{{.}}
-</h4>
-{{end}}
+ </p>
+ {{end}}
</div>
</div>
+{{end}}
+{{if .Success}}
<div class="container">
<div class="row">
+ {{range .Success}}
+ <p id="dd-alert-success" class="col-md-4 col-md-offset-4 alert alert-success alert-dismissible shadow-z-2" role="alert"> <button type="button" class="close" data-dismiss="alert" aria-label="close"><span aria-hidden="true">&times;</span></button>
+ {{.}}
+ </p>
+ {{end}}
</div>
</div>
+{{end}}
+
<div class="container">
<div class="row">
-<form class="form-horizontal" method='post' action='/register'>
+<form class="form-horizontal" method='post' action='/create'>
<fieldset>
<!-- Form Name -->
<div class="text-center">
- <legend>Register!</legend>
+ <legend>Freemail @ mail.iamfabulous.de</legend>
</div>
<!-- Text input-->
<div class="form-group">
- <label class="col-md-4 control-label" for="Name">Name:</label>
+ <label class="col-md-4 control-label" for="Email">Email:</label>
+ <div class="col-md-4">
+ <input id="Email" name="Email" placeholder="Your desired mail adress." class="form-control input-md" required="" type="text">
+ </div>
+ </div>
+
+ <!-- Text input-->
+ <div class="form-group">
+ <label class="col-md-4 control-label" for="ConfirmEmail">Confirm Email:</label>
<div class="col-md-4">
- <input id="Name" name="Name" placeholder="Your Name" class="form-control input-md" required="" type="text">
+ <input id="ConfirmEmail" name="ConfirmEmail" placeholder="Confirm your choice." class="form-control input-md" required="" type="text">
</div>
</div>
@@ -42,15 +55,15 @@
<div class="form-group">
<label class="col-md-4 control-label" for="Password">Password:</label>
<div class="col-md-4">
- <input id="Password" name="Password" placeholder="Your Password" class="form-control input-md" required="" type="password">
+ <input id="Password" name="Password" placeholder="Your password." class="form-control input-md" required="" type="password">
</div>
</div>
<!-- Text input-->
<div class="form-group">
- <label class="col-md-4 control-label" for="Email">Email:</label>
+ <label class="col-md-4 control-label" for="ConfirmPassword">Confirm Password:</label>
<div class="col-md-4">
- <input id="Email" name="Email" placeholder="Your Email" class="form-control input-md" required="" type="email">
+ <input id="ConfirmPassword" name="ConfirmPassword" placeholder="Confirm your password." class="form-control input-md" required="" type="password">
</div>
</div>
@@ -58,7 +71,7 @@
<div class="form-group">
<label class="col-md-4 control-label" for="submit"></label>
<div class="col-md-4">
- <button class="btn btn-primary">Submit</button>
+ <button class="btn btn-primary btn-raised">Submit</button>
</div>
</div>