mirror of
https://github.com/jessfraz/dockerfiles.git
synced 2024-11-27 04:16:45 +01:00
update telize
Signed-off-by: Jessica Frazelle <acidburn@docker.com>
This commit is contained in:
parent
b26259e206
commit
6b616050d4
|
@ -18,6 +18,7 @@ RUN ln -sf /dev/stdout /var/log/nginx/access.log \
|
|||
|
||||
COPY nginx.conf /etc/nginx/nginx.conf
|
||||
COPY mime.types /etc/nginx/mime.types
|
||||
COPY telize.conf /etc/nginx/conf.d/telize.conf
|
||||
|
||||
EXPOSE 80 443
|
||||
|
||||
|
@ -36,7 +37,6 @@ RUN buildDeps=' \
|
|||
&& git clone https://github.com/fcambus/telize.git /usr/src/telize \
|
||||
&& cd /usr/src/telize \
|
||||
&& cp timezone*.conf /etc/nginx/ \
|
||||
&& cp telize /etc/nginx/conf.d/telize.conf \
|
||||
&& rm -rf /usr/src/telize \
|
||||
&& apt-get purge -y --auto-remove $buildDeps
|
||||
|
||||
|
|
|
@ -94,6 +94,9 @@ http {
|
|||
# GeoIP
|
||||
##
|
||||
|
||||
map_hash_bucket_size 128;
|
||||
map_hash_max_size 4096;
|
||||
|
||||
include /etc/nginx/timezone.conf;
|
||||
include /etc/nginx/timezone-offset.conf;
|
||||
|
||||
|
@ -101,9 +104,6 @@ http {
|
|||
geoip_city /usr/share/GeoIP/GeoLiteCity.dat;
|
||||
geoip_org /usr/share/GeoIP/GeoIPASNum.dat;
|
||||
|
||||
##
|
||||
# Virtual Host Configs
|
||||
##
|
||||
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
# Virtual hosts
|
||||
include /etc/nginx/conf.d/telize.conf;
|
||||
}
|
||||
|
|
161
telize/telize.conf
Normal file
161
telize/telize.conf
Normal file
|
@ -0,0 +1,161 @@
|
|||
###############################################################################
|
||||
# #
|
||||
# Telize 1.05 #
|
||||
# Copyright (c) 2013-2016, Frederic Cambus #
|
||||
# http://www.telize.com #
|
||||
# #
|
||||
# Created: 2013-08-15 #
|
||||
# Last Updated: 2016-01-05 #
|
||||
# #
|
||||
# Telize is released under the BSD 3-Clause license. #
|
||||
# See LICENSE file for details. #
|
||||
# #
|
||||
###############################################################################
|
||||
|
||||
server {
|
||||
# Configuration variables
|
||||
set $cors "true";
|
||||
set $cors_origin "*";
|
||||
|
||||
server_name 127.0.0.1;
|
||||
|
||||
# Uncomment when using Telize behind a load balancer
|
||||
# set_real_ip_from 10.0.0.0/8; # Put your load balancer IP range here
|
||||
# real_ip_header X-Forwarded-For;
|
||||
|
||||
charset_types application/json;
|
||||
|
||||
keepalive_timeout 0;
|
||||
gzip off;
|
||||
|
||||
## Deny illegal Host headers
|
||||
if ($http_referer ~* ^(rwandair.com|m.rwandair.com|stage-rwandair.mobiashara.com)$ ) {
|
||||
return 444;
|
||||
}
|
||||
|
||||
location ~ /ip$ {
|
||||
add_header Cache-Control no-cache;
|
||||
|
||||
charset off;
|
||||
default_type text/plain;
|
||||
|
||||
echo $remote_addr;
|
||||
}
|
||||
|
||||
location ~ /jsonip$ {
|
||||
charset utf-8;
|
||||
default_type application/json;
|
||||
|
||||
content_by_lua '
|
||||
local cjson = require("cjson")
|
||||
|
||||
local json = cjson.encode({
|
||||
ip = ngx.var.remote_addr
|
||||
})
|
||||
|
||||
local callback = ngx.var.arg_callback
|
||||
|
||||
if callback then
|
||||
ngx.say(callback, "(", json, ");")
|
||||
else
|
||||
ngx.say(json)
|
||||
end';
|
||||
}
|
||||
|
||||
location ~ /geoip/?(?<ip>.*) {
|
||||
if ($ip = "") {
|
||||
set $ip $remote_addr;
|
||||
}
|
||||
|
||||
# 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-Real-IP $ip;
|
||||
proxy_set_header Host $host;
|
||||
proxy_pass $scheme://127.0.0.1/jsonify?callback=$arg_callback;
|
||||
}
|
||||
|
||||
location /jsonify {
|
||||
set_real_ip_from 127.0.0.1;
|
||||
|
||||
access_log off;
|
||||
|
||||
charset utf-8;
|
||||
default_type application/json;
|
||||
|
||||
if ($cors = "true") {
|
||||
add_header Access-Control-Allow-Origin $cors_origin;
|
||||
}
|
||||
|
||||
more_set_headers "Cache-Control: no-cache";
|
||||
|
||||
content_by_lua '
|
||||
local cjson = require("cjson")
|
||||
local iconv = require("iconv")
|
||||
local cd = iconv.new("utf-8","iso-8859-15")
|
||||
|
||||
-- Check for invalid IP addresses
|
||||
if ngx.var.remote_addr == "127.0.0.1" then
|
||||
ngx.status = ngx.HTTP_BAD_REQUEST
|
||||
ngx.say(cjson.encode({code = 401, message = "Input string is not a valid IP address"}))
|
||||
ngx.exit(ngx.HTTP_OK)
|
||||
end
|
||||
|
||||
local payload = {
|
||||
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
|
||||
|
||||
-- Convert latitude and longitude to numeric values
|
||||
if payload.latitude ~= nil and payload.longitude ~= nil then
|
||||
payload.latitude = tonumber(payload.latitude)
|
||||
payload.longitude = tonumber(payload.longitude)
|
||||
end
|
||||
|
||||
-- Convert city name to UTF-8 if it exists
|
||||
if payload.city ~= nil then
|
||||
payload.city = cd:iconv(payload.city)
|
||||
end
|
||||
|
||||
-- Convert region name to UTF-8 if it exists
|
||||
if payload.region ~= nil then
|
||||
payload.region = cd:iconv(payload.region)
|
||||
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';
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user