This repository has been archived by the owner on Oct 31, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d0e145e
Showing
6 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pkg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
What? | ||
===== | ||
|
||
A plugin for Oldskool displays IP information from ipinfodb.com | ||
|
||
Configuration? | ||
-------------- | ||
|
||
You should sign up for an account at ipinfodb.com, once you have an | ||
API key fill it into your config | ||
|
||
In your _oldskool.yaml_ add the following: | ||
|
||
- :ipinfodb_apikey: YOUR_API_KEY | ||
|
||
You can then create a keyword: | ||
|
||
:keywords: | ||
- :type: :ipinfodb | ||
:keywords: | ||
- ip | ||
|
||
This creates a keyword _ip_ that you can call without any parameters | ||
to get info for your browser IP, otherwise supply an IP as an argument. | ||
|
||
Only IPv4 is supported at the moment | ||
|
||
Contact? | ||
-------- | ||
|
||
R.I.Pienaar / rip@devco.net / @ripienaar / http://devco.net/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'rubygems' | ||
require 'rake/gempackagetask' | ||
|
||
spec = Gem::Specification::new do |spec| | ||
spec.name = "oldskool-ipinfodb" | ||
spec.version = "0.0.1" | ||
spec.platform = Gem::Platform::RUBY | ||
spec.summary = "oldskool-ipinfodb" | ||
spec.description = "description: Display IP information from ipinfodb.com" | ||
|
||
spec.files = FileList["lib/**/*.rb", "views/*.erb"] | ||
spec.executables = [] | ||
|
||
spec.require_path = "lib" | ||
|
||
spec.has_rdoc = false | ||
spec.test_files = nil | ||
spec.add_dependency 'geo_ip' | ||
|
||
spec.extensions.push(*[]) | ||
|
||
spec.author = "R.I.Pienaar" | ||
spec.email = "rip@devco.net" | ||
spec.homepage = "http://devco.net/" | ||
end | ||
|
||
Rake::GemPackageTask.new(spec) do |pkg| | ||
pkg.need_zip = false | ||
pkg.need_tar = false | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'oldskool/ipinfodb_handler' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module Oldskool | ||
class IpinfodbHandler | ||
def initialize(params, keyword, config) | ||
require 'geo_ip' | ||
require 'ipaddr' | ||
|
||
@params = params | ||
@keyword = keyword | ||
@config = config | ||
self | ||
end | ||
|
||
def plugin_template(template) | ||
File.read(File.expand_path("../../../views/#{template}.erb", __FILE__)) | ||
end | ||
|
||
def handle_request(keyword, query) | ||
raise "Please set :ipinfodb_apikey in the config" unless @config[:ipinfodb_apikey] | ||
|
||
(query == "") ? ip = @params[:http_request].ip : ip = query | ||
|
||
ipaddr = IPAddr.new(ip) | ||
return({:template => :error, :error => "Invalid IP #{ip}, only IPv4 addresses are supported"}) unless ipaddr.ipv4? | ||
|
||
GeoIp.api_key = @config[:ipinfodb_apikey] | ||
geoip = GeoIp.geolocation(ip) | ||
|
||
{:template => plugin_template(:ipinfo), :ipinfo => geoip} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<% unless @error %> | ||
<% unless @result[:ipinfo][:status_message] == "" %> | ||
Failed to retrieve IP Info: <%= @result[:ipinfo][:status_message] %> | ||
<% else %> | ||
<table> | ||
<tr><td><strong>IP Address:</strong></td><td><%= @result[:ipinfo][:ip] %></td></tr> | ||
<tr><td><strong>City:</strong></td><td><%= @result[:ipinfo][:city].capitalize %></td></tr> | ||
<tr><td><strong>Country:</strong></td><td><%= @result[:ipinfo][:country_name].capitalize %></td></tr> | ||
<tr><td><strong>Country Code:</strong></td><td><%= @result[:ipinfo][:country_code] %></td></tr> | ||
<tr><td><strong>Region:</strong></td><td><%= @result[:ipinfo][:region_name].capitalize %></td></tr> | ||
<tr><td><strong>ZIP Code:</strong></td><td><%= @result[:ipinfo][:zip_code] %></td></tr> | ||
<tr><td><strong>Coordinates:</strong></td><td>lon <%= @result[:ipinfo][:longitude] %> lat <%= @result[:ipinfo][:latitude] %></td></tr> | ||
</table> | ||
<% end %> | ||
<% end %> |