473,807 Members | 2,883 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

cgi script with password_field parameter

4 New Member
Hi,

I have this cgi script which is a simple authentication web page, it check the value of the password_field and if correct call the subroutine alfa.

I don't know why it stops with an error when I click on "insert new stream"

I tried to call the subroutine without the authentication part and it works.
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -Tw
  2. use CGI;
  3. $query = new CGI;
  4. print $query->header;
  5. print $query->start_html();
  6. if (!$query->param) {
  7.         print $query->startform;
  8.         print $query->password_field(-name=>'the_password',
  9.                 -size=>35,
  10.                 -maxlength=>50);
  11.         print $query->br;
  12.         print $query->submit(-value=>'Submit your password');
  13.         print $query->endform;
  14. } else {
  15.         $yourPassword = $query->param('the_password');
  16. if ($yourPassword eq '123') { alfa ();} {print 'error';}
  17.  
  18. }
  19.  
  20. print $query->end_html;
  21.  
  22.  
  23.  
  24. sub alfa () {
  25. use strict;
  26. use CGI::Carp qw(fatalsToBrowser);
  27. use CGI qw(:standard);
  28. use DBI;
  29. my $mode = param('mode');
  30. my $url = url;
  31. print header,
  32. start_html;
  33.  
  34. print h2('insert values'),
  35.      start_form(),
  36. textfield('DETAILS'),  'detail bor bla bla..' . br,
  37. textfield('TARGET_DATABASE') . br ,
  38. textfield('TARGET_HOST'). br,
  39. textfield('TARGET_IP') . br,
  40. textfield('TARGET_ACCOUNT') . br,
  41. textfield('SOURCE_DATABASE') . br,
  42. textfield('SOURCE_HOST'). br,
  43. textfield('SOUCE_IP') . br,
  44. textfield('SOURCE_ACCOUNT') . br,
  45. textfield('STREAM_NAME') . br,
  46. textfield('ID') . br,
  47. submit('insert new stream'),
  48.      end_form;
  49.  
  50. if($mode eq 'process_form')
  51.    {
  52. my $dbh = DBI->connect('DBI:Oracle:(DESCRIPTION = (ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = xx.xx.xx.xx)(PORT = xxxx)))(CONNECT_DATA =(SERVICE_
  53. NAME = xxxxxxx)))', 'monitor', 'monitor', {RaiseError=>'1'});
  54. my $sth = $dbh->prepare('insert into s_test (DETAILS, TARGET_DATABASE, TARGET_HOST, TARGET_IP, TARGET_ACCOUNT, SOURCE_DATABASE, SOURCE_HOST, SOUCE_IP, S
  55. OURCE_ACCOUNT,STREAM_NAME, ID)  values (? , ? , ?, ?, ?, ?, ?, ?, ?, ?, ?)');
  56.      $sth->execute(param('DETAILS'), param('TARGET_DATABASE'), param('TARGET_HOST'), param('TARGET_IP'), param('TARGET_ACCOUNT'), param('SOURCE_DATABASE
  57. '), param('SOURCE_HOST'), param('SOUCE_IP'), param('SOURCE_ACCOUNT'),param('STREAM_NAME'), param('ID'));
  58.      $dbh->disconnect;
  59.    }
  60.    print end_html;
  61. }
  62.  
Dec 28 '09 #1
11 3374
numberwhun
3,509 Recognized Expert Moderator Specialist
In line 16, shown here:

Expand|Select|Wrap|Line Numbers
  1. if ($yourPassword eq '123') { alfa ();} {print 'error';}
  2.  
I took out the {print 'error';} and it gave a bunch of output. Try removing that and see if that is what you were looking for. Not sure why you had that print statement there, but it overrode the subroutine execution, or so it seems.

Also, any time you post code in the forums, please use code tags.

Regards,

Jeff
Dec 28 '09 #2
RonB
589 Recognized Expert Moderator Contributor
Here are some questions for you to think about. As you answer them, your problem and solution should be discovered.

Why are you loading the CGI module twice?

Why are you using CGI's OO interface in the begining but then switch over to the functional interface in the sub?

Why do you have the use statements in the sub and not at the beginning of the script?

Why are you specifying an empty prototype in the subroutine declaration? You should be receiving this warning:
main::alfa() called too early to check prototype at m4x123.pl line 16
Why are you enclosing the print 'error'; statement in it's own block?

Why are you outputting 2 sets of headers?
Dec 28 '09 #3
RonB
589 Recognized Expert Moderator Contributor
I have not tested the script but I don't think that print error statement prevented the script from working correctly.

After fixing the formatting of that else block, here is what it looks like.
Expand|Select|Wrap|Line Numbers
  1. else {
  2.     $yourPassword = $query->param('the_password');
  3.  
  4.     if ($yourPassword eq '123') {
  5.         alfa();
  6.     }
  7.  
  8.     { print 'error'; }
  9. }
It's more likely that it's the prototype that's causing the problem.
Dec 28 '09 #4
numberwhun
3,509 Recognized Expert Moderator Specialist
I agree with you that I don't see why that would have effected it, but when I removed the print statement it produced a totally different output.
Dec 28 '09 #5
RonB
589 Recognized Expert Moderator Contributor
I just tested the script as written by the OP and the only "error message" I receive is the one that is hard coded into the script and is displayed whenever the user clicks on the 'Submit your password' button.

The script works exactly as I would expect. Meaning that the form in the alfa() sub is displayed, but since there is no form field with the name of 'mode' anywhere in the script, then the corresponding DB code won't be executed.
Dec 29 '09 #6
m4x123
4 New Member
Hi,
First of all thanks to all of you for the help.
I changed the code as follow(see m4x123.txt attached):

1) implemented the Rob's formatting at line 16-21
2) I've updated the script with form field with method=post, hidden name and value='process_ form'

I tested the subroutine again removing lines from 1 to 25 and using only "alfa ();" to call it and it works.

when I use all the script I can access the form for inserting the values in the form but after clicking on
the insert button I get the print 'error'; from line 23

from the error.log on the apache server:
[Tue Dec 29 11:46:39 2009] null: Use of uninitialized value in string eq at /u01/appl/ora102/product/http10g/Apache/Apache/cgi-bin/inspwd.pl line 19.

Still cannot figure out why the subroutine doesn't work if I call it from if statement.

should I use a different form ?

regards,
max
Attached Files
File Type: txt m4x123.txt (2.5 KB, 370 views)
Dec 29 '09 #7
RonB
589 Recognized Expert Moderator Contributor
What makes you think the subroutine is not working? For me, it works exactly as I'd expect, but clearly it's not what you want. What are your expectations.

One of the first and most important steps in writing and troubleshooting code is the ability to clearly describe step by step what the code needs to do. This is called writing pseudo code. From there you fill in the code details to accomplish each step.

I have a good idea of what you want the script to do, but as written has a number of logic errors, which is why it's not doing what you want.
Dec 29 '09 #8
RonB
589 Recognized Expert Moderator Contributor
Line 31 is one logic error example.

How can you retrieve the value of a hidden form field before creating the form in which it is defined?
Dec 29 '09 #9
m4x123
4 New Member
Hi Ron,

I just tried to reuse some code which I've found on internet since I like the flexibility and simplicity of perl/cgi but of course I'm not a perl expert

this for the insert into the database:
http://www.expertwebinstalls.com/cgi...ipulation.html

and http://www.devdaily.com/perl/perl-cg...ield-html-form
for the authentication

btw I don't want necessarily use this code what I'm trying to do is just creating a simple form for inserting a row in my table after authentication through another form. If you could address me I would really appreciate it.

thanks,
Max
Dec 29 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
4346
by: Raju V.K | last post by:
can I use javascript and PHP in the following manner to create a pop-up window: <--- in <head> </head> <script language=javascript> function popup(folder1, file1) { window1=open("solution.php?folder=folder1&file=file1"); }
0
6033
by: Will Seay | last post by:
At the end of this message I've pasted a script we're trying to modify slightly. I don't believe it is VBscript or javascript but these are the closest groups I could find with my limited programming knowledge. Basically, we are trying to add a few lines to this script that will execute a few shell commands (see comments at the very end of the code). We think this may be ActionScript2 but aren't sure. If you can offer any help, or know...
2
6930
by: Eyal | last post by:
Hey, I would appriciate if anyone can help on this one: I have a java object/inteface having a method with a boolean parameter. As I'm trying to call this method from a javascript it fails on a type mismatch. It is positively because of the boolean(java primitive)parameter. It goes fine if I change this parameter to int or String. This inteface has a lot more methods which works fine, it is just the
1
6722
by: CR1 | last post by:
I found a great cookie script below, but don't know how to make it also pass the values sent to the cookie, to a querystring as well for tracking purposes. Can anyone help? If there was a way to simply pass the values in a cookie to the querystring that would be even easier, but from what I've been able to tell, cookie values can't be passed to a querystring. I'm sure the answer will help alot of others who are using this script, and would...
6
2909
by: Velislav | last post by:
Hi, I have a client script block, which is registered in my Page_Load. However a button may result in the need to change the script which I've registered. Obviously the OnClick event occurs after Page_Load, so calling RegisterClientScriptBlock with the same key does nothing.
0
1453
by: =?Utf-8?B?TG93bGFuZGVy?= | last post by:
Hello, I've built a web application that uses client script callbacks. It is used on a large network with a large variety of user OSes and IE versions. It was tested on IE 6 on different setups and IE 5.5 to a lesser degree without problems. I know of a least one user who gets an error in WebResource.axd when using the application. The same error also occurs on a simple reproduction page with just a button and a div. When the button...
3
5207
by: Odd Bjørn Andersen | last post by:
Is there a way to check the return status from a stored procedure when called from a OS (Windows) script? I have a stored procedure that does some checking in the database, and the return status is set to 0 or -1 if 'OK' or 'not OK' respectively. When I call the from CLP I get something like this: Value of output parameters --------------------------
1
2560
by: ora2000 | last post by:
Hi I would like to create a unix script to connect to an ORACLE database using a oracle package. Also this script should provide functionality to call an oracle procedure that contains a parameter value that is passed to it. The parameter value passed to the procedure should be "editable" i.e user should be able to change it. Please specify if any more information is needed what I have done is the following example script name ->...
2
2192
by: peteinglastonbury | last post by:
I'd be most grateful if someone would help me. I hope I'm in the right forum (apologies if not) - I'm not sure whether my problem is CGI or Javascript related. I found a script called BatmoAudiopop.js which opens a pop-up browser window with an audio player when a link is clicked. Basically, it sets the right mime-type depending on the operating system and audio file type, then opens a window with the audio file (passed as a parameter) in...
0
9720
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9599
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10626
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10374
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9193
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7650
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4330
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.