#!/usr/bin/perl -s our $force; use warnings; use strict; use File::Copy; use File::Slurp qw/slurp/; unless (@ARGV == 1) { die "Usage: mabc_wiki_setup \n"; } # sanity checks my $WIKIROOT = shift; unless (-e $WIKIROOT) { die "Can't find path: $WIKIROOT\n"; } unless (-w $WIKIROOT) { die "Can't write on $WIKIROOT\n"; } mkdir("/tmp/multiabc"); chmod(0777,"/tmp/multiabc"); # chdir and create files chdir $WIKIROOT; my $perl = `which perl`; chomp $perl; my $mabc_build = `which mabc_build`; chomp $mabc_build; my $mabc_init_proj = `which mabc_init_proj`; chomp $mabc_init_proj; my $mabc_hsexec = `which mabc_hsexec`; chomp $mabc_hsexec; my %vars = ( wikiroot => $WIKIROOT, perl => $perl, mabc_build => $mabc_build, mabc_build_proj => $mabc_build, mabc_init_proj => $mabc_init_proj, mabc_hsexec => $mabc_hsexec, ); my @files = __create_files(); my @cleanup; # fix permissions my @stat = stat('.'); my $uid = $stat[4]; my $gid = $stat[5]; chown $uid, $gid, @files; # apply patch if needed my $content = slurp('conf/dokuwiki.php'); $content =~ m/\$conf\[\'htmlok\'\]\s*=\s*(\d)+\s*;/; if ($1 == 1) { print "Patching wiki config not required.\n"; } else { print `/usr/bin/patch -p0 < dokuwiki_conf_htmlok.patch`; } push @cleanup, "dokuwiki_conf_htmlok.patch"; # create multiabc namespace and index page unless (-e 'data/pages/multiabc') { mkdir 'data/pages/multiabc'; @stat = stat('data/pages'); $uid = $stat[4]; $gid = $stat[5]; chown $uid, $gid, 'data/pages/multiabc'; } unless (-e 'data/pages/multiabc/index.txt') { move("multiabc_index.txt", 'data/pages/multiabc/index.txt'); @stat = stat('data/pages'); $uid = $stat[4]; $gid = $stat[5]; chown $uid, $gid, 'data/pages/multiabc/index.txt'; } # done unlink @cleanup; print "All done!\n"; sub __create_files { my $fh; my $filename; my @files; while () { if ($_ =~ m/\-\-\-\-([\w\.]+)\-\-\-\-/) { $filename = $1; close $fh if $fh; open $fh, '>', $filename; push @files, $filename; } else { $_ =~ s/\[% (\w+) %\]/$vars{$1}/ge; print $fh $_; } } return @files; } __DATA__ ----mabc_handler.php---- &1 > /tmp/build_multi.pl.log"); header("Location: ".$_SERVER['HTTP_REFERER']); break; case 'init_proj': $name = $_POST['name']; $name = escapeshellcmd($name); $c = "sections=0\nparts=0\nT=\"$name\"\npages=1\nbar=26\nstaves=\"\"\noriginal=\"\"\n%%\n[%voice_def%]\nT: [%T%]\nT: [%part_number%]\nC:\"AnĂ³nimo\"\nM:3/4\nL:1/4\nK:C\n%\nZ[%bar%] |]\n"; $c = "name=\"$name\"\n" . $c; $fh = fopen("/tmp/multiabc/auto_init.pabc", "w"); fwrite($fh, $c); fclose($fh); system("[% perl %] [% mabc_init_proj %] [% wikiroot %] /tmp/multiabc/auto_init.pabc 2>&1 > /tmp/init_multi.pl.log"); header("Location: ./doku.php?id=$name:index"); break; case 'recalc_proj': $project = $_GET['id']; $project = escapeshellcmd($project); $conf_file = $_SERVER['SCRIPT_FILENAME']; $conf_file = str_replace('mabc_handler.php', '', $conf_file); $conf_file .= "/data/pages/$project/conf.txt"; $content = file_get_contents($conf_file); $matches = array(); $pattern = '/(.*)<\/code>/s'; preg_match($pattern, $content, $matches); $final = $matches[0]; $final = str_replace('', '', $final); $final = str_replace('', '', $final); file_put_contents("/tmp/multiabc/auto_update_proj.pabc", $final); system("[% perl %] [% mabc_init_proj %] [% wikiroot %] /tmp/multiabc/auto_update_proj.pabc 2>&1 > /tmp/init_proj.pl.log"); header("Location: ".$_SERVER['HTTP_REFERER']); break; case 'build': $project = $_GET['id']; $project = escapeshellcmd($project); $target = $_GET['target']; $target = escapeshellcmd($target); $source = $_GET['source']; $source = escapeshellcmd($source); $filename = system("[% perl %] [% mabc_build %] -$target $project $source"); $filename = trim($filename); header("Location: /wiki-score/files/$filename"); break; case 'column': $project = $_GET['id']; $project = escapeshellcmd($project); $c = $_GET['c']; $c = escapeshellcmd($c); $extra = $_GET['extra']; $extra = escapeshellcmd($extra); header('Content-type: text/html; charset=utf-8'); system("[% perl %] [% mabc_hsexec %] [% wikiroot %] column $project $c $extra"); break; case 'row': $project = $_GET['id']; $project = escapeshellcmd($project); $r = $_GET['r']; $r = escapeshellcmd($r); $extra = $_GET['extra']; $extra = escapeshellcmd($extra); header('Content-type: text/html; charset=utf-8'); system("[% perl %] [% mabc_hsexec %] [% wikiroot %] row $project $r $extra"); break; case 'all': $project = $_GET['id']; $project = escapeshellcmd($project); header('Content-type: text/html; charset=utf-8'); system("[% perl %] [% mabc_hsexec %] [% wikiroot %] all $project"); break; } } else { // no action provided header("Location: ".$_SERVER['HTTP_REFERER']); } ?> ----dokuwiki_conf_htmlok.patch---- --- conf/dokuwiki.php.orig 2011-03-30 15:30:09.000000000 +0100 +++ conf/dokuwiki.php 2011-03-28 16:43:07.000000000 +0100 @@ -32,7 +32,7 @@ $conf['breadcrumbs'] = 10; //how many recent visited pages to show $conf['youarehere'] = 0; //show "You are here" navigation? 0|1 $conf['typography'] = 1; //smartquote conversion 0=off, 1=doublequotes, 2=all quotes -$conf['htmlok'] = 0; //may raw HTML be embedded? This may break layout and XHTML validity 0|1 +$conf['htmlok'] = 1; //may raw HTML be embedded? This may break layout and XHTML validity 0|1 $conf['phpok'] = 0; //may PHP code be embedded? Never do this on the internet! 0|1 $conf['dformat'] = '%Y/%m/%d %H:%M'; //dateformat accepted by PHPs strftime() function $conf['signature'] = ' --- //[[@MAIL@|@NAME@]] @DATE@//'; //signature see wiki:config for details ----multiabc_index.txt----
Project Name: