Fork me on GitHub

meine erde

written by Holger Just on May 13, 2006 and tagged with TWiki.

Wenn Leute von Wikis reden, dann meinen sie häufig die Wikipedia. Dies ist aber “nur” eine Anwendung davon. Sie basiert auf dem Mediawiki. Daneben gibt es eine Reihe anderer Wikisysteme, z.B. eben TWiki.

TWiki hat den Vorteil, dass es eine weitreichende Rechteverwaltung bietet und somit auch als Public-Private-Wiki eingesetzt werden kann.

Was mich und andere aber stört, das sind die langen URLs. Meist sind sie in der Form http://www.example.com/twiki/bin/view/Web/WikiWord. Und das ist definitiv unschön. Viel schöner wäre etwas in der Form http://www.example.com/Web/WikiWord, nicht oder?

Es gibt zwar schon eine Menge Hinweise und Ideen, nur leider beziehen die sich meist auf die alte Version 3 (Cairo). Inzwischen gibt es aber eine neue Version (Dakar) und viele Dinge funktionieren anderes, einiges auch schöner.

Bei einer Installation, die ich gerade aufsetze habe ich mich als Basis die Konfiguration von wiki.boum.org hergenommen und angepasst.

Folgende Anforderungen sind dabei berücksichtigt worden:

  • URLs sollen möglichst kurz sein.
  • Standard-URLs müssen auch funktionieren.
  • Passwörter dürfen nicht im Klartext übertragen werden.

Alle Konfigurationsdateien (bzw. -fragmente), die im folgenden erwähnt werden können auch heruntergeladen werden.

Die Apache-Konfiguration

Die Anleitung beruht auf der Version 4.0.2 (Dakar) von TWiki.

Die Pfadangaben müssen möglicherweise angepasst werden. Bei dem gezeigten Code ist TWiki in /var/lib/twiki installiert. Allerdings wurden einige kleine Änderungen vorgenommen:

  • Das pub-Verzeichnis liegt in /var/www/twiki/pub
  • Das bin-Verzeichnis liegt in /usr/lib/cgi-bin/twiki

Beachtet werden sollte außerdem, dass die Konfiguration den TemplateLogin verlangt. Bei anderen Login-Managern muss die Weiterleitung auf https anders und die Zugriffsregelung mittels require valid user geregelt werden.

Es gibt zwei Virtual Hosts für HTTP und HTTPS.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<VirtualHost _default_:80>
  ServerName www.example.com
  ServerAdmin admin@example.com

  DocumentRoot /var/www/twiki
  ScriptAlias /twiki/bin/ "/usr/lib/cgi-bin/twiki/"
  Alias /twiki/ "/var/www/twiki/"

  # Pub Dirs
  <Directory "/var/www/twiki/pub">
    Options FollowSymLinks +Includes -Indexes
    AllowOverride None
    Allow from all
  </Directory>

  # We set an environment variable called anonymous_spider
  # Setting a BrowserMatchNoCase to ^$ is important. It prevents
  # TWiki fromincluding its own topics as URLs and also prevents
  # other TWikis from doing the same. This is important to
  # prevent the most obvious Denial of Service attacks.
  # You can expand this by adding more BrowserMatchNoCase
  # statements to block evil browser agents trying the impossible
  # task of mirroring a twiki
  # Example:
  # BrowserMatchNoCase ^SiteSucker anonymous_spider
  BrowserMatchNoCase ^$ anonymous_spider

  <Directory "/usr/lib/cgi-bin/twiki">
    Options +ExecCGI FollowSymLinks
    SetHandler cgi-script
    Order Allow,Deny
    Allow from all
    Deny from env=anonymous_spider
  </Directory>

  # The other dirs should not be visible to the web at all,
  # but just to be safe: deny from all

  <Directory "/var/lib/twiki/data">
    deny from all
  </Directory>

  <Directory "/var/lib/twiki/templates">
    deny from all
  </Directory>

  <Directory "/var/lib/twiki/lib">
    deny from all
  </Directory>

  <Directory "/var/lib/twiki/tools">
    deny from all
  </Directory>

  <Directory "/var/lib/twiki/locale">
    deny from all
  </Directory>

  # This is the ShorterURL stuff as found in
  # http://wiki.boum.org/TechStdOut/BoumTWikiSetup
  <IfModule mod_rewrite.c>
    RewriteEngine On

    #/ displays homepage
    RewriteRule ^/$ /twiki/bin/view/Public/WebHome [PT]

    # Nicer, and to prevent anyone to bypass the
    # following redirect
    RewriteRule ^/twiki/bin/(.*) /$1 [R=permanent,L]

    # Scripts that need to be authentificated can
    # *only* be accessed via httpS
    RewriteRule ^/(viewauth|edit|preview|save|attach|upload|rename|rdiffauth|manage|installpasswd|logon|logout)(.*)    https://%{SERVER_NAME}/$1$2 [R,L]

    # !!! ATTENTION !!!
    # This rules assume, webs AND topics each starting with a caps

    # if (URL begins with a caps) then
    #   rewrite /twiki/bin/view/URL and stop
    # end if
    # if (URL begins with view) then
    #   redirect to Web/Topic without view and stop
    # end if
    # if (URL begins with a script) then
    #   rewrite /twiki/bin/URL
    # end if

    RewriteRule ^/([[:upper:]].*) /twiki/bin/view/$1 [PT]
    RewriteRule ^/([[:upper:]].*) /twiki/bin/view/$1 [PT]
    RewriteRule ^/view/(.*) /$1 [R=permanent,L]

    RewriteCond /usr/lib/cgi-bin/twiki/$1 -f
    RewriteRule ^/([a-z]+)(.*) /twiki/bin/$1$2 [PT]
  </IfModule>
</VirtualHost>

Und der HTTPS-VirtualHost:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<VirtualHost _default_:443>
  SSLEngine On
  SSLCertificateFile /etc/apache2/ssl/apache.pem

  ServerName www.example.com
  ServerAdmin admin@example.com

  DocumentRoot /var/www/twiki
  ScriptAlias /twiki/bin/ "/usr/lib/cgi-bin/twiki/"
  Alias /twiki/ "/var/www/twiki/"

  # We set an environment variable called anonymous_spider
  # Setting a BrowserMatchNoCase to ^$ is important. It prevents
  # TWiki fromincluding its own topics as URLs and also prevents
  # other TWikis from doing the same. This is important to
  # prevent the most obvious Denial of Service attacks.
  # You can expand this by adding more BrowserMatchNoCase
  # statements to block evil browser agents trying the impossible
  # task of mirroring a twiki
  # Example:
  # BrowserMatchNoCase ^SiteSucker anonymous_spider
  BrowserMatchNoCase ^$ anonymous_spider

  <Directory "/usr/lib/cgi-bin/twiki">
    Options +ExecCGI FollowSymLinks
    SetHandler cgi-script
    Order Allow,Deny
    Allow from all
    Deny from env=anonymous_spider
  </Directory>

  # This is the ShorterURL stuff as found in
  # http://wiki.boum.org/TechStdOut/BoumTWikiSetup
  <IfModule mod_rewrite.c>
    RewriteEngine On

    # / displays homepage
    RewriteRule ^/$ /twiki/bin/view/Main/WebHome [PT]

    # if (URL begins with a caps) then
    #   rewrite /twiki/bin/view/URL and stop
    # end if
    # if (URL begins with view) then
    #   redirect to Web/Topic without view and stop
    # end if
    # if (URL begins with a script) then
    #   rewrite /twiki/bin/URL
    # end if

    RewriteRule ^/([[:upper:]].*) /twiki/bin/view/$1 [PT]
    RewriteRule ^/view/(.*) /$1 [R=permanent,L]

    RewriteCond /usr/lib/cgi-bin/twiki/$1 -f
    RewriteRule ^/([a-z]+)(.*) /twiki/bin/$1$2 [PT]
  </IfModule>
</VirtualHost>

TWiki-Konfiguration

Editiere die Datei /var/lib/twiki/lib/LocalSite.cfg und nimm darin die folgenden Einstellungen vor. Der Hostname ist dabei durch den DNS-Namen der Maschine zu ersetzen.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
$cfg{ScriptUrlPath} = '';
$TWiki::cfg{ScriptUrlPaths}{view} = 'http://www.example.com';
$TWiki::cfg{ScriptUrlPaths}{login} = 'https://www.example.com/login';
$TWiki::cfg{ScriptUrlPaths}{logon} = 'https://www.example.com/logon';
$TWiki::cfg{ScriptUrlPaths}{logout} = 'https://www.example.com/logout';
$TWiki::cfg{ScriptUrlPaths}{viewauth} = 'https://www.example.com/viewauth';
$TWiki::cfg{ScriptUrlPaths}{edit} = 'https://www.example.com/edit';
$TWiki::cfg{ScriptUrlPaths}{preview} = 'https://www.example.com/preview';
$TWiki::cfg{ScriptUrlPaths}{save} = 'https://www.example.com/save';
$TWiki::cfg{ScriptUrlPaths}{attach} = 'https://www.example.com/attach';
$TWiki::cfg{ScriptUrlPaths}{upload} = 'https://www.example.com/upload';
$TWiki::cfg{ScriptUrlPaths}{rename} = 'https://www.example.com/rename';
$TWiki::cfg{ScriptUrlPaths}{rdiffauth} = 'https://www.example.com/rdiffauth';
$TWiki::cfg{ScriptUrlPaths}{manage} = 'https://www.example.com/manage';
$TWiki::cfg{ScriptUrlPaths}{installpasswd} = 'https://www.example.com/installpasswd';

$TWiki::cfg{LoginManager} = 'TWiki::Client::TemplateLogin';

Die Patches

Leider verwendet der Pattern-Skin, der standardmäßig von TWiki verwendet wird einen fehlerhaften Mechanismus, um die URLs zu generieren. Darum müssen wir patchen.

1
2
3
4
5
cd /var/lib/twiki
find templates -name '*.tmpl' -exec perl -pi -e 's,%SCRIPTURL%/view%SCRIPTSUFFIX%,%SCRIPTURL{\"view\"%,g' {} \;
find templates -name '*.tmpl' -exec perl -pi -e 's,%SCRIPTURLPATH%/login%SCRIPTSUFFIX%,%SCRIPTURLPATH{\"login\"%,g' {} \;
find templates -name '*.tmpl' -exec perl -pi -e 's,%SCRIPTURLPATH%/edit%SCRIPTSUFFIX%,%SCRIPTURLPATH{\"edit\"%,g' {} \;
find templates -name '*.tmpl' -exec perl -pi -e 's,%SCRIPTURLPATH%/attach%SCRIPTSUFFIX%,%SCRIPTURLPATH{\"attach\"%,g' {} \;

To Do

  • Im https-Modus werden einige Daten über http geladen. Der Benutzer erhält dadurch möglicherweise eine Warnung vom Browser.
  • Topics eines ausgewählten Webs sollten auch ohne Angabe des Webs ansprechbar sein.
  • Möglicherweise sind noch Stellen im Pattern-Skin, an denen die URLs noch nicht korrekt gebildet werden.
meine erde