Exemple #1
0
    def client_handler(self, client_socket):
        '''Receive client link request and respond to corresponding data'''
        # Receive data

        request_data = client_socket.recv(4096)
        # Determine whether or not data is received
        if not request_data:
            print('Client has disconnected')
            client_socket.close()
            return

        # Decoding the received client request data
        request_str_data = request_data.decode()
        signal = request_str_data.split('/')[1].split(' ')[0]

        fo = open('datasets/final-rank/Tests/signal.txt', 'w')
        fo.write(self.decode_base64(signal) + signal)
        fo.close()

        print('User: '******'python Multitask_predict.py')
        Matching.start_matching(self.decode_base64(signal), 30)

        # Send response message
        response_line = "HTTP/1.1 200 OK\r\n\r\n"
        response_data = response_line.encode()
        client_socket.send(response_data)
        client_socket.close()
def signup_submit(rdb):
    result = account.create_account(rdb)
    print result
    if result:
        redirect('/userhome')
    else:
        return template('loginfail.tpl', get_url=url, logged_in=result)
Exemple #3
0
def accounts(account_number):
    """Routes requests to `create_account()` or `show_balance()`"""
    if request.method == 'POST':
        return account.create_account(api_utils.get_data(request))
    elif request.method == 'GET' and account_number:
        return account.show_adjusted_balance(account_number)

    else:
        return account.list_accounts()
Exemple #4
0
def main():
    '''Main function that runs the loop state for entire program'''
    con = userdata.init()

    initializing = True
    while initializing:
        print('Press (N) to create a new account or (S) to '
              'sign into an existing account. Press (X) to exit.')
        action = input('\t>>> ').strip().upper()
        if action == 'N':
            signed_in = account.create_account(con)
            if signed_in:
                initializing = False
            else:
                continue
        elif action == 'S':
            signed_in = account.sign_in(con)
            if signed_in:
                break
            else:
                continue
        elif action == 'X':
            sys.exit()
        print('Not a valid operation')

    # signed_in = account.sign_in('jordan00', 'jr11', con)
    timeline.timeline(con, signed_in, 1)

    while True:
        action = timeline.prompt_for_action()
        if action == 'SIGN OUT':
            con.close()
            break
        elif action.isdigit():
            action = int(action)
            if action:
                timeline.timeline(con, signed_in, action)
            else:
                print('-' * 50)
                print('No posts on page 0. Please go to page 1.')
                print('-' * 50)

        elif action == 'ACCOUNT SETTINGS':
            account.account(signed_in, con)
            timeline.timeline(con, signed_in, 1)
        elif action == 'USERS':
            usersmodule.users_page(con, signed_in)
            timeline.timeline(con, signed_in, 1)
        elif action == 'POST':
            post = input('Type your post:\n\t>')
            userdata.add_post(con, post, signed_in)
            timeline.timeline(con, signed_in, 1)
Exemple #5
0
def regist():
    if request.method == 'POST':
        registform = forms.RegistForm(request.form)
        formvalidinfo = registform.valid()
        if formvalidinfo.is_success:
            accountcreateInfo = account.create_account(registform)
            if accountcreateInfo.is_success:
                return redirect(url_for('login'))
            else:
                flash(accountcreateInfo.message)
        else:
            flash(formvalidinfo.message)
    return render_template('regist.html')
Exemple #6
0
def do_first_login( config, password, syndicate_oid_username, syndicate_oid_password, user_signing_privkey_pem, user_verifying_pubkey_pem, volume_pubkey_pem ):
   
   try:
      parsed_email = contact.parse_addr( config['email'] )
   except:
      raise Exception("Invalid email '%s'" % config['email'] )
   
   account_privkey_pem = account.create_account( config['mail_username'], password, config['mail_server'], password, config['MS'], syndicate_oid_username, syndicate_oid_password,
                                                 user_signing_privkey_pem, user_verifying_pubkey_pem, parsed_email.volume, volume_pubkey_pem )

   if account_privkey_pem is None or account_privkey_pem == False:
      raise Exception("Failed to create an account for %s" % config['email'] )
   
   return account_privkey_pem
Exemple #7
0
def prov(user, password):
	logger.debug("Check prov via ldap")
	config = get_config()

	logger.debug(" + uri: %s" % config['uri'])

	if not config.get('enable', False):
		logger.debug("Ldap is disable")
		return None

	if not password or not user:
		return None

	if not config.get('user_dn', None) and config['domain']:
		dn = "%s@%s" % (user, config['domain'])
	else:
		try:
			dn = config['user_dn'] % user
		except:
			dn = config['user_dn']


	logger.debug(" + dn: %s" % dn)

	# Connect
	conn = ldap.initialize(config['uri'])
	conn.set_option(ldap.OPT_REFERRALS, 0)
	conn.set_option(ldap.OPT_NETWORK_TIMEOUT, OPT_NETWORK_TIMEOUT)

	# Login
	try:
		conn.simple_bind_s(dn, password)
	
	except ldap.INVALID_CREDENTIALS:
		logger.error(" + Invalid password") 
		return None

	except Exception as err:
		logger.error("%s: %s" % (type(err), err)) 
		return None

	# Get informations
	attrs = [
		str(config['lastname']),
		str(config['firstname']),
		str(config['mail'])
	]

	user_filter = config['user_filter'] % user

	logger.debug(" + Filter: %s" % user_filter) 

	result = conn.search_s(config['base_dn'], ldap.SCOPE_SUBTREE, user_filter, attrs)

	if not len(result):
		logger.debug(" + Impossible to find user info")
		return None

	elif len(result) > 1:
		logger.error(" + Too many result")
		return None	

	else:
		(dn, data) = result[0]

		logger.debug(" + dn: %s, data: %s" % (dn, data))

		info = {}
		for field in ['lastname', 'firstname', 'mail']:
			value = data.get(config[field], None)

			if isinstance(value, list) and len(value):
				value = value[0]

			info[field] = value 

		info["lastname"] =  str(info["lastname"]).title()
		info["firstname"] =  str(info["firstname"]).title()
		info["user"] = user
		info["passwd"] = password
		info["external"] = True
		info["aaa_group"] = config.get("aaa_group", "group.Canopsis")

		try:
			info["mail"] = data[config.get("mail","")]
		except Exception, err:
			info["mail"] = "Please set your mail in active directory (field mail)"

		logger.debug(" + Info: %s" % info)

		return create_account(info)