Added the ability to convert links on email import to point to the landing page. Fixes #201

pull/207/head
Jordan Wright 2016-03-10 20:35:33 -06:00
parent c979dbd58d
commit cfba48a824
3 changed files with 42 additions and 5 deletions

View File

@ -1,12 +1,14 @@
package controllers
import (
"bytes"
"crypto/tls"
"encoding/json"
"errors"
"fmt"
"net/http"
"strconv"
"strings"
"text/template"
"time"
@ -446,11 +448,38 @@ func API_Import_Email(w http.ResponseWriter, r *http.Request) {
JSONResponse(w, models.Response{Success: false, Message: "Method not allowed"}, http.StatusBadRequest)
return
}
defer r.Body.Close()
e, err := email.NewEmailFromReader(r.Body)
ir := struct {
Content string `json:"content"`
ConvertLinks bool `json:"convert_links"`
}{}
err := json.NewDecoder(r.Body).Decode(&ir)
if err != nil {
JSONResponse(w, models.Response{Success: false, Message: "Error decoding JSON Request"}, http.StatusBadRequest)
return
}
e, err := email.NewEmailFromReader(strings.NewReader(ir.Content))
if err != nil {
Logger.Println(err)
}
// If the user wants to convert links to point to
// the landing page, let's make it happen by changing up
// e.HTML
if ir.ConvertLinks {
d, err := goquery.NewDocumentFromReader(bytes.NewReader(e.HTML))
if err != nil {
JSONResponse(w, models.Response{Success: false, Message: err.Error()}, http.StatusBadRequest)
return
}
d.Find("a").Each(func(i int, a *goquery.Selection) {
a.SetAttr("href", "{{.URL}}")
})
h, err := d.Html()
if err != nil {
JSONResponse(w, models.Response{Success: false, Message: err.Error()}, http.StatusInternalServerError)
return
}
e.HTML = []byte(h)
}
er := emailResponse{
Subject: e.Subject,
Text: string(e.Text),

View File

@ -230,15 +230,19 @@ function copy(idx) {
function importEmail() {
raw = $("#email_content").val()
convert_links = $("#convert_links_checkbox").prop("checked")
if (!raw) {
modalError("No Content Specified!")
} else {
$.ajax({
type: "POST",
method: "POST",
url: "/api/import/email",
data: raw,
data: JSON.stringify({
content: raw,
convert_links: convert_links
}),
dataType: "json",
contentType: "text/plain"
contentType: "application/json"
})
.success(function(data) {
$("#text_editor").val(data.text)

View File

@ -140,6 +140,10 @@
<div class="form-group">
<textarea rows="10" id="email_content" class="gophish-editor form-control" placeholder="Raw Email Source"></textarea>
</div>
<div class="checkbox checkbox-primary">
<input id="convert_links_checkbox" type="checkbox" checked>
<label for="convert_links_checkbox">Change Links to Point to Landing Page</label>
</div>
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn btn-default">Cancel</button>