LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-04-2004, 08:35 PM   #1
DirtyDan
Member
 
Registered: Aug 2004
Posts: 41

Rep: Reputation: 15
Web interface with a cgi script


Im trying to set this up, and right now to do what it needs to its great. All it does is runs a cgi script that opens a C programs with a given input, coded into the CGI. I want to create and html file that can use a for with check boxes to send a combination of data to a similar cgi file. Let me show you the code, it will help.
The first cgi:

Code:
#!/bin/sh
# Parallel port CGI script
# This would be controller.cgi, obviously my form will not do anything to supply this
# Send HTTP headers
echo Content-type: text/html;charset=ISO-8859
echo
# Do the controlling
/usr/sbin/lptest 0        /*<----This is what i want to be able to change, with any value from 0 to 255*/
# Output web page data
echo "<html><head></head><body>"
echo "Parallel port controlled<br>"
echo "<a href=\"/link1.html\">Go back to controlling page</a>"
echo "</body></html>"
#
And what i would do (kinda, just missing the actual working parts :rollseyes
Code:
<html>
<body>

<form name="input" action="controller.cgi"
method="post">
Pin 1
<input type="checkbox" name="Pin 1">
<br>
Pin 2
<input type="checkbox" name="Pin 2">
<br>
Pin 3
<input type="checkbox" name="Pin 3">
<br>
Pin 4
<input type="checkbox" name="Pin 4">
<br>
Pin 5
<input type="checkbox" name="Pin 5">
<br>
Pin 6
<input type="checkbox" name="Pin 6">
<br>
Pin 7
<input type="checkbox" name="Pin 7">
<br>
Pin 8
<input type="checkbox" name="Pin 8">
<br>
<input type="submit" value="Submit">
</form>

</body>
</html>

My hope was to make one checkbox worth 1, one worth 2, one worth 4, etc up to 8, and add these together then send that number to the cgi so that it can run my C file (which im using from HeRe )

How do I edit the two files? Sorry for the excessive amount of code, its really simple probably to you guys I just wasnt sure how to explain my question. Thanks a ton!

Its really is a mess, but thanks a ton secesh. I'll try to make it more readable. What you made worked great!

Last edited by DirtyDan; 10-05-2004 at 12:15 AM.
 
Old 10-04-2004, 10:43 PM   #2
secesh
Senior Member
 
Registered: Sep 2004
Location: Savannah, GA
Distribution: Ubuntu, Gentoo, Mythbuntu, ClarkConnect
Posts: 1,154

Rep: Reputation: 47
well... this is a cluster-f***
first- comment what script belongs to what filename
second- this is not CGI -- you're throwing around all kinds of files -- an sh script, a reference to an asp page...

third -- i have no real idea of what you're trying to accomplish, but here's how you throw form data around with perl. Also, i'm a little rusty, and not going to test this, so it is what it is.

Code:
#!/usr/bin/perl
###########
## Moray ##
###########
## filename: parallel.cgi
#
print "Content-Type: text/html\n\n";
use CGI;
my $q = new CGI;
## TODO: Error catch!
system("/usr/sbin/lptest ".$q->param("my_val"));
# Output web page data
print "<html><head></head><body>";
print "Parallel port controlled<br>";
print "<a href=\"/link1.html\">Go back to controlling page</a>";
print "</body></html>";
and the html file includes this form with action to parallel.cgi
Code:
<form action="parallel.cgi" method="post">
    <input type="text" name="my_val" value="0" />
    <input type="submit" />
</form>
 
Old 10-05-2004, 12:14 AM   #3
DirtyDan
Member
 
Registered: Aug 2004
Posts: 41

Original Poster
Rep: Reputation: 15
Ok, im getting the hang of this sorta. But for some reason, my cgi now ALWAYS gives me 255?

Code:
/*link1org.html*/
<html>
<body>

<form name="input" action="/cgi-bin/lpton2.cgi"
method="get">
User Name
<input type="text" name="user" size=30 maxlength=20>
<br>
Password
<input type="password" name="pass" size=30 maxlength=20>
<br>
Pin 1
<input type="checkbox" name="Pin_1">
<br>
Pin 2
<input type="checkbox" name="Pin_2">
<br>
Pin 3
<input type="checkbox" name="Pin_3">
<br>
Pin 4
<input type="checkbox" name="Pin_4">
<br>
Pin 5
<input type="checkbox" name="Pin_5">
<br>
Pin 6
<input type="checkbox" name="Pin_6">
<br>
Pin 7
<input type="checkbox" name="Pin_7">
<br>
Pin 8
<input type="checkbox" name="Pin_8">
<br>
<input type="submit" value="Submit">
</form>

</body>
</html>
And...
Code:
#!/usr/bin/perl
###########
## filename: lpton2.cgi
#
print "Content-Type: text/html\n\n";
use CGI;
my $q = new CGI;
## TODO: Error catch!
$tot=0;
for($coun=0;$coun<=7;$coun++)
{
    if ($q->param("Pin_".($coun+1))=="on")
        {
            $tot+=2**$coun;
        };
};
system("/usr/sbin/lptest ".$tot);
# Output web page data
print $tot;
print "<html><head></head><body>";
print "Parallel port controlled<br>";
print "<a href=\"/link1org.html\">Go back to controlling page</a>";
print "</body></html>";

Yeah, the user and pass do nothing yet, but thats ok. It's stupid anyways. But why is my conditional statement " if ($q->param("Pin_".($coun+1))=="on") " always coming back true??

Last edited by DirtyDan; 10-05-2004 at 01:00 AM.
 
Old 10-05-2004, 06:28 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,406

Rep: Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396
In Perl, numeric 'equal' tst is '==', string 'equal' test is 'eq' ! It's prob cvt both stings to 'true' => 1...
 
Old 10-05-2004, 07:33 AM   #5
DirtyDan
Member
 
Registered: Aug 2004
Posts: 41

Original Poster
Rep: Reputation: 15
Thumbs up

Wow, thanks, switched it to eq and its working great! Is eq equivalent to =?
Nevermind, I see, I need it for a string conditional. This is great, i have username and pass stuff working too now.. Thanks again!

Last edited by DirtyDan; 10-05-2004 at 07:50 AM.
 
Old 10-05-2004, 07:58 AM   #6
secesh
Senior Member
 
Registered: Sep 2004
Location: Savannah, GA
Distribution: Ubuntu, Gentoo, Mythbuntu, ClarkConnect
Posts: 1,154

Rep: Reputation: 47
no.

perl handles variables a little differently. it does not make a difference between string variables and numerical variables, they are all 'scalars' to perl.

therefore, you must watch what operators you use while manipulating scalars:
eq is NOT the same as ==.

look at what this does as a quick example:
Code:
#!/usr/bin/perl
###########
## Moray ##
###########
my($val1, $val2, $val3, $val4);
$val1 = 1;
$val2 = 1;

$val3 = "apples";
$val4 = "oranges";

print($val1+$val2);print "\n";
print($val1.$val2);print "\n";

if($val1==$val2){
        print "$val1 == $val2\n";
}
if($val3 == $val4){
        print "$val3 == $val4\n";
}
if($val3 eq $val4){
        # Not eq!
}else{
        print "NOT($val3 eq $val4)\n";
}
you get this output:

Code:
2
11
1 == 1
apples == oranges
NOT(apples eq oranges)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Directory listing - Calling shell script from a CGI script seran Programming 6 08-11-2005 11:08 PM
python cgi script and premature end of script headers Neruocomp Programming 1 07-28-2005 11:43 AM
Is there a CGI implement (c or c++) of web session ? tclwp Programming 7 06-18-2005 09:55 PM
start daemon from cgi-bin via web-interface Xa! Programming 1 07-26-2004 03:08 PM
perl newbie. hangman.cgi script displaying strangely (additional code) on the web. WorldBuilder Programming 4 11-21-2003 07:09 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration