skip to Main Content

Briefly: After a long time away from web tech, I’m experimenting with it again as I prepare to retire. Thus, this is merely a sandbox experiment I’m trying on my local machine. I’m using the X1 version of Aprelium’s Abyss web server, which I have used for a variety of purposes over the years very successfully.

I have a small sqlite database I’ve set up containing only one table, a guitar inventory. I wish to have a web form requesting the make and model and pass those values to a shell script and return the results in a frame on the web page.

I can successfully run a "select * from" sqlite3 query, but I’m stymied as to how I can receive the form values. From a command line, I can run

make=Fender

model=Telecaster

sqlite3 -list guitardb 'select * from inventory where make = "${make}" and model = "${model}";'

But I can’t seem to capture the FORM data. I created a simple CGI script to show the environment variables returned when the FORM is processed, but there is no QUERY_CONTENT or RESPONSE_QUERY or any data values in the display. I can see POST or GET methods, but neither gives me data.

I know Abyss is not the most well-known web server, but I’ve run it in an office environment using luxcal, and a file upload/download capability, and I even made a mockup phpBB3 forum, so I know it’s possible.

(Why not use php, you may ask? Simply because I’m not wanting to learn a new programming language at the time. As I said, this is a proof of concept, and I’m pretty close, I think). Any assistance will be appreciated.

This is the response from calling my script to display the environment variables. Edited to remove user name. (Sorry for the length). The REQUEST_METHOD (GET in this case) is shown, but not the data:

XPC_SERVICE_NAME=0
PATH=/usr/bin:/bin:/usr/sbin:/sbin
XPC_FLAGS=0x0
SERVER_SOFTWARE=Abyss/2.16.4-X1-macOS AbyssLib/2.16.4
SERVER_PROTOCOL=HTTP/1.1
HTTPS=off
IS_SUBREQ=false
HTTP2=off
COOKIE=phpbb3_qtei6_k=; PHPSESSID=d7mvb47vlrd43160290ugec0n9; PHPSESSIDmycal=d7mvb47vlrd43160290ugec0n9mycal; phpbb3_qtei6_u=2; phpbb3_qtei6_sid=3961a5f7ff7cf89e8b34ab94a5559a7d
SERVER_PORT=80
SERVER_NAME=localhost
SERVER_ADDR=::1
LOCAL_ADDR=::1
REMOTE_ADDR=::1
REMOTE_PORT=62529
REQUEST_URI=/cgi-bin/envvars.sh?
GATEWAY_INTERFACE=CGI/1.1
DOCUMENT_ROOT=/Users/user/Abyss Web Server/htdocs
APPL_MD_PATH=/
APPL_PHYSICAL_PATH=/Users/user/Abyss Web Server/htdocs
URL=/cgi-bin/envvars.sh
SCRIPT_URI=http://localhost/cgi-bin/envvars.sh?
SCRIPT_URL=/cgi-bin/envvars.sh?
SCRIPT_NAME=/cgi-bin/envvars.sh
SCRIPT_FILENAME=/Users/user/Abyss Web Server/htdocs/cgi-bin/envvars.sh
REQUEST_FILENAME=/Users/user/Abyss Web Server/htdocs/cgi-bin/envvars.sh
REQUEST_METHOD=GET
CONTENT_LENGTH=0
HTTP_HOST=localhost
HTTP_CONNECTION=keep-alive
HTTP_SEC_CH_UA="Brave";v="111", "Not(A:Brand";v="8", "Chromium";v="111"
HTTP_SEC_CH_UA_MOBILE=?0
HTTP_SEC_CH_UA_PLATFORM="macOS"
HTTP_UPGRADE_INSECURE_REQUESTS=1
HTTP_USER_AGENT=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36
HTTP_ACCEPT=text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8
HTTP_SEC_GPC=1
HTTP_ACCEPT_LANGUAGE=en-US,en
HTTP_SEC_FETCH_SITE=same-origin
HTTP_SEC_FETCH_MODE=navigate
HTTP_SEC_FETCH_USER=?1
HTTP_SEC_FETCH_DEST=document
HTTP_REFERER=http://localhost/envtest.html
HTTP_ACCEPT_ENCODING=gzip, deflate, br
HTTP_COOKIE=phpbb3_qtei6_k=; PHPSESSID=d7mvb47vlrd43160290ugec0n9; PHPSESSIDmycal=d7mvb47vlrd43160290ugec0n9mycal; phpbb3_qtei6_u=2; phpbb3_qtei6_sid=3961a5f7ff7cf89e8b34ab94a5559a7d
ALL_HTTP=HTTP_HOST: localhost
HTTP_CONNECTION: keep-alive
HTTP_SEC_CH_UA: "Brave";v="111", "Not(A:Brand";v="8", "Chromium";v="111"
HTTP_SEC_CH_UA_MOBILE: ?0
HTTP_SEC_CH_UA_PLATFORM: "macOS"
HTTP_UPGRADE_INSECURE_REQUESTS: 1
HTTP_USER_AGENT: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36
HTTP_ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8
HTTP_SEC_GPC: 1
HTTP_ACCEPT_LANGUAGE: en-US,en
HTTP_SEC_FETCH_SITE: same-origin
HTTP_SEC_FETCH_MODE: navigate
HTTP_SEC_FETCH_USER: ?1
HTTP_SEC_FETCH_DEST: document
HTTP_REFERER: http://localhost/envtest.html
HTTP_ACCEPT_ENCODING: gzip, deflate, br
HTTP_COOKIE: phpbb3_qtei6_k=; PHPSESSID=d7mvb47vlrd43160290ugec0n9; PHPSESSIDmycal=d7mvb47vlrd43160290ugec0n9mycal; phpbb3_qtei6_u=2; phpbb3_qtei6_sid=3961a5f7ff7cf89e8b34ab94a5559a7d

ALL_RAW=Host: localhost
Connection: keep-alive
sec-ch-ua: "Brave";v="111", "Not(A:Brand";v="8", "Chromium";v="111"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "macOS"
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8
Sec-GPC: 1
Accept-Language: en-US,en
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Sec-Fetch-Dest: document
Referer: http://localhost/envtest.html
Accept-Encoding: gzip, deflate, br
Cookie: phpbb3_qtei6_k=; PHPSESSID=d7mvb47vlrd43160290ugec0n9; PHPSESSIDmycal=d7mvb47vlrd43160290ugec0n9mycal; phpbb3_qtei6_u=2; phpbb3_qtei6_sid=3961a5f7ff7cf89e8b34ab94a5559a7d

INSTANCE_ID=0
X_ABYSS_STATS_SERVER_TOTAL=4398
X_ABYSS_STATS_SERVER_ERROR=211
X_ABYSS_STATS_SERVER_HTML=656
X_ABYSS_STATS_SERVER_IMAGE=768
X_ABYSS_STATS_SERVER_NOTMODIFIED=884
X_ABYSS_STATS_SERVER_OUTPUT=30538689
X_ABYSS_STATS_SERVER_UPTIME=5640289
X_ABYSS_STATS_SERVER_CURRENT_UPTIME=677192
X_ABYSS_STATS_HOST_TOTAL=4398
X_ABYSS_STATS_HOST_ERROR=211
X_ABYSS_STATS_HOST_HTML=656
X_ABYSS_STATS_HOST_IMAGE=768
X_ABYSS_STATS_HOST_NOTMODIFIED=884
X_ABYSS_STATS_HOST_OUTPUT=30538689
X_ABYSS_STATS_HOST_UPTIME=5640127
X_ABYSS_STATS_HOST_CURRENT_UPTIME=677192
X_ABYSS_STATS_HOST_COMPRESS_TOTAL=1273
X_ABYSS_STATS_HOST_COMPRESS_OUTPUT=2968368
X_ABYSS_STATS_HOST_COMPRESS_ORIGINAL_OUTPUT=12760398
X_ABYSS_STATS_SERVER_COMPRESS_TOTAL=1938
X_ABYSS_STATS_SERVER_COMPRESS_OUTPUT=5098202
X_ABYSS_STATS_SERVER_COMPRESS_ORIGINAL_OUTPUT=22201933
HOME=/Users/user
LOGNAME=root
SHLVL=1

2

Answers


  1. Chosen as BEST ANSWER

    Every day is an improvement. I have resolved the issue of passing POST (and GET) data to a shell script. Thanks to other posts and hints, here is the solution, in brief.

    In my HTML page, I have a form that uses the POST method to pass the values from two inputs: MAKE and MODEL. That form calls a shell script which contains:

    setIFS=$IFS
    IFS="=&"
    tag=(`cat < vars.txt`)
    

    The effect of setting IFS to "=&" strips out the single line POST data (e.g., name=Martin&model=D18) into an array of 4 words. Words 2 and 4 make up the parameters to pass to the sqlite query. I added code to clarify this:

    mk="${tag[2]}"
    md="${tag[4]}"
    

    And the finished query is

    sqlite3 -box $db "select * from inventory where make like "%$mk%" and model like "%$md%";"
    

    This all runs fine from the command line. The next step is to wrap it in HTML to render it on a web page... (e.g.,


  2. SQL string delimiter is a single quote, while you are providing double quotes.
    Additionally, the single quote probably hinder variable replacement.

    In such a case, you should redirect stderr to stdout to see evtl. error output.
    To check var resolving, exchange "sqlite" with "cat" and try to use a here-document instead of cmdline param wherever possible:

    cat << .EndOfInput
    bla bla bla
    ${sausageDog}
    blub
    .EndOfInput
    

    this way, you don’t have to care so much about escaping quotes and stuff.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search