[vhffs-dev] [2053] Reworked web robots |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Revision: 2053
Author: gradator
Date: 2012-02-25 13:57:56 +0100 (Sat, 25 Feb 2012)
Log Message:
-----------
Reworked web robots
Modified Paths:
--------------
trunk/vhffs-api/src/Vhffs/Robots/Web.pm
trunk/vhffs-api/src/Vhffs/Robots.pm
trunk/vhffs-robots/Makefile.am
Added Paths:
-----------
trunk/vhffs-robots/src/web.pl
Removed Paths:
-------------
trunk/vhffs-robots/src/web_create.pl
trunk/vhffs-robots/src/web_delete.pl
Modified: trunk/vhffs-api/src/Vhffs/Robots/Web.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Web.pm 2012-02-25 12:22:28 UTC (rev 2052)
+++ trunk/vhffs-api/src/Vhffs/Robots/Web.pm 2012-02-25 12:57:56 UTC (rev 2053)
@@ -34,84 +34,100 @@
use File::Path;
use File::Basename;
-
-package Vhffs::Robots::Web;
-
-use Vhffs::Services::Web;
use Vhffs::Constants;
use Vhffs::Functions;
use Vhffs::Robots;
-use Vhffs::Group;
+use Vhffs::Services::Web;
-sub create_web
-{
- use Vhffs::Group;
+package Vhffs::Robots::Web;
- my $main = shift;
+sub create {
my $web = shift;
+ return undef unless defined $web and $web->get_status == Vhffs::Constants::WAITING_FOR_CREATION;
- if( defined $web )
- {
- $web->add_history( "Ok, the robot take the creation of this object. Web directory will be created");
- my $webdir = $web->get_dir;
+ my $vhffs = $web->get_main;
+ my $dir = $web->get_dir;
- my @dirs = ( $webdir.'/htdocs', $webdir.'/php-include', $webdir.'/tmp' );
+ if( -e $dir ) {
+ $web->set_status( Vhffs::Constants::CREATION_ERROR );
+ $web->commit();
+ Vhffs::Robots::vhffs_log( $vhffs, 'An error occured while creating web repository '.$web->get_servername.' to the filesystem' );
+ return undef;
+ }
- File::Path::make_path( @dirs, { error => \my $errors });
- return undef if @$errors;
+ my @dirs = ( $dir.'/htdocs', $dir.'/php-include', $dir.'/tmp' );
- foreach( @dirs ) {
- chown( $web->get_owner_uid, $web->get_owner_gid, $_ );
- chmod( 02775, $_ );
- }
+ File::Path::make_path( @dirs, { error => \my $errors });
+ if(@$errors) {
+ $web->set_status( Vhffs::Constants::CREATION_ERROR );
+ $web->commit;
+ Vhffs::Robots::vhffs_log( $vhffs, 'An error occured while creating web repository '.$web->get_servername.' to the filesystem' );
+ return undef;
+ }
- my $group = Vhffs::Group::get_by_gid( $main , $web->get_owner_gid );
- if(Vhffs::Robots::link_to_group( $group, $web->get_servername.'-web', $webdir ) < 0) {
-# $web->add_history( "Can't link the webdirectory to the specified group");
- }
- else {
-# $web->add_history( "Ok, robots finished to create webdir. Webdir is now linked to the group directory");
- }
- $web->set_status( Vhffs::Constants::ACTIVATED );
+ foreach( @dirs ) {
+ chown( $web->get_owner_uid, $web->get_owner_gid, $_ );
+ chmod( 02775, $_ );
+ }
+
+ unless( Vhffs::Robots::link_to_group( $web->get_group, $web->get_servername.'-web', $dir ) ) {
+ $web->set_status( Vhffs::Constants::CREATION_ERROR );
$web->commit;
+ return undef;
}
+
+ Vhffs::Robots::vhffs_log( $vhffs, 'Created web area '.$web->get_servername );
+ $web->set_status( Vhffs::Constants::ACTIVATED );
+ $web->commit;
}
+sub delete {
+ my $web = shift;
+ return undef unless defined $web and $web->get_status == Vhffs::Constants::WAITING_FOR_DELETION;
-sub delete
-{
- my( $main , $web ) = @_;
+ my $vhffs = $web->get_main;
+ my $dir = $web->get_dir;
- my $dir;
- if(defined $web)
- {
- $web->add_history( "Ok, the robot will delete this object. Web directory will be removed");
- my $webdir = $web->get_dir;
- my $group = $web->get_group;
- if(Vhffs::Robots::unlink_from_group( $group, $web->get_servername.'-web' ) < 0) {
- $web->add_history( "Can't unlink the webdirectory from the specified group");
- }
- else {
- $web->add_history( "Webdir is now unlinked from the group directory");
- }
+ unless( Vhffs::Robots::unlink_from_group( $web->get_group, $web->get_servername.'-web' ) ) {
+ $web->set_status( Vhffs::Constants::DELETION_ERROR );
+ $web->commit;
+ return undef;
+ }
- Vhffs::Robots::archive_targz( $web, $webdir );
+ Vhffs::Robots::archive_targz( $web, $dir );
- # TODO: check remove_tree
- File::Path::remove_tree( $webdir );
- my $parent = File::Basename::dirname($webdir);
- rmdir $parent;
- $parent = File::Basename::dirname($parent);
- rmdir $parent;
- $parent = File::Basename::dirname($parent);
- rmdir $parent;
+ File::Path::remove_tree( $dir, { error => \my $errors });
+ my $parent = File::Basename::dirname($dir);
+ rmdir $parent;
+ $parent = File::Basename::dirname($parent);
+ rmdir $parent;
+ $parent = File::Basename::dirname($parent);
+ rmdir $parent;
- $web->add_history( "Webdir is now erased.");
- $web->delete;
+ if(@$errors) {
+ $web->set_status( Vhffs::Constants::DELETION_ERROR );
+ $web->commit;
+ Vhffs::Robots::vhffs_log( $vhffs, 'An error occured while removing web area '.$web->get_servername.' from the filesystem' );
+ return undef;
}
+
+ if( $web->delete ) {
+ Vhffs::Robots::vhffs_log( $vhffs, 'Deleted web repository '.$web->get_servername );
+ } else {
+ $web->set_status( Vhffs::Constants::DELETION_ERROR );
+ $web->commit;
+ Vhffs::Robots::vhffs_log( $vhffs, 'An error occured while deleting web area '.$web->get_servername.' object' );
+ return undef;
+ }
+
+ return 1;
}
+sub modify {
+ my $web = shift;
+ return undef unless defined $web and $web->get_status == Vhffs::Constants::WAITING_FOR_MODIFICATION;
+ $web->set_status( Vhffs::Constants::ACTIVATED );
+ $web->commit;
+}
-
1;
-
Modified: trunk/vhffs-api/src/Vhffs/Robots.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots.pm 2012-02-25 12:22:28 UTC (rev 2052)
+++ trunk/vhffs-api/src/Vhffs/Robots.pm 2012-02-25 12:57:56 UTC (rev 2053)
@@ -162,6 +162,15 @@
return -1 unless symlink( $dir , $group->get_dir.'/'.$linkname );
+#TODO: change return values
+
+# TODO: add messages to logfile and object history
+# $web->add_history( "Can't link the webdirectory to the specified group");
+# }
+# else {
+# $web->add_history( "Ok, robots finished to create webdir. Webdir is now linked to the group directory");
+# }
+
return 1;
}
@@ -183,6 +192,15 @@
return -1 unless unlink( $group->get_dir.'/'.$linkname );
+#TODO: change return values
+
+# TODO: add messages to logfile and object history
+# $web->add_history( "Can't unlink the webdirectory from the specified group");
+# }
+# else {
+# $web->add_history( "Webdir is now unlinked from the group directory");
+# }
+
return 1;
}
Modified: trunk/vhffs-robots/Makefile.am
===================================================================
--- trunk/vhffs-robots/Makefile.am 2012-02-25 12:22:28 UTC (rev 2052)
+++ trunk/vhffs-robots/Makefile.am 2012-02-25 12:57:56 UTC (rev 2053)
@@ -56,8 +56,7 @@
src/user_group.pl \
src/user_quota.pl \
src/user_cleanup.pl \
- src/web_create.pl \
- src/web_delete.pl \
+ src/web.pl \
src/web_stats.pl \
src/cron.pl
Copied: trunk/vhffs-robots/src/web.pl (from rev 2052, trunk/vhffs-robots/src/web_create.pl)
===================================================================
--- trunk/vhffs-robots/src/web.pl (rev 0)
+++ trunk/vhffs-robots/src/web.pl 2012-02-25 12:57:56 UTC (rev 2053)
@@ -0,0 +1,59 @@
+#!%PERL%
+# Copyright (c) vhffs project and its contributors
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+#3. Neither the name of vhffs nor the names of its contributors
+# may be used to endorse or promote products derived from this
+# software without specific prior written permission.
+#
+#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+#FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+#COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+#INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+use strict;
+use utf8;
+
+use lib '%VHFFS_LIB_DIR%';
+use Vhffs::Robots::Web;
+
+my $vhffs = init Vhffs::Main;
+exit 1 unless defined $vhffs;
+
+Vhffs::Robots::lock( $vhffs, 'web' );
+
+my $repos = Vhffs::Services::Web::getall( $vhffs, Vhffs::Constants::WAITING_FOR_CREATION );
+foreach ( @{$repos} ) {
+ Vhffs::Robots::Web::create( $_ );
+}
+
+$repos = Vhffs::Services::Web::getall( $vhffs, Vhffs::Constants::WAITING_FOR_DELETION );
+foreach ( @{$repos} ) {
+ Vhffs::Robots::Web::delete( $_ );
+}
+
+$repos = Vhffs::Services::Web::getall( $vhffs, Vhffs::Constants::WAITING_FOR_MODIFICATION );
+foreach ( @{$repos} ) {
+ Vhffs::Robots::Web::modify( $_ );
+}
+
+Vhffs::Robots::unlock( $vhffs, 'web' );
+exit 0;
Deleted: trunk/vhffs-robots/src/web_create.pl
===================================================================
--- trunk/vhffs-robots/src/web_create.pl 2012-02-25 12:22:28 UTC (rev 2052)
+++ trunk/vhffs-robots/src/web_create.pl 2012-02-25 12:57:56 UTC (rev 2053)
@@ -1,64 +0,0 @@
-#!%PERL%
-# Copyright (c) vhffs project and its contributors
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-#2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in
-# the documentation and/or other materials provided with the
-# distribution.
-#3. Neither the name of vhffs nor the names of its contributors
-# may be used to endorse or promote products derived from this
-# software without specific prior written permission.
-#
-#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-#FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-#COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-#INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-# POSSIBILITY OF SUCH DAMAGE.
-
-use strict;
-use utf8;
-
-use lib '%VHFFS_LIB_DIR%';
-use Vhffs::Robots::Web;
-use Vhffs::Services::Web;
-use Vhffs::Robots;
-use Vhffs::Main;
-
-
-my $vhffs = init Vhffs::Main;
-
-Vhffs::Robots::lock( $vhffs , "web" );
-
-my $webs = Vhffs::Services::Web::getall( $vhffs , Vhffs::Constants::WAITING_FOR_CREATION );
-my $web;
-
-foreach $web ( @{$webs} )
-{
- if( Vhffs::Robots::Web::create_web( $vhffs , $web ) < 0 )
- {
- Vhffs::Robots::vhffs_log( $vhffs, sprintf( "Cannot create web %s" , $web->get_servername ) );
- }
- else
- {
- Vhffs::Robots::vhffs_log( $vhffs, sprintf( "Create web %s" , $web->get_servername ) );
- }
-}
-
-Vhffs::Robots::unlock( $vhffs , "web" );
-
-exit 0;
-
Deleted: trunk/vhffs-robots/src/web_delete.pl
===================================================================
--- trunk/vhffs-robots/src/web_delete.pl 2012-02-25 12:22:28 UTC (rev 2052)
+++ trunk/vhffs-robots/src/web_delete.pl 2012-02-25 12:57:56 UTC (rev 2053)
@@ -1,65 +0,0 @@
-#!%PERL%
-# Copyright (c) vhffs project and its contributors
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-#2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in
-# the documentation and/or other materials provided with the
-# distribution.
-#3. Neither the name of vhffs nor the names of its contributors
-# may be used to endorse or promote products derived from this
-# software without specific prior written permission.
-#
-#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-#FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-#COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-#INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-# POSSIBILITY OF SUCH DAMAGE.
-
-use strict;
-use utf8;
-
-use lib '%VHFFS_LIB_DIR%';
-use Vhffs::Robots;
-use Vhffs::Robots::Web;
-use Vhffs::Services::Web;
-use Vhffs::Main;
-use Vhffs::Constants;
-
-
-my $vhffs = init Vhffs::Main;
-
-Vhffs::Robots::lock( $vhffs , "web" );
-
-my $webs = Vhffs::Services::Web::getall( $vhffs , Vhffs::Constants::WAITING_FOR_DELETION );
-my $web;
-
-
-foreach $web ( @{$webs} )
-{
- if( Vhffs::Robots::Web::delete( $vhffs , $web ) < 0 )
- {
- Vhffs::Robots::vhffs_log( $vhffs, sprintf( "Cannot delete web %s" , $web->get_servername ) );
- }
- else
- {
- Vhffs::Robots::vhffs_log( $vhffs, sprintf( "Delete web %s" , $web->get_servername ) );
- }
-}
-
-
-Vhffs::Robots::unlock( $vhffs , "web" );
-exit 0;