newLISP Fan Club

Forum => newLISP and the O.S. => Topic started by: dukester on March 26, 2019, 06:28:10 AM

Title: Newlisp-Apache-CGI Issues Again
Post by: dukester on March 26, 2019, 06:28:10 AM
PS C:binnewlisp> newlisp -v

newLISP v.10.7.1 64-bit on Windows IPv4/6 UTF-8 libffi.



Running Apache2.4 on a Win10 box.



Apache is choking - once again - on the header sent by newlisp:


QuoteContent-type' contains invalid characters, aborting request


Lutz fixed a similar issue back in 2015, but it seems to have re-surfaced!



This is the code used then and now:
#!C:binnewlispnewlisp.exe
(print "Content-type: text/htmlnn")

(print "<html>")
(print "<h4>CGI by newLISP v" (sys-info -2)" on " ostype "</h4>")
(dolist (e (env)) (println (e 0) " : " (e 1) "</br>"))
(println "</html>")
(exit)


Anybody know how to fix this issue?
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: rickyboy on March 26, 2019, 11:56:19 AM
Looks suspiciously like the ole windoze versus unix line ending issue/difference. I'd check that before moving on to anything else.



For instance, what about trying this instead? (Sorry, "I don't do windows." :)


(println "Content-type: text/html")
(println "")

Or something like that? Good luck!
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: dukester on March 26, 2019, 01:47:31 PM
Quote from: "rickyboy"Looks suspiciously like the ole windoze versus unix line ending issue/difference. I'd check that before moving on to anything else.

Nope! It's a newlisp issue - just like back in 2015.



I tried your suggestion, even though I knew it wouldn't work. And it didn't. Lutz will have to get involved I'm sure. Thanks anyway!
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: rrq on March 26, 2019, 02:40:55 PM
You might want to try the initial line Status: 200 OK
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: dukester on March 26, 2019, 02:55:24 PM
Quote from: "ralph.ronnquist"You might want to try the initial line Status: 200 OK

Don't know what you mean!
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: rrq on March 26, 2019, 03:46:53 PM
afair, a CGI response that includes headers should have a very first line being the HTTP response status code, then the header lines, then an empty line, and then the payload.



You may omit the headers part and start with the empty line, and then the CGI runner would insert a standard header component (with a default status line).



But not all CGI runners insert a status line before headers when headers are given. For example, newlisp does insert a default status line and default headers (in its -http mode CGI runner), but possibly apache2 doesn't.



Though, I do this irregularly enough that I typically have to refer to the CGI spec's to remind myself about the nitty-gritty, and apache2 is (like most) a moving target anyhow.
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: dukester on March 26, 2019, 04:02:27 PM
@ralph.ronnquist - I'm sure that you are absolutely correct. However, I've never had to do what you are suggesting. Most of my experience has been on Apache using from CL to Perl to crank out CGI stuff.  Newlisp is the only interpreter that has ever given me fits with these type of issues - given that I didn't trash that very important first line of code.



Lutx fixed this issue once. He may not want to deal with it again. I've got the very same script running just fine using CLISP2.49. I don't use -http unless I want to serve an Intranet.



thx for getting back to me.
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: rickyboy on March 26, 2019, 04:10:49 PM
What ralph said.  Apache 2.4 got "strict" with the header validations to mitigate vulnerabilities when used as an http proxy, e.g. this one in 2016 (interesting read too):



https://httpd.apache.org/security/vulnerabilities_24.html#CVE-2016-8743



Notice the switch where you can turn that off (although not recommended):



http://httpd.apache.org/docs/2.4/mod/core.html#httpprotocoloptions



Could that have been the reason that that code worked recently and now it doesn't?  (Switch got changed?)



I think keeping that setting to the default strict mode and going down the path that ralph suggested for your troubleshooting sounds good to me -- at least in the meantime before you hear anything from Lutz.  Again, good luck.



(If I had the same stack, I could try to recreate the problem; however. along with not being a Windows user, I'm also not an Apache user. :)
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: dukester on March 26, 2019, 04:41:01 PM
@rickyboy  All good stuff!  But if Apache was being a bad-ass, it would be doing so with my Perl, Python and Ruby scripts!  Even old CLISP scripts run well.  Get where I'm going with this?  ;-)



Thanks for the heads-up regarding Apache security stuff!
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: xytroxon on March 26, 2019, 07:42:59 PM
I think the problem is that the command-line prompt and initial copyright banner output needs to be suppressed.



Change the line:
#!C:binnewlispnewlisp.exe

To:
#!C:binnewlispnewlisp.exe -c

-- xytroxon
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: dukester on March 26, 2019, 08:04:30 PM
Quote from: "xytroxon"I think the problem is that the command-line prompt and initial copyright banner output needs to be suppressed.



Change the line:
#!C:binnewlispnewlisp.exe

To:
#!C:binnewlispnewlisp.exe -c

Thx!  I'll give that a shot!!
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: dukester on March 26, 2019, 08:12:05 PM
Nope!  No cigar! LOL
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: Lutz on March 26, 2019, 08:21:55 PM
Try:


(print "Content-Type: text/htmlrnrn")
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: dukester on March 27, 2019, 03:35:40 AM
@lutz Thx, but that does not work either. Sorry!
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: rrq on March 27, 2019, 05:42:04 AM
Have you verified the byte sequence from the script, eg by running it manually and pipe its output into a file, which you the inspect with a hex code viewer? Or even perhaps like the following:
% thescript | C:binnewlispnewlisp.exe -e '(read 0 b 10000)(map char (explode b))'
Note, I don't really use windows myself, so I'm guessing about piping the output from one command (thescript) to another (the unpacking into character codes). In any case, the resulting character codes list should then begin
(67 111 110 116 101 110 116 45 116 121 112 101 ...
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: dukester on March 27, 2019, 08:28:17 AM
@ralph.ronnquist

You bet that I have an Hex editor!!  I don't see any garbage - which puzzles me. I've included a screen capture of the output. Now I'm wondering what Apache is choking on!! Pain in the Pa-toot!! LOL
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: Lutz on March 27, 2019, 09:55:43 AM
Check how NEWLISPDIR and PROGRAMFILES are defined.



See here for an explanation of these directories: http://www.newlisp.org/downloads/newlisp_manual.html#startup



You could use the fowlowing script to check:


Quote(println (env "PROGRAMFILES"))   ;  only defined on Windows

(println (env "NEWLISPDIR"))

(exit)
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: dukester on March 27, 2019, 10:28:03 AM
Both are set.  I've installed newlisp in c:binnewlisp to make sure that I did not have future issues with spaces in directory names like "Program Files" etc. So  NEWLISPDIR  points to c:binnewlisp.



PROGRAMFILES is set to "Program Files".  I changed it to c:binnewlisp.



The change did not fix my problem. BTW what did you do in 2015 to fix this very same issue?  You modified something in newlisp.exe and asked me to try your modifications. One of them worked!!! :-)
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: rickyboy on March 27, 2019, 10:34:49 AM
duke,



Hex dump seems ok to me. I'm assuming you did something like:


C:> newlisp-cgi-script > newlisp-cgi.out
Then, looked at newlisp-cgi.out in the hex editor.  Maybe try also something like:


C:> perl-cgi-script > perl-cgi.out
and maybe the same with the Ruby, CLISP scripts, etc. (i.e., all the CGI scripts that Apache doesn't choke on), and see if you can spot any difference between each output from those and newlisp-cgi.out.
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: Lutz on March 29, 2019, 07:47:48 AM
Try the following:



Create a subdirectory "newlisp" in "Program Files" and put the newlisp.exe executable in there. If there are any modules you are going to use, create a "modules" directory inside the "newlisp" directory.


(env "PROGRAMFILES") => C:Program Files (x86)
(env "NEWLISPDIR") => C:Program Files (x86)newlisp

Path of newlisp.exe is now: C:Program Files (x86)newlispnewlisp.exe



So both environment variables point to directories and the path in NEWLISPDIR must be in the executable path.



May be Windows finds the newlisp executable when using the command line, but not when called from Apache.



The original fix for Apache in 2015 was putting defaults (the above) for both environment variables.
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: dukester on March 29, 2019, 08:44:00 AM
@Lutz Thanks for all the trouble you went through!!  Unfortunately, after doing all your recommendations, nothing changed!  No Cigars!!  I still get the same response from Apache:


Quote[Fri Mar 29 09:35:53.040187 2019] [http:error] [pid 10048:tid 1076] [client 127.0.0.1:51447] AH02429: Response header name 'Environment variable TMP not set, assuming /tmp .Content-Type' contains invalid characters, aborting request


I keep wondering if it is not an Apache issue, but that question quickly fades away because I never get that response from any other interpreter!  So it must be something that "print" or "println" is emitting?  Maybe UTF8?
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: rickyboy on March 29, 2019, 12:21:08 PM
Quote from: "dukester"I keep wondering if it is not an Apache issue, but that question quickly fades away because I never get that response from any other interpreter!  So it must be something that "print" or "println" is emitting?  Maybe UTF8?

That's not what your hex dump indicates.



It may be due to a configuration/interface issue — I believe that's the trail Lutz was going down and a good one to pursue.



It would be nice to see what text stream Apache is seeing. It may be something very unlike what we are imagining in our heads. Any way to do that? IOW, does Apache have a better way to diagnose these problems (like a debug level) because that exception message that you get tells us hardly anything at all and it may even be "lying" to us.



Also, if you don't know already, you may want to research into how Apache is calling out to / running your script. There may be some devil in the details there. If they didn't doc it well, you might have to go code spelunking. Ugh.
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: dukester on March 29, 2019, 03:06:32 PM
@rickyboy  You know - I'm thinking that Lutz has already wasted enough time looking into this issue. If there were hundreds of folks using newlisp on Apache, it might then be a worthwhile investment of time.  I'm sure that the folks at Apache would pretty much feel the same way!  How many people are they aware of that use Apache to run newlisp scripts.  I'm sure they couldn't be bothered.



How's the song go? "You got to know when to hold 'em, know when to fold 'em, Know when to walk away and know when to run. "  Maybe that time is come.  I'll pick at it now and then, but let's not waste anymore time.  I thought the solution might be simple, and already solved. But there I went thinking again!  LOL   Thanks anyway!  Everybody ....
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: rickyboy on March 29, 2019, 04:09:43 PM
duke, I wasn't saying for Lutz to look at it, but for *you* to look at it.  lol!



No worries, I get it.  I've been there many times.  We do indeed have to make that determination: whether to spelunk or not.  :) Sometimes, it's not worth it, especially when we have time constraints.  I hope you get some time here and there to mess around with it ... and succeed!



All the best! rickyboy
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: dukester on March 29, 2019, 04:27:46 PM
Yeah!  I realized that you meant me!   I was just trying to be civil and say "No $%%^^* way!!"  LOL  And Lutz does have better things to do! Thanks - I will fiddle with it as and when the mood hits me.  Good luck yourself!
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: rrq on March 29, 2019, 06:12:05 PM
Hey!


Quote from: "dukester"
QuoteResponse header name 'Environment variable TMP not set, assuming /tmp .Content-Type' contains invalid characters, aborting request

That error message shows that newlisp has an initial "complaint" about "TMP", which means what it says, and that complaint precedes the script output. It has nothing to do with your script.



So the quest should rather be to get rid of that piece of output. That amounts to making sure that TMP is set before newlisp is invoked, or, you get it compiled without that complaint.
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: dukester on March 29, 2019, 06:23:16 PM
I've got TMP/tmp/temp set in so many places that all hell wont have it. BTW I never get this bleeding tmp issue with any other script.
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: rrq on March 29, 2019, 06:42:30 PM
RIght. And yet it's missing for newlisp.



Apparently Apache has "SetEnv" and "PassEnv" directives that possibly would service your use case. Or else, I suppose you can wrap the script with a shell script for this purpose. Or if you like living on the edge, you could apply a binary editor to your newlisp executable and put a 00 at the beginning of the boring output string ;)
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: rickyboy on March 29, 2019, 07:50:05 PM
Good catch, Ralph. I read that message wrong (but yet there is the response header name, right there between the two single quotes).  Didn't help that duke's OP didn't have the entire message there to begin with. Kinda faked me out. dukester! lol ;)
Title: Re: Newlisp-Apache-CGI Issues Again
Post by: dukester on April 03, 2019, 03:42:12 PM
Problem solved!



I configured Apache to run as a reverse proxy on a sub-directory to my cgi-bin containing newlisp scripts. I run newlisp as -http -d 8080 -w <fullpathtocgi-binnewLISP>



In Apache httpd.conf, simply load:

mod_proxy.so

mod_proxy_http.so

mod_proxy_http2.so



and insert the following directive in the same file:



<Location "/cgi-bin/newLISP/">
      ProxyPass  "http://127.0.0.1:8080/"
</Location>


Cigars and joy all around!!!  :-)