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
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"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)
|
JSONResponse(w, models.Response{Success: false, Message: "Method not allowed"}, http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer r.Body.Close()
|
ir := struct {
|
||||||
e, err := email.NewEmailFromReader(r.Body)
|
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 {
|
if err != nil {
|
||||||
Logger.Println(err)
|
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{
|
er := emailResponse{
|
||||||
Subject: e.Subject,
|
Subject: e.Subject,
|
||||||
Text: string(e.Text),
|
Text: string(e.Text),
|
||||||
|
|
|
@ -230,15 +230,19 @@ function copy(idx) {
|
||||||
|
|
||||||
function importEmail() {
|
function importEmail() {
|
||||||
raw = $("#email_content").val()
|
raw = $("#email_content").val()
|
||||||
|
convert_links = $("#convert_links_checkbox").prop("checked")
|
||||||
if (!raw) {
|
if (!raw) {
|
||||||
modalError("No Content Specified!")
|
modalError("No Content Specified!")
|
||||||
} else {
|
} else {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
method: "POST",
|
||||||
url: "/api/import/email",
|
url: "/api/import/email",
|
||||||
data: raw,
|
data: JSON.stringify({
|
||||||
|
content: raw,
|
||||||
|
convert_links: convert_links
|
||||||
|
}),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
contentType: "text/plain"
|
contentType: "application/json"
|
||||||
})
|
})
|
||||||
.success(function(data) {
|
.success(function(data) {
|
||||||
$("#text_editor").val(data.text)
|
$("#text_editor").val(data.text)
|
||||||
|
|
|
@ -140,6 +140,10 @@
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<textarea rows="10" id="email_content" class="gophish-editor form-control" placeholder="Raw Email Source"></textarea>
|
<textarea rows="10" id="email_content" class="gophish-editor form-control" placeholder="Raw Email Source"></textarea>
|
||||||
</div>
|
</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>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" data-dismiss="modal" class="btn btn-default">Cancel</button>
|
<button type="button" data-dismiss="modal" class="btn btn-default">Cancel</button>
|
||||||
|
|
Loading…
Reference in New Issue