 |
Web Conference 2004
Writing Perl/CGI Scripts for ITS/ASET Web services
Using Data files
|
|
One of the first things you will want to do with a dynamic content
Web page is to save data on the server for later retrieval. There are
various ways to do this, including databases. But first let's start
with the oldest and simplest way, using files.
Reading a file
First let's read a file and send it to the browser.
[an error occurred while processing this directive]
Run readfile.cgi [download]
Writing to a file
Writing a file is similar to reading a file. You use the open() function, but
with the > symbol in the filename to indicate you want to write to it.
Then use print FILE to print to the FILE filehandle.
[an error occurred while processing this directive]
Run write2file.cgi [download]
Check, check...is this mic on?
|
Setting permissions to allow test.scripts.psu.edu to write files
To give the script server the ability to save changes to individual files
that already exist, do the following:
Login to the ACL Explorer (via https://www.work.psu.edu/)
Navigate to your working Web folder as you did to make files executable, and select the file you want to save changes to.
In one of the bottom two rows of the ACL table, select "group" from the pull-down menu (set to "user" by default).
Type in test.scripts.psu.edu in the field next to it.
Check the boxes for Read and Write permissions next in the same row.
If the mask_obj restricts either Read or Write, enable them for mask_obj as well.
If the other_obj restricts either Read or Write, enable them for other_obj as well. - This is actually a requirement of Apache, not necessarily used by the PASS permission system to grant access to the Web server process.
Click the Modify Access button.
|
|
To give the script server the ability to create and change any file in a folder,
do the following:
Login to the ACL Explorer (via https://www.work.psu.edu/)
Navigate to your working Web folder as you did to make files executable, and select the folder in which you want to create and modify files.
If you want to grant access to change existing files as well, click Hide Files. Otherwise you can only create new files (although you can delete other files).
In one of the bottom two rows of the ACL table, select "group" from the pull-down menu (set to "user" by default).
Type in test.scripts.psu.edu in the field next to it.
Check the boxes for Read, Write, eXecute, Insert and Delete permissions next in the same row.
If the mask_obj restricts any of Read, Write, eXecute, Insert or Delete, enable them for mask_obj as well.
If the other_obj restricts any of Read, Write or eXecute, enable them for other_obj as well. - This is actually a requirement of Apache, not necessarily used by the PASS permission system to grant access to the Web server process. Because of this, Insert or Delete don't matter for other_obj (but don't hurt either).
Click the Modify Access button.
It is wise to grant these permissions on a separate folder than the
folder where CGI scripts reside to prevent them from being altered by
someone else using the servers.
|
Saving parameters to a file
Let's do a simple log script. Save the parameters as they come and
the time and IP address.
[an error occurred while processing this directive]
Run log2file_clean.cgi [download]
If you have any questions, feel free to ask me - mailto:jcd@psu.edu
Content by: Jeff D'Angelo <jcd@psu.edu> © 2004
Last update on: Monday, 14-Jun-2004 14:32:50 EDT