summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2009-07-03 23:05:07 -0500
committerJesse Luehrs <doy@tozt.net>2009-07-03 23:05:07 -0500
commit7d6ebe0833f62cae9ed5e4007935776808c29fd3 (patch)
treee6841de9d35e0c891de2b5d8d2441a38e7232ee5
parent3673f0638493b84e0f30149987c246e85a403068 (diff)
downloadapp-termcast-7d6ebe0833f62cae9ed5e4007935776808c29fd3.tar.gz
app-termcast-7d6ebe0833f62cae9ed5e4007935776808c29fd3.zip
first stab at implementation
-rw-r--r--lib/App/Termcast.pm63
1 files changed, 63 insertions, 0 deletions
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;