1 Replies - 10654 Views - Last Post: 02 January 2012 - 05:17 AM

#1 Dr_Fog   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-December 11

perl program does not wait for response and does not recognize answer

Posted 28 December 2011 - 07:59 AM

I am new to Perl and Javascript and have searched the world over looking for answers to the ultimate question.
Why is this not working?
Most of it works except "sub Wizard_user". The program falls through to the calling program without waiting for an answer from the submit.
Thank you in advance for your HELP!

#----------------------------------------------------------------------
#Perl Subroutine to retrieve CAC user info from CERT_SUBJECT
#Use button for Admin user so he/she can log in as Admin (default) or user
#----------------------------------------------------------------------

use CGI qw( :all -debug );
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use warnings;

#MDF  Start -----------
#MDF  Get  CERT_SUBJECT

sub get_me
{
#----------------------------------------------------------------------
# this section gets the CERT_SUBJECT from ENV
#----------------------------------------------------------------------

    my $cert =$ENV{CERT_SUBJECT};

    my @mycert= split /,/, $cert;

    my $mycertname=$mycert[5];

 #----------------------------------------------------------------------
 # this section splits out the user from CERT_SUBJECT from ENV
 #----------------------------------------------------------------------

   #  my @mywho= split /\.|\=/, $myparts; # split on period and equal signs
    my @mynameid = split /=/, $mycertname;  # split on equal signs


    $my_name_parts= "$mynameid[1]";

#----------------------------------------------------------------------
# this section is where we get the first & last name for display
#----------------------------------------------------------------------

    my @mynamesplit = (split /\./, $my_name_parts);  # split on period

    $my_first_name = lc"$mynamesplit[1]";
    $my_first_name = ucfirst"$my_first_name";


    $my_last_name = lc"$mynamesplit[0]";
    $my_last_name = ucfirst"$my_last_name";

#----------------------------------------------------------------------
# this section is where we need to read  a table using  the USER ID FROM CERT_SUBJECT
#----------------------------------------------------------------------

    $wizard_user  = "2";

    my $Last_Entry = "LastEntry";

    $UserFile= "Fogg_test.txt";
    open (FILE, "<$UserFile") or die "Could not open $UserFile: $!";
    foreach $line (<FILE>)
     {
      ($User_F_User, $User_F_User_code, $User_F_User_muggle, $User_F_User_wizard) = split(' ',$line);
       # do line-by-line processing.

        if($my_name_parts eq $User_F_User)
            {

# ---------------------------------
# ---------------------------------
# ---------------------------------

              if("$User_F_User_code" eq "$wizard_user")
                  {
                  Wizard_user();

                  if("$whoami" eq "Admin")
                      {
                       $user_ROAkey = $User_F_User_wizard;
                      }
                  else
                      {
                       $user_ROAkey = $User_F_User_muggle;
                      }
                  return  $user_ROAkey;
                  }
              else
                 {

                 $user_ROAkey = $User_F_User_muggle;
                 return  $user_ROAkey;
                 }
            exit;

            }
         else
            {
             if($User_F_User eq $Last_Entry)
               {

                User_failed();
               }
            }
     }
      close($UserFile);
} # end of get_me


#----------------------------------------------------------------------
# this  is Wizard_user
#----------------------------------------------------------------------
sub Wizard_user
{
    print header('text/html');

    sub generateHeader
        {
        print start_html(-title=>'Select User');
        print h3({-align=>'center'}, 'Select User');
        print start_form(-method => 'GET',
                         -id => 'main_form',
                         -name => 'main_form',
                         -action => '#',
                         -enctype => 'multipart/form-data');
        }

    sub submitButtonGenerator
        {
        my $button_name = shift;
        print submit(-value=>$button_name);
        }

    sub generateFooter
        {
#        my ($i, $tmp);

        print end_form();
        print hr();

        print end_html();
        }

    sub display
        {
        my @arr = ('Admin', 'User');
        my $u_type_arr = \@arr;

        print popup_menu(-name=>'u_type',
              -onchange => q/document.getElementById('main_form').submit()/,
              -values=>$u_type_arr);
        }

    sub displayResult
        {
        print param("u_type").br();
        $whoami=param("u_type");
        }

    generateHeader;
    display;

    print br();
    submitButtonGenerator("Go");
    print br();

    displayResult;
    print br();
    generateFooter;
    print end_html;

}  # this  is end of  Wizard_user

#----------------------------------------------------------------------
# this  is User_failed
#----------------------------------------------------------------------

sub User_failed
{

    my $timestamp = localtime;
    my ($d,$m,$y) = (localtime)[3,4,5];

    print header( "text/html" ),
      start_html( -title => "Welcome  $my_first_name  $my_last_name" ),
      h2( "Current Date / Time" ),
      hr,     #straight line
      p( "The current time, according to this system, is: ",
      br, br,
      b( $timestamp ) ),;

   print
  "<FONT COLOR=\"RED\">
   <H1> *** FATAL --- DR --- ERROR  ***</H1>
   </FONT>
    <H3><FONT COLOR=\"#736AFF\">
       Hello &nbsp; $my_first_name $my_last_name,
          </FONT>
       <FONT COLOR=\"blue\">&nbsp;&nbsp;
   <br><br><FONT COLOR=\"RED\">
    *** Your - CAC - ID
   <br><FONT COLOR=\"#5E7D7E\">[ $my_name_parts  ]
      </FONT>
       <FONT COLOR=\"RED\">
   <br>is not registered in the DR Application ***
   <br><br>Please copy and paste
   <br>this entire error message into
   <br> an email and
       </FONT>
   <br><FONT COLOR=\"#FF0080\">
       send it to the -->
   <a href=\"mailto:greg.simms.ctr\@dfas.mil\;
                    mark.fogg.ctr\@dfas.mil\">
           DR Admin.
   </a>

   <FONT COLOR=\"blue\">
   <H3> Thank you for <i> your </i> cooperation\! </H3>
       </FONT>

   <img border=\"0\" src=\"https://djmsdrin1.dfas.mil/RoAccess/user_html/atatat-1vvlpqn.gif\"
     width=\"304\"
     height=\"232\">"
     ;

    end_html;
    exit ;

}  #end  User_failed

#------------------------------------------------------------------
# MDF  End of getme.pl
#------------------------------------------------------------------
1;



Is This A Good Question/Topic? 0
  • +

Replies To: perl program does not wait for response and does not recognize answer

#2 dsherohman   User is offline

  • Perl Parson
  • member icon

Reputation: 227
  • View blog
  • Posts: 654
  • Joined: 29-March 09

Re: perl program does not wait for response and does not recognize answer

Posted 02 January 2012 - 05:17 AM

If I'm understanding your question correctly, it's simply because CGI Doesn't Work Like That. The user submits a request to the server and it sends a document back. If that document happens to contain a form with a submit button and the user submits the form, then the submission is a completely separate request and will run in separate invocation of your CGI program. The first one (normally) exits as soon as it finishes sending the response document. It doesn't wait around for the form to be submitted. (Consider what would happen if it did: Users abandon forms constantly without submitting them. This very page has a form embedded in it for users to submit quick replies, but the vast, vast majority of readers will not post replies. If the server waited around for a submission in response to every form it sent out, it would quickly be choked with many thousands of instances of the forum software, all waiting for submissions that will never come.)

The normal way of associating the two requests with each other would be to use a session cookie. While it's an easy thing to implement for yourself, I'd suggest taking a look at the CGI::Session module instead.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1