Browse Source

[REF] remove useless field 'name' and fix description;

pull/262/head
Sylvain LE GAL 9 years ago
parent
commit
fea6fe0068
  1. 2
      auth_brute_force/README.rst
  2. 18
      auth_brute_force/models/res_banned_remote.py
  3. 7
      auth_brute_force/views/view.xml

2
auth_brute_force/README.rst

@ -28,7 +28,7 @@ of the user can be wrong, and mainly in the following cases:
* if the Odoo server is behind an Apache / NGinx proxy without redirection,
all the request will be have the value '127.0.0.1' for the REMOTE_ADDR key;
* If some users are behind the same Internet Service Provider, if a user is
banned, all the other users will be banned to;
banned, all the other users will be banned too;
Configuration
-------------

18
auth_brute_force/models/res_banned_remote.py

@ -24,11 +24,11 @@ import urllib
import json
from openerp import models, fields, api
from openerp.tools.translate import _
class ResBannedRemote(models.Model):
_name = 'res.banned.remote'
_rec_name = 'remote'
_GEOLOCALISATION_URL = "http://ip-api.com/json/{}"
@ -37,13 +37,8 @@ class ResBannedRemote(models.Model):
return fields.Datetime.now()
# Column Section
name = fields.Char(
string='Name', compute='_compute_remote_description',
store=True, multi='remote_description', required=True)
description = fields.Text(
string='Description', compute='_compute_remote_description',
store=True, multi='remote_description')
string='Description', compute='_compute_description', store=True)
ban_date = fields.Datetime(
string='Ban Date', required=True, default=_default_ban_date)
@ -61,20 +56,13 @@ class ResBannedRemote(models.Model):
# Compute Section
@api.multi
@api.depends('remote')
def _compute_remote_description(self):
def _compute_description(self):
for item in self:
url = self._GEOLOCALISATION_URL.format(item.remote)
res = json.loads(urllib.urlopen(url).read())
item.description = ''
for k, v in res.iteritems():
item.description += '%s : %s\n' % (k, v)
if res.get('status', False) == 'success':
item.name = _("%s %s - %s %s (ISP: %s)" % (
res.get('country', ''), res.get('regionName', ''),
res.get('zip', ''), res.get('city'),
res.get('isp', '')))
else:
item.name = _('Unidentified Call from %s' % (item.remote))
@api.multi
def _compute_attempt_ids(self):

7
auth_brute_force/views/view.xml

@ -51,9 +51,8 @@
<field name="model">res.banned.remote</field>
<field name="arch" type="xml">
<tree colors="gray: active==False">
<field name="name" />
<field name="ban_date" />
<field name="remote" />
<field name="ban_date" />
<field name="active" invisible="1" />
</tree>
</field>
@ -65,10 +64,8 @@
<form>
<sheet>
<group>
<field name="name" />
<field name="ban_date" />
<field name="remote" />
<field name="ban_date" />
<field name="active" />
<field name="description" />
<field name="attempt_ids" />

Loading…
Cancel
Save