Tags:
create new tag
, view all tags

Load App Plugin

Load TWiki application code from a topic in a hidden web (for copy protection)

Introduction

diagram.png
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:

  1. TWiki application code can be distracting and messy, especially to non-programmers.
  2. 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:

  1. Work web: Web where users interact with the application and create content, such as a CRM web.
  2. 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

Description

As described in the introduction, the user interface and the application code reside in two TWiki webs:

  1. Work web: Web where users interact with the application and creates content, such as a KB web.
  2. 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:

%CALCULATE{ }%
Result:
TWiki Guest

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 TWiki06x00 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.

  • Install dependencies:

  • 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)

Plugin Author: TWiki:Main.PeterThoeny
Copyright: © 2015-2016 TWiki:Main.PeterThoeny
© 2015-2016 TWiki:TWiki.TWikiContributor
License: GPL (GNU General Public License)
Plugin Version: 2016-04-27
2016-04-27: TWikibug:Item7703: Doc improvements
2016-04-25: TWikibug:Item7703: Add demo app page and sandbox page that loads the demo app page; doc improvements
2016-01-14: TWikibug:Item7708: Copyright update to 2016
2015-03-31: TWikibug:Item7624: Initial version
TWiki Dependency: $TWiki::Plugins::VERSION 1.1
CPAN Dependencies: none
Other Dependencies: none
Perl Version: 5.005
Benchmarks: GoodStyle 100%, FormattedSearch 99%, LoadAppPlugin 99%
Plugin Home: http://TWiki.org/cgi-bin/view/Plugins/LoadAppPlugin
Feedback: http://TWiki.org/cgi-bin/view/Plugins/LoadAppPluginDev
Appraisal: http://TWiki.org/cgi-bin/view/Plugins/LoadAppPluginAppraisal

Related Topics: VarLOADAPP, LoadAppDemoPage, Sandbox.LoadAppDemoPage, TWikiPlugins, DeveloperDocumentationCategory, AdminDocumentationCategory, VarINCLUDE

Topic attachments
I Attachment History Action Size Date Who Comment
Unknown file formatmd5 LoadAppPlugin.md5 r3 r2 r1 manage 0.2 K 2016-04-27 - 09:03 PeterThoeny  
Compressed Zip archivetgz LoadAppPlugin.tgz r3 r2 r1 manage 77.2 K 2016-04-27 - 09:03 PeterThoeny  
Compressed Zip archivezip LoadAppPlugin.zip r3 r2 r1 manage 81.6 K 2016-04-27 - 09:03 PeterThoeny  
Unknown file formatEXT LoadAppPlugin_installer r1 manage 3.7 K 2016-04-27 - 09:03 PeterThoeny  
Edit | Attach | Watch | Print version | History: r5 < r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r5 - 2016-05-19 - PeterThoeny
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.