Using FlagShip on the Web

460 views
Skip to first unread message

donpro

unread,
Aug 28, 2011, 11:42:24 PM8/28/11
to multisoft FlagShip
Hi,

I am trying to use a FlagShip executable on the web via cgi-bin.
Following the docs at: http://www.fship.com/fs4web.html, I am getting
an Internal Service Error. The cgi-bin is properly defined in the
apache configuration file but I'm not sure about the setup in the cgi-
bin directory itself.

I have set the followng:
webbook.sh (script)
webook (FlagShip exectable)

My HTML form calls webbook.sh using GET. Looking for advice on how to
debug

Thanks,
Don

donpro

unread,
Aug 29, 2011, 8:27:46 AM8/29/11
to multisoft FlagShip
I looked at the server error log file and I see the following:
Premature end of script headers: webbook.sh

Here are the contents of webbook.sh
#!/bin/sh
set -f
TERMINFO=/cgi-bin; export TERMINFO
TERM=linux; export TERM
FSOUTPUT=/tmp; export FSOUTPUT
./example1

example 1 is the example1.prg from the documentation

Paul

unread,
Aug 29, 2011, 9:57:20 AM8/29/11
to multisoft FlagShip
You have not specify the used server type. Especially for Ubuntu Linux
(I however would suggest to do it generally), replace the first line
in the script to read
#!/bin/bash
Also, the line/statement "./example1" invokes the executable named
"example1" if any, not your "webbook" executable - you need to replace
the line by "./webook". Make sure the script is in Unix/Linux
convention, i.e. line ends with new-line (LF = 0x0a) instead of CR/LF
(= 0x0d 0x0a) when created by DOS/Windows editor. Check by "hexdump -C
webbook.sh". Check also files permission, see details in
http://www.fship.com/fs4web.html section 1.b

Would strongly suggest first to try the example supplied in
http://www.fship.com/fs4web.html

Paul

donpro

unread,
Aug 29, 2011, 12:37:58 PM8/29/11
to multisoft FlagShip
Hi,

I am using RedHat.

My apache docs state that the ServerType directive is deprecated (it
is hot in my apache config. file) unless you meas as an environment
variable in webbook.sh
I replaced the first line with: #!/bin/bash
I compiled your example and installed "example1" binary in the cgi-bin
directory as a test.
Either way, my HTTP request fails with INTERNAL SERVER ERROR with both
binaries.
I created the PRG scripts in the LINUX environment as well as the
webbook.sh script so I can only assume the proper line feeds.
I changed the permission of the cgi-bin directory and all files
contained as per your docs.

Now receiving these two errors:
/bin/bash: /var/www/cgi-bin/webbook.sh: Permission denied
Premature end of script headers: webbook.sh

(note the permission error so the 711 mode does not seem to work for
this web server. Also, the ownership/group is root for all cgi-bin)

How next to debug please?

The hexdump command shows the following output:
[root@lcl-mtl /var/www/cgi-bin]# hexdump -C webbook.sh
00000000 23 21 2f 62 69 6e 2f 62 61 73 68 0a 73 65 74 20 |#!/bin/
bash.set |
00000010 2d 66 0a 54 45 52 4d 49 4e 46 4f 3d 2f 63 67 69 |-
f.TERMINFO=/cgi|
00000020 2d 62 69 6e 3b 20 65 78 70 6f 72 74 20 54 45 52 |-bin;
export TER|
00000030 4d 49 4e 46 4f 0a 54 45 52 4d 3d 6c 69 6e 75 78 |
MINFO.TERM=linux|
00000040 3b 20 65 78 70 6f 72 74 20 54 45 52 4d 0a 46 53 |; export
TERM.FS|
00000050 4f 55 54 50 55 54 3d 2f 74 6d 70 3b 20 65 78 70 |OUTPUT=/
tmp; exp|
00000060 6f 72 74 20 46 53 4f 55 54 50 55 54 0a 2e 2f 65 |ort
FSOUTPUT../e|
00000070 78 61 6d 70 6c 65 31 |xample1|


On Aug 29, 9:57 am, Paul <supp...@flagship.de> wrote:
> You have not specify the used server type. Especially for Ubuntu Linux
> (I however would suggest to do it generally), replace the first line
> in the script to read
>   #!/bin/bash
> Also, the line/statement "./example1" invokes the executable named
> "example1" if any, not your "webbook" executable - you need to replace
> the line by "./webook". Make sure the script is in Unix/Linux
> convention, i.e. line ends with new-line (LF = 0x0a) instead of CR/LF
> (= 0x0d 0x0a) when created by DOS/Windows editor. Check by "hexdump -C
> webbook.sh". Check also files permission, see details inhttp://www.fship.com/fs4web.htmlsection 1.b
>
> Would strongly suggest first to try the example supplied inhttp://www.fship.com/fs4web.html

donpro

unread,
Aug 29, 2011, 1:14:56 PM8/29/11
to multisoft FlagShip
Note:

I tried a PERL script as cgi-bin (the famous hello world script) and
it would only work with permission 755, not 711

On Aug 28, 11:42 pm, donpro <donpro-2...@rogers.com> wrote:

Paul

unread,
Aug 30, 2011, 5:28:25 AM8/30/11
to multisoft FlagShip
You need to carefully read the how-to description in http://www.fship.com/fs4web.html
;-) It says in section 1.b: "The scripts or executables have usually
only read & execute permission (755, -rwxr-xr-x)..."

Paul

Paul

unread,
Aug 30, 2011, 5:30:42 AM8/30/11
to multisoft FlagShip
There is no NewLine at the end of your script.

On Aug 29, 6:37 pm, donpro <donpro-2...@rogers.com> wrote:
> Hi,
>

donpro

unread,
Aug 30, 2011, 7:38:05 AM8/30/11
to multisoft FlagShip
You are correct. I have made the changes but it has ot helped

On Aug 30, 5:28 am, Paul <supp...@flagship.de> wrote:
> You need to carefully read the how-to description inhttp://www.fship.com/fs4web.html

donpro

unread,
Aug 30, 2011, 7:41:18 AM8/30/11
to multisoft FlagShip
I have saved the script, webbook.sh as UNIX but am still getting an
Internal Service Error with the single log file message: Premature end
of script headers: webbook.sh
How do I manually add a NewLine to a file? Should I try to save in PC
or MAC format?

Alternatively, can FlagShip be run from the web as non compiled same
as PHP, something like #include webbook.prg. This would also solve my
problem

Paul

unread,
Aug 30, 2011, 9:38:13 AM8/30/11
to multisoft FlagShip
Pls read _carefully_ my comments and hints below.

On Aug 30, 1:38 pm, donpro <donpro-2...@rogers.com> wrote:
> You are correct. I have made the changes but it has ot helped

What does not helped? Have you downloaded the fs4web.tar example,
compiled on the Linux system and run as described in the how-to and as
I previously suggested? How did you compile? According to your
postings, you are not using these supplied examples, since the the
"example1.sh" is formatted correctly in the tar archive.

On Aug 30, 1:41 pm, donpro <donpro-2...@rogers.com> wrote:
> I have saved the script, webbook.sh as UNIX but am still getting an
> Internal Service Error with the single log file message: Premature end
> of script headers: webbook.sh
> How do I manually add a NewLine to a file?  Should I try to save in PC
> or MAC format?

How about vi (on the server) ?

> Alternatively, can FlagShip be run from the web as non compiled same
> as PHP, something like #include webbook.prg.  This would also solve my
> problem

FlagShip is native compiler, not an interpreter like PHP. As stated in
the above how-to, you MUST compile your application statically by the
Pro version of FlagShip corresponding to the target system (in your
case: by FlagShip for RedHat Linux). Again: re-read the how-to and
check first by the example.

Generally: To check if your Apache is configured correctly, create in /
cgi-bin directory (on the server) file named webbook.sh containing:

#!/bin/bash
echo 'Content-Type: text/html'
echo ''
echo '<html><head>my cgi test</head><body>'
echo 'Hello world!<p> </p>'
echo '</body></html>'

set it permission to 755 and then invoke/submit (by any browser) your
HTML file containing the line
<FORM ACTION="/cgi-bin/webbook.sh" METHOD="get">
The above webbook.sh script on the server will/should then simply
reply with "Hello world!" displayed in your local browser. If not so,
it is something wrong with your settings, since it is fully
independent on the FlagShip's executable. In such a case, contact your
system or server administrator. For FlagShip support, best to contact
directly <support -at- flagship -dot- de>

Paul

donpro

unread,
Aug 31, 2011, 12:14:32 AM8/31/11
to multisoft FlagShip
Hi,

I have done as you suggested and have had success. After managing to
get the example1 scripts to work, I tried the same with my webbook
scripts and it worked. I think the problem was how I compiled my
webbook.prg script. Furthermore, after more experimentation, I found
I do not need the webbook.sh script and can call the FlagShip binary
direct.

Thanks,
Don

On Aug 30, 9:38 am, Paul <supp...@flagship.de> wrote:
> Pls read _carefully_ my comments and hints below.
>
> On Aug 30, 1:38 pm, donpro <donpro-2...@rogers.com> wrote:
>
> > You are correct.  I have made the changes but it has ot helped
>
> What does not helped? Have you downloaded the fs4web.tar example,
> compiled on the Linux system and run as described in the how-to and as
> I previously suggested? How did you compile? According to your
> postings, you are not using these supplied examples, since the the
> "example1.sh" is formatted correctly in the tar archive.
>
> On Aug 30, 1:41 pm, donpro <donpro-2...@rogers.com> wrote:
>
> > I have saved the script, webbook.sh as UNIX but am still getting an
> > Internal Service Error with the single log file message: Premature end
> > of script headers: webbook.sh
> > How do I manually add a NewLine to a file?  Should I try to save in PC
> > or MAC format?
>
> How about vi (on the server) ?
>
> > Alternatively, can FlagShip be run from the web as non compiled same
> > as PHP, something like #include webbook.prg.  This would also solve my
> > problem
>
> FlagShip is native compiler, not an interpreter like PHP. As stated in
> the above how-to, you MUST compile your application statically by the
> Pro version of FlagShip corresponding to the target system (in your
> case: by FlagShip for RedHat Linux). Again: re-read the how-to and
> check first by the example.
>
>

donpro

unread,
Sep 5, 2011, 4:49:21 PM9/5/11
to multisoft FlagShip
Is there a way to run PHP code from a FlagShip CGI script? I have the
following test script I call from my browser yet the page shows blank:

WebHtmlBegin()
? '<?php'
? 'echo "xxxxxxxxxxxxxxxxxxxxxxx";'
? '?>'
WebHtmlEnd()

Paul

unread,
Sep 6, 2011, 3:16:09 AM9/6/11
to multisoft FlagShip
You need to read all the postings carefully. I already replied this
question on August 30 in this thread.

donpro

unread,
Sep 6, 2011, 9:25:32 AM9/6/11
to multisoft FlagShip
I understand that I cannot run FlagShip from the web as interpreted
code. I was simply wondering if there is a method to execute PHP code
from a FlagShip binary that is called as CGI; perhaps executed via an
external call?
> > WebHtmlEnd()- Hide quoted text -
>
> - Show quoted text -

donpro

unread,
Sep 6, 2011, 7:10:59 PM9/6/11
to multisoft FlagShip
Are FlagShip CGI binaries allowed to access DBF files in another file
system (directory) if I use the full path, e.g.

dbfFile = '/lcl/testsystem/data/shsite02'
use &dbfFile

When the database exists in the cgi-bin directory, I can access it but
when it exists in the other directory, neterr() returns an error. I
have checked the opermissions and they seem OK. Is this a limitation
of CGI? I note that your example has:

#define DBFNAME "example1"
use (DBFNAME) index (DBFNAME) shared

which implies that all binaries and database reside in cgi-bin. This
seems very limiting.

Thanks,
Don
> > - Show quoted text -- Hide quoted text -

alex

unread,
Sep 7, 2011, 8:43:47 AM9/7/11
to multisoft FlagShip
You may use the RUN command to execute any script or application, see
the flagship manual for details.
Alex

Paul

unread,
Jul 19, 2019, 3:51:55 AM7/19/19
to multisoft...@googlegroups.com
On Sep 7, 1:10 am, donpro <donpro-2...@rogers.com> wrote:
> Are FlagShip CGI binaries allowed to access DBF files in another file
> system (directory) if I use the full path, e.g.
>
> dbfFile = '/lcl/testsystem/data/shsite02'
> use &dbfFile

The application in cgi-bin runs usually as user "nobody". If you give this user corresponding access rights to another directory on the server (would NOT recommend to do it) and set Apache correspondingly, you may access it. Usually, your application will see the cgi-bin directory as root path "/", you hence can access data and subdirectories in and below cgi-bin, but not in another directories on the server. This is an important security issue.

Note: depending on the server setting, the executable may need to have ".cgi" extension, otherwise the browser will try to download the file. Alternatively you can use the .htaccess file with "AddHandler cgi-script .your_extension" to define your own extension.

> When the database exists in the cgi-bin directory, I can access it but
> when it exists in the other directory, neterr() returns an error.  I
> have checked the opermissions and they seem OK.  Is this a limitation
> of CGI?  I note that your example has:
>
> #define DBFNAME "example1"
> use (DBFNAME) index (DBFNAME) shared
>
> which implies that all binaries and database reside in cgi-bin.  This
> seems very limiting.
>
> Thanks,
> Don

Hint: since out of scope here, would strongly suggest to read a short overview about the used Common Gateway Interface (or CGI) in e.g. http://htmlhelp.com/faq/cgifaq.1.html. A good introduction is
available in several books, e.g. in the O'Reilly Open Book "CGI Programming on the World Wide Web" by Shishir Gundavaram = http://oreilly.com/openbook/cgi/

Hope this helps you.

Paul
Reply all
Reply to author
Forward
0 new messages