synced
This commit is contained in:
parent
7d602e5e31
commit
f4680dfd8d
26
c.rb
26
c.rb
|
@ -1,5 +1,7 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
require 'json'
|
||||||
|
|
||||||
class IO
|
class IO
|
||||||
def readall
|
def readall
|
||||||
buf = ''
|
buf = ''
|
||||||
|
@ -25,15 +27,25 @@ class File
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
tor = IO.pipe
|
$tor = tor = IO.pipe
|
||||||
tos = IO.pipe
|
$tos = tos = IO.pipe
|
||||||
|
|
||||||
fork do
|
if Process.fork
|
||||||
$stdin.reopen tor.first
|
$stdin.reopen tor.first
|
||||||
|
tor.last.close
|
||||||
$stdout.reopen tos.last
|
$stdout.reopen tos.last
|
||||||
|
tos.first.close
|
||||||
|
$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
|
||||||
end
|
else
|
||||||
|
#$stdout.puts 'test'
|
||||||
|
#$stderr.print '>> '
|
||||||
|
#$stdin.each_line {|l| p eval( l); print '>> ' }
|
||||||
|
|
||||||
$stdin.reopen tos.first
|
$stdin.reopen tos.first
|
||||||
$stdout.reopen tor.last
|
tos.last.close
|
||||||
exec 'perl', 'r.pl', ARGV[2].shdump
|
$stdout.reopen tor.last
|
||||||
|
tor.first.close
|
||||||
|
$stderr.puts( {proc: 'c', exec: 'reciever', destination: ARGV[2]}.to_json)
|
||||||
|
exec 'perl', 'r.pl', ARGV[2].shdump
|
||||||
|
end
|
||||||
|
|
39
r.pl
39
r.pl
|
@ -1,16 +1,47 @@
|
||||||
#!/usr/bin/env perl
|
#!/usr/bin/env perl
|
||||||
|
|
||||||
while( read( STDIN, my $data, 6)) {
|
use strict;
|
||||||
my( $cmd, $length) = unpack 'nN', $data;
|
use warnings;
|
||||||
read STDIN, my $data, $length;
|
$|++;
|
||||||
|
|
||||||
|
$SIG{CLD} = sub {
|
||||||
|
printf STDERR "{proc: \"r\", action: \"child_died\"}\n";
|
||||||
|
wait;
|
||||||
|
printf STDERR "{proc: \"r\", action: \"exit\", code: 0}\n";
|
||||||
|
exit 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
my @cmds = (
|
||||||
|
1 => 'file',
|
||||||
|
2 => 'content'
|
||||||
|
);
|
||||||
|
|
||||||
|
print STDERR "r << s";
|
||||||
|
|
||||||
|
sub readcmd {
|
||||||
|
my $data = '';
|
||||||
|
while( length( $data) < 6) {
|
||||||
|
read( STDIN, $data, 6-length($data), length($data)) or return(0);
|
||||||
|
}
|
||||||
|
$data;
|
||||||
|
}
|
||||||
|
|
||||||
|
while( my$data = readcmd) {
|
||||||
|
printf STDERR "{proc: \"r\", read_length: %d}\n", length( $data);
|
||||||
|
(my$cmd, my$length) = unpack( 'nN', $data);
|
||||||
|
print STDERR "{cmd: $cmd, length: $length}\n";
|
||||||
|
print STDERR "r << s\n";
|
||||||
|
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\", 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 {
|
||||||
|
|
33
s.pl
33
s.pl
|
@ -1,22 +1,33 @@
|
||||||
#!/usr/bin/env perl
|
#!/usr/bin/env perl
|
||||||
|
|
||||||
my $dir = shift @ARGV;
|
use strict;
|
||||||
$dir =~ /^(\/.*)\/([^\/]+)$/ or die( "{proc: \"s\", error: \"invalid_path_expression\", message: \"Path-Expression is invalid.\"}\n");
|
use warnings;
|
||||||
($dir, my( $fexpr)) = ($1, $2);
|
$|++;
|
||||||
|
|
||||||
print STDERR $fexpr;
|
my%cmds = (file => 1, content => 2);
|
||||||
|
|
||||||
|
my$dir = shift @ARGV;
|
||||||
|
$dir =~ /^(\/.*)\/([^\/]+)$/ or die( "{proc: \"s\", error: \"invalid_path_expression\", message: \"Path-Expression is invalid.\"}\n");
|
||||||
|
($dir, my$fexpr) = ($1, $2);
|
||||||
|
|
||||||
chdir( $dir) or die( "{proc: \"s\", error: \"change_directory\", value: \"$dir\", message: \"$!\"}\n");
|
chdir( $dir) or die( "{proc: \"s\", error: \"change_directory\", value: \"$dir\", message: \"$!\"}\n");
|
||||||
opendir( my( $dh), '.') || die "{proc: \"s\", error: \"dir_not_found\", message: \"Directory not found.\"}\n";
|
opendir( my$dh, '.') || die "{proc: \"s\", error: \"dir_not_found\", message: \"Directory not found.\"}\n";
|
||||||
while( $filename = readdir( $dh)) {
|
while( my$filename = readdir( $dh)) {
|
||||||
print STDERR "{proc: \"s\", action: \"find\", file: \"$filename\"}\n";
|
|
||||||
$filename =~ /$fexpr/ or next;
|
$filename =~ /$fexpr/ or next;
|
||||||
print pack( 'nN/(A*)', 1, $filename);
|
-f $filename or next;
|
||||||
|
print STDERR "s >> r\n";
|
||||||
|
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;
|
||||||
read STDIN, my $length, 4; # Was wenn < 4 ?
|
print STDERR "s << r\n";
|
||||||
seek F, $length, SEEK_SET;
|
read STDIN, my$length, 4; # Was wenn < 4 ?
|
||||||
print pack( 'nN/(A*)', 2, $r) while read( F, $r, 2048);
|
$length = unpack 'N', $length;
|
||||||
|
print STDERR "s: seek $length\n";
|
||||||
|
seek F, $length, 0;
|
||||||
|
print STDERR "s >>>> r\n";
|
||||||
|
while( read( F, my$r, 2048)) {
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue