» cFos Personal Net documentation, The standard scripts

The cFos PNet standard scripts

The scripts shipped with cFos PNet may show how to implement server functions with JavaScript. They are designed to be used with client side browser scripting, like jQuery. By convention server side scripts use the extension .jss while client side scripts use the extension .js. That is, cFos PNet *executes* .jss files, while it sends .js files to the browser.

You can use script debugging with Visual studio or Visual Web Developer. For the script debugging you need a Visual studio or Visual Web Developer version with remote debugging support, ie. Visual studio Professional Edition. To enable script debugging, set the key enable_script_debugging=1 in the section [param] of the file GLOBAL.INI in the c:\programdata\cFos\cFosPNet folder.

If you don't have a script debugger installed, set this to 0. Otherwise scripts may hang on some machines. You can also load cfospnet.exe with -enable_script_debugging or -esd command line switch to enable script debugging for this program start.

Script-based user administration and authentication

In the pub folder is a sub-folder users with a subfolder for every user, who has an account on your cFos PNet server. The users password or other optional profile data is stored in a hash list, named PROFILE.TXT. This allows speedy and cached accesses for by cFos PNet built-in HTTP authentication. In the public folder is also a sub-folder www with a subfolder for every user. This folder can contain downloadable files of that user. The file_op.jss script also allows the user to upload files into this folder.

The scripts perform authentication according to the respective .htaccess settings. So you need appropriated user credentials for the user to which the directory belongs.

Here a short description of the scripts. You should take a look into the source code, to see how they work.
makedir2.jss If no index.htm or index.html file are present in the requested directory cFos PNet starts this script to generate a directory listing.
The script uses the FileSystemObject to collect information about the contents of the current directory. It then loads an XML template file, parses it and generates a HTML page from the directory contents and the snippets provided by the XML. To change the look or functionality of the directory listing modify the XML template. The resulting HTML file has basic file maintenance links in it. As administrator you can login using HTTP authentication and rename, delete file or folders, upload files as well as create new folders. This is supported by jQuery on the client side, which is basically used to conveniently send Ajax requests to cFos PNet. The server side script file_op.jss performs the necessary HTTP authentication and handles the file operations.

file_op.jss Performs file operations according to the authentication above. File operations are rename, delete, mkdir to create a folder and upload. Upload typically needs authentication. Because the browser always first sends the whole uploaded file to the server and then get the authentication information, it would send the file twice. To give the browser the authentication information first, the file_op.jss script supports an upload pre-flight operation. The browser, using an Ajax request, asks the server for the HTTP authentication response (401) and then automatically uses it for the actual upload. Upload is handled by a function in upload.jss, which uses cFos PNet's file object to allow upload of files with an arbitrary size.

user_op.jss Performs basic user administration functions: create, delete, reset password and list. The admin user is required for authentication.

list_op.jss
Because hash list play an important role for cFos PNet, list_op.jss provides basic list operations available for Ajax requests. The same authentication scheme as described above is performed. That is: Depending on the location of the script the user for which the authentication is required is chosen. The authentication is done according to the directives in the respective .htaccess files. list_op.jss offers the following operations:

get Get a list of values in the hash list.
set Set a list of keys to a list of values.
save Save a snapshot to disk.
erase Erases a list of keys.
clear Erases all keys.
remove Delete the list from memory / disk.
size Return the list size.
list List all elements in the hash list.

The Ajax in dyndns.htm makes use of these operations to setup DynDNS configuration information.

dyndns.jss Performs DynDNS register or unregister, using the config data in the hash list dyndns.txt in the private folder.
Can be used at server startup and shutdown (see Chapter 1).

get_connections.jss Used to display the current HTTP connections. HTTP is done via TCP. To speed up HTTP requests, the browsers try to re-use TCP connections for HTTP requests. The actual HTTP request is only a short message and a response. After that the browser closes the TCP connection after a few seconds. So you may see a user only for a short time. If authentication was successfull the user's name is also returned with the users IP address.

stretch.jss Because it is always a burden to the web master to resize images to the format used the web page, we implemented a little script, which uses the cFos PNet image object (GDI+). It uses a filename and a w (width) and h (height) parameter in the URL's query string. If your images are of arbitrary size, you should use only one parameter to preserve the image's aspect ratio. makedir2.jss uses links to this script to display thumbnail images for images stored in the current folder.

utils.jss
Collection of utility functions to simplify server side scripting. Offers the following functionality:

- wrap the web server object and its functions.
- extend the JavaScript String object with a few usefull functions.
- perform script parameter evaluation either of the query string or the form data used with POST.
- loading, saving and sending (via mail) of small files.
- rfc 1123 dates as used in cookies.
- cookies.
- a simple XML transformation function.

If you use cFos PNet for bigger projects, you may want to package functional units into modules, instead of a simple included script file. cFos PNet offers support of the module specification of the common.js initiative.

cFos Personal Net documentation

Powered by cFos Personal Net Web Server
Practice random kindness and senseless acts of beauty