Exemple #1
0
def main():
    #import lank.utils
    # print (logfile)
    #lank.utils.logit("hello",1,"crit")

    from lank import utils
    utils.init()
    utils.logit("hello", "critical")
    #utils.logit("hello","error")
    #utils.logit("hello","warning")
    #utils.logit("hello","info")
    #utils.logit("hello","debug")

    utils.runcmd('ps -eaf')
    utils.runcmd('ifconfig -a')
Exemple #2
0
def main():
    #import lank.utils
    # print (logfile)'
    #lank.utils.logit("hello",1,"crit")
    
    #from lank import utils

    # We set the PYTHONPATH so that we don't have to specify the modules dir.
    # Alternatively, we can set it in the main program as follows
    # sys.path.append('/u/gitwork/utils/python/admin/lank')
    from lank import utils
    # import signal

    #from vars import dbname, dbuser, dbpass, dbport
    from lank.vars import db_creds
    utils.init()
    # utils.create_key()
    # crd = utils.encrypt_cred('587')
    # print(crd)
    # exit(0)
    # from lank.vars import smtp_user, smtp_passwd, smtp_server, smtp_port
    # (gmus, gmpa, gmse, gmpo) = utils.get_creds(smtp_user, smtp_passwd, smtp_server, smtp_port)
    # print(gmus, gmpa, gmse, gmpo)
    # exit(0)

    recipient = ['*****@*****.**', '*****@*****.**']
    # recipient = '*****@*****.**'
    # recipient = '*****@*****.**'
    subject = 'Test from Python'
    body = 'Test 5 to GMail and Yahoo with Mimetext and Multipart with file'
    # body = """
    # <html>
    # <head></head>
    # <body>
    # <p>Hi!
      # <br><b>How are you?<br></b>
       # Here is the <a href="https://www.python.org">link</a> you wanted.
    # </p>
    # </body>
    # </html>
    # """
    attachment = "/u/tmp/test.html"
    # attachment = "NOFILE"
    # attachment = "/home/lmascare/misc/earthmoon_nasa.jpg"
    # attachment = "/home/lmascare/misc/KEYS.gz"
    attachment = "NOFILE"

    # Process a CSV file and send the data as a table.
    csv_file = "/u/tmp/cities.csv"
    with open(csv_file, "r") as csv_data:
        csv_reader = csv.reader(csv_data, dialect="excel", delimiter=",", quotechar='"')
        # Begin table definition
        table = "<!DOCTYPE html>"
        table += "<html>"
        table += "<head>"
        table += "<style>"
        table += """
        table, th, td {
        border: 1px solid black;
        border-collapse: collapse;
        }
        """
        table += "</head>"
        table += "</style>"
        table += "<table>\n"
        for row in csv_reader:
            table += "<tr>" + \
                          "<td>" + \
                              string.join( row, "</td><td>" ) + \
                          "</td>" + \
                     "</tr>\n"
        # End table definition
        table += "</table>"

        table += "</html>"
    # print table
    utils.send_mail(recipient, subject, table, attachment)





    exit(0)
    dbnames = db_creds.keys()
    print(dbnames)

    for dbcred in dbnames:
        print dbcred

        dbname = db_creds[dbcred]['db_name']
        print(dbname)

        dbuser = db_creds[dbcred]['db_user']
        print(dbuser)

        dbpass = db_creds[dbcred]['db_pass']
        print(dbpass)

        dbport = db_creds[dbcred]['db_port']
        print(dbport)

        (db_name, db_user, db_pass, db_port) = utils.get_creds(dbname, dbuser, dbpass, dbport)
        print("DBNAME = {} DBUSER = {} DBPASS = {} DBPORT = {}".format(db_name, db_user, db_pass, db_port))

    #utils.hello()
    #utils.logit("hello","critical")
    #utils.logit("hello","error")
    #utils.logit("hello","warning")
    #utils.logit("hello","info")

    ##utils.logit("info", "hello", 1)
    ##utils.timeout(1)
    ##signal.pause()
    
    utils.runcmd('ps -eaf')
Exemple #3
0
#!/usr/local/bin/python3

from lank import utils


utils.init()

# utils.create_key()
# exit()

dbname = "dmzdb"
dbuser = "******"
dbpass = "******"
dbport = "5432"

(db_name, db_user, db_pass, db_port) = utils.encrypt_creds(dbname, dbuser, dbpass, dbport)

# dbname = 'gAAAAABcV1HROmvUfUByqtZg5lS2HHRCXeDA36TE-uDrsgcExb8B3iEBHqdwuf0RLE_PDFlXf8RjRuC4Q0exn6ZSRW38wLbJ7g=='
# db_name = utils.decrypt_token(dbname)

print ("DBNAME --> {}".format(db_name))
print ("DBUSER --> {}".format(db_user))
print ("DBPASS --> {}".format(db_pass))
print ("DBPORT --> {}".format(db_port))
Exemple #4
0
        else:
            scan_host = args.scan_host if type (args.scan_host) is list else \
                [args.scan_host]
        utils.logit("info", "Hosts to scan --> {}".format(scan_host), 0)

        s = Pool(mpx)
        func = partial(process_host, scan_port)
        scan_results = s.map(func, scan_host)
        s.close()
        s.join()
        print(scan_results)

    # Return to main with message and rc
    return (error_message, error_rc)


def main():
    """Fabled main where it all begins."""
    (error_message, rc) = process_parameters()
    if (rc > 0):
        utils.logit("warning", "Script ended with '{}' error(s)".format(rc), 1)
        # utils.logit("warning", "Error Message --> {}".format(error_message), 0)
    else:
        utils.logit("info", "Congratulations. Script completed successfully",
                    1)


if __name__ == "__main__":
    utils.init()
    main()
Exemple #5
0
def main():
    #import lank.utils
    # print (logfile)'
    #lank.utils.logit("hello",1,"crit")

    #from lank import utils

    # We set the PYTHONPATH so that we don't have to specify the modules dir.
    # Alternatively, we can set it in the main program as follows
    # sys.path.append('/u/gitwork/utils/python/admin/lank')
    from lank import utils
    # import signal

    #from vars import dbname, dbuser, dbpass, dbport
    from lank.vars import db_creds
    utils.init()
    # utils.create_key()
    # crd = utils.encrypt_cred('587')
    # print(crd)
    # exit(0)
    from lank.vars import smtp_user, smtp_passwd, smtp_server, smtp_port
    (gmus, gmpa, gmse, gmpo) = utils.get_creds(smtp_user, smtp_passwd,
                                               smtp_server, smtp_port)
    print(gmus, gmpa, gmse, gmpo)
    exit(0)

    recipient = ['*****@*****.**', '*****@*****.**']
    # recipient = '*****@*****.**'
    # recipient = '*****@*****.**'
    subject = 'Test from Python'
    body = 'Test 5 to GMail and Yahoo with Mimetext and Multipart with file'
    # body = """
    # <html>
    # <head></head>
    # <body>
    # <p>Hi!
    # <br><b>How are you?<br></b>
    # Here is the <a href="https://www.python.org">link</a> you wanted.
    # </p>
    # </body>
    # </html>
    # """
    attachment = "/u/tmp/test.html"
    # attachment = "NOFILE"
    # attachment = "/home/lmascare/misc/earthmoon_nasa.jpg"
    # attachment = "/home/lmascare/misc/KEYS.gz"
    attachment = "NOFILE"

    # Process a CSV file and send the data as a table.
    csv_file = "/u/tmp/cities.csv"
    with open(csv_file, "r") as csv_data:
        csv_reader = csv.reader(csv_data,
                                dialect="excel",
                                delimiter=",",
                                quotechar='"')
        # Begin table definition
        table = "<!DOCTYPE html>"
        table += "<html>"
        table += "<head>"
        table += "<style>"
        table += """
        table, th, td {
        border: 1px solid black;
        border-collapse: collapse;
        }
        """
        table += "</head>"
        table += "</style>"
        table += "<table>\n"
        for row in csv_reader:
            table += "<tr>" + \
                          "<td>" + \
                              string.join( row, "</td><td>" ) + \
                          "</td>" + \
                     "</tr>\n"
        # End table definition
        table += "</table>"

        table += "</html>"
    # print table
    utils.send_mail(recipient, subject, table, attachment)

    exit(0)
    dbnames = db_creds.keys()
    print(dbnames)

    for dbcred in dbnames:
        print dbcred

        dbname = db_creds[dbcred]['db_name']
        print(dbname)

        dbuser = db_creds[dbcred]['db_user']
        print(dbuser)

        dbpass = db_creds[dbcred]['db_pass']
        print(dbpass)

        dbport = db_creds[dbcred]['db_port']
        print(dbport)

        (db_name, db_user, db_pass,
         db_port) = utils.get_creds(dbname, dbuser, dbpass, dbport)
        print("DBNAME = {} DBUSER = {} DBPASS = {} DBPORT = {}".format(
            db_name, db_user, db_pass, db_port))

    #utils.hello()
    #utils.logit("hello","critical")
    #utils.logit("hello","error")
    #utils.logit("hello","warning")
    #utils.logit("hello","info")

    ##utils.logit("info", "hello", 1)
    ##utils.timeout(1)
    ##signal.pause()

    utils.runcmd('ps -eaf')
Exemple #6
0
def main():
    from lank import utils
    from lank.vars import db_creds
    utils.init()
    recipient = ['*****@*****.**', '*****@*****.**']
    # recipient = '*****@*****.**'
    # recipient = '*****@*****.**'
    subject = 'Test from Python'
    body = 'Test 5 to GMail and Yahoo with Mimetext and Multipart with file'
    # attachment = "NOFILE"
    attachment = "/home/lmascare/misc/earthmoon_nasa.jpg"
    # attachment = "/home/lmascare/misc/KEYS.gz"
    attachment = "NOFILE"

    # Process a CSV file and send the data as a table.
    csv_file = "/u/tmp/cities.csv"
    out_file = "/u/tmp/cities_table.html"
    with open(csv_file, "r") as csv_data:
        # csv_reader = csv.reader(csv_data, dialect="excel", delimiter=",", quotechar='"', strict=True)
        csv_reader = csv.reader(csv_data,
                                dialect="excel",
                                delimiter=",",
                                quotechar='"',
                                strict=True,
                                skipinitialspace=True)
        # Begin table definition
        table = """
        <!DOCTYPE html>
        <html>
        <head>
        <style>
        table, th, td {
            border: 1px solid black;
            border-collapse: collapse;
        }
        th, td {
            padding: 5px;
            text-align: left;
            background-color: powderblue;
            color: green;
        }
        </style>
        </head>
        <table>
        <caption><h1>Geo Location of cities</h1></caption>
        """
        header = next(csv_reader)
        print type(header)
        table += "<th>" + string.join(header, "</th><th>") + \
                 "</th>"
        for row in csv_reader:

            table += "<tr>" + \
                          "<td>" + \
                              string.join( row, "</td><td>" ) + \
                          "</td>" + \
                     "</tr>\n"
        # End table definition
        table += "</table>"

        table += "</html>"
    # print table
    utils.send_mail(recipient, subject, table, attachment)
    f = open(out_file, "wb")
    f.write(table)
    f.close()
    exit(0)