mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-27 00:07:16 +00:00
chg: [BankAccount] regex
This commit is contained in:
parent
57b631233b
commit
153f9f38cc
1 changed files with 25 additions and 11 deletions
|
@ -2,12 +2,12 @@
|
||||||
# -*-coding:UTF-8 -*
|
# -*-coding:UTF-8 -*
|
||||||
|
|
||||||
"""
|
"""
|
||||||
The ApiKey Module
|
The BankAccount Module
|
||||||
======================
|
======================
|
||||||
|
|
||||||
This module is consuming the Redis-list created by the Categ module.
|
This module is consuming the Redis-list created by the Categ module.
|
||||||
|
|
||||||
It apply API_key regexes on paste content and warn if above a threshold.
|
It apply BankAccount regexes on paste content and warn if above a threshold.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ import redis
|
||||||
import time
|
import time
|
||||||
import re
|
import re
|
||||||
import string
|
import string
|
||||||
|
from itertools import chain
|
||||||
|
|
||||||
from packages import Paste
|
from packages import Paste
|
||||||
from pubsublogger import publisher
|
from pubsublogger import publisher
|
||||||
|
@ -31,15 +32,19 @@ def timeout_handler(signum, frame):
|
||||||
|
|
||||||
signal.signal(signal.SIGALRM, timeout_handler)
|
signal.signal(signal.SIGALRM, timeout_handler)
|
||||||
|
|
||||||
LETTERS_IBAN = {ord(d): str(i) for i, d in enumerate(string.digits + string.ascii_uppercase)}
|
#LETTERS_IBAN = {ord(d): str(i) for i, d in enumerate(string.digits + string.ascii_uppercase)}
|
||||||
|
_LETTERS_IBAN = chain(enumerate(string.digits + string.ascii_uppercase),
|
||||||
|
enumerate(string.ascii_lowercase, 10))
|
||||||
|
LETTERS_IBAN = {ord(d): str(i) for i, d in _LETTERS_IBAN}
|
||||||
|
|
||||||
def iban_number(iban):
|
def iban_number(iban):
|
||||||
return (iban[4:] + iban[:4].translate(LETTERS_IBAN))
|
return (iban[4:] + iban[:4]).translate(LETTERS_IBAN)
|
||||||
|
|
||||||
def is_valid_iban(iban):
|
def is_valid_iban(iban):
|
||||||
iban = iban.replace(' ', '')
|
|
||||||
iban_numb = iban_number(iban)
|
iban_numb = iban_number(iban)
|
||||||
iban_numb_check = iban_number(iban[:2] + '00' + iban[4:])
|
iban_numb_check = iban_number(iban[:2] + '00' + iban[4:])
|
||||||
|
print(iban_numb)
|
||||||
|
print(iban_numb_check)
|
||||||
check_digit = '{:0>2}'.format(98 - (int(iban_numb_check) % 97))
|
check_digit = '{:0>2}'.format(98 - (int(iban_numb_check) % 97))
|
||||||
if check_digit == iban[2:4] and int(iban_numb) % 97 == 1:
|
if check_digit == iban[2:4] and int(iban_numb) % 97 == 1:
|
||||||
# valid iban
|
# valid iban
|
||||||
|
@ -51,10 +56,16 @@ def is_valid_iban(iban):
|
||||||
def check_all_iban(l_iban, paste, filename):
|
def check_all_iban(l_iban, paste, filename):
|
||||||
nb_valid_iban = 0
|
nb_valid_iban = 0
|
||||||
for iban in l_iban:
|
for iban in l_iban:
|
||||||
|
iban = iban[0]+iban[1]+iban[2]
|
||||||
|
iban = ''.join(e for e in iban if e.isalnum())
|
||||||
|
#iban = iban.upper()
|
||||||
|
res = iban_regex_verify.findall(iban)
|
||||||
|
if res:
|
||||||
print('checking '+iban)
|
print('checking '+iban)
|
||||||
if is_valid_iban(iban):
|
if is_valid_iban(iban):
|
||||||
print('------')
|
print('------')
|
||||||
nb_valid_iban = nb_valid_iban + 1
|
nb_valid_iban = nb_valid_iban + 1
|
||||||
|
|
||||||
if(nb_valid_iban > 0):
|
if(nb_valid_iban > 0):
|
||||||
to_print = 'Iban;{};{};{};'.format(paste.p_source, paste.p_date, paste.p_name)
|
to_print = 'Iban;{};{};{};'.format(paste.p_source, paste.p_date, paste.p_name)
|
||||||
publisher.warning('{}Checked found {} IBAN;{}'.format(
|
publisher.warning('{}Checked found {} IBAN;{}'.format(
|
||||||
|
@ -78,7 +89,10 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
message = p.get_from_set()
|
message = p.get_from_set()
|
||||||
|
|
||||||
iban_regex = re.compile(r'\b[A-Za-z]{2}[0-9]{2}(?:[ ]?[0-9]{4}){4}(?:[ ]?[0-9]{1,2})?\b')
|
#iban_regex = re.compile(r'\b[A-Za-z]{2}[0-9]{2}(?:[ ]?[0-9]{4}){4}(?:[ ]?[0-9]{1,2})?\b')
|
||||||
|
iban_regex = re.compile(r'\b([A-Za-z]{2}[ \-]?[0-9]{2})(?=(?:[ \-]?[A-Za-z0-9]){9,30})((?:[ \-]?[A-Za-z0-9]{3,5}){2,6})([ \-]?[A-Za-z0-9]{1,3})\b')
|
||||||
|
iban_regex_verify = re.compile(r'^([A-Z]{2})([0-9]{2})([A-Z0-9]{9,30})$')
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
|
@ -103,5 +117,5 @@ if __name__ == "__main__":
|
||||||
check_all_iban(l_iban, paste, filename)
|
check_all_iban(l_iban, paste, filename)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
publisher.debug("Script ApiKey is Idling 10s")
|
publisher.debug("Script BankAccount is Idling 10s")
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
Loading…
Reference in a new issue