#!/usr/bin/perl ###################################################################### +###### # S U B R O U T I N E S ###################################################################### +###### ######################################################## sub valid_cookie{ $flag=0; my $session_file=$companyrepository."/session.txt"; #file where se +ssions are stored unless(open(INTT, "$session_file")){print "Session not found $sess +ion_file. $cookie<br>";} while (<INTT>){ #find existing cookie if($_=~/^$cookie\;/){#if cookie exist $flag=1; last; } } close INTT; return $flag; } ###################################################################### +###### sub writeData { my $j=0; open (OUT,">".$datafile); # Print header foreach $head (@header_names){ print OUT "$head\t"; } print OUT "\n"; # Print data $i=0; # $i represents each row + + for ($i=0;$i<=$#write_data;$i++){ for ($j=0;$j<=$#{$write_data[$i]};$j++){ print OUT "$write_data[$i][$j]\t"; } print OUT "\n"; } close (OUT); } ###################################################################### +###### sub readData { my @temp=""; open (IN,"<".$datafile); $i=0; # $i represents each row while (<IN>) { if ($i==0){ # ignore the header $i++; next; }elsif ($_=~/^(.*?)\t/){# read in and split tabs @temp=split("\t", $_); $j=0; foreach $t (@temp){ # each column $j in row $i $read_data[$i-1][$j]="$t"; # store names $j++; } $i++; } } close (IN); } ###################################################################### +###### sub validate_input{ my $p_name=shift; my $p_value=shift; my $vflag=shift; # cosname must contain an aphanumeric character if ($p_name=~/col0/){ if ($p_value!~/[0-9]/){ $vflag=0; } # cosnum must be a digit between 1 and 32767 }elsif($p_name=~/col1/){ if ($p_value!~/[A-Za-z0-9_]/){ $vflag=0; } } return $vflag; } ###################################################################### +###### # E N D S U B R O U T I N E S ###################################################################### +###### ###################################################################### +###### # M A I N ###################################################################### +###### use CGI; $query = new CGI; # initial global variables $repository="/home/warp/userdata/"; $paramcount=0; $formcomplete=1; @header_names=("LATA"); @read_data=(); @read_names=(); @read_cos=(); @data=(); @cos=(); @names=(); $error=""; # pluck out some common params that may have been passed $answer=$query->param("answer"); ####check for valid cookie#### $cookie=""; @temp=""; $cookie=$ENV{'HTTP_COOKIE'}; #identify cookie @temp_cookie=split(';',$cookie); $cookie=$temp_cookie[0]; ($sess_id,$company,$site,$user)=split('%2C', $cookie); $companyrepository=$repository.$company."/".$site; valid_cookie(); # If cookie not valid, then redirect to login page if ($flag==0){print $query->redirect('http://services.genband.com/cgi- +bin/dbq/na/DBQ_welcome.cgi'); }#redirect to another location if ($flag==1){ $dbqfile=$companyrepository."/dbq_finished.txt"; if (-e $dbqfile){ # DBQ has been finished and database has been built print $query->redirect('http://services.genband.com/cgi-bin/dbq/na +/home.cgi'); #redirect to home } } print "Content-type: text/html\n\n"; # create company specific variables $datafile=$companyrepository."/latas.txt"; ################################ # start html $header_file = "header1.html"; open(FILE,"$header_file"); while(<FILE>) { print $_; } close FILE; print <<'ENDHTML'; <tr> <td width="1020" bgcolor="#f4f4f4" align="center"> <table width="900" border="0" cellspacing="0" cellpadding="0"> <tr> <td bgcolor="#232021" height="25px" width="499" align="left" valig +n="bottom"><p class="h1"><a href="DBQ.cgi?tab=1#TabbedPanels1">Call P +rocessing Resources</a> : LATAs</p></td> <td bgcolor="#232021" height="25px" width="401" align="right" vali +gn="bottom"><p class="blinks"><a href="logout.cgi">Logout</a> | + <a href="DBQ_setPW.cgi">Add User</a> | <a href="co +ntact.cgi">Contact</a> | <a href="comment.cgi">Comment</a +></p></td> </tr> <tr><td colspan=2 align=left bgcolor=#ffffff class=border2 class=b +order2> ENDHTML # if the screens file exists then we have already been here once and s +aved valid data, read this data in if (!$answer) { if (-e $datafile){ readData; $formprocessed=1; }else{$formcomplete=0;} } # process passed parameters foreach $paramname ($query->param) { # $paramcount++; $paramvalue=$query->param($paramname); $$paramname=$paramvalue; $$paramname =~ s/\s+/_/g; # place the values in the appropriate array location if ($paramname =~ /row(\d+)col(\d+)/) { # row(i) and column(j) as +read from webpage $match1="$1"; $match2="$2"; $write_data[$1][$2]="$$paramname"; if ($match2==0){ if ($$paramname=~/[0-9]/){ # validate name push @fail, $match1; } } if ($$paramname=~/\D/){ $formcomplete=0; $error="Lata value must be numeric"; } } # print "$paramname, $$paramname, $paramvalue, $$paramvalue<br>"; if (($paramname eq "answer") && ($answer eq "finish")) { $finished=1; } } # trunkate list where Profile names are undefined $len=@fail; @write_data = splice (@write_data, $fail[0], $len); ##################################################################### # if the finish button has been clicked # ##################################################################### ##################################################################### # when entering this page from the main DBQ the answer will be null # ##################################################################### if (($finished) && ($formcomplete)) { writeData; print "<form action=DBQ.cgi?tab=1#TabbedPanels1 method=post>"; print "<p class=status>"; print "The class of service data has been saved. Please click next + to continue. <input type=submit name=answer value=next>"; print "</p>"; # if we are arriving from the main page, a next or re-submit button wa +s clicked, or there # was an error in the form when the finish button was clicked then red +raw the }else{ # if we are here from the main page and this form has been process +ed before then print this message if ($formprocessed) { print "<p class=main>"; print "The Class of Service form has already been processed at + least once, the data last submitted is below.<br><br>"; print "</p>"; } # print instructions print "<p class=status>"; print "In the table below is a list of the termination types that +will be data filled in the switch. "; print "To define a Class of Service, provide a name in the box at +the top of the column and then to the "; print "right of each termination type click the check box to allow + that termination type "; print "for the given screening class. An uncheck box will indicate + that the termination type is to be "; print "blocked for the screening class. For more details click the + help button."; print "</p>"; print "<hr>"; print "<form action='latacfg.cgi' method='post'>"; # present form print "<div style=background-color:#ffffff;overflow:scroll;width:9 +00px;text-align:top;border:1;>"; print "<table cellpadding=0 cellspacing=0 border=0 style=margin:.1 +in;><tr>"; print "<th class=\"mess left_border\" >LATA<span>Specify the LATA +in which you will be providing service.</span></th>"; print "</tr>"; # Print rows for ($i=0;$i<=10;$i++) { print "<tr >"; for ($j=0;$j<=0;$j++){ $type=""; print "<td align=center>"; $paramname="row".$i."col".$j; if ($read_data[$i][$j]){ $type="<input style=text-align:center type=text size=17 maxlen +gth=16 name=$paramname value=$read_data[$i][$j]>"; }else{$type="<input style=text-align:center type=text size=17 +maxlength=16 name=$paramname value=$$paramname>";} print "$type"; print "</td>"; } print "</tr>"; } print "</table></div>"; print "<div style=margin:.2in>"; # initial presentation of the page if ((!$formcomplete) && ($error eq "")) { print "<input type=submit name=answer value=submit>"; print "<button type=button type=button type=button onclick=\"w +indow.location='DBQ.cgi?tab=1#TabbedPanels1'\">"; print "cancel</button> Click 'cancel' to return to Main Menu w +ithout saving your data.<br>"; print "Click 'submit' to proceed with this form."; # errors found when processing }elsif((!$formcomplete) && ($error ne "")){ print "<input type=submit name=answer value='re-submit'>"; print "<button type=button type=button type=button onclick=\"w +indow.location='DBQ.cgi?user=$user&company=$company'\">"; print "cancel</button> $error"; print "Click 'cancel' to return to the Main Menu<br>without sa +ving your data or"; print " please make corrections and click re-submit to proceed + with this form."; # form has been completed without errors }elsif ($formcomplete) { print "<input type=submit name=answer value=re-submit>"; print "<button type=button type=button type=button onclick=\"w +indow.location='DBQ.cgi?tab=1#TabbedPanels1'\">cancel</button>"; print "<input type=submit name=answer value=finish> "; print "The data on the form has been validated. Click 'cancel' + to return to the Main Menu<br>without saving your data,"; print " click 're-submit' to make changes, or click 'finish' to save y +our data and return to the Main Menu."; } print "</form>"; } print "</td></tr>"; print <<'ENDHTML'; </table> </td> </tr> <tr> <td colspan="4" height="25px" bgcolor="#f4f4f4"></td> </tr> <tr> <td colspan="4" height="25px" bgcolor="#F0251A"><p class="h2">&nbs +p;</p></td> </tr> ENDHTML $footer_file = "footer1.html"; open(FILE,"$footer_file"); while(<FILE>) { print $_; } close FILE;
In reply to Re^3: PLEASE Help with this script
by ksolomon
in thread PLEASE Help with this script
by ksolomon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |