Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Enable support for Redis password authentication #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions runserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ def login():
# TODO: test connection, handle failures
host = request.form["host"]
port = int(request.form["port"])
password = request.form["password"]
session['password'] = password if password != '' else None
db = int(request.form["db"])
url = url_for("server_db", host=host, port=port, db=db)
return redirect(url)
Expand All @@ -142,7 +144,7 @@ def server_db(host, port, db):
List all databases and show info on server
"""
s = time.time()
r = redis.StrictRedis(host=host, port=port, db=0)
r = redis.StrictRedis(host=host, port=port, db=0, password=session['password'])
info = r.info("all")
dbsize = r.dbsize()
return render_template('server.html',
Expand All @@ -161,7 +163,7 @@ def keys(host, port, db):
List keys for one database
"""
s = time.time()
r = redis.StrictRedis(host=host, port=port, db=db)
r = redis.StrictRedis(host=host, port=port, db=db, password=session['password'])
if request.method == "POST":
action = request.form["action"]
app.logger.debug(action)
Expand Down Expand Up @@ -205,7 +207,7 @@ def key(host, port, db, key):
"""
key = base64.urlsafe_b64decode(key.encode("utf8"))
s = time.time()
r = redis.StrictRedis(host=host, port=port, db=db)
r = redis.StrictRedis(host=host, port=port, db=db, password=session['password'])
dump = r.dump(key)
if dump is None:
abort(404)
Expand Down Expand Up @@ -253,7 +255,7 @@ def pubsub(host, port, db):


def pubsub_event_stream(host, port, db, pattern):
r = redis.StrictRedis(host=host, port=port, db=db)
r = redis.StrictRedis(host=host, port=port, db=db, password=session['password'])
p = r.pubsub()
p.psubscribe(pattern)
for message in p.listen():
Expand Down
9 changes: 8 additions & 1 deletion templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ <h3>Connect to your Redis database</h3>
</div>
</div>

<div class="form-group">
<label for="password" class="col-sm-3">Password:</label>
<div class="col-sm-9">
<input id="password" name="password" type="password" value="" class="form-control" />
</div>
</div>

<div class="form-group">
<label for="db" class="col-sm-3">Database ID:</label>
<div class="col-sm-9">
Expand All @@ -44,4 +51,4 @@ <h3>Connect to your Redis database</h3>
</div>
</div>

{% endblock %}
{% endblock %}