github.com/merlinepedra/gophish1@v0.9.0/static/js/src/app/gophish.js (about)

     1  function errorFlash(message) {
     2      $("#flashes").empty()
     3      $("#flashes").append("<div style=\"text-align:center\" class=\"alert alert-danger\">\
     4          <i class=\"fa fa-exclamation-circle\"></i> " + message + "</div>")
     5  }
     6  
     7  function successFlash(message) {
     8      $("#flashes").empty()
     9      $("#flashes").append("<div style=\"text-align:center\" class=\"alert alert-success\">\
    10          <i class=\"fa fa-check-circle\"></i> " + message + "</div>")
    11  }
    12  
    13  // Fade message after n seconds
    14  function errorFlashFade(message, fade) {
    15      $("#flashes").empty()
    16      $("#flashes").append("<div style=\"text-align:center\" class=\"alert alert-danger\">\
    17          <i class=\"fa fa-exclamation-circle\"></i> " + message + "</div>")
    18      setTimeout(function(){ 
    19          $("#flashes").empty() 
    20      }, fade * 1000);
    21  }
    22  // Fade message after n seconds
    23  function successFlashFade(message, fade) {  
    24      $("#flashes").empty()
    25      $("#flashes").append("<div style=\"text-align:center\" class=\"alert alert-success\">\
    26          <i class=\"fa fa-check-circle\"></i> " + message + "</div>")
    27      setTimeout(function(){ 
    28          $("#flashes").empty() 
    29      }, fade * 1000);
    30  
    31  }
    32  
    33  function modalError(message) {
    34      $("#modal\\.flashes").empty().append("<div style=\"text-align:center\" class=\"alert alert-danger\">\
    35          <i class=\"fa fa-exclamation-circle\"></i> " + message + "</div>")
    36  }
    37  
    38  function query(endpoint, method, data, async) {
    39      return $.ajax({
    40          url: "/api" + endpoint,
    41          async: async,
    42          method: method,
    43          data: JSON.stringify(data),
    44          dataType: "json",
    45          contentType: "application/json",
    46          beforeSend: function (xhr) {
    47              xhr.setRequestHeader('Authorization', 'Bearer ' + user.api_key);
    48          }
    49      })
    50  }
    51  
    52  function escapeHtml(text) {
    53      return $("<div/>").text(text).html()
    54  }
    55  window.escapeHtml = escapeHtml
    56  
    57  function unescapeHtml(html) {
    58      return $("<div/>").html(html).text()
    59  }
    60  
    61  /**
    62   * 
    63   * @param {string} string - The input string to capitalize
    64   * 
    65   */
    66  var capitalize = function (string) {
    67      return string.charAt(0).toUpperCase() + string.slice(1);
    68  }
    69  
    70  /*
    71  Define our API Endpoints
    72  */
    73  var api = {
    74      // campaigns contains the endpoints for /campaigns
    75      campaigns: {
    76          // get() - Queries the API for GET /campaigns
    77          get: function () {
    78              return query("/campaigns/", "GET", {}, false)
    79          },
    80          // post() - Posts a campaign to POST /campaigns
    81          post: function (data) {
    82              return query("/campaigns/", "POST", data, false)
    83          },
    84          // summary() - Queries the API for GET /campaigns/summary
    85          summary: function () {
    86              return query("/campaigns/summary", "GET", {}, false)
    87          }
    88      },
    89      // campaignId contains the endpoints for /campaigns/:id
    90      campaignId: {
    91          // get() - Queries the API for GET /campaigns/:id
    92          get: function (id) {
    93              return query("/campaigns/" + id, "GET", {}, true)
    94          },
    95          // delete() - Deletes a campaign at DELETE /campaigns/:id
    96          delete: function (id) {
    97              return query("/campaigns/" + id, "DELETE", {}, false)
    98          },
    99          // results() - Queries the API for GET /campaigns/:id/results
   100          results: function (id) {
   101              return query("/campaigns/" + id + "/results", "GET", {}, true)
   102          },
   103          // complete() - Completes a campaign at POST /campaigns/:id/complete
   104          complete: function (id) {
   105              return query("/campaigns/" + id + "/complete", "GET", {}, true)
   106          },
   107          // summary() - Queries the API for GET /campaigns/summary
   108          summary: function (id) {
   109              return query("/campaigns/" + id + "/summary", "GET", {}, true)
   110          }
   111      },
   112      // groups contains the endpoints for /groups
   113      groups: {
   114          // get() - Queries the API for GET /groups
   115          get: function () {
   116              return query("/groups/", "GET", {}, false)
   117          },
   118          // post() - Posts a group to POST /groups
   119          post: function (group) {
   120              return query("/groups/", "POST", group, false)
   121          },
   122          // summary() - Queries the API for GET /groups/summary
   123          summary: function () {
   124              return query("/groups/summary", "GET", {}, true)
   125          }
   126      },
   127      // groupId contains the endpoints for /groups/:id
   128      groupId: {
   129          // get() - Queries the API for GET /groups/:id
   130          get: function (id) {
   131              return query("/groups/" + id, "GET", {}, false)
   132          },
   133          // put() - Puts a group to PUT /groups/:id
   134          put: function (group) {
   135              return query("/groups/" + group.id, "PUT", group, false)
   136          },
   137          // delete() - Deletes a group at DELETE /groups/:id
   138          delete: function (id) {
   139              return query("/groups/" + id, "DELETE", {}, false)
   140          }
   141      },
   142      // templates contains the endpoints for /templates
   143      templates: {
   144          // get() - Queries the API for GET /templates
   145          get: function () {
   146              return query("/templates/", "GET", {}, false)
   147          },
   148          // post() - Posts a template to POST /templates
   149          post: function (template) {
   150              return query("/templates/", "POST", template, false)
   151          }
   152      },
   153      // templateId contains the endpoints for /templates/:id
   154      templateId: {
   155          // get() - Queries the API for GET /templates/:id
   156          get: function (id) {
   157              return query("/templates/" + id, "GET", {}, false)
   158          },
   159          // put() - Puts a template to PUT /templates/:id
   160          put: function (template) {
   161              return query("/templates/" + template.id, "PUT", template, false)
   162          },
   163          // delete() - Deletes a template at DELETE /templates/:id
   164          delete: function (id) {
   165              return query("/templates/" + id, "DELETE", {}, false)
   166          }
   167      },
   168      // pages contains the endpoints for /pages
   169      pages: {
   170          // get() - Queries the API for GET /pages
   171          get: function () {
   172              return query("/pages/", "GET", {}, false)
   173          },
   174          // post() - Posts a page to POST /pages
   175          post: function (page) {
   176              return query("/pages/", "POST", page, false)
   177          }
   178      },
   179      // pageId contains the endpoints for /pages/:id
   180      pageId: {
   181          // get() - Queries the API for GET /pages/:id
   182          get: function (id) {
   183              return query("/pages/" + id, "GET", {}, false)
   184          },
   185          // put() - Puts a page to PUT /pages/:id
   186          put: function (page) {
   187              return query("/pages/" + page.id, "PUT", page, false)
   188          },
   189          // delete() - Deletes a page at DELETE /pages/:id
   190          delete: function (id) {
   191              return query("/pages/" + id, "DELETE", {}, false)
   192          }
   193      },
   194      // SMTP contains the endpoints for /smtp
   195      SMTP: {
   196          // get() - Queries the API for GET /smtp
   197          get: function () {
   198              return query("/smtp/", "GET", {}, false)
   199          },
   200          // post() - Posts a SMTP to POST /smtp
   201          post: function (smtp) {
   202              return query("/smtp/", "POST", smtp, false)
   203          }
   204      },
   205      // SMTPId contains the endpoints for /smtp/:id
   206      SMTPId: {
   207          // get() - Queries the API for GET /smtp/:id
   208          get: function (id) {
   209              return query("/smtp/" + id, "GET", {}, false)
   210          },
   211          // put() - Puts a SMTP to PUT /smtp/:id
   212          put: function (smtp) {
   213              return query("/smtp/" + smtp.id, "PUT", smtp, false)
   214          },
   215          // delete() - Deletes a SMTP at DELETE /smtp/:id
   216          delete: function (id) {
   217              return query("/smtp/" + id, "DELETE", {}, false)
   218          }
   219      },
   220      // IMAP containts the endpoints for /imap/
   221      IMAP: {
   222          get: function() {
   223              return query("/imap/", "GET", {}, !1)
   224          },
   225          post: function(e) {
   226              return query("/imap/", "POST", e, !1)
   227          },
   228          validate: function(e) {
   229              return query("/imap/validate", "POST", e, true)
   230          }
   231      },
   232      // users contains the endpoints for /users
   233      users: {
   234          // get() - Queries the API for GET /users
   235          get: function () {
   236              return query("/users/", "GET", {}, true)
   237          },
   238          // post() - Posts a user to POST /users
   239          post: function (user) {
   240              return query("/users/", "POST", user, true)
   241          }
   242      },
   243      // userId contains the endpoints for /users/:id
   244      userId: {
   245          // get() - Queries the API for GET /users/:id
   246          get: function (id) {
   247              return query("/users/" + id, "GET", {}, true)
   248          },
   249          // put() - Puts a user to PUT /users/:id
   250          put: function (user) {
   251              return query("/users/" + user.id, "PUT", user, true)
   252          },
   253          // delete() - Deletes a user at DELETE /users/:id
   254          delete: function (id) {
   255              return query("/users/" + id, "DELETE", {}, true)
   256          }
   257      },
   258      webhooks: {
   259          get: function() {
   260              return query("/webhooks/", "GET", {}, false)
   261          },
   262          post: function(webhook) {
   263              return query("/webhooks/", "POST", webhook, false)
   264          },
   265      },
   266      webhookId: {
   267          get: function(id) {
   268              return query("/webhooks/" + id, "GET", {}, false)
   269          },
   270          put: function(webhook) {
   271              return query("/webhooks/" + webhook.id, "PUT", webhook, true)
   272          },
   273          delete: function(id) {
   274              return query("/webhooks/" + id, "DELETE", {}, false)
   275          },
   276          ping: function(id) {
   277              return query("/webhooks/" + id + "/validate", "POST", {}, true)
   278          },
   279      },
   280      // import handles all of the "import" functions in the api
   281      import_email: function (req) {
   282          return query("/import/email", "POST", req, false)
   283      },
   284      // clone_site handles importing a site by url
   285      clone_site: function (req) {
   286          return query("/import/site", "POST", req, false)
   287      },
   288      // send_test_email sends an email to the specified email address
   289      send_test_email: function (req) {
   290          return query("/util/send_test_email", "POST", req, true)
   291      },
   292      reset: function () {
   293          return query("/reset", "POST", {}, true)
   294      }
   295  }
   296  window.api = api
   297  
   298  // Register our moment.js datatables listeners
   299  $(document).ready(function () {
   300      // Setup nav highlighting
   301      var path = location.pathname;
   302      $('.nav-sidebar li').each(function () {
   303          var $this = $(this);
   304          // if the current path is like this link, make it active
   305          if ($this.find("a").attr('href') === path) {
   306              $this.addClass('active');
   307          }
   308      })
   309      $.fn.dataTable.moment('MMMM Do YYYY, h:mm:ss a');
   310      // Setup tooltips
   311      $('[data-toggle="tooltip"]').tooltip()
   312  });