|
Post by rikky on Aug 3, 2021 18:14:07 GMT 1
CURDIR$ is only in the certificates directory because CERTIFICATE does not like variables in it (in my case) So I did a CHANGEDIR DIRNAME$(ME$) & "/srv/BaConServer/certificates" and then a CERTIFICATE "key.pem", "certificate.pem" What I use there is full_path$, which is the full path to whatever it is you have requested. That should be in your case : /home/peter/programming/bacon/BaConServer/srv/ Try this one and see what is shows: SERV_TLS.bac (79.01 KB)
|
|
|
Post by Pjot on Aug 3, 2021 19:36:47 GMT 1
Well I don't think you understand my reply? The 'full_path$' variable shows a "./srv" when printed on screen. The CURDIR$ shows '/home/peter/programming/bacon/BaConServer/srv/BaConServer/certificates'. So, if your program searches for "./srv" then it actually will be looking into its current directory to see if "./srv" is there. In other words, it will look for: /home/peter/programming/bacon/BaConServer/srv/BaConServer/certificates/./srv Your newly posted version in your last post shows the following: Connect with your browser to '127.0.0.1:8082'. HANDLE : 94640902535040
-------------------------------
----------------------------------- ----------------------------------- 3/8/2021 20:31:54 SSH_CLIENT : GET / HTTP/1.1 Host: localhost:8082 User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:90.0) Gecko/20100101 Firefox/90.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 Accept-Language: nl,en-US;q=0.7,en;q=0.3 Accept-Encoding: gzip, deflate, br Connection: keep-alive Upgrade-Insecure-Requests: 1 Sec-Fetch-Dest: document Sec-Fetch-Mode: navigate Sec-Fetch-Site: none Sec-Fetch-User: ?1
Runtime error: function 'FILETYPE' at line 2031 in 'SERV_TLS.bac': Unable to stat file: No such file or directory
BR Peter PS see line 489 in your program: CHANGEDIR DIRNAME$(ME$) & "/srv/BaConServer/certificates"
|
|
|
Post by rikky on Aug 3, 2021 21:05:44 GMT 1
Oh, I posted the wrong program, sorry, it's fixed now. But it's odd that you get a 'full_path$ = ./srv' recapitulating from the new program: REPEAT RECEIVE dat$ FROM handle CHUNK 1 SIZE size data$ = data$ & dat$ UNTIL RIGHT$(data$, 4) = Sep$ So data$ is the first chunk from the client. In your case: GET / HTTP/1.1 Host: localhost:8082 User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:90.0) Gecko/20100101 Firefox/90.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 Accept-Language: nl,en-US;q=0.7,en;q=0.3 Accept-Encoding: gzip, deflate, br Connection: keep-alive Upgrade-Insecure-Requests: 1 Sec-Fetch-Dest: document Sec-Fetch-Mode: navigate Sec-Fetch-Site: none Sec-Fetch-User: ?1
2309 line$ = TOKEN$(data$,1,NL$) => GET / HTTP/1.1 2313 SERV_DATA$("METHOD") = TOKEN$(line$,1) => GET 2314 SERV_DATA$(SERV_DATA$("METHOD")) = TOKEN$(DEL$(line$,1),1) => / 2001 adressbar$ = TOKEN$(SERV_DATA$(SERV_DATA$("METHOD")),1) (I see I made a dobble TOKEN$(..,1), the result stays the same.) => / 2008 adress$ = adressbar$ => / 2018 full_path$ = folder$ & adress$ AHA <= ./srv 547 GLOBAL folder$ = directory$ & "/srv" 487 LOCAL directory$ = DIRNAME$(ME$) Is apparently <= . I've made it into a REALPATH$(DIRNAME$(ME$)) See If this will do: SERV_TLS.bac (79.22 KB)
|
|
|
Post by Pjot on Aug 4, 2021 11:07:43 GMT 1
Thanks rikky, Now all works without a problem! The server uses full TLS and there are no errors. You're ready for retirement Below some of the last lines of the output your server is generating. BR, Peter -------------------------------- full_path$ : /home/peter/programming/bacon/BaConServer/srv/BaConServer/svg/pdf.svg --------------------------------
-------------------- CGI system variables --------------------
ALL_VARIABLES= HANDLE HEADER HTTP_REFERER METHOD GET Host User_Agent Accept Accept_Language Accept_Encoding Connection Referer Sec_Fetch_Dest Sec_Fetch_Mode Sec_Fetch_Site FULLPATH FILENAME URI DIRECTORY FILETYPE CONTENT_TYPE SERVER_SOFTWARE SERVER_NAME SERVER_PROTOCOL SERVER_PORT REQUEST_METHOD SCRIPT_NAME HTTP_USER_AGENT
HANDLE = 94710964719408
HEADER = GET /BaConServer/svg/pdf.svg HTTP/1.1 Host: localhost:8082 User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:90.0) Gecko/20100101 Firefox/90.0 Accept: image/webp,*/* Accept-Language: nl,en-US;q=0.7,en;q=0.3 Accept-Encoding: gzip, deflate, br Connection: keep-alive Referer: https://localhost:8082/ Sec-Fetch-Dest: image Sec-Fetch-Mode: no-cors Sec-Fetch-Site: same-origin
HTTP_REFERER = https://localhost:8082/ METHOD = GET GET = /BaConServer/svg/pdf.svg Host = localhost:8082 User_Agent = Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:90.0) Gecko/20100101 Firefox/90.0 Accept = image/webp,*/* Accept_Language = nl,en-US;q=0.7,en;q=0.3 Accept_Encoding = gzip, deflate, br Connection = keep-alive Referer = https://localhost:8082/ Sec_Fetch_Dest = image Sec_Fetch_Mode = no-cors Sec_Fetch_Site = same-origin FULLPATH = /home/peter/programming/bacon/BaConServer/srv/BaConServer/svg/pdf.svg FILENAME = pdf.svg URI = /BaConServer/svg/pdf.svg DIRECTORY = /home/peter/programming/bacon/BaConServer/srv/BaConServer/svg FILETYPE = svg CONTENT_TYPE = image/svg+xml SERVER_SOFTWARE = BaconServer TLS 0.13 SERVER_NAME = localhost SERVER_PROTOCOL = HTTP/1.1 SERVER_PORT = 8082 REQUEST_METHOD = GET SCRIPT_NAME = /BaConServer/svg/pdf.svg HTTP_USER_AGENT = Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:90.0) Gecko/20100101 Firefox/90.0 --------------------
|
|
|
Post by rikky on Aug 4, 2021 15:58:29 GMT 1
That is good to hear, for I have the SSL accept errors flying around my ears. Every time it eventually succeeds to grab a handle though, and the end result is that it works also here. There must still be something wrong in my system, or maybe a Raspi3 is just too little. It works, that's what is important. I have found one last bug. Working on this and then, if there are no new serious developments, I will update the package silently, and then that's it. Finally retired. Thanks, Rik.
|
|
|
Post by rikky on Dec 17, 2022 16:53:54 GMT 1
Not so. I want to put the following template here just for reference, in case my RPi crashes again. For if you put a SERVER into a FORK, you better be sure where to write your END SERVERS and put your ENDFORKS IF you mix things up, you'll end up with a lot of open handles. So CLOSE the SERVERS in the PARENT, NOT in the CHILD. Took me over a year to find this. OPTION EXPLICIT TRUE
GLOBAL HANDLE GLOBAL NEW$ = CHR$(13) & NL$ GLOBAL SEP$ = CHR$(13) & NL$ & CHR$(13) & NL$ GLOBAL CHILD GLOBAL dat$ GLOBAL data$ GLOBAL size GLOBAL mynet
SUB TRANSMIT(string$) IF HANDLE != 0 THEN SEND string$ TO HANDLE ELSE PRINT string$ END IF END SUB
SUB SEND_HEADER()
TRANSMIT("HTTP/1.1 200 Ok" & NEW$) TRANSMIT("Server: BaCon webserver" & NEW$) TRANSMIT("Cache-Control: no-cache, no-store, must-revalidate" & NEW$) TRANSMIT("Pragma: no-cache" & NEW$) TRANSMIT("Expires: 0" & NEW$) TRANSMIT("Connection: close" & NEW$) END SUB
FUNCTION SERVER$() REPEAT RECEIVE dat$ FROM HANDLE CHUNK 1 SIZE size IF ASC(dat$) = 0 THEN RETURN data$ END IF data$ = data$ & dat$ 'what happens if the SEP$ never comes? UNTIL RIGHT$(data$, 4) = SEP$ RETURN data$ END FUNCTION
SUB DOFORK()
CHILD = FORK IF CHILD = 0 THEN PRINT PRINT "I am the child, my PID is:", MYPID PRINT ' Get the request data$ = CHOP$(SERVER$()) SEND_HEADER() TRANSMIT("Content-type: text/plain; charset=UTF-8" & SEP$) TRANSMIT(NL$ & "HANDLE : " & STR$(HANDLE) & NL$ & data$ & NL$) LABEL END_SERV ENDFORK
PRINT NL$ & "HANDLE : " & STR$(HANDLE) & " : CLOSED" & NL$ ELIF CHILD > 0 THEN PRINT "I am the parent, pid of child : ", CHILD REPEAT PRINT PRINT "Waiting for ",CHILD," to exit" PRINT SLEEP 50 UNTIL REAP(CHILD) CLOSE SERVER HANDLE CLOSE SERVER mynet ELSE PRINT PRINT "Error in fork" PRINT ENDIF
END SUB
PRINT PRINT "Connect from browser 'http://localhost:8080." PRINT
' Ignore child signals to avoid zombie processes SIGNAL SIG_IGN, SIGCHLD
' Keep receiving requests WHILE TRUE
data$ = ""
OPEN "localhost:8080" FOR SERVER AS mynet
HANDLE = ACCEPT(mynet) IF HANDLE < 0 THEN CLOSE SERVER HANDLE CLOSE SERVER mynet ENDFORK ELSE DOFORK() END IF WEND
CLOSE SERVER mynet
END 0
So, I've got some work to do to implement this. Rik. Edit1 : putted an extra 'CLOSE SERVER mynet' in 'IF HANDLE < 0'
|
|
|
Post by rikky on Dec 20, 2022 17:44:48 GMT 1
Oeps, The above program is not only a bit ugly, having the mynet SERVER closed every time, instead of only the handle, but more importantly, it does not do the job. If you have a : REPEAT PRINT PRINT "Waiting for ",CHILD," to exit" PRINT SLEEP 50 UNTIL REAP(CHILD)
In the Parent then you can only have one child. You have to wait for that child to die, before you can have a new one. NOT a good idea for Slippy Maps. I now realize that my SERVER was working thanks to the bug. Only after 1022 HANDLES the computer says no. So you have to close them, somehow In a normal FORK, you can figure something out, but with a SERVER, the ACCEPT waits forever, until there is something, which means that you can never truly close the last Child. (For you can not test if it's finished) I have figured something out that works, with the ALARM. Nasty, but it works. Except that you have to close the handle if REAP = -1 It does that in a SUB apparently. I've got no idea why. New template : GLOBAL HANDLE GLOBAL NEW$ = CHR$(13) & NL$ GLOBAL SEP$ = CHR$(13) & NL$ & CHR$(13) & NL$ GLOBAL CHILD GLOBAL dat$ GLOBAL data$ GLOBAL size GLOBAL mynet GLOBAL var GLOBAL CHILDREN$ GLOBAL HANDLES$ GLOBAL key
SUB TRANSMIT(string$) IF HANDLE != 0 THEN SEND string$ TO HANDLE ELSE PRINT string$ END IF END SUB
SUB SEND_HEADER()
TRANSMIT("HTTP/1.1 200 Ok" & NEW$) TRANSMIT("Server: BaCon webserver" & NEW$) TRANSMIT("Cache-Control: no-cache, no-store, must-revalidate" & NEW$) TRANSMIT("Pragma: no-cache" & NEW$) TRANSMIT("Expires: 0" & NEW$) TRANSMIT("Connection: close" & NEW$) END SUB
SUB dinner() FOR word$ IN CHILDREN$ var = REAP(VAL(word$)) IF var = -1 THEN PRINT PRINT "ERROR IN REAP:" PRINT "child = " & word$ PRINT "HANDLE = " & TOKEN$(HANDLES$,ISTOKEN(CHILDREN$,word$)) PRINT 'CONTINUE : ' No, not in this case. END IF
IF var = 0 THEN CONTINUE : ' still busy. 'success istoken = ISTOKEN(CHILDREN$,word$) PRINT PRINT "HANDLE " & TOKEN$(HANDLES$,istoken) & " has ended." PRINT "PID = " & word$ & " : " & "REAP = " & STR$(var) PRINT "CLOSE SERVER " & TOKEN$(HANDLES$,istoken) CLOSE SERVER VAL(TOKEN$(HANDLES$,istoken)) CHILDREN$ = DEL$(CHILDREN$,istoken) HANDLES$ = DEL$(HANDLES$,istoken) PRINT NEXT word$ LABEL END_dinner ALARM dinner, 500 END SUB
PRINT "Connect from browser 'http://localhost:8080'."
PRINT "press a key :"; key = GETKEY PRINT CHR$(key) PRINT
dinner
' Ignore child signals to avoid zombie processes SIGNAL SIG_IGN, SIGCHLD
' Open listening port OPEN "localhost:8080" FOR SERVER AS mynet
' Keep receiving requests WHILE TRUE ' Handle for newly incoming connection HANDLE = ACCEPT(mynet) IF HANDLE < 0 THEN CONTINUE END IF ' Incoming connection -> create background process child = FORK IF child = 0 THEN ' We are in the child 'method 3 WHILE WAIT(HANDLE, 2000) RECEIVE dat$ FROM HANDLE CHUNK 1 SIZE size IF ASC(dat$) = 0 THEN BREAK data$ = data$ & dat$ IF RIGHT$(data$,4) = SEP$ THEN BREAK WEND data$ = CHOP$(data$) SEND_HEADER() TRANSMIT("Content-type: text/plain; charset=UTF-8" & SEP$) TRANSMIT(NL$ & "HANDLE : " & STR$(HANDLE) & NL$ & data$ & NL$) LABEL END_SERV 'NO! 'CLOSE SERVER HANDLE ENDFORK ELSE CHILDREN$ = CHOP$(CHILDREN$ & " " & STR$(child)) HANDLES$ = CHOP$(HANDLES$ & " " & STR$(HANDLE)) ENDIF WEND
CLOSE SERVER mynet
END 0
|
|
|
Post by rikky on Dec 26, 2022 12:09:41 GMT 1
Updated the BaConServer in the first post. Without the mayor bug this time. No TLS also. I now understand why I had so much errors flying round my ears. Other people did not experience this , possibly because they have a bigger computer that can handle more then 1020+ handles. Also cleaned up. What is left are a few demonstration programs in the cgi-example folder, AND a Seachart. No demonstration animation for the SeaChart, only one example file, for it is Xmas time. So there is not a lot of movement around here? That would be a dull animation. Unfortunately my locally served charts and boats work slower than vesseltracker over the net. This is discouraging. So lets see what Alexfish comes up with next week. Rik.
|
|
|
Post by alexfish on Dec 26, 2022 17:45:32 GMT 1
Hi Rik
Have looked at your code.
The While loops so not have a sleep,
normal and Esp on a PI use sleep 1
IE
WHILE (1) DO 'code bits here SLEEP 1
WEND
The sleep allows for other apps to get a slot . esp for an app which forks or threaded
the is an a update on hug_imager + map example * osm2seamap example
BR Alex
|
|
|
Post by rikky on Dec 26, 2022 19:42:55 GMT 1
Updated with SLEEP 2 (to be sure) in first post. Thanks.
|
|