You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

103 lines
2.7 KiB

"""
Skript för att söka i FB-läckan.
"""
import re
import paramiko
import arangodb
from getpass import getpass
from sshtunnel import open_tunnel
from termcolor import cprint
def search(db, attribute, value):
"""
Search for attribute in db.
Returns list of matching documents.
"""
if '%' in value or '_' in value:
match = 'like'
else:
match = '=='
cursor = db.aql.execute(
f"""
FOR doc IN leak
FILTER doc.@attribute {match} @value
RETURN doc
""",
bind_vars={"attribute": attribute, "value": value},
)
return [doc for doc in cursor]
pwd_key = getpass(f"Password key: ")
with open_tunnel(
("studio-garda.asuscomm.com", 2200),
ssh_username="Lasse",
ssh_pkey=paramiko.RSAKey.from_private_key_file(
"/Users/Lasse/.ssh/id_rsa", password=pwd_key
),
ssh_private_key_password=pwd_key,
remote_bind_address=("127.0.0.1", 8529),
) as server:
# server.start()
port_arango = server.local_bind_port
db = arangodb.arango_connect(
"gruel-ADOBE-foolish-winy-borax",
username="Leak",
host_arango="http://127.0.0.1",
port_arango=port_arango,
)
cprint("\n\nVad vill du söka efter?", attrs=['bold'])
print("1 - Telefonnummer")
print("2 - Facebook-ID")
print('3 - Namn')
print("4 - Arbete")
print('5 - Bostadsort')
print("6 - Födelseort")
print("7 - Epost")
# Få input för attribut
attribute = input("\n>>> ")
attributes = {
"1": ("telefonnummer", "phone"),
"2": ("Facebook-ID", "_key"),
"3": ("namn", "full_name"),
"4": ("arbete", "work"),
"5": ('bostadsort', "lives_in"),
"6": ('födelseort', 'from'),
"7": ('epost', 'email')
}
# Bestäm n- eller t-form och få input för värde.
if attribute in ['5', '6', '7']:
genus = 'n'
else:
genus = 't'
cprint(f"\nVilke{genus} {attributes[attribute][0]}? ", attrs=['bold'])
cprint('Använd % för att ersätta flera okända tecken, _ för att ersätta ett.', attrs=['dark'])
value = input('\n>>> ')
if attribute == '1': # telefonnummer
value = ''.join(re.findall(r'\d+', value))
if value[0] == '0':
value = f'46{value[1:]}'
elif attribute == '3': # namn
value = value.upper()
# Sök i databasen.
result = search(db, attributes[attribute][1], value)
# Presentera reultaten #TODO hur vill man få dem? Spara ner?
for i in result:
print('\n', i['full_name'])
for key, value in i.items():
print(f'{key}: {value}')
print(f'https://facebook.com/{i["_key"]}')
print(f'\nAntal träffar: {len(result)}\n')