2018-06-15 11:03:24 -04:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
import AdminUser from "admin/models/admin-user";
|
2018-08-20 11:29:20 -04:00
|
|
|
import copyText from "discourse/lib/copy-text";
|
2015-11-20 20:27:06 -05:00
|
|
|
|
2014-07-07 16:18:18 -04:00
|
|
|
export default Ember.Component.extend({
|
|
|
|
classNames: ["ip-lookup"],
|
|
|
|
|
2014-11-24 13:34:04 -05:00
|
|
|
otherAccountsToDelete: function() {
|
|
|
|
// can only delete up to 50 accounts at a time
|
|
|
|
var total = Math.min(50, this.get("totalOthersWithSameIP") || 0);
|
|
|
|
var visible = Math.min(50, this.get("other_accounts.length") || 0);
|
|
|
|
return Math.max(visible, total);
|
|
|
|
}.property("other_accounts", "totalOthersWithSameIP"),
|
|
|
|
|
2014-07-07 16:18:18 -04:00
|
|
|
actions: {
|
2018-06-15 11:03:24 -04:00
|
|
|
lookup: function() {
|
2014-07-07 16:18:18 -04:00
|
|
|
var self = this;
|
|
|
|
this.set("show", true);
|
|
|
|
|
|
|
|
if (!this.get("location")) {
|
2016-06-30 13:55:44 -04:00
|
|
|
ajax("/admin/users/ip-info", {
|
2014-07-07 16:18:18 -04:00
|
|
|
data: { ip: this.get("ip") }
|
2018-06-15 11:03:24 -04:00
|
|
|
}).then(function(location) {
|
2014-07-07 16:18:18 -04:00
|
|
|
self.set("location", Em.Object.create(location));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.get("other_accounts")) {
|
2014-11-17 12:17:24 -05:00
|
|
|
this.set("otherAccountsLoading", true);
|
2014-11-24 13:34:04 -05:00
|
|
|
|
|
|
|
var data = {
|
2018-06-15 11:03:24 -04:00
|
|
|
ip: this.get("ip"),
|
|
|
|
exclude: this.get("userId"),
|
|
|
|
order: "trust_level DESC"
|
2014-11-24 13:34:04 -05:00
|
|
|
};
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
ajax("/admin/users/total-others-with-same-ip", { data }).then(function(
|
|
|
|
result
|
|
|
|
) {
|
2014-11-24 13:34:04 -05:00
|
|
|
self.set("totalOthersWithSameIP", result.total);
|
|
|
|
});
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
AdminUser.findAll("active", data).then(function(users) {
|
2014-07-07 16:18:18 -04:00
|
|
|
self.setProperties({
|
|
|
|
other_accounts: users,
|
2018-06-15 11:03:24 -04:00
|
|
|
otherAccountsLoading: false
|
2014-07-07 16:18:18 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
hide: function() {
|
2014-07-07 16:18:18 -04:00
|
|
|
this.set("show", false);
|
2014-11-20 13:59:20 -05:00
|
|
|
},
|
|
|
|
|
2018-08-20 11:29:20 -04:00
|
|
|
copy: function() {
|
|
|
|
let text = `IP: ${this.get("ip")}\n`;
|
|
|
|
const location = this.get("location");
|
|
|
|
if (location) {
|
|
|
|
if (location.hostname) {
|
|
|
|
text += `${I18n.t("ip_lookup.hostname")}: ${location.hostname}\n`;
|
|
|
|
}
|
|
|
|
|
|
|
|
text += I18n.t("ip_lookup.location");
|
2018-10-30 18:08:57 -04:00
|
|
|
if (location.location) {
|
|
|
|
text += `: ${location.location}\n`;
|
2018-08-20 11:29:20 -04:00
|
|
|
} else {
|
|
|
|
text += `: ${I18n.t("ip_lookup.location_not_found")}\n`;
|
|
|
|
}
|
|
|
|
|
2018-10-30 18:08:57 -04:00
|
|
|
if (location.organization) {
|
2018-08-20 11:29:20 -04:00
|
|
|
text += I18n.t("ip_lookup.organisation");
|
2018-10-30 18:08:57 -04:00
|
|
|
text += `: ${location.organization}\n`;
|
2018-08-20 11:29:20 -04:00
|
|
|
}
|
|
|
|
}
|
2018-08-23 16:27:08 -04:00
|
|
|
const copyRange = $('<p id="copy-range"></p>');
|
2018-10-30 18:08:57 -04:00
|
|
|
copyRange.html(text.trim().replace(/\n/g, "<br>"));
|
2018-08-20 11:29:20 -04:00
|
|
|
$(document.body).append(copyRange);
|
2018-08-23 16:27:08 -04:00
|
|
|
if (copyText(text, copyRange[0])) {
|
|
|
|
this.set("copied", true);
|
|
|
|
Ember.run.later(() => this.set("copied", false), 2000);
|
|
|
|
}
|
2018-08-20 11:29:20 -04:00
|
|
|
copyRange.remove();
|
|
|
|
},
|
|
|
|
|
2014-11-24 12:04:34 -05:00
|
|
|
deleteOtherAccounts: function() {
|
2014-11-20 13:59:20 -05:00
|
|
|
var self = this;
|
2018-06-15 11:03:24 -04:00
|
|
|
bootbox.confirm(
|
|
|
|
I18n.t("ip_lookup.confirm_delete_other_accounts"),
|
|
|
|
I18n.t("no_value"),
|
|
|
|
I18n.t("yes_value"),
|
|
|
|
function(confirmed) {
|
|
|
|
if (confirmed) {
|
|
|
|
self.setProperties({
|
|
|
|
other_accounts: null,
|
|
|
|
otherAccountsLoading: true,
|
|
|
|
totalOthersWithSameIP: null
|
|
|
|
});
|
2014-11-24 13:34:04 -05:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
ajax("/admin/users/delete-others-with-same-ip.json", {
|
|
|
|
type: "DELETE",
|
|
|
|
data: {
|
|
|
|
ip: self.get("ip"),
|
|
|
|
exclude: self.get("userId"),
|
|
|
|
order: "trust_level DESC"
|
|
|
|
}
|
|
|
|
}).then(function() {
|
|
|
|
self.send("lookup");
|
|
|
|
});
|
|
|
|
}
|
2014-11-20 13:59:20 -05:00
|
|
|
}
|
2018-06-15 11:03:24 -04:00
|
|
|
);
|
2014-07-07 16:18:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|