########### Code Segment ####################### $tax_label = ""; $cost_of_stamps = "0"; $dtax="0"; $final_bill = 0; $cur_postage = ""; $total_weight = 0; $cur_postage = ""; $total_weight = 0; $price{'a'} = 105; $price{'b'} = 126; $price{'c'} = 147; $price{'d'} = 168; $price{'e'} = 189; $price{'f'} = 210; $price{'g'} = 231; $price{'h'} = 252; $price{'i'} = 273; $price{'j'} = 294; $price{'k'} = 315; $price{'l'} = 336; $method = 'E-Mail using SMTP'; $options=''; # Fetch the data for this request. if ( $ENV{'REQUEST_METHOD'} eq 'POST' ) { # Read it from standard input. local ($len) = $ENV{'CONTENT_LENGTH'}; if ( read (STDIN, $data, $len) != $len ) { &end_cgi("Error reading 'POST' data"); } } else { # Fetch from environment variable. $data = $ENV{'QUERY_STRING'}; } %q = (); # resultant hash array # The data is encoded as name1=val1&name2=val2&etc. # First split on name/value pairs. foreach $q ( split ('&', $data) ) { # Then split name and value. local ($name, $val) = split ('=', $q); # URL decode and put in resultant hash array. $name = &url_decode ($name); if ( defined $q{$name} ) { # Multiple values. Append using \0 separator. $q{$name} .= "\0" . &url_decode ($val); } else { # Store it. $q{$name} = &url_decode ($val); } } $q{'item_price'}= "\L$q{'item_price'}"; if($price{$q{'item_price'}} ne undef) { $q{'item_price'} = $price{$q{'item_price'}}; } ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); $sender_name = $q{"name"}; $addr1 = $q{"mail"}; $process_name = $q{"process_id"}; $process_name =~ s#\.\.([/\:]Ý$)##g; if($staging_server eq "") { $staging_server = $ENV{'SCRIPT_NAME'}; } # Process E-Mail Request if($doc_dir eq "") { if ($ENV{'DOCUMENT_ROOT'} ne undef) { $doc_dir = $ENV{'DOCUMENT_ROOT'}; $doc_dir = $doc_dir . '/output/'; } else { if($ENV{'PATH_TRANSLATED'} ne undef) { $doc1 = $ENV{'PATH_TRANSLATED'}; $doc1 =~ s#\\#/#g; $pos1 = rindex($doc1,'/'); $doc1 = substr($doc1,0,$pos1); $pos1 = rindex($doc1,'/'); $doc_dir = substr($doc1,0,$pos1); $doc_dir = $doc_dir . '/output/'; } } } $tax_label = $q{'sales_tax'}; $cur_postage = $q{'shipping'}; print"Content-Type: text/html\n\n"; local ($i) = @_; local ($file)= $doc_dir . $ENV{"REMOTE_ADDR"}. ".tmp"; %form_data; if( open (TEMP, $file)) { # || end_cgi ("Cannot read $file: $!")); $output=""; $out=""; $weight="0"; $id=""; $add=""; $price=""; $q=""; while () { $out = $out . $_; $_ =~ s/\n//; $_ =~ s/\r//; ($q,$id,$add,$price,$weight)= split('\|',$_); $total_weight = $total_weight + ($weight*$q); # print "$total_weight #"; $temp_data = $id .'|' .$add .'|' . $price .'|' . $weight; if($form_data{$temp_data} eq undef) { $form_data{$temp_data} = $q; } else { $form_data{$temp_data} = $form_data{$temp_data} + $q; } } close(TEMP); } if ($q{'add_to_order'} ne undef) { $q{'add_to_order'} = &convert($q{'add_to_order'}); if($q{'menu_1'} ne undef) { $q{'add_to_order'} = $q{'menu_1'} . ' ' . $q{'add_to_order'}; $temp = &scan($q{'menu_1'}); if($temp ne "") { $q{'item_price'} = $q{'item_price'} + $temp; } #print $temp; } if($q{'menu_2'} ne undef) { $q{'add_to_order'} = $q{'menu_2'} . ' ' . $q{'add_to_order'}; $temp = &scan($q{'menu_2'}); if($temp ne "") { $q{'item_price'} = $q{'item_price'} + $temp; } } if($q{'menu_3'} ne undef) { $q{'add_to_order'} = $q{'menu_3'} . ' ' . $q{'add_to_order'}; $temp = &scan($q{'menu_3'}); if($temp ne "") { $q{'item_price'} = $q{'item_price'} + $temp; } } $temp_record = $q{'id'} .'|' . $q{'add_to_order'} .'|' . $q{'item_price'} .'|' . $q{'weight'}; $temp_record = $temp_record; # add on previously bought items if($form_data{$temp_record} eq undef) { $form_data{$temp_record} = $q{'qty'}; } else { # $form_data{$temp_record} = $form_data{$temp_record} + $q{'qty'}; $form_data{$temp_record} = $q{'qty'}; } $total_weight = $total_weight + ($q{'weight'} * $q{'qty'}); } # print "## $total_weight"; $total = 0; $save = ""; $out =""; $id = ""; ########### Look for shop.html ################### $begin = ""; $begin2 = ""; if(open (FILE_LIST2, $doc_dir . "shop.html"))# || (&end_cgi("Cannot read shop.html: $!"))); { while () { $out = $out . $_; } close(FILE_LIST2); if(index($out,'',$end); } if(index($out,'',$end); } } if($begin eq "") { $begin =" Shopping Cart "; $end = " "; } print $begin; print'
'; print"  "; if($q{'menu_1'} ne undef && index($q{'menu_1'},'Select') != -1) { print"

Error. $q{'menu_1'}"; exit; } if($q{'menu_2'} ne undef && index($q{'menu_2'},'Select') != -1) { print"

Error. $q{'menu_2'}"; exit; } if($q{'menu_3'} ne undef && index($q{'menu_3'},'Select') != -1) { print"

Error. $q{'menu_3'}"; exit; } print"

"; print ''; print''; print''; print''; print''; print''; print''; while(($first,$last) = each(%form_data)) { ($id,$add,$price,$weight) = split('\|',$first); $first =~ s/\n//; $first =~ s/\r//; if($q{&unconvert($first)} eq undef) { print''; print''; print''; print''; print''; print''; $total = $total + ($last*$price); # print "$total" ."xxxxxx" . ($last*$price) ; print''; } else { # print "reduction"; # $total_weight = $total_weight - ($weight * $form_data{$first}); # $total = $total - ($price * $form_data{$first}); $form_data{$first}="DEL"; } } ######## Shipping ################## if($total > 0) { &calc(); } else { $cost_of_stamps=0; $dtax=0; } if($cur_postage ne "") { print''; print"'; print''; } ######## Tax Details ############################### if($tax_label ne "") { print''; print "'; #print''; print''; print''; } ####### Grand Total ###################### print''; print''; print''; print''; print''; print''; print''; print '
'; print 'Remove'; print''; print 'Quantity'; print''; print 'Item Code'; print''; print 'Price'; print''; print'Totals'; print'
'; #print $q{$first}; print''; print''; print sprintf($last); print''; print $add; print''; print sprintf("%.2f",($price)); print''; print sprintf("%.2f",($last * $price)); print'
"; if(index($cur_postage,'Select ') != 0) { print "

Shipping  

"; } else { print "

Please select a shipping rate from the menu  

"; } print'
'; print sprintf("%.2f",($cost_of_stamps)); print'
"; if(index($tax_label,'Select ') != 0) { print "

Sales Tax  

"; } else { print "

Please select a Sales or VAT rate from the menu  

"; } print'
'; print sprintf("%.2f",($dtax)); print'
'; #print sprintf("%.2f",$last); print''; #print $add; print''; #print $add; print''; #print sprintf("%.2f",($price)); print''; print sprintf("%.2f",($final_bill)); print'

'; if($total_weight > 0) { print "Total weight of the order is, $total_weight kg
"; } ######### Shipping Drop Down Menu ###################### if($POST{'1'} ne undef) { print " "; } ############ VAT Drop Down Menu ##################### if($TAX{'1'} ne undef) { print " "; } if($POST{'1'} ne undef) { print""; } print '
'; $product_des = ""; $data_file = ">" . $doc_dir . $ENV{"REMOTE_ADDR"} .".tmp"; while(($first,$last) = each(%form_data)) { if($last ne "DEL") { $save = $save . $last . '|' . $first . "\r\n"; $first =~ s/\n//; $first =~ s/\r//; ($id,$add,$price,$weight) = split('\|',$first); $product_des = $product_des . "$id $add ($last x £$price)\r\n"; } } if($q{'shipping'} ne undef) { $product_des = $product_des . $q{'shipping'} ."\r\n"; } if($q{'sales_tax'} ne undef) { $product_des = $product_des . $q{'sales_tax'} ."\r\n"; } $product_des =~ s/&/&/g; $product_des =~ s/"/"/g; $product_des =~ s//&rt;/g; open(FILE,$data_file) || (&end_cgi( "Could not write")); print FILE $save; close(FILE); ####### Show Payment Buttons ###################### if(($total > 0) && (index($tax_label,'Select ') != 0) && (index($cur_postage,'Select ') != 0) && ($cur_postage ne "" || $POST{'1'} eq undef) && ($tax_label ne "" || $TAX{'1'} eq undef)) { ######## Worldpay Button ###################### print""; print""; if($worldpay eq "Yes") { print""; } if($barclay eq "Yes") { print""; } if($protx eq "Yes") { print""; } if($authorizenet eq "Yes") { print""; } if($printable_form eq "Yes") { print""; } print""; print"
"; print'
'; print ""; print ""; print ""; print ""; print ""; if($acc_id ne "") { print ""; print ""; } print""; print""; print""; print "
"; print"
"; &barclay_button(); print""; &protx_button(); print""; &authorize_button(); print""; &form_button(); print"
"; } if($total == 0) { print "
No items are currently selected. Please click 'Continue Shopping' and select the item, you wish to purchase.
"; } ##### Print Form Footer ######################## print $end; #print' #'; #$data_file = ">" . $doc_dir . $ENV{"REMOTE_ADDR"} .".tmp"; # while(($first,$last) = each(%form_data)) # { # if($last ne "DEL") # { # $save = $save . $last . '|' . $first . "\r\n"; # } # } #open(FILE,$data_file) || (&end_cgi( "Could not write")); #print FILE $save; #close(FILE); #exit; #-------------------------- Subroutines ------------------------------ sub end_cgi { print"Content-Type: text/html\n\n$i\nend\n"; exit; } sub calc { $british_postal_rates=0; $base_price=0; $cost_of_stamps = 0; $compare_to = 0; $rate_amount=0; $n=1; while($POST{$n} ne undef) { $postage_record = $POST{$n}; ($delivery_method,$table,$post_rate) = split(',',$postage_record); $table =~ s/£/\$/g; #replace £ with $ $weight_or_money = ""; $greater_than = 0; if(index($table,'+') > -1) { $greater_than = 1; $table =~ s/\+//g; } if(index($table,'$') == -1) { $weight_or_money = "W"; $table =~ s/W//g; $table =~ s/w//g; } else { $weight_or_money = '$'; $table =~ s/\$//g; $table =~ s/£//g ; } $compare_to = 0; #convert to double 0 if error $compare_to = $table; $post_rate =~ s/£/\$/g; # new line , is this necessary? $percent_or_money =""; if(index($post_rate,'%') != -1) { $percent_or_money = '%'; $post_rate =~ s/\%//g; } else { $percent_or_money = '$'; $post_rate =~ s/\$//g; $post_rate =~ s/£//g; } $rate_amount = $post_rate; #remove ? #error rate amount =0; $dual_variable = 0; #if (shipping.getSelectedItem().equals(delivery_method)) if($cur_postage eq $delivery_method) { if ($weight_or_money eq '$') { $dual_variable = $total; } else { $dual_variable = $total_weight; } # print "XXXX--$dual_variable--$compare_to--$greater_than
"; if (($dual_variable < $compare_to) || (($dual_variable >= $compare_to) && ($greater_than == 1))) { if ($percent_or_money eq '%') { $dual_variable = ($dual_variable * $rate_amount)/100; } else { $dual_variable = $rate_amount; } # n = postage.countItems(); $n=10000; $cost_of_stamps = $dual_variable; } } # print $table; # print "#"; # print $weight_or_money; # print "#"; # print $post_rate; # print "#"; # print $percent_or_money; # print "Rate Amount $rate_amount"; # print "#cost of stamps: "; # print $cost_of_stamps; $n++; } $vat = 0; $dstamps = 0; $svat = "0"; #//tax.getSelectedItem(); $n=1; while($TAX{$n} ne undef) { if($TAX{$n} eq $tax_label) { $svat = $TAX{$n+1}; } $n++;$n++; } $vat = $svat; ### if(!post) ### { ### cost_of_stamps = dstamps; ### } # if($total == 0) { $vat = 0; } $vat = $vat * 10; $dtax=0; if($vat_on_post eq "Yes") { $dtax = (($total + $cost_of_stamps) * $vat)/1000; } else { $dtax = ($total * $vat)/1000; } $tax_total = $dtax; $final_bill=0; if($vat_on_post eq "Yes") { $final_bill = (($total + $cost_of_stamps) * (1000 + $vat))/1000; } else { $final_bill = (($total * (1000 + $vat))/1000)+ $cost_of_stamps; } $final_bill = sprintf("%.2f",($final_bill)); #print("Final bill $final_bill"); } sub barclay_button { ########## Barclay ePDQ Button ###################### print'
'; print ""; $item_no = 0; while(($first,$last) = each(%form_data)) { $item_no++; ($id,$add,$price,$weight) = split('\|',$first); $first =~ s/\n//; $first =~ s/\r//; print ""; print ""; print ""; print ""; print ""; } $item_no++; #### ePDQ ################### if($cur_postage ne "" && $total > 0 && $POST{'1'} ne undef) { print ""; print ""; print ""; print ""; print ""; } $item_no++; #### ePDQ ###################### if($tax_label ne "" && $total > 0 && $TAX{'1'} ne undef) { print "" ; print ""; print ""; print ""; print ""; } print ""; print""; print "
\r\n"; # } } sub protx_button { ########## Protx Button ###################### print'
'; print ""; $item_no = 0; while(($first,$last) = each(%form_data)) { $item_no++; ($id,$add,$price,$weight) = split('\|',$first); $first =~ s/\n//; $first =~ s/\r//; print ""; print ""; print ""; print ""; print ""; } $item_no++; #### ePDQ ################### if($cur_postage ne "" && $total > 0 && $POST{'1'} ne undef) { print ""; print ""; print ""; print ""; print ""; } $item_no++; #### ePDQ ###################### if($tax_label ne "" && $total > 0 && $TAX{'1'} ne undef) { print "" ; print ""; print ""; print ""; print ""; } print ""; print""; print "
\r\n"; # } } sub authorize_button { ########## AuthorizeNet Button ###################### print'
'; print $cgi_script; print"\">\r\n"; # print "\r\n"; print "\r\n"; # print ""; # print "\r\n"; print"\r\n"; #print"\r\n"; print"\n"; print"\r\n"; print "
\r\n"; # } } sub form_button { ########## Form Button ###################### print'
'; print ""; $item_no = 0; while(($first,$last) = each(%form_data)) { ($id,$add,$price,$weight) = split('\|',$first); $first =~ s/\n//; $first =~ s/\r//; if($last ne "DEL") { $item_no++; print ""; print ""; print ""; print ""; print ""; } } $item_no++; #### form ################### if($cur_postage ne "" && $total > 0 && $POST{'1'} ne undef) { print ""; print ""; print ""; print ""; print ""; } $item_no++; #### form ###################### if($tax_label ne "" && $total > 0 && $TAX{'1'} ne undef) { print "" ; print ""; print ""; print ""; print ""; } print ""; print""; print "
"; # } } sub nochex_button { ########## NoChex Button ###################### print'
'; # "email=" + URLEncoder.encode(getParameter("E_Mail_Address")) + # "&ordernumber=" + day.getTime() + # "&amount=" + pounds(grand_total); #"&description=" + URLEncoder.encode("afjlsadjfaslkdfjklasdf\nsdfasdfasdffasdffsadfasdfasdf\nsdfffadsfasfasfasss\nsdfsdfasdffasdfasdfffasreewr\ndsfasfsafewrewtewtttetetdsfd\nsdfasfasdfasfdsadf\nadsfasasffffsdsaddd\ndsffffffsdfffffffffsadskjfdsalkjfklasdfjlksadfjkaksjlfjklasfjlk"); $item_no = 0; print ""; print ""; while(($first,$last) = each(%form_data)) { $item_no++; ($id,$add,$price,$weight) = split('\|',$first); $first =~ s/\n//; $first =~ s/\r//; #if($barclay eq "Yes") # { # print ""; # } print ""; print ""; print ""; print ""; print ""; } $item_no++; #### form ################### if($cur_postage ne "" && total > 0 && $POST{'1'} ne undef) { print ""; print ""; print ""; print ""; print ""; } $item_no++; #### form ###################### if($tax_label ne "" && total > 0 && $TAX{'1'} ne undef) { print "" ; print ""; print ""; print ""; print ""; } print ""; print""; print "
"; # } } sub g_value { local ($rec,$field)=@_; $zz=0; $yy=0; $rec = $rec + ",,,,,,,,,"; for($nn=1;$nn<$field;$nn++) { $zz=index($rec,',',$zz)+1; } $yy = index($rec,',',$zz); $rec= substr($rec,$zz,$yy); return $rec; } sub get_temp { local ($file)=@_; ( open (FILE_LIST, $doc_dir.$file.'.log') ) || (&end_cgi ("Cannot read $file: $!")); while () { print $_; } close(FILE_LIST); } sub get_file { local ($file)=@_; ( open (FILE_LIST, $file) ) || (&end_cgi ("Cannot read $file: $!")); $output=""; $out=""; while () { $out = $out . $_; } if (($q{'Action'} eq 'processform')) { $out =~ s/e_mail_address/$addr1/; $out =~ s///; $out =~ s/staging_server/$staging_server/; $out =~ s/send_all/$method/; $out =~ s/<\/select>/$options/; $show_info = $q{'info'}; $show_info =~ s/\r\n/

\r\n/g; $show_info =~ s/ / /g; $show_info = '' . $show_info; $show_info = $show_info . ''; # $out =~ s//$show_info/; } print $out; close(FILE_LIST); } sub convert { local ($html_info)= @_; $html_info =~ s/&/&/g; $html_info =~ s/"/"/g; $html_info =~ s//&rt;/g; return($html_info); } sub unconvert { local ($html_info)= @_; $html_info =~ s/&/&/g; $html_info =~ s/"/"/g; $html_info =~ s/<//g; return($html_info); } sub find { local ($file)=@_; $string = $q{'item_name'} . ","; #url_decode($ENV{'QUERY_STRING'}) . ","; open (FILE_LIST, $doc_dir . $ENV{"REMOTE_ADDR"}. ".tmp"); # ( open (FILE_LIST,"$file") ) || (&end_cgi ("Cannot read $file: $!")); while () { $string = $string . $_; } close(FILE_LIST); ( open (FILE_LIST, $file) ) || (&end_cgi ("Cannot read $file: $!")); $output=""; $out=""; while () { $out = $out . $_; } ## $out =~ s///; $out =~ s///; print $out; #print $ENV{'QUERY_STRING'}; close(FILE_LIST); } sub delete_file { local($file)=@_; $file =~ s#\.\.([/\:]Ý$)##g; unlink($file) || (&CgiDie( "Cannot delete file\n")); } # Read associative array from dir sub read_doc { local ($dir)=$doc_dir; local ($file,$name); if($dir ne "") { opendir(DOC,$dir) || (&end_cgi( "could not open $dir")); while ($file=readdir(DOC)) { if ($file =~ /\.tmp/i) { ($name)=split(/\./,$file); $file=$dir.$file; if((-M $file) > 0.01) { $file =~ s#\.\.([/\:]Ý$)##g; unlink($file) || (&cgi_die( "Cannot find temporary file\n")); } } } closedir(DOC); } } sub get_tally { local ($tally,$buf); (open (F, '<' . $doc_dir."tally_no") ) || (&end_cgi("Error updating tally file")); # flock(F,2); $buf = ; # Increment it. chop ($buf); $tally = $buf; $tally++; # Write the new count to the tally file. open (F, '>' . $doc_dir . "tally_no") || (&end_Cgi ("Error writing to tally file")); print F ("$tally\n"); close (F); $tally; } sub show_form { $output2 = " Card Number: " . $q{'card_number'} . "\r\nExpiry Date: " . $q{'expiry_month'} . "/" . $q{'expiry_year'} . "\r\n Issue Number: " . $q{'issue_number'} . "\r\n Payment Type: " . $q{'type_of_payment'} . "\r\n Name: " . $q{'card_name'} . "\r\n Address: " . $q{'card_address'} . "\r\nPost/Zip Code: " . $q{'card_zip'} . "\r\n E-Mail: " . $q{"name"} . "\r\n Delivery\r\n:" . "\r\n Name: " . $q{'del_name'} . "\r\n Address: " . $q{'del_address'} . "\r\n Zip/Code: " . $q{'del_zip'} ."\r\n" . $output; $output = $output2; # while (($name,$description) = each(%q)) # { # $output = $output . " " . $description . "\r\n"; # } } # $user = "webmaster@test.web"; # $subj = "Message from the Web"; # $message = "...text with embedded newlines..."; # &sendmail ($user, $subj, $message); # sub scan { $testc=0; $n=0; ($cc_number) = @_; $new_ccnumber=""; $cclen = length($cc_number); if((index($cc_number,'\$') != -1) || (index($cc_number,'£') != -1)) { $startc = index($cc_number,'\$')+1; if($startc==0) { $startc = index($cc_number,"£")+1; } for($n=$startc;$n<$cclen;$n++) { $tc = substr($cc_number,$n,1); if($tc eq "0" || $tc eq "1" || $tc eq "2" || $tc eq "3" || $tc eq "4" || $tc eq "5" || $tc eq "6" || $tc eq "7" || $tc eq "8" || $tc eq "9" || $tc eq ".") { $new_ccnumber = $new_ccnumber . $tc; } else { $n = $cclen; } } } return $new_ccnumber; } sub save_array { # local ($file_contents,$name)=@_; # $name=$name; # open(DATAFILE,">$name") || (&CgiDie("cannot update $name: $!\n")); # { # print DATAFILE "$file_contents"; # close (DATAFILE); # } } sub add { local($file_contents)=@_; $data_file = ">>" . $doc_dir . $ENV{"REMOTE ADDRESS"}; open(FILE,$data_file) || (&end_cgi( "Could not write to log file")); print FILE $file_contents . "\n"; close(FILE); } sub save_log { local($file_contents)=@_; $data_file = ">>" . $doc_dir . "user.log"; open(FILE,$data_file) || (&end_cgi( "Could not write to log file")); print FILE $file_contents . "\n"; close(FILE); } sub save_orders { local($file_contents)=@_; $data_file = ">>" . $doc_dir . "orders.log"; open(FILE,$data_file) || (&end_cgi( "Could not write")); print FILE $file_contents . "\n"; close(FILE); } sub temp_order { local($file_id,$file_contents)=@_; $data_file = ">" . $doc_dir . "$file_id"; open(FILE,$data_file) || (&end_cgi( "Could not write to $data_file")); print FILE $file_contents . "\n"; close(FILE); } sub load_data { open(FILE,$doc_dir . "database.txt") || (&end_cgi( "Could not write")); while () { ($key) = split('|',$_); s/\n//g; s/\r//g; $data{$key}=$_; } # $data{$key_no} = $key_no . '|' . $record; close(FILE); } sub save_data { $data_file = ">" . $doc_dir . "database.txt"; open(FILE,$data_file) || (&end_cgi( "Could not write")); foreach(keys %data) { print FILE $data{$_} . "\n"; } close(FILE); } #sub get_message # { # ( open (FILE_LIST, $doc_dir.'e_mail_check') ) || (); ## print $doc_dir.'e_mail_check'; # $message=""; # while () # { # $message = $message . $_; # } # close(FILE_LIST); # $message; # } # Subroutine cgiparse parses the contents # of a CGI query into an associative array. # # Typical use: # # %query = &cgiparse(); # if ( defined $query{'Name'} ) .... # # A string of data may be passed as a parameter. This is useful # for testing and for occasions where the CGI input has already # been collected. # Subroutine lockfile: # # &lockfile (FH) # # FH is a handle to an opened file, with r/w access. # # Return values: # 1 lock succeeded # 0 lock failed # # Locking is implemented using the flock(2) system call that is # available on most modern systems. # # Typical use: # # open (F, "+>>datafile") || die (...); # if ( &lockfile (F) ) { # seek (F, 0, 2); # seek to end # print F (...); # append info # } # close (F); # release the file and lock sub lockfile { # local ($FH) = @_; # local ($LOCK_SH) = 1; # shared lock # local ($LOCK_EX) = 2; # lock exclusive # local ($LOCK_NB) = 4; # don't block when locking # local ($LOCK_UN) = 8; # release the lock # flock ($FH, $LOCK_EX); # lock exclusive, TRUE # return TRUE upon success. } # Subroutine to handle basic decoding of URL data. sub url_decode { local ($s) = @_; # Translate + to space, and %XX to the character code. $s =~ tr/+/ /; $s =~ s/%([0-9A-F][0-9A-F])/pack("C",oct("0x$1"))/gie; $s; } sub addr_to_host { local($ip_address) = $_[0]; $ip_address =~ s/^\s+|\s+$//g; local(@bytes) = split(/\./, $ip_address); local($packaddr) = pack("C4",@bytes); local($host_name) = (gethostbyaddr($packaddr, 2))[0]; return($host_name); } 1;