CipUX-Dog-3.4.0.0/0000755000175000017500000000000011156472646013563 5ustar ckuelkerckuelkerCipUX-Dog-3.4.0.0/lib/0000755000175000017500000000000011156472646014331 5ustar ckuelkerckuelkerCipUX-Dog-3.4.0.0/lib/CipUX/0000755000175000017500000000000011156472646015321 5ustar ckuelkerckuelkerCipUX-Dog-3.4.0.0/lib/CipUX/Dog.pm0000444000175000017500000003644611156472646016403 0ustar ckuelkerckuelker# +==========================================================================+ # || CipUX::Dog || # || || # || CipUX CipUX::Dog || # || || # || Copyright 2008 - 2009 by Christian Kuelker. All rights reserved! || # || || # || License: GNU GPL version 2 or any later version. || # || || # +==========================================================================+ # ID: $Id$ # Revision: $Revision$ # Head URL: $HeadURL$ # Date: $Date$ # Source: $Source$ package CipUX::Dog; use 5.008001; use strict; use warnings; use Carp; use Class::Std; use Data::Dumper; use English qw( -no_match_vars); use Log::Log4perl qw(get_logger :levels); use Readonly; use base qw(CipUX); { # BEGIN INSIDE-OUT CLASS use version; our $VERSION = qv('3.4.0.0'); use re 'taint'; # Keep data captured by parens tainted delete @ENV{qw(PATH IFS CDPATH ENV BASH_ENV)}; # Make %ENV safe # +======================================================================+ # || CONST || # +======================================================================+ Readonly::Scalar my $EMPTY_STRING => q{}; Readonly::Scalar my $WRITE_EXEC => q{-|}; # +======================================================================+ # || OBJECT || # +======================================================================+ # If use af ATTR above OK, then sub BUILD is not needed: my %dog_hr_of : ATTR( init_arg => 'dog_hr'); # dog my %object_of : ATTR( init_arg => 'object'); # dog my %overwrite_hr_of : ATTR( init_arg => 'overwrite_hr'); # dog my %dog_cfg : ATTR( :get ); # +======================================================================+ # || GLOBAL || # +======================================================================+ # +======================================================================+ # || CONSTRUCTOR || # +======================================================================+ sub BUILD { # +------------------------------------------------------------------+ # | API my ( $self, $ident, $arg_r ) = @_; # add prefix for cfg, if needed my $pref = exists $arg_r->{pref} ? $self->l( $arg_r->{pref} ) : $EMPTY_STRING; # +------------------------------------------------------------------+ # | main $dog_cfg{$ident} = $self->cfg( { 'sub' => 'dog', pref => $pref } ); # add them if needed: # $dog_of{$ident} = $arg_r->{dog}; # $object_of{$ident} = $arg_r->{object}; # $overwrite_hr_of{$ident} = $arg_r->{overwrite_hr}; # +------------------------------------------------------------------+ # | API return; } # +======================================================================+ # || DESTRUCTOR || # +======================================================================+ sub DEMOLISH { # +------------------------------------------------------------------+ # | API my ( $self, $ident ) = @_; # +------------------------------------------------------------------+ # | main delete $dog_cfg{$ident}; delete $dog_hr_of{$ident}; delete $object_of{$ident}; delete $overwrite_hr_of{$ident}; # +------------------------------------------------------------------+ # | API return; } # +======================================================================+ # || MAIN || # +======================================================================+ # +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ # | PRIVATE INTERFACE | # +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ # Module implementation here # +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ # | PUBLIC INTERFACE | # +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ # +======================================================================+ # || METHODS || # +======================================================================+ sub bite { # API my ($self) = @_; my $logger = get_logger(__PACKAGE__); $logger->debug('BEGIN'); my $cfg_dog_cmd_hr = $dog_cfg{ ident $self}; $logger->debug( 'cfg_dog_cmd_hr: ', { filter => \&Dumper, value => $cfg_dog_cmd_hr } ); $logger->debug('starting dog action'); my $cipux_dog = $EMPTY_STRING; my $cmdargs_hr = {}; # key: cipux_dog, user, role # val: create_homedir, @object@, role foreach my $key ( sort keys %{ $dog_hr_of{ ident $self } } ) { $logger->debug( 'dog_hr_of key', { filter => \&Dumper, value => $key } ); $logger->debug( 'dog_hr_of value', { filter => \&Dumper, value => $dog_hr_of{ ident $self }{$key} } ); if ( $key eq 'cipux_dog' ) { $cipux_dog = $dog_hr_of{ ident $self }{$key}; } else { my $cli_opt = $self->l($key); $cli_opt =~ s/\@object\@/$object_of{ident $self}/gsmx; my $cli_val = $self->l( $dog_hr_of{ ident $self }{$key} ); $cli_val =~ s/\@object\@/$object_of{ident $self}/gsmx; # { # 'user' => 'testuser12', # 'role' => 'role', # } $cmdargs_hr->{$cli_opt} = $cli_val; } } my $msg = 'The section "commands" is not defined'; $msg .= " in cipux-dog.perl for $cipux_dog!\n"; my %commands = exists $cfg_dog_cmd_hr->{cipux_dogs}->{$cipux_dog}->{commands} ? %{ $cfg_dog_cmd_hr->{cipux_dogs}->{$cipux_dog}->{commands} } : croak $msg; my $cmd = $EMPTY_STRING; my $cmd_args_ar = []; # $cmd: 1, 2, 3, ... foreach my $count ( sort keys %commands ) { $logger->debug("count: $count"); $cmd = $cfg_dog_cmd_hr->{cipux_dogs}->{$cipux_dog}->{commands} ->{$count}->{shell}; $logger->debug("cmd: $cmd"); my $args_ar = $cfg_dog_cmd_hr->{cipux_dogs}->{$cipux_dog}->{commands} ->{$count}->{args}; $logger->debug( 'args_ar ', { filter => \&Dumper, value => $args_ar } ); # arg: --user, @user@, --role, @role@, foreach my $arg ( @{$args_ar} ) { # if arg is a variable if ( $arg =~ m/^\@(.*)\@$/xms ) { if ( defined $cmdargs_hr->{$1} ) { # @user@ -> testuser12 # @role@ -> role $arg = $cmdargs_hr->{$1}; } } # --user -> --user # @user@ -> testuser12 push @{$cmd_args_ar}, $self->l($arg); } } $logger->debug("cmd: $cmd"); $logger->debug( 'cmd_args_ar ', { filter => \&Dumper, value => $cmd_args_ar } ); my $return = $self->execute( { command => $self->l($cmd), cmdargs_ar => $cmd_args_ar } ); $logger->debug('END'); return ( $cmd, $cmd_args_ar, $return ); } sub execute { my ( $self, $arg_r ) = @_; my $command = exists $arg_r->{command} ? $self->l( $arg_r->{command} ) : $self->perr('command'); my $cmdargs_ar = exists $arg_r->{cmdargs_ar} ? $self->a( $arg_r->{cmdargs_ar} ) : $self->perr('cmdargs_ar'); my $logger = get_logger(__PACKAGE__); $logger->debug('BEGIN'); $logger->debug("> command: $command"); $logger->debug( '> cmdargs_ar ', { filter => \&Dumper, value => $cmdargs_ar } ); my @sanitized_arg = (); foreach my $arg ( @{$cmdargs_ar} ) { $arg =~ s/[`]//gsmx; push @sanitized_arg, $arg; } my @return = (); my $return = $EMPTY_STRING; my $msg = "Cannot execute [$command " . join q{ }, @sanitized_arg; $msg .= ']. Please provide this command or change [cipux-dog.perl].'; $msg .= ' The error message was: '; if ( not -e $command ) { croak $msg . 'Command do not exist!'; } if ( not -x $command ) { croak $msg . 'Command is not executable! (forget chmod +x ?)'; } open my $GET_HANDLE, $WRITE_EXEC, $command, @sanitized_arg or croak $msg . $CHILD_ERROR; while (<$GET_HANDLE>) { if (wantarray) { push @return, $_; } else { $return .= $_; } } close $GET_HANDLE or croak "Can not close command $command!\n"; $logger->debug('END'); return ( wantarray ? @return : $return ); } } # END INSIDE-OUT CLASS 1; # Magic true value required at end of module __END__ =pod =for stopwords CipUX Kuelker config Readonly webpage cipux-dog.perl =head1 NAME CipUX::Dog - Adds a hook to CipUX::Task to execute commands. =head1 VERSION This document describes CipUX::Dog version 3.4.0.0 =head1 SYNOPSIS use CipUX::Dog; or use English qw( -no_match_vars); eval { require CipUX::Dog; }; if ( not $EVAL_ERROR ) { my $dog = CipUX::Dog->new( { dog_hr => $dog_hr, object => $object, overwrite_hr => $overwrite_hr, } ); $dog->bite(); # exec files system command } =head1 DESCRIPTION CipuX::Dog can be used as a hook for CipUX::Task. If CipUX::Dog is installed it can be configured by the administrator to execute commands triggered by execution of a given task. =head1 SUBROUTINES/METHODS =head2 BUILD Create the Object, reads the config file =head2 DEMOLISH Removes the object =head2 bite Calls the dog to bite. =head2 execute Execute a command. my $return = $self->execute( { command => $self->l($cmd), cmdargs_ar => $cmd_args_ar } ); =head1 DIAGNOSTICS This section list every single error and warning message that the module can generate (even the ones that will "never happen"), with a full explanation of each problem, one or more likely causes, and any suggested remedies. =over =item C<< The section "commands" is not defined in cipux-dog.perl for %s >> The hash key 'commands' is not inside the configuration for a given dog hash key in cipux-dog.perl configuration. The problem might look like this: $cfg = { cipux_dogs => { create_homedir => { }, }, }; It can be solved by adding a 'commands' key: $cfg = { cipux_dogs => { create_homedir => { commands => { }, }, }, }; =item C<< Cannot execute [%s]. Please provide this command or change [cipux-dog.perl]. The error message was: %s >> There can be different reasons for this message. It depends on the last %s. The following reasons are foreseen: C<< Command do not exist! >> The command specified in cipux-dog.perl do not exist. You should copy, provide or write this command. C<< Command is not executable! (forget chmod +x ?) >> The command specified in cipux-dog.perl exists but can not be executed. Either it has no executable flags or you have not the right to execute it. Check and/ro set the execution bit on this command or try do give you the right to execute it. C<< ? >> Other reasons not be able to execute the command might come from the system and will display after the message. =item C<< Can not close command %s >> If the file handle can not be closed this message will be displayed. =back =head1 CONFIGURATION AND ENVIRONMENT CipUX::Dog requires a configuration file but no environment variables. It can be configured by cipux-dog.$ext, where $ext is a valid and capable extension from CipUX configuration space. The default configuration for CipUX::Dog is in: /usr/share/cipux/etc/cipux-dog.perl =head1 DEPENDENCIES Carp CipUX Class::Std Data::Dumper English Log::Log4perl Readonly version =head1 INCOMPATIBILITIES None reported. =head1 BUGS AND LIMITATIONS No bugs have been reported. =head1 SEE ALSO See the CipUX webpage and the manual at L =head1 AUTHOR Christian Kuelker C<< >> =head1 LICENSE AND COPYRIGHT Copyright (C) 2008 - 2009, Christian Kuelker. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA =head1 DISCLAIMER OF WARRANTY BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENSE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. =cut CipUX-Dog-3.4.0.0/META.yml0000444000175000017500000000143411156472646015034 0ustar ckuelkerckuelker--- name: CipUX-Dog version: 3.4.0.0 author: - 'Christian Kuelker ' abstract: Adds a hook to CipUX::Task to execute commands. license: gpl resources: homepage: http://www.cipux.org license: http://opensource.org/licenses/gpl-license.php requires: Carp: 0 CipUX: 3.4.0.0 Class::Std: 0.0.9 Data::Dumper: 0 English: 0 Log::Log4perl: 0.42 Readonly: 0 version: 0 build_requires: File::Spec: 0 Module::Build: 0 Module::Build::CipUX: 0.4.0 Test::More: 0 Test::Pod: 1.14 recommends: Test::Perl::Critic: 0 Test::Pod::Coverage: 1.04 provides: CipUX::Dog: file: lib/CipUX/Dog.pm version: 3.4.0.0 generated_by: Module::Build version 0.280801 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.2.html version: 1.2 CipUX-Dog-3.4.0.0/t/0000755000175000017500000000000011156472646014026 5ustar ckuelkerckuelkerCipUX-Dog-3.4.0.0/t/perlcriticrc0000444000175000017500000000101711156472646016433 0ustar ckuelkerckuelker# CipUX Perl::Critic Configuration # # SEVERITY NAME ...is equivalent to... SEVERITY NUMBER # ---------------------------------------------------- # gentle 5 # stern 4 # harsh 3 # cruel 2 # brutal 1 severity = brutal verbose = 11 CipUX-Dog-3.4.0.0/t/perlcritic_cpan.t0000444000175000017500000000100711156472646017350 0ustar ckuelkerckuelker#!perl use strict; use warnings; use File::Spec; use Test::More; use English qw(-no_match_vars); if ( not $ENV{TEST_AUTHOR} ) { my $msg = 'Author test. Set $ENV{TEST_AUTHOR} to a true value to run.'; plan( skip_all => $msg ); } eval { require Test::Perl::Critic; }; if ($EVAL_ERROR) { my $msg = 'Test::Perl::Critic required to criticise code'; plan( skip_all => $msg ); } my $rcfile = File::Spec->catfile( 't', 'perlcriticrc' ); Test::Perl::Critic->import( -profile => $rcfile ); all_critic_ok(); CipUX-Dog-3.4.0.0/t/pod-coverage.t0000444000175000017500000000026011156472646016562 0ustar ckuelkerckuelker#!perl -T use Test::More; eval "use Test::Pod::Coverage 1.04"; plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; all_pod_coverage_ok(); CipUX-Dog-3.4.0.0/t/pod.t0000444000175000017500000000021411156472646014770 0ustar ckuelkerckuelker#!perl -T use Test::More; eval "use Test::Pod 1.14"; plan skip_all => "Test::Pod 1.14 required for testing POD" if $@; all_pod_files_ok(); CipUX-Dog-3.4.0.0/t/00.load.t0000444000175000017500000000016211156472646015345 0ustar ckuelkerckuelkeruse Test::More tests => 1; BEGIN { use_ok('CipUX::Dog'); } diag("Testing CipUX::Dog $CipUX::Dog::VERSION"); CipUX-Dog-3.4.0.0/t/perlcritic.t0000444000175000017500000000043611156472646016354 0ustar ckuelkerckuelker#!perl use strict; use warnings; use Test::More; use English qw(-no_match_vars); eval { require Test::Perl::Critic; }; if ($EVAL_ERROR) { my $msg = 'Test::Perl::Critic required to for testing PBP compliance'; plan( skip_all => $msg ); } Test::Perl::Critic::all_critic_ok(); CipUX-Dog-3.4.0.0/Changes0000444000175000017500000000013511156472646015053 0ustar ckuelkerckuelkerRevision history for CipUX-Dog 3.4.0.0 Fri Sep 13 13:33:21 2009 Initial release. CipUX-Dog-3.4.0.0/MANIFEST0000444000175000017500000000030111156472646014704 0ustar ckuelkerckuelkerBuild.PL Changes lib/CipUX/Dog.pm Makefile.PL MANIFEST README t/00.load.t t/perlcritic.t t/perlcritic_cpan.t t/perlcriticrc t/pod-coverage.t t/pod.t usr/share/cipux/etc/cipux-dog.perl META.yml CipUX-Dog-3.4.0.0/usr/0000755000175000017500000000000011156472646014374 5ustar ckuelkerckuelkerCipUX-Dog-3.4.0.0/usr/share/0000755000175000017500000000000011156472646015476 5ustar ckuelkerckuelkerCipUX-Dog-3.4.0.0/usr/share/cipux/0000755000175000017500000000000011156472646016626 5ustar ckuelkerckuelkerCipUX-Dog-3.4.0.0/usr/share/cipux/etc/0000755000175000017500000000000011156472646017401 5ustar ckuelkerckuelkerCipUX-Dog-3.4.0.0/usr/share/cipux/etc/cipux-dog.perl0000444000175000017500000000447211156472646022171 0ustar ckuelkerckuelker# +=========================================================================+ # || /usr/share/cipux/etc/cipux-dog.perl || # || || # || Configuration of different external CipUX::Dog commands. || # || CipUX::Dog can optional be used by the CipUX task layer. || # || || # || || # +=========================================================================+ # do NOT change the ordering of the configuration sections my $prefix = "/usr/bin"; # %dog_cfg $cfg = { cipux_dogs => { # this will create a home dir and sync /etc/skel and the role skel create_homedir => { commands => { '1' => { 'shell' => $prefix . '/sometool_homedir_create', 'args' => [qw(--user @user@ --role @role@)], }, }, }, # this will restore a home dir from skel without deleting content # restore referes here to the skel perspective restore_homedir => { commands => [ '1' => { 'shell' => $prefix . '/sometool_homedir_restore', 'args' => [qw(--user @user@ --role @role@)], }, ], }, # this will make a backup, wipe out the homedir and then creates # it again and syncronize skels reset_homedir => { commands => [ '1' => { 'shell' => $prefix . '/sometool_homedir_backup', 'args' => [qw(--user @user@ --role @role@)], }, '2' => { 'shell' => $prefix . '/sometool_homedir_reset', 'args' => [qw(--user @user@ --role @role@)], }, ], }, }, }; # In future (not implemented jet) this might create a user with # "2nd Forbach Skel". You have to add a second "--skel %cipuxSkeletonUid" # to all relevant commands. Example: # commands => [ # 'sometool_homedir_reset --user %uid --skel %cipuxRole \ # --skel %cipuxSkeletonUid' # ], # CipUX-Dog-3.4.0.0/Build.PL0000444000175000017500000000247111156472646015061 0ustar ckuelkerckuelkeruse strict; use warnings; use Module::Build::CipUX; my $builder = Module::Build::CipUX->new( module_name => 'CipUX::Dog', license => 'gpl', dist_author => 'Christian Kuelker ', dist_version_from => 'lib/CipUX/Dog.pm', installdirs => 'vendor', # create_makefile_pl => 'traditional', # create_readme => 1, meta_merge => { resources => { homepage => q(http://www.cipux.org), }, }, recommends => { 'Test::Perl::Critic' => 0, 'Test::Pod::Coverage' => '1.04', }, build_requires => { 'File::Spec' => 0, 'Module::Build' => 0, 'Module::Build::CipUX' => '0.4.0', 'Test::More' => 0, 'Test::Pod' => '1.14', }, requires => { 'Carp' => 0, 'CipUX' => '3.4.0.0', 'Class::Std' => '0.0.9', 'Data::Dumper' => 0, 'English' => 0, 'Log::Log4perl' => '0.42', 'Readonly' => 0, 'version' => 0, }, add_to_cleanup => ['CipUX-Dog-*'], ); # Only to uncomment, if you changed the BUILD target # $builder->add_build_element('dat'); #$builder->do_create_readme(); #$builder->do_create_makefile_pl(); $builder->create_build_script(); CipUX-Dog-3.4.0.0/Makefile.PL0000444000175000017500000000017111156472646015532 0ustar ckuelkerckuelkeruse Module::Build::Compat; Module::Build::Compat->run_build_pl(args => \@ARGV); Module::Build::Compat->write_makefile(); CipUX-Dog-3.4.0.0/README0000444000175000017500000000150611156472646014443 0ustar ckuelkerckuelkerCipUX-Dog version 3.4.0.0 CipUX::Dog can be used to execute commands defined in a configuration file. For the CipUX::Task package hooks are defined for CipUX::Dog as an optionional package. INSTALLATION To install this module, run the following commands: perl Build.PL ./Build ./Build test ./Build install Alternatively, to install with ExtUtils::MakeMaker, you can use the following commands: perl Makefile.PL make make test make install DEPENDENCIES Carp CipUX Class::Std Data::Dumper English Log::Log4perl Readonly version COPYRIGHT AND LICENSE Copyright (C) 2008 - 2009, Christian Kuelker This library is licensed under the GNU GPL - GNU General Public License version 2 or later.