def http2sms(self): ''' This function simulates an HTTP SMS Gateway. method: test/http2sms arguments: * sender, absender * from, von * destination, ziel * password, passwort * from, von * text * account * api_id returns: As this is a test controller, the response depends on the input values. account = 5vor12, sender = legit -> Response Success: "200" (Text) account = 5vor12, sender = <!legit> -> Response Failed: "Failed" (Text) account = clickatel, username = legit -> Response Success: "ID <Random Number>" (Text) account = clickatel, username = <!legit> -> Response Success: "FAILED" (Text) ''' log.debug('[http2sms]') param = request.params try: account = getParam(param, "account", optional=False) sender = getParam(param, "sender", optional=True) username = getParam(param, "username", optional=True) destination = getParam(param, "destination") if not destination: destination = getParam(param, "ziel") text = getParam(param, "text") if not text: text = getParam(param, "text") if not destination: raise Exception("Missing <destination>") if not text: raise Exception("Missing <text>") if account == "5vor12": if sender == "legit": return "200" else: return "Failed" if account == "clickatel": if username == "legit": return "ID %i" % int(urandom.randint(1000)) else: return "FAILED" Session.commit() return "Missing account info." except Exception as e: log.error('[http2sms] %r' % e) log.error("[http2sms] %s" % traceback.format_exc()) Session.rollback() return sendError(response, unicode(e), 0) finally: Session.close() log.debug('[http2sms] done')
import crypt try: import bcrypt _bcrypt_hashpw = bcrypt.hashpw except ImportError: _bcrypt_hashpw = None # On App Engine, this function is not available. if hasattr(os, 'getpid'): _pid = os.getpid() else: # Fake PID from linotp.lib.crypt import urandom _pid = urandom.randint(0, 100000) class PasswordHash: def __init__(self, iteration_count_log2=8, portable_hashes=True, algorithm=''): alg = algorithm.lower() if (alg == 'blowfish' or alg == 'bcrypt') and _bcrypt_hashpw is None: raise NotImplementedError('The bcrypt module is required') self.itoa64 = \ './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' if iteration_count_log2 < 4 or iteration_count_log2 > 31: iteration_count_log2 = 8 self.iteration_count_log2 = iteration_count_log2 self.portable_hashes = portable_hashes