Catalyst: securely upload a log file

I have the following problem:

my Catalyst Webservice uses Log4Perl to create a log file that logs all user activity.

How can I provide this file as a download only for administrators? The root directory is not an option, because everyone can download it. I need a safe way. Admins have a separate area in the web service for user management.

Using ssh / sftp, unfortunately, is also not an option, the log must be accessible through webservice.

+4
source share
2 answers

Sorry, I have been very busy the last few days.
Thanks for your help, this is the solution I created and it works :-)

sub log : Chained('base_admin') PathPart('log') Args(0) { my ( $self, $c ) = @_; my $logfile = $c->path_to('test.log'); $c->response->header('Content-Type' => 'text/plain'); $c->response->header('Content-Disposition' => 'attachment; filename=test.log'); $c->serve_static_file($logfile); } 
0
source

To create the action of sending a log file as suggested by @memowe, you need a controller that performs the following actions:

  • Verify that the logged-in user is an administrator and redirects if not.
  • Create a $filehandle scalar to read the log file.
  • Use $c->res->content_type(something) and $c->res->header('Content-Disposition' => 'attachment') to force the response to be processed as a download for the browser to display the Save As dialog. .. ".
  • Set $c->res->body($filehandle) to return the contents of the log file and bypass the View renderer (Template or something else).

Hope this should help you.

+1
source

Source: https://habr.com/ru/post/1447906/


All Articles