Load App Plugin
Load TWiki application code from a topic in a hidden web (for copy protection)
Introduction
When TWiki is used as an application platform, all application code resides in TWiki topics. The source can easily be inspected with the "Raw View" option. This is good so that people can learn and create apps for their own needs. However, there can be drawbacks as well:
- TWiki application code can be distracting and messy, especially to non-programmers.
- Proprietary application code is not protected, .e.g. anybody can copy the source code if the application runs on a public TWiki site.
This plugin addresses both issues. The user interface and the application code are split up, and reside in two TWiki webs:
- Work web: Web where users interact with the application and create content, such as a CRM web.
- App web: Access restricted web, hosting the application code, such as a CRMApp web.
When a topic in the Work web needs some application code, the
%LOADAPP{}% variable is used to load the code from the App web. This variable works similar to the
%INCLUDE{}% variable.
Syntax Rules
LOADAPP{"id"} -- Load TWiki application code from a hidden web
- Include a TWiki application topic indicated by an ID. The LOADAPP variable is handled by the LoadAppPlugin, and works similar to the INCLUDE variable.
- Syntax:
%LOADAPP{"id" ...}%
- Supported parameters:
| Parameter: | Description: | Default: |
"someID" | The ID of the application snippet to include. Example: %LOADAPP{"kbHeader"}% will include the topic KnowledgeBaseHeader from the KB web, assuming the mapping 'kbHeader: KB.KnowledgeBaseHeader' is defined in configure | (required) |
section="name" | Include only the specified named section, as defined in the included topic by the STARTSECTION and ENDSECTION variables. Nothing is shown if the named section does not exists. section="" is equivalent to not specifying a section | "" |
PARAMONE="val 1" PARAMTWO="val 2" | Any other parameter will be defined as a variable within the scope of the included topic. The example parameters on the left will result in %PARAMONE% and %PARAMTWO% being defined within the included topic. A default value for a variable can be specified in the included topic in case the corresponding parameter is not specified, such as %PARAMONE{ default="..." }% | (optional) |
- Example: See LoadAppPlugin
- Category: ApplicationsAndComponentsVariables, DevelopmentVariables, ImportVariables
- Related: BASETOPIC, BASEWEB, INCLUDE, INCLUDINGTOPIC, INCLUDINGWEB, STARTINCLUDE, STOPINCLUDE, STARTSECTION, ENDSECTION, IncludeTopicsAndWebPages, ParameterizedVariables, LoadAppPlugin
Description
As described in the introduction, the user interface and the application code reside in two TWiki webs:
- Work web: Web where users interact with the application and creates content, such as a KB web.
- App web: Access restricted web, hosting the application code, such as a KBApp web.
Steps to create an application where the code is hidden:
1. Create Application in App web
Create the application along with test data in the App web. For example, a knowledge base application might have these application topics:
- KnowledgeBase - KB home (dashboard)
- KnowledgeBaseSearch - search the KB
- KnowledgeBaseAddArticle - add article
- KnowledgeBaseForm - form definition of a KB article
- KnowledgeBaseTemplate - template for new KB articles
- KnowledgeBaseHeader - header of KB articles
- KnowledgeBaseMaintenance - KB maintenance topic, for admin docs and app topic links
KB article topics could have
WikiWord names or be auto-numbered, such as KB-0001, KB-0002. Create articles for testing, and modify the application until it performs as desired.
Restrict access to the App web if you want to copy protect the application. An ALLOWWEBVIEW restriction is typically done to the
TWikiAdminGroup so that only TWiki administrators can view the application logic.
2. Define ID to Topic Mapping
Before we can load application code into the Work web we need to define an ID to topic mapping. The
%LOADAPP{}% variable loads application code identified by an ID, not directly by topic name. This is done by design for security. In contrast to
INCLUDE, the LOADAPP variable loads topics regardless of access control.
The ID to topic mapping is defined in configure with a
{Plugins}{LoadAppPlugin}{Map}{<App name>} setting. Using the previous KBApp example, edit
twiki/lib/LocalSite.cfg and add this:
$TWiki::cfg{Plugins}{LoadAppPlugin}{Map}{KB} = 'kbHome: KBApp.KnowledgeBase, kbSearch: KBApp.KnowledgeBaseSearch, kbAdd: KBApp.KnowledgeBaseAddArticle, kbHeader: KBApp.KnowledgeBaseHeader';
The
{Plugins}{LoadAppPlugin}{Map} supports any number of applications; in our example the
{KB} defines the mapping for the KB application.
Only define IDs for application pages you want to load. Topics that you want users to see are duplicated in the Work web, such as the KnowledgeBaseForm and KnowledgeBaseTemplate.
3. Create Application in Work web
Now we can create the application in the Work web, after getting the application to work in the App web, and after defining the ID to topic mapping.
Create all application topics in the Work web:
- For topics you want users to see, do a copy & paste from the App web (or a file copy on the server) - in our example KnowledgeBaseForm, KnowledgeBaseTemplate and KnowledgeBaseMaintenance.
- For topics you want to hide the source from the user, create each topic containing just one LOADAPP line. For example, the KnowledgeBaseSearch topic contains
%LOADAPP{"kbSearch"}%.
One point of consideration is the scope of topics in regards to
%WEB% and
%TOPIC%. With an INCLUDE the scope is the included web, e.g. the Apps web. In contrast, the scope of the topic loaded with LOADAPP is the current web, e.g. the Work web. This is done by design so that the application thinks it runs in the current web.
Example
Here is an example based on above documentation.
1. Create Application Page in App web: The Plugins web serves as the app web for this example. It contains a sample application page called
LoadAppDemoPage. The page contains a form to try
SpreadSheetPlugin formulas. It is shown here with a regular INCLUDE for illustration:
2. Define ID to Topic Mapping: The configuration at
twiki/lib/LocalSite.cfg has the following setting ready for use:
$TWiki::cfg{Plugins}{LoadAppPlugin}{Map}{Demo} = 'demoPage: %SYSTEMWEB%.LoadAppDemoPage';
It defines a
demoPage ID that points to the LoadAppDemoPage topic in the TWiki06x01 web.
3. Create Application in Work web: The Sandbox web serves as the work web for this example. It contains a sample application page called
LoadAppDemoPage. It simply contains one line:
%LOADAPP{"demoPage"}%
Assuming the LoadAppPlugin is installed and enabled, the
Sandbox.LoadAppDemoPage will show the form to try out spreadsheet functions. On submit, a URL parameter is used to carry over the formula. That URL parameter is used transparently by the included application topic.
Plugin Installation Instructions
You do not need to install anything on the browser to use this plugin. These instructions are for the administrator who installs the plugin on the TWiki server.
- For an automated installation, run the configure script and follow "Find More Extensions" in the in the Extensions section.
- Or, follow these manual installation steps:
- Download the ZIP file from the Plugins home (see below).
- Unzip
LoadAppPlugin.zip in your twiki installation directory. Content: | File: | Description: |
data/TWiki/LoadAppPlugin.txt | Plugin topic |
data/TWiki/LoadAppDemoPage.txt | Demo app topic |
data/TWiki/VarLOADAPP.txt | GET documentation |
data/Sandbox/LoadAppDemoPage.txt | Demo topic that loads an app topic |
lib/TWiki/Plugins/LoadAppPlugin.pm | Plugin Perl module |
lib/TWiki/Plugins/LoadAppPlugin/Core.pm | Core Perl module |
lib/TWiki/Plugins/LoadAppPlugin/Config.spec | Configuration file |
- Set the ownership of the extracted directories and files to the webserver user.
- Plugin configuration and testing:
- Run the configure script and enable the plugin in the Plugins section.
- Test if the installation was successful: Follow the example above.
Plugin Info
- One line description, is shown in the TextFormattingRules topic:
- Set SHORTDESCRIPTION = Load TWiki application code from a topic in a hidden web (for copy protection)
Related Topics: VarLOADAPP,
LoadAppDemoPage,
Sandbox.LoadAppDemoPage,
TWikiPlugins,
DeveloperDocumentationCategory,
AdminDocumentationCategory,
VarINCLUDE