WWW-APPN
-- Application Web Server
[New Application no longer accepted]
This
is the Application Web Server of School
of Computing, NUS.
It provides web-based applications for the School.
Perl and PHP scripts are supported.
Most
of the applications here are on-going final-yr student projects
which require the use of CGI. If you are doing a SoC final-yr (or
similar) student project which requires the use of CGI, you may
request for the use of this web server. Please submit a
Helpdesk e-form.
In the form, select "CGI:UNIX" as the "Resource Required".
This
web server does not cater for personal homepages.
Please do not request to use this web server for running
your own CGI programs in your personal homepage.
Instructions
for Application Developers
-
Where should you put your HTML, CGI, and other files?
-
What is the URL for your homepage?
-
What is the local directory pathname to your homepage?
-
What filename should you give to your CGI programs?
-
What type of CGI programs can you use?
-
What file permission must you give on your files?
-
How to override the default web server directives with
your own?
-
Where can you read the error_log file to debug your CGI
program?
-
How to program your CGI using Oracle and DBI in perl?
-
Why some browsers are denied from accessing your webpage?
-
How to allow web browsers outside SoC to access your webpage?
-
Notes on using server-side include.
1.
Where should you put your HTML, CGI, and other files?
You
should create a subdirectory under your account's home directory,
named
- public_html
and put
all the files required by your system under this directory.
The
Application Web Server can only see the files which are located
under your public_html directory and not anywhere else.
Note: If you are using the same public_html directory
for your personal homepage, then in order to eliminate conflicts
between the two purposes, you are advised to create a subdirectory
further down (e.g. public_html/myproject) and use this
subdirectory solely for the purpose of your CGI project.
You
are encouraged to sub-divide your public_html directory
further into various subdirectories and organise your files into
the respective subdirectories according to their functionality.
For example, you can create a subdirectory
- public_html/cgi-bin
for storing
all your CGI programs; and create another subdirecotry
- public_html/data
for storing
the data files used by your CGI programs.
You
can put your CGI programs anywhere under your public_html
directory tree. You can scatter them into various subdirectories,
and you can name the subdirectories any name you like.
To
top
2.
What is the URL for your homepage?
The
URL for your homepage is
- http://www-appn.comp.nus.edu.sg/~username
or
- https://www-appn.comp.nus.edu.sg/~username
(where username is the username of your project account)
which
is mapped to your public_html directory.
To
top
3.
What is the local directory pathname to your homepage?
If
your CGI program needs to access certain directories or files which
are located under your public_html directory, you can use
the pathname which you normally see when you login to your account.
For example
- /home/stuproj/~username/public_html/subdir/.../filename
To
top
4.
What filename should you give to your CGI programs?
You
can give any name you like, but the name must, by default,
end with the suffix
- .cgi
This is
the convention used by this Application Web Server to recognise a
requested file to be a CGI program instead of a static file.
For
example, if you want to use a perl script which you had originally
named as
- login.pl
as a CGI
program, rename it to
- login.cgi
If
you wish to retain the original filename suffix, you can achieve
this by overriding the web server's configuration with your own
configuration via the use of the AddHandler directive in your
per-directory AccessConfig file (typically named .htaccess).
See the "How to override the default web server
directives with your own?" section below for more details.
To
top
5.
What type of CGI programs can you use?
- Perl
scripts
-
Use the following as the first line of your Perl scripts:
- #!
/usr/local/bin/perl
To make the task of writing your CGI programs easier, you
can also use the
CGI.pm perl module in your Perl scripts:
- use
CGI;
To learn how to use CGI.pm, get the book
Official Guide to Programming with CGI.pm written by
Lincoln D. Stein.
You can also make use of the DBI perl module:
- use
DBI;
For an example of using DBI with Oracle, see the section
How to program your CGI using Oracle and
DBI in Perl? below.
- Shell
scripts
-
You can use sh, ksh, bash, csh, tcsh.
They are all located under /bin.
For example,
- #!
/bin/sh
- Compiled
binaries for SUN Sparc Solaris platform
-
Your program must be compiled on a hardware/software platform
which is compatible with the one used by this web server.
- Java
programs
-
You have to write a shell script as a wrapper to invoke your
actual java programs. In this wrapper shell script, set up
your java environment (e.g. CLASSPATH) accordingly.
Our JDK programs are located under
- /usr/local/bin/java/jdk/
To
top
6.
What file permission must you give on your files?
Correct
file permissions have to be set on your directories and files. Otherwise,
a "Permission Denied" message will be returned to the user's
web browser when attempting to access your webpage.
- Directories
which store web documents, e.g. public_html
-
World-readable-and-executable is required:
- drwxr-xr-x
- Web
documents, e.g. index.html
-
World-readable is required:
- -rw-r--r--
- CGI
programs, e.g. login.cgi
-
Only owner-readable-and-executable is required.
World-permissions are not required, because the web
server will your CGI program in your identity.
- -rwx------
- Data
directories used by your CGI program, e.g. public_html/archive
-
Only owner-permissions are required.
World-permissions are not required, because the web
server will your CGI program in your identity.
- drwx------
- Data
files used by your CGI program, e.g. public_html/database/members.dat
-
Only owner-permissions are required.
World-permissions are not required, because the web
server will your CGI program in your identity.
- -rw-------
To
top
7.
How to override the default web server directives with your own?
If
you wish to override the default configuration directives with your
own directives, you can plant a per-directory AccessConfig
file at the directory beyond which you want your directives to prevail.
The default filename of this per-directory AccessConfig file
is
- .htaccess
The permission
of this file should be -rw-r--r--.
Inside
this file, you can specify any configuration directives which like
to override.
For
example, if you want the web server to recognise files with filename
suffix .pl to be CGI program, you can specify:
- AddHandler
cgi-script .pl
For example,
if you want to enable the server-side include feature, you can specify:
- AddType
text/html .shtml
AddHandler server-parsed .shtml
- Note:
See Notes on using server-side include below.
For example,
if you want to allow access to everywhere, you can specify:
- Order
deny,allow
Allow from all
For example,
if you want to turn off certain Options, you can specify:
- Options
-ExecCGI -Includes
For
the list of directives which you can use, refer to the online Apache
documentation under Run-time
configuration directives.
To
top
8.
Where can you read the error_log file to debug your CGI program?
You
can use the following URL to read the last few lines of the web server's
error_log file, which should give you more information about
the error encountered by your CGI program:
- http://www-appn.comp.nus.edu.sg/cgi-bin/errlog
To
top
9.
How to program your CGI using Oracle and DBI in Perl?
Below
is an example:
-
#!/usr/local/bin/perl
use DBI;
$ENV{'ORACLE_HOME'} = '/opt/oracle';
$drh = DBI->install_driver('Oracle');
$dbh = $drh->connect('sid3.comp.nus.edu.sg', '', '');
$sh = $dbh->prepare("select table_name from user_tables");
$sh->execute;
($table_name) = $sh->fetchrow();
print "Content-Type: text/html\n\n";
print "OK!!!!\n\n";
print "$table_name $a\n\n";
print "OK!!!!\n\n";
$a=1;
$sh->finish;
$dbh->disconnect;
To
top
10.
Why some browsers are denied from accessing your webpage?
By default,
only web browsers which are located within the SoC network are allowed
to access your webpage. Web browsers which are located outside the
SoC network will be denied.
Even
when someone uses a web browser from within the SoC network, the
web browser may have configured to go through a proxy server (e.g.
the NUS Proxy Server) which is located outside the SoC network.
In this case, the web browser should be configured to bypass the
proxy server for accessing destinations which are located within
the NUS network.
To
top
11.
How to allow web browsers outside SoC to access your webpage?
You can
override the default restriction for your webpage by using the Allow
directive. See the "How to override the default
web server directives with your own?" section above for more details.
To
top
12.
Notes on using server-side include.
Because
we have enabled the "SetUserID Execution for CGI" feature on this
web server and because of the restrictions imposed by this feature
for security concerns, you can only execute your own program when
you use server-side include with #exec cmd. E.g.
- <!--#exec
cmd="myprog">
The file
myprog must be owned by you and reside within your public_html
directory space.
The
following example will not work because the command to
be executed, /bin/who, is not owned by you and does not
reside within your public_html directory:
- <!--#exec
cmd="/bin/who">
To
top
|