From 831fb175f86241cb5f16d98fc3c387dc0a608f37 Mon Sep 17 00:00:00 2001 From: MinRK Date: Tue, 27 Dec 2011 21:46:10 -0800 Subject: [PATCH 1/4] serve files in notebook-dir as local/foo --- IPython/frontend/html/notebook/notebookapp.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/IPython/frontend/html/notebook/notebookapp.py b/IPython/frontend/html/notebook/notebookapp.py index 767903401..8c25a29aa 100644 --- a/IPython/frontend/html/notebook/notebookapp.py +++ b/IPython/frontend/html/notebook/notebookapp.py @@ -103,7 +103,8 @@ class NotebookWebApplication(web.Application): (r"/kernels/%s/shell" % _kernel_id_regex, ShellHandler), (r"/notebooks", NotebookRootHandler), (r"/notebooks/%s" % _notebook_id_regex, NotebookHandler), - (r"/rstservice/render", RSTHandler) + (r"/rstservice/render", RSTHandler), + (r"/local/(.*)", web.StaticFileHandler, {'path' : notebook_manager.notebook_dir}), ] settings = dict( template_path=os.path.join(os.path.dirname(__file__), "templates"), From d67865c73c0b837ccb57d7d7785ae8f07887afcc Mon Sep 17 00:00:00 2001 From: MinRK Date: Tue, 27 Dec 2011 22:08:03 -0800 Subject: [PATCH 2/4] authenticate local file access adds AuthenticatedFileHandler, which extends StaticFileHandler with a simple authentication check before providing access to files local to the notebook dir. --- IPython/frontend/html/notebook/handlers.py | 9 +++++++++ IPython/frontend/html/notebook/notebookapp.py | 5 +++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/IPython/frontend/html/notebook/handlers.py b/IPython/frontend/html/notebook/handlers.py index f275d1864..cca873091 100644 --- a/IPython/frontend/html/notebook/handlers.py +++ b/IPython/frontend/html/notebook/handlers.py @@ -107,6 +107,7 @@ def authenticate_unless_readonly(f, self, *args, **kwargs): @web.authenticated def auth_f(self, *args, **kwargs): return f(self, *args, **kwargs) + if self.application.read_only: return f(self, *args, **kwargs) else: @@ -174,6 +175,14 @@ class AuthenticatedHandler(RequestHandler): return "%s://%s" % (proto, self.request.host) +class AuthenticatedFileHandler(AuthenticatedHandler, web.StaticFileHandler): + """static files should only be accessible when logged in""" + + @authenticate_unless_readonly + def get(self, path): + return web.StaticFileHandler.get(self, path) + + class ProjectDashboardHandler(AuthenticatedHandler): @authenticate_unless_readonly diff --git a/IPython/frontend/html/notebook/notebookapp.py b/IPython/frontend/html/notebook/notebookapp.py index 8c25a29aa..926cf5c97 100644 --- a/IPython/frontend/html/notebook/notebookapp.py +++ b/IPython/frontend/html/notebook/notebookapp.py @@ -48,7 +48,8 @@ from .kernelmanager import MappingKernelManager from .handlers import (LoginHandler, LogoutHandler, ProjectDashboardHandler, NewHandler, NamedNotebookHandler, MainKernelHandler, KernelHandler, KernelActionHandler, IOPubHandler, - ShellHandler, NotebookRootHandler, NotebookHandler, RSTHandler + ShellHandler, NotebookRootHandler, NotebookHandler, RSTHandler, + AuthenticatedFileHandler, ) from .notebookmanager import NotebookManager @@ -104,7 +105,7 @@ class NotebookWebApplication(web.Application): (r"/notebooks", NotebookRootHandler), (r"/notebooks/%s" % _notebook_id_regex, NotebookHandler), (r"/rstservice/render", RSTHandler), - (r"/local/(.*)", web.StaticFileHandler, {'path' : notebook_manager.notebook_dir}), + (r"/local/(.*)", AuthenticatedFileHandler, {'path' : notebook_manager.notebook_dir}), ] settings = dict( template_path=os.path.join(os.path.dirname(__file__), "templates"), From ba5e2538b5c725408306c20b46e3729ed8beabe8 Mon Sep 17 00:00:00 2001 From: MinRK Date: Wed, 28 Dec 2011 21:28:21 -0800 Subject: [PATCH 3/4] use absolute URLs for static files --- IPython/frontend/html/notebook/notebookapp.py | 2 +- .../html/notebook/templates/layout.html | 20 ++--- .../html/notebook/templates/notebook.html | 86 +++++++++---------- .../notebook/templates/projectdashboard.html | 6 +- 4 files changed, 57 insertions(+), 57 deletions(-) diff --git a/IPython/frontend/html/notebook/notebookapp.py b/IPython/frontend/html/notebook/notebookapp.py index 926cf5c97..cf29208f5 100644 --- a/IPython/frontend/html/notebook/notebookapp.py +++ b/IPython/frontend/html/notebook/notebookapp.py @@ -282,7 +282,7 @@ class NotebookApp(BaseIPythonApplication): static_path = self.webapp_settings.get("static_path", os.path.join(os.path.dirname(__file__), "static")) if os.path.exists(os.path.join(static_path, 'mathjax', "MathJax.js")): self.log.info("Using local MathJax") - return u"static/mathjax/MathJax.js" + return u"/static/mathjax/MathJax.js" else: self.log.info("Using MathJax from CDN") return u"http://cdn.mathjax.org/mathjax/latest/MathJax.js" diff --git a/IPython/frontend/html/notebook/templates/layout.html b/IPython/frontend/html/notebook/templates/layout.html index 8d5e4d224..407e2ab0d 100644 --- a/IPython/frontend/html/notebook/templates/layout.html +++ b/IPython/frontend/html/notebook/templates/layout.html @@ -6,10 +6,10 @@ {% block title %}IPython Notebook{% end %} - - - - + + + + {% block stylesheet %} {% end %} @@ -21,7 +21,7 @@ - - - - - + + + + + {% block script %} {% end %} diff --git a/IPython/frontend/html/notebook/templates/notebook.html b/IPython/frontend/html/notebook/templates/notebook.html index ab160a1db..11daece2f 100644 --- a/IPython/frontend/html/notebook/templates/notebook.html +++ b/IPython/frontend/html/notebook/templates/notebook.html @@ -15,20 +15,20 @@ window.mathjax_url = "{{mathjax_url}}"; - - - - - - + + + + + + - + - - - - - + + + + + {% comment In the notebook, the read-only flag is used to determine %} {% comment whether to hide the side panels and switch off input %} @@ -42,7 +42,7 @@ > - - - + + + - - - - - - - - + + + + + + + + - + - + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + diff --git a/IPython/frontend/html/notebook/templates/projectdashboard.html b/IPython/frontend/html/notebook/templates/projectdashboard.html index d3036afa5..3dfc52b7a 100644 --- a/IPython/frontend/html/notebook/templates/projectdashboard.html +++ b/IPython/frontend/html/notebook/templates/projectdashboard.html @@ -5,7 +5,7 @@ IPython Dashboard {% end %} {% block stylesheet %} - + {% end %} {% block meta %} @@ -38,6 +38,6 @@ data-base-kernel-url={{base_kernel_url}} {% end %} {% block script %} - - + + {% end %} From 1d65883212b88f1ae1f594c49d8a518e1f3759f3 Mon Sep 17 00:00:00 2001 From: MinRK Date: Tue, 3 Jan 2012 11:39:54 -0800 Subject: [PATCH 4/4] serve local files as `files/foo` --- IPython/frontend/html/notebook/notebookapp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IPython/frontend/html/notebook/notebookapp.py b/IPython/frontend/html/notebook/notebookapp.py index cf29208f5..18bb21e73 100644 --- a/IPython/frontend/html/notebook/notebookapp.py +++ b/IPython/frontend/html/notebook/notebookapp.py @@ -105,7 +105,7 @@ class NotebookWebApplication(web.Application): (r"/notebooks", NotebookRootHandler), (r"/notebooks/%s" % _notebook_id_regex, NotebookHandler), (r"/rstservice/render", RSTHandler), - (r"/local/(.*)", AuthenticatedFileHandler, {'path' : notebook_manager.notebook_dir}), + (r"/files/(.*)", AuthenticatedFileHandler, {'path' : notebook_manager.notebook_dir}), ] settings = dict( template_path=os.path.join(os.path.dirname(__file__), "templates"),