Jump to content

marcovaldo

Members
  • Content Count

    20
  • Joined

  • Last visited

Everything posted by marcovaldo

  1. Hi All, Beside using MARS as a REST server using JSON interface I also want to serve a few plain HTML pages used for status display with browsers. There shall be a table returned containing text and if possible images/icons beside that like Device1 online [an image] Device2 offline [ an other image] Is there any example how to do this? The images are shown as broken in browser. Does this need multiple endpoints to serve ? (One for the text and then one extra for every image, as the browser will do several HTTP connections to retrieve them) I am using Indy in a windows service (alternatively startable via /GUI as application) Kind Greetings, M.
  2. marcovaldo

    Serving html page containing images

    Attila, thank you for advice! Any advice that this is very welcome, as security is always a very important aspect of IT...
  3. marcovaldo

    Serving html page containing images

    The slightly extended version of the handler now sends differnt images from [Application Bin folder]\img folder function TDominoServerResource.ServerImg([PathParam('*')] AllStrings: string): TStream; begin //DebLog.DebOut('ImageRequest:'+AllStrings+'*'); //AllStrings contains plain image filename Result := TFileStream.Create('img\'+AllStrings, fmOpenRead or fmShareDenyWrite); end; Why I wanted that MARS is also serving HTML pages for browser - Status Display - Setup functions (as my app normally is running as service) My old application used a telnet connection for that purpose but I bet that customer IT is nowadays unhappy having an open telnet connection on a productive server. The http connection can be protected by various auth methods.. Greetings
  4. marcovaldo

    Serving html page containing images

    Fixed: 1) Created a separate handler in MARS for images (similar to MARSContentType Demo): [GET, Path('/img/{*}'), Produces('image/jpg')] function ServerImg([PathParam('*')] AllStrings: string): TStream; and function TDominoServerResource.ServerImg([PathParam('*')] AllStrings: string): TStream; begin Result := TFileStream.Create('Sample.jpg', fmOpenRead or fmShareDenyWrite); end; Note: This sample serves only one fixed image to all requests. AllStrings needs to be processed still... 2) In HTML I had to take care not only on HTML SRC path but also on MARS/REST path <img src="/rest/default/myservername/img/Sample.jpg"> Waterfall mode of Chrome Browser is your friend! (as it showed what is requested by browser) Greetings to All, M.
  5. marcovaldo

    Serving html page containing images

    Many Thanks Attila, for your quick help! I am trying to play with the Bootstrap Server example (as I can edit html without compile) In Mars this page is served as follows function THelloWorldResource.SayHelloWorld: string; var LStreamReader: TStreamReader; begin LStreamReader := TStreamReader.Create('..\www\helloworld.html', TEncoding.UTF8); try Result := LStreamReader.ReadToEnd; finally LStreamReader.Free; end; end; What works: if the IMG is served from external server What doesn't work: if the IMG is referenced to local filesystem (location of binary) i thought that WEB root is application folder (maybee I am wrong?) Just try to find something in the web about this .... Greetings!
  6. Solved. Need not the URL; generic meta refresh works for me..
  7. Hi, I am following down this path - but no success: - marsRequest stays nil - Also ading [HeaderParam] and [QueryParam] stay empty. What I am looking for is having the RequestURL to create an auto refresh status page which autorefreshs after a short time. Don't want to set URL as constant string... Any hints how to retrieve the Request URL simplest way (Just scrolling through Demo Code, but not seeing the trees instead of the wood...) Kind Greetings, Marcovaldo
  8. marcovaldo

    License Questions -

    Hello All, Hi Kiriakos Vlahos, Many thanks, Kiriakos, for creating the P4D and Pyscripter! (I am only just scratchig on the surface, but I am allready aware that this is a great tool and opportunity) Question (maybee anybody here has a hint) if I include P4D Code into my commercial application, how do the different licenses propagate through the call stack: Delphi code (commercial project) D4P Interface Code (MIT license) Python code (PSFL similar to BSD license ) 3rd party Library (GPL or Commercial license ) Question: Isolates the D4P and Python layer the Delphi App from the GPL constraints or propagates this up so that I need either putting my App into GPL too or purchase a commercial license of the 3rd party lib? Kind greetings, marcovaldo
  9. marcovaldo

    License Questions -

    Many thanks for your Answer - I want to do it the proper way, therefore was asking.
  10. Hi All, I am working on a MARS Server (runnable as Application AND as Service). MARS REST interface is used to communicate with Enterprise IoT Servers (eg. Upstream comms) The same Server also shall communicate using various TCP protocols to IoT Sensors (eg Downstream comms) ? What TCP library would you recommend to use for this ? - Indy is used by (the stand alone server of MARS). Its a blocking/synchronous library (the downcomms will have to be moved into threads) ? Might using this interfere with the MARS internals? - ICS - I was very happy using this over the years in kind of Bread and butter VCL apps. But not sure if they depend much on Windows Message Loop / Events and might be difficult to handle in a Windows Service/ Multithreading enviroment (I will have to implement much to keep the engine under the hood running) (I think there is a Multiping Example by Angus Robertson at least, which might help me) ? Is it better to go for Indy or even for the Synapse lightweight library - because a linear comms task in a thread is simpler structure than all that message pump ens Event stuff ? Many thanks in advance for any suggestion guiding my half-noob in a swampy area! Seasonal Greetings & a good 2022! marcovaldo
  11. Hi, Thx for your suggestions! In the meantime I am looking more into Using ICS for the downcomms. Something event driven might be easier for implementation with complex protocols handling many different kinds of protocols (needing timeouts, single byte answers etc.) Unfortunately there will be lost of (partially yet undefined) downstream protocols... And if I use Indy for the MARS (Uplink side) only I can later on decide to convert to apache module (NO - i think this will not work; Apache Module will run in a Apache Request/Answer Thread and will not have means to keep connections with the IoT sensor nodes continously ) Greetings, Marcovaldo
  12. Always finding first answers _after_ posting something... (I can confirm I have searched around before posting...) On ICS in Service and Application Example (Thx François Piette!)
  13. Hi All, Sorry for duplicating information! I repostet under new Topic for better visibility. May this save others the days I lost... CERTIFICATE LOCATIONS FOR WINDOWS SERVICE DIFFERENT TO WINDOWS APPLICATION! (at least on Win10/Pro as I have) : the cert files (supposed to be in bin/executable folder) MUST BE IN C:\Windows\SysWOW64\ folder also a cert.pem is queried from C:\usr\local\ssl\cert (i copied the root cert to this name, however not sure if necessary) so if sticking with Indy default names, the files are: C:\Windows\SysWOW64\localhost.pem root cert C:\Windows\SysWOW64\localhost.crt cert C:\Windows\SysWOW64\localhost.key key Selfsigned cert OK (created using XCA) For copying to this folder, of course Admin rights are necessary. If you are using a VMWare VM for Delphi 10.4.X, as I do, and the project files are in the shared VM drive outside the VM, you need 2-step copy: 1) project/bin to local desktop 2) local desktop to SysWOW64 All the above is for WIN32 Service target, as I did not tryout X64 yet. I am happy to be out of the swamp and back on the road (after fighting Windows and not Project) Kind Greetings, ckranich
  14. Final Remark: This confusion has been triggered by my specific setup (maybee no one else uses this...) => if you run a Win32 Service on Win64, then the current folder IS SysWOW64, no matter where the executable is located.
  15. Hi, I did not want to trigger a dispute about this :-0 Only wanted to share my findings - might they (possibly) be helpful to others... Yes, I tried absolute file locations before (like C:\certs\localhost.pem etc). did not work here (or only worked with application, not with service. Thank you for contributing to Indy & kind Greetings, m.
  16. They were ignored in application folder (if started as service) In my case they _have_been_ all the time in application folder. But only used by server compiled as application. When service has been started, it was terminated after a few seconds (Event entry: Service failed at start....) I first thought it has to do with my special setup (Delphi in VM, Project files outside in shared folder), but it also failed if i copied service application, OpenSSL dlls, certs to a local folder inside VM, like C:\Test. Could this be a special case of Win10 running in a VMWare Player VM then?
  17. Hi All, Sysinternals ProcMon is your friend 🙂 Problem solved. CERTIFICATE LOCATIONS FOR WINDOWS SERVICE DIFFERENT TO WINDOWS APPLICATION! (at least on Win10/Pro as I have) : the cert files (supposed to be in bin/executable folder) MUST BE IN C:\Windows\SysWOW64\ folder also a cert.pem is queried from C:\usr\local\ssl\cert (i copied the root cert to this name, however not sure if necessary) so if sticking with Indy default names, the files are: C:\Windows\SysWOW64\localhost.pem root cert C:\Windows\SysWOW64\localhost.crt cert C:\Windows\SysWOW64\localhost.key key Selfsigned cert OK (created using XCA) For copying to this folder, of course Admin rights are necessary. If you are using a VMWare VM for Delphi 10.4.X, as I do, and the project files are in the shared VM drive outside the VM, you need 2-step copy: 1) project/bin to local desktop 2) local desktop to SysWOW64 All the above is for WIN32 Service target, as I did not tryout X64 yet. I am happy to be out of the swamp and back on the road (after fighting Windows and not Project) I will duplicate this to new Topic for better visibility. Might it be helpful for others! Kind Regards, ckranich
  18. At first supposed it might have todo with certificates somehow (or with user context versus local system context to access certificates) But - same certificates work if used from MARS Sercer compiled as VCL Application - no change if service is started using local user instead of local system - Datasnap REST server works OK running as Service using same (selfsigned) certificates and same OpenSSL dlls. => Indy seems to be able to use SSL from Service Application (DataSnap uses Indy too) => will have to dig deeper (traced until inherited call)
  19. Additional Info: First thought it might have todo with the Certificates (However when run Server as App they work OK) Recreated some fresh ones using XCA. no change. This has definitively to do with enabling SSL. As soon as a SSL Port is assigned by FServer.Engine.PortSSL := the Startup stalls in MARShttpServerIndy.Startup (never finished) SetupSSLIOHandler() exit OK SetupThreadPooling() exit OK with 100 Threads Any Ideas? I know that Andrea suggests a Reverse Proxy etc for SSL (and doing only Http on the Rest server), but in this project a standalone Service App has been requested by customer ... Kind Greetings, ckranich
  20. Hi Andrea, Hi All, I am struggling at the same theme - In Reference to the 1000th commit: This works very well when using ServerVCLApplication, but I ran into problems getting SSL AND SERVICE running: I have stated in Server.Service.ServiceCreate() or Server.Service.ServiceStart() : FServer.Engine.Port := 0; FServer.Engine.PortSSL := 8443; Service terminates few seconds after started with: "The xxxxxx service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other service or programs The Windows Events say: Failed to load root certificate. Therefore I copied the 3 files from bin folder (where they were as default and work for the ServerApplication to an absolute path like C:\CERT\ and setup this by (I thought, maybee the Service is started in a different context): (also in Server.Service.ServiceCreate() , just before setting FServer.Engine.PortSSL) FServer.SSLIOHandler.SSLOptions.RootCertFile := 'C:\CERT\localhost.pem'; FServer.SSLIOHandler.SSLOptions.CertFile := 'C:\CERT\localhost.crt'; FServer.SSLIOHandler.SSLOptions.KeyFile := 'C:\CERT\localhost.key'; still not working... (I am a complete newbee with services unfortunately; Any suggestions very wellcome) Kind Regards, ckranich
×