def send_email():
    """send email alert"""
    logger.info('| Sending email')
    recipient = credentials.get_recipient_email()
    subject = 'Google Cloud Security Risks Found!'
    body = 'Please log into your Google Account and review Security Logs.\n\n\nThank you,\nSecurity'

    # Gmail Sign In
    gmail_sender = credentials.get_sender_email()
    gmail_passwd = credentials.get_password()
    try:
        server = smtplib.SMTP('smtp.gmail.com', 587)
        server.ehlo()
        server.starttls()
        server.login(gmail_sender, gmail_passwd)
    except smtplib.SMTPAuthenticationError:
        logger.error('| Bad credentials.  Exiting...')
        exit(1)
    except Exception as e:
        logger.error('| Gmail unknown error.  Exiting...')
        exit(1)

    BODY = '\r\n'.join([
        'To: %s' % recipient,
        'From: %s' % gmail_sender,
        'Subject: %s' % subject, '', body
    ])

    try:
        server.sendmail(gmail_sender, [recipient], BODY)
        logger.info('| Email sent')
    except Exception:
        logger.error('| Error sending mail')

    server.quit()
Exemple #2
0
def new_saved_session(_pickle_file):
    print "No pickle file, generating new session"
    with open(_pickle_file, 'wb') as output:
        s = myuscauth.usc_auth(credentials.get_username(),
                               credentials.get_password())
        pickle.dump(s, output, pickle.HIGHEST_PROTOCOL)
        print "Logged In"
def send_email(body):
    """send email alert"""
    logging.info('Sending email')
    recipient = credentials.get_recipient_email()
    subject = 'Security Alert for Google Cloud Storage'

    # gmail sign-in
    gmail_sender = credentials.get_sender_email()
    gmail_passwd = credentials.get_password()
    try:
        server = smtplib.SMTP('smtp.gmail.com', 587)
        server.ehlo()
        server.starttls()
        server.login(gmail_sender, gmail_passwd)
    except smtplib.SMTPAuthenticationError:
        logging.error('Bad credentials.  Exiting...')
        exit(1)
    except Exception as err:
        logging.error('Gmail failure: {0}'.format(err))
        exit(1)

    body = '\r\n'.join([
        'To: %s' % recipient,
        'From: %s' % gmail_sender,
        'Subject: %s' % subject, '', body
    ])

    try:
        server.sendmail(gmail_sender, [recipient], body)
        logging.info('Email sent!')
    except Exception as err:
        logging.error('Sending mail failure: {0}'.format(err))

    server.quit()
Exemple #4
0
def clear_data(dbname, tblname):
    """Deletes ALL the data/rows in the specified table."""
    connection = mysql.connector.connect(user=cred.get_user_name(), password=cred.get_password(),
                                         host=cred.get_server_address(),
                                         database=dbname)
    cursor = connection.cursor()

    tables = show_tables(dbname)
    found = False

    for x in range(len(tables)):
        if tblname in tables[x]:
            found = True
    if not found:
        raise Exception("This table does not exist anyway!")

    command = "DELETE FROM " + tblname
    cursor.execute(command)

    success = count_rows(dbname, tblname)

    connection.commit()
    cursor.close()
    connection.close()

    if success == 0:
        return True
    else:
        return False
Exemple #5
0
def save_data(dbname, tblname, ndarray_input):
    """Save data in the specified table. Delete previous data from table or create table if it does not exist."""
    if len(ndarray_input.shape) != 2:
        raise Exception("This function requires multiple rows and an nd-array as input. "
                        "Try append_row or check the entries in each row.")

    connection = mysql.connector.connect(user=cred.get_user_name(), password=cred.get_password(),
                                         host=cred.get_server_address(),
                                         database=dbname)
    cursor = connection.cursor()

    tables = show_tables(dbname)

    present = False
    for x in range(len(tables)):
        if tblname in tables[x]:
            present = True
            cleared = clear_data(dbname, tblname)
            if not cleared:
                raise Exception("Data wasn't cleared!")
            break
    if not present:
        raise Exception("Table does not exist!")
        # create_table(dbname, tblname, columns, column_types)

    num_of_s = ndarray_input.shape[1]
    num_of_rows = ndarray_input.shape[0]

    command = "INSERT INTO " + tblname + " VALUES ("
    for x in range(num_of_s):
        if x == 0:
            command += "%s"
        else:
            command += ", %s"
    command += ")"

    for x in range(num_of_rows):
        row = ndarray_input[x]
        data = row.tolist()
        cursor.execute(command, data)

    connection.commit()
    cursor.close()
    connection.close()

    count = count_rows(dbname, tblname)

    if count > 0:
        success = True
    else:
        success = False

    return success
Exemple #6
0
    def provide_credentials(self):
        # Provide the credentials
        #input("next? - credentials")
        l = credentials.get_login()
        print("l = " + str(l))
        self.driver.find_element(By.CSS_SELECTOR, "*[data-test=\"email-input\"]").send_keys(l)
        time.sleep(1)

        #input("next? - credentials")
        p = credentials.get_password()
        print("p = " + str(p))
        self.driver.find_element(By.CSS_SELECTOR, "*[data-test=\"password-input\"]").send_keys(p)
        #input("next? - credentials")
        time.sleep(1)
Exemple #7
0
def count_rows(dbname, tblname):
    """Executes the SQL command to count the number of rows in the specified table."""
    connection = mysql.connector.connect(user=cred.get_user_name(), password=cred.get_password(),
                                         host=cred.get_server_address(),
                                         database=dbname)
    cursor = connection.cursor()
    cmd = "SELECT COUNT(*) FROM " + tblname
    cursor.execute(cmd)
    count = cursor.fetchall()

    connection.commit()
    cursor.close()
    connection.close()

    return count[0][0]
Exemple #8
0
def show_tables(dbname):
    """Executes the SQL command to show all tables in the specified database."""
    connection = mysql.connector.connect(user=cred.get_user_name(), password=cred.get_password(),
                                         host=cred.get_server_address(),
                                         database=dbname)
    cursor = connection.cursor()
    cmmnd = "SHOW TABLES"
    cursor.execute(cmmnd)
    tables = cursor.fetchall()

    connection.commit()
    cursor.close()
    connection.close()

    return tables
Exemple #9
0
def load_weather():
    username = get_username()
    password = get_password()
    watsonUrl = 'https://twcservice.eu-gb.mybluemix.net/api/weather/v1/geocode/59.52/17.9/forecast/intraday/3day.json?language=en-US&units=m'
    global weather
    global loaded_time
    print("Laddar väderprognos...")
    r = requests.get(watsonUrl, auth=(username, password))
    weather = json.loads(str(r.text))
    # test that the proper structure was recieved
    _ = weather['forecasts'][0]['precip_type']
    _ = weather['forecasts'][0]['pop']
    _ = weather['forecasts'][1]['precip_type']
    _ = weather['forecasts'][1]['pop']
    loaded_time = int(time.time())
    print("Klart!")
Exemple #10
0
def append_row(dbname, tblname, ndarray_input):
    """Append data from the given ndarray in the specified table and database.
    Return true if some rows were appended."""
    if len(ndarray_input.shape) != 1:
        raise Exception("This function only takes a single row as input.")

    connection = mysql.connector.connect(user=cred.get_user_name(), password=cred.get_password(),
                                         host=cred.get_server_address(),
                                         database=dbname)
    cursor = connection.cursor()

    cursor.execute("SELECT count(*) FROM information_schema.columns WHERE table_name = '" + tblname + "'")
    columns = cursor.fetchall()
    if columns[0][0] != len(ndarray_input):
        raise Exception("This row does not have the same number of entries as there are columns!")

    count1 = count_rows(dbname, tblname)
    print(count1)

    command = "INSERT INTO " + tblname + " VALUES ("
    for x in range(ndarray_input.shape[0]):
        if x == 0:
            command += "%s"
        else:
            command += ", %s"
    command += ")"

    data = ndarray_input.tolist()

    cursor.execute(command, data)

    connection.commit()
    cursor.close()
    connection.close()

    count2 = count_rows(dbname, tblname)
    print(count2)

    if count2 == count1+1:
        success = True
    else:
        success = False

    return success
Exemple #11
0
def get_data(dbname, tblname):
    """Get the data from the specified table and database, and return it as an ndarray"""
    connection = mysql.connector.connect(user=cred.get_user_name(), password=cred.get_password(),
                                         host=cred.get_server_address(),
                                         database=dbname)
    cursor = connection.cursor()
    cursor.execute("SELECT * FROM " + tblname)
    results = cursor.fetchall()

    data_array = np.array([])

    for x in range(len(results)):
        row = results[x]
        if x == 0:
            data_array = np.array(row)
        else:
            rownp = np.array(row)
            data_array = np.vstack([data_array, rownp])

    cursor.close()
    connection.close()

    return data_array
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from bs4 import BeautifulSoup
import applicant as applicants

uni_dict = {
    168: 'University of Southern California;Computer Science',
    588: 'New York University;Computer Science',
    135: 'Northeastern University;Computer Science'
}

login_url = "https://yocket.in/account/login"
login_payload = {
    "email": credentials.get_email(),
    "password": credentials.get_password()
}
proxies = {
    "http": 'http://94.21.118.140:61379',
    "https": 'https://185.189.199.75:23500'
}


def extract_session_cookie():
    print("Waiting for session cookie extraction.....")
    options = webdriver.ChromeOptions()
    options.add_argument("--start-maximized")
    driver = webdriver.Chrome(options=options)
    driver.get(login_url)
    email_xpath = """//*[@id="overlay"]/div/div[1]/div/div[2]/form/div[2]/input"""
    email_button_xpath = """//*[@id="overlay"]/div/div[1]/div/div[2]/form/div[3]/button"""