示例#1
0
 def start(self):
     print(self.hostname)
     self.server = SMTPServer(localaddr=(self.hostname, self.port),
                              remoteaddr=(self.hostname, self.port),
                              ssl=True,
                              certfile="localhost.pem",
                              keyfile="localhost-key.pem")
     asyncore.loop()
示例#2
0
from srht.objects import User
from sqlalchemy import or_


class UserValidator(object):
    def validate(self, username, password):
        user = User.query.filter(
            or_(User.username == username, User.email == username)).first()
        if not user:
            print("Authentication failed for {}, unknown user".format(user))
            return False
        if not user.approved:
            print("Authentication failed for {}, account unapproved".format(
                user))
            return False
        success = bcrypt.hashpw(password, user.password) == user.password
        if not success:
            print("Authentication failed for {}, bad password".format(user))
        else:
            print("Authentication successful for {}".format(user))
        return success


SMTPServer(
    ('127.0.0.1', 4650),
    None,
    require_authentication=True,
    ssl=False,
    credential_validator=UserValidator(),
).run()
示例#3
0
            data = {}
            data['mailfrom'] = username
            data['bell'] = 'on'
            json_data = json.dumps(data)

            client.publish(args.mqtttopic, json_data, qos=0)
            client.disconnect()

            print("Published in: %s:%s - %s" %
                  (args.mqtthost, args.mqttport, args.mqtttopic))

            return True
        else:
            print("Login failed!")
            return False


logging.getLogger(LOG_NAME)
logging.basicConfig(level=logging.DEBUG)

server = SMTPServer((args.smtphost, args.smtpport),
                    None,
                    require_authentication=True,
                    ssl=False,
                    credential_validator=FakeCredentialValidator(),
                    process_count=5,
                    maximum_execution_time=30)

print('Server running on %s:%d for username/password: %s/%s' %
      (args.smtphost, args.smtpport, args.smtpusername, args.smtppassword))
server.run()
示例#4
0
                    username,
                    "password":
                    password,
                    "port":
                    port,
                    'date':
                    datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
                    "module_name":
                    "smtp/strong_password",
                }) + "\n")
            logfile_handle.close()
        finally:
            self.output_lock.release()

    def validate(self, username, password, fromaddr):
        self.log_to_file(fromaddr[0], fromaddr[1], username, password)
        return False


try:
    SMTPServer(
        ('0.0.0.0', 25),
        None,
        require_authentication=True,
        ssl=False,
        credential_validator=FakeCredentialValidator(),
    ).run()
except Exception as e:
    print(e)
    sys.exit()
class SMTPServer(SMTPServer):
    def process_message(self, peer, mailfrom, rcpttos, message_data):
        if (mailfrom.startswith("*****@*****.**")
                and rcpttos[0] == "*****@*****.**"):
            data = {}
            data['peer'] = peer
            data['mailfrom'] = mailfrom
            data['rcpttos'] = rcpttos
            data['bell'] = 'on'
            json_data = json.dumps(data)
            #print (json_data)
            request = urllib2.Request(
                "http://192.168.1.32:5665/json.htm?type=command&param=switchlight&idx=228&switchcmd=On&level=0"
            )
            response = urllib2.urlopen(request)
        else:
            print "Do nothing"


fake_val = FakeCredentialValidator()

server = SMTPServer(('0.0.0.0', 1125),
                    None,
                    require_authentication=True,
                    credential_validator=fake_val,
                    ssl=False)

#print('server run')
server.run()