| > >
 |  TWiki CGI and Command Line Scripts Programs on the TWiki server performing actions such as rendering, saving and renaming topics.
The TWiki scripts are located in thetwiki/binandtwiki/toolsdirectories. This topic describes the interfaces to some of those scripts. All scripts in thetwiki/bindirectory can be called from the CGI (Common Gateway Interface) environment or from the command line. The scripts in thetwiki/toolsdirectory can only be called from the command line. CGI Scripts Details on CGI scripts located in thetwiki/bindirectory. General Information  CGI environment In the CGI environment parameters are passed to the scripts via the URL and URL parameters. Environment variables are also used to determine the user performing the action. If the environment is not set up, the default TWiki user is used (usuallyguest). Command-line You must be cd'd to thetwiki/bindirectory to run the scripts from the command line. To avoid issues with file permissions, run the scripts as the web server user such asnobodyorwww.
Parameters are passed using '-name' - for example,
$ cd /usr/local/twiki/bin
$ save -topic MyWeb.MyTopic -user admin -action save -text "New text of the topic"
All parameters require a value.  Common parameters All the scripts accept a number of common parameters. The first two components of the URL after the script name are taken as the web and the topic, respectively. Standard URL parameters are:| Parameter | Description | Default | 
|---|
 | topic | If this is set to a URL, TWiki will immediately redirect to that URL. Otherwise it overrides the URL and is taken as the topic name (you can pass Web.TopicName) |  |  | user | Command-line only; set the name of the user performing the action. Note: this usage is inherently insecure, as it bypasses webserver login constraints. For this reason only authorised users should be allowed to execute scripts from the command line. |  |  | skin | Overrides the default skin path (see TWikiSkins) |  |  | cover | Specifies temporary skin path to prepend to the skin path for this script only (see TWikiSkins) |  | 
  Despite the name, this script doesn't actually attach a file to a topic - for that, useattachupload. This script is part of the transactions sequence executed when a file is uploaded from the browser. it just generates the "new attachment" page for a topic.| Parameter | Description | Default | 
|---|
 | filename | Name of existing attachment (if provided, this is a "manage attachment" action) | none (in which case this is a "new attachment" action) | 
  Shows all the changes in the given web. 
Thechangeschangesscript can receive one parameter:
The main difference between invoking this script and using WebChanges is that WebChanges is based on a%SEARCH%, while this script reads thechangesfile in each web, making it much faster.
NOTE: The result fromchangesscript and the topic WebChanges can be different, if thechangesfile is deleted from a web. In particular, in new installations thechangesscript will return no results while the WebChanges topic will. configureconfigureis the browser script used for inspection and configuration of the TWiki configuration. None of the parameters to this script are useable for any purpose exceptconfigure. Theediteditscipt understands the following parameters, typically supplied by HTML input fields:Form field values are passed in parameters named 'field' - for example, if I have a field| Parameter | Description   | Default | 
|---|
 | anyname | Any parameter can passed to the new topic; if the template topic contains %URLPARAM{"anyname"}%, it will be replaced by its value |  |  | breaklock | If set, any lease conflicts will be ignored, and the edit will proceed even if someone is already editing the topic. |  |  | onlynewtopic | If set, error if topic already exists |  |  | onlywikiname | If set, error if topic name is not a WikiWord |  |  | text | Initial text for the topic |  |  | formtemplate | Name of the form to instantiate in the topic. Overrides the form set in the templatetopicif defined. |  |  | contenttype | Optional parameter that defines the application type to write into the CGI header. Defaults to text/html. May be used to invoke alternative client applications |  |  | action | Optional. Use the editaction template instead of the standard edit. If action=text, then hide the form. If action=form hide the normal text area and only edit the form. |  |  | templatetopic | The name of the template topic, copied to get the initial content |  |  | topicparent | The parent topic |  | 
 Statusthe parameter name isStatus.
NOTE: most skins support the definition of The first sequence of ten or more Xcharacters in the topic name will be converted on save to a number such that the resulting topic name is unique in the target web. EDIT_SKIN, which is used as the value of thecoverparameter ineditURLs. This allows you to override the default edit skin on a web, topic or user basis. Used for logging in when TWiki login is being used (e.g TemplateLoginManager).login| Parameter | Description | Default | 
|---|
 | origurl | URL that was being accessed when an access violation occurred. the login process will redirect to this URL if it is successful | none |  | username | username of user logging in | none |  | password | password of user logging in | none | 
  Used for logging in when Web Server authentication is being used (e.g. ApacheLoginManager). The script does nothing; it is purely a placeholder for triggering the login process. The webserver will be set up to require a valid user to access this script, thus triggering the webserver login process.logon Performs a range of management functions.manage action=createweb| Parameter | Description | Default | 
|---|
 | newweb | Name of the new web | '' |  | baseweb | Name of the web to copy to create the new web | '' |  | webbgcolor | value for WEBBGCOLOR | '' |  | sitemapwhat | Value for SITEMAPWHAT | '' |  | sitemapuseto | Value for SITEMAPUSETO | '' |  | nosearchall | Value for NOSEARCHALL | '' | 
  Unregisters (removes) the currently logged-in user.action=deleteUserAccount No parametersaction=editSettings See BulkRegistration.action=bulkRegister| Parameter | Description | Default | 
|---|
 | OverwriteHomeTopics | Whether to overwrite existing home topics or not | false |  | EmailUsersWithDetails | Whether to mail registered users or not | false |  | LogTopic | Topic to save the log in | Same as topic name, with 'Result' appended. | 
  All other parameters may be interpreted as form fields, depending on the current form definition in the topic.action=saveSettings This script is mainly used for rendering pages containing error messages, though it is also used for some functional actions such as manage pages (move topic etc).oopsoopstemplates are used with theoopsscript to generate system messages. This is done to make internationalisation or other local customisations simple. 
Theoopsscript supports the following parameters:| Parameter | Description | Default | 
|---|
 | template | Name of the template file to display |  |  | def | Optional, can be set to the name of a single definition within template. This definition will be instantiated in thetemplatewherever%INSTANTIATE%is seen. This lets you use a single template file for many messages. For an example, seeoopsmanagebad.tmpl. |  |  | paramN | Where N is an integer from 1 upwards. These values will be substituted into templatefor%PARAM1%etc. |  | 
  Other parameters as described underpasswdmanage,action=changePassword. action=changePassword| Parameter | Description | Default | 
|---|
 | username | Username |  |  | oldpassword | Existing password (plain text) |  |  | password | New password (plain text) |  |  | passwordA | New password confirmation (plain text) |  |  | TopicName | ? |  | 
  This script is deprecated. Its functions are covered by thepreviewsavescript. Renders the differences between version of a TWiki topicrdiffTODO:| Parameter | Description | Default | 
|---|
 | rev1 | the higher revision |  |  | rev2 | the lower revision |  |  | render | the rendering style {sequential, sidebyside, raw, debug} | DIFFRENDERSTYLE, sequential |  | type | history, diff, last} history diff, version to version, last version to previous | diff |  | context | number of lines of context |  | 
 
 add a {word} render style
  register Used for renaming topics.rename| Parameter | Description | Default | 
|---|
 | skin | skin(s) to use |  |  | newweb | new web name |  |  | newtopic | new topic name |  |  | breaklock |  |  |  | attachment |  |  |  | confirm | if defined, requires a second level of confirmation |  |  | currentwebonly | if defined, searches current web only for links to this topic |  |  | nonwikiword | if defined, a non-wikiword is acceptable for the new topic name |  | 
  Reset the password for a single or multiple usersresetpasswdThis is used by BulkResetPassword and ResetPassword. Only users belonging to the TWikiAdminGroup can provide a list of LoginNames, non-admins can only provide a single LoginName. 
BulkRegistration provides the means to create multiple accounts but it does not announce those accounts to the users who own them. BulkResetPassword is used to assign the passwords, the Introduction is used to explain why they are receiving the mail.| Parameter | Description | Default | 
|---|
 | LoginName | list of usernames to reset | none - error if not set |  | Introduction | message to be sent alongside the reset, most often used to announce to the user that they have been given an account. | '' | 
  This REST (Representational State Transfer) script can be invoked via http in a similar way as the view script (see Invocation Examples, below) to execute a function that is associated to a "subject" and a "verb" (see below). It'll print the result directly to the stream unless therestendPointparameter is specified, in which case the control is redirected to the given topic.
Therestscript itself uses one parameter:Any additional parameters are passed directly to the function (i.e: The function can get any other parameter using the CGI $query object)| endPoint | Where to redirect the response once the request is served, in the form "Web.Topic" | 
  Invocation Examples Therestscript assumes that it will be called with URL in the form:http://my.host/bin/rest/<subject>/<verb>where<subject>must be the WikiWord name of one of the installed TWikiPlugins, and the<verb>is the alias for the function registered using theregisterRESTHandler. The<subject>and<verb>are then used to lookup and call the registered function.
Functions outside the Plugins also can be registered, but please consider the security implications of allowing URL access, as functions can sidestep TWiki Authentication & Authorisation settings.<subject>and<verb>are checked for illegal characters exactly in the same way as the web and topic names.
As an example, the EmptyPlugin has registered a function to be used with therestscript under the subject EmptyPlugin and the verb example. Click below to see therestscript in action (run as TWikiGuest).
Call the Plugin
You can also call the function from the command line, but this will be run as the TWikiAdminGroup (as it is assumed that shell access is secure) - eg:./rest EmptyPlugin.exampleNote that for calls to Plugins, they must be enabled in configure. Thesavesavescript performs a range of save-related functions, as selected by theactionparameter.Any errors will cause a redirect to an| Parameter | Description | Default | 
|---|
 | action_save=1 | default; save, return to view, dontnotify is OFF |  |  | action_quietsave=1 | save, and return to view, dontnotifyis ON |  |  | action_checkpoint | save and redirect to the edit script, dontnotifyis ON |  |  | action_cancel | exit without save, return to view |  |  | action_preview | preview edited text |  |  | action_addform | Redirect to the "change form" page. |  |  | action_replaceform... | Redirect to the "change form" page. |  |  | action_delRev | Administrators only delete the most recent revision of the topic - all other parameters are ignored. You have to be a member of TWikiAdminGroup to use this, and not all store implementations will support it. |  |  | action_repRev | Administrators only replace the text of the most recent revision of the topic with the text in the textparameter.textmust included embedded meta-data tags. All other parameters are ignored. You have to be a member of TWikiAdminGroup to use this, and not all store implementations will support it. |  |  | onlynewtopic | If set, error if topic already exists |  |  | onlywikiname | If set, error if topic name is not a WikiWord |  |  | dontnotify | if defined, suppress change notification |  |  | templatetopic | Name of a topic to use as a template for the text and form |  |  | text | New text of the topic |  |  | forcenewrevision | if set, forces a revision even if TWiki thinks one isn't needed |  |  | topicparent | If 'none' remove any current topic parent. If the name of a topic, set the topic parent to this. |  |  | formtemplate | if defined, use the named template for the form |  |  | editaction | When action is checkpoint,add formorreplace form..., this is used as theactionparameter to theeditscript that is redirected to after the save is complete. |  |  | originalrev | Revision on which the edit started. |  | 
 oopspage.
The parameters are interpreted in according to the following rules.
Merging is only enabled if the topic text comes from The first sequence of ten or more Xcharacters in the topic name will be converted to a number such that the resulting topic name is unique in the target web. When the action is save,checkpoint,quietsave, orpreview:
 The new text is taken from the textparameter, if it is defined,
 otherwise it is taken from the templatetopic, if it is defined, otherwise it is taken from the previous version of the topic, if any,
 The name of the new form is taken from the formtemplate, if defined
 otherwise it is taken from the templatetopic, if defined, otherwise it is taken from the previous version of the topic, if any,
 otherwise no form is attached.
 The value for each field in the form is taken from the query, if it is defined 
 otherwise it is taken from the templatetopic, if defined, otherwise it is taken from the previous version of the topic, if any,
 otherwise it defaults to the empty string.
 textandoriginalrevis > 0 and is not the same as the revision number of the most recent revision. If merging is enabled both the topic and the meta-data are merged.
Form field values are passed in parameters named 'field' - for example, if I have a fieldStatusthe parameter name isStatus. CGI gateway to thesearch%SEARCH%functionality driven by the following CGI parameters:| Parameter: | Description: | Default: | 
|---|
 | "text" | Search term. Is a keyword search, literal search or regular expression search, depending on the typeparameter. SearchHelp has more | required |  | search="text" | (Alternative to above) | N/A |  | web="Name"
 web="Main, Know"
 web="all" | Comma-separated list of webs to search. The special word allmeans all webs that doe not have theNOSEARCHALLvariable set toonin their WebPreferences. You can specifically exclude webs from anallsearch using a minus sign - for example,web="all,-Secretweb". | Current web |  | topic="WebPreferences"
 topic="*Bug" | Limit search to topics: A topic, a topic with asterisk wildcards, or a list of topics separated by comma. | All topics in a web |  | excludetopic="Web*"
 excludetopic="WebHome, WebChanges" | Exclude topics from search: A topic, a topic with asterisk wildcards, or a list of topics separated by comma. | None |  | type="keyword"
 type="literal"
 type="regex" | Do a keyword search like soap "web service" -shampoo; a literal search likeweb service; or RegularExpression search likesoap;web service;!shampoo | %SEARCHVAR- DEFAULTTYPE%preferences setting (literal) |  | scope="topic"
 scope="text"
 scope="all" | Search topic name (title); the text (body) of topic; or all (both) | "text" |  | order="topic"
 order="created"
 order="modified"
 order="editby"
 order="formfield(name)"
 | Sort the results of search by the topic names, topic creation time, last modified time, last editor, or named field of TWikiForms. The sorting is done web by web; in case you want to sort across webs, create a formatted table and sort it with TablePlugin's initsort | Sort by topic name |  | limit="all"
 limit="16" | Limit the number of results returned. This is done after sorting if orderis specified | All results |  | date="..." | limits the results to those pages with latest edit time in the given TimeInterval. | All results |  | reverse="on" | Reverse the direction of the search | Ascending search |  | casesensitive="on" | Case sensitive search | Ignore case |  | bookview="on" | BookView search, e.g. show complete topic text | Show topic summary |  | nonoise="on" | Shorthand for nosummary="on" nosearch="on" nototal="on" zeroresults="off" noheader="on" noempty="on" | Off |  | nosummary="on" | Show topic title only | Show topic summary |  | nosearch="on" | Suppress search string | Show search string |  | noheader="on" | Suppress search header Topics: Changed: By:
 | Show search header |  | nototal="on" | Do not show number of topics found | Show number |  | zeroresults="off" | Suppress all output if there are no hits | zeroresults="on", displays: "Number of topics: 0" |  | noempty="on" | Suppress results for webs that have no hits. | Show webs with no hits |  | header="..."
 format="..." | Custom format results: see FormattedSearch for usage, variables & examples | Results in table |  | expandvariables="on" | Expand variables before applying a FormattedSearch on a search hit. Useful to show the expanded text, e.g. to show the result of a SpreadSheetPlugin %CALC{}%instead of the formula | Raw text |  | multiple="on" | Multiple hits per topic. Each hit can be formatted. The last token is used in case of a regular expression ";" and search | Only one hit per topic |  | nofinalnewline="on" | If on, the search variable does not end in a line by itself. Any text continuing immediately after the search tag on the same line will be rendered as part of the table generated by the search, if appropriate. | off |  | separator=", " | Line separator between hits | Newline "$n" | 
  Refresh the WebStatistics topics in range of webs.statistics Single-script interface to the functionality of all the other scripts. Experimental, not for production use. Read the code if you want to know more.twiki Uploads an attachment to a topic. The HTTP request is expected to be inuploadmultipart/form-dataformat.You can use a tool like| Parameter | Description | Default | 
|---|
 | hidefile | if defined, will not show file in attachment table |  |  | filepath | local (client) path name of the file being uploaded. This is used to look up the data for the file in the HTTP query. |  |  | filename | deprecated, do not use |  |  | filecomment | Comment to associate with file in attachment table |  |  | createlink | if defined, will create a link to file at end of topic |  |  | changeproperties | if defined, this is a property change operation only - no file will be uploaded. | null | 
 curlto upload files from the command line using this script. Used for viewing topics.view| Parameter | Description | Default | 
|---|
 | raw=on | Shows the text of the topic in a scrollable textarea |  |  | raw=debug | As raw=on, but also shows the metadata (forms etc) associated with the topic. |  |  | raw=text | Shows only the source of the topic, as plain text (Content-type: text/plain). Only shows the body text, not the form or other meta-data. |  | raw=all | Shows only the source of the topic, as plain text (Content-type: text/plain), with embedded meta-data. This may be useful if you want to extract the source of a topic to a local file on disc. |  |  | contenttype | Allows you to specify a different Content-Type: (e.g. contenttype=text/plain) |  |  | rev | Revision to view (e.g. rev=45) |  |  | template | Allows you to specify a different skin template, overriding the 'view' template the view script would normally use. The default template is view. For example, you could specify /twiki/bin/view/TWiki/TWikiScripts?template=edit. This is mainly useful when you have specialised templates for a TWiki Application. |  | 
  For historical reasons, the view script has a special interpretation of the textskin. In earlier TWiki versions theskin=textparameter was used like this:http://.../view/MyWeb/MyTopic?skin=text&contenttype=text/plain&raw=onwhich shows the topic as plain text; useful for those who want to download plain text for the topic.
Usingskin=textthis way is DEPRECATED, useraw=textinstead. Used for viewing attachments. Normally, a site will publish the attachments (viewfilepub) directory using a URL. However if it contains sensitive information, you will want to protect attachments using TWikiAccessControls. In this case, you can use theviewfilescript to give access to attachments while still checking access controls. Command Line Scripts Details on command line scripts located in thetwiki/toolsdirectory. This is a very simple script to get the content of a web site. It is marked as deprecated and might be removed (or enhanced) in a future TWiki release. Its functions are covered by the standardgeturl.plwgetandcurlcommands.
 Usage:	 geturl <host> <path> [<port> [<header>]] Example:  geturl some.domain /some/dir/file.html 80 Will get: http://some.domain:80/some/dir/file.html  Simple script to rewrite therewriteshebang.pl#!/usr/bin/perlshebang lines specific to your local Perl installation. It will rewrite the first line of all your TWiki cgi scripts so they use a different shebang line. Use it if your perl is in a non-standard location, or you want to use a different interpreter (such as 'speedy'). This script executes a number of non-essential regular administration tasks that will help keep your TWiki healthy and happy, such as removing expired sessions and lease files.
It is intended to be run as a cron job or a scheduled task once a week. Example crontab entry:tick_twiki.pl
 0 0 * * 0 cd /usr/twiki/bin && perl ../tools/tick_twiki.plNote: The script has to be run by a user who can write files created by the webserver user.
Related Topics: AdminDocumentationCategory, DeveloperDocumentationCategory |