I'm creating an app that runs external programs, which produce HTML
reports. These reports are produced outside the static directory, but
I want the user to be able to browse them.
Unfortunately, no. I might be able to create soft links under static
to those directories, making up a guid each time for the name. I was
hoping for a more elegant solution.
That lets me read the URL from my web2py code, right? Instead, I want
to serve the file via web2py to the browser.
I suppose I could use this with response.stream, if I knew how to
parse the rest of the URL component below my controller....
+1
Plus, if you are running web2py via apache, my suggestion is something
like this:
- Configure an alias (``Alias /reports /path/to/reports``) in the
virtualhost configuration
- Configure in your app that ``reports_url = "/reports/"`` and
``reports_path = "/path/to/reports"``
- Browse files into reports_path and then link them using
``posixpath.join(reports_url, 'path/to/file')``
[posixpath uses UNIX file names, so it joins using '/'; only on Unix
platforms (a part from macosx..?) os.path == posixpath]
--
Samuele ~redShadow~ Santi
----------------------------------------------------------------
redshadow[at]hackzine.org - redshadowhack[at]gmail.com
Blog: http://hackzine.org
GPG Key signature:
050D 3E9F 6E0B 44CE C008 D1FC 166C 3C7E EB26 4933
----------------------------------------------------------------
/me recommends:
Squadra Informatica - http://www.squadrainformatica.com
----------------------------------------------------------------
- Proud ThinkPad T-Series owner
- Registered Linux-User: #440008
* GENTOO User since 1199142000 (2008-01-01)
* former DEBIAN SID user
----------------------------------------------------------------
"Software is like sex: it's better when it's free!"
-- Linus Torvalds
These files can appear ANYWHERE on the file system. I do not know in
advance, as the user can add directories for the input (and output)
data at runtime via configuration. So, I need a fully dynamic solution
that I can tweak programmatically at runtime.
Your solution (creating links under a path served by Apache) is
similar to something I already tried (a path under static/).
What I'd really love is to be able to have a routes module I could
talk to from the controllers, or one that called a function in my
controller to get the file name to read given a URL.
To serve anything anywhere in the filesystem, you can do something like:
Alias /reports /
And then append the file path. Of course be aware of the risks of
letting users browse the whole filesystem..
If that's in a small intranet to which only trusted people can have
access, plus you tweak permissions on filesystem in order to limit where
the www-data user can have access, plus limit cgi/php/.. file execution
to only some locations, and maybe even add http authentication, this
could be a valid solution..
Better if you can restrict more the accessible path, eg. if your users
will create reports only in their home dirs, you can use something like:
Alias /reports /home
And maybe even limit which user can access which directory (there are
several ways to do this, depending on where you get the users, etc.)
--
Samuele ~redShadow~ Santi
----------------------------------------------------------------
redshadow[at]hackzine.org - redshadowhack[at]gmail.com
Blog: http://hackzine.org
GPG Key signature:
050D 3E9F 6E0B 44CE C008 D1FC 166C 3C7E EB26 4933
----------------------------------------------------------------
/me recommends:
Squadra Informatica - http://www.squadrainformatica.com