mirror of https://github.com/gophish/gophish
Merge pull request #207 from gophish/201-converting-links
Added the ability to convert links on email import to point to the landing pagepull/233/head
commit
92531db4dc
|
@ -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),
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue