summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scripts/db_access/client_side_db.py33
-rwxr-xr-xscripts/profiling/spam.py44
2 files changed, 49 insertions, 28 deletions
diff --git a/scripts/db_access/client_side_db.py b/scripts/db_access/client_side_db.py
index f43b2f14..25eebfbe 100644
--- a/scripts/db_access/client_side_db.py
+++ b/scripts/db_access/client_side_db.py
@@ -106,18 +106,18 @@ def _get_soledad_info(username, provider, passphrase, basedir):
if choice != '':
host = hostnames[int(choice) - 1]
server_url = 'https://%s:%d/user-%s' % \
- (soledad_hosts[host]['hostname'], soledad_hosts[host]['port'],
- auth[2]['id'])
+ (soledad_hosts[host]['hostname'], soledad_hosts[host]['port'],
+ auth[2]['id'])
# get provider ca certificate
ca_cert = requests.get('https://%s/ca.crt' % provider, verify=False).text
cert_file = os.path.join(basedir, 'ca.crt')
with open(cert_file, 'w') as f:
- f.write(ca_cert)
+ f.write(ca_cert)
return auth[2]['id'], server_url, cert_file, auth[2]['token']
def _get_soledad_instance(uuid, passphrase, basedir, server_url, cert_file,
- token):
+ token):
# setup soledad info
logger.info('UUID is %s' % uuid)
logger.info('Server URL is %s' % server_url)
@@ -138,8 +138,8 @@ def _get_soledad_instance(uuid, passphrase, basedir, server_url, cert_file,
def _get_keymanager_instance(username, provider, soledad, token,
- ca_cert_path=None, api_uri=None, api_version=None, uid=None,
- gpgbinary=None):
+ ca_cert_path=None, api_uri=None, api_version=None,
+ uid=None, gpgbinary=None):
return KeyManager(
"{username}@{provider}".format(username=username, provider=provider),
"http://uri",
@@ -173,6 +173,9 @@ def _parse_args():
'--sync', '-s', action='store_true',
help='synchronize with the server replica')
parser.add_argument(
+ '--repeat-sync', '-r', action='store_true',
+ help='repeat synchronization until no new data is received')
+ parser.add_argument(
'--export-public-key', help="export the public key to a file")
parser.add_argument(
'--export-private-key', help="export the private key to a file")
@@ -209,7 +212,8 @@ def _get_basedir(args):
@inlineCallbacks
def _export_key(args, km, fname, private=False):
address = args.username + "@" + args.provider
- pkey = yield km.get_key(address, OpenPGPKey, private=private, fetch_remote=False)
+ pkey = yield km.get_key(
+ address, OpenPGPKey, private=private, fetch_remote=False)
with open(args.export_private_key, "w") as f:
f.write(pkey.key_data)
@@ -240,7 +244,8 @@ def _main(soledad, km, args):
if args.create_docs:
for i in xrange(args.create_docs):
t = time.time()
- logger.debug("Creating doc %d/%d..." % (i + 1, args.create_docs))
+ logger.debug(
+ "Creating doc %d/%d..." % (i + 1, args.create_docs))
content = {
'datetime': time.strftime(
"%Y-%m-%d %H:%M:%S", time.gmtime(t)),
@@ -251,6 +256,12 @@ def _main(soledad, km, args):
yield soledad.create_doc(content)
if args.sync:
yield soledad.sync()
+ if args.repeat_sync:
+ old_gen = 0
+ new_gen = yield soledad.sync()
+ while old_gen != new_gen:
+ old_gen = new_gen
+ new_gen = yield soledad.sync()
if args.get_all_docs:
yield _get_all_docs(soledad)
if args.export_private_key:
@@ -258,7 +269,8 @@ def _main(soledad, km, args):
if args.export_public_key:
yield _export_key(args, km, args.expoert_public_key, private=False)
if args.export_incoming_messages:
- yield _export_incoming_messages(soledad, args.export_incoming_messages)
+ yield _export_incoming_messages(
+ soledad, args.export_incoming_messages)
except Exception as e:
logger.error(e)
finally:
@@ -274,7 +286,8 @@ if __name__ == '__main__':
if not args.use_auth_data:
# get auth data from server
uuid, server_url, cert_file, token = \
- _get_soledad_info(args.username, args.provider, passphrase, basedir)
+ _get_soledad_info(
+ args.username, args.provider, passphrase, basedir)
else:
# load auth data from file
with open(args.use_auth_data) as f:
diff --git a/scripts/profiling/spam.py b/scripts/profiling/spam.py
index 3f8d5207..76a5ed97 100755
--- a/scripts/profiling/spam.py
+++ b/scripts/profiling/spam.py
@@ -7,12 +7,12 @@ import string
import smtplib
import threading
import logging
+import dns.resolver
from argparse import ArgumentParser
-SMTP_HOST = 'chipmonk.cdev.bitmask.net'
-SMTP_PORT = 465
+SMTP_DEFAULT_PORT = 465
NUMBER_OF_THREADS = 20
@@ -20,7 +20,7 @@ logger = logging.getLogger(__name__)
LOG_FORMAT = '%(asctime)s %(message)s'
-def _send_email(host, port, subject, to_addr, from_addr, body_text):
+def _send_email(server, port, subject, to_addr, from_addr, body_text):
"""
Send an email
"""
@@ -32,12 +32,12 @@ def _send_email(host, port, subject, to_addr, from_addr, body_text):
body_text
), "\r\n")
logger.debug("setting up smtp...")
- server = smtplib.SMTP_SSL(host, port)
+ smtp = smtplib.SMTP_SSL(server, port)
logger.info(
"sending message: (%s, %s, %s, %i)"
- % (from_addr, to_addr, host, port))
- server.sendmail(from_addr, [to_addr], body)
- server.quit()
+ % (from_addr, to_addr, server, port))
+ smtp.sendmail(from_addr, [to_addr], body)
+ smtp.quit()
def _parse_args():
@@ -49,10 +49,10 @@ def _parse_args():
'number_of_messages', type=int,
help='The amount of messages email address to spam')
parser.add_argument(
- '--server', '-s', default=SMTP_HOST,
+ '--server', '-s',
help='The SMTP server to use')
parser.add_argument(
- '--port', '-p', default=SMTP_PORT,
+ '--port', '-p', default=SMTP_DEFAULT_PORT,
help='The SMTP port to use')
parser.add_argument(
'--threads', '-t', default=NUMBER_OF_THREADS,
@@ -65,11 +65,11 @@ def _parse_args():
class EmailSenderThread(threading.Thread):
- def __init__(self, host, port, subject, to_addr, from_addr, body_text,
- finished_fun):
+ def __init__(self, server, port, subject, to_addr, from_addr, body_text,
+ finished_fun):
threading.Thread.__init__(self)
logger.debug("initilizing thread...")
- self._host = host
+ self._server = server
self._port = port
self._subject = subject
self._to_addr = to_addr
@@ -80,16 +80,16 @@ class EmailSenderThread(threading.Thread):
def run(self):
logger.debug("running thread...")
_send_email(
- self._host, self._port, self._subject, self._to_addr,
+ self._server, self._port, self._subject, self._to_addr,
self._from_addr, self._body_text)
self._finished_fun()
-def _launch_email_thread(host, port, subject, to_addr, from_addr, body_text,
- finished_fun):
+def _launch_email_thread(server, port, subject, to_addr, from_addr, body_text,
+ finished_fun):
logger.debug("will launch email thread...")
thread = EmailSenderThread(
- host, port, subject, to_addr, from_addr, body_text, finished_fun)
+ server, port, subject, to_addr, from_addr, body_text, finished_fun)
thread.start()
return thread
@@ -107,7 +107,7 @@ class FinishedThreads(object):
def _send_messages(args):
- host = args.server
+ server = args.server
port = args.port
subject = "Message from Soledad script"
to_addr = args.target_address
@@ -121,6 +121,14 @@ def _send_messages(args):
level = logging.INFO
logging.basicConfig(format=LOG_FORMAT, level=level)
+ # get MX configuration
+ if not server:
+ logger.info("Resolving MX server...")
+ _, domain = to_addr.split("@", 1)
+ result = dns.resolver.query(domain, "MX")
+ server = result[0].exchange.to_text()
+ logger.info("MX server is: %s" % server)
+
semaphore = threading.Semaphore(args.threads)
threads = []
finished_threads = FinishedThreads()
@@ -133,7 +141,7 @@ def _send_messages(args):
semaphore.acquire()
threads.append(
_launch_email_thread(
- host, port, subject, to_addr, from_addr, body_text,
+ server, port, subject, to_addr, from_addr, body_text,
_finished_fun))
for t in threads: