コード例 #1
0
def login():
    auth = request.authorization
    if not auth:
        return jsonify({'message': 'Authotization Not Provided!'}), 400
    else:
        username = auth.username
        password = auth.password

        for user in users_list:
            if username == user.name and password == user.password:
                token = jwt.encode(
                    {
                        'name':
                        user.name,
                        'exp':
                        datetime.datetime.utcnow() +
                        datetime.timedelta(minutes=15)
                    }, os.environ['SECRET_KEY'])

                mail = Mail(
                    user.mail, 'Login',
                    'http://0.0.0.0:50/user-login?token={}'.format(
                        token.decode('utf-8')))
                mail.send()
                sms = SMS(user.phone, 'Someone Logged into your account')
                sms.send()
                return jsonify({'token': token.decode('utf-8')}), 200
            else:
                return jsonify({'message':
                                'Username or Password is Invalid'}), 400
        return jsonify({'message': 'Username or Password is Invalid'}), 400
コード例 #2
0
    def _send(self, df):
        body = """<html>
                  <head><style  type="text/css" > th {border: 1px solid black;width: 65px;} td 
                  {border: 1px solid black;} table {border-collapse: collapse;border: 1px solid black;}
                  </style>
                  </head>
                  <body>"""

        body += df.to_html(index=False)
        body += "</body></html>"
        Mail.send(body, subject='Konfliktplan', to=self.mailto)
コード例 #3
0
def PredictionProcess(logs, waitTime, logType):

    currTime = datetime.now() - timedelta(seconds=10) + timedelta(hours=4)
    startDate = currTime.strftime('%Y-%m-%dT%H:%M:%S')

    while True:

        uniqueAttacks = []
        endDate = datetime.now() - timedelta(seconds=5) + timedelta(hours=4)
        endDate = endDate.strftime('%Y-%m-%dT%H:%M:%S')
        failStr = logType + ": No Data for the time period " + startDate + " - " + endDate + ".\n"

        #For sanity print that the process is running
        print(logType + " is running for time range: " + startDate + " - " +
              endDate + ".")
        if logType is "DB":
            initdf = logs.DatabaseLogs.MySQLLogs(startDate, endDate)
            if initdf is not None:
                df = logs.DatabaseLogs.Transform(initdf)
                model = Model('DB')
                predictedDF, uniqueAttacks = IdentifyAttacks(model, df)

            else:
                print(failStr)

        elif logType is "IIS":
            initdf = logs.WebLogs.IISLog(startDate, endDate)
            if initdf is not None:
                df = logs.WebLogs.Transform(initdf)
                model = Model('IIS')
                predictedDF, uniqueAttacks = IdentifyAttacks(model, df)
            else:
                print(failStr)

        if uniqueAttacks:
            print(logType + " has detected the following attacks: " +
                  " ".join(uniqueAttacks) + "\n")
            notif = Mail(
                "ALERT! " + logType + " has detected attacks.",
                logType + " has detected the following attacks: " +
                " ".join(uniqueAttacks) + "\n")
            notif.send()

        startDate = endDate
        t.sleep(waitTime)
コード例 #4
0
ファイル: test_mail.py プロジェクト: nfredrik/pyjunk
from Mail import Mail
import re
import sys

fh = open('emails.txt', 'r')

list_of_addr = []

for line in fh:
    if re.match('^\w+(\.\w+)*@[a-zA-Z_]+?\.[a-zA-Z_]{2,6}$',
                line.rstrip()) != None:
        print line.rstrip(), ' is a valid address'
        list_of_addr.append(line.rstrip())
    else:
        print line.rstrip(), ' is NOT a valid address'

print list_of_addr

#sys.exit(42)

mail = Mail(
    list_of_addr,
    'dummy_user',
    'dummy_passwd',
    'mail01.ad.bolagsverket.se',
)
mail.send('test mail for jenkins')
コード例 #5
0
ファイル: main.py プロジェクト: nfredrik/berry_rrd
def main(args):
    mail = Mail('*****@*****.**', '*****@*****.**', 'hoppa2lo',
                'smtp.gmail.com')

    mail.send('from pi', 'Sylvia Wrethammar', [])
コード例 #6
0
ファイル: run_ctrl.py プロジェクト: nfredrik/pyjunk
observer.schedule(event_handler, FILEWATCH_DIR, recursive=True)
observer.start()

# FIXME : Create a data object
io = NewLoopDataObject()

# FIXME : Create a protocol
protocol = Protocol(io)

generator = TrafficGenerator(protocol, logger)
# FIXME : Create an instance of a traffic generator

try:
    while True:
        time.sleep(1)
        if event.isSet():
            # FIXME: implement a protocol to send a message to the printer over a
            #        serial line 
            print parser.get('printer', 'message')
            generator.generatePrintStatus()
            event.clear() 

except KeyboardInterrupt:
    observer.stop()
# FIXME: if NACK raise a exception
except Exception, e:
    mail.send('Failed to communicate with the printer')
    logging.debug('Failed to communicate with the printer')

observer.join()