diff --git a/.gitattributes b/.gitattributes index 3935aec7..9cdb2f68 100644 --- a/.gitattributes +++ b/.gitattributes @@ -12,3 +12,4 @@ static/js/moment.min.js linguist-vendored static/js/jquery* linguist-vendored static/js/ui-bootstrap-* linguist-vendored static/js/datatables* linguist-vendored +static/js/sweetalert2.min.js linguist-vendored diff --git a/controllers/api.go b/controllers/api.go index e541abfd..dabb5d8b 100644 --- a/controllers/api.go +++ b/controllers/api.go @@ -128,6 +128,22 @@ func API_Campaigns_Id_Results(w http.ResponseWriter, r *http.Request) { } } +// API_Campaigns_Id_Complete effectively "ends" a campaign. +// Future phishing emails clicked will return a simple "404" page. +func API_Campaigns_Id_Complete(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + id, _ := strconv.ParseInt(vars["id"], 0, 64) + switch { + case r.Method == "GET": + err := models.CompleteCampaign(id, ctx.Get(r, "user_id").(int64)) + if err != nil { + JSONResponse(w, models.Response{Success: false, Message: "Error completing campaign"}, http.StatusInternalServerError) + return + } + JSONResponse(w, models.Response{Success: true, Message: "Campaign completed successfully!"}, http.StatusOK) + } +} + // API_Groups returns a list of groups if requested via GET. // If requested via POST, API_Groups creates a new group and returns a reference to it. func API_Groups(w http.ResponseWriter, r *http.Request) { diff --git a/controllers/route.go b/controllers/route.go index 3f5e0267..44accc9f 100644 --- a/controllers/route.go +++ b/controllers/route.go @@ -47,6 +47,7 @@ func CreateAdminRouter() http.Handler { api.HandleFunc("/campaigns/", Use(API_Campaigns, mid.RequireAPIKey)) api.HandleFunc("/campaigns/{id:[0-9]+}", Use(API_Campaigns_Id, mid.RequireAPIKey)) api.HandleFunc("/campaigns/{id:[0-9]+}/results", Use(API_Campaigns_Id_Results, mid.RequireAPIKey)) + api.HandleFunc("/campaigns/{id:[0-9]+}/complete", Use(API_Campaigns_Id_Complete, mid.RequireAPIKey)) api.HandleFunc("/groups/", Use(API_Groups, mid.RequireAPIKey)) api.HandleFunc("/groups/{id:[0-9]+}", Use(API_Groups_Id, mid.RequireAPIKey)) api.HandleFunc("/templates/", Use(API_Templates, mid.RequireAPIKey)) @@ -110,6 +111,11 @@ func PhishTracker(w http.ResponseWriter, r *http.Request) { if err != nil { Logger.Println(err) } + // Don't process events for completed campaigns + if c.Status == models.CAMPAIGN_COMPLETE { + http.NotFound(w, r) + return + } c.AddEvent(models.Event{Email: rs.Email, Message: models.EVENT_OPENED}) // Don't update the status if the user already clicked the link // or submitted data to the campaign @@ -157,11 +163,16 @@ func PhishHandler(w http.ResponseWriter, r *http.Request) { http.NotFound(w, r) return } - rs.UpdateStatus(models.STATUS_SUCCESS) c, err := models.GetCampaign(rs.CampaignId, rs.UserId) if err != nil { Logger.Println(err) } + // Don't process events for completed campaigns + if c.Status == models.CAMPAIGN_COMPLETE { + http.NotFound(w, r) + return + } + rs.UpdateStatus(models.STATUS_SUCCESS) p, err := models.GetPage(c.PageId, c.UserId) if err != nil { Logger.Println(err) diff --git a/models/campaign.go b/models/campaign.go index ec91c3ef..460fd37d 100644 --- a/models/campaign.go +++ b/models/campaign.go @@ -338,8 +338,29 @@ func DeleteCampaign(id int64) error { // Delete the campaign err = db.Delete(&Campaign{Id: id}).Error if err != nil { - Logger.Panicln(err) - return err + Logger.Println(err) + } + return err +} + +// CompleteCampaign effectively "ends" a campaign. +// Any future emails clicked will return a simple "404" page. +func CompleteCampaign(id int64, uid int64) error { + Logger.Printf("Marking campaign %d as complete\n", id) + c, err := GetCampaign(id, uid) + if err != nil { + return err + } + // Don't overwrite original completed time + if c.Status == CAMPAIGN_COMPLETE { + return nil + } + // Mark the campaign as complete + c.CompletedDate = time.Now() + c.Status = CAMPAIGN_COMPLETE + err = db.Where("id=? and user_id=?", id, uid).Save(&c).Error + if err != nil { + Logger.Println(err) } return err } diff --git a/static/css/main.css b/static/css/main.css index f14866d8..b8198b55 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -513,7 +513,14 @@ td.details-control{ margin-left:10px !important; } } - table.dataTable{ width:100% !important; } +.btn-blue { + color:#fff; + background-color:#428bca; + border-color:#428bca; +} +.btn-blue:hover{ + background-color:#64a1d6; +} diff --git a/static/css/sweetalert2.min.css b/static/css/sweetalert2.min.css new file mode 100644 index 00000000..afa27ee0 --- /dev/null +++ b/static/css/sweetalert2.min.css @@ -0,0 +1 @@ +.swal2-modal,.swal2-overlay{position:fixed;display:none}.swal2-overlay{background-color:rgba(0,0,0,.4);left:0;right:0;top:0;bottom:0;z-index:1000}.swal2-modal{background-color:#fff;font-family:"Source Sans Pro", Helvetica, Arial, sans-serif,Helvetica,Arial,sans-serif;border-radius:5px;box-sizing:border-box;text-align:center;left:50%;top:50%;margin-top:-200px;max-height:90%;overflow-x:hidden;overflow-y:auto;z-index:2000}.swal2-modal:focus{outline:0}.swal2-modal.loading{overflow-y:hidden}.swal2-modal h2{color:#575757;font-size:30px;text-align:center;font-weight:600;text-transform:none;position:relative;margin:0;padding:0;line-height:60px;display:block}.swal2-modal hr{height:10px;color:transparent;border:0}.swal2-modal button.styled{color:#fff;border:0;box-shadow:none;font-size:17px;font-weight:500;border-radius:5px;padding:10px 32px;margin:0 5px;cursor:pointer}.swal2-content,.swal2-icon{padding:0;position:relative}.swal2-modal button.styled:focus{outline:0}.swal2-modal button.styled:not(.loading)[disabled]{opacity:.4;cursor:no-drop}.swal2-modal button.styled.loading{box-sizing:border-box;border:4px solid transparent;width:40px;height:40px;padding:0;margin:-2px 30px;vertical-align:top;background-color:transparent!important;color:transparent;cursor:default;border-radius:100%;-webkit-animation:rotate-loading 1.5s linear 0s infinite normal;animation:rotate-loading 1.5s linear 0s infinite normal}.swal2-modal button.styled::-moz-focus-inner{border:0}.swal2-modal button:not(.styled).loading:after{display:inline-block;content:"";margin-left:5px;vertical-align:-1px;height:6px;width:6px;border:3px solid #999;border-right-color:transparent;border-radius:50%;-webkit-animation:rotate-loading 1.5s linear 0s infinite normal;animation:rotate-loading 1.5s linear 0s infinite normal}.swal2-checkbox input,.swal2-checkbox span,.swal2-radio input,.swal2-radio span{vertical-align:middle}.swal2-modal .swal2-image{margin:20px auto;max-width:100%}.swal2-modal .swal2-close{font-size:36px;line-height:36px;font-family:serif;position:absolute;top:5px;right:13px;cursor:pointer;color:#cfcfcf;-webkit-transition:all .1s ease;transition:all .1s ease}.swal2-modal .swal2-close:hover{color:#d55}.swal2-modal>.swal2-checkbox,.swal2-modal>.swal2-input,.swal2-modal>.swal2-radio,.swal2-modal>.swal2-select,.swal2-modal>.swal2-textarea{display:none}.swal2-content{font-size:18px;text-align:center;font-weight:400;float:none;margin:0;line-height:normal;color:#555}.swal2-icon.swal2-info,.swal2-icon.swal2-question,.swal2-icon.swal2-warning{font-size:60px;line-height:80px;text-align:center}.swal2-icon{width:80px;height:80px;border:4px solid grey;border-radius:50%;margin:20px auto 30px;box-sizing:content-box;cursor:default;-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.swal2-icon.swal2-error{border-color:#f27474}.swal2-icon.swal2-error .x-mark{position:relative;display:block}.swal2-icon.swal2-error .line{position:absolute;height:5px;width:47px;background-color:#f27474;display:block;top:37px;border-radius:2px}.swal2-icon.swal2-error .line.left{-webkit-transform:rotate(45deg);transform:rotate(45deg);left:17px}.swal2-icon.swal2-error .line.right{-webkit-transform:rotate(-45deg);transform:rotate(-45deg);right:16px}.swal2-icon.swal2-warning{font-family:"Source Sans Pro", Helvetica, Arial, sans-serif,Helvetica,Arial,sans-serif;color:#f8bb86;border-color:#f8bb86}.swal2-icon.swal2-info{font-family:"Open Sans",sans-serif;color:#3fc3ee;border-color:#3fc3ee}.swal2-icon.swal2-question{font-family:"Source Sans Pro", Helvetica, Arial, sans-serif,Helvetica,Arial,sans-serif;color:#c9dae1;border-color:#c9dae1}.swal2-icon.swal2-success{border-color:#a5dc86}.swal2-icon.swal2-success::after,.swal2-icon.swal2-success::before{content:'';position:absolute;width:60px;height:120px;background:#fff}.swal2-icon.swal2-success::before{border-radius:120px 0 0 120px;top:-7px;left:-33px;-webkit-transform:rotate(-45deg);transform:rotate(-45deg);-webkit-transform-origin:60px 60px;transform-origin:60px 60px}.swal2-icon.swal2-success::after{border-radius:0 120px 120px 0;top:-11px;left:30px;-webkit-transform:rotate(-45deg);transform:rotate(-45deg);-webkit-transform-origin:0 60px;transform-origin:0 60px}.swal2-icon.swal2-success .placeholder{width:80px;height:80px;border:4px solid rgba(165,220,134,.2);border-radius:50%;box-sizing:content-box;position:absolute;left:-4px;top:-4px;z-index:2}.swal2-icon.swal2-success .fix{width:7px;height:90px;background-color:#fff;position:absolute;left:28px;top:8px;z-index:1;-webkit-transform:rotate(-45deg);transform:rotate(-45deg)}.swal2-icon.swal2-success .line{height:5px;background-color:#a5dc86;display:block;border-radius:2px;position:absolute;z-index:2}.swal2-icon.swal2-success .line.tip{width:25px;left:14px;top:46px;-webkit-transform:rotate(45deg);transform:rotate(45deg)}.swal2-icon.swal2-success .line.long{width:47px;right:8px;top:38px;-webkit-transform:rotate(-45deg);transform:rotate(-45deg)}.swal2-checkbox,.swal2-input,.swal2-radio,.swal2-select,.swal2-textarea{margin:20px auto}.swal2-input:not([type=file]),.swal2-textarea{width:100%;box-sizing:border-box;border-radius:3px;border:1px solid #d7d7d7;font-size:18px;box-shadow:inset 0 1px 1px rgba(0,0,0,.06);-webkit-transition:all .3s;transition:all .3s}.swal2-input:not([type=file]).error,.swal2-textarea.error{border-color:#f06e57!important}.swal2-input:not([type=file]):focus,.swal2-textarea:focus{outline:0;box-shadow:0 0 3px #c4e6f5;border:1px solid #b4dbed}.swal2-input:not([type=file]):focus::-moz-placeholder,.swal2-textarea:focus::-moz-placeholder{-webkit-transition:opacity .3s 30ms ease;transition:opacity .3s 30ms ease;opacity:.8}.swal2-input:not([type=file]):focus:-ms-input-placeholder,.swal2-textarea:focus:-ms-input-placeholder{-webkit-transition:opacity .3s 30ms ease;transition:opacity .3s 30ms ease;opacity:.8}.swal2-input:not([type=file]):focus::-webkit-input-placeholder,.swal2-textarea:focus::-webkit-input-placeholder{-webkit-transition:opacity .3s 30ms ease;transition:opacity .3s 30ms ease;opacity:.8}.swal2-input:not([type=file])::-moz-placeholder,.swal2-textarea::-moz-placeholder{color:#bdbdbd}.swal2-input:not([type=file]):-ms-input-placeholder,.swal2-textarea:-ms-input-placeholder{color:#bdbdbd}.swal2-input:not([type=file])::-webkit-input-placeholder,.swal2-textarea::-webkit-input-placeholder{color:#bdbdbd}.swal2-input:not([type=file]){height:43px;padding:0 12px}.swal2-input[type=file]{font-size:20px}.swal2-textarea{height:108px;padding:12px}.swal2-select{color:#555;font-size:inherit;padding:5px 10px;min-width:40%;max-width:100%}.swal2-radio{border:0}.swal2-radio label:not(:first-child){margin-left:20px}.swal2-radio input{margin:0 3px 0 0}.swal2-checkbox{color:#555}.swal2-validationerror{background-color:#f1f1f1;margin:0 -20px;overflow:hidden;padding:10px;color:#797979;font-size:16px;font-weight:400;display:none}.swal2-validationerror::before{content:"!";display:inline-block;width:24px;height:24px;border-radius:50%;background-color:#ea7d7d;color:#fff;line-height:24px;text-align:center;margin-right:10px}@-webkit-keyframes showSweetAlert{0%{-webkit-transform:scale(.7);transform:scale(.7)}45%{-webkit-transform:scale(1.05);transform:scale(1.05)}80%{-webkit-transform:scale(.95);transform:scale(.95)}100%{-webkit-transform:scale(1);transform:scale(1)}}@keyframes showSweetAlert{0%{-webkit-transform:scale(.7);transform:scale(.7)}45%{-webkit-transform:scale(1.05);transform:scale(1.05)}80%{-webkit-transform:scale(.95);transform:scale(.95)}100%{-webkit-transform:scale(1);transform:scale(1)}}@-webkit-keyframes hideSweetAlert{0%{-webkit-transform:scale(1);transform:scale(1);opacity:1}100%{-webkit-transform:scale(.5);transform:scale(.5);opacity:0}}@keyframes hideSweetAlert{0%{-webkit-transform:scale(1);transform:scale(1);opacity:1}100%{-webkit-transform:scale(.5);transform:scale(.5);opacity:0}}.show-swal2{-webkit-animation:showSweetAlert .3s;animation:showSweetAlert .3s}.show-swal2.no-animation{-webkit-animation:none;animation:none}.hide-swal2{-webkit-animation:hideSweetAlert .15s;animation:hideSweetAlert .15s}.hide-swal2.no-animation{-webkit-animation:none;animation:none}@-webkit-keyframes animate-success-tip{0%,54%{width:0;left:1px;top:19px}70%{width:50px;left:-8px;top:37px}84%{width:17px;left:21px;top:48px}100%{width:25px;left:14px;top:45px}}@keyframes animate-success-tip{0%,54%{width:0;left:1px;top:19px}70%{width:50px;left:-8px;top:37px}84%{width:17px;left:21px;top:48px}100%{width:25px;left:14px;top:45px}}@-webkit-keyframes animate-success-long{0%,65%{width:0;right:46px;top:54px}84%{width:55px;right:0;top:35px}100%{width:47px;right:8px;top:38px}}@keyframes animate-success-long{0%,65%{width:0;right:46px;top:54px}84%{width:55px;right:0;top:35px}100%{width:47px;right:8px;top:38px}}@-webkit-keyframes rotatePlaceholder{0%,5%{-webkit-transform:rotate(-45deg);transform:rotate(-45deg)}100%,12%{-webkit-transform:rotate(-405deg);transform:rotate(-405deg)}}@keyframes rotatePlaceholder{0%,5%{-webkit-transform:rotate(-45deg);transform:rotate(-45deg)}100%,12%{-webkit-transform:rotate(-405deg);transform:rotate(-405deg)}}.animate-success-tip{-webkit-animation:animate-success-tip .75s;animation:animate-success-tip .75s}.animate-success-long{-webkit-animation:animate-success-long .75s;animation:animate-success-long .75s}.swal2-icon.swal2-success.animate::after{-webkit-animation:rotatePlaceholder 4.25s ease-in;animation:rotatePlaceholder 4.25s ease-in}@-webkit-keyframes animate-error-icon{0%{-webkit-transform:rotateX(100deg);transform:rotateX(100deg);opacity:0}100%{-webkit-transform:rotateX(0);transform:rotateX(0);opacity:1}}@keyframes animate-error-icon{0%{-webkit-transform:rotateX(100deg);transform:rotateX(100deg);opacity:0}100%{-webkit-transform:rotateX(0);transform:rotateX(0);opacity:1}}.animate-error-icon{-webkit-animation:animate-error-icon .5s;animation:animate-error-icon .5s}@-webkit-keyframes animate-x-mark{0%,50%{-webkit-transform:scale(.4);transform:scale(.4);margin-top:26px;opacity:0}80%{-webkit-transform:scale(1.15);transform:scale(1.15);margin-top:-6px}100%{-webkit-transform:scale(1);transform:scale(1);margin-top:0;opacity:1}}@keyframes animate-x-mark{0%,50%{-webkit-transform:scale(.4);transform:scale(.4);margin-top:26px;opacity:0}80%{-webkit-transform:scale(1.15);transform:scale(1.15);margin-top:-6px}100%{-webkit-transform:scale(1);transform:scale(1);margin-top:0;opacity:1}}.animate-x-mark{-webkit-animation:animate-x-mark .5s;animation:animate-x-mark .5s}@-webkit-keyframes pulse-warning{0%{border-color:#f8d486}100%{border-color:#f8bb86}}@keyframes pulse-warning{0%{border-color:#f8d486}100%{border-color:#f8bb86}}.pulse-warning{-webkit-animation:pulse-warning .75s infinite alternate;animation:pulse-warning .75s infinite alternate}@-webkit-keyframes rotate-loading{0%{-webkit-transform:rotate(0);transform:rotate(0)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@keyframes rotate-loading{0%{-webkit-transform:rotate(0);transform:rotate(0)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}} diff --git a/static/js/app/campaign_results.js b/static/js/app/campaign_results.js index fc0a48d0..b1b3f258 100644 --- a/static/js/app/campaign_results.js +++ b/static/js/app/campaign_results.js @@ -1,4 +1,5 @@ var map = null +var doPoll = true; // statuses is a helper map to point result statuses to ui classes var statuses = { @@ -94,6 +95,52 @@ function deleteCampaign() { } } +// Completes a campaign after prompting the user +function completeCampaign() { + swal({ + title: "Are you sure?", + text: "Gophish will stop processing events for this campaign", + type: "warning", + animation: false, + showCancelButton: true, + confirmButtonText: "Complete Campaign", + confirmButtonColor: "#428bca", + reverseButtons: true, + allowOutsideClick: false, + preConfirm: function() { + return new Promise(function(resolve, reject) { + api.campaignId.complete(campaign.id) + .success(function(msg) { + resolve() + }) + .error(function(data) { + reject(data.responseJSON.message) + }) + }) + } + }).then(function() { + swal( + 'Campaign Completed!', + 'This campaign has been completed!', + 'success' + ); + $('#complete_button')[0].disabled = true; + $('#complete_button').text('Completed!') + doPoll = false; + }) + /* + if (confirm("Are you sure you want to delete: " + campaign.name + "?")) { + api.campaignId.delete(campaign.id) + .success(function(msg) { + location.href = '/campaigns' + }) + .error(function(e) { + $("#modal\\.flashes").empty().append("