So it appears this is a Windows Cygwin problem only, trying to send a
password to a windows exe. All tests run successfully on linux and mac.
I have a feelings it has to do something with some way a windows shell takes
in passwords. I have a "temp" workaround for windows using the
Win32::GuiTest library to send key strokes to the shell. The support is
well appreciated for the feedback received. If anyone has any insight into
the problem for windows password prompts, I would be interested in the
feedback.
Thanks,
Jonathan
On Wed, Jul 21, 2010 at 4:07 PM, Jonathan <jwstric2@...> wrote:
> I had some requests for and to try; much appreciated. Here is the
> feedback:
>
> 1. Expect opening code:
>
> sub new
> {
> my $class = shift;
> my $exp=Expect->new;
> my $spawn_ok = 1;
>
> #$exp->raw_pty(1);
> #$exp->debug($vars{"debug"});
> $exp->log_stdout(1);
> $exp->spawn("$AnyConnectShellWrapper::Shell_Path") or die "Cannot
> spawn vpn shell $AnyConnectShellWrapper::Shell_Path : $!\n";
>
>
> my $self = {
>
> exp => $exp
>
> };
>
> $exp->expect(15,
> [
> 'VPN>',
> sub {
> $spawn_ok = 1;
> my $fh = shift;
>
> }
> ],
>
> [
> eof =>
> sub {
> if ($spawn_ok) {
>
> die "ERROR: premature EOF in vpn shell.\n";
> } else {
> die "ERROR: could not spawn vpn shell.\n";
> }
> }
> ],
> [
> timeout =>
> sub {
> die "No login.\n";
> }
> ]
> );
>
>
> bless $self, $class;
> return $self;
>
> }
>
>
> sub connect {
>
> if ($vars{"debug"}){
> print "Entering AnyConnectShellWrapper::connect\n";
>
> }
>
> my ($self, $hostname, $username, $password, $group) = @_;
> my $exp = $self->{exp};
> my $connected = 0;
> my $processed = 0;
>
> if ($vars{"debug"}){
>
> print "Username is $username\n";
> print "Password is $password\n";
> print "Group is $group\n";
> print "Hostname is $hostname\n";
> }
>
>
> #Make sure VPN is not already up
> if ($self->connected){
> return $connected;
> }
>
> $exp->send("connect $hostname\r");
> $exp->expect(15,
> [
> '-re','failed',
>
> sub {
> if ($vars{"debug"}){
>
> my $fh = shift;
>
> $connected = -1;
> print "AnyConnectShellWrapper::connect fatal login
> error, must destory shell\n";
>
> $self->destroy;
>
> }
> }
> ],
> [
> '-re','error',
>
> sub {
> if ($vars{"debug"}){
>
> my $fh = shift;
>
> $connected = -1;
> print "AnyConnectShellWrapper::connect fatal shell
> error, must destory shell\n";
>
> $self->destroy;
>
> }
> }
> ],
> [
> '-re','Username:\s*(.*)',
> sub {
> my $fh = shift;
> $fh->send("$username\r");
> exp_continue;
> }
> ],
> [
> '-re','Password:\s',
> sub {
> my $fh = shift;
> sleep 2;
> #This is jacked, we have to fix this, will not send
> password correct
> send_password($fh, $password);
> #$fh ->send("$password\r");
> exp_continue;
> }
> ],
> [
> '-re','state:.*Connected',
>
> sub {
> my $fh = shift;
> $connected = 1;
> if ($vars{"debug"}){
> print "AnyConnectShellWrapper::connect successful
> connect\n";
>
> }
>
> }
> ],
> [
> '-re','VPN>$',
> sub {
> my $fh = shift;
> exp_continue;
> }
>
> ],
> [
> eof =>
> sub {
> die "ERROR: premature EOF in vpn shell.\n";
> }
> ],
> [
> timeout =>
> sub {
> die "No prompt.\n";
> }
> ]
> );
> if ($vars{"debug"}){
> print "Exiting AnyConnectShellWrapper::connect with return code of
> $connected\n";
> }
>
> return $connected;
>
> }
>
>
>
>
> 2. Had some comments on my regular expressions, you guys are right. I
> should not be checking for Password:\s*, this wsa in there due to
> frustrations of trying to figure out why the password was not being
> accepted. Added back proper reg expression
>
> 3. Tried a recommendation to sleep to allow the application to prepare for
> password acceptance. See code.
>
> Thanks again,
> Jonathan
>
>
>
>
>
>
> > On Wed, Jul 21, 2010 at 09:39:50AM -0400, Jonathan wrote:
> >> I have an application, a client module that control a server module,
> >> that my group is automating tests for. This may be a cygwin problem,
> >> I will have to try on a cross platform system as the server/client
> >> model runs on Windows/Linux/Mac. However, does anyone have any
> >> insight into why I can't send a password to this application with
> >> cygwin.
> >>
> >> Output:
> >> VPN> connect as5505-1.testbed
> >> >> contacting host as5505-1.testbed.cisco.com) for login
> information...
> >> >> notice: Contactingas5505-1.testbed
> >> VPN>
> >> >> Please enter your username and password.
> >> Group: SSLVPNClient
> >>
> >> Username: [userA] userA
> >> Password: test123 ************************* this is the
> >> password, it picked up the password prompt but never is accepted.... I
> >> can enter keystroke right when displaying as test123 and it will
> >> connect.
> >> No prompt.
> >>
> >>
> >> Code:
> >>
> >> sub connect {
> >>
> >> if ($VpnHelper::Debug){
> >> print "Entering VpnHelper::connect\n";
> >> }
> >>
> >> my ($self, $hostname, $username, $password, $group) = @_;
> >> my $exp = $self->{exp};
> >> my $connected = 0;
> >>
> >> if ($VpnHelper::Debug){
> >> print "Username is $username\n";
> >> print "Password is $password\n";
> >> print "Group is $group\n";
> >> print "Hostname is $hostname\n";
> >> }
> >>
> >>
> >> #Make sure VPN is not already up
> >> if ($self->connected){
> >> return $connected;
> >> }
> >>
> >> $exp->send("connect $hostname\r");
> >> $exp->expect(15,
> >> [
> >> '-re','Username:\s*(.*)',
> >> sub {
> >> my $fh = shift;
> >> $fh->send("$username\r");
> >> exp_continue;
> >> }
> >> ],
> >> [
> >> '-re','Password:\s*',
> >> sub {
> >> my $fh = shift;
> >> $fh ->send("$password\r");
> >> exp_continue;
> >> }
> >> ],
> >> [
> >> '-re','state:\sConnected',
> >> sub {
> >> my $fh = shift;
> >> $connected = 1;
> >> exp_continue;
> >> }
> >> ],
> >> [
> >> '-re','VPN>',
> >> sub {
> >> my $fh = shift;
> >> exp_continue;
> >> }
> >>
> >> ],
> >>
> >> [
> >> eof =>
> >> sub {
> >> die "ERROR: premature EOF in vpn shell.\n";
> >> }
> >> ],
> >> [
> >> timeout =>
> >> sub {
> >> die "No prompt.\n";
> >> }
> >> ]
> >> );
> >>
> >> }
> >>
> >> Thank you in advance,
> >> Jonathan
> >>
> >>
> ------------------------------------------------------------------------------
> >> This SF.net email is sponsored by Sprint
> >> What will you do first with EVO, the first 4G phone?
> >> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
> >> _______________________________________________
> >> Expectperl-discuss mailing list
> >> Expectperl-discuss@...
> >> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss
> >
> > --
> > http://singinst.org/ : Our last, best hope for a fantastic future.
> > Lojban (http://www.lojban.org/): The language in which "this parrot
> > is dead" is "ti poi spitaki cu morsi", but "this sentence is false"
> > is "na nei". My personal page: http://www.digitalkingdom.org/rlp/
> >
>
>
|