Comment 0 for bug 1065127

Revision history for this message
The Loeki (the-loeki) wrote :

When OpenERP (at least 6.1+) is deployed behind a proxy, the dbfilter option won't work.

This is due to openerp/addons/web/controllers/main.py (lines 136+) doing:

def db_list(req):
    dbs = []
    proxy = req.session.proxy("db")
    dbs = proxy.list()
    h = req.httprequest.environ['HTTP_HOST'].split(':')[0]
    d = h.split('.')[0]
    r = req.config.dbfilter.replace('%h', h).replace('%d', d)
    dbs = [i for i in dbs if re.match(r, i)]
    return dbs

However, in proxy configs, it should user HTTP_X_FORWARDED_HOST as filter.

This can easily be done by checking whether that var is in the environ:

def db_list(req):
    dbs = []
    proxy = req.session.proxy("db")
    dbs = proxy.list()
    if 'HTTP_X_FORWARDED_HOST' in req.httprequest.environ:
        h = 'HTTP_X_FORWARDED_HOST'
    else:
        h = 'HTTP_HOST'
    h = req.httprequest.environ[h].split(':')[0]
    d = h.split('.')[0]
    r = req.config.dbfilter.replace('%h', h).replace('%d', d)
    dbs = [i for i in dbs if re.match(r, i)]
    return dbs