[HN Gopher] CGI with Awk on OpenBSD Httpd (2020)
       ___________________________________________________________________
        
       CGI with Awk on OpenBSD Httpd (2020)
        
       Author : todsacerdoti
       Score  : 86 points
       Date   : 2021-05-04 13:03 UTC (9 hours ago)
        
 (HTM) web link (box.matto.nl)
 (TXT) w3m dump (box.matto.nl)
        
       | hibbelig wrote:
       | Using awk to run CGI scripts is a cool idea. Awk is underrated
       | :-)
        
         | pantulis wrote:
         | I did that 20 years ago with Solaris. Was contrived and not the
         | easiest thing, but work it did.
        
           | cyberpunk wrote:
           | I once inherited one such system, it was running on 2.5.1..
           | My job was to move it to a zone on s10.. It actually pretty
           | much worked, I had to port it forwards to S8, but then word
           | got around that someone had done 'something' to this ancient
           | pile of tech debt and feature requests started coming in so I
           | rewrote it all in perl in an afternoon.. I didn't even try to
           | understand the code, I just used tcpdump to look at the
           | requests/responses and treated it as a black box.
           | 
           | I don't miss this kind of work ;)
        
             | pantulis wrote:
             | There has been a lot of advances all these years, thank
             | $DEITY.
        
       | tyingq wrote:
       | You can also coax gawk into being a web server itself, albeit a
       | bit brain-dead. I wish they would tweak the way it does server
       | sockets so that you could make a decent forking server. As it
       | stands now, you don't get the socket until after the listen() and
       | accept().
       | 
       | https://news.ycombinator.com/item?id=22085459
        
       | sigmonsays wrote:
       | totally unrelated to the topic but here I am following this blog
       | now because of very much in common. That is, 1. i3, 2. emacs, 3.
       | sync'ing git repos accross machines.
       | 
       | https://box.matto.nl/sparkleshare-to-sync-org-files.html
        
       | [deleted]
        
       | torstenvl wrote:
       | I like obhttpd and would like to migrate to it eventually. Cool
       | project!
        
         | Voline wrote:
         | I have several servers running it, and I've been pretty pleased
         | with it. If you want to try it out you can get an OpenBSD VM at
         | Vultr or OpenBSD.amsterdam for about $6/month.
         | 
         | I also highly recommend Michael W Lucas's book Relayd & Httpd
         | Mastery.
        
           | torstenvl wrote:
           | One thing keeping me on Apache I stead of NGINX or obhttpd is
           | how easy it is to do overrides for particular directories. I
           | use this A LOT for generating dynamic content.
           | 
           | Example: Let's say I want to generate an RTF doc for a power
           | of attorney. I'll set the index in /poa/ to be poa.rtf and
           | also tell Apache to treat .rtf documents in that directory as
           | CGI scripts. poa.rtf then is a Python script to process the
           | QUERY_STRING or POST parameters into an RTF template and spit
           | it out. End result is that browser requests poa.rtf and gets
           | a file called poa.rtf -- generated on the fly.
           | 
           | Do you have an idea how you'd accomplish the same trickery in
           | obhttpd? I guess you'd have to have the per-directory config
           | in the main config file?
        
       | gbrown_ wrote:
       | I replied to someone on Twitter about this as I mistakenly
       | thought they were the author, but the interpreter line in the
       | example script should be #!/usr/bin/awk rather than #!/bin/awk.
        
         | sigzero wrote:
         | Yeah, I don't see how to contact the actual author.
        
         | LeoPanthera wrote:
         | You can use "#!/usr/bin/env awk" to make it universal, this
         | works on all the BSDs and Linux. Works for bash and other
         | interpreters too.
        
           | gbrown_ wrote:
           | I just wanted to point out typo. I'm aware of the env idiom,
           | though that wouldn't work in the chroot environment described
           | in the article. Short of also copying it to the chroot which
           | would be a bit redundant.
        
         | the_trapper wrote:
         | The author actually has it right due to OpenBSD's httpd running
         | in a chroot of /var/www.
         | 
         | Edit: nevermind, you're right, just checked it again and the
         | author put the copied awk under /usr/bin inside the chroot
        
       | nwmcsween wrote:
       | Maybe use with https://github.com/nwmcsween/tawk
       | 
       | sample index.html.tawk which can generate index.html
       | 
       | ```` <p> {{! cat /proc/cpuinfo }} </p>
       | 
       | ````
        
         | throwawayboise wrote:
         | Except in this specific example, OpenBSD doesn't have /proc
        
           | nwmcsween wrote:
           | This was an example... Do any command you feel like with that
           | awk script
        
           | mrweasel wrote:
           | And it wouldn't work in a chroot.
        
       | bifrost wrote:
       | I used to do this with csh to annoy a certain friend, awk
       | would've been pretty good too TBH.
        
       | mkovach wrote:
       | When I had a requirement to do this, I used the one true awk and
       | compiled it statically. Didn't require mucking around with all
       | the libraries.
        
       | bdwjn wrote:
       | I was expecting computer-generated imagery, disappointed.
        
       ___________________________________________________________________
       (page generated 2021-05-04 23:02 UTC)