diff -Nru aceproxy-0.9.1-626~e066964/acehttp.py aceproxy-0.9.1-638~c939589/acehttp.py --- aceproxy-0.9.1-626~e066964/acehttp.py 2017-01-17 23:22:58.000000000 +0000 +++ aceproxy-0.9.1-638~c939589/acehttp.py 2017-02-13 13:05:05.000000000 +0000 @@ -29,6 +29,7 @@ import time import threading import urllib2 +import urllib import urlparse import Queue import aceclient @@ -51,6 +52,19 @@ requestlist = [] + def log_message(self, format, *args): + logger.info("%s - - [%s] %s\n" % + (self.address_string(), + self.log_date_time_string(), + urllib.unquote(format%args).decode('UTF-8'))) + + def log_request(self, code='-', size='-'): + logger.debug('"%s" %s %s', + self.requestline, str(code), str(size)) + + def log_error(self, format, *args): + logger.error(format, *args) + def handle_one_request(self): ''' Add request to requestlist, handle request and remove from the list @@ -176,7 +190,8 @@ # Current greenlet self.requestgreenlet = gevent.getcurrent() # Connected client IP address - self.clientip = self.request.getpeername()[0] + self.clientip = self.headers['X-Forwarded-For'] \ + if self.headers.has_key('X-Forwarded-For') else self.request.getpeername()[0] if AceConfig.firewall: # If firewall enabled @@ -190,7 +205,7 @@ self.dieWithError(403) # 403 Forbidden return - logger.info("Accepted connection from " + self.clientip + " path " + self.path) + logger.info("Accepted connection from " + self.clientip + " path " + urllib.unquote(self.path).decode('UTF-8')) try: self.splittedpath = self.path.split('/') diff -Nru aceproxy-0.9.1-626~e066964/debian/changelog aceproxy-0.9.1-638~c939589/debian/changelog --- aceproxy-0.9.1-626~e066964/debian/changelog 2017-01-17 23:22:59.000000000 +0000 +++ aceproxy-0.9.1-638~c939589/debian/changelog 2017-02-13 13:05:06.000000000 +0000 @@ -1,7 +1,29 @@ -aceproxy (0.9.1-626~e066964-yakkety) yakkety; urgency=medium +aceproxy (0.9.1-638~c939589-yakkety) yakkety; urgency=medium - * [569de632a89ad2fee78667c3f9a57a10215c77c5] - universalization EOL (EndOFLine) for playlist + * [01d5b271a9f634f274a4a5fe21da298caa25a118] + Change urllib to urllib2 for geoip + + * [73b886f6103b2af1293781aed0b834a2ba3dc502] + Minor changes for stat_plugin stability + + * [14006d7fae51968bf13fd63ef0539ea92318f436] + Add duration time & GeoIP info for connections + + * [61ff44388fa1163184abe475ea0b1777241b95ce] + Add locale support for stat info + + * [4f71a186d910fa87d6dbaf9861bd29ddeab9ed8b] + Get client IP from Header + + * [902226e26d5118c43c37252d4ef04b3f11e5cdd6] + Small changes for loggin + + * [c90d5d316355a01b23802440355623ec5080fd60] + Add subclass for override the log messages + + Change log massages in Cyrillic to readable format + + Logger output changes - -- Andrey Pavlenko Wed, 18 Jan 2017 02:22:59 +0300 + -- Andrey Pavlenko Mon, 13 Feb 2017 16:05:06 +0300 diff -Nru aceproxy-0.9.1-626~e066964/plugins/stat_plugin.py aceproxy-0.9.1-638~c939589/plugins/stat_plugin.py --- aceproxy-0.9.1-626~e066964/plugins/stat_plugin.py 2017-01-17 23:22:58.000000000 +0000 +++ aceproxy-0.9.1-638~c939589/plugins/stat_plugin.py 2017-02-13 13:05:05.000000000 +0000 @@ -5,6 +5,18 @@ ''' from modules.PluginInterface import AceProxyPlugin import time +import json +import plugins.modules.ipaddr as ipaddr +import urllib2 + +localnetranges = ( + '192.168.0.0/16', + '10.0.0.0/8', + '172.16.0.0/12', + '224.0.0.0/4', + '240.0.0.0/5', + '127.0.0.0/8', + ) class Stat(AceProxyPlugin): handlers = ('stat', 'favicon.ico') @@ -13,7 +25,24 @@ self.config = AceConfig self.stuff = AceStuff + def geo_ip_lookup(self, ip_address): + """ + Look up the geo information based on the IP address passed in + """ + GEOIP_LOOKUP_URL = 'http://api.2ip.ua/geo.json?ip=%s' + lookup_url = GEOIP_LOOKUP_URL % ip_address + req = urllib2.Request(lookup_url, headers={'User-Agent' : "Magic Browser"}) + response = json.loads(urllib2.urlopen(req, timeout=5).read()) + + return {'country_code' : response['country_code'], + 'country' : response['country'], + 'region' : response['region'], + 'city' : response['city'], + } + def handle(self, connection, headers_only=False): + current_time = time.time() + if connection.reqtype == 'favicon.ico': connection.send_response(404) return @@ -26,6 +55,7 @@ return connection.wfile.write( + '' '

Connected clients: ' + str(self.stuff.clientcounter.total) + '

') connection.wfile.write( '
Concurrent connections limit: ' + str(self.config.maxconns) + '
') @@ -38,6 +68,16 @@ connection.wfile.write(c.channelName.encode('UTF8')) else: connection.wfile.write(i) + connection.wfile.write('') - connection.wfile.write('') + clientinrange = any(map(lambda i: ipaddr.IPAddress(c.handler.clientip) in ipaddr.IPNetwork(i),localnetranges)) + + if clientinrange: + connection.wfile.write('') + else: + geo_ip_info = self.geo_ip_lookup(c.handler.clientip) + connection.wfile.write('') + + connection.wfile.write('') + connection.wfile.write('') connection.wfile.write('
' + c.handler.clientip + '' + time.strftime('%d %b %Y %H:%M:%S', time.localtime(c.connectionTime)) + '
' + 'Local IP adress' + '' + geo_ip_info.get('country') + ', ' + geo_ip_info.get('city') + '' + time.strftime('%c', time.localtime(c.connectionTime)) + '' + time.strftime("%H:%M:%S", time.gmtime(current_time-c.connectionTime)) + '
')