From 7d6ebe0833f62cae9ed5e4007935776808c29fd3 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 3 Jul 2009 23:05:07 -0500 Subject: first stab at implementation --- lib/App/Termcast.pm | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/lib/App/Termcast.pm b/lib/App/Termcast.pm index 34179df..9f7adca 100644 --- a/lib/App/Termcast.pm +++ b/lib/App/Termcast.pm @@ -1,5 +1,9 @@ package App::Termcast; use Moose; +use IO::Pty::Easy; +use IO::Socket::INET; +use Term::ReadKey; +with 'MooseX::Getopt'; =head1 NAME @@ -13,6 +17,65 @@ App::Termcast - =cut +has host => ( + is => 'rw', + isa => 'Str', + default => 'noway.ratry.ru', +); + +has port => ( + is => 'rw', + isa => 'Int', + default => 31337, +); + +has user => ( + is => 'rw', + isa => 'Str', + default => sub { $ENV{USER} }, +); + +has password => ( + is => 'rw', + isa => 'Str', + default => 'asdf', # really unimportant +); + +sub run { + my $self = shift; + my @argv = @{ $self->extra_argv }; + push @argv, ($ENV{SHELL} || '/bin/sh') if !@argv; + + ReadMode 3; + + my $socket = IO::Socket::INET->new(PeerAddr => $self->host, + PeerPort => $self->port); + $socket->write('hello '.$self->user.' '.$self->password."\n"); + + my $pty = IO::Pty::Easy->new; + $pty->spawn(@argv); + + my ($rin, $rout) = ''; + vec($rin, fileno(STDIN) ,1) = 1; + vec($rin, fileno($pty->{pty}), 1) = 1; + while (1) { + my $ready = select($rout = $rin, undef, undef, undef); + if (vec($rout, fileno(STDIN), 1)) { + my $buf; + sysread STDIN, $buf, 4096; + $pty->write($buf); + } + if (vec($rout, fileno($pty->{pty}), 1)) { + my $buf = $pty->read(0); + syswrite STDOUT, $buf; + $socket->write($buf); + } + } + if ($!) { + warn "Error reading: $!\n"; + } +} + __PACKAGE__->meta->make_immutable; no Moose; -- cgit v1.2.3-54-g00ecf