Author Topic: BASIC  (Read 3463 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: BASIC
« Reply #15 on: March 11, 2023, 01:34:12 PM »
The ScriptBasic web solution is a lightweight httpd server using SB execution objects in a threaded sub-process with inter-thread variable sharing. (MT extension) It can run standalone or as a proxy.

I normally run sbhttpd as a proxy and Nginx to handle HTTPS and security. This environment can scale to whatever the demand might be required.

Offline Gemino Smothers

  • BASIC Developer
  • Posts: 24
    • Lucid Apogee
Re: BASIC
« Reply #16 on: March 13, 2023, 11:04:18 AM »
Where is it available? The web solution.

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: BASIC
« Reply #17 on: March 13, 2023, 11:14:48 AM »
SBHTTPD is included in the distribution for both Windows and Linux.

Offline Gemino Smothers

  • BASIC Developer
  • Posts: 24
    • Lucid Apogee
Re: BASIC
« Reply #18 on: March 13, 2023, 03:13:47 PM »
Ok, I see the documentation chm file.  At a glance, I see it works with Apache. Is that correct? In that case it's very much like PHP.

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: BASIC
« Reply #19 on: March 13, 2023, 03:52:45 PM »
I started off using Apache mod proxy reverse but I couldn't get it to work with HTTPS. Nginx is a MUCH better proxy server front end. I only use Apache for local web applications.

Session data is maintained in memory. Shared variables between SB threads have R/W locking if desired.

All this in less than a 800 KB footprint.

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: BASIC
« Reply #20 on: March 14, 2023, 09:55:11 PM »
Quote
In that case it's very much like PHP.

PHP is an external scripting language to Apache as is Python and others. The ScriptBasic web server is a C program that runs as a service managing threaded ScriptBasic execution objects. Session and shared variables are handled by the MT extension module. The CGI extension module supports cookies and POST/GET strings. This is an echo example that shows the CGI extension features.

CGI ECHO

Code: ScriptBasic
  1. ' CGI Echo
  2.  
  3. GLOBAL CONST nl = "\n"
  4. CONST NumberOfCookies = 3
  5.  
  6. INCLUDE cgi.bas
  7.  
  8. OPTION cgi$Method cgi::Get OR cgi::Post
  9.  
  10. cgi::Header 200,"text/html"
  11.  
  12. FOR i = 1 TO NumberOfCookies
  13.   ' cookie(i) is i, no domain is defined, path is /, expires after 10 seconds, not secure
  14.  cgi::SetCookie "cookie" & i, i, undef, "/", gmtime() + 10, false
  15. NEXT
  16.  
  17. cgi::FinishHeader
  18.  
  19. '-------------------------------------------------------
  20. PRINT """
  21. <HTML>
  22. <HEAD>
  23. <title>CGI Echo</title>
  24. </HEAD>
  25. <BODY><font face="VERDANA" size="2">
  26. <H1>View CGI Parameters</H1>
  27. This page shows the CGI parameters the way it was uploaded.
  28. <!-- here is the result of the previous HTTP request -->
  29. <FONT SIZE="3">
  30. <PRE>
  31. CGI system variables
  32. --------------------
  33.  
  34. """
  35.  
  36. PRINT "ServerSoftware  = ", cgi::ServerSoftware(), nl
  37. PRINT "ServerName      = ", cgi::ServerName(), nl
  38. PRINT "GatewayInterface= ", cgi::GatewayInterface(),nl
  39. PRINT "ServerProtocol  = ", cgi::ServerProtocol(), nl
  40. PRINT "ServerPort      = ", cgi::ServerPort(), nl
  41. PRINT "RequestMethod   = ", cgi::RequestMethod(), nl
  42. PRINT "PathInfo        = ", cgi::PathInfo(), nl
  43. PRINT "PathTranslated  = ", cgi::PathTranslated(), nl
  44. PRINT "ScriptName      = ", cgi::ScriptName(), nl
  45. PRINT "QueryString     = ", cgi::QueryString(), nl
  46. PRINT "RemoteHost      = ", cgi::RemoteHost(), nl
  47. PRINT "RemoteAddress   = ", cgi::RemoteAddress(), nl
  48. PRINT "AuthType        = ", cgi::AuthType(), nl
  49. PRINT "RemoteUser      = ", cgi::RemoteUser(), nl
  50. PRINT "RemoteIdent     = ", cgi::RemoteIdent(), nl
  51. PRINT "ContentType     = ", cgi::ContentType(), nl
  52. PRINT "ContentLength   = ", cgi::ContentLength(), nl
  53. PRINT "UserAgent       = ", cgi::UserAgent(), nl
  54. PRINT "Cookie          = ", cgi::RawCookie(), nl
  55.  
  56. PRINT "Referer         = ", cgi::Referer(), nl
  57. PRINT "Password        = ", Environ("HTTP_PASSWORD"), nl
  58. PRINT "Full auth string= ", Environ("HTTP_AUTHORIZATION"), nl
  59. PRINT "\nCookies:\n"
  60. FOR i = 1 TO NumberOfCookies
  61.   PRINT "cookie" & i, " ", cgi::Cookie("cookie" & i), "\n"
  62. NEXT
  63.  
  64. IF cgi::RequestMethod() = "GET" THEN
  65.   PRINT "GET text field using GetParam(\"TEXT-GET\") is ", cgi::GetParam("TEXT-GET"), nl
  66. END IF
  67.  
  68. IF cgi::RequestMethod() = "POST" THEN
  69.   PRINT "POST text field using PostParam(\"TEXT-POST\") is ", cgi::PostParam("TEXT-POST"), nl
  70. END IF
  71.  
  72. PRINT """
  73. </PRE>
  74. <TABLE>
  75.  <TR>
  76.    <TD BORDER=0 BGCOLOR="EEEEEE">
  77.      <PRE>
  78.      A simple form to POST parameters:<BR>
  79.      <FORM METHOD="POST" ACTION="/home/qbo/echo">
  80.        <INPUT TYPE="TEXT" VALUE="Default POST Field Text" NAME="TEXT-POST">
  81.        <INPUT TYPE="SUBMIT" NAME="SUBMIT-BUTTON" VALUE=" POST ">
  82.      </FORM>
  83.      </PRE>
  84.    </TD>
  85.    <TD BORDER=1 width="20">&nbsp;</TD>
  86.    <TD BORDER=0 BGCOLOR="EEEEEE">
  87.    <PRE>
  88.    A simple form to GET parameters:<BR>
  89.    <FORM METHOD="GET" ACTION="/home/qbo/echo">
  90.      <INPUT TYPE="TEXT" VALUE="Default GET Field Text" NAME="TEXT-GET">
  91.      <INPUT TYPE="SUBMIT" NAME="SUBMIT-BUTTON" VALUE=" GET ">
  92.    </FORM>
  93.  
  94.    </TD>
  95.  </TR>
  96. </TABLE>
  97. </BODY>
  98. </HTML>
  99. """
  100.  

« Last Edit: March 18, 2023, 11:32:49 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: BASIC
« Reply #21 on: March 19, 2023, 10:14:41 PM »
This is an example of using AJAX with the ScriptBasic application server. I'm using the MySQL Classic models DB for this demonstration. The dropdown button does an AJAX call to select the product line chosen.

AJAX Example

sbajax
Code: ScriptBasic
  1. ' ScriptBasic AJAX & MySQL
  2.  
  3. IMPORT cgi.bas
  4.  
  5. cgi::Header 200,"text/html"
  6. cgi::FinishHeader
  7.  
  8. PRINT """
  9. <html>
  10. <head>
  11. <script>
  12. function showItems(str) {
  13.  if (str == "") {
  14.    document.getElementById("results").innerHTML = "";
  15.    return;
  16.  } else {
  17.    var xmlhttp = new XMLHttpRequest();
  18.    xmlhttp.onreadystatechange = function() {
  19.      if (this.readyState == 4 && this.status == 200) {
  20.        document.getElementById("results").innerHTML = this.responseText;
  21.      }
  22.    };
  23.    xmlhttp.open("GET","/home/qbo/getitems.sb?q="+str,true);
  24.    xmlhttp.send();
  25.  }
  26. }
  27. </script>
  28. </head>
  29. <body>
  30.  
  31. <form>
  32.  <select name="items" onchange="showItems(this.value)">
  33.    <option value="">Product Line</option>
  34.    <option value="Classic Cars">Classic Cars</option>
  35.    <option value="Motorcycles">Motorcycles</option>
  36.    <option value="Planes">Planes</option>
  37.    <option value="Ships">Ships</option>
  38.    <option value="Trains">Trains</option>
  39.    <option value="Trucks and Buses">Trucks and Buses</option>
  40.    <option value="Vintage Cars">Vintage Cars</option>
  41.  </select>
  42. </form>
  43. <br>
  44. <div id="results"></div>
  45.  
  46. </body>
  47. </html>
  48. """
  49.  

getitems.sb
Code: ScriptBasic
  1. ' AJAX - getitems.sb
  2.  
  3. IMPORT cgi.bas
  4. IMPORT mysql.bas
  5.  
  6. cgi::Header 200,"text/html"
  7.  
  8. PRINT """
  9. <!DOCTYPE html>
  10. <html>
  11. <head>
  12. <style>
  13. table {
  14.  width: 100%;
  15.  border-collapse: collapse;
  16. }
  17.  
  18. table, td, th {
  19.  border: 1px solid black;
  20.  padding: 5px;
  21. }
  22.  
  23. th {text-align: left;}
  24. </style>
  25. </head>
  26. <body>
  27. """
  28.  
  29. product_line = cgi::GetParam("q")
  30.  
  31. dbh = mysql::RealConnect("localhost","USER","PASSWORD","classicmodels")
  32. mysql::query(dbh,"SELECT * FROM products WHERE productLine = '" & product_line & "'")
  33.  
  34. PRINT """
  35. <table>
  36.  <tr>
  37.    <th>Product Code</th>
  38.    <th>Product Line</th>
  39.    <th>Product Vendor</th>
  40.    <th>Product Name</th>
  41.    <th>In Stock</th>
  42.    <th>Cost</th>
  43.    <th>MSRP</th>
  44.  </tr>
  45. """
  46.  
  47. WHILE mysql::FetchHash(dbh,column)
  48.   PRINT "  <tr>\n"
  49.   PRINT "    <td>", column{"productCode"}, "</td>\n"
  50.   PRINT "    <td>", column{"productLine"}, "</td>\n"
  51.   PRINT "    <td>", column{"productVendor"}, "</td>\n"
  52.   PRINT "    <td>", column{"productName"}, "</td>\n"
  53.   PRINT "    <td align=\"right\">", column{"quantityInStock"}, "</td>\n"
  54.   PRINT "    <td align=\"right\">", FORMAT("%~$###.00~",column{"buyPrice"}), "</td>\n"
  55.   PRINT "    <td align=\"right\">", FORMAT("%~$###.00~",column{"MSRP"}), "</td>\n"
  56.   PRINT "  </tr>\n"
  57. WEND
  58.  
  59. PRINT """
  60. </table>
  61. </body>
  62. </html>
  63. """
  64.  
  65. mysql::Close(dbh)
  66.  

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: BASIC
« Reply #22 on: March 25, 2023, 04:56:06 PM »
I'm extending the ScriptBasic QBO SDK by adding a UI framework. I'm going to be using the Bootstrap 5 framework as its base.

QBO SDK Framework Example

Offline Gemino Smothers

  • BASIC Developer
  • Posts: 24
    • Lucid Apogee
Re: BASIC
« Reply #23 on: April 04, 2023, 10:21:10 AM »
I must say those examples do well to demonstrate how underrated Script Basic is.
One could replace PHP entirely with it, but without having to totally reinvent the wheel.

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: BASIC
« Reply #24 on: April 04, 2023, 04:07:51 PM »
I'm seriously thinking of renaming ScriptBasic to TGTBT BASIC:)

When you run any of the examples I posted they are running as a thread process of SBHTTPD.

Converting PHP code to ScriptBasic isn't hard to do. PHP is hard to interface with custom C libraries.

SBHTTPD and Nginx is a no bloat, fast web app development solution.
« Last Edit: April 04, 2023, 04:23:49 PM by John »