mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-17 17:47:03 +00:00
The main index template renders now!
This commit is contained in:
@@ -32,7 +32,7 @@ ip4.port=9000
|
|||||||
theme=integral
|
theme=integral
|
||||||
|
|
||||||
# Path to the selected themes template files
|
# Path to the selected themes template files
|
||||||
templates.dir=%(install.dir)s/themes/%(theme)s/templates
|
template.dir=%(install.dir)s/themes/%(theme)s/templates
|
||||||
|
|
||||||
# Path to the selected themes public (static) files
|
# Path to the selected themes public (static) files
|
||||||
public.dir=%(install.dir)s/themes/%(theme)s/public
|
public.dir=%(install.dir)s/themes/%(theme)s/public
|
||||||
|
|||||||
10
config.go
10
config.go
@@ -19,7 +19,7 @@ type SmtpConfig struct {
|
|||||||
type WebConfig struct {
|
type WebConfig struct {
|
||||||
Ip4address net.IP
|
Ip4address net.IP
|
||||||
Ip4port int
|
Ip4port int
|
||||||
TemplatesDir string
|
TemplateDir string
|
||||||
PublicDir string
|
PublicDir string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ func LoadConfig(filename string) error {
|
|||||||
requireOption(messages, "smtp", "domain")
|
requireOption(messages, "smtp", "domain")
|
||||||
requireOption(messages, "web", "ip4.address")
|
requireOption(messages, "web", "ip4.address")
|
||||||
requireOption(messages, "web", "ip4.port")
|
requireOption(messages, "web", "ip4.port")
|
||||||
requireOption(messages, "web", "templates.dir")
|
requireOption(messages, "web", "template.dir")
|
||||||
requireOption(messages, "web", "public.dir")
|
requireOption(messages, "web", "public.dir")
|
||||||
requireOption(messages, "datastore", "path")
|
requireOption(messages, "datastore", "path")
|
||||||
if messages.Len() > 0 {
|
if messages.Len() > 0 {
|
||||||
@@ -151,12 +151,12 @@ func parseWebConfig() error {
|
|||||||
return fmt.Errorf("Failed to parse %v: %v", option, err)
|
return fmt.Errorf("Failed to parse %v: %v", option, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
option = "[web]templates.dir"
|
option = "[web]template.dir"
|
||||||
str, err = Config.String("web", "templates.dir")
|
str, err = Config.String("web", "template.dir")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to parse %v: %v", option, err)
|
return fmt.Errorf("Failed to parse %v: %v", option, err)
|
||||||
}
|
}
|
||||||
webConfig.TemplatesDir = str
|
webConfig.TemplateDir = str
|
||||||
|
|
||||||
option = "[web]public.dir"
|
option = "[web]public.dir"
|
||||||
str, err = Config.String("web", "public.dir")
|
str, err = Config.String("web", "public.dir")
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 8.7 KiB |
@@ -4,19 +4,21 @@ Design by Free CSS Templates
|
|||||||
http://www.freecsstemplates.org
|
http://www.freecsstemplates.org
|
||||||
Released for free under a Creative Commons Attribution 2.5 License
|
Released for free under a Creative Commons Attribution 2.5 License
|
||||||
-->
|
-->
|
||||||
|
{{define "col1menu"}}{{/* Used inside #content div */}}
|
||||||
|
<div id="colOne">
|
||||||
|
<div id="logo">
|
||||||
|
<h1><a href="#">inbucket</a></h1>
|
||||||
|
<h2>email testing service</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
<title>{{.title}}</title>
|
<title>{{template "title" .}}</title>
|
||||||
<link href="/public/stylesheets/main.css" rel="stylesheet" type="text/css" />
|
<link href="/public/main.css" rel="stylesheet" type="text/css" />
|
||||||
<link rel="shortcut icon" type="image/png" href="/public/images/favicon.png">
|
<link rel="shortcut icon" type="image/png" href="/public/images/favicon.png">
|
||||||
<script src="/public/js/jquery-1.5.2.min.js" type="text/javascript" charset="utf-8"></script>
|
<script src="/public/jquery-1.5.2.min.js" type="text/javascript" charset="utf-8"></script>
|
||||||
{{range .moreStyles}}
|
|
||||||
<link rel="stylesheet" type="text/css" href="/public/{{.}}">
|
|
||||||
{{end}}
|
|
||||||
{{range .moreScripts}}
|
|
||||||
<script src="/public/{{.}}" type="text/javascript" charset="utf-8"></script>
|
|
||||||
{{end}}
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="header">
|
<div id="header">
|
||||||
@@ -32,3 +34,12 @@ Released for free under a Creative Commons Attribution 2.5 License
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div id="content">
|
<div id="content">
|
||||||
|
{{template "content" .}}
|
||||||
|
</div>
|
||||||
|
<div id="footer">
|
||||||
|
<p>Inbucket is an open source project hosted at
|
||||||
|
<a href="http://github.com/jhillyerd/inbucket/">github</a>.
|
||||||
|
Design by <a href="http://www.freecsstemplates.org/">FCT</a>.</p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
</div>
|
|
||||||
<div id="footer">
|
|
||||||
<p>Inbucket is an open source project hosted at
|
|
||||||
<a href="http://github.com/jhillyerd/inbucket/">github</a>.
|
|
||||||
Design by <a href="http://www.freecsstemplates.org/">FCT</a>.</p>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,15 +1,11 @@
|
|||||||
{{set "title" "Inbucket" .}}
|
{{define "title"}}Inbucket{{end}}
|
||||||
{{template "header.html" .}}
|
{{define "content"}}
|
||||||
{{template "menu.html" .}}
|
{{template "col1menu" .}}
|
||||||
|
|
||||||
<div id="colTwo">
|
<div id="colTwo">
|
||||||
{{template "errors.html" .}}
|
|
||||||
|
|
||||||
<p>Inbucket is an email testing service; it will accept email for any email
|
<p>Inbucket is an email testing service; it will accept email for any email
|
||||||
address and make it available to view without a password.</p>
|
address and make it available to view without a password.</p>
|
||||||
<p>To view email for a particular address, enter the username portion
|
<p>To view email for a particular address, enter the username portion
|
||||||
of the address into the box on the upper right and click <em>go</em>.</p>
|
of the address into the box on the upper right and click <em>go</em>.</p>
|
||||||
</div>
|
</div>
|
||||||
|
{{end}}
|
||||||
{{template "footer.html" .}}
|
|
||||||
|
|
||||||
31
web/app.go
31
web/app.go
@@ -1,31 +0,0 @@
|
|||||||
package web
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/jhillyerd/inbucket/app/smtpd"
|
|
||||||
"github.com/robfig/revel"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Application struct {
|
|
||||||
*rev.Controller
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c Application) Index() rev.Result {
|
|
||||||
return c.Render()
|
|
||||||
}
|
|
||||||
|
|
||||||
type SmtpdPlugin struct {
|
|
||||||
rev.EmptyPlugin
|
|
||||||
server *smtpd.Server
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p SmtpdPlugin) OnAppStart() {
|
|
||||||
domain := rev.Config.StringDefault("smtpd.domain", "localhost")
|
|
||||||
port := rev.Config.IntDefault("smtpd.port", 2500)
|
|
||||||
rev.INFO.Printf("SMTP Daemon plugin init {domain: %v, port: %v}", domain, port)
|
|
||||||
p.server = smtpd.New(domain, port)
|
|
||||||
go p.server.Start()
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
rev.RegisterPlugin(SmtpdPlugin{})
|
|
||||||
}
|
|
||||||
25
web/context.go
Normal file
25
web/context.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package web
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gorilla/sessions"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Context struct {
|
||||||
|
Session *sessions.Session
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Context) Close() {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewContext(req *http.Request) (*Context, error) {
|
||||||
|
sess, err := sessionStore.Get(req, "inbucket")
|
||||||
|
ctx := &Context{
|
||||||
|
Session: sess,
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return ctx, err
|
||||||
|
}
|
||||||
|
return ctx, err
|
||||||
|
}
|
||||||
9
web/root_controller.go
Normal file
9
web/root_controller.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package web
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func RootIndex(w http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
|
||||||
|
return T("root-index.html").Execute(w, nil)
|
||||||
|
}
|
||||||
@@ -6,11 +6,15 @@ package web
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
"github.com/gorilla/sessions"
|
||||||
"github.com/jhillyerd/inbucket"
|
"github.com/jhillyerd/inbucket"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"thegoods.biz/httpbuf"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type handler func(http.ResponseWriter, *http.Request, *Context) error
|
||||||
|
|
||||||
/*
|
/*
|
||||||
type WebServer struct {
|
type WebServer struct {
|
||||||
thing string
|
thing string
|
||||||
@@ -24,24 +28,31 @@ func NewWebServer() *Server {
|
|||||||
|
|
||||||
var Router *mux.Router
|
var Router *mux.Router
|
||||||
|
|
||||||
|
var sessionStore sessions.Store
|
||||||
|
|
||||||
func setupRoutes(cfg inbucket.WebConfig) {
|
func setupRoutes(cfg inbucket.WebConfig) {
|
||||||
r := mux.NewRouter()
|
r := mux.NewRouter()
|
||||||
Router = r
|
Router = r
|
||||||
inbucket.Info("Theme templates mapped to '%v'", cfg.TemplatesDir)
|
inbucket.Info("Theme templates mapped to '%v'", cfg.TemplateDir)
|
||||||
inbucket.Info("Theme static content mapped to '%v'", cfg.PublicDir)
|
inbucket.Info("Theme static content mapped to '%v'", cfg.PublicDir)
|
||||||
|
|
||||||
// Static content
|
// Static content
|
||||||
r.PathPrefix("/public/").Handler(http.StripPrefix("/public/",
|
r.PathPrefix("/public/").Handler(http.StripPrefix("/public/",
|
||||||
http.FileServer(http.Dir(cfg.PublicDir))))
|
http.FileServer(http.Dir(cfg.PublicDir))))
|
||||||
|
|
||||||
|
// Root
|
||||||
|
r.Path("/").Handler(handler(RootIndex))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start() the web server
|
// Start() the web server
|
||||||
func Start() {
|
func Start() {
|
||||||
cfg := inbucket.GetWebConfig()
|
cfg := inbucket.GetWebConfig()
|
||||||
setupRoutes(cfg)
|
setupRoutes(cfg)
|
||||||
|
|
||||||
|
sessionStore = sessions.NewCookieStore([]byte("something-very-secret"))
|
||||||
|
|
||||||
addr := fmt.Sprintf("%v:%v", cfg.Ip4address, cfg.Ip4port)
|
addr := fmt.Sprintf("%v:%v", cfg.Ip4address, cfg.Ip4port)
|
||||||
inbucket.Info("HTTP listening on TCP4 %v", addr)
|
inbucket.Info("HTTP listening on TCP4 %v", addr)
|
||||||
|
|
||||||
s := &http.Server{
|
s := &http.Server{
|
||||||
Addr: addr,
|
Addr: addr,
|
||||||
Handler: Router,
|
Handler: Router,
|
||||||
@@ -54,3 +65,31 @@ func Start() {
|
|||||||
inbucket.Error("HTTP server failed: %v", err)
|
inbucket.Error("HTTP server failed: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ServeHTTP builds the context and passes onto the real handler
|
||||||
|
func (h handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
|
// Create the context
|
||||||
|
ctx, err := NewContext(req)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer ctx.Close()
|
||||||
|
|
||||||
|
// Run the handler, grab the error, and report it
|
||||||
|
buf := new(httpbuf.Buffer)
|
||||||
|
err = h(buf, req, ctx)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the session
|
||||||
|
if err = ctx.Session.Save(req, buf); err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply the buffered response to the writer
|
||||||
|
buf.Apply(w)
|
||||||
|
}
|
||||||
|
|||||||
33
web/template.go
Normal file
33
web/template.go
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package web
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jhillyerd/inbucket"
|
||||||
|
"html/template"
|
||||||
|
"path/filepath"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
var cachedTemplates = map[string]*template.Template{}
|
||||||
|
var cachedMutex sync.Mutex
|
||||||
|
|
||||||
|
func T(name string) *template.Template {
|
||||||
|
cachedMutex.Lock()
|
||||||
|
defer cachedMutex.Unlock()
|
||||||
|
|
||||||
|
if t, ok := cachedTemplates[name]; ok {
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
templateDir := inbucket.GetWebConfig().TemplateDir
|
||||||
|
templateFile := filepath.Join(templateDir, name)
|
||||||
|
inbucket.Trace("Parsing template %v", templateFile)
|
||||||
|
|
||||||
|
t := template.New("_base.html").Funcs(TemplateFuncs)
|
||||||
|
t = template.Must(t.ParseFiles(
|
||||||
|
filepath.Join(templateDir, "_base.html"),
|
||||||
|
templateFile,
|
||||||
|
))
|
||||||
|
cachedTemplates[name] = t
|
||||||
|
|
||||||
|
return t
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user