mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-02-25 07:54:11 -05:00
BUGFIX: IP lookup wasn't working when using HTTPS
REFACTOR: the ip locator into a ip-lookup component
This commit is contained in:
parent
18fafa12a2
commit
59b5ba7c0f
12 changed files with 125 additions and 64 deletions
43
app/assets/javascripts/admin/components/ip-lookup.js.es6
Normal file
43
app/assets/javascripts/admin/components/ip-lookup.js.es6
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
export default Ember.Component.extend({
|
||||||
|
classNames: ["ip-lookup"],
|
||||||
|
|
||||||
|
city: function () {
|
||||||
|
return [
|
||||||
|
this.get("location.city"),
|
||||||
|
this.get("location.region"),
|
||||||
|
this.get("location.country")
|
||||||
|
].filter(Boolean).join(", ");
|
||||||
|
}.property("location.@{city,region,country}"),
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
lookup: function () {
|
||||||
|
var self = this;
|
||||||
|
this.set("show", true);
|
||||||
|
|
||||||
|
if (!this.get("location")) {
|
||||||
|
Discourse.ajax("/admin/users/ip-info.json", {
|
||||||
|
data: { ip: this.get("ip") }
|
||||||
|
}).then(function (location) {
|
||||||
|
self.set("location", Em.Object.create(location));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.get("other_accounts")) {
|
||||||
|
this.set("other_accounts_loading", true);
|
||||||
|
Discourse.AdminUser.findAll("active", {
|
||||||
|
"ip": this.get("ip"),
|
||||||
|
"exclude": this.get("user_id")
|
||||||
|
}).then(function (users) {
|
||||||
|
self.setProperties({
|
||||||
|
other_accounts: users,
|
||||||
|
other_accounts_loading: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
hide: function () {
|
||||||
|
this.set("show", false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
|
@ -91,7 +91,7 @@ Discourse.AdminUsersListController = Ember.ArrayController.extend(Discourse.Pres
|
||||||
var adminUsersListController = this;
|
var adminUsersListController = this;
|
||||||
adminUsersListController.set('loading', true);
|
adminUsersListController.set('loading', true);
|
||||||
|
|
||||||
Discourse.AdminUser.findAll(this.get('query'), this.get('username')).then(function (result) {
|
Discourse.AdminUser.findAll(this.get('query'), { filter: this.get('username') }).then(function (result) {
|
||||||
adminUsersListController.set('content', result);
|
adminUsersListController.set('content', result);
|
||||||
adminUsersListController.set('loading', false);
|
adminUsersListController.set('loading', false);
|
||||||
});
|
});
|
||||||
|
|
|
@ -431,7 +431,7 @@ Discourse.AdminUser.reopenClass({
|
||||||
|
|
||||||
findAll: function(query, filter) {
|
findAll: function(query, filter) {
|
||||||
return Discourse.ajax("/admin/users/list/" + query + ".json", {
|
return Discourse.ajax("/admin/users/list/" + query + ".json", {
|
||||||
data: { filter: filter }
|
data: filter
|
||||||
}).then(function(users) {
|
}).then(function(users) {
|
||||||
return users.map(function(u) {
|
return users.map(function(u) {
|
||||||
return Discourse.AdminUser.create(u);
|
return Discourse.AdminUser.create(u);
|
||||||
|
|
|
@ -1,54 +0,0 @@
|
||||||
{{#if view.ip}}
|
|
||||||
<button class='btn' {{action lookup target="view"}}>
|
|
||||||
<span class="fa fa-globe"></span> {{i18n admin.user.ip_lookup}}
|
|
||||||
</button>
|
|
||||||
{{/if}}
|
|
||||||
{{#if view.showBox }}
|
|
||||||
<div class="location-box">
|
|
||||||
<h4>{{i18n ip_info.title}}</h4>
|
|
||||||
<dl>
|
|
||||||
{{#if view.location}}
|
|
||||||
{{#if view.location.hostname}}
|
|
||||||
<dt>{{i18n ip_info.hostname}}</dt>
|
|
||||||
<dd>{{view.location.hostname}}</dd>
|
|
||||||
{{/if}}
|
|
||||||
|
|
||||||
<dt>{{i18n ip_info.location}}</dt>
|
|
||||||
<dd>
|
|
||||||
{{#if view.location.loc}}
|
|
||||||
<a href="https://maps.google.com/maps?q={{unbound view.location.loc}}" target="_blank">{{view.location.loc}}</a><br>
|
|
||||||
{{view.location.city}}, {{view.location.region}}, {{view.location.country}}
|
|
||||||
{{else}}
|
|
||||||
{{i18n ip_info.location_not_found}}
|
|
||||||
{{/if}}
|
|
||||||
</dd>
|
|
||||||
|
|
||||||
{{#if view.location.org}}
|
|
||||||
<dt>{{i18n ip_info.organisation}}</dt>
|
|
||||||
<dd>{{view.location.org}}</dd>
|
|
||||||
{{/if}}
|
|
||||||
|
|
||||||
{{#if view.location.phone}}
|
|
||||||
<dt>{{i18n ip_info.phone}}</dt>
|
|
||||||
<dd>{{view.location.phone}}</dd>
|
|
||||||
{{/if}}
|
|
||||||
{{else}}
|
|
||||||
<div class='spinner'>{{i18n loading}}</div>
|
|
||||||
{{/if}}
|
|
||||||
|
|
||||||
<dt>{{i18n ip_info.other_accounts}}</dt>
|
|
||||||
<dd>
|
|
||||||
{{#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}}
|
|
||||||
<dd>
|
|
||||||
</dl>
|
|
||||||
<button class='btn close' {{action hideBox target="view" }}>{{i18n close}}</button>
|
|
||||||
</div>
|
|
||||||
{{/if}}
|
|
|
@ -76,10 +76,10 @@
|
||||||
<div class='value'>{{ip_address}}</div>
|
<div class='value'>{{ip_address}}</div>
|
||||||
<div class='controls'>
|
<div class='controls'>
|
||||||
{{#if currentUser.admin}}
|
{{#if currentUser.admin}}
|
||||||
<button class='btn' {{action refreshBrowsers target="content"}}>
|
<button class='btn' {{action refreshBrowsers target="content"}}>
|
||||||
{{i18n admin.user.refresh_browsers}}
|
{{i18n admin.user.refresh_browsers}}
|
||||||
</button>
|
</button>
|
||||||
{{view Discourse.AdminIpLocatorView ipBinding="ip_address"}}
|
{{ip-lookup ip=ip_address user_id=id}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -89,7 +89,7 @@
|
||||||
<div class='value'>{{registration_ip_address}}</div>
|
<div class='value'>{{registration_ip_address}}</div>
|
||||||
<div class='controls'>
|
<div class='controls'>
|
||||||
{{#if currentUser.admin}}
|
{{#if currentUser.admin}}
|
||||||
{{view Discourse.AdminIpLocatorView ipBinding="registration_ip_address"}}
|
{{ip-lookup ip=registration_ip_address user_id=id}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
{{#if ip}}
|
||||||
|
<button class="btn" {{action lookup}}>
|
||||||
|
<span class="fa fa-globe"></span> {{i18n admin.user.ip_lookup}}
|
||||||
|
</button>
|
||||||
|
{{/if}}
|
||||||
|
{{#if show}}
|
||||||
|
<div class="location-box">
|
||||||
|
<h4>{{i18n ip_lookup.title}}</h4>
|
||||||
|
<dl>
|
||||||
|
{{#if location}}
|
||||||
|
{{#if location.hostname}}
|
||||||
|
<dt>{{i18n ip_lookup.hostname}}</dt>
|
||||||
|
<dd>{{location.hostname}}</dd>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
<dt>{{i18n ip_lookup.location}}</dt>
|
||||||
|
<dd>
|
||||||
|
{{#if location.loc}}
|
||||||
|
<a href="https://maps.google.com/maps?q={{unbound location.loc}}" target="_blank">{{location.loc}}</a><br>
|
||||||
|
{{city}}
|
||||||
|
{{else}}
|
||||||
|
{{i18n ip_lookup.location_not_found}}
|
||||||
|
{{/if}}
|
||||||
|
</dd>
|
||||||
|
|
||||||
|
{{#if location.org}}
|
||||||
|
<dt>{{i18n ip_lookup.organisation}}</dt>
|
||||||
|
<dd>{{location.org}}</dd>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
{{#if location.phone}}
|
||||||
|
<dt>{{i18n ip_lookup.phone}}</dt>
|
||||||
|
<dd>{{location.phone}}</dd>
|
||||||
|
{{/if}}
|
||||||
|
{{else}}
|
||||||
|
<div class="spinner">{{i18n loading}}</div>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
<dt>{{i18n ip_lookup.other_accounts}}</dt>
|
||||||
|
<dd>
|
||||||
|
{{#if other_accounts_loading}}
|
||||||
|
<div class="spinner">{{i18n loading}}</div>
|
||||||
|
{{else}}
|
||||||
|
{{#each other_accounts}}
|
||||||
|
{{#link-to "adminUser" this}}{{avatar this usernamePath="user.username" imageSize="small"}}{{/link-to}}
|
||||||
|
{{else}}
|
||||||
|
{{i18n ip_lookup.no_other_accounts}}
|
||||||
|
{{/each}}
|
||||||
|
{{/if}}
|
||||||
|
<dd>
|
||||||
|
</dl>
|
||||||
|
<button class="btn close" {{action hide}}>{{i18n close}}</button>
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
|
@ -86,7 +86,7 @@ td.flaggers td {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
.iplocator {
|
.ip-lookup {
|
||||||
position: relative;
|
position: relative;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
|
||||||
|
|
|
@ -183,6 +183,15 @@ class Admin::UsersController < Admin::AdminController
|
||||||
def leader_requirements
|
def leader_requirements
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ip_info
|
||||||
|
params.require(:ip)
|
||||||
|
ip = params[:ip]
|
||||||
|
|
||||||
|
# should we cache results in redis?
|
||||||
|
location = Excon.get("http://ipinfo.io/#{ip}/json", read_timeout: 30, connect_timeout: 30).body rescue nil
|
||||||
|
|
||||||
|
render json: location
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
|
|
@ -240,7 +240,7 @@ en:
|
||||||
one: "%{count} new post in the past %{unit}."
|
one: "%{count} new post in the past %{unit}."
|
||||||
other: "%{count} new posts in the past %{unit}."
|
other: "%{count} new posts in the past %{unit}."
|
||||||
|
|
||||||
ip_info:
|
ip_lookup:
|
||||||
title: IP Address Lookup
|
title: IP Address Lookup
|
||||||
hostname: Hostname
|
hostname: Hostname
|
||||||
location: Location
|
location: Location
|
||||||
|
|
|
@ -48,6 +48,7 @@ Discourse::Application.routes.draw do
|
||||||
resources :users, id: USERNAME_ROUTE_FORMAT do
|
resources :users, id: USERNAME_ROUTE_FORMAT do
|
||||||
collection do
|
collection do
|
||||||
get "list/:query" => "users#index"
|
get "list/:query" => "users#index"
|
||||||
|
get "ip-info" => "users#ip_info"
|
||||||
put "approve-bulk" => "users#approve_bulk"
|
put "approve-bulk" => "users#approve_bulk"
|
||||||
delete "reject-bulk" => "users#reject_bulk"
|
delete "reject-bulk" => "users#reject_bulk"
|
||||||
end
|
end
|
||||||
|
|
|
@ -40,7 +40,6 @@ class AdminUserIndexQuery
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def filter_by_ip
|
def filter_by_ip
|
||||||
if params[:ip].present?
|
if params[:ip].present?
|
||||||
@query.where('ip_address = :ip or registration_ip_address = :ip', ip: params[:ip])
|
@query.where('ip_address = :ip or registration_ip_address = :ip', ip: params[:ip])
|
||||||
|
|
|
@ -371,6 +371,15 @@ describe Admin::UsersController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'ip-info' do
|
||||||
|
|
||||||
|
it "uses ipinfo.io webservice to retrieve the info" do
|
||||||
|
Excon.expects(:get).with("http://ipinfo.io/123.123.123.123/json", read_timeout: 30, connect_timeout: 30)
|
||||||
|
xhr :get, :ip_info, ip: "123.123.123.123"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue