Exemple #1
0
def send_reset():
    if request.method == "GET":
        return render_template("reset.html")
    else:
        uname = request.form['username']
        if not utils.user_exists(uname):
            return render_template("reset.html",message="That user does not exist.")
        
        pword = utils.get_password(uname)
        #sends the hash to the email                                           
        d = utils.reset_password(uname, pword)
        email = d['email']
        new_pass = d['pw']
        myemail = '*****@*****.**'
        text = "Your username is " + uname + ". Type this for your password " + new_pass
        #send email
        s = smtplib.SMTP("smtp.gmail.com", 587)
        s.ehlo()
        s.starttls()
        s.ehlo()
        s.login(myemail,"thisisapass")
        msg = 'To: '+email+'\n' +'From: '+myemail+'\n'+'Subject: reset password \n' + '\n' + text
        s.sendmail(myemail,email,msg)
        s.close()
        #update password
        utils.temp_password(uname, new_pass)
        return redirect(url_for("fix"))
Exemple #2
0
    def make_user(self, first_name, last_name, username, personal_email, orgunit_path="OU=ECA,OU=ECA Users", **kwargs):

        password = get_password()
        full_name = "%s %s" % (first_name, last_name)
        target_ou = "%s,DC=ECA,DC=local" % orgunit_path
        principal_name = "*****@*****.**" % username
        extra_args = ""
        for arg, value in kwargs.iteritems():
            extra_args += "-%s '%s' " % (arg, value)

        ps = self.make_user_script % (
            password,
            full_name,
            first_name,
            last_name,
            username,
            target_ou,
            principal_name,
            extra_args,
        )
        r = self.session.run_ps(ps)

        if not r.status_code == 0:
            raise Exception("There was an error creating user %s: \n %s" % (username, r.std_err))

        t = _get_template("templates/server_account_creation.txt")
        message = t.render(first_name=first_name, username=username, password=password)
        message_id = self.gapps.send_message(
            "Chuck Wilson <*****@*****.**>", personal_email, "ECA Server Account Creation", message
        )
        if message_id:
            print ("User %s created in OU %s" % (username, orgunit_path))
            return True
Exemple #3
0
    def turnover_user(self, first_name, last_name, email, personal_email):
        # get password from random.org
        password = get_password()
        password_hash = sha1(password)

        self.set_service('admin', 'directory_v1')
        name = { 'familyName': last_name, 'givenName': first_name }
        user = {
            'name': name,
            'password': password_hash.hexdigest(),
            'hashFunction': 'SHA-1',
            'changePasswordAtNextLogin': True,
        }
        results = self.service.users().update(userKey=email, body=user).execute()

        # Send email to user with their username/password
        t = _get_template('templates/email_turnover.txt')
        message = t.render(
                first_name=first_name,
                email=email,
                password=password
        )
        message_id = self.send_message(
                'Chuck Wilson <*****@*****.**>',
                personal_email,
                'ECA Email Account Details',
                message
        )
        if message_id:
            print('Sent welcome email with reset password to %s (%s %s) for account %s' % (personal_email, first_name, last_name, email))
            return True
Exemple #4
0
    def reset_password(self, first_name, email, personal_email):
        # get password from random.org
        password = get_password()
        password_hash = sha1(password)

        self.set_service('admin', 'directory_v1')
        user = {
            'password': password_hash.hexdigest(),
            'hashFunction': 'SHA-1',
            'changePasswordAtNextLogin': True,
        }
        results = self.service.users().update(userKey=email, body=user).execute()
        print(results)

        # Send email to user with their username/password
        t = _get_template('templates/email_password_reset.txt')
        message = t.render(
                first_name=first_name,
                email=email,
                password=password
        )
        message_id = self.send_message(
                'Chuck Wilson <*****@*****.**>',
                personal_email,
                'ECA Email Password Reset',
                message
        )
        if message_id:
            print('Sent password reset email for %s to %s' % (email,personal_email))
            return True
Exemple #5
0
 def _reset_password_ps(self, username):
     password = get_password()
     d = {"username": username, "password": password}
     ps = self.reset_pw_script % d
     r = self.session.run_ps(ps)
     if r.status_code != 0:
         raise Exception("Unable to reset password for %(username)s" % username)
     return password
Exemple #6
0
    def _save_quit(self, button):
        """Writes the game data to a file and exits."""
        del button

        save = open(save_file, 'w')
        save_string = ""
        save_string += str(self.score) + '\n'
        for i in range(self.grid_size):
            for j in range(self.grid_size):
                save_string += str(self.grid[i][j]) + '\n'

        cipher_text = sc.encrypt(get_password(), save_string)
        save.write(cipher_text)
        save.close()

        Gtk.main_quit()
Exemple #7
0
    def get_db_url(self):

        if self.database_type == 'postgresql':
            self.drivername = 'postgresql+psycopg2'
        else:
            sys.exit('Only postgresql is supported at the moment')

        if not (self.database and self.host and self.username):
            raise ValueError('database, host, port and username must be set.')

        dburl = engine.url.URL(self.drivername, self.username, self.password,
                               self.host, self.port, self.database)

        if self.password is PASSWORD_NOT_SET:
            pass  # No password
        elif self.password is None:
            dburl.password = get_password('Database password: ')
        else:
            dburl.password = self.password
        return dburl
Exemple #8
0
    def make_user(self, first_name, last_name, username, personal_email,
                  orgunit_path='/'):
        # get password from random.org
        password = get_password()
        password_hash = sha1(password)

        # Add the user to the google domain
        self.set_service('admin', 'directory_v1')
        name = { 'familyName': last_name, 'givenName': first_name }
        email = '*****@*****.**' % username
        user = {
            'name': name,
            'primaryEmail': email,
            'password': password_hash.hexdigest(),
            'hashFunction': 'SHA-1',
            'changePasswordAtNextLogin': True,
            'orgUnitPath': orgunit_path
            }
        try:
            results = self.service.users().insert(body=user).execute()
        except errors.HttpError as e:
            print("Unable to create user %s" % username)
            raise e

        # Send email to user with their username/password
        t = _get_template('templates/email_account_creation.txt')
        message = t.render(
                first_name=first_name,
                username=username,
                password=password
        )
        message_id = self.send_message(
                'Chuck Wilson <*****@*****.**>',
                personal_email,
                'ECA Email Creation',
                message
        )
        if message_id:
            print('Successfully created user %s' % username)
            return True
Exemple #9
0
    def _load_save(self):
        """Loads the saved game file."""
        try:
            load = open(save_file, 'r')
            cipher_text = load.read()
            load_string = sc.decrypt(get_password(), cipher_text)
            load_values = load_string.splitlines()
            if len(load_values) != self.grid_size*self.grid_size + 1:
                raise ValueError
            self.score = int(load_values[0])
            for i in range(self.grid_size):
                for j in range(self.grid_size):
                    self.grid[i][j] = int(load_values[i*self.grid_size + j + 1])
                    if not is_power(self.grid[i][j], 2) and self.grid[i][j] != 0:
                        raise ValueError
        except sc.DecryptionException:
            print("Save file could not be read. Starting new game")
            self.new_game()
        except ValueError:
            print("Save file format corrupted. Starting new game")
            self.new_game()

        os.remove(save_file)
        self.win.queue_draw()
Exemple #10
0
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.selector import HtmlXPathSelector
import requests

from mongodb import issues


from utils import parse_gnats_item, get_password

urlquote_safe = "%/:=?&"

user, password = get_password()

host = 'http://api.jcnrd.us'
api_monitored_members = host + '/directory/gnats-monitored-members.json'


responsible_base = 'https://gnats.juniper.net/web/default/do-query?adv=1&ignoreclosed=on&expr=%28%28%28arrival-date' \
                   + '+%3E+%222010-01-01%22%29+%26+%28%28dev-owner+%3D%3D+%22tchen%22%29+%7C+%28responsible+' \
                   + '%3D%3D+%22tchen%22%29%29%29+%26+%28last-modified+%3E+%221+years+ago%22%29%29+%26+%28' \
                   + 'builtinfield%3AState%5Btype%5D+%21%3D+%22closed%22%29&queryname=tchen%27s%2B' \
                   + 'responsible%2BPRs&recentPRs=lm2yr&colType=noscoped&csv=0&columns=synopsis%2Creported-in' \
                   + '%2Csubmitter-id%2Ccategory%2Cproblem-level%2Cblocker%2Cplanned-release%2Cstate%2Cresponsible' \
                   + '%2Coriginator%2Carrival-date%2Cbranch%2Ccustomer%2Ccustomer-escalation-owner%2Cdev-owner' \
                   + '%2Csystest-owner%2Clast-modified&op=%26'
pr_base = 'https://gnats.juniper.net/web/default/%s'


def format_url(uid):
    return responsible_base.replace('tchen', uid)
Exemple #11
0
# to prevent unknown host error
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

# connect to remote server
print('connecting...\n')
client.connect(hostname=utils.ADDRESS,
               port=utils.PORT,
               username=USERNAME,
               password=PASSWORD)

print('ls -la')
stdin, stdout, stderr = client.exec_command('ls -la')
utils.print_stdout(stdout)

# read the password
print('cat readme')
stdin, stdout, stderr = client.exec_command('cat readme')

# save the output from stdout to be list of strings
# if the original stdout is simply passed to the next two functions,
# the last function will get the input where the pointer is already at the end of the file
# thus, it won't print out anything
stdout = stdout.readlines()
password = utils.get_password(stdout)
utils.print_stdout(stdout)

# bandit1 password: boJ9jbbUNNfktd78OOpsqOltutMc3MY1
print('bandit1 password: ' + password)

client.close()
Exemple #12
0
def main():
    config = get_config()
    db_type = 'mariadb'
    db_port = config.get('db_port', 3306)
    db_host = config.get('db_host')
    site_name = os.environ.get("SITE_NAME", 'site1.localhost')
    db_root_username = os.environ.get("DB_ROOT_USER", 'root')
    mariadb_root_password = get_password("MYSQL_ROOT_PASSWORD", 'admin')
    postgres_root_password = get_password("POSTGRES_PASSWORD")
    db_root_password = mariadb_root_password

    if postgres_root_password:
        db_type = 'postgres'
        db_host = os.environ.get("POSTGRES_HOST")
        db_port = 5432
        db_root_password = postgres_root_password
        if not db_host:
            db_host = config.get('db_host')
            print('Environment variable POSTGRES_HOST not found.')
            print('Using db_host from common_site_config.json')

        sites_path = os.getcwd()
        common_site_config_path = os.path.join(sites_path,
                                               COMMON_SITE_CONFIG_FILE)
        update_site_config("root_login",
                           db_root_username,
                           validate=False,
                           site_config_path=common_site_config_path)
        update_site_config("root_password",
                           db_root_password,
                           validate=False,
                           site_config_path=common_site_config_path)

    force = True if os.environ.get("FORCE", None) else False
    install_apps = os.environ.get("INSTALL_APPS", None)
    install_apps = install_apps.split(',') if install_apps else []
    frappe.init(site_name, new_site=True)

    _new_site(
        None,
        site_name,
        mariadb_root_username=db_root_username,
        mariadb_root_password=db_root_password,
        admin_password=get_password("ADMIN_PASSWORD", 'admin'),
        verbose=True,
        install_apps=install_apps,
        source_sql=None,
        force=force,
        db_type=db_type,
        reinstall=False,
        db_host=db_host,
        db_port=db_port,
    )

    if db_type == "mariadb":
        site_config = get_site_config(site_name)
        db_name = site_config.get('db_name')
        db_password = site_config.get('db_password')

        mysql_command = [
            "mysql", f"-h{db_host}", f"-u{db_root_username}",
            f"-p{mariadb_root_password}", "-e"
        ]

        # Drop User if exists
        print("Drop user if exists")
        command = mysql_command + [
            f"DROP USER IF EXISTS '{db_name}'; FLUSH PRIVILEGES;"
        ]
        run_command(command)

        # Grant permission to database and set password
        grant_privileges = "ALL PRIVILEGES"

        # for Amazon RDS
        if config.get(RDS_DB) or site_config.get(RDS_DB):
            grant_privileges = RDS_PRIVILEGES

        print("Grant privileges")
        command = mysql_command + [
            f"GRANT {grant_privileges} ON `{db_name}`.* TO '{db_name}'@'%' IDENTIFIED BY '{db_password}'; FLUSH PRIVILEGES;"
        ]
        run_command(command)

    if frappe.redis_server:
        frappe.redis_server.connection_pool.disconnect()

    exit(0)
Exemple #13
0
def main():
    config = get_config()
    db_type = 'mariadb'
    db_port = config.get('db_port', 3306)
    db_host = config.get('db_host')
    site_name = os.environ.get("SITE_NAME", 'site1.localhost')
    mariadb_root_username = os.environ.get("DB_ROOT_USER", 'root')
    mariadb_root_password = get_password("MYSQL_ROOT_PASSWORD", 'admin')
    postgres_root_password = get_password("POSTGRES_PASSWORD")

    if postgres_root_password:
        db_type = 'postgres'
        db_host = os.environ.get("POSTGRES_HOST")
        db_port = 5432
        if not db_host:
            db_host = config.get('db_host')
            print('Environment variable POSTGRES_HOST not found.')
            print('Using db_host from common_site_config.json')

        sites_path = os.getcwd()
        common_site_config_path = os.path.join(sites_path,
                                               COMMON_SITE_CONFIG_FILE)
        update_site_config("root_login",
                           mariadb_root_username,
                           validate=False,
                           site_config_path=common_site_config_path)
        update_site_config("root_password",
                           postgres_root_password,
                           validate=False,
                           site_config_path=common_site_config_path)

    force = True if os.environ.get("FORCE", None) else False
    install_apps = os.environ.get("INSTALL_APPS", None)
    install_apps = install_apps.split(',') if install_apps else []
    frappe.init(site_name, new_site=True)

    if semantic_version.Version(frappe.__version__).major > 11:
        _new_site(
            None,
            site_name,
            mariadb_root_username=mariadb_root_username,
            mariadb_root_password=mariadb_root_password,
            admin_password=get_password("ADMIN_PASSWORD", 'admin'),
            verbose=True,
            install_apps=install_apps,
            source_sql=None,
            force=force,
            db_type=db_type,
            reinstall=False,
            db_host=db_host,
            db_port=db_port,
        )
    else:
        _new_site(
            None,
            site_name,
            mariadb_root_username=mariadb_root_username,
            mariadb_root_password=mariadb_root_password,
            admin_password=get_password("ADMIN_PASSWORD", 'admin'),
            verbose=True,
            install_apps=install_apps,
            source_sql=None,
            force=force,
            reinstall=False,
        )

    if db_type == "mariadb":
        site_config = get_site_config(site_name)
        db_name = site_config.get('db_name')
        db_password = site_config.get('db_password')

        mysql_command = [
            "mysql", f"-h{db_host}", f"-u{mariadb_root_username}",
            f"-p{mariadb_root_password}", "-e"
        ]

        # Drop User if exists
        command = mysql_command + [
            f"DROP USER IF EXISTS '{db_name}'@'%'; FLUSH PRIVILEGES;"
        ]
        run_command(command)

        # update User's host to '%' required to connect from any container
        command = mysql_command + [
            f"UPDATE mysql.user SET Host = '%' where User = '******'; FLUSH PRIVILEGES;"
        ]
        run_command(command)

        # Set db password
        command = mysql_command + [
            f"ALTER USER '{db_name}'@'%' IDENTIFIED BY '{db_password}'; FLUSH PRIVILEGES;"
        ]
        run_command(command)

        # Grant permission to database
        command = mysql_command + [
            f"GRANT ALL PRIVILEGES ON `{db_name}`.* TO '{db_name}'@'%'; FLUSH PRIVILEGES;"
        ]
        run_command(command)

    if frappe.redis_server:
        frappe.redis_server.connection_pool.disconnect()

    exit(0)
Exemple #14
0
    f'cd /tmp/{FOLDERNAME}/repo && echo "May I come in?" | tee key.txt')
utils.print_stdout(stdout)

print(
    f'cd /tmp/{FOLDERNAME}/repo && git add -f key.txt && git commit -m "added key.txt"'
)
_, stdout, _ = client.exec_command(
    f'cd /tmp/{FOLDERNAME}/repo && git add -f key.txt && git commit -m "added key.txt"'
)
utils.print_stdout(stdout)

print(f'cd /tmp/{FOLDERNAME}/repo && git push')
stdin, stdout, _ = client.exec_command(
    f'cd /tmp/{FOLDERNAME}/repo && git push', get_pty=True)
time.sleep(1)
stdin.write('yes\n')
time.sleep(1)
stdin.write(f'{PASSWORD}\n')
stdin.flush()
stdout = stdout.readlines()
utils.print_stdout(stdout)
password = utils.get_password(stdout[-7].split()[-1])

# bandit32 password: 56a9bf19c63d650ce78e6ec0354ee45e
print(f'bandit32 password: {password}\n')

# cleanup
print('deleting temporary directory...')
client.exec_command(f'rm -rf /tmp/{FOLDERNAME}')

client.close()
Exemple #15
0
    failed_file = []
    for data_file in list_files_in_path(local_path):
        target_file = os.path.join(data_path, data_file.lstrip(local_path))
        hash_file = os.path.join(hash_sum_path, data_file.lstrip(local_path))
        folder = os.path.dirname(target_file)
        os.makedirs(folder, exist_ok=True)
        try:
            sha256sum = get_file_sha256sum(data_file)
            old_sha256sum = None
            if os.path.exists(hash_file):
                with open(hash_file, "r") as f:
                    old_sha256sum = f.read()

            if str(old_sha256sum) != str(sha256sum):
                start_time = time.time()
                ret = enrypt_file(data_file, target_file, get_password())
                end_time = time.time()
                if ret.exit == 0:
                    print("Encrypt %s ok.... %ss" %
                          (data_file, end_time - start_time))
                    os.remove(data_file)
                else:
                    failed_file.append(data_file)
                    print("Encrypt %s failed, output is: %s" % ret.output)
            else:
                print("File %s not changed, skip..." % data_file)
                os.remove(data_file)

        except Exception as e:
            print("Encrypt %s failed, exception: %s" % (data_file, e))
            failed_file.append(data_file)