LDD Today


An alternative to the OpenServer URL command

by
John
Chamberlain

Level: Beginner
Works with: Domino 5.0.6a
Updated: 01-May-2001


The Domino Web server has a special URL, http://myserver/?OpenServer, which generates a page containing a list of all the databases on the server. The database names are active links, so you can open a database just by clicking a name. This is a convenient shortcut for administrators or designers working on a Web site. However, the OpenServer URL isn't really appropriate for the public users of your site, for two reasons:
This article discusses a LotusScript agent that provides a flexible alternative to the OpenServer URL. You can copy the agent's script from the Open Server agent sidebar or download it in a text file from the Iris Sandbox. You can then use it to control who has access to the list of databases on your server and how that list appears.

This article assumes a basic understanding of Domino database design and administration. You can download the agent and use it as is, by following the instructions in the Using the agent section, below. An understanding of LotusScript will allow you to customize the agent as well.

The Open Server agent was developed and tested with Domino R5.0.6a, and should work with 5.0.6a and later releases.

How the agent works
The OpenServer URL displays a list of all databases on the server, with active links to those databases:

OpenServer URL results

The Open Server agent output mimics the OpenServer URL. In fact, it's a slight improvement, with all databases in a directory sorted before all subdirectories:

Open Server agent results

Because the agent resides in a database, you can restrict who can run the agent by modifying the database ACL, as described in the Using the agent section, below.

This agent makes extensive use of the LotusScript "list" facility. A list, like an array, is a collection of objects, but a list is more flexible than an array because it can grow and shrink as elements are added and deleted. Also, elements in an array are identified by numeric subscripts, but elements in a list are identified by tags, which can be meaningful text strings. Since most of the information we are dealing with in this agent is in the form of short text strings, lists are the ideal way to organize and access the information.

The most important data structure in the agent is the DirList class. This class represents a directory in the Domino data-directory hierarchy. The "level" variable indicates how deep a directory is in the hierarchy, with the Domino data directory itself at level 1, a child of the data directory at level 2, and so on. The "prefix" variable represents a text string that should be displayed in front of the database names in a directory to indent them properly. The "entries" variable is a list of the databases in the directory.

Class DirList End Class

All of the agent code is in the Initialize event.

Sub Initialize
'
' Certain system databases are hidden by OpenServer.
' We list these databases here. You can modify
' this list if you want. '
' Create a list of databases on the server
'
To get the list of databases, we use the LotusScript NotesDbDirectory class. Every database returned by this class (except for ones we want to hide) will be added as a DirList object to the "pathmap" list. The next few lines of code are a standard way to set up a loop to use the NotesDbDirectory class.
' Check if this database is supposed to be hidden ' Change Windows backslashes to forward slashes
Windows and Unix return different slashes as path delimiters. By standardizing the direction of the slashes right away, the rest of the code only has to deal with one kind of slash.

' Get actual subdirectory path (everything before the file name) ' Normalize the path to start and end with a slash ' Add this path to the directory list

For elements in the pathmap list, the value is a new DirList object, and the tag is the path name (for example, /help).
' Determine how many levels deep this path is

By counting the number of path delimiters, we determine how deep this directory is in the hierarchy. We need to do this to set the level and prefix variables correctly.
' Save the name to be displayed for this database

The databases in the directory are stored as elements in the "entries" variable of the directory's DirList object. The value of an element is the database title, and the tag is the database's file name.
NextDb:
At this point, we have a complete list of all the databases on the server (minus the ones we want to hide). Now we can work on generating the actual HTML response.

The OpenServer URL prints out the databases sorted without regard to paths, so databases in child directories are mixed up with databases in parent directories. For example, it will print out /events4.nsf, /help/readme.nsf, /names.nsf.

The Open Server agent improves on this because it prints all the databases in a directory before any child directories. For the same example, the agent prints /event4.nsf, /names.nsf, /help/readme.nsf. Notice that the root Domino data directory is represented as /, so it will always sort before any child directory (such as /help), guaranteeing that all databases in the root will be printed first.

'
' Generate HTML, looping over directories in sort order
' ' Search the directory list for the lowest-sorting path

The following code is a straightforward way for finding the lowest-ordered string in a collection of strings.

For all directories except the root, we need to indent directory and database names by adding the prefix. Notice that we use {} (braces) to delimit strings in the Print statements. Although strings are traditionally delimited by double-quotation marks, you can use braces or vertical bars instead; and it's a good idea to do so if the strings themselves contain quotes. Otherwise you have to remember to double the embedded double-quotation marks, which looks really strange.

' Generate HTML for subdirectory name
' Generate HTML for all entries in the database name list for this path 'Done with this path, get it out of the list End Sub

Customizing the agent
Since the HTML output is completely controlled by the LotusScript code, you can easily customize the agent to change the layout of the page, to restrict browsing to certain databases or directories, or do anything else you want.

For example, you might change the layout of the page by displaying both the path and title for each database, and placing the output in a table. Here's what the new layout would look like:

customizing the layout

To change to this layout, delete all the agent code after the comment "Generate HTML, looping over directories in sort order", and replace it with the following code:

'
' Generate HTML, looping over directories in sort order
' ' Generate HTML for the title row ' Search the directory list for the lowest-sorting path ' Generate HTML for all entries in the database list for this path ' Done with this path, get it out of the list End Sub

This code uses more HTML than the original agent in order to create the table. If you're not an HTML expert but you're handy with Domino Designer, then you can create a page in Designer with the layout you want, and check the page in a browser until it looks right. Then view the HTML source in the browser (in Microsoft Internet Explorer 5, choose View - Source), and copy-and-paste the HTML into your agent code.

As another example, suppose you want to restrict the database list to a certain directory, for example, the Help directory. You can do this by adding one line of code to these lines:

so that they read:

If you make this change in addition to the table-layout change above, here's what you get in a browser. (We added some files to the directory to get a larger table.)

limiting the database list

Using the agent
To use the Open Server agent on your server, you place the agent in a database on the server. For easiest ACL control, create a new database to hold the agent. For example, create webtools.nsf. Then:
  1. Open the database in Designer.
  2. Go to the Agent pane and click the New Agent button.
  3. Give the agent a simple name like Browse.
  4. Click the Shared Agent checkbox.
  5. Set "Which documents(s) should it act on?" to "Run once (@commands may be used)."
  6. In the Run list, select LotusScript.
  7. Select the Initialize event and delete the existing code in the event.
  8. Copy the agent's script from the Open Server agent sidebar or download the text file openserveragent.txt from the Iris Sandbox and copy its contents.
  9. Paste the agent's script into the event. (The Class definition will automatically move into the Declarations event.)

    The agent in Designer
  10. Save the agent. (If your ID doesn't have privileges to run agents on the server, resign the agent with an ID that does.)

On the server, start the http task. Open your browser and enter the URL http://myserver/webtools.nsf/browse. The database list for the server should appear.

Now set up the ACL for the agent's database (webtools.nsf, in this example) so that only those who should be able to browse the server have Reader access. A browser user only needs to have "Read public documents" access to the database to run the agent. If you want to restrict the agent to a certain set of users, you can change the ACL settings for -Default- (and Anonymous, if present) to No Access and then uncheck "Read/Write public documents." Then add the allowed users or user groups to the ACL and set them to Reader, or No Access with public access checked.

Finally, open the Server document and in the Basics section of the HTTP tab under the Internet Protocols tab, set the "Allow HTTP clients to browse databases" to No. Save the document and restart the http task. Now only those you have specified can run the agent and so view the server's database list.

About the Author
John Chamberlain is a Software Quality Architect on the Domino Web Server team.