update telize

Signed-off-by: Jess Frazelle <acidburn@google.com>
This commit is contained in:
Jess Frazelle 2017-06-05 16:20:42 -04:00
parent 2acc9e3b4e
commit a22f3334af
No known key found for this signature in database
GPG Key ID: 18F3685C0022BFF3
3 changed files with 96 additions and 95 deletions

View File

@ -19,7 +19,7 @@ COPY telize.conf /etc/nginx/conf.d/telize.conf
EXPOSE 80 443 EXPOSE 80 443
ENV TELIZE_VERSION 1.07 ENV TELIZE_VERSION master
RUN buildDeps=' \ RUN buildDeps=' \
curl \ curl \
@ -29,9 +29,9 @@ RUN buildDeps=' \
&& apt-get update && apt-get install -y $buildDeps --no-install-recommends \ && apt-get update && apt-get install -y $buildDeps --no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \ && rm -rf /var/lib/apt/lists/* \
&& mkdir -p /usr/share/GeoIP \ && mkdir -p /usr/share/GeoIP \
&& curl -sSL https://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz -o /usr/share/GeoIP/GeoIP.dat.gz \ && curl -sSL https://geolite.maxmind.com/download/geoip/database/GeoIPv6.dat.gz -o /usr/share/GeoIP/GeoIPv6.dat.gz \
&& curl -sSL http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz -o /usr/share/GeoIP/GeoLiteCity.dat.gz \ && curl -sSL http://geolite.maxmind.com/download/geoip/database/GeoLiteCityv6-beta/GeoLiteCityv6.dat.gz -o /usr/share/GeoIP/GeoLiteCityv6.dat.gz \
&& curl -sSL http://download.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz -o /usr/share/GeoIP/GeoIPASNum.dat.gz \ && curl -sSL http://download.maxmind.com/download/geoip/database/asnum/GeoIPASNumv6.dat.gz -o /usr/share/GeoIP/GeoIPASNumv6.dat.gz \
&& gunzip /usr/share/GeoIP/*gz \ && gunzip /usr/share/GeoIP/*gz \
&& git clone --depth 1 --branch "${TELIZE_VERSION}" https://github.com/fcambus/telize.git /usr/src/telize \ && git clone --depth 1 --branch "${TELIZE_VERSION}" https://github.com/fcambus/telize.git /usr/src/telize \
&& ( \ && ( \

View File

@ -96,15 +96,15 @@ http {
# GeoIP # GeoIP
## ##
map_hash_bucket_size 128; map_hash_bucket_size 64;
map_hash_max_size 4096; map_hash_max_size 8192;
include /etc/nginx/timezone.conf; include /etc/nginx/timezone.conf;
include /etc/nginx/timezone-offset.conf; include /etc/nginx/timezone-offset.conf;
geoip_country /usr/share/GeoIP/GeoIP.dat; geoip_country /usr/share/GeoIP/GeoIPv6.dat;
geoip_city /usr/share/GeoIP/GeoLiteCity.dat; geoip_city /usr/share/GeoIP/GeoLiteCityv6.dat;
geoip_org /usr/share/GeoIP/GeoIPASNum.dat; geoip_org /usr/share/GeoIP/GeoIPASNumv6.dat;
# Virtual hosts # Virtual hosts
include /etc/nginx/conf.d/telize.conf; include /etc/nginx/conf.d/telize.conf;

View File

@ -1,13 +1,13 @@
############################################################################### ###############################################################################
# # # #
# Telize 1.05 # # Telize 1.07 #
# Copyright (c) 2013-2016, Frederic Cambus # # Copyright (c) 2013-2017, Frederic Cambus #
# http://www.telize.com # # https://www.telize.com #
# # # #
# Created: 2013-08-15 # # Created: 2013-08-15 #
# Last Updated: 2016-01-05 # # Last Updated: 2017-02-07 #
# # # #
# Telize is released under the BSD 3-Clause license. # # Telize is released under the BSD 2-Clause license. #
# See LICENSE file for details. # # See LICENSE file for details. #
# # # #
############################################################################### ###############################################################################
@ -28,38 +28,36 @@ server {
keepalive_timeout 0; keepalive_timeout 0;
gzip off; gzip off;
## Deny illegal Host headers
if ($http_referer ~* ^(rwandair.com|m.rwandair.com|stage-rwandair.mobiashara.com)$ ) {
return 444;
}
location ~ /ip$ { location ~ /ip$ {
add_header Cache-Control no-cache; add_header Cache-Control no-cache;
charset off; charset off;
default_type text/plain; default_type text/plain;
echo $remote_addr; content_by_lua_block {
ngx.say(ngx.var.remote_addr)
}
} }
location ~ /jsonip$ { location ~ /jsonip$ {
charset utf-8; charset utf-8;
default_type application/json; default_type application/json;
content_by_lua ' content_by_lua_block {
local cjson = require("cjson") local cjson = require("cjson")
local json = cjson.encode({ local json = cjson.encode({
ip = ngx.var.remote_addr ip = ngx.var.remote_addr
}) })
local callback = ngx.var.arg_callback local callback = ngx.var.arg_callback
if callback then if callback then
ngx.say(callback, "(", json, ");") ngx.say(callback, "(", json, ");")
else else
ngx.say(json) ngx.say(json)
end'; end
}
} }
location ~ /geoip/?(?<ip>.*) { location ~ /geoip/?(?<ip>.*) {
@ -67,7 +65,8 @@ server {
set $ip $remote_addr; set $ip $remote_addr;
} }
# Uncomment when using Telize behind a load balancer, and comment the directive setting X-Real-IP # Uncomment when using Telize behind a load balancer, and
# comment the directive setting X-Real-IP
# proxy_set_header X-Forwarded-For $ip; # proxy_set_header X-Forwarded-For $ip;
proxy_set_header X-Real-IP $ip; proxy_set_header X-Real-IP $ip;
@ -87,77 +86,79 @@ server {
add_header Access-Control-Allow-Origin $cors_origin; add_header Access-Control-Allow-Origin $cors_origin;
} }
more_set_headers "Cache-Control: no-cache"; content_by_lua_block {
local cjson = require("cjson")
local iconv = require("iconv")
local cd = iconv.new("utf-8","iso-8859-15")
content_by_lua ' ngx.header["Cache-Control"] = "no-cache";
local cjson = require("cjson")
local iconv = require("iconv")
local cd = iconv.new("utf-8","iso-8859-15")
-- Check for invalid IP addresses -- Check for invalid IP addresses
if ngx.var.remote_addr == "127.0.0.1" then if ngx.var.remote_addr == "127.0.0.1" then
ngx.status = ngx.HTTP_BAD_REQUEST ngx.status = ngx.HTTP_BAD_REQUEST
ngx.say(cjson.encode({code = 401, message = "Input string is not a valid IP address"})) ngx.say(cjson.encode({
ngx.exit(ngx.HTTP_OK) code = 401,
end message = "Input string is not a valid IP address"
}))
local payload = { ngx.exit(ngx.HTTP_OK)
ip = ngx.var.remote_addr,
country_code = ngx.var.geoip_city_country_code,
country_code3 = ngx.var.geoip_city_country_code3,
country = ngx.var.geoip_city_country_name,
region = ngx.var.geoip_region_name,
region_code = ngx.var.geoip_region,
city = ngx.var.geoip_city,
postal_code = ngx.var.geoip_postal_code,
continent_code = ngx.var.geoip_city_continent_code,
latitude = ngx.var.geoip_latitude,
longitude = ngx.var.geoip_longitude,
dma_code = ngx.var.geoip_dma_code,
area_code = ngx.var.geoip_area_code,
organization = ngx.var.geoip_org,
timezone = ngx.var.geoip_timezone,
offset = ngx.var.geoip_timezone_offset,
}
local callback = ngx.var.arg_callback
-- Validate payload
for item, value in pairs(payload) do
if payload[item] == "" then
payload[item] = nil
end end
end
-- Convert latitude and longitude to numeric values local payload = {
if payload.latitude ~= nil and payload.longitude ~= nil then ip = ngx.var.remote_addr,
payload.latitude = tonumber(payload.latitude) country_code = ngx.var.geoip_city_country_code,
payload.longitude = tonumber(payload.longitude) country_code3 = ngx.var.geoip_city_country_code3,
end country = ngx.var.geoip_city_country_name,
region = ngx.var.geoip_region_name,
region_code = ngx.var.geoip_region,
city = ngx.var.geoip_city,
postal_code = ngx.var.geoip_postal_code,
continent_code = ngx.var.geoip_city_continent_code,
latitude = ngx.var.geoip_latitude,
longitude = ngx.var.geoip_longitude,
dma_code = ngx.var.geoip_dma_code,
area_code = ngx.var.geoip_area_code,
organization = ngx.var.geoip_org,
timezone = ngx.var.geoip_timezone,
offset = ngx.var.geoip_timezone_offset,
}
-- Convert city name to UTF-8 if it exists local callback = ngx.var.arg_callback
if payload.city ~= nil then
payload.city = cd:iconv(payload.city)
end
-- Convert region name to UTF-8 if it exists -- Validate payload
if payload.region ~= nil then for item, value in pairs(payload) do
payload.region = cd:iconv(payload.region) if payload[item] == "" then
end payload[item] = nil
end
end
-- Convert organization name to UTF-8 if it exists -- Convert latitude and longitude to numeric values
if payload.organization ~= nil then if payload.latitude ~= nil and payload.longitude ~= nil then
payload.organization = cd:iconv(payload.organization) payload.latitude = tonumber(payload.latitude)
end payload.longitude = tonumber(payload.longitude)
end
local json = cjson.encode(payload) -- Convert city name to UTF-8 if it exists
if payload.city ~= nil then
payload.city = cd:iconv(payload.city)
end
if callback ~= "" then -- Convert region name to UTF-8 if it exists
ngx.say(callback, "(", json, ");") if payload.region ~= nil then
else payload.region = cd:iconv(payload.region)
ngx.say(json) end
end';
-- Convert organization name to UTF-8 if it exists
if payload.organization ~= nil then
payload.organization = cd:iconv(payload.organization)
end
local json = cjson.encode(payload)
if callback ~= "" then
ngx.say(callback, "(", json, ");")
else
ngx.say(json)
end
}
} }
} }
# vi: ft=nginx