This commit is contained in:
Denis Knauf 2010-09-27 13:40:21 +02:00
commit 46cd565e34
3 changed files with 49 additions and 0 deletions

14
c.rb Executable file
View file

@ -0,0 +1,14 @@
#!/usr/bin/env ruby
tor = IO.pipe
tos = IO.pipe
fork do
$stdin.reopen tor.first
$stdout.reopen tos.last
exec 'ssh', ARGV[0], 'perl', 'r.pl', ARGV[1]
end
$stdin.reopen tos.first
$stdout.reopen tor.last
exec 'perl', 's.pl', ARGV[2]

18
r.pl Executable file
View file

@ -0,0 +1,18 @@
#!/usr/bin/env perl
while( read STDIN, my $data, 6) {
my( $cmd, $length) = unpack 'nN', $data;
read STDIN, my $data, $length;
if( 1 == $cmd) {
print STDERR "{action: \"open_file\", file: \"$data\"}";
open( F, '>>', $data) or print STDERR ("{error: \"unable_to_open_file\", message: \"Can't open file <$data>.\"}");
my( $dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks) = stat F;
print pack( 'N', $size);
}
elsif( 2 == $cmd) {
print F, $data;
}
else
exit(1);
}

17
s.pl Executable file
View file

@ -0,0 +1,17 @@
#!/usr/bin/env perl
my $dir = shift @ARGS;
$dir =~ /^(\/.*)\/[^/]*$/ or die( '{error: "invalid_path_expression", message: "Path-Expression is invalid."}');
$dir, my $fexpr = $1, $2;
$fexpr = /$fexpr/;
opendir( my $dh, $dir) || die '{error: "dir_not_found", message: "Directory not found."}';
while( $filename = readdir( $dh)) {
print pack( 'nN/(A*)', 1, $filename);
open F, $filename;
read STDIN, my $length, 4; # Was wenn < 4 ?
seek F, $length, SEEK_SET;
print pack( 'nN/(A*)', 2, $r) while read( F, $r, 2048);
close F;
}
closedir $dh;