diff --git a/app/assets/javascripts/admin/templates/ip_locator.js.handlebars b/app/assets/javascripts/admin/templates/ip_locator.js.handlebars
new file mode 100644
index 00000000000..379e61fe7de
--- /dev/null
+++ b/app/assets/javascripts/admin/templates/ip_locator.js.handlebars
@@ -0,0 +1,54 @@
+{{#if view.ip}}
+
+{{/if}}
+{{#if view.showBox }}
+
+
{{i18n ip_info.title}}
+
+ {{#if view.location}}
+ {{#if view.location.hostname}}
+ - {{i18n ip_info.hostname}}
+ - {{view.location.hostname}}
+ {{/if}}
+
+ - {{i18n ip_info.location}}
+ -
+ {{#if view.location.loc}}
+ {{view.location.loc}}
+ {{view.location.city}}, {{view.location.region}}, {{view.location.country}}
+ {{else}}
+ {{i18n ip_info.location_not_found}}
+ {{/if}}
+
+
+ {{#if view.location.org}}
+ - {{i18n ip_info.organisation}}
+ - {{view.location.org}}
+ {{/if}}
+
+ {{#if view.location.phone}}
+ - {{i18n ip_info.phone}}
+ - {{view.location.phone}}
+ {{/if}}
+ {{else}}
+ {{i18n loading}}
+ {{/if}}
+
+ - {{i18n ip_info.other_accounts}}
+ -
+ {{#if view.other_accounts_loading}}
+ {{i18n loading}}
+ {{else}}
+ {{#each view.other_accounts}}
+ {{#link-to 'adminUser' this}}{{avatar this usernamePath="user.username" imageSize="small"}}{{/link-to}}
+ {{else}}
+ {{i18n ip_info.no_other_accounts}}
+ {{/each}}
+ {{/if}}
+
-
+
+
+
+{{/if}}
\ No newline at end of file
diff --git a/app/assets/javascripts/admin/templates/user_index.js.handlebars b/app/assets/javascripts/admin/templates/user_index.js.handlebars
index 867fa38226c..e3a8d41ef9e 100644
--- a/app/assets/javascripts/admin/templates/user_index.js.handlebars
+++ b/app/assets/javascripts/admin/templates/user_index.js.handlebars
@@ -79,6 +79,7 @@
+ {{view Discourse.AdminIpLocatorView ipBinding="ip_address"}}
{{/if}}
@@ -86,7 +87,11 @@
{{i18n user.registration_ip_address.title}}
{{registration_ip_address}}
-
+
+ {{#if currentUser.admin}}
+ {{view Discourse.AdminIpLocatorView ipBinding="registration_ip_address"}}
+ {{/if}}
+
{{#if showBadges}}
diff --git a/app/assets/javascripts/admin/views/admin_ip_locator_view.js b/app/assets/javascripts/admin/views/admin_ip_locator_view.js
new file mode 100644
index 00000000000..f2500c929cd
--- /dev/null
+++ b/app/assets/javascripts/admin/views/admin_ip_locator_view.js
@@ -0,0 +1,29 @@
+Discourse.AdminIpLocatorView = Discourse.View.extend({
+ templateName: 'admin/templates/ip_locator',
+ classNames: ["iplocator"],
+ actions: {
+ hideBox: function(){
+ this.set("showBox", false);
+ },
+ lookup: function(){
+ if (!this.get("location")){
+ $.get("http://ipinfo.io/" + this.get("ip"), function(response) {
+ this.set("location", response);
+ }.bind(this), "jsonp");
+ }
+
+ if (!this.get("other_accounts")){
+ this.set("other_accounts_loading", true);
+ Discourse.ajax("/admin/users/list/active.json", {
+ data: {"ip": this.get("ip"),
+ "exclude": this.get("controller.id")
+ }
+ }).then(function (users) {
+ this.set("other_accounts", users.map(function(u) { return Discourse.AdminUser.create(u);}));
+ this.set("other_accounts_loading", false);
+ }.bind(this));
+ }
+ this.set("showBox", true);
+ }
+ }
+});
\ No newline at end of file
diff --git a/app/assets/stylesheets/common/admin/admin_base.scss b/app/assets/stylesheets/common/admin/admin_base.scss
index bb1eb10983d..8682484c41b 100644
--- a/app/assets/stylesheets/common/admin/admin_base.scss
+++ b/app/assets/stylesheets/common/admin/admin_base.scss
@@ -81,6 +81,25 @@
};
}
+.iplocator {
+ position: relative;
+ display: inline-block;
+
+ .location-box {
+ position: absolute;
+ width: 460px;
+ right: 0px;
+ z-index: 990;
+ box-shadow: 0 2px 6px scale-color-diff();
+ margin-top: -2px;
+ background-color: $secondary;
+ padding: 12px 12px 5px;
+ .close {
+ float: right;
+ }
+ }
+}
+
.admin-container {
margin-top: 20px;
}
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index e76677ad775..870f68c6212 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -238,6 +238,16 @@ en:
one: "%{count} new post in the past %{unit}."
other: "%{count} new posts in the past %{unit}."
+ ip_info:
+ title: ip_info_title
+ hostname: ip_info_hostname
+ location: ip_info_location
+ location_not_found: ip_info_location_not_found
+ organisation: ip_info_organisation
+ phone: ip_info_phone
+ other_accounts: ip_info_other_accounts
+ no_other_accounts: ip_info_no_other_accounts
+
user:
said: "{{username}} said:"
profile: "Profile"
@@ -1713,6 +1723,7 @@ en:
refresh_browsers: "Force browser refresh"
show_public_profile: "Show Public Profile"
impersonate: 'Impersonate'
+ ip_lookup: "ip_lookup"
log_out: "Sign Out"
logged_out: "User was logged out on all devices"
revoke_admin: 'Revoke Admin'
diff --git a/lib/admin_user_index_query.rb b/lib/admin_user_index_query.rb
index 49ae8ed1975..d59ab466c5b 100644
--- a/lib/admin_user_index_query.rb
+++ b/lib/admin_user_index_query.rb
@@ -40,6 +40,19 @@ class AdminUserIndexQuery
end
end
+
+ def filter_by_ip
+ if params[:ip].present?
+ @query.where('ip_address = :ip or registration_ip_address = :ip', ip: params[:ip])
+ end
+ end
+
+ def filter_exclude
+ if params[:exclude].present?
+ @query.where('id != ?', params[:exclude])
+ end
+ end
+
# this might not be needed in rails 4 ?
def append(active_relation)
@query = active_relation if active_relation
@@ -48,6 +61,8 @@ class AdminUserIndexQuery
def find_users_query
append filter_by_trust
append filter_by_query_classification
+ append filter_by_ip
+ append filter_exclude
append filter_by_search
@query
end