From 34414fb0d45c274a03a8b01de4688e8ae50702c2 Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Mon, 12 Jan 2015 11:01:32 +0200 Subject: server: add 404 redirection (no error page), Fixes #210 --- src/server/rz_server.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/server/rz_server.py b/src/server/rz_server.py index 8693ef52..023cd880 100644 --- a/src/server/rz_server.py +++ b/src/server/rz_server.py @@ -230,6 +230,13 @@ def init_rest_interface(cfg, flask_webapp): flask_webapp.f = f # assign decorated function + # install 404 handler to redirect to root - which redirects further to login (index if access disabled) + @flask_webapp.errorhandler(404) + def page_not_found(e): + # FIXME: template for 404 which redirects (html, not http) + return redirect('/') + + def init_webapp(cfg, kernel, db_ctl=None): """ Initialize webapp: -- cgit v1.3.1 From db5dfcbec8cc1fa2ea9110f59adcd7972bd657a9 Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Mon, 12 Jan 2015 11:19:39 +0200 Subject: server: implement init_pw_db, update docs, set default Config.htpasswd_path to /htpasswd TODO: permissions - warn on lax permissions for password file (and for init file?) --- README.mediawiki | 14 ++++++++++++++ src/server/rz_server.py | 10 ++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/README.mediawiki b/README.mediawiki index 1484ffc3..58fda93e 100644 --- a/README.mediawiki +++ b/README.mediawiki @@ -25,13 +25,27 @@ To run Rhizi locally: For testing locally run neo4j locally on the default 7474 port and then launch run-local.sh:
./run-local.sh Or perform the following tasks by hand: +# Update css files from scss sources using make # Invoke the local deployment Ant target:
$ cd ./rhizi && ant -f build.ant deploy-local # Assert Neo4J is running and listening on it's default port # Run rhizi-server.py:
$ cd deploy-local && python bin/rz_server.py --config-dir=etc Command line use documentation can be view with: :$ python rz_server.py -h + +== Installation == + +=== Setup user password file === +The following works in conjunction with run-local.sh, for real deployment place the resulting htpasswd file in the location matching the config you use. +# put a SECRET_KEY entry in the config file: + echo SECRET_KEY=mysecret >> res/etc/rhizi-server.conf +# create an initialization file with email/password separated by a comma: + echo test@example.com,test > res/etc/htpasswd-init-file +# create the htpasswd file: + python src/server/rz_server.py --init-htpasswd-db --htpasswd-init-file res/etc/htpasswd-init-file + = Development = + To update the css files you need [sass](http://sass-lang.com/) The build tool is [make](https://www.gnu.org/software/make/) diff --git a/src/server/rz_server.py b/src/server/rz_server.py index 023cd880..88f2e9f0 100644 --- a/src/server/rz_server.py +++ b/src/server/rz_server.py @@ -58,6 +58,7 @@ class Config(object): cfg['listen_port'] = 8080 cfg['root_path'] = os.getcwd() cfg['static_url_path'] = '/static' + cfg['htpasswd_path'] = os.path.join(cfg['config_dir'], 'htpasswd') # Flask keys cfg['SECRET_KEY'] = '' @@ -269,8 +270,13 @@ def init_config(cfg_dir): return cfg def init_pw_db(cfg, user_pw_list_file): - pass # TODO: stub, will move to tools/ - + if not os.path.exists(user_pw_list_file): + print("error: missing specified htpasswd init file '%s'" % user_pw_list_file) + raise SystemExit + with open(user_pw_list_file) as user_pwd_list_fd: + for line in user_pwd_list_fd: + u, p = [word.strip() for word in line.split(',')] + crypt_util.add_user_login(cfg, u, p) if __name__ == "__main__": -- cgit v1.3.1 From f6def5675506a35d8be6461411de4626fb71f29e Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Mon, 12 Jan 2015 11:40:33 +0200 Subject: server/404: add debug print of request --- src/server/rz_server.py | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/server/rz_server.py b/src/server/rz_server.py index 88f2e9f0..64a85588 100644 --- a/src/server/rz_server.py +++ b/src/server/rz_server.py @@ -235,6 +235,7 @@ def init_rest_interface(cfg, flask_webapp): @flask_webapp.errorhandler(404) def page_not_found(e): # FIXME: template for 404 which redirects (html, not http) + log.debug("failed redirection: request = %s" % request) return redirect('/') -- cgit v1.3.1 From 2974f916df0614c892a94d3e0f192e10aa03b0b6 Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Mon, 12 Jan 2015 11:41:12 +0200 Subject: server/client: s/res/static/, drop dev_mode__resend_from_static --- res/templates/index.html | 10 +++++----- res/templates/login.html | 6 +++--- src/client/app.js | 2 +- src/server/rz_server.py | 22 ---------------------- 4 files changed, 9 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/res/templates/index.html b/res/templates/index.html index cba394d6..13913ba2 100644 --- a/res/templates/index.html +++ b/res/templates/index.html @@ -2,11 +2,11 @@ Rhizi Prototype - - + + - + @@ -25,7 +25,7 @@ AN
Welcome Anonymous! Logout
- + diff --git a/res/templates/login.html b/res/templates/login.html index 8ddde1b2..000395c2 100644 --- a/res/templates/login.html +++ b/res/templates/login.html @@ -2,7 +2,7 @@ Welcome to Rhizi - +