|
Post by rikky on Jul 12, 2021 15:42:27 GMT 1
A Server like Apache. Should serv nearly everything. Only tested little things like images text html js css. But it should work for everything that has an official content-type. works like a charm. For GET and POST. The rest is not implemented yet. Got a nice favicon even, if you do not provode your own. NOT tested streaming things nor upload etc. It"s written as clearly as possible so that you do not have to do a lot of effort to be able to understand the program. It's got a few issues though, that I cannot solve, only work around. Dealing with BaCon flaw inside of a FORK. A (CGI) script called from within a fork does not receive the current directory, and always returns the exitcode 0, even when it's not. Especially the latter is nasty. I have to rewrite al my Apache cgi's to work around this. A clear explanation about this issue can be seen when you serv to <ip:port>/Playroom/script Working on a bug report for this, but I do not want to have a bug report as big as this. I want to have a bug report no longer than 5 sentences. That's why it is in Projects. It is perfect. Easily understandably written. T's got a readme. A new access method: bcaccess, which is super, compared to htaccess. You can do 675 times more with less effort, if you think of it. Just imagine the Rewriterules from htaccess, ghhh... You learn BaCon in half the time than that you learn htaccess. But then again, It's mostly the not so clever people that think they are clever. So I'm looking for criticism. What is wrong, what is stupid, what can be better, And help for providing a short bug report is appreciated. BaConServer.tgz (517.25 KB) Rik Btw9 updated BaConServer to version 1.42 No TLS this time, maybe later.
|
|
|
Post by Pjot on Jul 12, 2021 17:00:59 GMT 1
Thanks rikky, Very cool! Note that compilation fails in 4.3.2 with an error: "'ACTION' redeclared as different kind of symbol". The ACTION word already is being used by libc in the 'search.h' header file. I had to rename ACTION on lines 996 and 1022 and after that all worked. Looking forward to your bug report, Regards Peter
|
|
|
Post by rikky on Jul 13, 2021 5:28:43 GMT 1
Ah, indeed. Renamed ACTION to _ACTION and now it works. AND the RETVAL error vanished in version 4.3.2 This was the main issue. Now SSH_CLIENT returns an empty value though. Working onit.
|
|
|
Post by rikky on Jul 18, 2021 10:41:37 GMT 1
Updated to version 0.8 in first post. I forgot last time that a lot of people are working on different systems. And there are some executables in there. So start with compiling 'compile.bac' and then running 'compile' Then run 'SERV' , just like that should do. Then point your browser to the given ip:port adress. Implemented this time is an example upload program. Surf to ip:port/upload/upload It should be able to upload everything. Tested text pdf and tar.gz The uploaded files are then positioned in the folder 'downloads' Surf to ip:port/downloads. You will there find your uploaded files. Click on anyone of them, and if all went well, this file will now be downloaded back. The SeaChart will have to wait a bit, for this took longer then I thought it would. Rik.
|
|
|
Post by rikky on Jul 20, 2021 15:48:57 GMT 1
Apart from 228 people visiting this blog in one time , it's awfully quiet out here. deleted by user ? Updated BaConServer to version 0.9. I think now it is super. It blasts Apache from it's feet by it's simplicity. And safe? off course it's save. It all depends on you, what you allow, and what mistakes you make. Apache's security politic is to make things complex. But that is not secure. It only makes the chance for mistakes bigger. It's these mistakes that the hackers use. (my opinion) So the more simple it is, the more secure it is. For you find your mistakes easier. One such a mistake might be to allow users to upload bcaccess(.bac) So don't allow it, problem solved. (see example in the upload folder) Note for Pjot.: The retval error and the SSH-CLIENT variable are system related, NOT bacon related. Updated my original raspy to bacon version 4.iforgot and the retval error is still there, as well as the SSH-CLIENT variable. Ghhhh ... Linux .. Rik.
|
|
|
Post by Pjot on Jul 20, 2021 17:09:54 GMT 1
Thanks rikky, Compiles and runs as advertised looks good! I guess most people are on holidays... BR Peter
|
|
|
Post by vovchik on Jul 20, 2021 18:47:07 GMT 1
Dear Rik,
Thanks. It is working very nicely. Well done. And it is easy to use. I will now look at your code....and learn something.
With kind regards, vovchik
|
|
|
Post by rikky on Jul 22, 2021 14:58:35 GMT 1
Thanks Pjot & Vovchik. The SSH_CLIENT problem is solved. Turned out there never was a SSH_CLIENT problem. I started developing this server on a remote raspberry, where there was already an Apache server running. This way I could lay the two alongside and check things. Later I needed to update my bacon, so I just took my server to the machine I was already working on. And the SSH_CLIENT disappeared. Now I discovered, by working on yet another raspberry, that the SSH_CLIENT was back again. Aha .. when the client comes from 'abroad' there is an SSH_CLIENT available, otherwise not, problem solved. I have my SeaChart for the BaConServer ready, and was wondering where to publish it. Since the SeaChart program itself did not change much, apart from the BaConServer parts and The BaconServer itself changed into something maybe now a bit too fancy , I publish it here. Now you can put a file favicon.svg in a folder and that will then be used as a favicon for this folders and it's subfolders, AND it will be used as the folder-icon in the .. how do you call this in English .. file overview? Don't realy know if that was a good idea. At least now it has a good example of what you can do with bcacces.bac in the SeaChart folder That was it, everything ready, nothing to do anymore. I'm going to retire. Thanks for your attention. Rik.
|
|
|
Post by Pjot on Jul 22, 2021 19:48:38 GMT 1
I'm going to retire. Really? But you did not implement CGI yet Anyway, well done! Thanks and regards,
Peter
|
|
|
Post by rikky on Jul 22, 2021 21:44:30 GMT 1
?? Are you making a joke that I do not understand ?? It"s nearly all cgi. One big bunch of scripts.
|
|
|
Post by Pjot on Jul 23, 2021 6:31:10 GMT 1
Hi rikky, Well, my apologies for any misunderstanding, but I guess my concept of CGI is different than yours? Or maybe I missed something? So, can you show us how we can do the following with your server (quoting Wiki here): "A typical use case occurs when a Web user submits a Web form on a web page that uses CGI. The form's data is sent to the Web server within an HTTP request with a URL denoting a CGI script. The Web server then launches the CGI script in a new computer process, passing the form data to it. The output of the CGI script, usually in the form of HTML, is returned by the script to the Web server, and the server relays it back to the browser as its response to the browser's request." Thanks! Peter
|
|
|
Post by rikky on Jul 23, 2021 8:17:05 GMT 1
Ghh, that was a short lived retirement. From the wikipedia the first example is the addition of two numbers. Make a folder called CGI Make bcaccess.bac IF GETENVIRON$("FILENAME") = "INDEX" THEN PRINT "ACTION : CGI" Make INDEX.bac CHANGEDIR DIRNAME$(ME$) : ' make sure you are in the directory of the script. handle = VAL(GETENVIRON$("HANDLE")) : ' this is the handle the server gave to you. 'some variables CONST New$ = CHR$(13) & NL$ CONST Sep$ = CHR$(13) & NL$ & CHR$(13) & NL$ 'send header SEND "HTTP/1.1 200 Ok" & New$ TO handle SEND "Server: BaCon webserver" & New$ TO handle SEND "Content-type: text/html; charset=UTF-8" & Sep$ TO handle
SEND NL$ TO handle SEND "<BR>" & NL$ TO handle SEND "<!DOCTYPE html>" & NL$ TO handle SEND "<html>" & NL$ TO handle SEND " <body>" & NL$ TO handle SEND " <form method='POST'>" & NL$ TO handle SEND " <fieldset>" & NL$ TO handle SEND " <legend>Enter two numbers to add</legend>" & NL$ TO handle SEND " <label>First Number: <input type='number' name='num1'></label><br/>" & NL$ TO handle SEND " <label>Second Number: <input type='number' name='num2'></label><br/>" & NL$ TO handle SEND " </fieldset>" & NL$ TO handle SEND " <button>Add</button>" & NL$ TO handle SEND " </form>" & NL$ TO handle SEND "<BR>" & NL$ TO handle
IF GETENVIRON$("Content_Length") <> "" THEN data$ = "" part_one$ = "" : ' part one is not needed in this case REPEAT RECEIVE data$ FROM handle CHUNK 1 SIZE size part_one$ = part_one$ & data$ UNTIL RIGHT$(part_one$,LEN(Sep$)) = Sep$ 'two methods in this case: 'method 1: 'REPEAT ' RECEIVE data$ FROM handle CHUNK 1 SIZE size ' SEND data$ TO handle ' part_two$ = part_two$ & data$ 'UNTIL RIGHT$(part_two$,LEN(Sep$)) = Sep$ 'method 2: length = VAL(GETENVIRON$("Content_Length")) total_size = 0 part_two$ = "" WHILE total_size < length RECEIVE data$ FROM handle CHUNK 1 SIZE size total_size = total_size + size part_two$ = part_two$ & data$ WEND var1$ = TOKEN$(TOKEN$(part_two$,1,"&"),2,"=") var2$ = TOKEN$(TOKEN$(part_two$,2,"&"),2,"=") SEND "<br>" & NL$ TO handle SEND var1$ & " + " & var2$ & " = " & STR$(VAL(var1$)+VAL(var2$)) & "<br>" & NL$ TO handle ELSE END IF SEND " </body>" & NL$ TO handle SEND "</html>" & NL$ TO handle Now I'm going to retire. Rik.
|
|
|
Post by vovchik on Jul 23, 2021 12:37:16 GMT 1
Dear Rik, I know this isn't BaCon (it's python3), but it is tiny, supposedly supports CGI and runs on my Pi. You might have some use for it... With kind regards, vovchik
|
|
|
Post by rikky on Jul 23, 2021 13:59:45 GMT 1
I don't get ir. It's working fine. In fact it was already working fine. The whole upload.bac program in the folder upload is a fairly complex cgi program. And since I'm just retired, I'm NOT going to learn Python3 I'm going to sit behind my geraniums and look out of the window all day, every day. But here is the next one. bcaccess.bac IF GETENVIRON$("FILENAME") = "user_pass" THEN PRINT "ACTION : CGI" user_pass.bac CHANGEDIR DIRNAME$(ME$) : ' make sure you are in the directory of the script. handle = VAL(GETENVIRON$("HANDLE")) : ' this is the handle the server gave to you. 'some variables CONST New$ = CHR$(13) & NL$ CONST Sep$ = CHR$(13) & NL$ & CHR$(13) & NL$ 'send header SEND "HTTP/1.1 200 Ok" & New$ TO handle SEND "Server: BaCon webserver" & New$ TO handle SEND "Content-type: text/html; charset=UTF-8" & Sep$ TO handle
SEND NL$ TO handle SEND "<BR>" & NL$ TO handle SEND "<pre>" & NL$ TO handle SEND "Login :" & NL$ TO handle SEND "<form method=post> " & NL$ TO handle SEND "username :" & NL$ TO handle SEND "<input type='text' value='some user' " & \ "size='10' maxlength='10' name='username' " & \ "tabindex='1'>" & NL$ TO handle SEND "password :" & NL$ TO handle SEND "<input type=password placeholder='Enter Password' " & \ "size='10' maxlength='15' name=password " & \ "required> <input type=submit name=password_action " & \ "value=ok size=2> </form>" & NL$ TO handle SEND "</pre>" & NL$ TO handle
IF GETENVIRON$("Content_Length") <> "" THEN data$ = "" part_one$ = "" : ' part one is not needed in this case REPEAT RECEIVE data$ FROM handle CHUNK 1 SIZE size part_one$ = part_one$ & data$ UNTIL RIGHT$(part_one$,LEN(Sep$)) = Sep$ 'two methods in this case: 'method 1: 'REPEAT ' RECEIVE data$ FROM handle CHUNK 1 SIZE size ' SEND data$ TO handle ' part_two$ = part_two$ & data$ 'UNTIL RIGHT$(part_two$,LEN(Sep$)) = Sep$ 'method 2: length = VAL(GETENVIRON$("Content_Length")) total_size = 0 part_two$ = "" WHILE total_size < length RECEIVE data$ FROM handle CHUNK 1 SIZE size total_size = total_size + size part_two$ = part_two$ & data$ WEND var1$ = TOKEN$(TOKEN$(part_two$,1,"&"),2,"=") var2$ = TOKEN$(TOKEN$(part_two$,2,"&"),2,"=") SEND "user = " & var1$ & "<br>" & NL$ TO handle SEND "password = " & var2$ & "<br>" & NL$ TO handle ELSE END IF SEND " </body>" & NL$ TO handle SEND "</html>" & NL$ TO handle
|
|
|
Post by Pjot on Jul 23, 2021 17:12:46 GMT 1
Hi rikky, Thanks for the example, but your program doesn't fully demonstrate a CGI capability A script which resides in a CGI directory should be able to read parameters from its standard input. Note this text: "If parameters are sent to the script via an HTTP POST request, they are passed to the script's standard input." But I do not think your server is able to make this work. See also the RFC for CGI. Please note that Apache has such functionality. If you can make the BaCon CGI program work with your server then I will be convinced Best regards Peter
|
|