Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Location
    Indianapolis
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question perl program does not wait for response from JavaScript and does not recognize answer

    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"go" button.

    Thank you in advance for your HELP!
    [CODE]
    #----------------------------------------------------------------------
    # project X1482-00 DR-CACard
    # Written by Mark D Fogg 13.Oct.2011
    #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;

    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
    {

    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

    #------------------------------------------------------------------
    # End of getme.pl
    #------------------------------------------------------------------
    1;
    [ICODE]

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,871
    Thanks
    2
    Thanked 164 Times in 159 Posts
    perl program does not wait for response from JavaScript
    That tells me that you don't understand how cgi programs work. Perl scripts are server side scripts which execute on the server. Javascript is executed on the client. CGI scripts never execute and then wait for input from the client (javascript execution) before completing its code.

    I have not analyzed your code, but I noticed that you're defining multiple subroutines inside the Wizard_user() sub. That's considered to be a very poor practice. Fix that and add this pragma with the other use statements and fix the problems that it points out.
    Code:
    use strict;

  • #3
    New to the CF scene
    Join Date
    Dec 2011
    Location
    Indianapolis
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You are right, I don't.
    pragma??
    I added "use strict" and I get package errors on my global variables like "$my_name_parts" that are used throughout the script. How do I get around that?
    I added "use diagnostics" to get a better and removed strict and readded nothing worked... CGI heading error. I can't find a decent tutorial that covers what I need to do...
    What I really need is a true "popup" where the user can select "Admin" or "User" and then continue on.
    I am running Perl v5.8.9 on a secure(?) windows server 2003 with java version "1.6.0_26".
    I've typed this twice now because I get logged off before I can post..


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •