olupotd / mongoose

Automatically exported from code.google.com/p/mongoose
MIT License
0 stars 0 forks source link

On windows, can not visit *.exe file as cgi. #77

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
first step:
following is a simple cgi file named www.c. when set  the interpreter as 
a "tcc -run",tiny c complier. set the cgi_ext whit c(extention),it works 
on Mongoose.
{{{
#include <stdio.h>
#include <stdlib.h>
int main(void)
 {//QUERY_STRING test,GET method test
  char* query;
 printf("Content-type:text/html\n\n");
 query = getenv("QUERY_STRING");  
 printf("<html><title>Hello</title><body>\n");
 printf("obtain QUERY_STRING params!<br>\n");
printf("%s\n<br>",query);
 printf("</body></html>");
 return 1;
 }}}

second step:
but after compiler it to www.exe with tcc, and set the cgi_ext option to 
exe or .exe, at same time unset the cgi_interp option at mongoose.conf,
visit http://172.16.0.22/www.exe
 it repeatly results following error:

{{{
Loading config file C:\cgi-test-fields\mongoose.conf
Mongoose 2.8 started on port(s) [8077], serving directory [C:\cgi-test-
fields\ss
l]
[1247990705] [error] [client 172.16.0.22] GET /www.exe: line 1311: 
CreateProcess
(www.exe): 2
}}}

the content of mongoose.conf is: 
{{{
# Mongoose web server configuration file.
# Lines starting with '#' and empty lines are ignored.
# For detailed description of every option, visit
# http://code.google.com/p/mongoose/wiki/MongooseManual
  root           C:\cgi-test-fields\ssl
ports           8077
#access_log      c:\mongoose_access_log.txt
#error_log       c:\mongoose_error_log.txt
##################
# NOTE FOR PHP USERS:
# Correct PHP binary to use is php-cgi.exe, NOT php.exe!
# cgi_interp    C:\xampp\php\php-cgi.exe
#  cgi_interp    E:\ruby\bin\ruby.exe 
 cgi_interp    C:\cgi-test-fields\tcc\tcc.exe -run
# cgi_interp    c:\perl\bin\perl.exe
##################
#cgi_ext       cgi,pl,php,rb,c
#cgi_ext        .exe,exe
cgi_ext       c
# ssi_ext       shtml,shtm
# auth_realm    mydomain.com
# dir_list      no
# index_files   index.html,index.htm,index.php,index.cgi
# aliases   /my_d_disk=d:\,/my_e_disk=e:\
# acl           -0.0.0.0/0,+10.0.0.0/8,+192.168.0.0/16
# admin_uri     /remote_admin
# protect       /remote_admin=c:\passwords.txt
# cgi_env       FOO=BAR,BAZ=POO
# auth_gpass    c:\mongoose_global_web_passwords.txt
# auth_PUT      c:\mongoose_put_delete_passwords.txt
# ssl_cert      ssl_cert.pem
max_threads 100
# idle_time 10
}}}

Original issue reported on code.google.com by hnle...@gmail.com on 23 Jul 2009 at 9:34

GoogleCodeExporter commented 9 years ago
What is the purpose of the line `cgi_interp    C:\cgi-test-fields\tcc\tcc.exe 
-run` ?
Can you start Mongoose successfully if you leave it out? I have no idea what 
tcc is.
If it is the name of a compiler (such as the Tiny C Compiler or the Turbo C/C++
Compiler), then you have made a mistake. A compiler cannot be used as a CGI 
program.

Also, make sure that www.exe actually exists.

I will try your test case when I have time.

I am guessing that you want to use www.exe as your CGI interpreter instead of 
ttt.exe.

It might help if you explain exactly what you are trying to do. Then we can 
help you
better.

Original comment by googl...@springtimesoftware.com on 25 Jul 2009 at 12:59

GoogleCodeExporter commented 9 years ago
thank you for your attention ,:)
tcc is tiny c complier, there may be nothing to do with the complier, 
I tried to use visual studio 2008 express to complier the same code as 
following,
than used the compiled executable file as a cgi file,the error repeats. when 
used 
executable file as a cgi file,in the mongoose.conf I sure left the cgi_interp 
out, 
and set the cgi_ext option to exe or .exe. 

#include <stdio.h>
#include <stdlib.h>
int main(void)
 {//QUERY_STRING test,GET method test
  char* query;
 printf("Content-type:text/html\n\n");
 query = getenv("QUERY_STRING");  
 printf("<html><title>Hello</title><body>\n");
 printf("obtain QUERY_STRING params!<br>\n");
printf("%s\n<br>",query);
 printf("</body></html>");
 return 1;}

Original comment by hnle...@gmail.com on 25 Jul 2009 at 6:18

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
in addition, I tried other compiled pieces of simple C code to test cgi, all 
repeated the same error. would you give a passed C code as cgi? and the config 
file 
on Windows.

Original comment by hnle...@gmail.com on 26 Jul 2009 at 10:00

GoogleCodeExporter commented 9 years ago
Valenok,

I have verified that executable CGI files will not run using mongoose-2.8.exe
standalone on Windows XP Home SP3, either from the browser address bar (Firefox
3.0.12: asks whether to download the file; Internet Explorer 8.0: shows "cannot
display the webpage" error page) or from an HTML test file (included below). I 
don't
know what the `cgi_interp` configuration directive should be set to, if 
anything, for
executable files, so I left it out of the Mongoose configuration file.

Feel free to respond to me here until we figure this out.

Executable program (`www.c`):

{{{
// Test case for Mongoose #77
#include <stdio.h>
#include <stdlib.h>

int main(int argc, const char* argv[]) 
    {
    char* query;

    printf("Content-type:text/html\n\n");

    query = getenv("QUERY_STRING");  
    printf("<html><head><title>Show Arguments Test</title></head>\n");
    printf("<body>Number of Arguments is (argc): %d\n<br>\n", argc);
    printf("<body>Arguments are (argv[1],may be null): %s\n<br>\n", argv[1]);
    printf("<body>Arguments are (QUERY_STRING environment variable): %s\n<br>\n", query);
    printf("</body></html>\n");
    return 0;
    }
}}}

Partial Mongoose config file (`mongoose.conf`):

{{{
cgi_ext         exe
acl             -0.0.0.0/0,+192.168.0.0/32,+127.0.0.1
root            C:\Web\root
ports           965
}}}

Test address for browser:

{{{
http://localhost:965/Web/root/cgi-bin/argstest.exe?arg1&arg2
}}}

Test program (`argstest.php`):

{{{
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<meta name="generator" content="NoteTab Pro">
<meta name="Author" content="D.Spector">

<title>Test argstest (Mongoose #77)</title>

<style type="text/css">
body {padding: 25px; background-color: #eee; color: #000;
    font-family: Arial,Helvetica,sans-serif; font-size: 90%;}
</style>
</head>

<body>

<h1>Test argstest (Mongoose #77)</h1>

<form action="http://localhost:965/cgi-bin/argstest.exe" method=get>
<input type=hidden id="Test1" name="Test1" value="One">
<input type=hidden id="Test2" name="Test2" value="Two">
<input type=submit class=button title="Do Test" value="Do Test">
</form>

</body>
</html>
}}}

Original comment by googl...@springtimesoftware.com on 27 Jul 2009 at 1:01

GoogleCodeExporter commented 9 years ago
Looking into this, thanks.

Original comment by valenok on 27 Jul 2009 at 10:33

GoogleCodeExporter commented 9 years ago
hi!

i have the same issue compiling the cgi program with cross-mingw, but if i 
compile
with mingw32 in windows it does work

Original comment by rene.bel...@gmail.com on 14 Aug 2009 at 6:43

GoogleCodeExporter commented 9 years ago
Can't reproduce it. My test cgi.c -> cgi.exe worked fine.
David, I also compiled your code, and it worked fine.

I am using latest code (revision 466)

Original comment by valenok on 17 Aug 2009 at 9:01

GoogleCodeExporter commented 9 years ago
I don't know what your cgi.c program is, please show it. What compiler did you 
use?
What happened when you tried my program, www.c, called by argstest.php?

Original comment by googl...@springtimesoftware.com on 17 Aug 2009 at 9:59

GoogleCodeExporter commented 9 years ago
David, I made following steps: 
  1. compiled your program, www.c into www.exe
  2. started mongoose: ./mongoose -cgi_ext .exe
  3. pointed my browser at http://127.0.0.1:8080/www.exe

I saw a valid output.
I haven't tried executing .exe from the HTML form yet.

Original comment by valenok on 18 Aug 2009 at 7:47

GoogleCodeExporter commented 9 years ago
I see. So what hnlee65 and I did not understand is that Mongoose can only 
execute one
type of CGI file, which must be specified by the cgi_ext directive, and that
executable files must be indicated by the ".exe" parameter (I had used "php" 
for php
cgi, which worked, so I was trying "exe" for executable files). Would one also 
use
"cgi_ext .exe" under Linux to execute files like "my_prog", which have no 
extensions?

I think these details need to be made clearer in the documentation.

Original comment by googl...@springtimesoftware.com on 18 Aug 2009 at 2:03

GoogleCodeExporter commented 9 years ago
Hmm. You could specify many CGI extensions. For example, this should work:
-cgi_ext .exe,.php

In this case, files that end with ".exe" and ".php" will be treated as CGI.
Or are we talking about different things?

Original comment by valenok on 18 Aug 2009 at 2:11

GoogleCodeExporter commented 9 years ago
The only other point I can think of is that some CGI files require the location 
of an
interpeter. PHP files require the pathname of the PHP CGI interpreter. EXE 
files do
not require such a pathname, since they are executed by calling a system 
function.
Linux script files require a filter program that looks at the first line of the 
file
to choose which interpreter to run.

When I have time, I'll retest with your latest version, if it is later than 2.8.

Original comment by googl...@springtimesoftware.com on 18 Aug 2009 at 2:25

GoogleCodeExporter commented 9 years ago
Correct.
If the cgi_interp is not set, then Mongoose looks at the first line of the 
program. If 
it starts with #!, then the rest is treated as an interpreter. This is true for 
UNIX 
and Windows.
If cgi_interp is set, then all files that match -cgi_ext will be started with 
that 
interpreter. No good for exe's.

Original comment by valenok on 18 Aug 2009 at 2:31

GoogleCodeExporter commented 9 years ago
So it sounds like a lot of details need to be added to the documentation, so 
poeple
don't have to experiment to figure it out.

You might get another bug report in the future if someone wants to run both .pl 
and
.exe files on a single website, or .pl and .php. Such situations actually 
happen.

Thanks.

Again, I'll test some more when I have time, probably in a few days.

Original comment by googl...@springtimesoftware.com on 18 Aug 2009 at 3:33

GoogleCodeExporter commented 9 years ago
the scenario:
1. compiled your program, www.c into www.exe
  2. started mongoose: ./mongoose -cgi_ext .exe
  3. pointed my browser at http://127.0.0.1:8080/www.exe

doesn't work for me on Windows XP. I always get "This webpage is not available" 
message. Any ideas?

Original comment by aab...@gmail.com on 16 Oct 2009 at 9:22

GoogleCodeExporter commented 9 years ago
Is this issue actually fixed?

Original comment by gymsou...@gmail.com on 1 Apr 2010 at 1:32

GoogleCodeExporter commented 9 years ago
I'm using 2.8 on Windows 7. I use CGI files written in C/C++.

In your config file you need to specify your extensions exactly or else the 
mongoose 
will bite you:

cgi_ext         exe

or if you want to use multiple extensions:

cgi_ext         cgi,exe

if you put a space between the comma it won't work and causes bad mojo. hope 
that 
helps.

Original comment by auronpri...@gmail.com on 7 Apr 2010 at 4:22

GoogleCodeExporter commented 9 years ago
Using the following program (test-cgi.c) and the config file (mongoose.conf), I 
get 
something similar to "webpage is not available." However, if my root directory 
is the 
directory where mongoose.exe is (i.e. mongoose.exe and test-cgi.exe are in the 
same 
directory), the problem goes away.

/* test-cgi.c */
#include <stdio.h>

int main(int argc, char** argv)
{
    printf("Content-Type: text/plain\n");
    printf("\n");
    printf("This is a test.\n");
    return 0;
}

# mongoose.conf
root            c:\tmp\cgi-bin
ports           80
cgi_ext         .exe

This works for me, so I didn't test any other permutations, but hopefully it 
helps 
people who need a workaround and provides some sort of starting point for 
anyone 
looking to fix this issue.

Original comment by ericdu...@gmail.com on 9 May 2010 at 3:05

GoogleCodeExporter commented 9 years ago
I created the test program suggested by ericdutko above.  I finally got it to 
work on my system, but I had to do the following:

#mongoose.conf
root c:\somewhere
cgi_ext exe,php

I think put the executable file (test.exe) in the same directory as 
mongoose.exe, and put a 0-byte file with the same name (test.exe) in the 
'c:\somewhere' directory.  It worked.  If I deleted the 0-byte 'test.exe' from 
'c:\somewhere', it fails; if I put 'test.exe' in 'c:\somewhere' and delete it 
from the directory with mongoose.exe, it fails.

Original comment by douglasm...@yahoo.ca on 2 Jul 2010 at 3:48

GoogleCodeExporter commented 9 years ago
This is a but in send_cgi function. when interp is null, cmdline variable was 
set correctly to the cgi directory, then overwritten. I did the following to 
fix it:

just added "else" in line 1299. The statements inside the 'else' was in the 
code before.

    /* else added by tiebing*/
    else{
        if ((p = (char *) strrchr(prog, '/')) != NULL)
            prog = p + 1;

        (void) mg_snprintf(conn, cmdline, sizeof(cmdline), "%s%s%s",
            interp, interp[0] == '\0' ? "" : " ", prog);
    }

Original comment by tiebingz...@gmail.com on 24 Jul 2010 at 3:02

GoogleCodeExporter commented 9 years ago
Is it even possible to pass arguments for interpreter in cgi_interp line? 
For Rebol "cgi_interp rebol.exe" works but "cgi_interp rebol.exe -q" don't. 
Seems to me this is the same problem with "tcc -run" what works like 
interpreter (on demand compilation)
Is there some special notation for passing the arguments to cgi interpreter?

Original comment by kebo...@gmail.com on 9 Aug 2010 at 8:46

GoogleCodeExporter commented 9 years ago
Sorry my fault, args passing works OK

Original comment by kebo...@gmail.com on 9 Aug 2010 at 9:20

GoogleCodeExporter commented 9 years ago
TCC(tcc -run) works as a perfect interpreter for mongoose. No problems with 
standard libraries. But whenever i include an optional (exported) external dll 
to process requests means, it dies!
For example,
1. In mongoose conf i used this confs:
cgi_pattern **.c$
cgi_interpreter ../cgi-interpreters/TinyCC/bin/tcc.exe -run -llibcgi

2. Everything normal when i use srd libs. But if i use libcgi, fails.

Code runs perfectly in console! I tried almost everything. Anybody have cure??

a. Copied libcgi.dll & imported def files to their home dirs.(system32 & lib 
dirs respectively)
b. Changed -L option in tcc(almost a 100 times)

No results, still 500:internal server error! Please help!

P.S I attached libcgi.dll & c script with this request!

Original comment by saravana...@gmail.com on 27 Jul 2012 at 6:04

Attachments:

GoogleCodeExporter commented 9 years ago
Got it working under Wine:
wine mongoose.exe -cgi_pattern '**.c$' -cgi_interpreter 'tcc/tcc.exe -I 
libcgi-1.0/src -llibcgi -L. -run'
I had to add this to the beginning of main():

  printf("%s\n\n", "Content-Type: text/html");

I believe this bug is fixed and I am closing it.

Original comment by valenok on 2 Oct 2012 at 10:50