mirror of https://github.com/gophish/gophish
Working on importing emails from source (still doesn't work yet!)
parent
cb081f4a17
commit
759f86447d
|
@ -3,6 +3,7 @@ package controllers
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"text/template"
|
||||
|
@ -335,8 +336,8 @@ func API_Pages_Id(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
// API_Import_Group imports a CSV of group members
|
||||
func API_Import_Group(w http.ResponseWriter, r *http.Request) {
|
||||
Logger.Println("Parsing CSV....")
|
||||
ts, err := util.ParseCSV(r)
|
||||
if checkError(err, w, "Error deleting template", http.StatusInternalServerError) {
|
||||
return
|
||||
|
@ -344,6 +345,19 @@ func API_Import_Group(w http.ResponseWriter, r *http.Request) {
|
|||
JSONResponse(w, ts, http.StatusOK)
|
||||
}
|
||||
|
||||
// API_Import_Email allows for the importing of email.
|
||||
// Returns a Message object
|
||||
func API_Import_Email(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "POST" {
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
Logger.Println(err)
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
fmt.Fprintf(w, "%s", body)
|
||||
}
|
||||
}
|
||||
|
||||
// JSONResponse attempts to set the status code, c, and marshal the given interface, d, into a response that
|
||||
// is written to the given ResponseWriter.
|
||||
func JSONResponse(w http.ResponseWriter, d interface{}, c int) {
|
||||
|
|
|
@ -47,6 +47,7 @@ func CreateAdminRouter() http.Handler {
|
|||
api.HandleFunc("/pages/", Use(API_Pages, mid.RequireAPIKey))
|
||||
api.HandleFunc("/pages/{id:[0-9]+}", Use(API_Pages_Id, mid.RequireAPIKey))
|
||||
api.HandleFunc("/import/group", API_Import_Group)
|
||||
api.HandleFunc("/import/email", API_Import_Email)
|
||||
|
||||
// Setup static file serving
|
||||
router.PathPrefix("/").Handler(http.FileServer(http.Dir("./static/")))
|
||||
|
|
|
@ -653,13 +653,12 @@ app.controller('TemplateCtrl', function($scope, $modal, TemplateService, ngTable
|
|||
}
|
||||
})
|
||||
|
||||
var TemplateModalCtrl = function($scope, $upload, $modalInstance) {
|
||||
var TemplateModalCtrl = function($scope, $upload, $modalInstance, $modal) {
|
||||
$scope.editorOptions = {
|
||||
fullPage: true,
|
||||
allowedContent: true
|
||||
}
|
||||
$scope.onFileSelect = function($files) {
|
||||
console.log($files)
|
||||
angular.forEach($files, function(file, key) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(e) {
|
||||
|
@ -686,6 +685,31 @@ var TemplateModalCtrl = function($scope, $upload, $modalInstance) {
|
|||
$scope.removeFile = function(file) {
|
||||
$scope.template.attachments.splice($scope.template.attachments.indexOf(file), 1);
|
||||
}
|
||||
|
||||
$scope.importEmail = function() {
|
||||
var emailInstance = $modal.open({
|
||||
templateUrl: '/js/app/partials/modals/importEmailModal.html',
|
||||
controller: ImportEmailCtrl,
|
||||
scope: $scope
|
||||
});
|
||||
|
||||
emailInstance.result.then(function(raw) {
|
||||
$scope.template.subject = raw;
|
||||
}, function() {});
|
||||
};
|
||||
};
|
||||
|
||||
var ImportEmailCtrl = function($scope, $http, $modalInstance) {
|
||||
$scope.email = {}
|
||||
$scope.ok = function() {
|
||||
// Simple POST request example (passing data) :
|
||||
$http.post('/api/import/email', $scope.email.raw,
|
||||
{ headers : {"Content-Type" : "text/plain"}}
|
||||
).success(function(data) {console.log("Success: " + data)})
|
||||
.error(function(data) {console.log("Error: " + data)});
|
||||
$modalInstance.close($scope.email.raw)
|
||||
};
|
||||
$scope.cancel = function() {$modalInstance.dismiss()}
|
||||
};
|
||||
|
||||
app.controller('LandingPageCtrl', function($scope, $modal, LandingPageService, ngTableParams) {
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
<!-- Import Email Modal -->
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" ng-click="cancel()">×</button>
|
||||
<h4 class="modal-title">Import Email</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<tabset>
|
||||
<tab>
|
||||
<tab-heading>
|
||||
<span>Raw <i class="fa fa-question-circle" tooltip="Input the raw email content, or "source"" tooltip-placement="right"></i></span>
|
||||
</tab-heading>
|
||||
<textarea rows="10" style="font-family:monospace;" class="form-control" ng-model="email.raw" placeholder="Email Content"></textarea>
|
||||
</tab>
|
||||
</tabset>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" ng-click="cancel()">Cancel</button>
|
||||
<button type="button" class="btn btn-primary" ng-click="ok()">Import</button>
|
||||
</div>
|
|
@ -9,11 +9,9 @@
|
|||
<div class="form-group">
|
||||
<input type="text" class="form-control" ng-model="template.name" placeholder="Template name" id="name" autofocus/>
|
||||
</div>
|
||||
<fieldset disabled>
|
||||
<div class="form-group">
|
||||
<button class="btn btn-danger btn-disabled"><i class="fa fa-envelope"></i> Import Email (Coming Soon!)</button>
|
||||
<button class="btn btn-danger btn-disabled" ng-click="importEmail()"><i class="fa fa-envelope"></i> Import Email (Coming Soon!)</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
<label class="control-label" for="subject">Subject:</label>
|
||||
<div class="form-group">
|
||||
<input type="text" class="form-control" ng-model="template.subject" placeholder="Email Subject" id="subject" />
|
||||
|
|
16
util/util.go
16
util/util.go
|
@ -4,11 +4,27 @@ import (
|
|||
"encoding/csv"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/mail"
|
||||
|
||||
"github.com/jordan-wright/email"
|
||||
"github.com/jordan-wright/gophish/models"
|
||||
)
|
||||
|
||||
// ParseMail takes in an HTTP Request and returns an Email object
|
||||
// TODO: This function will likely be changed to take in a []byte
|
||||
func ParseMail(r *http.Request) (email.Email, error) {
|
||||
e := email.Email{}
|
||||
m, err := mail.ReadMessage(r.Body)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
body, err := ioutil.ReadAll(m.Body)
|
||||
e.HTML = body
|
||||
return e, err
|
||||
}
|
||||
|
||||
func ParseCSV(r *http.Request) ([]models.Target, error) {
|
||||
mr, err := r.MultipartReader()
|
||||
ts := []models.Target{}
|
||||
|
|
Loading…
Reference in New Issue