[vhffs-dev] [2218] Add disable/enable webarea capabilities to web bot. |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Revision: 2218
Author: lau
Date: 2012-10-24 12:53:34 +0200 (Wed, 24 Oct 2012)
Log Message:
-----------
Add disable/enable webarea capabilities to web bot.
Modified Paths:
--------------
trunk/vhffs-api/src/Vhffs/Robots/Web.pm
trunk/vhffs-robots/Makefile.am
trunk/vhffs-robots/src/web.pl
Added Paths:
-----------
trunk/vhffs-robots/misc/disabled_webarea.htaccess
Modified: trunk/vhffs-api/src/Vhffs/Robots/Web.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Web.pm 2012-10-18 20:06:32 UTC (rev 2217)
+++ trunk/vhffs-api/src/Vhffs/Robots/Web.pm 2012-10-24 10:53:34 UTC (rev 2218)
@@ -33,6 +33,7 @@
use utf8;
use File::Path;
use File::Basename;
+use File::Copy;
use Vhffs::Constants;
use Vhffs::Functions;
@@ -132,6 +133,46 @@
return 1;
}
+sub disable {
+ my $web = shift;
+ return undef unless defined $web and $web->get_status == Vhffs::Constants::WAITING_FOR_SUSPENSION;
+
+ my $vhffs = $web->get_vhffs;
+ my $template = '%VHFFS_BOTS_DIR%/misc/disabled_webarea.htaccess';
+ my $htaccess = $web->get_dir.'/.htaccess';
+
+ unless ( File::Copy::copy( $template, $htaccess ) ) {
+ Vhffs::Robots::vhffs_log( $vhffs, 'An error occured while disabling web area '.$web->get_servername.' : '.$! );
+ $web->set_status( Vhffs::Constants::SUSPENSION_ERROR );
+ $web->commit;
+ return undef;
+ }
+ Vhffs::Robots::vhffs_log( $vhffs, 'Disabled web area '.$web->get_servername );
+ $web->set_status( Vhffs::Constants::SUSPENDED );
+ $web->commit;
+ return 1;
+}
+
+sub enable {
+ my $web = shift;
+ return undef unless defined $web and $web->get_status == Vhffs::Constants::WAITING_FOR_ACTIVATION;
+
+ my $vhffs = $web->get_vhffs;
+
+ my $htaccess = $web->get_dir."/.htaccess";
+
+ unless( unlink $htaccess ) {
+ Vhffs::Robots::vhffs_log( $vhffs, 'An error occured while enabling web area '.$web->get_servername );
+ $web->set_status( Vhffs::Constants::ACTIVATION_ERROR );
+ $web->commit;
+ return undef;
+ }
+ Vhffs::Robots::vhffs_log( $vhffs, 'Enabled web area '.$web->get_servername );
+ $web->set_status( Vhffs::Constants::ACTIVATED );
+ $web->commit;
+ return 1;
+}
+
#Your logs must be in format : "%V %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""
#So, add in your httpd.conf following lines :
#LogFormat "%V %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" vhffs
Modified: trunk/vhffs-robots/Makefile.am
===================================================================
--- trunk/vhffs-robots/Makefile.am 2012-10-18 20:06:32 UTC (rev 2217)
+++ trunk/vhffs-robots/Makefile.am 2012-10-24 10:53:34 UTC (rev 2218)
@@ -6,6 +6,7 @@
misc/awstats_7.0_vhffs.patch \
misc/awstats_htaccess_example \
misc/awstats.sample \
+ misc/disabled_webarea.htaccess \
misc/repository.awstats_6.95_vhffs.patch \
misc/repository.awstats_7.0_vhffs.patch \
misc/repository.awstats_htaccess_example \
Added: trunk/vhffs-robots/misc/disabled_webarea.htaccess
===================================================================
--- trunk/vhffs-robots/misc/disabled_webarea.htaccess (rev 0)
+++ trunk/vhffs-robots/misc/disabled_webarea.htaccess 2012-10-24 10:53:34 UTC (rev 2218)
@@ -0,0 +1,3 @@
+ErrorDocument 503 "<html><title>Maintenance page</title><body><h1>This webarea has been disabled.</h1><br/><h2>Please contact its webmaster for additionnal information.</h2></body></html>"
+RewriteEngine On
+RewriteRule ".*" - [R=503,L]
Modified: trunk/vhffs-robots/src/web.pl
===================================================================
--- trunk/vhffs-robots/src/web.pl 2012-10-18 20:06:32 UTC (rev 2217)
+++ trunk/vhffs-robots/src/web.pl 2012-10-24 10:53:34 UTC (rev 2218)
@@ -55,5 +55,15 @@
Vhffs::Robots::Web::modify( $_ );
}
+$repos = Vhffs::Services::Web::getall( $vhffs, Vhffs::Constants::WAITING_FOR_SUSPENSION );
+foreach ( @{$repos} ) {
+ Vhffs::Robots::Web::disable( $_ );
+}
+
+$repos = Vhffs::Services::Web::getall( $vhffs, Vhffs::Constants::WAITING_FOR_ACTIVATION );
+foreach ( @{$repos} ) {
+ Vhffs::Robots::Web::enable( $_ );
+}
+
Vhffs::Robots::unlock( $vhffs, 'web' );
exit 0;