From 7d12d89a0afda3ff5383b4c64e7408485dd959bc Mon Sep 17 00:00:00 2001 From: Jermolene Date: Thu, 28 Nov 2013 14:03:08 +0000 Subject: [PATCH] Added primitive support for basic authentication Note that the password will be passed over HTTP in plain text. --- boot/boot.js | 1 + core/modules/commands/server.js | 63 ++++++++++++++----- core/modules/utils/utils.js | 12 ++++ .../tw5.com/tiddlers/Release 5.0.0alpha16.tid | 1 + .../tiddlers/commands/ServerCommand.tid | 3 + readme.md | 2 +- serve.cmd | 2 +- serve.sh | 2 +- 8 files changed, 68 insertions(+), 18 deletions(-) diff --git a/boot/boot.js b/boot/boot.js index 7f3aaa1b2..a6b88a26e 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -555,6 +555,7 @@ $tw.modules.execute = function(moduleName,moduleRoot) { clearInterval: clearInterval, setTimeout: setTimeout, clearTimeout: clearTimeout, + Buffer: $tw.browser ? {} : Buffer, $tw: $tw, require: function(title) { return $tw.modules.execute(title, name); diff --git a/core/modules/commands/server.js b/core/modules/commands/server.js index 116c47adf..19ac526fb 100644 --- a/core/modules/commands/server.js +++ b/core/modules/commands/server.js @@ -49,27 +49,58 @@ SimpleServer.prototype.addRoute = function(route) { this.routes.push(route); }; +SimpleServer.prototype.findMatchingRoute = function(request,state) { + for(var t=0; tWelcome to TiddlyWiki5

This is the developer documentation hub for TiddlyWiki. For convenience, it also contains all of the end user documentation that appears at http://five.tiddlywiki.com/.

Overview

Developer Cookbooks

Using TiddlyWiki for GitHub Pages project documentation

Internal Objects and Mechanisms

BootMechanism
DraftMechanism
EncryptionMechanism
LazyLoadingMechanism
ParsingMechanism
PluginMechanism
RenderingMechanism

Getting started with TiddlyWiki under Node.js

TiddlyWiki5 can be used on the command line to perform an extensive set of operations based on tiddlers, TiddlyWikiFolders, TiddlerFiles and TiddlyWikiFiles. For example, the following command loads the tiddlers from a TiddlyWiki HTML file and then saves one of them in HTML:

node tiddlywiki.js --verbose --load mywiki.html --rendertiddler ReadMe ./readme.html

In order to use TiddlyWiki5 on the command line you must first install node.js from http://nodejs.org/

Usage

Running tiddlywiki.js from the command line boots the TiddlyWiki kernel, loads the core plugins and establishes an empty wiki store. It then sequentially processes the command line arguments from left to right. The arguments are separated with spaces.

The first argument is the optional path to the TiddlyWikiFolder to be loaded. If not present, then the current directory is used.

The commands and their individual arguments follow, each command being identified by the prefix --.

node tiddlywiki.js [<wikipath>] [--<command> [<arg>[,<arg>]]]

Script Files

For trying TiddlyWiki5 out under Node.js, several scripts are provided (.sh for *nix and .cmd for Windows):

bld: builds tw5.com

This script builds several variants of TiddlyWiki5 for deployment on tiddlywiki.com.

By default, files are output to a folder called jermolene.github.com, sibling to the TiddlyWiki5 source directory. For example:

/TiddlyWork/ - Directory for working with TiddlyWiki5
 	/TiddlyWiki5/ - Directory containing the TiddlyWiki5 repo from GitHub
-	/jermolene.github.com/ - Directory for output files

You can override the build output directory by defining the environment variable TW5_BUILD_OUTPUT. The easiest way to do this is to create a personal batch file to invoke TiddlyWiki5 that first sets the environment variable and then invokes bld.

The files output by bld are:

bld also runs the TiddlyWiki5 Node.js-based test suite (see TestingMechanism)

serve.sh <username> or serve.cmd <username>: serves tw5.com

This script starts TiddlyWiki5 running as an HTTP server with the content from the clientserver edition. By default, the Node.js serves on port 8080. If the optional username parameter is provided, it is used for signing edits.

To experiment with this configuration, run the script and then visit http://0.0.0.0:8080 in a browser.

Changes made in the browser propagate to the server over HTTP (use the browser developer console to see these requests). The server then syncs changes to the file system (and logs each change to the screen).

wbld: builds TiddlyWiki5 for TiddlyWeb

This script builds and deploys the code for TiddlyWiki5 in the Sky for TiddlyWeb. If you want to experiment with your own builds of TiddlyWiki5 for TiddlyWeb you could use this batch file as a base.

2bld: builds TiddlyWiki 2.6.5

This script builds TiddlyWiki 2.6.5 from the original source and then displays the differences between them (diff is used for *nix, fc for Windows).

Commands

The following commands are available:

LoadCommand

Load tiddlers from 2.x.x TiddlyWiki files (.html), .tiddler, .tid, .json or other files

--load <filepath>

PasswordCommand

Set a password for subsequent crypto operations

--password <password>

PrintCommand

The print command outputs specified information.

print tiddlers

Output the titles of the tiddlers in the wiki store

--print tiddlers

print tiddler

Print the fields of an individual tiddler

--print tiddler <title>

print system

Print the titles of the system tiddlers in the wiki store

--print system

print config

Print the current core configuration

--print config

RenderTiddlerCommand

Render an individual tiddler as a specified ContentType, defaults to text/html and save it to the specified filename

--rendertiddler <title> <filename> [<type>]

RenderTiddlersCommand

Render a set of tiddlers matching a filter to separate files of a specified ContentType (defaults to text/html) and extension (defaults to .html).

--rendertiddlers <filter> <template> <pathname> [<type>] [<extension>]

For example:

--rendertiddlers [!is[system]] $:/core/templates/static.tiddler.html ./static text/plain

ServerCommand

The server built in to TiddlyWiki5 is very simple. Although compatible with TiddlyWeb it doesn't support many of the features needed for robust Internet-facing usage - in particular, TiddlyWiki5 is an old-school wiki in the sense that it offers no authentication.

At the root, it serves a rendering of a specified tiddler. Away from the root, it serves individual tiddlers encoded in JSON, and supports the basic HTTP operations for GET, PUT and DELETE.

--server <port> <roottiddler> <rendertype> <servetype> <username>

The parameters are:

For example:

--server 8080 $:/core/tiddlywiki5.template.html text/plain text/html MyUserName

VerboseCommand

Triggers verbose output, useful for debugging

--verbose

VersionCommand

Displays the version number of TiddlyWiki.

--version

This readme file was automatically generated by TiddlyWiki5 + /jermolene.github.com/ - Directory for output files

You can override the build output directory by defining the environment variable TW5_BUILD_OUTPUT. The easiest way to do this is to create a personal batch file to invoke TiddlyWiki5 that first sets the environment variable and then invokes bld.

The files output by bld are:

bld also runs the TiddlyWiki5 Node.js-based test suite (see TestingMechanism)

serve.sh <username> or serve.cmd <username>: serves tw5.com

This script starts TiddlyWiki5 running as an HTTP server with the content from the clientserver edition. By default, the Node.js serves on port 8080. If the optional username parameter is provided, it is used for signing edits.

To experiment with this configuration, run the script and then visit http://0.0.0.0:8080 in a browser.

Changes made in the browser propagate to the server over HTTP (use the browser developer console to see these requests). The server then syncs changes to the file system (and logs each change to the screen).

wbld: builds TiddlyWiki5 for TiddlyWeb

This script builds and deploys the code for TiddlyWiki5 in the Sky for TiddlyWeb. If you want to experiment with your own builds of TiddlyWiki5 for TiddlyWeb you could use this batch file as a base.

2bld: builds TiddlyWiki 2.6.5

This script builds TiddlyWiki 2.6.5 from the original source and then displays the differences between them (diff is used for *nix, fc for Windows).

Commands

The following commands are available:

LoadCommand

Load tiddlers from 2.x.x TiddlyWiki files (.html), .tiddler, .tid, .json or other files

--load <filepath>

PasswordCommand

Set a password for subsequent crypto operations

--password <password>

PrintCommand

The print command outputs specified information.

print tiddlers

Output the titles of the tiddlers in the wiki store

--print tiddlers

print tiddler

Print the fields of an individual tiddler

--print tiddler <title>

print system

Print the titles of the system tiddlers in the wiki store

--print system

print config

Print the current core configuration

--print config

RenderTiddlerCommand

Render an individual tiddler as a specified ContentType, defaults to text/html and save it to the specified filename

--rendertiddler <title> <filename> [<type>]

RenderTiddlersCommand

Render a set of tiddlers matching a filter to separate files of a specified ContentType (defaults to text/html) and extension (defaults to .html).

--rendertiddlers <filter> <template> <pathname> [<type>] [<extension>]

For example:

--rendertiddlers [!is[system]] $:/core/templates/static.tiddler.html ./static text/plain

ServerCommand

The server built in to TiddlyWiki5 is very simple. Although compatible with TiddlyWeb it doesn't support many of the features needed for robust Internet-facing usage - in particular, TiddlyWiki5 is an old-school wiki in the sense that it offers no authentication.

At the root, it serves a rendering of a specified tiddler. Away from the root, it serves individual tiddlers encoded in JSON, and supports the basic HTTP operations for GET, PUT and DELETE.

--server <port> <roottiddler> <rendertype> <servetype> <username>

The parameters are:

If the password parameter is specified then the browser will prompt the user for the username and password. Note that the password is transmitted in plain text so this implementation isn't suitable for general use.

For example:

--server 8080 $:/core/tiddlywiki5.template.html text/plain text/html MyUserName

VerboseCommand

Triggers verbose output, useful for debugging

--verbose

VersionCommand

Displays the version number of TiddlyWiki.

--version

This readme file was automatically generated by TiddlyWiki5

\ No newline at end of file diff --git a/serve.cmd b/serve.cmd index 09f788e1b..213016222 100644 --- a/serve.cmd +++ b/serve.cmd @@ -7,5 +7,5 @@ rem Optional parameter is the username for signing edits node .\tiddlywiki.js ^ editions\clientserver ^ --verbose ^ - --server 8080 $:/core/save/all text/plain text/html %1^ + --server 8080 $:/core/save/all text/plain text/html %1 %2^ || exit 1 diff --git a/serve.sh b/serve.sh index 7d84e7e89..9e3738269 100755 --- a/serve.sh +++ b/serve.sh @@ -7,5 +7,5 @@ node ./tiddlywiki.js \ editions/clientserver \ --verbose \ - --server 8080 $:/core/save/all text/plain text/html $1\ + --server 8080 $:/core/save/all text/plain text/html $1 $2\ || exit 1