Net-FullAuto

 view release on metacpan or  search on metacpan

lib/Net/FullAuto/FA_Core.pm  view on Meta::CPAN

                  check_for_amazon_localhost $OUTPUT
                  get_amazon_external_ip $random
                  fa_welcome get_isets cmd_raw
                  connect_berkeleydb $dashboard
                  clean_filehandle);

{
   no warnings;
   use BerkeleyDB;
   use Sys::Hostname;
   our $local_hostname=&Sys::Hostname::hostname();
   use Data::Dump::Streamer;
   use Devel::StackTrace;
   use Time::Local;
   use Crypt::CBC;
   use Crypt::DES;
   use Cwd qw(getcwd);
   use Digest::MD5 qw(md5);
   use Digest::SHA qw(sha256_hex);
   use English;
   use Email::Sender::Simple qw(sendmail);
   use Email::Sender::Transport::SMTP qw();
   use Errno qw(EAGAIN EINTR EWOULDBLOCK);
   use File::HomeDir;
   use File::stat;
   use File::Copy;
   use MIME::Entity;
   use Module::Load::Conditional qw[can_load];
   use Net::Telnet;
   use Getopt::Long;
   use Pod::Usage;
   use Proc::ProcessTable;
   use Term::ReadKey;
   use Term::RawInput;
   use LWP::UserAgent ();
   use LWP::MediaTypes qw(guess_media_type media_suffix);
   use URI ();
   use HTTP::Date ();
   use IO::Handle;
   use IO::Select;
   use IO::Capture::Stderr;
   use Capture::Tiny;
   use String::Random;
   use Symbol qw(qualify_to_ref);
   use Tie::Cache;
   use IO::Pty;
   use POSIX qw(setsid uname getuid geteuid);
   use Want qw(howmany);

};

our $home_dir='~';
if (exists $ENV{HOME} && -d $ENV{HOME}) {
   $home_dir=$ENV{HOME};
} elsif (exists $ENV{USER} && $ENV{USER}) {
   if (-d "/home/$ENV{USER}") {
      $home_dir="/home/$ENV{USER}";
   } elsif (-d "/export/home/$ENV{USER}") {
      $home_dir="/export/home/$ENV{USER}";
   }
} elsif ((getpwuid($<))[7]) {
   $home_dir=(getpwuid($<))[7];
}

BEGIN {

   my $md_='';our $thismonth='';our $thisyear='';
   ($md_,$thismonth,$thisyear)=(localtime)[3,4,5];
   my $mo_=$thismonth;my $yr_=$thisyear;
   $md_="0$md_" if $md_<10;
   $mo_++;$mo_="0$mo_" if $mo_<10;
   my $yr__=sprintf("%02d",$yr_%100);
   my $yr____=(1900+$yr_);
   my $mdy="$mo_$md_$yr__";
   my $mdyyyy="$mo_$md_$yr____";
   my $tm=scalar localtime($^T);
   my $hms=substr($tm,11,8);
   $hms=~s/^(\d\d):(\d\d):(\d\d)$/h${1}m${2}s${3}/;
   my $hr=$1;my $mn=$2;my $sc=$3;
   our $curyear=$thisyear + 1900;
   our $curcen=unpack('a2',$curyear);
   our @invoked=($^T, $tm, $mdy, $hms, $hr, $mn, $sc, $mdyyyy);
   my $customdir='Net/FullAuto/Custom';

   our $fa_conf='';
   if (defined $Term::Menus::fa_conf) {
      $fa_conf=$Term::Menus::fa_conf;
      if (ref $fa_conf eq 'ARRAY' && defined $fa_conf->[0]) {
         eval {
            require $fa_conf->[0];
            my $mod=substr($fa_conf->[0],(rindex $fa_conf->[0],'/')+1,-3);
            import $mod;
            $fa_conf=$mod.'.pm';
         };
      }
   }

   our $fa_host='';
   if (defined $Term::Menus::fa_host) {
      $fa_host=$Term::Menus::fa_host;
      if (ref $fa_host eq 'ARRAY' && defined $fa_host->[0]) {
         eval {
            require $fa_host->[0];
            my $mod=substr($fa_host->[0],(rindex $fa_host->[0],'/')+1,-3);
            import $mod;
            $fa_host=$mod.'.pm';
         };
      }
   }

   our $fa_menu='';
   if (defined $Term::Menus::fa_menu) {
      $fa_menu=$Term::Menus::fa_menu;
      if (ref $fa_menu eq 'ARRAY' && defined $fa_menu->[0]) {
         eval {
            require $fa_menu->[0];
            my $mod=substr($fa_menu->[0],(rindex $fa_menu->[0],'/')+1,-3);
            import $mod;
            $fa_menu=$mod.'.pm';
         };
      }
   }

lib/Net/FullAuto/FA_Core.pm  view on Meta::CPAN

      }
   }
   if ($param_two eq 'ALRM') {
      print "\nINFO: Going to pkill"
         if !$Net::FullAuto::FA_Core::cron &&
         $Net::FullAuto::FA_Core::debug;
      print $Net::FullAuto::FA_Core::LOG
         "\nINFO: Going to pkill"
         if $Net::FullAuto::FA_Core::log &&
         -1<index $Net::FullAuto::FA_Core::LOG,'*';
      my $pkill=$Net::FullAuto::FA_Core::gbp->('pkill');
      exec "$pkill/pkill fullauto.pl";#<-DO NOT REMOVE
   }
   return 1 if $param_one eq '__return__';#<-DO NOT REMOVE
   exit 1 if $param_one;#<-DO NOT REMOVE
   exit 0;#<-DO NOT REMOVE

};

# Handle INT SIGNAL interruption
$SIG{ INT } = sub{
                    print "\n\nSIG INT CALLER=".caller."\n";
      my $trace = Devel::StackTrace->new();
      print "\nINFO: SIG INT (((((((CALLER))))))):\n       ",
      $trace->as_string(),"\n\n";

                    print "\n\nCAUGHT AN INTERUPT SIGNAL!!\n";
                    print $Net::FullAuto::FA_Core::LOG
                       "\n\n=============================",
                       "\n====   INTERUPT SIGNAL   ====",
                       "\n=============================\n\n",
                       if $Net::FullAuto::FA_Core::log &&
                       -1<index $Net::FullAuto::FA_Core::LOG,'*';
                    unlink $ENV{FA_ACQUIRING_BERKELEY_DB_LOCK}
                       if exists $ENV{FA_ACQUIRING_BERKELEY_DB_LOCK};
                    &release_fa_lock(6543);
                    $cleanup=1;&cleanup('','INT') };
our $alarm_sounded=0;
$SIG{ ALRM } = sub{ open(AL,">>ALRM.txt");
                    print AL scalar(localtime()),"\n";
                    print AL "CAUGHT AN ALRM FROM: ",caller,"\n";
                    close AL;
                    $alarm_sounded=1;
                    print "CAUGHT AN ALRM!! FROM ",caller,"\n";
                    $cleanup=1;&cleanup('','ALRM') };
$SIG{ CHLD } = 'DEFAULT';

my @Hosts=@{&check_Hosts($Net::FullAuto::FA_Core::fa_host)};

sub username
{

   my $path=
      substr($INC{'Net/FullAuto.pm'},0,
      (rindex $INC{'Net/FullAuto.pm'},'Net'));
   eval {
      require "${path}Net/FullAuto/fa_global.pm";
      my $mod="fa_global";
      import $mod;
   };
   $username=getlogin || getpwuid($<);
   $username=$Net::FullAuto::FA_Core::usrname if
         defined $Net::FullAuto::FA_Core::usrname
         && $Net::FullAuto::FA_Core::usrname;
   $username=$Net::FullAuto::fa_global::FA_Sudo{$username}
      if exists $Net::FullAuto::fa_global::FA_Sudo{$username};
   if (wantarray && !$@) {
      my $force_login=0;
      if (defined $Net::FullAuto::fa_global::FA_Force_Login &&
            $Net::FullAuto::fa_global::FA_Force_Login) { 
         $force_login=$Net::FullAuto::fa_global::FA_Force_Login;
      } elsif (defined $fa_conf::fa_force_login &&
            $fa_conf::fa_force_login) {
         $force_login=$fa_conf::fa_force_login;
      } elsif (defined $fa_conf::force_login &&
            $fa_conf::force_login) {
         $force_login=$fa_conf::force_login;
      }
      $force_login||=0;
      return $username, $force_login;
   } elsif (wantarray) {
      return $username, 0;
   }
   return $username;

}

sub grep_for_string_existence_only
{
   my $file=$_[0];
   my $pattern=$_[1];
   my $return_value=0;
   eval {
      open(FH,"<$file") || return 0;
      my $keygen_flag=0;
      while (my $line=<FH>) {
         if ($line=~/^\[localhost\]/) {
            $return_value=1;
            last;
         } elsif ($line=~/^\|?\[?(?:1|localhost)\]?\|?|ssh-rsa|ecdsa-sha2/s) {
            $keygen_flag=1;
            last;
         } elsif ($line=~/$pattern/) {
            $return_value=1;
            last;
         }
      }
      if ($keygen_flag) {
         my ($stdout,$stderr)=('','');
         my $output=`ssh-keygen -F localhost 2>&1`;
         $return_value=1 if (-1<index $output,'localhost')
            || (-1<index $output,'illegal option -- F');
      }
   };
   return $return_value;
}

sub fetch
{
   my @topcaller=caller;
   print "\nINFO: main::fetch() (((((((CALLER))))))):\n       ",

lib/Net/FullAuto/FA_Core.pm  view on Meta::CPAN

   } elsif ((defined $fa_conf::berkeleydb) &&
         ($fa_conf::berkeleydb) && (-d $fa_conf::berkeleydb)) {
      if (-1<index $fa_conf::berkeleydb,$bver) {
         if (-d $fa_conf::berkeleydb.'/bin') {
            return $fa_conf::berkeleydb.'/bin/db_'.$db_util;
         } elsif (-f $fa_conf::berkeleydb.'/db_'.$db_util) {
            return $fa_conf::berkeleydb.'/db_'.$db_util;
         }
      } elsif (-d $fa_conf::berkeleydb.'/include') {
         if (-f $fa_conf::berkeleydb.'/include/db.h') {
            my $dbh=$fa_conf::berkeleydb.'/include/db.h';
            open(FH,"<$fa_conf::berkeleydb/include/db.h")
               or &handle_error(
               "Cannot open $fa_conf::berkeleydb/include/db.h");
            my @finc=<FH>;
            close(FH);
            foreach my $line (@finc) {
               if ($line=~/^.*VERSION.*$bver.*$/) {
                  if (-d $fa_conf::berkeleydb.'/bin') {
                     return $fa_conf::berkeleydb.'/bin/db_'.$db_util;
                  } elsif (-f $fa_conf::berkeleydb.'/db_'.$db_util) {
                     return $fa_conf::berkeleydb.'/db_'.$db_util;
                  }
               }
            }
            &handle_error("Cannot Locate BerkeleyDB installation");
         } elsif (-d $fa_conf::berkeleydb.'/bin') {
            return $fa_conf::berkeleydb.'/bin/db_'.$db_util;
         } elsif (-f $fa_conf::berkeleydb.'/db_'.$db_util) {
            return $fa_conf::berkeleydb.'/db_'.$db_util;
         } else {
            &handle_error("Cannot Locate BerkeleyDB db_$db_util utility");
         }
      } elsif (-d $fa_conf::berkeleydb.'/bin') {
         return $fa_conf::berkeleydb.'/bin/db_'.$db_util;
      } elsif (-f $fa_conf::berkeleydb.'/db_'.$db_util) {
         return $fa_conf::berkeleydb.'/db_'.$db_util;
      } elsif ($^O eq 'cygwin' && (-f "/bin/db${bver}_$db_util.exe")) {
         return "/bin/db${bver}_$db_util.exe";
      } else {
         &handle_error("Cannot Locate BerkeleyDB db_$db_util utility");
      }
   } else {
      my @output=();
      my $greppath=$Net::FullAuto::FA_Core::gbp->('grep');
      my $testgrep =`${greppath}grep -H 2>&1`;
      my $testgrep2=`${greppath}grep 2>&1`;
      my $grepopt='';
      if ((-1==index $testgrep,'illegal option')
            && (-1==index $testgrep2,'-insvxbhwyu')) {
         $grepopt='-H ';
      }
      my $find_cmd1=$Net::FullAuto::FA_Core::gbp->('find')."find ";
      my $find_cmd2=" -name \"*.h\" ".
                   "| ".$Net::FullAuto::FA_Core::gbp->('xargs')."xargs ".
                   $greppath."grep ".
                   "${grepopt}DB_VERSION_STRING";
      print "\nSearching for latest verison of BerkeleyDB.\n".
            "This may take up to five minutes ...\n\n";
      foreach my $dir ('/usr/local/',
            '/usr/','/opt/',(getpwuid $>)[7].'/') {
         next if unpack('a1',$dir) eq '.';
         next unless -d $dir;
         opendir(DIR, $dir) or Net::FullAuto::FA_Core::handle_error($!);
         while (my $file = readdir(DIR) ) {
            next if ($file eq "." or $file eq ".." or $file eq "doc" or
                     $file eq "X11R6" or $file eq "docs" or
                     $file eq "man" or $file eq "ssl" or
                     $file eq "license" or $file eq "logfile" or
                     $file eq "bin" or ($^O eq 'cygwin' &&
                     ($file eq "Application Data" or
                      $file eq "Favorites" or $file eq
                      "Local Settings" or $file eq "Recent" or
                      $file eq "Start Menu" or $file eq "SendTo" or
                      $file eq "NetHood" or $file eq "PrintHood")));
            if (-d $dir.$file) {
               print "Searching $dir$file ...\n";
               my @subout=`$find_cmd1\"$dir$file\"$find_cmd2`;
               if (-1<$#subout) {
                  eval {
                     our %Config=();
                     require Config;
                     import Config;
                     if (!(-e "$ENV{HOME}/.cpan/CPAN/MyConfig.pm") || (!old_cpan() && -e $^X)) {
                        my $run_cpan="echo y | $^X -e \"require CPAN;".
                                     'require CPAN::FirstTime;'.
                                     '*{CPAN::FirstTime::_using_sudo} = sub { return 1 };'.
                                     "CPAN::FirstTime::init(\'$Config{privlib}\');\" 2>&1";
                        system($run_cpan);
                        $run_cpan="echo yes | /usr/bin/perl -e \"require CPAN;".
                                  "CPAN::Shell->o('conf','init','auto_commit')\"";
                        system($run_cpan);
                        $run_cpan="CPAN::Shell->o('conf','urllist','http://www.cpan.org')";
                        system($run_cpan);
                     }
                     require CPAN;
                     import CPAN;
                     CPAN::HandleConfig->load;
                  };
                  &handle_error($@) if $@;
                  my $ccon=(defined $CPAN::Config &&
                        exists $CPAN::Config->{cpan_home})?
                        $CPAN::Config->{cpan_home}:'';
                  my @vers=();my %verhash=();
                  foreach my $version (@subout) {
                     next if (-1<index $version, $ccon) ||
                             (-1<index $version, 'Net-FullAuto-') ||
                             $version!~/db.h:.*DB_VERSION_STRING/;
                     my @fileparts=split 'db.h:', $version;
                     $fileparts[1]=~s/^.*DB (\d+[^:]+):.*$/$1/;
                     if (-1<index $fileparts[1], $bver) {
                        my $bintest=$subout[0];
                        substr($bintest,(rindex $bintest,'include'))='bin';
                        $berkeleydb=substr($bintest,0,-4)
                           if -d $bintest;
                     }
                  }
               }
            }
            last if $berkeleydb;
         } last if $berkeleydb;

lib/Net/FullAuto/FA_Core.pm  view on Meta::CPAN

            $editor='/usr/bin/emacs';
         }
      }
   }

   my $savdir=Cwd::cwd();
   if ($_[0]=~/ho*s*t*|^fa_host$/i) {
      $cpath.='Host';
      system("cd $cpath;\"$editor\" ".
         "$fa_host;cd \"$savdir\"");
   } elsif ($_[0]=~/^m$|^me$|^men$|^menu$|^fa_menu$/i) {
      $cpath.='Menu';
      $fa_menu=~s/^(fa_.*)_demo(.pm)$/$1$2/
         unless -f "$cpath./$fa_menu";
      system("cd $cpath;\"$editor\" ".
         "$fa_menu;cd \"$savdir\"");
   } elsif ($_[0]=~/^c$|^co$|^cod$|^code$|^fa_code$/i) {
      $cpath.='Code';
      $fa_code=~s/^(fa_.*)_demo(.pm)$/$1$2/
         unless -f "$cpath./$fa_code";
      system("cd $cpath;\"$editor\" ".
         "$fa_code;cd \"$savdir\"");
   } elsif ($_[0]=~/con*f*|^fa_conf$/i) {
      $cpath.='Conf';
      system("cd $cpath;\"$editor\" ".
         "$fa_conf;cd \"$savdir\"");
   } elsif ($_[0]=~/f/) {
      system("cd $path;\"$editor\" FA_Core.pm;cd \"$savdir\"");
   } elsif ($_[0]=~/r/) {
      system("cd ${tpath}Term;\"$editor\" RawInput.pm;cd \"$savdir\"");
   } elsif ($_[0]=~/t/) {
      system("cd ${tpath}Term;\"$editor\" Menus.pm;cd \"$savdir\""); 
   } else {
      my $stderr='';my $stdout='';
      chdir $cpath;
      ($stdout,$stderr)=cmd($Net::FullAuto::FA_Core::gbp->('ls')."ls -lR");
      &Net::FullAuto::FA_Core::handle_error($stderr) if $stderr;
      my @files=split "\n", $stdout;
      my @file=();my $dirr='';
      my $rx1=qr/\d+\s+\w\w\w\s+\d+\s+\d\d:\d\d\s+.*/;
      my $rx2=qr/\d+\s+\w\w\w\s+\d+\s+\d\d\d\d\s+.*/;
      foreach my $file (@files) {
         next if $file=~/^\s*$/;
         next if unpack('a1',$file) eq 'd';
         next if $file=~/^total/;
         next if $file eq '.:';
         if (unpack('a2',$file) eq './') {
            $dirr=unpack('x2a*',$file);
            chop($dirr);
            next;
         } 
         chomp($file);
         next if $file=~/\/$/;
         next if $file eq 'README';
         if ($file=~s/^.*\s+($rx1|$rx2)$/$1/) {
            $file=~
               s/^\d+\s+\w\w\w\s+\d+\s+(?:\d\d:\d\d\s+|\d\d\d\d\s+)(.*)$/$1/;
         }
         push @file,$username.'/'.$dirr.'/'.$file;
      }
      my $owner=getpwuid(${stat($path)}[4]);
      if ($owner eq $username) {
         ($stdout,$stderr)=cmd($Net::FullAuto::FA_Core::gbp->('ls').
            "ls -1 ..");
         &Net::FullAuto::FA_Core::handle_error($stderr) if $stderr;
         foreach my $file (split "\n", $stdout) {
            push @file, "Template $file" if $file=~/[.]pm$/;
         }
         push @file, "Global Settings fa_global.pm";
      }
      my %Menu_1=(

         Item_1  => {

            Text    => "]C[",
            Convey  => \@file,

         },
         Select => 'One',
         Banner => "\n   Choose a File to Edit:\n\n"

      );
      my $file=Menu(\%Menu_1);
      if ($file eq ']quit[') {
         print "\n";
         exit;
      }
      chdir '..';
      $file=~s/^Template (.*)/$1/;
      chdir '..' if $file=~s/^Global Settings (.*)/$1/;
      system("\"$editor\" $file");
      chdir $savdir;
   }
   
   exit;
}

my $today=unpack('x2a2',$invoked[7]);
my $curmonth=unpack('a2',$invoked[7]);
my $fullmonth=$month[$curmonth-1];
$fullmonth=~s/\s*$//;
my $todays_date="$fullmonth $today, $curyear";
my $endyear=$curyear + 20;
my $lastday='';
my $showmins=sub { package showmins;
                   my $datechosen=']P[{select_cal_days}';
                   $datechosen=~s/^"//;
                   $datechosen=~s/"$//;
                   $datechosen=~s/^(?:Today|Tomorrow) - //;
                   $datechosen=~s/^[A-Za-z]+, //;
                   my @hrmn=();
                   if ($datechosen eq $todays_date) {
                      my $now=unpack('a2',(split ':',
                         &Net::FullAuto::FA_Core::get_now_am_pm)[1]);
                      $now++;
                      foreach my $hr (@hours[$invoked[4]..23]) {
                         foreach my $mn ($now..59) {
                            if (length $mn==1) {
                               $mn='0'.$mn;
                            }
                            push @hrmn, unpack('a3',$hr).$mn.unpack('x5a2',$hr);

lib/Net/FullAuto/FA_Core.pm  view on Meta::CPAN

                'edit:s'                => \$edit,
                'e:s'                   => \$edit,
                'users'                 => \$users,
                'v'                     => \$version,
                'version'               => \$version,
                'V'                     => \$VERSION,
              ) or pod2usage(2);
   pod2usage(1) if $help;
   pod2usage(-exitstatus => 0, -verbose => 2) if $man;
   @ARGV=@holdARGV;undef @holdARGV;
   $random='__random__' if $random;
   if (defined $log) { $log=1 }
   $log=$log_ if !$log;
   $tosspass=$tosspass_ if !$tosspass;
   if ($test_arg) {
      $prod=0;$test=1;
   } elsif ($prod) {
      $test=0;
   }
   my $track=0;
   if (defined $passwrd) {
      if ($passwrd) {
         my $warn_against_commandline_password=<<END;

  WARNING!  A cleartext password is being passed to FullAuto via 
            commandline argument. This is a VERY insecure and *HIGHLY
            DISCOURAGED* practice. It is suggested to use Saved Passwords
            instead which is more secure, and does not leave cleartext
            passwords in the process table, invocation history, volatile
            memory and log files.

            Use the  --password  (or --pw) argument with *NO* password after
            it, and follow the online instructions that will appear when
            you this method of invocation.

            It is *STRONGLY* advised that you change your password BEFORE
            saving since the current one was used insecurely.

            If you still want to pass cleartext passwords on the commandline
            and not see this warning, use the  --password_no_warning  or
            --pwnw  arguments (followed by the password) instead.
            Use at YOUR OWN RISK!

END
         warn $warn_against_commandline_password;
         $passwd[0]=$passwrd;
         $Net::FullAuto::FA_Core::password_from='cmd_line_arg';
      } else {
         $Net::FullAuto::FA_Core::save_main_pass=1;
      } undef $passwrd;
   } elsif (defined $passwrdnw) {
      if ($passwrdnw) {
         $passwd[0]=$passwrdnw;
         $Net::FullAuto::FA_Core::password_from='cmd_line_arg';
      } else {
         $Net::FullAuto::FA_Core::save_main_pass=1;
      } undef $passwrdnw;
   } elsif (defined $go) {
      $Net::FullAuto::FA_Core::save_main_pass=1;
   }
   my $uname_uid=getlogin || getpwuid($<);
   my $launch_local_ssh_telnet=0;
   if (defined $usrname) {
      $username=$usrname;
      $launch_local_ssh_telnet=1 if $username ne $uname_uid; 
      $username_from='cmd_line_arg';
      $userflag=1;
   } elsif (defined $go) {
      $username=&Net::FullAuto::FA_Core::username();
      $launch_local_ssh_telnet=1 if $username ne $uname_uid;
      $username_from='go_arg_current';
      $userflag=1;
   } else {
      my $force_login=0;
      ($username,$force_login)=&Net::FullAuto::FA_Core::username();
      $launch_local_ssh_telnet=1 if ($username ne $uname_uid)
         || $force_login;
      $userflag=1 unless $force_login;
      $username_from='from_uid' if $userflag;
   }
   if (defined $identityfile && $identityfile) {
      $Hosts{"__Master_${$}__"}{'IdentityFile'}=$identityfile;
   } elsif (exists $Hosts{'localhost'}{'IdentityFile'}) {
      $Hosts{"__Master_${$}__"}{'IdentityFile'}=
         $Hosts{'localhost'}{'IdentityFile'};
   }
   if ($Hosts{"__Master_${$}__"}{'IdentityFile'} &&
        !(-r $Hosts{"__Master_${$}__"}{'IdentityFile'})) {
      my $i=$Hosts{"__Master_${$}__"}{'IdentityFile'};
      my $login_Mast_error=
            "SSH identity_file  $i  cannot be read.";
      my $die="\n       FATAL ERROR! - The Host "
         ."$Net::FullAuto::FA_Core::local_hostname Returned"
         ."\n              the Following Unrecoverable Error Condition"
         ."\,\n              Rejecting the Login Attempt of the ID"
         ."\n              -> $username :\n\n       "
         ."$login_Mast_error\n";
      &Net::FullAuto::FA_Core::handle_error($die,'__cleanup__');
   }

   if (-1<$#_ && $_[0] && $_[0]!~/^\d+$/) {
      if ($#_ && $#_%2!=0) {
         my $key='';my $margs=0;
         foreach my $arg (@_) {
            if (!$key) {
               $key=$arg;next;
            } else {
               if ($key eq 'local-login-id') {
                  $username=$arg;
               } elsif ($key eq 'login') {
                  $username=$arg;
               } elsif ($key eq 'password') {
                  $Net::FullAuto::FA_Core::password_from='fa_login_arg';
                  $arg=~/^(.*)$/;
                  $passwd[0]=$1;
               } elsif ($key eq 'sub_arg' ||
                     $key eq 'sub-arg') {
                  @menu_args=() if !$margs;
                  $margs=1;
                  push @menu_args, $arg;
               } elsif ($key ne 'test' || $prod==0) {

lib/Net/FullAuto/FA_Core.pm  view on Meta::CPAN

            unless (ref $pla_n eq 'HASH' and exists $pla_n->{Plan}) {
               my $die="\n       FATAL ERROR! -  Plan $plan is *NOT* a"
                  ."\n              Valid FullAuto Plan. Please indicate\,"
                  ."\n              a Valid Plan, or Create one using the"
                  ."\n              --plan argument without a number.\n"
                  ."\n           $status\n";
               print $LOG $die
                  if $log && -1<index $LOG,'*';
               &handle_error($die,'__cleanup__');
            }
            $bdb->db_close();
            undef $bdb;
            $dbenv->close();
            undef $dbenv;
         }
         if ($admin && !defined $main::plan_menu_sub) {
            $Net::FullAuto::FA_Core::adminmenu->();
         }
         if ($localhost &&
               (-1<index $login_Mast_error,'invalid log'
               && -1<index $login_Mast_error,'ogin incor'
               && -1<index $login_Mast_error,'sion den') ||
               (-1<index $login_Mast_error,'/dev/tty: No')) {
            if ($cmd_type eq 'telnet' &&
                  defined fileno $localhost->{_cmd_handle}) {
#print "GOING TO INT THREEZZZ\n";
               #$localhost->{_cmd_handle}->print("\003");
               $localhost->{_cmd_handle}->print(' exit');
               while (defined fileno $localhost->{_cmd_handle}) {
                  while (my $line=$localhost->{_cmd_handle}->get) {
print $LOG "FA_LOGINTRYINGTOKILL=$line\n"
   if $Net::FullAuto::FA_Core::log &&
   -1<index $Net::FullAuto::FA_Core::LOG,'*';
                     $line=~s/\s//g;
                     my $allout.=$line;
                     last if $allout=~/logout|closed/s;
                  } $localhost->{_cmd_handle}->close;
               }
            } elsif ($cmd_type eq 'ssh') {
#print "GOING TO INT FOURZZZ\n";
               #$localhost->{_cmd_handle}->print("\003");
               #$localhost->{_cmd_handle}->print("\003");
               $localhost->{_cmd_handle}->close; 
            } elsif (exists $localhost->{_cmd_handle}) {
               $localhost->{_cmd_handle}->close;
            }
         }

         if ($login_Mast_error) {
            if ($login_Mast_error=~/[Ll]ogin|sion den|Passwo/) {
               $userflag=0;@passwd=();
               chomp($login_Mast_error);
               $login_Mast_error=~s/^(.*try again.).*$/$1\n/s;
               $login_Mast_error=~s/^debug1.*interactive\s*//s;
            } else {
               chomp($login_Mast_error);
            }
         }
         if ((!$userflag && !$cron) || 
               (defined $usrname && !$usrname) || $launch_local_ssh_telnet) {
            my $uid=getlogin || getpwuid($<);
            $launch_local_ssh_telnet=1;
            if (!$Net::FullAuto::FA_Core::cron && !$usrname) {
               while (1) {
                  if ($^O ne 'cygwin') {
                     print $blanklines;
                  } else {
                     print "$blanklines\n";
                  }
                  if ($login_Mast_error) {
                     if ($Net::FullAuto::FA_Core::debug) {
                        print "\n  ERROR MESSAGE (5) -> $login_Mast_error";
                     } else {
                        print "\n  ERROR MESSAGE -> $login_Mast_error";
                     }
                  }
                  if ($test && !$prod) {
                     if ($Net::FullAuto::FA_Core::debug) {
                        print "\n  Running in TEST (2) mode\n";
                     } else {
                        print "\n  Running in TEST mode\n";
                     }
                  } else {
                     if ($Net::FullAuto::FA_Core::debug) {
                        print "\n  Running in PRODUCTION (2) mode\n";
                     } else {
                        print "\n  Running in PRODUCTION mode\n";
                     }
                  }
                  my $usrname_timeout=350;
                  my $usrname='';
                  eval {
                     local $SIG{ALRM} = 
                        sub { &Net::FullAuto::FA_Core::die("alarm\n") };
                        # \n required
                     alarm($usrname_timeout);
                     &acquire_fa_lock(1234);
                     my $ikey='';
                     print "\n";
                     ($usrname,$ikey)=rawInput("  $hostname Login <$uid> : ");
                     &release_fa_lock(1234);
                  };alarm(0);
                  if ($@ eq "alarm\n") {
                     print "\n\n";
                     &handle_error(
                        "Time Allowed for Username Input has Expired.",
                        '__cleanup__');
                  }
                  chomp $usrname;
                  $usrname=~s/^\s*//s;
                  $usrname=~s/\s*$//s;
                  next if $usrname=~/^\d/ || !$usrname && !$uid;
                  $username= ($usrname) ? $usrname : $uid;
                  $username_from='user_input';
                  $userflag=1;
                  last;
               }
            } elsif ($login_Mast_error &&
                  (-1==index $login_Mast_error,'/dev/tty: No')) {
               &handle_error($login_Mast_error);
            } else { 

lib/Net/FullAuto/FA_Core.pm  view on Meta::CPAN

   ####                                                              ###
   #####################################################################
                                                                     ###
   our $fa_host=['Distro/fa_host.pm', #<== Change Location Here      ###
                 "From $INC{'Net/FullAuto/FA_Core.pm'}, Line: ".     ###
                 ($vlin+51)];                                        ###
                                                                     ###
   #####################################################################

   #####################################################################
   ####                                                              ###
   #### DEFAULT MODULE OF  Net::FullAuto  $fa_menu IS:               ###
   ####                                                              ###
   #### ==> Distro/fa_menu_demo.pm <==  If you want a different      ###
   ####                                                              ###
   #### module to be the default, change $fa_menu variable below or  ###
   #### set the $fa_menu variable in the BEGIN { } block             ###
   #### of the top level script invoking Net::FullAuto. (Advised)    ###
   ####                                                              ###
   #####################################################################
                                                                     ###
   our $fa_menu=['Distro/fa_menu_demo.pm', #<== Change Location Here ###
                 "From $INC{'Net/FullAuto/FA_Core.pm'}, Line: ".     ###
                 ($vlin+87)];                                        ###
                                                                     ###
   #####################################################################

   unless (exists $INC{'Net/FullAuto.pm'}) {
      foreach my $fpath (@INC) {
         my $f=$fpath;
         if (-e $f.'/Net/FullAuto.pm') {
            $INC{'Net/FullAuto.pm'}=$f.'/Net/FullAuto.pm';
            last;
         }
      }
   }
   my $fa_path=$INC{'Net/FullAuto.pm'};
   substr($fa_path,-3)='';
   chomp($fa_path);
   my $net_path=$fa_path;
   $net_path=~s/Net\/.*$//;
   my %fullpath_files=();
   my $default_modules='';
   unless ($main::fa_code && $main::fa_conf && $main::fa_host
           && $main::fa_menu) {
      my $progname=substr($0,(rindex $0,'/')+1,-3);
      if (-f $fa_path.'/fa_global.pm') {
         if (-r $fa_path.'/fa_global.pm') {
            {
               no strict 'subs';
               require $fa_path.'/fa_global.pm';
               $fa_global::berkeley_db_path||='';
               if ($fa_global::berkeley_db_path &&
                     -d $fa_global::berkeley_db_path.'Defaults') {
                  BEGIN { $Term::Menus::facall=caller(2);
                          $Term::Menus::facall||='' };
                  use if (-1<index $Term::Menus::facall,'FullAuto'),
                      "BerkeleyDB";
                  my ($dbenv,$bdb)=
                     Net::FullAuto::FA_Core::connect_berkeleydb('Defaults');
                  my $username=getlogin || getpwuid($<);
                  if (exists $ENV{'SSH_CONNECTION'} &&
                        exists $ENV{'USER'} && ($ENV{'USER'}
                        ne $username)) {
                     $username=$ENV{'USER'};
                  } elsif ($username eq 'SYSTEM' &&
                        exists $ENV{'IWUSER'} && ($ENV{'IWUSER'}
                        ne $username)) {
                     my $login_flag=0;
                     foreach (@ARGV) {
                        my $argv=$_;
                        if ($login_flag) {
                           $username=$argv;
                           last;
                        } elsif (lc($argv) eq '--login') {
                           $login_flag=1;
                        }
                     }
                     $username=$ENV{'IWUSER'} unless $login_flag;
                  }
                  my $status=$bdb->db_get(
                        $username,$default_modules) if $bdb;
                  my $test_string=
                        Data::Dump::Streamer::Dump($default_modules)->Out();
                  if (-1<index $test_string,'{}') {
                     $default_modules={};
                  } else {
                     $default_modules=~s/\$HASH\d*\s*=\s*//s;
                     $default_modules=eval $default_modules;
                  }
                  $default_modules||={};
                  $bdb->db_close();
                  undef $bdb;
                  $dbenv->close();
                  undef $dbenv;
                  unless (keys %{$default_modules}) {
                     $default_modules->{'set'}='none';
                     $default_modules->{'fa_code'}=
                        'Net/FullAuto/Distro/fa_code_demo.pm';
                     $default_modules->{'fa_conf'}=
                        'Net/FullAuto/Distro/fa_conf.pm';
                     $default_modules->{'fa_host'}=
                        'Net/FullAuto/Distro/fa_host.pm';
                     $default_modules->{'fa_menu'}=
                        'Net/FullAuto/Distro/fa_menu_demo.pm';
                  } elsif (exists $default_modules->{'set'} &&
                        $default_modules->{'set'} ne 'none') {
                     my $setname=$default_modules->{'set'};
                     my ($stenv,$std)=
                           Net::FullAuto::FA_Core::connect_berkeleydb('Sets');
                     my $username=&Net::FullAuto::FA_Core::username();
                     my $set='';
                     my $status=$std->db_get(
                           $username,$set);
                     $set||='';
                     $set=~s/\$HASH\d*\s*=\s*//s
                        if -1<index $set,'$HASH';
                     $set=eval $set;
                     $set||={};
                     undef $std;
                     $stenv->close();



( run in 0.614 second using v1.01-cache-2.11-cpan-39bf76dae61 )