CGI issue (SOLVED)

Just starting out? Need help? Post your questions and find answers here.
thanos
Enthusiast
Enthusiast
Posts: 422
Joined: Sat Jan 12, 2008 3:25 pm
Location: Greece
Contact:

Re: CGI issue

Post by thanos »

@Daniel
I tried the

Code: Select all

WriteCGIStringN("</body></html>")
in both Windows and Lixux. Same bad results.
I run the Dependency Walker.
There is a warning as you can see in the attached photos.
I copied the api-ms-win-service-private-l1-1-1.dll inside the cgi-bin directory but without any improvement.
https://files.fm/u/cfbvz73b4
I do not own the Linux server. I tested the executables in site which I buy host.
I give you the direct link and i hope it may help you understand something more.
http://www.adouros.gr/cgi-bin/cgi_test.cgi
The small c piece is working:
http://www.adouros.gr/cgi-bin/cgi_trivial_test.cgi
» myPersonal Banker :: Because you do not need to have a master degree in economics in order to organize your finances!
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: CGI issue

Post by infratec »

Code: Select all

More information about this error may be available in the server error log.
So please look into /var/log/apache/error.log or whatever the webbrowser error log is.
thanos
Enthusiast
Enthusiast
Posts: 422
Joined: Sat Jan 12, 2008 3:25 pm
Location: Greece
Contact:

Re: CGI issue

Post by thanos »

infratec wrote:

Code: Select all

More information about this error may be available in the server error log.
So please look into /var/log/apache/error.log or whatever the webbrowser error log is.
[Wed Dec 30 18:28:59.754489 2020] [cgi:error] [pid 5868:tid 1704] [client ::1:50849] End of script output before headers: a_test64.exe
» myPersonal Banker :: Because you do not need to have a master degree in economics in order to organize your finances!
DarkDragon
Addict
Addict
Posts: 2218
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: CGI issue

Post by DarkDragon »

infratec wrote:

Code: Select all

More information about this error may be available in the server error log.
So please look into /var/log/apache/error.log or whatever the webbrowser error log is.
He already pasted it here: viewtopic.php?p=563694#p563694
But it would be interesting to see if it changed.

@thanos
Did you compile in console mode (see compiler options)?
bye,
Daniel
User avatar
the.weavster
Addict
Addict
Posts: 1537
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Re: CGI issue

Post by the.weavster »

If the problem is missing content length you could try using chunked transfer encoding.

Give this a try:

Code: Select all

EnableExplicit

If Not InitCGI() Or Not ReadCGI()
  End
EndIf

Procedure SendChunk(txt$)
  Protected nSize = StringByteLength(txt$, #PB_UTF8)
  If nSize = 0 : ProcedureReturn : EndIf ; don't want to SendEOT by mistake
  Protected hxSize$ = Hex(nSize)
  Protected res$ = hxSize$ + #CRLF$ + txt$ + #CRLF$
  WriteCGIString(res$, #PB_UTF8) 
EndProcedure

Procedure SendEOT()
  WriteCGIString(Hex(0) + #CRLF$ + #CRLF$, #PB_UTF8)
EndProcedure

WriteCGIHeader(#PB_CGI_HeaderContentType, "text/html", #PB_UTF8)
WriteCGIString("Transfer-Encoding: chunked" + #CRLF$ + #CRLF$, #PB_UTF8)

SendChunk("<html><title>PureBasic CGI</title><body>") 
Procedure WriteCGIConstant(Constant$)
  SendChunk(Constant$ + ": " + CGIVariable(Constant$) + "<br>")
EndProcedure

WriteCGIConstant(#PB_CGI_AuthType)
WriteCGIConstant(#PB_CGI_ContentLength)
WriteCGIConstant(#PB_CGI_HeaderContentType)
WriteCGIConstant(#PB_CGI_DocumentRoot)
WriteCGIConstant(#PB_CGI_GatewayInterface)
WriteCGIConstant(#PB_CGI_PathInfo)
WriteCGIConstant(#PB_CGI_PathTranslated)
WriteCGIConstant(#PB_CGI_QueryString)
WriteCGIConstant(#PB_CGI_RemoteAddr)
WriteCGIConstant(#PB_CGI_RemoteHost)
WriteCGIConstant(#PB_CGI_RemoteIdent)
WriteCGIConstant(#PB_CGI_RemotePort)
WriteCGIConstant(#PB_CGI_RemoteUser)
WriteCGIConstant(#PB_CGI_RequestURI)
WriteCGIConstant(#PB_CGI_RequestMethod)
WriteCGIConstant(#PB_CGI_ScriptName)
WriteCGIConstant(#PB_CGI_ScriptFilename)
WriteCGIConstant(#PB_CGI_ServerAdmin)
WriteCGIConstant(#PB_CGI_ServerName)
WriteCGIConstant(#PB_CGI_ServerPort)
WriteCGIConstant(#PB_CGI_ServerProtocol)
WriteCGIConstant(#PB_CGI_ServerSignature)
WriteCGIConstant(#PB_CGI_ServerSoftware)
WriteCGIConstant(#PB_CGI_HttpAccept)
WriteCGIConstant(#PB_CGI_HttpAcceptEncoding)
WriteCGIConstant(#PB_CGI_HttpAcceptLanguage)
WriteCGIConstant(#PB_CGI_HttpCookie)
WriteCGIConstant(#PB_CGI_HttpForwarded)
WriteCGIConstant(#PB_CGI_HttpHost)
WriteCGIConstant(#PB_CGI_HttpPragma)
WriteCGIConstant(#PB_CGI_HttpReferer)
WriteCGIConstant(#PB_CGI_HttpUserAgent)

SendChunk("</body></html>")
SendEOT()
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1243
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: CGI issue

Post by Paul »

This is the PB example code precompiled to Linux...
https://reelmedia.org/test/testcgi.cgi

Download it and place in your cgi-bin folder on your Linux Server.
Make sure permissions are 755 for this file.

See if you have a problem calling this file.
Image Image
thanos
Enthusiast
Enthusiast
Posts: 422
Joined: Sat Jan 12, 2008 3:25 pm
Location: Greece
Contact:

Re: CGI issue

Post by thanos »

DarkDragon wrote: @thanos
Did you compile in console mode (see compiler options)?
Yes.
But i also tried as normal executable.
» myPersonal Banker :: Because you do not need to have a master degree in economics in order to organize your finances!
thanos
Enthusiast
Enthusiast
Posts: 422
Joined: Sat Jan 12, 2008 3:25 pm
Location: Greece
Contact:

Re: CGI issue

Post by thanos »

Paul wrote:This is the PB example code precompiled to Linux...
https://reelmedia.org/test/testcgi.cgi

Download it and place in your cgi-bin folder on your Linux Server.
Make sure permissions are 755 for this file.

See if you have a problem calling this file.
Download the file, copy to my site, set permission to 755.
Two calls,
http://www.adouros.gr/cgi-bin/testcgi.cgi?name=paul and http://www.adouros.gr/cgi-bin/testcgi.cgi
Same results

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at webmaster@adouros.gr to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
» myPersonal Banker :: Because you do not need to have a master degree in economics in order to organize your finances!
thanos
Enthusiast
Enthusiast
Posts: 422
Joined: Sat Jan 12, 2008 3:25 pm
Location: Greece
Contact:

Re: CGI issue

Post by thanos »

the.weavster wrote:If the problem is missing content length you could try using chunked transfer encoding.

Give this a try:

Code: Select all

EnableExplicit

If Not InitCGI() Or Not ReadCGI()
  End
EndIf

Procedure SendChunk(txt$)
  Protected nSize = StringByteLength(txt$, #PB_UTF8)
  If nSize = 0 : ProcedureReturn : EndIf ; don't want to SendEOT by mistake
  Protected hxSize$ = Hex(nSize)
  Protected res$ = hxSize$ + #CRLF$ + txt$ + #CRLF$
  WriteCGIString(res$, #PB_UTF8) 
EndProcedure

Procedure SendEOT()
  WriteCGIString(Hex(0) + #CRLF$ + #CRLF$, #PB_UTF8)
EndProcedure

WriteCGIHeader(#PB_CGI_HeaderContentType, "text/html", #PB_UTF8)
WriteCGIString("Transfer-Encoding: chunked" + #CRLF$ + #CRLF$, #PB_UTF8)

SendChunk("<html><title>PureBasic CGI</title><body>") 
Procedure WriteCGIConstant(Constant$)
  SendChunk(Constant$ + ": " + CGIVariable(Constant$) + "<br>")
EndProcedure

WriteCGIConstant(#PB_CGI_AuthType)
WriteCGIConstant(#PB_CGI_ContentLength)
WriteCGIConstant(#PB_CGI_HeaderContentType)
WriteCGIConstant(#PB_CGI_DocumentRoot)
WriteCGIConstant(#PB_CGI_GatewayInterface)
WriteCGIConstant(#PB_CGI_PathInfo)
WriteCGIConstant(#PB_CGI_PathTranslated)
WriteCGIConstant(#PB_CGI_QueryString)
WriteCGIConstant(#PB_CGI_RemoteAddr)
WriteCGIConstant(#PB_CGI_RemoteHost)
WriteCGIConstant(#PB_CGI_RemoteIdent)
WriteCGIConstant(#PB_CGI_RemotePort)
WriteCGIConstant(#PB_CGI_RemoteUser)
WriteCGIConstant(#PB_CGI_RequestURI)
WriteCGIConstant(#PB_CGI_RequestMethod)
WriteCGIConstant(#PB_CGI_ScriptName)
WriteCGIConstant(#PB_CGI_ScriptFilename)
WriteCGIConstant(#PB_CGI_ServerAdmin)
WriteCGIConstant(#PB_CGI_ServerName)
WriteCGIConstant(#PB_CGI_ServerPort)
WriteCGIConstant(#PB_CGI_ServerProtocol)
WriteCGIConstant(#PB_CGI_ServerSignature)
WriteCGIConstant(#PB_CGI_ServerSoftware)
WriteCGIConstant(#PB_CGI_HttpAccept)
WriteCGIConstant(#PB_CGI_HttpAcceptEncoding)
WriteCGIConstant(#PB_CGI_HttpAcceptLanguage)
WriteCGIConstant(#PB_CGI_HttpCookie)
WriteCGIConstant(#PB_CGI_HttpForwarded)
WriteCGIConstant(#PB_CGI_HttpHost)
WriteCGIConstant(#PB_CGI_HttpPragma)
WriteCGIConstant(#PB_CGI_HttpReferer)
WriteCGIConstant(#PB_CGI_HttpUserAgent)

SendChunk("</body></html>")
SendEOT()
Tried to linux and windows.
http://www.adouros.gr/cgi-bin/cgi_the_weavster.cgi
Same error as above.
But as you can see, in the attached picture https://ibb.co/0DLk760 there is a small executable cgi_trivial_test.cgi in the same path, which i compiled with tcc (the code is before some posts)
This cgi is working well
http://www.adouros.gr/cgi-bin/cgi_trivial_test.cgi
or
http://www.adouros.gr/cgi-bin/cgi_trivi ... ame=THANOS
» myPersonal Banker :: Because you do not need to have a master degree in economics in order to organize your finances!
User avatar
the.weavster
Addict
Addict
Posts: 1537
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Re: CGI issue

Post by the.weavster »

I did a fresh install of XAMPP on my PC, compiled the code I included above and put the exe in the cgi-bin and I have no errors:
Image


Where did you install XAMPP? There was a warning about your choice of install folder:
Image
thanos
Enthusiast
Enthusiast
Posts: 422
Joined: Sat Jan 12, 2008 3:25 pm
Location: Greece
Contact:

Re: CGI issue

Post by thanos »

@the.weavster
At:
C:\xampp
Path without space or any special character
» myPersonal Banker :: Because you do not need to have a master degree in economics in order to organize your finances!
User avatar
HeX0R
Addict
Addict
Posts: 980
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: CGI issue

Post by HeX0R »

Is that your local PC or a remote one?
I'm just asking, because if those are remote PCs and you are transfering your cgi file with a ftp client, make sure that it transfers it in BINARY mode.
I had similar problems somewhen in the past, because that damn FTP client thought cgi files must be transmitted in ascii mode.
But then your whole file is scrambled and of no use.
thanos
Enthusiast
Enthusiast
Posts: 422
Joined: Sat Jan 12, 2008 3:25 pm
Location: Greece
Contact:

Re: CGI issue

Post by thanos »

Happy new year!
HeX0R wrote:Is that your local PC or a remote one?
I'm just asking, because if those are remote PCs and you are transfering your cgi file with a ftp client, make sure that it transfers it in BINARY mode.
I had similar problems somewhen in the past, because that damn FTP client thought cgi files must be transmitted in ascii mode.
But then your whole file is scrambled and of no use.
Both. The local pc running Xampp for Windows and the remote is running Linux.
I have used the Filezilla for decades. It was always in Auto mode for transfers.
I changed to binary mode as you suggested and everything is working now! I can't believe it! :shock:
Thank you very much!!!
The strange issue is the c compiled cgi. It had been transferred with same way, and it worked. Probably the Filezilla understood from its headers, that it is binary?
Never mind,
The only remaining thing for now is to solve the issue in Xammp for windows.
» myPersonal Banker :: Because you do not need to have a master degree in economics in order to organize your finances!
User avatar
the.weavster
Addict
Addict
Posts: 1537
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Re: CGI issue

Post by the.weavster »

thanos wrote:The only remaining thing for now is to solve the issue in Xammp for windows.
Perhaps just uninstall and reinstall xampp because it worked out of the box for me
DarkDragon
Addict
Addict
Posts: 2218
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: CGI issue

Post by DarkDragon »

thanos wrote:Probably the Filezilla understood from its headers, that it is binary?
I think it might have converted all newlines and the PureBasic libraries might have some 10 (LF) or 13 (CR) commands inside which got converted. The C code is also a bit smaller, if you did more stuff there it might have appeared, too.

Btw. I don't use FTP anymore and I can recommend switching over to SSH alternatives such as SFTP or SCP. However it is only a recommendation.
bye,
Daniel
Post Reply