shinken-monitoring / mod-webui

Shinken Web User Interface
GNU Affero General Public License v3.0
79 stars 71 forks source link

WebUI2 HTTP 500 error #391

Closed massimiliano-dalcero closed 8 years ago

massimiliano-dalcero commented 8 years ago

On Debian Testing, when use WebUI2 return HTTP error 500 when (in first page) template call method

    def can_action(self, username=None)

because when:

    user = request.environ.get('USER', None)

this line return a string ("root") in "user" variable and the next "return statment" :

       return user and ((not self.manage_acl) or user.is_admin or user.can_submit_commands)

come back error:

Error: 500 Internal Server Error

Sorry, the requested URL 'http://172.16.224.188:7767/user/login' caused an error:

Internal Server Error

Exception:

AttributeError("'str' object has no attribute 'is_admin'",)

Traceback:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/bottle.py", line 862, in _handle
    return route.call(**args)
  File "/usr/local/lib/python2.7/dist-packages/bottle.py", line 1732, in wrapper
    rv = callback(*a, **ka)
  File "/var/lib/shinken/modules/webui2/module.py", line 400, in lock_version
    return f(**args)
  File "/usr/local/lib/python2.7/dist-packages/bottle.py", line 3619, in wrapper
    return template(tpl_name, **tplvars)
  File "/usr/local/lib/python2.7/dist-packages/bottle.py", line 3595, in template
    return TEMPLATES[tplid].render(kwargs)
  File "/usr/local/lib/python2.7/dist-packages/bottle.py", line 3399, in render
    self.execute(stdout, env)
  File "/usr/local/lib/python2.7/dist-packages/bottle.py", line 3386, in execute
    eval(self.co, env)
  File "/var/lib/shinken/modules/webui2/plugins/login/views/login.tpl", line 83, in <module>
    %include("footer_element")
  File "/usr/local/lib/python2.7/dist-packages/bottle.py", line 3376, in _include
    return self.cache[_name].execute(env['_stdout'], env)
  File "/usr/local/lib/python2.7/dist-packages/bottle.py", line 3386, in execute
    eval(self.co, env)
  File "/var/lib/shinken/modules/webui2/views/footer_element.tpl", line 23, in <module>
    %if app.can_action():
  File "/var/lib/shinken/modules/webui2/module.py", line 687, in can_action
    return user and ((not self.manage_acl) or user.is_admin or user.can_submit_commands)
AttributeError: 'str' object has no attribute 'is_admin'

so I changed method like this:

    try:
        retval = user and ((not self.manage_acl) or user.is_admin or user.can_submit_commands)
    except:
        retval = False
    return retval

and now all work

mohierf commented 8 years ago

Thanks for reporting, I will include your fix ...