4

I have the following problem:

my Catalyst Webservice uses Log4Perl to generate a logfile which logs all user activities.

How can i provide this file as download only for admins? The root directory is no option, because everybody could download it. I need a secure way. Admins have a separate area within the webservice to manage the users.

Using ssh / sftp is unfortunately also no option, the log has to be available over the webservice.

theguest
  • 83
  • 4

2 Answers2

1

To build a log-file-sending action as @memowe suggested, you will need a controller that does the following things:

  1. Verify the logged-in user is an admin, and redirect if not.
  2. Create a scalar $filehandle to read the log-file.
  3. Use $c->res->content_type(something) and $c->res->header('Content-Disposition' => 'attachment') to force the response to be treated as a download for the browser to present the "Save As..." dialog.
  4. Set $c->res->body($filehandle) to return the contents of the log-file and bypass your View renderer (Template or whatever).

Hopefully that should get you on your way.

RET
  • 9,100
  • 1
  • 28
  • 33
0

Sorry, i was really busy the last few days.
Thanks for your help, thats the solution i have built 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);
}
theguest
  • 83
  • 4