mirror of https://github.com/gophish/gophish
parent
c75e55154b
commit
3edcc11e61
|
@ -20,18 +20,11 @@ const (
|
|||
ERROR string = "Error"
|
||||
)
|
||||
|
||||
// API (/api) provides access to api documentation
|
||||
func API(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "GET" {
|
||||
|
||||
}
|
||||
if r.Method == "POST" {
|
||||
//Add a new campaign
|
||||
//v :=
|
||||
}
|
||||
if u, err := json.Marshal(ctx.Get(r, "user")); err == nil {
|
||||
writeJSON(w, u)
|
||||
} else {
|
||||
http.Error(w, "Server Error", 500)
|
||||
switch {
|
||||
case r.Method == "GET":
|
||||
getTemplate(w, "api_doc").ExecuteTemplate(w, "base", nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,11 +95,6 @@ func API_Campaigns_Id(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
//API_Doc renders a template describing the API documentation.
|
||||
func API_Doc(w http.ResponseWriter, r *http.Request) {
|
||||
getTemplate(w, "api_doc").ExecuteTemplate(w, "base", nil)
|
||||
}
|
||||
|
||||
func writeJSON(w http.ResponseWriter, c []byte) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
fmt.Fprintf(w, "%s", c)
|
||||
|
|
|
@ -47,17 +47,15 @@ func CreateRouter() *mux.Router {
|
|||
router.HandleFunc("/login", Login)
|
||||
router.HandleFunc("/register", Register)
|
||||
router.HandleFunc("/", Use(Base, mid.RequireLogin))
|
||||
router.HandleFunc("/campaigns", Use(Campaigns, mid.RequireLogin))
|
||||
router.HandleFunc("/campaigns/{id}", Use(Campaigns_Id, mid.RequireLogin))
|
||||
router.HandleFunc("/users", Use(Users, mid.RequireLogin))
|
||||
router.HandleFunc("/settings", Use(Settings, mid.RequireLogin))
|
||||
|
||||
// Create the API routes
|
||||
api := router.PathPrefix("/api").Subrouter()
|
||||
api.HandleFunc("/", Use(API, mid.RequireAPIKey))
|
||||
api.HandleFunc("/", Use(API, mid.RequireLogin))
|
||||
api.HandleFunc("/campaigns", Use(API_Campaigns, mid.RequireAPIKey))
|
||||
api.HandleFunc("/campaigns/{id}", Use(API_Campaigns_Id, mid.RequireAPIKey))
|
||||
api.HandleFunc("/doc", API_Doc)
|
||||
|
||||
//Setup static file serving
|
||||
router.PathPrefix("/").Handler(http.FileServer(http.Dir("./static/")))
|
||||
|
@ -101,14 +99,13 @@ func Settings(w http.ResponseWriter, r *http.Request) {
|
|||
getTemplate(w, "settings").ExecuteTemplate(w, "base", params)
|
||||
}
|
||||
|
||||
func Campaigns(w http.ResponseWriter, r *http.Request) {
|
||||
//session, _ := auth.Store.Get(r, "gophish")
|
||||
getTemplate(w, "dashboard").ExecuteTemplate(w, "base", nil)
|
||||
}
|
||||
|
||||
func Campaigns_Id(w http.ResponseWriter, r *http.Request) {
|
||||
//session, _ := auth.Store.Get(r, "gophish")
|
||||
getTemplate(w, "dashboard").ExecuteTemplate(w, "base", nil)
|
||||
params := struct {
|
||||
User models.User
|
||||
Title string
|
||||
Flashes []interface{}
|
||||
}{Title: "Results", User: ctx.Get(r, "user").(models.User)}
|
||||
getTemplate(w, "dashboard").ExecuteTemplate(w, "base", params)
|
||||
}
|
||||
|
||||
func Login(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{{define "content"}} {{template "nav"}}
|
||||
{{%define "content"%}} {{%template "nav"%}}
|
||||
<div class="jumbotron">
|
||||
<div class="container" style="text-align:center;">
|
||||
<h1 class="sans header">
|
||||
|
@ -15,7 +15,7 @@
|
|||
</li>
|
||||
<li><a href="/settings">Settings</a>
|
||||
</li>
|
||||
<li class="active"><a href="/api/doc">API Documentation</a>
|
||||
<li class="active"><a href="/api/">API Documentation</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -26,5 +26,5 @@
|
|||
<p>Test.</p>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
{{%end%}}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
</li>
|
||||
<li><a href="/settings">Settings</a>
|
||||
</li>
|
||||
<li><a href="/api/doc">API Documentation</a>
|
||||
<li><a href="/api/">API Documentation</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue