def get(self):
        try:
            user_name = request.args.get(constant.USER_NAME)
            if user_name:
                users = database.getParticularUser(user_name)
            else:
                users = database.getUsers()
            return make_response(
                jsonify({
                    "title": "Users Details Fetched Successfully",
                    "status": HTTPStatus.OK,
                    "data": users,
                }), HTTPStatus.OK)

        except Exception as e:
            return make_response(
                jsonify({
                    'title': "Unsuccessful from fetching users",
                    "status": HTTPStatus.BAD_REQUEST,
                    "error": {
                        "message": str(e)
                    }
                }),
                HTTPStatus.BAD_REQUEST,
            )
Exemple #2
0
def signup():
    users = database.getUsers()
    # checks if credentials for flash message
    if request.form.get('username') in users:
        flash("Username already taken")
    elif request.form.get('password0') != request.form.get('password1'):
        flash("Passwords do not match")
    else:
        flash("Please log in with your new credentials!")
        database.addUser(request.form.get('username'), request.form.get('password0'))
    return redirect(url_for('authentication'))
Exemple #3
0
def login():
    users = database.getUsers()
    # checks credentials for login
    if request.form.get('username') in users:
        if request.form.get('password') == users[request.form.get('username')]:
            session['username'] = request.form.get('username')
            return redirect(url_for('profile'))
        else:
            flash("Bad password")
            return redirect(url_for('authentication'))
    else:
        flash("Bad username")
        return redirect(url_for('authentication'))
Exemple #4
0
def login():
    users = database.getUsers()
    # checks credentials for login
    if request.form.get('username') in users:
        hash_object = hashlib.sha224(request.form.get('password'))
        hashed_pass = hash_object.hexdigest()
        if hashed_pass == users[request.form.get('username')]:
            session['username'] = request.form.get('username')
            return redirect(url_for('start'))
        else:
            flash("Yikes! Bad password")
            return redirect(url_for('authentication'))
    else:
        flash("Yikes! Bad username")
        return redirect(url_for('authentication'))
Exemple #5
0
def signup():
    users = database.getUsers()
    # checks if credentials for flash message
    if request.form.get('username') in users:
        flash("Yikes! Username already taken")
        return redirect(url_for('crt_acct'))
    elif request.form.get('password0') != request.form.get('password1'):
        flash("Yikes! Passwords do not match")
        return redirect(url_for('crt_acct'))
    else:
        flash("Yay! Please log in with your new credentials!")
        hash_object = hashlib.sha224(request.form.get('password0'))
        hashed_pass = hash_object.hexdigest()
        database.addUser(request.form.get('username'), hashed_pass)
        return redirect(url_for('authentication'))
Exemple #6
0
async def sendUsers(ownId, roomId, ws):

    usersInRoom = db.getUsers(roomId)
    if (len(usersInRoom) is not 0):  # if the room is not empty
        log(f"Sending a list of clients to new client")
        for user in usersInRoom:  # user is (clientId, roomId, name, avatar, ws)
            if user[0] is not ownId:  # if the user is not itself
                userAttributes = {
                    "newPeer": {
                        "id": user[0],
                        "name": user[2],
                        "avatar": user[3]
                    }
                }
                await ws.send(json.dumps(userAttributes))
Exemple #7
0
    def authenticate(self):
        loginReq = '{"packet_type" : "CONTROL", "subtype" : "loginRequest"}'
        self.sock.sendall(loginReq.encode())
        message = ''
        try:
            message = recv_all(self.sock)
        except SocketClosedException:
            return False
        except IncorrectPacketFormatException:
            return False

        jdict = json.loads(message)

        userlist = database.getUsers(jdict["user"])

        for (ID, username, pHash, rank) in userlist:
            if werkzeug.security.check_password_hash(pHash, jdict["pass"]):
                self.client_id = ID
                if ID in clientDict.keys():
                    return False
                self.rank = rank
                return True
        return False
Exemple #8
0
        flash("Yikes! Bad username")
        return redirect(url_for('authentication'))


# Signs user up for the website (from form)
def signup():
    users = database.getUsers()
    # checks if credentials for flash message
    print(request.form.get('email') + "===================")
    if request.form.get('username') in users:
        flash("Yikes! Username already taken")
        return redirect(url_for('crt_acct'))
    elif request.form.get('email') in users:
        flash("Yikes! Email already taken")
        return redirect(url_for('crt_acct'))
    elif request.form.get('password0') != request.form.get('password1'):
        flash("Yikes! Passwords do not match")
        return redirect(url_for('crt_acct'))
    else:
        flash("Yay! Please log in with your new credentials!")
        hash_object = hashlib.sha224(request.form.get('password0'))
        hashed_pass = hash_object.hexdigest()
        database.addUser(request.form.get('username'), hashed_pass,
                         request.form.get('email'))
        return redirect(url_for('authentication'))


if __name__ == '__main__':
    database.addUser("elmo", "goldfish")
print database.getUsers()
Exemple #9
0
    def render_GET(self, request):
	StatusOutput=''
	for user in ForwardUser.loggedin:
	    for host, port in user.listeners:
		listener = user.listeners[(host, port)]
		StatusOutput+='''<tr>
		    <td>%(username)s</td>
		    <td>%(rhost)s:%(rport)s</td>
		    <td>%(host)s:%(port)s</td>
		    <td><a href="javascript:forward(%(port)s);">Open</a></td>
		    <td><a href="/proxy_localhost_%(port)s/">Proxy</a></td>
		</tr>''' % {
		    'username': user.username,
		    'rhost': listener.remote_host,
		    'rport': listener.remote_port,
		    'host': host,
		    'port':port
		}

        UserOutput=''
        for user in database.getUsers():
            key = md5(user['key']).hexdigest()
            UserOutput+="""<tr>
            <td>%s</td>
            <td>%s</td>
            <td>%s</td>
            <td>%s</td>
            <td>%s</td>
            <td><a href=\"/user/%s/\">Config</a></td>
            <td><a href=\"/user/%s/delete/\">Delete</a></td>
            </tr>""" % (
                            user['user'], 
                            "yes" if user['enabled'] else "no",  
                            key, 
                            user['lastlogin'], 
                            user['accumulated_time'],
                            user['id'],
                            user['id'])

        ConfigOutput=''
        for key, val in config.iteritems():
            ConfigOutput+="""
            <tr>
                <td>%s</td>
                <td>%s</td>
                <td><a href=\"/config/%s/\">Config</a></td>
            </tr>""" % (key, val, key)

        out="""
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
        <title>Remote Control Server</title>
	<script type="text/javascript">
	    function forward(port){
		var url = location.protocol+'//'+location.host.split(':')[0] + ':' + port;
		location.href=url
	    }
	</script>
    </head>
    <body>
	<h1>Status</h1>
	<table style=\"width:100%%;\">
	    <tr>
		<td>UserName</td>
		<td>Remote Port</td>
		<td>Local Port</td>
		<td></td>
	    </tr>
	    %s
	</table>
        <h1>Users</h1>
        <table style=\"width:100%%;\">
            <tr>
                <td>UserName</td>
                <td>Enabled</td>
                <td>RsaKey Md5</td>
                <td>Last Login</td>
                <td>Accumulated Time</td>
                <td></td>
                <td></td>
            </tr>
            %s
        </table>
        <h1>Configuration</h1>
        <table>
            <tr>
                <td>Key</td>
                <td>Value</td>
                <td></td>
            </tr>
            %s
        </table>
    </body>
</html>""" % (StatusOutput, UserOutput, ConfigOutput)
        return str(out)
Exemple #10
0
    def render_GET(self, request):
        StatusOutput = ''
        for user in ForwardUser.loggedin:
            for host, port in user.listeners:
                listener = user.listeners[(host, port)]
                StatusOutput += '''<tr>
		    <td>%(username)s</td>
		    <td>%(rhost)s:%(rport)s</td>
		    <td>%(host)s:%(port)s</td>
		    <td><a href="javascript:forward(%(port)s);">Open</a></td>
		    <td><a href="/proxy_localhost_%(port)s/">Proxy</a></td>
		</tr>''' % {
                    'username': user.username,
                    'rhost': listener.remote_host,
                    'rport': listener.remote_port,
                    'host': host,
                    'port': port
                }

        UserOutput = ''
        for user in database.getUsers():
            key = md5(user['key']).hexdigest()
            UserOutput += """<tr>
            <td>%s</td>
            <td>%s</td>
            <td>%s</td>
            <td>%s</td>
            <td>%s</td>
            <td><a href=\"/user/%s/\">Config</a></td>
            <td><a href=\"/user/%s/delete/\">Delete</a></td>
            </tr>""" % (user['user'], "yes" if user['enabled'] else "no", key,
                        user['lastlogin'], user['accumulated_time'],
                        user['id'], user['id'])

        ConfigOutput = ''
        for key, val in config.iteritems():
            ConfigOutput += """
            <tr>
                <td>%s</td>
                <td>%s</td>
                <td><a href=\"/config/%s/\">Config</a></td>
            </tr>""" % (key, val, key)

        out = """
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
        <title>Remote Control Server</title>
	<script type="text/javascript">
	    function forward(port){
		var url = location.protocol+'//'+location.host.split(':')[0] + ':' + port;
		location.href=url
	    }
	</script>
    </head>
    <body>
	<h1>Status</h1>
	<table style=\"width:100%%;\">
	    <tr>
		<td>UserName</td>
		<td>Remote Port</td>
		<td>Local Port</td>
		<td></td>
	    </tr>
	    %s
	</table>
        <h1>Users</h1>
        <table style=\"width:100%%;\">
            <tr>
                <td>UserName</td>
                <td>Enabled</td>
                <td>RsaKey Md5</td>
                <td>Last Login</td>
                <td>Accumulated Time</td>
                <td></td>
                <td></td>
            </tr>
            %s
        </table>
        <h1>Configuration</h1>
        <table>
            <tr>
                <td>Key</td>
                <td>Value</td>
                <td></td>
            </tr>
            %s
        </table>
    </body>
</html>""" % (StatusOutput, UserOutput, ConfigOutput)
        return str(out)