--- nfo/perl/libs/Data/Rap/Engine.pm 2003/03/28 07:02:56 1.7 +++ nfo/perl/libs/Data/Rap/Engine.pm 2003/03/29 07:11:54 1.8 @@ -1,7 +1,11 @@ ## ---------------------------------------------------------------------- -## $Id: Engine.pm,v 1.7 2003/03/28 07:02:56 joko Exp $ +## $Id: Engine.pm,v 1.8 2003/03/29 07:11:54 joko Exp $ ## ---------------------------------------------------------------------- ## $Log: Engine.pm,v $ +## Revision 1.8 2003/03/29 07:11:54 joko +## modified: sub run_executable +## new: sub run_script +## ## Revision 1.7 2003/03/28 07:02:56 joko ## modified structure around '$wrapper_program' ## @@ -41,7 +45,8 @@ use shortcuts qw( run_cmd ); use Data::Mungle::Code::Ref qw( ref_slot ); -use Data::Mungle::Transform::Deep qw( expand ); +use Data::Mungle::Transform::Deep qw( expand deep_copy ); +use File::Temp qw/ tempfile tempdir /; sub performTarget { @@ -56,10 +61,16 @@ my $header = ("- " x 12) . " " . $targetname . " " . ("- " x 6); + # V1 #$self->log("- " x 35, 'notice'); #$self->log("Performing Target '$targetname'.", 'notice'); - $self->log($header, 'notice'); + # V2 + #$self->log($header, 'notice'); + + # V3 + $self->log("- " x 35, 'info'); + $self->log("Performing Target '$targetname'.", 'notice'); #exit; @@ -102,7 +113,8 @@ foreach my $entry (@{$target->{content}}) { my $command = $entry->{name}; my $args = $entry->{attrib}; - $self->perform_command($command, $args); + my $content = $entry->{content}; + $self->perform_command($command, $args, $content); # check recursiveness if ($entry->{content} && ref $entry->{content}) { $self->perform_details($entry); @@ -118,6 +130,8 @@ sub perform_command { my $self = shift; my $command = shift; + my $args_list = shift; + my $content = shift; if (!$command) { $self->log("Command was empty!", 'debug'); @@ -127,7 +141,6 @@ # FIXME: make '__PACKAGE__' go one level deeper properly! $self->log( __PACKAGE__ . "->perform_command: " . $command, 'debug'); - my $args_list = shift; my $args = {}; #print Dumper($args_list); if ($args_list) { @@ -147,7 +160,7 @@ $container ||= $self; if ($container->can($command)) { - $container->$command($args); + $container->$command($args, $content); } else { $self->log("Command '$command' not implemented.", "warning"); } @@ -300,6 +313,13 @@ my $self = shift; my $opts = shift; + my $meta = deep_copy($opts); + + delete $opts->{caption}; + delete $opts->{async}; + + #print Dumper($meta); + if ($opts->{executable}) { my $program = $opts->{executable}; @@ -355,7 +375,9 @@ #run_cmd($cmd); # V1.b - enhanced: variable local method - my $evalstr = "run_cmd('$cmd', 'Some task...', { async => 1 });"; + $meta->{caption} ||= ''; + $meta->{async} ||= 0; + my $evalstr = "run_cmd('$cmd', '$meta->{caption}', { async => $meta->{async} });"; eval($evalstr); #my $res = do "$cmd"; #print $res, "\n" if $res; @@ -372,5 +394,51 @@ } +sub run_script { + + my $self = shift; + my $args = shift; + my $code = shift; + + if ($args->{language} eq 'msdos/bat') { + + #print "code: $code", "\n"; + + # reporting + $self->log("Executing some arbitrary unsigned code (probably unsafe). [language=$args->{language}]", 'info'); + $self->log("\n\n$code\n", 'info'); + + # create temporary intermediate file to execute code + my $tmpdir = '/tmp/rap'; + mkdir $tmpdir; + (my $fh, my $filename) = tempfile( DIR => $tmpdir, SUFFIX => '.bat' ); + print $fh $code, "\n"; + run_cmd( $filename, '', { async => 1 } ); + + # FIXME: DELETE code inside temp-files as soon as possible! + #print $fh ''; + + # TODO: delete FILE completely! + # required for this: wait until execution has finished, then unlink.... + # but: "how to wait until execution is finished"? + # i believe the best is to spawn *another* process directly from here, + # let's call it 'watcher-agent'. + # This one should monitor a certain running process and delete its + # executable file after it has finished execution. + # Possible extensions could be: + # keep track of all stuff sent to STDOUT or STDERR and + # send that stuff to the task-owner indirectly (not via shell/console) + # (e.g. via email, by posting report to a newsgroup or publishing on a specified web-page: use mod-dav!) + + } elsif ($args->{language} eq 'bash') { + $self->log("FIXME: - - - - - -- - - -- BASH - - - - - - - -- - ", 'error'); + + } else { + $self->log("FIXME: Script language '$args->{language}' not implemented.", 'error'); + + } + +} + 1; __END__