Guest User

Untitled

a guest
Jun 25th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.20 KB | None | 0 0
  1. for mod in dav_fs.conf dav_fs.load dav.load dav_lock.load; do
  2. (cd /etc/apache2/mods-enabled; ln -s ../mods-available/${mod})
  3. done
  4. cat<<EOF>/etc/apache2/conf.d/recollection.dav
  5. Alias /working/ "/software/data/factory/working/"
  6. <Directory "/software/data/factory/working/">
  7. DAV On
  8. PerlFixupHandler +ApachePerl::AutoMKCOL
  9. PerlCleanupHandler +ApachePerl::AutoDeleteEmpty
  10. Options Indexes MultiViews FollowSymLinks
  11. AllowOverride None
  12. Order allow,deny
  13. Allow from all
  14. </Directory>
  15. EOF
  16. mkdir /var/www/working
  17. /etc/init.d/apache2 restart
  18.  
  19. ################################################################################
  20. # /etc/apache2/ApachePerl/AutoMKCOL.pm
  21. ###########################################################
  22. #
  23. # This is a PerlFixupHandler that will take any PUT
  24. # requests, determine the path required, and if it doesn't
  25. # exist, creates the whole path. If there is a problem
  26. # creating the path, an error is generated.
  27. #
  28. ###########################################################
  29. package ApachePerl::AutoMKCOL;
  30.  
  31. use strict;
  32. use warnings;
  33.  
  34. use Apache2::RequestRec ();
  35. use Apache2::ServerRec ();
  36. use Apache2::Log ();
  37.  
  38. use File::Path;
  39. use File::Basename;
  40.  
  41. # Compile constants
  42. use Apache2::Const -compile => qw(DECLINED);
  43.  
  44. sub handler {
  45. my $r = shift;
  46.  
  47. # Create directories if processing a put request.
  48. if ($r->method() eq "PUT")
  49. {
  50. # The full file system path to the file requested is a concat of the request filename and path_info.
  51. my $fullpath = $r->filename() . $r->path_info();
  52. my $dirname = dirname($fullpath);
  53.  
  54. # If the directory doesn't exist, create it
  55. if (!(-d $dirname))
  56. {
  57. $r->log->info("Creating directory structure for PUT request: '" . $dirname . "'.");
  58. my @dirlist = mkpath ($dirname);
  59.  
  60. # If at least one directory wasn't created, there was a problem
  61. die "Failed to create directory structure: '" . $dirname . "'." unless $#dirlist > -1;
  62. }
  63. }
  64.  
  65. # Allow next handler to run
  66. return Apache2::Const::DECLINED;
  67. }
  68. 1;
  69.  
  70.  
  71.  
  72. ################################################################################
  73. #/etc/apache2/ApachePerl/AutoDeleteEmpty.pm
  74. ###########################################################
  75. #
  76. # This is a PerlCleanupHandler that will, after any DELETE
  77. # requests, traverse the path for the file deleted
  78. # backwards and delete any empty directories
  79. #
  80. ###########################################################
  81. package ApachePerl::AutoDeleteEmpty;
  82.  
  83. use strict;
  84. use warnings;
  85.  
  86. use Apache2::RequestRec ();
  87. use Apache2::ServerRec ();
  88. use Apache2::Log ();
  89.  
  90. use File::Path;
  91. use File::Basename;
  92.  
  93. # Compile constants
  94. use Apache2::Const -compile => qw(DECLINED);
  95.  
  96. sub handler {
  97. my $r = shift;
  98.  
  99. # Create directories if processing a put request.
  100. if ($r->method() eq "DELETE")
  101. {
  102. # The full file system path to the file requested is a concat of the request filename and path_info.
  103. my $fullpath = $r->filename() . $r->path_info();
  104. my $dirname = dirname($fullpath);
  105. opendir(my $dh, $dirname) || warn "can't opendir $dirname: $!";
  106. my @files = grep { /^[^\.]+/ && -f "$dirname/$_" } readdir($dh);
  107. closedir($dh);
  108. if($#files < 0){ rmdir $dirname || warn "cannot remove $dirname $!!"; }
  109. my @dirparts=split('/',$dirname);
  110.  
  111. while(pop(@dirparts)){
  112. $dirname=join('/',@dirparts);
  113. opendir(my $dh, $dirname) || warn "can't opendir $dirname: $!";
  114. my @files = grep { /^[^\.]+/ } readdir($dh);
  115. closedir($dh);
  116. if($#files < 0){
  117. rmdir $dirname || warn "cannot remove $dirname $!!";
  118. }else{
  119. # no point in continuing if this directory is not empty
  120. return Apache2::Const::DECLINED;
  121. }
  122. }
  123. }
  124. # Allow next handler to run
  125. return Apache2::Const::DECLINED;
  126. }
  127. 1;
Add Comment
Please, Sign In to add comment