Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

litle patch for import_logs.py to request from source address #6027

Closed
ghost opened this issue Aug 20, 2014 · 2 comments
Closed

litle patch for import_logs.py to request from source address #6027

ghost opened this issue Aug 20, 2014 · 2 comments
Labels
Bug For errors / faults / flaws / inconsistencies etc. duplicate For issues that already existed in our issue tracker and were reported previously.
Milestone

Comments

@ghost
Copy link

ghost commented Aug 20, 2014

litle patch for import_logs.py to request from source address:


import functools

Formats.

class BoundHTTPHandler(urllib2.HTTPHandler):

def __init__(self, source_address=None, debuglevel=0):
    urllib2.HTTPHandler.__init__(self, debuglevel)
    self.http_class = functools.partial(httplib.HTTPConnection,
            source_address=source_address)

def http_open(self, req):
    return self.do_open(self.http_class, req)

(...other code....)

def _call(path, args, headers=None, url=None, data=None):
    """
    Make a request to the Piwik site. It is up to the caller to format
    arguments, to embed authentication, etc.
    """
    if url is None:
        url = config.options.piwik_url
    headers = headers or {}

    if data is None:
        # If Content-Type isn't defined, PHP do not parse the request's body.
        headers['Content-type'] = 'application/x-www-form-urlencoded'
        data = urllib.urlencode(args)
    elif not isinstance(data, basestring) and headers['Content-type'] == 'application/json':
        data = json.dumps(data)

    handler = BoundHTTPHandler(source_address=('127.0.0.1', 0))
    opener = urllib2.build_opener(handler)
    urllib2.install_opener(opener)

    headers['User-Agent'] = 'Piwik/LogImport'
    request = urllib2.Request(url + path, data, headers)
    response = urllib2.urlopen(request)
    result = response.read()
    response.close()
    return result
@mattab
Copy link
Member

mattab commented Aug 20, 2014

Hi @den68 thanks for the report. Would you mind creating a pull request with your change explaining:

  • what was the problem
  • how your pull request solves the issue?

We will then consider merging the pull request in Piwik for all to benefit. Thank you!

@mattab mattab added this to the Piwik 2.6.0 milestone Aug 20, 2014
@mattab mattab closed this as completed Aug 20, 2014
@ghost
Copy link
Author

ghost commented Aug 20, 2014

when applying nginx and restrict access by ip address it is sometimes necessary to specify the source address of the sender.
I hope I'm clearly outlined, sorry my english .. :)

@mattab mattab added the Bug For errors / faults / flaws / inconsistencies etc. label Sep 20, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc. duplicate For issues that already existed in our issue tracker and were reported previously.
Projects
None yet
Development

No branches or pull requests

1 participant