|
USENIX Technical Program - Paper - Proceedings of the The Sixth Annual Tcl/Tk Workshop, 1998   
[Technical Program]
WebWiseTclTk:
A Safe-Tcl/Tk-based Toolkit
Enhanced for the World Wide Web
|
Hemang Lavana | Franc Brglez |
---|
The toolkit supports (1) creation of new Web-based Tcl applications with greatly enhanced functionality, and (2) migration of existing Tcl applications to the Web by merely writing an encapsulation script. We demonstrate the capabilities of the WebWiseTclTk toolkit by readily creating an encapsulation script for Web-based execution of the Tk Widget Demonstrations, distributed with the core Tcl/Tk.
Keywords: plugins, Web browsers, security, scripting, encapsulation, GUI.
comp.lang.tcl
.
Scripting languages
such as Tcl are designed for `gluing' applications and encourage rapid
application development as compared to system programming languages,
and hence are very important for applications of the future
[4].
The emergence of organizations such as the recently formed
Scriptics [5] and the
Tcl/Tk Consortium [6], focusing entirely
on scripting tools, applications and services, is an example of this trend.
The maturity and robustness of Tcl/Tk provides a new opportunity to support creation and presentation of multimedia content on the WWW. Tcl-plugin [7,8] is an example of an elegant solution for embedding Tcl/Tk applications for ready access inside the Web browser. In addition, the Tcl-plugin supports an excellent mechanism for security of client hosts using a padded cell approach [9]. The default security policy prohibits Tcl applets (tclets) from running other programs, accessing the file system, and creating toplevel windows (including menus), thereby giving the client hosts a high level of confidence when executing tclets. However, such restrictions limit the scope of the Tcl applications executed inside a Web-browser.
Our initial experience with Tcl/Tk, predating the phenomenal growth of WWW,
was motivated by the need to
develop a user-friendly and versatile environment to support
user-reconfiguration of complex workflows that execute
heterogeneous programs and
data for the design of experiments in VLSI CAD.
This environment, called REUBEN (for reusable and reconfigurable
benchmarking environment), was implemented entirely in
Tcl/Tk [1] and Expect [10].
In essence, it provides the user with the ability to create directed
dependency graphs as workflows of data, program, decision, and workflow nodes.
Data and programs can reside anywhere on the Internet, and execution of
all nodes can be scheduled automatically, regardless of the data-dependent
cycles in the graph. In its final form, the workflows in REUBEN
can be multi-cast to
several collaborating sites, recorded, and played-back for re-execution.
An example of REUBEN environment to support a number of
distributed and heterogeneous tasks in a VLSI CAD workflow is
illustrated in Figure 1.
More details are available in
[11,12,13].
Migration of large applications, such as REUBEN, to the Web is not easy if highest level of confidence in terms of security is desired. This is especially true, because toplevel windows and menus are essential in such applications. One solution could be to use Jacl [14], an interpreter to run Tcl scripts in a Java environment. Unfortunately, Jacl does not yet contain the entire feature set of Tcl, including namespaces and Tk. The WebWiseTclTk toolkit provides an easy solution for the migration of existing Tcl applications to the Web. Minimal changes are required in the original application. Our approach uses an encapsulating script to call the main script of the original application.
This paper is organized into the following sections:
(2) motivation; (3) WebWiseTclTk architecture; (4) implementation of WebWiseTk; (5) implementation of WebWiseTcl; (6) user's guide; (7) programmer's guide; (8) software status and availability; and (9) conclusions.
The Tcl-plugin, based on Safe-Tcl, restricts running such large applications inside a Web-browser. A few of these restrictions are listed below:
The Tcl-plugin supports multiple security policies so that the tclets can perform any of the functionality described above. However, this requires every client host to devise and customize their security policies for every application before accessing these as tclets.
It is desirable that the Tcl applications be easily translated into tclets and made readily available on the World Wide Web:
We have developed the WebWiseTclTk toolkit as an enhancement to the Tcl-plugin that makes use of the home policy only. The home policy is, by default, enabled in the Tcl-plugin and hence applications using WebWiseTclTk do not require the host clients to modify their existing security policies.
We decided to use the Tk widget demonstrations, distributed
with the core Tcl/Tk, as a test-bench for testing
the WebWiseTclTk toolkit. We chose to translate these demos
for the World Wide Web because they cover most of the commands of the
core Tcl/Tk that are otherwise unavailable in Safe-Tcl/Tk.
Figure 2 shows the result of posting these demos
on the Web and executing them on a host client as a tclet using the
Netscape browser.
We invite users to try out this demo and send us comments on its
features and performance.
The toolkit WebWiseTclTk consists of two parts: (1) WebWiseTcl which is an enhancement for Safe-Tcl and is useful for applications that do not require display, and (2) WebWiseTk which is an enhancement for Safe-Tk for applications requiring display. The toolkit itself consists of several smaller scripts and uses the modified auto_load mechanism designed for WebWiseTclTk.
Figure 3(a) shows the general architecture that implements the auto_load mechanism. Special cases of the generalized architecture are shown in Figures3(b), (c) and (d) and described below:
The generalized architecture allows the main tclet script to dynamically use one of the above three mechanisms, based on the configuration of the client host.
We next describe the implementation details of the two packages WebWiseTk and WebWiseTcl.
We propose to overcome these limitations as follows:
The following sub-sections describe the methodology used for implementation of the WebWiseTk toolkit.
Layout. Figure 4 shows the layout window of the WebWiseTk toolkit. It consists of two main widget frames:
Toplevel. The ability to create a detached window, as provided by the command toplevel, is very useful for GUI applications of even moderate complexity. We define a procedure called toplevel which makes use of the command frame to create a detached window and display it on the canvas widget.
For every toplevel window, a set of several frames is created,
as shown in Figure 5.
This gives the look and feel of a real window that would have, otherwise, been created by the window manager of the local host system. The frames are laid out using the grid geometry manager. Each frame serves a special purpose:
Wm. The window manager command wm needs to be defined as a procedure which manages the various attributes of the window created using the procedure toplevel described earlier. It can be used to change the title of the window, to iconify/de-iconify the window, or to return the state of the window.
Grab. An indefinite global grab performed by a tclet will result in a denial of service attack since all the input from the terminal would be re-directed to the tclet forever. But, if we re-define the implication of a global grab such that it affects only the windows created by the tclet, then it can be considered to be safe.
Thus, the command "grab -local $win", as defined here, results in grabbing of a single window within the tclet code and the command "grab -global $win" results in a grab across all the windows within the tclet. This effect of grab can be implemented by associating a new class of bind called WebWiseTclTk with every window in the tclet, as follows:
bindtags $w [linsert [bindtags $w] 0 WebWiseTclTk]
Initially, the class WebWiseTclTk has no bind scripts associated with
any of the events. Whenever a grab is performed on a window, a
bind script is created for each event sequence that redirects the
event to the grabbed window.
The event generate command is used to process the event in the grabbed
window. Figure 6 shows a script that achieves a
global grab for a specific window.
Menus.
Menu widgets are as important as any toplevel widgets in any GUI applications,
since they allow the user to invoke a list of one-line entries
as and when required.
The structural layout of the menu widgets created using frame
and other Tk commands is shown in Figure 7.
The command menu creates a toplevel frame and different types of
widgets are added inside this frame:
button widgets for command entries,
checkbutton widgets for check button entries,
radiobutton widgets for radio button entries and
menubutton widgets for cascaded menu entries.
Separator entries are created using frame widgets
as shown in Figure 7.
This structure is hidden from the display until the user clicks on the menu button at the top. The implementation of the command grab, as described earlier, is important and allows us to post the menu widget frame whenever the user clicks on the menu button. As the user moves the cursor over different widgets in the menu frame, each widget is highlighted and the associated command invoked if necessary. Clicking on the cascaded entry results in the posting of another menu frame with its associated entries.
If the menu widget is of the type pulldown menu in a Menubar, then the menu entries are packed into the Menubar frame that was created in the toplevel procedure (Figure 5).
Standard I/O and audio. We have created a special window for standard I/O in WebWiseTclTk. Any communication to the standard I/O channel by commands such as puts and gets is redirected to the special window, as shown in Figure 8. Therefore, it is possible for the tclet and a user to interact through the commands puts and gets.
Audio commands, such as bell, are still potentially dangerous, with the risk of producing a continuous tone. Therefore, we defined a procedure bell which produces a visual effect by momentarily changing the background color of the canvas widget.
Safe commands. Earlier, we noticed that whenever a toplevel window, say ".w", is created, the window name is mapped to a new window name ".c.1.w", corresponding to the main frame in the set of toplevel frames. Therefore, existing safe commands such as button with window names ".w.b" will fail, unless their window names are also translated to a new name ".c.1.w.b", which is in the hierarchy of the toplevel main frame's children.
We rename the existing safe commands by moving them into a namespace for WebWiseTk, and define new procedures for them. Figure 9 shows a sample code for re-defining the command button. The newly defined procedure does the following:
The command bind also has to be re-defined. This is because the value of "%W" in the bind script gets the real window name (".c.1.b") instead of the window name (".b") supplied by the tclet. Thus all window names referred by "%W" in the bind script are mapped back appropriately, before invoking the original bind script.
Similarly, the command winfo is also redefined, so that its queries, such as "winfo width", "winfo children", etc., are correctly handled.
Unsafe commands. Few commands, such as send, tk_getOpenFile, tk_getSaveFile, etc., do not pose the denial of service attacks, but are still unsafe and very dangerous to the client host system since they present other forms of security attacks. These commands are therefore not available in WebWiseTk. However, it is always possible to use an appropriate security policy, other than the home policy, to enable these commands.
Unsafe options. A few options for safe commands are considered unsafe and hence not available in Safe-Tk. These include "-bitmap @filename", "-file filename" and "-maskfile filename", among others. It is possible to allow these options on the following conditions:
Script libraries and packages provide an excellent mechanism to structure an application code into several smaller scripts, and then dynamically load each script as needed. We modify the restricted commands in Safe-Tcl such that it supports the packaging facility to automatically load scripts from the server site of the tclet code. We only need to append the location of the server site, given by "getattr originHomeDirURL", to the auto_path variable for the auto_load procedure to work correctly with the modified commands described next.
Source.
The filename argument for the source command is parsed for
a URL. If the filename is a URL, then it is downloaded using the
command "::browser::getURL filename" and its contents are
evaluated. Otherwise, the original source command is invoked,
as shown in Figure 10.
Open and close. When a filename specified for open is a URL, the specified URL is downloaded and saved on the temporary disk space of the host system assigned by the home policy. Then, this file on the local disk is opened and its channel identifier returned. Correspondingly, when a close command is invoked for a URL, the file on the local disk is not only closed, but also deleted. These functions are useful for opening a file/URL in read-only mode.
File. We have re-defined the command file so that its options dirname, join, and split return correct results even when the specified filename is a URL.
Pwd, cd and glob. These commands are not available in Safe-Tcl. We therefore assign the URL of the server site, given by "getattr originHomeDirURL", to be the default working directory returned by the command pwd. This value is stored in a variable defined in WebWiseTcl namespace. The invocation of the command cd then results in change of value of the current working directory stored in the variable. The command glob returns a list of all matching URLs found under the URL given by the current working directory.
Users can very easily and quickly familiarize themselves with the WebWiseTclTk environment. Figure 2 shows one such typical view of the environment within a Netscape browser. The layout of the environment is shown in Figure 4. It has two widget areas - the one on the left contains windows created by the tclet, and the one on the right displays a list of buttons corresponding to each iconified window. Both the widgets have auto scrollbars. At the bottom, a single line help message is displayed, based on the location of the mouse cursor. The size of the widget containing the tclet windows may be increased or reduced by the user under the Preferences option. A user may also resize the canvas and the text widget areas by merely dragging the border between the two with a mouse cursor.
Installation. It is not necessary for the users to install the WebWiseTclTk toolkit. The scripts in the toolkit are dynamically downloaded, as and when required, from the server site of the running application/tclet. However, for faster access, users do have an option of installing the WebWiseTclTk toolkit in their Tcl-plugin directory. In this case, the installation procedure consists of the following:
# For local installation, csh% cd ~/.netscape/tclplug/2.0 # Or, for site installation, csh% cd /usr/local/lib/netscape/tclplug/2.0
csh% gzip -dc WebWiseTclTk-x.y.tar.gz | tar xf -
We define programmers as those who: (1) intend to write Tcl-plugin applications based on the WebWiseTclTk toolkit, or (2) wish to translate their existing Tcl applications into tclets for execution over the Web.
Programmers, who intend to use the WebWiseTclTk toolkit for their tclets, should follow the guidelines listed below:
csh% cd /home/user/public_html/tcletsFor example, let the URL corresponding to this directory be https://www.your.web.site/~ user/tclets.
csh% gzip -dc WebWiseTclTk-x.y.tar.gz | tar xf -
Figure 11 shows an example to encapsulate the Tk widget demos and execute them on the Web. The TkWidgetDemos.tcl script, the demos directory and the WebWiseTclTk toolkit directory all exist in the same directory location on the Web as shown below:
/home/user/public_html/tclets/WebWiseTclTk-x.y/examples
\
|_ TkWidgetDemos.html
|_ TkWidgetDemos.tcl
|_ WebWiseTclTk
| \
| |_ DownloadToolkit.tcl
| |_ toplevel.tcl
| ...
|_ demos
\
|_ widget
|_ arrow.tcl
|_ button.tcl
...
When a user downloads the TkWidgetDemos.tcl script, the script first tries to load the WebWiseTclTk toolkit from the user's host system. If it succeeds, then the home policy is requested since the Tk widget demos consist of several different scripts. On the other hand, if the WebWiseTclTk toolkit cannot be loaded from the user's host system, then it is downloaded from the tclets's server site.
The variable $tk_library is set to point to the tclets's server site so that it knows from where to auto_load the demo script. Finally, the widget script is sourced to execute the demos.
If the tclet does not require the use of display, possible by setting "tk=0" in the html embed statement, then it is also possible to load only the WebWiseTcl toolkit.
Debugging.
When writing new tclets,
programmers can avoid using Tcl-commands which are either
not available or not yet implemented in
WebWiseTclTk toolkit. However,
when converting existing applications, it is very difficult to isolate
and remove
these commands in the code. Therefore, we provide a mechanism whereby
a dialog box is popped up whenever any
unavailable or unimplemented command is used in the code
the first time, as shown in Figure 12.
The programmer, who is testing the tclet as a user, has a choice to either ignore the generation of this dialog box, the next time the same command is used, or to repeat it. A "Stack Trace" button is also available to locate the generation of the unimplemented command in the code.
Extensibility and reconfigurability. The WebWiseTclTk toolkit consists of several smaller scripts, specifically one file for each command that is either newly defined or re-defined. Therefore, programmers can (1) define and add their own commands which may be unavailable, such as send, in a separate file, or (2) re-define the existing commands by modifying the corresponding file to implement their own version of the command.
For example, the commands toplevel and menu may be re-implemented with a different layout to give a native look and feel on different platforms.
Installing a local copy of the toolkit with the Tcl-plugin on the client host will improve the performance when the distance between the client host and the web-server is large. We also need to improve the reliability of the toolkit by adding sufficient hooks to handle cases when `getURL' is likely to timeout or fail under high network traffic conditions.
https://www.cbl.ncsu.edu/software/#WebWiseTclTk. The current version of the toolkit is beta 1.02.
We have successfully tested this version of the toolkit on a Sun Sparc workstation with Solaris 2.5.1 using Netscape 4.0 and 3.0.
On a Windows 95/NT machine, we had to install the toolkit locally before we could access tclets based on WebWiseTclTk. Also, we had to use a special policy that allows downloading scripts from the server site using the command ::http::geturl from the http package. This is because, (1) the blocking version of the command ::browser::getURL is not supported in Netscape 4.0, and (2) the command ::browser::getURL is not available under Internet Explorer 4.0 for the Tcl-plugin. The implementation of menu widgets in WebWiseTclTk is specific to Unix and hence do not function properly on a Windows 95/NT machine.
We have also tested the toolkit successfully on a Mac running under MacOS 8.0. Again, the current implementation of menu widgets do not work correctly on a Mac.
Some of the features of the WebWiseTclTk toolkit described in this paper are not yet implemented. For example, in menu widgets, advanced features that are not implemented include: the accelerator option for any of its entry is ignored, creation of clones of menu frames using the tear-off entry is not possible, etc. For details of such items and current updates, please consult
https://www.cbl.ncsu.edu/software/#WebWiseTclTk.
Introduction of the WebWiseTcl toolkit, which uses the home policy, enables programmers to structure their tclets into several smaller scripts. Such scripts are easier to manage and dynamically loaded during the execution of the tclet.
While most of the commands related to denial of service attacks may be eventually restored in the Tcl-Plugin, WebWiseTclTk toolkit still offers the ability to confine the tclet windows to a single display within the Web browser.
Our first major application of WebWiseTk has been the introduction of Web-based user-configurable and executable workflows that support an environment functionally similar to one in REUBEN [11,12,13]. First demos of this capability has been shown in the University Booth during the 1998 Design Automation Conference [16]. On-line demos are accessible from https://www.cbl.ncsu.edu/demos.
This paper was originally published in the Sixth Annual Tcl/Tk Workshop, September 14-18, 1998, San Diego, California, USA
Last changed: 8 April 2002 ml |
|