Apache2-FileManager

 view release on metacpan or  search on metacpan

FileManager.pm  view on Meta::CPAN


 # Or specify different document root in your own mod_perl script
   use Apache2::FileManager;
   my $obj = Apache2::FileManager->new({
     DOCUMENT_ROOT => '/web/project/htdocs/newroot'
   });
   $obj->print();

=head1 SUBCLASSING Apache2::FileManager

 # Create a new file with the following code:

 package MyProject::MyFileManager;
 use strict;
 use Apache2::FileManager;
 our @ISA = ('Apache2::FileManager');

 #Add your own methods here

 1;

The best way to subclass the filemanager would be to copy the methods you want
to overload from the Apache2::FileManager file to your new subclass. Then change
the methods to your liking.

=head1 BUGS

There is a bug in L<File::NCopy> that occurs when trying to paste an empty
directory. The directory is copied but reports back as 0 directories pasted.
The author is in the process of fixing the problem.

=head1 AUTHOR

L<Apache::FileManager> was written by
Philip Collins E<lt>pmc@cpan.orgE<gt>.

L<Apache2::FileManager> was adapted for Apache2 by
David Aguilar E<lt>davvid@cpan.orgE<gt>.

=cut

use strict;
use warnings;
use Apache2::Log ();
use Apache2::Util ();
use Apache2::Const -compile => qw(OK DECLINED);
use Apache2::Request ();
use Apache2::RequestIO ();
use Apache2::RequestRec ();
use Apache2::RequestUtil ();
use Apache2::ServerUtil ();
use Apache2::Upload;
use IO::File;
use File::NCopy  qw(copy);
use File::Copy   qw(move);
use File::Remove qw(remove);
use File::stat;
use Archive::Any;
use POSIX qw(strftime);
use CGI::Cookie;
#use Data::Dumper;

require 5.005_62;

our $VERSION = '0.20';

sub r { return Apache2::Request->new(Apache2::RequestUtil->request) }

# ---------- Object Constructor -----------------------------------------
sub new {
  my $package = shift;
  my $attribs = shift || {};
  my $o = bless $attribs, $package;
  $o->intialize();
  $o->execute_cmds();
  return $o;
}


# ---- If this was called directly via a perl content handler by apache -------
sub handler {
  my $r = Apache2::Request->new(@_);
  return Apache2::Const::DECLINED if defined r->param('nossi');
  my $package = __PACKAGE__;
  my $obj = $package->new();
  r->content_type('text/html');
  r->print("<HTML><HEAD><TITLE>"
           .r->hostname." File Manager $VERSION</TITLE></HEAD>");
  $obj->print();
  r->print("</HTML>");
  return Apache2::Const::OK;
}


# ---- Call the view ----------------------------------------------
sub print {
  my $o = shift;

  my $view = "view_".$$o{'view'};
  $o->$view();
}


# ------------ Intialize object -----------------------------------------
sub intialize {
  my $o = shift;

  $$o{MESSAGE} = "";
  $$o{JS} = "";
  $$o{EDIT_COLS} ||= 75;
  $$o{EDIT_ROWS} ||= 22;


  # Is this filemanager rsync capable?
  $$o{RSYNC_TO} ||= r->dir_config('RSYNC_TO') || undef;

  #set some defaults (for warnings sake)

  $$o{FILEMANAGER_cmd} = r->param('FILEMANAGER_cmd') || "";
  $$o{FILEMANAGER_arg} = r->param('FILEMANAGER_arg') || "";
  $$o{FILEMANAGER_curr_dir} = r->param('FILEMANAGER_curr_dir') || "";



( run in 0.615 second using v1.01-cache-2.11-cpan-39bf76dae61 )