This commit is contained in:
Denis Knauf 2010-09-27 16:42:03 +02:00
parent f4680dfd8d
commit 650cf81e71
3 changed files with 12 additions and 34 deletions

16
c.rb
View file

@ -15,18 +15,18 @@ class IO
end end
end end
class String
def shdump
"'#{gsub( /[\\']/, '\'\\\\\&\'')}'"
end
end
class File class File
def self.readall file def self.readall file
open( file) {|f| f.readall } open( file) {|f| f.readall }
end end
end end
class String
def shdump
"'#{gsub( /[\\']/, '\'\\\\\&\'')}'"
end
end
$tor = tor = IO.pipe $tor = tor = IO.pipe
$tos = tos = IO.pipe $tos = tos = IO.pipe
@ -38,10 +38,6 @@ if Process.fork
$stderr.puts( {proc: 'c', connect: ARGV[0], args: ARGV[1]}.to_json) $stderr.puts( {proc: 'c', connect: ARGV[0], args: ARGV[1]}.to_json)
exec 'ssh', ARGV[0], 'perl', '-e', File.readall( 's.pl').shdump, ARGV[1].shdump exec 'ssh', ARGV[0], 'perl', '-e', File.readall( 's.pl').shdump, ARGV[1].shdump
else else
#$stdout.puts 'test'
#$stderr.print '>> '
#$stdin.each_line {|l| p eval( l); print '>> ' }
$stdin.reopen tos.first $stdin.reopen tos.first
tos.last.close tos.last.close
$stdout.reopen tor.last $stdout.reopen tor.last

18
r.pl
View file

@ -5,19 +5,11 @@ use warnings;
$|++; $|++;
$SIG{CLD} = sub { $SIG{CLD} = sub {
printf STDERR "{proc: \"r\", action: \"child_died\"}\n";
wait; wait;
printf STDERR "{proc: \"r\", action: \"exit\", code: 0}\n"; printf STDERR "{proc: \"r\", action: \"exit\", code: 1, error: \"child_died\"}\n";
exit 0; exit 1;
}; };
my @cmds = (
1 => 'file',
2 => 'content'
);
print STDERR "r << s";
sub readcmd { sub readcmd {
my $data = ''; my $data = '';
while( length( $data) < 6) { while( length( $data) < 6) {
@ -27,21 +19,17 @@ sub readcmd {
} }
while( my$data = readcmd) { while( my$data = readcmd) {
printf STDERR "{proc: \"r\", read_length: %d}\n", length( $data);
(my$cmd, my$length) = unpack( 'nN', $data); (my$cmd, my$length) = unpack( 'nN', $data);
print STDERR "{cmd: $cmd, length: $length}\n"; print STDERR "{cmd: $cmd, length: $length}\n";
print STDERR "r << s\n";
read STDIN, $data, $length; read STDIN, $data, $length;
if( 1 == $cmd) { if( 1 == $cmd) {
print STDERR "{proc: \"r\", action: \"open_file\", file: \"$data\"}\n"; print STDERR "{proc: \"r\", action: \"open\", file: \"$data\"}\n";
open( F, '>>', $data) or print STDERR ("{proc: \"r\", error: \"unable_to_open_file\", message: \"Can't open file <$data>.\"}\n"); open( F, '>>', $data) or print STDERR ("{proc: \"r\", error: \"unable_to_open_file\", message: \"Can't open file <$data>.\"}\n");
my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks) = stat F; $atime,$mtime,$ctime,$blksize,$blocks) = stat F;
print STDERR "r >> s\n";
print pack( 'N', $size); print pack( 'N', $size);
} }
elsif( 2 == $cmd) { elsif( 2 == $cmd) {
print STDERR "r >> f\n";
print F $data; print F $data;
} }
else { else {

12
s.pl
View file

@ -4,8 +4,6 @@ use strict;
use warnings; use warnings;
$|++; $|++;
my%cmds = (file => 1, content => 2);
my$dir = shift @ARGV; my$dir = shift @ARGV;
$dir =~ /^(\/.*)\/([^\/]+)$/ or die( "{proc: \"s\", error: \"invalid_path_expression\", message: \"Path-Expression is invalid.\"}\n"); $dir =~ /^(\/.*)\/([^\/]+)$/ or die( "{proc: \"s\", error: \"invalid_path_expression\", message: \"Path-Expression is invalid.\"}\n");
($dir, my$fexpr) = ($1, $2); ($dir, my$fexpr) = ($1, $2);
@ -15,18 +13,14 @@ opendir( my$dh, '.') || die "{proc: \"s\", error: \"dir_not_found\", message: \"
while( my$filename = readdir( $dh)) { while( my$filename = readdir( $dh)) {
$filename =~ /$fexpr/ or next; $filename =~ /$fexpr/ or next;
-f $filename or next; -f $filename or next;
print STDERR "s >> r\n"; print pack( 'nN/A*', 1, $filename);
print pack( 'nN/A*', $cmds{file}, $filename);
print STDERR "{proc: \"s\", action: \"open\", file: \"$filename\"}\n"; print STDERR "{proc: \"s\", action: \"open\", file: \"$filename\"}\n";
open F, $filename; open F, $filename;
print STDERR "s << r\n";
read STDIN, my$length, 4; # Was wenn < 4 ? read STDIN, my$length, 4; # Was wenn < 4 ?
$length = unpack 'N', $length; $length = unpack 'N', $length;
print STDERR "s: seek $length\n";
seek F, $length, 0; seek F, $length, 0;
print STDERR "s >>>> r\n"; while( read( F, my$r, 2040)) {
while( read( F, my$r, 2048)) { print pack( 'nN/A*', 2, $r);
print pack( 'nN/(A*)', $cmds{content}, $r);
} }
print STDERR "{proc: \"s\", action: \"close\", file: \"$filename\"}\n"; print STDERR "{proc: \"s\", action: \"close\", file: \"$filename\"}\n";
close F; close F;