PDA

View Full Version : cgi-bin


Justin
08-14-2000, 01:55 PM
I see where the confusion is coming from... A few things to note:

Your /www/ directory is your document root - from the web, simply: /

Your /cgi-bin/ directory is mapped into your document root, thus its url is: /cgi-bin/

You cannot use '..' to move up a level that is above your /www/ directory, as nothing above that is web accessible. The cgi-bin is a special case, where its URL is relative to the root, not above it.

So change your FORM ACTION to simply /cgi-bin/whatever.cgi.

Hope this clears any confusion :)

------------------
Justin Nelson
FutureQuest (http://www.FutureQuest.net/index.php) Support

Dark Mage
08-14-2000, 11:52 PM
I hate to say this, but it's telling me the pages are unable to be displayed.[nbsp][nbsp]I have 3 types, C++ Script (exe), PEARL, and ISAPI (dll), all three say the same thing when called:
"There is a problem wih the page you are trying to reach and it cannot be displayed."

The code I've got in the files is copied straight from books, and I've even double checked them.. they're considered simple things, like the old "Hello World" stuff.
Which leads me to believe it's something in my tags or my use of the server.

Here again is one of my 3 html's I'm trying:
<HTML>
[nbsp][nbsp][nbsp][nbsp][nbsp]<HEAD>
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]<TITLE>Just an example. </TITLE>
[nbsp][nbsp][nbsp][nbsp][nbsp]</HEAD>

[nbsp][nbsp][nbsp][nbsp][nbsp]<BODY>
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]<FORM ACTION=&quot;/cgi-bin/example.pl&quot; METHOD=&quot;POST&quot;>
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]Enter a string: <INPUT TYPE=&quot;text&quot; NAME=&quot;string&quot;>


[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]<INPUT TYPE=&quot;submit&quot;>
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]</FORM>
[nbsp][nbsp][nbsp][nbsp][nbsp]</BODY>

</HTML>

and there DOES exist a file named &quot;example.pl&quot; in my cgi-bin, and it is in lower case.

Thanks again...
*DM*
PS:[nbsp][nbsp]I've gotten more help from this message board so far than anywhere else.

Dark Mage
08-15-2000, 12:00 AM
The directory structure is something like a root with a systerm cgi bin, then down a couple there's a list of all the domain names, one of which is my directory.[nbsp][nbsp]Within that there is a cgi-bin and then the www directory where I post all my pages.
I made a PEARL script, an exe in C++, and a DLL ISAPI and put all three in the cgi-bin.[nbsp][nbsp]Then I made simple pages that called them to test them.[nbsp][nbsp]My tags looked like this:

<FORM ACTION=&quot;..\cgi-bin\something.pl&quot; METHOD=POST>

In some instances it seems to want to download the file now for some reason, and others it tells me it can't find the url.[nbsp][nbsp]Since www and cgi-bin are on the same level, I dropped down one &quot;..&quot; then gave the new address, &quot;\cgi-bin\filename.ext&quot;.[nbsp][nbsp]I'm an old DOS guy, does this look right?[nbsp][nbsp]any ideas why my scripts aren't running?

Thanks for any help...
*DM*

Justin
08-15-2000, 12:15 AM
I'm an old DOS guy... That would be the problem - Unix systems (and thus any URL) uses a forward slash (/) as a path separator, not a back slash.

Hope this helps.

------------------
Justin Nelson
FutureQuest (http://www.FutureQuest.net/index.php) Support

Dark Mage
08-15-2000, 12:44 AM
Okay, I changed the slashes, but it's still giving me the default url unavailable screen on ie.

Here's my simple html:
<HTML>
[nbsp][nbsp][nbsp][nbsp][nbsp]<HEAD>
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]<TITLE>Just an example.</TITLE>
[nbsp][nbsp][nbsp][nbsp][nbsp]</HEAD>

[nbsp][nbsp][nbsp][nbsp][nbsp]<BODY>
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]<FORM ACTION=&quot;../cgi-bin/example.pl&quot; METHOD=&quot;POST&quot;>
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]Enter a string: <INPUT TYPE=&quot;text&quot; NAME=&quot;string&quot;>


[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]<INPUT TYPE=&quot;submit&quot;>
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]</FORM>
[nbsp][nbsp][nbsp][nbsp][nbsp]</BODY>

</HTML>

See anything wrong?
Thanks...
Admittale new to Unix

Hunkorama417
08-15-2000, 12:46 AM
Just to note... I find it helpful if you chmod cgi files 755.
------------------
Andrew
www.digi-FX.net (http://www.digi-FX.net)

Dan Kaplan
08-15-2000, 01:52 AM
On a lot of servers that is true, but I haven't seen it being necessary on FQ servers.[nbsp][nbsp]I believe they are configured to automatically set permissions to 755 on files in the cgi-bin and subdirectories.

Dan

Justin
08-15-2000, 02:35 AM
I think you are still a bit too stuck in DOS... an EXE or DLL file are DOS/Windows executables, and will not run on a Unix system. Also note that path names are Case Sensitive.

Scripts are not run by file association on Unix systems, either - you have to specify the path to Perl (not Pearl) on the first line of the script (this goes for any script):

</font><font face="Courier" size="3">#!/usr/bin/perl</font><font face="Verdana, Arial" size="2">

Finally, your scripts must be uploaded without Windows-style line terminators (Windows uses CR+LF, or 0D0A, where Unix uses simply LF). In other words, upload in ASCII mode.

I think your best bet would be to hit the &quot;Script Troubleshooter&quot; tool within your CNC. This works for any script (eg, not compiled programs or HTML-embedded code). There are also sections on Aota.net (http://www.aota.net) that you will find helpful.

------------------
Justin Nelson
FutureQuest (http://www.FutureQuest.net/index.php) Support

Dark Mage
08-15-2000, 10:39 AM
Okay, I'm learning a lot, that line was in my perl script.

#!/usr/bin/perl

# example1.pl

if($ENV{'REQUEST_MOTHOD'} eq 'POST')
{
[nbsp][nbsp][nbsp][nbsp][nbsp]read(STDIN, $buffer, $ENV{'CONTENT_LENGTH');
[nbsp][nbsp][nbsp][nbsp][nbsp]@pairs = split(/&amp;/, $buffer);
[nbsp][nbsp][nbsp][nbsp][nbsp]foreach $pair (@pairs)
[nbsp][nbsp][nbsp][nbsp][nbsp]{
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]($name, $value) = split(/=/. $pair);
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]$value =- tr/+/ /;
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]$value =- s/%([a-fA-F0-9][a=fA-F0-9])/pack(&quot;C&quot;, hex($1))/eg;
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]$form{$name} = $value;
[nbsp][nbsp][nbsp][nbsp][nbsp]}
}

print &quot;Content-type: text/html\n\n&quot;;
print &quot;<HTML>&quot;;
print &quot;<HEAD>&quot;;
print &quot;<TITLE>Results from Example 1 </TITLE>&quot;;
print &quot;</HEAD>&quot;;
print &quot;<BODY>&quot;;
print &quot;<H1>Example 1 results </H1>&quot;;
print &quot;This is the string that you entered, \&quot;$form{'string'}\&quot; &quot;;
print &quot;</BODY>&quot;;
print &quot;</HTML>&quot;;
exit;

And is still not working.. I'll check to see if ASCII was chosen on my ftp, I think it was on 'auto detect'.[nbsp][nbsp]I didn't know of that difference between OS.[nbsp][nbsp]I'll aslo look into the script troubleshooter you mentioned.

As for DLL (ISAPI's) and C++ scripts (exe's), the book I'm reading has this to say about operating system and scripts, &quot;In this book, most of the scripts are in Perl and C.[nbsp][nbsp]Both of these languages are freely available for all the major operating systems.[nbsp][nbsp]Other languages include Visual Basic, TCL, C++, the Unix shell, and AppleScript.&quot;[nbsp][nbsp]and later in a later chapter it's talking about C's main() and where Unix and Window's both enter at the main() function.[nbsp][nbsp]The first 2 chapters of the book are how to comunicate with Unix via Terminal, and the commands.

You're of the opinion this is wrong then?[nbsp][nbsp]I've been programming in C/C++ for a very long time, but I'm completely green to Unix.[nbsp][nbsp](ironic since it started in Unix)

Thanks!

Dark Mage
08-15-2000, 10:46 AM
You nailed it!

Opening file...Ok
Checking for zero file size...Passed
Checking if file was uploaded in ASCII mode...Failed
Checking for proper interpreter path...Passed
Checking for Required Perl Modules...Passed
Checking file permissions...Passed

However, I deleted, reuploaded, and it passed ASCII mode, refreshed page, and it still said unable to display page.

Dark Mage
08-15-2000, 11:46 AM
Okay..[nbsp][nbsp]being new to Perl, I blindly copied the book, but then looking at the book again for my perl script, I saw that the book made a typo (as best my unexperienced eye could tell) and left out a closing '}'.[nbsp][nbsp]I added that, and again, being too use to something else (C/C++) I also saw in the script =~ and thought it was =- in two places, after these 3 corrections, and reoploading in ASCII (my editor also gave the option to create for PC, Unix or Apple), the script FINALLY RAN![nbsp][nbsp]Let the ANGELS sing![nbsp][nbsp]lol[nbsp][nbsp]Still not to the desired affect, but at LEAST it ran.[nbsp][nbsp]The script was suppose to give back the contents of a field in the form WITH white spaces and without the other added garble.[nbsp][nbsp]The string it gave back was &quot;&quot;, blank.[nbsp][nbsp]But I thank you for all your help, at least it's RUNNING now![nbsp][nbsp]I'd consider that a step in the right direction![nbsp][nbsp]:-)

My final concern for this forum (HTML), is something you brought up, I'me using two books mostly to learn this, one is solely dependent on Visual Studio and C/C++, the other is a book on CGI scripts, both seem to think you can use as a minimum C for Unix scripts, and I did realize I had compiled my code using _WIN32 and not _UNIX, but that has changed (but still not working yet).[nbsp][nbsp]Are you certain in your assertion that you can't use exe's?
[This message has been edited by Dark Mage (edited 08-15-00@11:50 am)]

urban
08-15-2000, 11:57 AM
...an EXE or DLL file are DOS/Windows executables, and will not run on a Unix system. What Justin means is that the files you have uploaded are DOS/Windows executables.[nbsp][nbsp]This does not mean that the code is DOS/Windows-specific, only that the files compiled on a Windows system will not run on a Unix system.

You might be able to run your C/C++ programs on a Unix system, but they will have to be recompiled for the target platform.

&quot;In this book, most of the scripts are in Perl and C. Both of these languages are freely available for all the major operating systems...&quot;

True, these languages are freely available for both Unix and Windows. However, the compiled code is specific to each operating system and shouldn't run on both.[nbsp][nbsp]

Are you certain in your assertion that you can't use exe's? You can use exe's, as long as they've been compiled for the correct platform.[nbsp][nbsp]However, .exe means nothing to Unix as Justin has already mentioned.[nbsp][nbsp]
.
[This message has been edited by urban (edited 08-15-00@12:00 pm)]

Justin
08-15-2000, 01:09 PM
There are actually many cross-compilers out there, but generally they are to port programs from one version of Unix to another (eg, I have a compiler to make binaries for Linux-PPC, but the compiler runs on x86).

Here's the problem: Yes, C/C++ *code* is the same anywhere. But using MS VC++, you are talking about a programming environment specifically intended for the Windows operating system. It will use the Win32 API, share functions with the many DLLs and so on...

On Unix there is no such thing as a DLL - there are similar libraries, but they are not used in the same way a Windows DLL is used.

I think you are failing to realize just how very different a Unix system is from a Windows/DOS system - they are two completely different environments...

What you will need to do is dump that book - any book that tells you to use MS VC++ or VB or anything like that to create web content is no good in my opinion. Use Perl or C/C++ (NOT Visual C, just plain C). If you do use C, compile it *on the server*, not on your Windows PC...

I would recommend reading some books/documentation/web sites on Unix (or Linux in particular), to gain a better understanding of how a Unix system operates and how it differs from Windows. Then you can get into writing applications for a Unix web server.

In conclusion, I can almost guarantee you that the book you are reading is targeted at Windows web servers. IISAPI stands for Internet Information Server Application Programming Interface - where IIS is Microsoft's web server. Thus, it is an API to work directly with their web server, which of course is not what we run.

------------------
Justin Nelson
FutureQuest (http://www.FutureQuest.net/index.php) Support

Dark Mage
08-15-2000, 01:31 PM
I'm operation on Win98 at home.[nbsp][nbsp]You mentioned &quot;compiling on the server&quot;, how do you do that?[nbsp][nbsp]Do you mean just compiling on a system with the same OS as the server?[nbsp][nbsp]In order to do this, I'll have to get another machine to code from for the server?

I do realize how different OS can be after having to take 3 classes in AS400 and RPG in school towards my degree, that things can be EXTREMELY different.[nbsp][nbsp]I just didn't realize that Visual Studio didn't have the ability to compile cross-platform.[nbsp][nbsp]I did realize that most of the code was the same.

I did make sure that only stdio.h was used in my compile, and set DO NOT USE MFC for the compile.[nbsp][nbsp]So none of the libs or dlls of MFC were used, I also read the MSDN help on compiling for UNIX and made sure my code was friendly to it, like using '/' rather than '\', along with other things.[nbsp][nbsp]I did not realize however that I needed to be doing in under that operating system.

I'll take your advice for ditching the book that soley relies on Visual Studio for use with Unix.[nbsp][nbsp]So this leaves me with one question.. how can I comile C++ for Unix?[nbsp][nbsp]I'd have to have the operating system in use in front of me?[nbsp][nbsp]at least that's what I gathered from you post.

Thanks for the patience and help..

Hunkorama417
08-15-2000, 01:46 PM
I've never compiled a C/C++ program before, but I do know that you upload your source code and use a compiler such as gnu which is part of FutureQuest. So no, you don't need another computer.
------------------
Andrew
www.digi-FX.net (http://www.digi-FX.net)

Dark Mage
08-15-2000, 01:52 PM
I'm very grateful for all the help and setting someone led astray back on the right track.

*DM*

Dark Mage
08-16-2000, 12:11 AM
I did change Visual Studio (Visaul C++) to compile for Unix, but it still spat out an exe.[nbsp][nbsp]Isn't this the file I'd use as the script?[nbsp][nbsp]What about the ISAPI, it made a DLL, can't it be used on Unix somehow?

These books have skipped a lot of the important information for cross platforms.[nbsp][nbsp]The one, &quot;Web Commerce Programming with Visual C++&quot; talks about nothing but the use of HTML and C++, for both ISAPI's and C++ scripts (teaches no Perl at all), and even recomends some servers, some of which are Unix servers (of course).[nbsp][nbsp]But says nothing of changing the compiling type to UNIX.[nbsp][nbsp]He even mentions in the opening of the book how big Unix is these days, swinging back from the windows world because of the internet as a preface to the book, so he fully inteded (as best I can tell) for it's contents to be used on Unix systems.

I guess the meat of it all, what do I need to do to use my C scripts and ISAPI's?[nbsp][nbsp]I have compiled them for the UNIX platform.

urban
08-16-2000, 12:42 AM
I don't have a compiler that can create an executable for another platform.[nbsp][nbsp]The code may be cross-platform, but that code needs to be compiled on the target OS.[nbsp][nbsp]The _UNIX and _WIN32 are compiler directives that are intended to be set on each system, respectively. If you are compiling on a Windows machine, your compiler is creating a Win32 image, regardless of the compiler directives.

You need to compile your code on the target platform (ie Linux).
.
[This message has been edited by urban (edited 08-15-00@1:25 pm)]