| 2 |
## $Id$ |
## $Id$ |
| 3 |
## ---------------------------------------------------------------------- |
## ---------------------------------------------------------------------- |
| 4 |
## $Log$ |
## $Log$ |
| 5 |
|
## Revision 1.9 2003/04/04 17:23:11 joko |
| 6 |
|
## minor update: debugging output |
| 7 |
|
## |
| 8 |
|
## Revision 1.8 2003/03/29 07:11:54 joko |
| 9 |
|
## modified: sub run_executable |
| 10 |
|
## new: sub run_script |
| 11 |
|
## |
| 12 |
## Revision 1.7 2003/03/28 07:02:56 joko |
## Revision 1.7 2003/03/28 07:02:56 joko |
| 13 |
## modified structure around '$wrapper_program' |
## modified structure around '$wrapper_program' |
| 14 |
## |
## |
| 48 |
|
|
| 49 |
use shortcuts qw( run_cmd ); |
use shortcuts qw( run_cmd ); |
| 50 |
use Data::Mungle::Code::Ref qw( ref_slot ); |
use Data::Mungle::Code::Ref qw( ref_slot ); |
| 51 |
use Data::Mungle::Transform::Deep qw( expand ); |
use Data::Mungle::Transform::Deep qw( expand deep_copy ); |
| 52 |
|
use File::Temp qw/ tempfile tempdir /; |
| 53 |
|
|
| 54 |
|
|
| 55 |
sub performTarget { |
sub performTarget { |
| 64 |
|
|
| 65 |
my $header = ("- " x 12) . " " . $targetname . " " . ("- " x 6); |
my $header = ("- " x 12) . " " . $targetname . " " . ("- " x 6); |
| 66 |
|
|
| 67 |
|
# V1 |
| 68 |
#$self->log("- " x 35, 'notice'); |
#$self->log("- " x 35, 'notice'); |
| 69 |
#$self->log("Performing Target '$targetname'.", 'notice'); |
#$self->log("Performing Target '$targetname'.", 'notice'); |
| 70 |
|
|
| 71 |
$self->log($header, 'notice'); |
# V2 |
| 72 |
|
#$self->log($header, 'notice'); |
| 73 |
|
|
| 74 |
|
# V3 |
| 75 |
|
$self->log("- " x 20, 'info'); |
| 76 |
|
$self->log("Performing Target '$targetname'.", 'notice'); |
| 77 |
|
|
| 78 |
#exit; |
#exit; |
| 79 |
|
|
| 116 |
foreach my $entry (@{$target->{content}}) { |
foreach my $entry (@{$target->{content}}) { |
| 117 |
my $command = $entry->{name}; |
my $command = $entry->{name}; |
| 118 |
my $args = $entry->{attrib}; |
my $args = $entry->{attrib}; |
| 119 |
$self->perform_command($command, $args); |
my $content = $entry->{content}; |
| 120 |
|
$self->perform_command($command, $args, $content); |
| 121 |
# check recursiveness |
# check recursiveness |
| 122 |
if ($entry->{content} && ref $entry->{content}) { |
if ($entry->{content} && ref $entry->{content}) { |
| 123 |
$self->perform_details($entry); |
$self->perform_details($entry); |
| 133 |
sub perform_command { |
sub perform_command { |
| 134 |
my $self = shift; |
my $self = shift; |
| 135 |
my $command = shift; |
my $command = shift; |
| 136 |
|
my $args_list = shift; |
| 137 |
|
my $content = shift; |
| 138 |
|
|
| 139 |
if (!$command) { |
if (!$command) { |
| 140 |
$self->log("Command was empty!", 'debug'); |
$self->log("Command was empty!", 'debug'); |
| 144 |
# FIXME: make '__PACKAGE__' go one level deeper properly! |
# FIXME: make '__PACKAGE__' go one level deeper properly! |
| 145 |
$self->log( __PACKAGE__ . "->perform_command: " . $command, 'debug'); |
$self->log( __PACKAGE__ . "->perform_command: " . $command, 'debug'); |
| 146 |
|
|
|
my $args_list = shift; |
|
| 147 |
my $args = {}; |
my $args = {}; |
| 148 |
#print Dumper($args_list); |
#print Dumper($args_list); |
| 149 |
if ($args_list) { |
if ($args_list) { |
| 163 |
$container ||= $self; |
$container ||= $self; |
| 164 |
|
|
| 165 |
if ($container->can($command)) { |
if ($container->can($command)) { |
| 166 |
$container->$command($args); |
$container->$command($args, $content); |
| 167 |
} else { |
} else { |
| 168 |
$self->log("Command '$command' not implemented.", "warning"); |
$self->log("Command '$command' not implemented.", "warning"); |
| 169 |
} |
} |
| 316 |
my $self = shift; |
my $self = shift; |
| 317 |
my $opts = shift; |
my $opts = shift; |
| 318 |
|
|
| 319 |
|
my $meta = deep_copy($opts); |
| 320 |
|
|
| 321 |
|
delete $opts->{caption}; |
| 322 |
|
delete $opts->{async}; |
| 323 |
|
|
| 324 |
|
#print Dumper($meta); |
| 325 |
|
|
| 326 |
if ($opts->{executable}) { |
if ($opts->{executable}) { |
| 327 |
|
|
| 328 |
my $program = $opts->{executable}; |
my $program = $opts->{executable}; |
| 378 |
#run_cmd($cmd); |
#run_cmd($cmd); |
| 379 |
|
|
| 380 |
# V1.b - enhanced: variable local method |
# V1.b - enhanced: variable local method |
| 381 |
my $evalstr = "run_cmd('$cmd', 'Some task...', { async => 1 });"; |
$meta->{caption} ||= ''; |
| 382 |
|
$meta->{async} ||= 0; |
| 383 |
|
my $evalstr = "run_cmd('$cmd', '$meta->{caption}', { async => $meta->{async} });"; |
| 384 |
eval($evalstr); |
eval($evalstr); |
| 385 |
#my $res = do "$cmd"; |
#my $res = do "$cmd"; |
| 386 |
#print $res, "\n" if $res; |
#print $res, "\n" if $res; |
| 397 |
} |
} |
| 398 |
|
|
| 399 |
|
|
| 400 |
|
sub run_script { |
| 401 |
|
|
| 402 |
|
my $self = shift; |
| 403 |
|
my $args = shift; |
| 404 |
|
my $code = shift; |
| 405 |
|
|
| 406 |
|
if ($args->{language} eq 'msdos/bat') { |
| 407 |
|
|
| 408 |
|
#print "code: $code", "\n"; |
| 409 |
|
|
| 410 |
|
# reporting |
| 411 |
|
$self->log("Executing some arbitrary unsigned code (probably unsafe). [language=$args->{language}]", 'info'); |
| 412 |
|
$self->log("\n<code>\n$code\n</code>", 'info'); |
| 413 |
|
|
| 414 |
|
# create temporary intermediate file to execute code |
| 415 |
|
my $tmpdir = '/tmp/rap'; |
| 416 |
|
mkdir $tmpdir; |
| 417 |
|
(my $fh, my $filename) = tempfile( DIR => $tmpdir, SUFFIX => '.bat' ); |
| 418 |
|
print $fh $code, "\n"; |
| 419 |
|
run_cmd( $filename, '', { async => 1 } ); |
| 420 |
|
|
| 421 |
|
# FIXME: DELETE code inside temp-files as soon as possible! |
| 422 |
|
#print $fh ''; |
| 423 |
|
|
| 424 |
|
# TODO: delete FILE completely! |
| 425 |
|
# required for this: wait until execution has finished, then unlink.... |
| 426 |
|
# but: "how to wait until execution is finished"? |
| 427 |
|
# i believe the best is to spawn *another* process directly from here, |
| 428 |
|
# let's call it 'watcher-agent'. |
| 429 |
|
# This one should monitor a certain running process and delete its |
| 430 |
|
# executable file after it has finished execution. |
| 431 |
|
# Possible extensions could be: |
| 432 |
|
# keep track of all stuff sent to STDOUT or STDERR and |
| 433 |
|
# send that stuff to the task-owner indirectly (not via shell/console) |
| 434 |
|
# (e.g. via email, by posting report to a newsgroup or publishing on a specified web-page: use mod-dav!) |
| 435 |
|
|
| 436 |
|
} elsif ($args->{language} eq 'bash') { |
| 437 |
|
$self->log("FIXME: - - - - - -- - - -- BASH - - - - - - - -- - ", 'error'); |
| 438 |
|
|
| 439 |
|
} else { |
| 440 |
|
$self->log("FIXME: Script language '$args->{language}' not implemented.", 'error'); |
| 441 |
|
|
| 442 |
|
} |
| 443 |
|
|
| 444 |
|
} |
| 445 |
|
|
| 446 |
1; |
1; |
| 447 |
__END__ |
__END__ |