Browse Source
[MIG] auth_brute_force: Backport from v10
[MIG] auth_brute_force: Backport from v10
Odoo v9 auth methods usually violate both old and new api; they just only work in old api, so I had to adapt some tests to use it instead. Normal backport outside of that.pull/1255/head
Jairo Llopis
7 years ago
6 changed files with 26 additions and 77 deletions
-
2auth_brute_force/README.rst
-
2auth_brute_force/__openerp__.py
-
50auth_brute_force/migrations/10.0.2.0.0/pre-migrate.py
-
2auth_brute_force/models/res_authentication_attempt.py
-
30auth_brute_force/models/res_users.py
-
17auth_brute_force/tests/test_brute_force.py
@ -1,50 +0,0 @@ |
|||||
# -*- coding: utf-8 -*- |
|
||||
# Copyright 2018 Tecnativa - Jairo Llopis |
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
|
||||
|
|
||||
from psycopg2 import IntegrityError |
|
||||
|
|
||||
|
|
||||
def migrate(cr, version): |
|
||||
# Fix typo across DB |
|
||||
cr.execute( |
|
||||
""" UPDATE res_authentication_attempt |
|
||||
SET result = 'successful' |
|
||||
WHERE result = 'successfull'""", |
|
||||
) |
|
||||
# Store whitelist IPs in new format |
|
||||
cr.execute( |
|
||||
""" SELECT remote |
|
||||
FROM res_banned_remote |
|
||||
WHERE active IS FALSE""", |
|
||||
) |
|
||||
remotes = {record[0] for record in cr.fetchall()} |
|
||||
try: |
|
||||
with cr.savepoint(): |
|
||||
cr.execute( |
|
||||
"INSERT INTO ir_config_parameter (key, value) VALUES (%s, %s)", |
|
||||
( |
|
||||
"auth_brute_force.whitelist_remotes", |
|
||||
",".join(remotes), |
|
||||
), |
|
||||
) |
|
||||
except IntegrityError: |
|
||||
# Parameter already exists |
|
||||
cr.execute( |
|
||||
"SELECT value FROM ir_config_parameter WHERE key = %s", |
|
||||
("auth_brute_force.whitelist_remotes",) |
|
||||
) |
|
||||
current = set(cr.fetchall()[0][0].split(",")) |
|
||||
cr.execute( |
|
||||
"UPDATE ir_config_parameter SET value = %s WHERE key = %s", |
|
||||
(",".join(current | remotes), |
|
||||
"auth_brute_force.whitelist_remotes"), |
|
||||
) |
|
||||
# Update the configured IP limit parameter |
|
||||
cr.execute( |
|
||||
"UPDATE ir_config_parameter SET key = %s WHERE key = %s", |
|
||||
( |
|
||||
"auth_brute_force.whitelist_remotes", |
|
||||
"auth_brute_force.max_by_ip", |
|
||||
) |
|
||||
) |
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue