|
Post by packetteer on Nov 28, 2013 14:50:56 GMT 1
Hi All I have a simple form working using BaCon as the CGI coder. Here is the HTML and BaCon code used.
<html> <head> <title>Operator Check In Form</title> </head> <body>
<p><center>Hurricane Some Female Name</center> <br><center>Please fill in the from below.</center></p> <form action="/cgi/cgitest2.bin" method="GET"> CallSign: <input type="text" name="callsign" size=6> <br> <br> First Name: <input type="text" name="firstname" size=30> <br> <br> Time In: <input type="text" name="timein" size=5> <br> <br> Time Out: <input type="text" name="timeout" size=5> <input type="submit"> <p> </form> </body> </html>
REM CgiTest2.bac REM By John KB2SCS Software Inc REM 11/26/2013 PRINT "Content-type: text/html" PRINT "" PRINT "<HTML>" PRINT "<HEAD>" PRINT "<TITLE>Cgi BaCon form Test</TITLE>" PRINT "</HEAD>" PRINT "<BODY>" OPTION BASE 1 LOCAL dimension SPLIT GETENVIRON$("QUERY_STRING") BY "&" TO array$ SIZE dimension FOR i = 1 TO dimension PRINT array$[i],"<br>" NEXT PRINT "</BODY>" PRINT "</HTML>"
The above works just fine. But instead of GET I would like to use POST. POST sends a stream to your CGI handler which in my case is BaCon.
So in essence what I am asking is how can I read a stream? The PERL example that I found on the web shows. READ STDIN I looked at that the BaCon documentation and could not find any input type commands that read from STDIN (Standard In)
An example modifying my above code using POST would be greatly appreciated.
Thank you for your time in reading this.
For those of you in the US Happy Thanksgiving.
John
|
|
|
Post by Pjot on Dec 1, 2013 10:14:12 GMT 1
Hi packetteer, You can use INPUT to read from stdin. See also this demo. BR, Peter
|
|
|
Post by SunBurnt on Dec 8, 2013 6:42:39 GMT 1
Just asked this same Q...
|
|
|
Post by packetteer on Dec 14, 2013 15:02:23 GMT 1
Hi Peter Thank you for your reply and coming up with BaCon in the first place. I tried the demo program you referred to before posting my message. It compiled just fine but I could not get it to do anything. I ran it in my browser (SeaMonkey) as a direct URL. SeaMonkey displayed "Loading" then did nothing. No error message. Nothing.
Peter could you or someone else please either take my code and make it work with the Post command instead of the Get command or explain how the demo program is to be run?
Again thank you for all you have done with BaCon.
Thank you for your time in reading this post.
|
|
|
Post by Pjot on Dec 14, 2013 15:43:48 GMT 1
Hi packetteer, The INPUT statement waits for a <CR> (carriage return) at the end of the line. So the POST string must end with a <CR>. So if you do not end your POST string with a <CR> then INPUT will wait endlessly, and this is what you observe in the demonstration program. Instead of INPUT you can use WAIT a well. Below the same demonstration program using WAIT. BR, Peter PRINT "Content-type: text/html" PRINT "" PRINT "<HTML>" PRINT "<HEAD>" PRINT "<TITLE>Echo CGI</TITLE>" PRINT "</HEAD>" PRINT "<BODY>" PRINT "<H1>View CGI Parameters</H1>" PRINT "This page shows the CGI parameters by submitting to itself." PRINT "<PRE>" PRINT "" PRINT "CGI system variables" PRINT "--------------------" PRINT "" PRINT "ServerSoftware = ", GETENVIRON$("SERVER_SOFTWARE") PRINT "ServerName = ", GETENVIRON$("SERVER_NAME") PRINT "GatewayInterface= ", GETENVIRON$("GATEWAY_INTERFACE") PRINT "ServerProtocol = ", GETENVIRON$("SERVER_PROTOCOL") PRINT "ServerPort = ", GETENVIRON$("SERVER_PORT") PRINT "RequestMethod = ", GETENVIRON$("REQUEST_METHOD") PRINT "PathInfo = ", GETENVIRON$("PATH_INFO") PRINT "PathTranslated = ", GETENVIRON$("PATH_TRANSLATED") PRINT "ScriptName = ", GETENVIRON$("SCRIPT_NAME") PRINT "GET QueryString = ", GETENVIRON$("QUERY_STRING") WHILE TRUE stndin = WAIT(STDIN_FILENO, 50) IF stndin = 0 THEN BREAK POST$ = POST$ & CHR$(stndin) WEND PRINT "POST Form Data = ", POST$ PRINT "RemoteHost = ", GETENVIRON$("REMOTE_HOST") PRINT "RemoteAddress = ", GETENVIRON$("REMOTE_ADDR") PRINT "AuthType = ", GETENVIRON$("AUTH_TYPE") PRINT "RemoteUser = ", GETENVIRON$("REMOTE_USER") PRINT "RemoteIdent = ", GETENVIRON$("REMOTE_IDENT") PRINT "ContentType = ", GETENVIRON$("CONTENT_TYPE") PRINT "ContentLength = ", GETENVIRON$("CONTENT_LENGTH") PRINT "UserAgent = ", GETENVIRON$("HTTP_USER_AGENT") PRINT "Cookie = ", GETENVIRON$("HTTP_COOKIE") PRINT "Referer = ", GETENVIRON$("HTTP_REFERER") PRINT "Password = ", GETENVIRON$("HTTP_PASSWORD") PRINT "</PRE>" PRINT "<TABLE><TR><TD BORDER=0 BGCOLOR='EEEEEE'><PRE>" PRINT "A simple form to POST parameters:<BR>" PRINT "<FORM METHOD='POST' ACTION='/cgi-bin/cgi'>" PRINT "<INPUT TYPE='TEXT' VALUE='DEFAULT TEXT' NAME='TEXT-FIELD'>" PRINT "<INPUT TYPE='SUBMIT' NAME='SUBMIT-BUTTON' VALUE=' POST '>" PRINT "</FORM></PRE></TD>" PRINT "<TD BORDER=1 width='20'> </TD>" PRINT "<TD BORDER=0 BGCOLOR='EEEEEE'><PRE>" PRINT "A simple form to GET parameters:<BR>" PRINT "<FORM METHOD='GET' ACTION='/cgi-bin/cgi'>" PRINT "<INPUT TYPE='TEXT' VALUE='DEFAULT TEXT' NAME='TEXT-FIELD'>" PRINT "<INPUT TYPE='SUBMIT' NAME='SUBMIT-BUTTON' VALUE=' GET '>" PRINT "</FORM></PRE></TD></TR></TABLE>" PRINT "</BODY></HTML>"
|
|
|
Post by packetteer on Dec 14, 2013 20:46:24 GMT 1
Hi Peter Thank you so much. The demo program now works.
Now that I have a working demo program I will take what I have learned from it and apply it to my own code.
Once I have my code working I will repost it here to this thread so others can have yet another example.
Again thank you for all your time and effort it is greatly appreciated. John
|
|
|
Post by bigbass on Dec 18, 2013 21:04:03 GMT 1
Thank you packetteer for asking the question and Thank you Peter for the example I was curious and set up a local server to do some tests for CGI widgets very interesting I found some detailed info here about perl and CGI oreilly.com/openbook/cgi/ch02_02.htmland there are a few tutorials to set up LAMP which was fun to test out ! Joe
|
|
|
Post by packetteer on Dec 19, 2013 1:08:29 GMT 1
Hi Bigbass Thanks to Peter I have a working demo. Unfortunately even with the demo I am unable to get my code to work. I did not ask for anymore help here since I have decided that for what I am going to use CGI for the "GET" command works just fine. This Friday or Saturday I plan on adding to my code (See my first post) so that it takes care of the non alphanumeric characters. Such as a space showing up as +20 which is hex for the decimal 32 which is the ASCII code for the space character. I will then post the full code to this thread. Just in case there is anyone interested in seeing a fully working example using BaCon and the HTTP "GET" command. A little more background I am Running Hiawatha web server on Puppy Precise 5.5 If you would like some information on how to setup an FTP server, NGIRCD and Hiawatha web server on Puppy Linux then please go to the following URL. murga-linux.com/puppy/viewtopic.php?t=90470Thank you all for your time in reading this post. John
|
|
|
Post by bigbass on Dec 20, 2013 16:25:59 GMT 1
Hello packetteer I am looking forward to your modified example that converts the data to the corrected syntax I just want to document the first example before things get more complex as widgets get more complex having a simple example to get started with I am also interested in how we can use widgets in BaCon and looking at this from another view not using GTK but using web CGI widgets is something very useful since we can compile the the bacon CGI script it becomes "safer" and probably much faster too and at the same time keeping things simpler meaning reducing dependencies and coding it in BaCon syntax instead of perl It can be a big step getting the first example to work meaning what to set up such as a local server to test with then the index.html and configuring the server permissions but if you already have that done here we go 1.) named and compiled Peter's above code example bacon3-cgi.bac a small edit to add the bacon binary to the cgi path in two places notice the added bacon3-cgi (not sure if this was implied or I did it wrong but it works ) PRINT "<FORM METHOD='POST' ACTION='/cgi-bin/cgi/bacon3-cgi'>" PRINT "<FORM METHOD='GET' ACTION='/cgi-bin/cgi/bacon3-cgi'>" a full copy here wiki.basic-converter.org/index.php/Bacon3-cgi.bac2.) and placed the compiled binary bacon3-cgi in /usr/lib/cgi-bin/cgi *your location may differ* 3.) modified a simple index.html that will have a link to the Bacon cgi app here is a simple index.html note: on linux mint the location for the local server index root directory is /var/www/ <html><body><h1>It works!</h1> <p>This is the default web page for this server.</p> <p>The web server software is running but no content has been added, yet.</p>
<p> <A HREF="http://localhost/cgi-bin/cgi/bacon3-cgi">Test of cgi-binary using the compiled bacon3-cgi.bac </A><p>
</BODY></HTML>
clicking on the link in the html.index for the first time you will see this output before entering any info into the widgets ![](//storage.proboards.com/3081746/thumbnailer/kWAGs72dV0NS4ksIfk8T.png) then we input some data into the post widget and just click the POST button notice the changes in blue ![](//storage.proboards.com/3081746/thumbnailer/gV4IjlHSPjJcwf4Tj9XK.png) then we test the Get widget the same way CGI system variables -------------------- ServerSoftware = Apache/2.2.22 (Ubuntu) ServerName = localhost GatewayInterface= CGI/1.1 ServerProtocol = HTTP/1.1 ServerPort = 80 RequestMethod = GETPathInfo = PathTranslated = ScriptName = /cgi-bin/cgi/bacon3-cgi GET QueryString = TEXT-FIELD=DONALD+DUCK&SUBMIT-BUTTON=+GET+POST Form Data = RemoteHost = RemoteAddress = 127.0.0.1 AuthType = RemoteUser = RemoteIdent = ContentType = ContentLength = UserAgent = Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:26.0) Gecko/20100101 Firefox/26.0 Cookie = mw_installer_session=0kbgu0liecd1chertbqq96e437 Referer = http://localhost/cgi-bin/cgi/bacon3-cgi Password =
|
|
|
Post by bigbass on Dec 21, 2013 17:14:44 GMT 1
Just testing some ideas it can be a way to show how to compile and run bacon apps on the server this means you test any example code to see if it runs with the latest BaCon all point and click or just test how to compile bacon apps on a local server bacon3-cgi.bac is already on the server find a copy here wiki.basic-converter.org/index.php/Bacon3-cgi.bac we want to see if the latest version of bacon compiles it cleanly or just test compiling bacon apps this script below is also placed on the server the latest bacon is on the server too (just testing the local server though) bacon3-cgi-compile.bac *which we already pre compiled for safety* this could be done in perl or bash but why when we have BaCon
PRINT "Content-type: text/html" PRINT "" PRINT "<HTML>" PRINT "<HEAD>" PRINT "<TITLE>BaCon test</TITLE>" PRINT "</HEAD>" PRINT "<BODY>" PRINT "<H1>Compile BaCon app</H1>"
PRINT "<PRE>" PRINT "" PRINT "Compile BaCon app" PRINT "--------------------" PRINT ""
SYSTEM "bacon bacon3-cgi.bac >log.txt" PRINT "DONE!"
PRINT "</PRE>" PRINT "<A HREF='http://localhost/cgi-bin/cgi/bacon3-cgi'>Test of compiling a bacon-binary link</A>"
PRINT "</BODY></HTML>"
just enter in or have a link if you just want see what it will look like ![](//storage.proboards.com/3081746/thumbnailer/XNA7zMcCt3osP6biaKmN.png) a log gets made for it done easy by just clicking ![:)](//storage.proboards.com/forum/images/smiley/smiley.png) maybe testing to see the output maybe testing code without first having to install bacon keeping everything simple Joe
|
|
|
Post by packetteer on Dec 21, 2013 18:04:37 GMT 1
Hi All Here is my full example of using BaCon as a CGI handler instead of PERL or any other programming language for that matter. Again some background first. I am running Puppy Precise 5.5 My web server is Hiawatha web server. If you would like to setup Hiawatha in your version of puppy then please go to the following URL to see my post. murga-linux.com/puppy/viewtopic.php?t=90470This example is actually part of a presentation/demonstration that I and a friend are doing to demonstrate Amateur Radio Mesh networks using old Linksys Wifi routers. So this example does nothing with the users input to the form. There is a comment in the BaCon program that shows where the programmer should add BaCon data processing commands to do something useful with the data. The HTML GET command is used since I could not get the POST command to work. For what I will be using CGI for in the foreseeable future the GET command is all I Need. Now finally for the stuff that is really of interest to you. The HTML code used to display the Form in the users browser. Note the form action statement showing where the web server what directory and what file is to be used for the cgi code. Hiawatha defaults to the following path. /root/web-server I put my BaCon CGI exe in the /root/web-server/cgi directory The Hiawatha configuration file has a line where you tell it the extension of the cgi program it is to run. I added bin to this line. So I rename my BaCon exe files to filename.bin <html> <head> <title>Operator Check In Form</title> </head> <body>
<p><center>Hurricane Some Female Name</center> <br><center>Please fill in the from below.</center></p> <form action="/cgi/cgitest3.bin" method="GET"> CallSign: <input type="text" name="callsign" size=6> <br> <br> First Name: <input type="text" name="firstname" size=30> <br> <br> Time In: <input type="text" name="timein" size=5> <br> <br> Time Out: <input type="text" name="timeout" size=5> <input type="submit"> <p> </form> </body> </html>
Here is the BaCon cgitest3.bac code REM CgiTest3.bac REM By John KB2SCS Software Inc REM 12/21/2013 MIT License PRINT "Content-type: text/html" PRINT "" PRINT "<HTML>" PRINT "<HEAD>" PRINT "<TITLE>Cgi BaCon form Test</TITLE>" PRINT "</HEAD>" PRINT "<BODY>" OPTION BASE 1 LOCAL diminputs LOCAL dimanswers FUNCTION ConVert$(STRING Field$) IF INSTR(Field$,"+") <> 0 THEN Field$ = REPLACE$(Field$,"+"," ") END IF WHILE INSTR(Field$,"%") Sholdbeg$ = MID$(Field$,1,INSTR(Field$,"%")-1) 'Sholdbeg$ contains the first part of Field$ until the first % but not the %
Sholdend$ = MID$(Field$,INSTR(Field$,"%")+1) 'Sholdend$ contains the second part of Field$ including the 2 char hex code. The 'Hex code is the non alphanumeric char that we want to convert. This HEX code is 'the first two characters of Sholden$ ' Schar$ = CHR$(DEC(LEFT$(Sholdend$,2))) 'The above line takes the 2 char hex code and converts it into an ascii text character. ' Field$=Sholdbeg$ & Schar$ & MID$(Sholdend$,3) 'The MID$ command removes the HEX code from Sholden$. The above line also puts the 'Field$ variable back together replacing the %2CharHexCode with the converted char. WEND RETURN Field$ END FUNCTION ' SPLIT GETENVIRON$("QUERY_STRING") BY "&" TO arrayinputs$ SIZE diminputs FOR i = 1 TO diminputs SPLIT arrayinputs$[i] BY "=" TO arrayanswers$ SIZE dimanswers answer$=ConVert$(arrayanswers$[2]) 'With each pass of the loop answer$ will 'contain the users answer to each of your forms fields. At this point you 'can do processing on the users answers. This is a demo program so no 'processing is done on the users answers all the next line does is display 'the users answers on a new HTML page. PRINT answer$,"<br>" NEXT PRINT "</BODY>" PRINT "</HTML>"
The HEX coding of characters in an URL is called URL-EnCoding. Some WEB Servers will encode the + character for a space. Other Web Servers will encode a space as %20 which is the HEX code for decimal 32 the ascii code for the space character. I have not tried to have the + character or the % character as part of my from answers so I do not know if my code would handle these two cases. For my demonstration program I do not have to worry about this since as I am demonstrating the web server I will not use the + or % character in my form answers. I hope that this Post is of some use to someone at some time. Thank you for your time in reading this post.
|
|
|
Post by bigbass on Dec 21, 2013 19:11:53 GMT 1
Hey packetteer
A nice example widget!
you adjust the code for your server everyone will have something different but just to speed up things its done here
I called it hurricane.html then edited for my box
and renamed the bacon app to just cgitest3
I just wanted to give you a thank you and progress report that it works perfectly this will be helpful for anyone wanting to get started using BaCon with widgets now that you added the decoding in bacon Joe
|
|
|
Post by packetteer on Dec 21, 2013 20:40:12 GMT 1
Hi Joe Thank you for your kind words. Thank you for trying out the code. Nice to know that it works for others not just me. I am glad you find the example useful. John
|
|
|
Post by alexfish on Dec 22, 2013 2:56:48 GMT 1
Hi packetteer
Although have not tried the demo , the bit I noted was the chars encoding been displayed.
In xml and html and text mark up languages sometimes using glyphs will overcome the encoding problem
I am not sure it would work on a particular server , have never tested it
but do know the if I include a glyph char then what is actually displayed is the unicode or chr$
IE this bit of code is used for replacing the < and >
text$=REPLACE$(text$,">",">") text$=REPLACE$(text$,"<","<") tex$= "<span foreground='" & fcolor$ & "' background ='" & bcolor$ & "'>" & text$ & "</span>"
as U can see on the forum the ">",">" = first char = ">" then the replace char is "& gt" without the space
I do not know the replacement code for + or % but think 'Inkscape' has a look up table for glyph
not sure if glyph fits the bill but may be worth experimenting with.
BR Alex
|
|
|
Post by bigbass on Dec 22, 2013 5:11:31 GMT 1
Here is the source code for form widgets using post Widgets4.bacstill have to glue some things together But here is a sampler of widgets ![](//storage.proboards.com/3081746/thumbnailer/tVl7xBvdW66yEZfTPDPY.png) and easy to convert the cgi to BaCon so a lot of available stuff out there to get working quickly I ported the source code from here www.opensourcewebbook.com/cgi-bin/widgets3.cgito BaCon the difference is we have full bacon syntax and commands available ![:)](//storage.proboards.com/forum/images/smiley/smiley.png) Joe
|
|