Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using CGI exe with IW
#1
Hi, I have a cgi exe of a third party that I need using to use with IW.
It works well using apache, IIS, AppServer ......

But I want to use IW.

The cgi.exe is named dgate.exe.

I did all setup after read the docs of cgi to use with a webserver.

It said just to copy a folder called cgi-bin  to wwwroot of the webserver.

To test I have to use: http://127.0.0.1:8888/cgi-bin/newweb/dgate.exe?mode=top

I did a test using a button click that run this code:

Code:
procedure TIWUserSession.load_dicom();
var
  CGIRunner: TIWCGIRunner;
  CGIModuleName: string;
  LFileName: string;
begin
  CGIModuleName := TIWAppInfo.GetAppPath + 'wwwroot\cgi-bin\newweb\dgate.exe';
  CGIRunner := TIWCGIRunner.Create;
  try
    // Set the name of the CGI module which runs our report
    CGIRunner.CGIModule := CGIModuleName;
    CGIRunner.CustomFields.Add('mode=top');
    // call the CGI application
    CGIRunner.Execute(WebApplication, WebApplication.Request);
    // Check status result. Zero indicates success. Anything else is an error
    if CGIRunner.StatusResult = 0 then
    begin
      //what I have to do here????
    end else
    begin
      WebApplication.ShowMessage('Error creating report: ' + CGIRunner.ErrorMessage);
    end;
  finally
    CGIRunner.Free;
  end;
end;

Here is the lua script executed by "dgate.exe" cgi to produce the html output:

Code:
HTML("Content-type: text/html\nCache-Control: no-cache\n");
HTML("<HEAD>")
print [[<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">]]
HTML("<TITLE>Conquest DICOM server - version %s</TITLE>", version)

HTML("</HEAD>")

HTML("<BODY BGCOLOR='CFDFCF'>")


HTML("<H1>Welcome to Conquest DICOM server - version %s</H1>", version)
HTML("<H2>Written by Conquest Project</H2>", version)
HTML("<IMG SRC='%sconquest.jpg' ALT='Written by Conquest Project'>", Global.WebCodeBase)
HTML("<HR>")

HTML("<HR>");

HTML("<table>");
key='' 
HTML("<tr>");
HTML("<FORM ACTION=\"dgate%s\"  onSubmit=\"if (this.patientnamematch.value == '' && this.patientidmatch.value == '') {alert('Please, fill the entry fields');return false;}\">", ex);
HTML("<INPUT NAME=mode    TYPE=HIDDEN VALUE=listpatients>");
HTML("<INPUT NAME=port    TYPE=HIDDEN VALUE=%s>", port);
HTML("<INPUT NAME=address TYPE=HIDDEN VALUE=%s>", address);
HTML("<INPUT NAME=key    TYPE=HIDDEN VALUE=%s>", key);
HTML("<td>Local Patient List");
HTML("<td>Patient ID: <INPUT NAME=patientidmatch TYPE=Text VALUE=>");
HTML("<td>Name: <INPUT NAME=patientnamematch TYPE=Text style=\"text-transform:uppercase;\" onkeyup=\"javascript:this.value=this.value.toUpperCase();\" VALUE=>");
HTML("<td>");
HTML("<td><INPUT TYPE=SUBMIT VALUE=Submit>");
HTML("</FORM>");
HTML("</tr>");

HTML("<tr>");
HTML("<FORM ACTION=\"dgate%s\" onSubmit=\"if (this.patientnamematch.value == '' && this.patientidmatch.value == '' && this.studydatematch.value == '') {alert('Please, fill the entry fields');return false;}\">", ex);
HTML("<INPUT NAME=mode    TYPE=HIDDEN VALUE=liststudies>");
HTML("<INPUT NAME=port    TYPE=HIDDEN VALUE=%s>", port);
HTML("<INPUT NAME=address TYPE=HIDDEN VALUE=%s>", address);
HTML("<INPUT NAME=key    TYPE=HIDDEN VALUE=%s>", key);
HTML("<td>Local Studies List");
HTML("<td>Patient ID: <INPUT NAME=patientidmatch TYPE=Text VALUE=>");
HTML("<td>Name: <INPUT NAME=patientnamematch TYPE=Text style=\"text-transform:uppercase;\" onkeyup=\"javascript:this.value=this.value.toUpperCase();\" VALUE=>");
HTML("<td>Date: <INPUT NAME=studydatematch id=studydatematch TYPE=Text VALUE=>");
HTML("<td><INPUT TYPE=SUBMIT VALUE=Submit>");
HTML("<tr><td><td><td><td>")
HTML([[<INPUT TYPE=BUTTON VALUE=Today onClick="var d=new Date(); document.getElementById('studydatematch').value=(d.getFullYear()).toString()+(d.getMonth()+101).toString().substring(1,3)+(d.getDate()+100).toString().substring(1,3)">]]);
HTML([[<INPUT TYPE=BUTTON VALUE=Yesterday onClick="var d=new Date(); d=new Date(d.valueOf()-864E5); document.getElementById('studydatematch').value=(d.getFullYear()).toString()+(d.getMonth()+101).toString().substring(1,3)+(d.getDate()+100).toString().substring(1,3)">]]);
HTML([[<INPUT TYPE=BUTTON VALUE='Last 7 days' onClick="var d=new Date(); var d1=new Date(d.valueOf()-7*864E5); document.getElementById('studydatematch').value=(d1.getFullYear()).toString()+(d1.getMonth()+101).toString().substring(1,3)+(d1.getDate()+100).toString().substring(1,3)+'-'+(d.getFullYear()).toString()+(d.getMonth()+101).toString().substring(1,3)+(d.getDate()+100).toString().substring(1,3)">]]);
HTML("</FORM>");
HTML("</tr>");


HTML("</table>");
HTML("</BODY>")



The cgi generate  a html page on the fly using your internal code with lua script. I can´t change that lua script from cgi.

How could I take the html page generated by dgate.exe to put after "if CGIRunner.StatusResult = 0 then" and show in the browser? 
Reply
#2
TIWCGIRunner.ResponseHeaders and TIWCGIRunner.ResponseContent both contain whatever the CGI script generated, i.e. headers and content.

In general you don't need the headers (unless there is something very specific on it, but it is not common).

You can just take the ResponseContent and write as is to the IW Response like:

if CGIRunner.StatusResult = 0 then begin
WebApplication.Response.WriteString(IWCGIRunner.ResponseContent.Text);
end;

It will work as long as your ResponseContent contains a correct representation of a valid HTML page
Reply
#3
Hi, Alexandre,
In the code posted above, I just did a test using:
Code:
WebApplication.Response.WriteString('<html><head></head><body>test</body></html>');

but I get an error:


Code:
Exception message : Reply type already set.
Exception class : Exception
Exception address : 006A1103
Exception Time : 2019-09-09 21:50:12.351
Reply
#4
Hum... looks like you need to reset the request. Try this:

with WebApplication.Response do
begin
ResetReplyType;
Code := 200;
ContentType := MIME_HTML;
WriteString(Your html here);
end;

It should work
Reply
#5
(09-10-2019, 09:27 AM)Alexandre Machado Wrote: Hum... looks like you need to reset the request. Try this:

with WebApplication.Response do
begin
  ResetReplyType;
  Code := 200;
  ContentType := MIME_HTML;
  WriteString(Your html here);
end;

It should work
Hi, Alexandre,
It doesn't  work. I have the same problem.

Luik
Reply
#6
Another problem is that the cgi is returning nothing:

If I do:

Code:
C:\AppProg\GestanCloud\wwwroot\cgi-bin\newweb>dgate
>>dgate.exe returned nothing


But if I do:

Code:
C:\AppProg\GestanCloud\wwwroot\cgi-bin\newweb>set QUERY_STRING=hallo

C:\AppProg\GestanCloud\wwwroot\cgi-bin\newweb>dgate
Content-type: text/html
Cache-Control: no-cache
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>Conquest DICOM server - version 1.4.19</TITLE>
<style type="text/css">
body { font:10pt Verdana; }
a { color:blue; }
#content { background-color:#dddddd; width:200px; margin-top:2px; }
h1 {background-color:#6495ed;}
</style>
</HEAD>
<BODY BGCOLOR='CFDFCF'>
<H1>Welcome to Conquest DICOM server - version 1.4.19</H1>

It looks like intraweb does not set QUERY_STRING or maybe it runs dgate.exe in the incorrect folder.
Reply
#7
That's not how CGI are supposed to work. CGI applications obtain all parameters from environment variables and IntraWeb executes the CGI application and communicates with it via named pipes.
Query_string is correctly set before executing the CGI script and all content returned by the script is put into ResponseContent property.
Reply
#8
What I think you must have in mind is that query_string might be empty. The query_string of a request to a IW application may or may not have data. Are you using a sync or async request? What is the expected input for that CGI script?
Reply
#9
Hi , Alexandre.
There is no other requirement. The cgi must be called using http://127.0.0.1:8888/cgi-bin/newweb/dgate.exe?mode=top.  Just It. 
It runs ok in wamp server and appserver. 
And I  have only to copy the cgi-bin folder with the cgi to wwwroot. 

I have contacted the author and He said the problem is with the www server. 

This cgi is part of a opensource project of pacs dicom server and is used for many people in the world. It is part of Conquest dicom server(https://ingenium.home.xs4all.nl/dicom.html).

(09-10-2019, 09:03 PM)Alexandre Machado Wrote: What I think you must have in mind is that query_string might be empty. The query_string of a request to a IW application may or may not have data. Are you using a sync or async request? What is the expected input for that CGI script?
I am using sync request.
It must return something as:

Content-type: text/html
Cache-Control: no-cache
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>Conquest DICOM server - version 1.4.19</TITLE>
<style type="text/css">
body { font:10pt Verdana; }
a { color:blue; }
#content { background-color:#dddddd; width:200px; margin-top:2px; }
h1 {background-color:#6495ed;}
</style>
</HEAD>
<BODY BGCOLOR='CFDFCF'>
<H1>Welcome to Conquest DICOM server - version 1.4.19</H1>
Reply
#10
If it requires the query_string to be mode=top, then you need to make sure it is before calling it.

You will need to modify the query_string yourself and make sure it matches the spec.

You are free to alter Request.QueryFields. It is just a TStringList which can be cleared and filled by you, before calling the CGIRunner
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)