6 use lib '/data/WebGUI/lib/';
11 webgui.pl - mount WebGUI templates as filesystem
15 webgui.pl /data/WebGUI/etc/webgui.conf /mnt
19 With this script, you can utilize C<Fuse> and C<Fuse::DBI> modules to mount
20 templates from WebGUI and edit them using command-line utilities (like C<vi>
23 It will present templates in WebGUI as directory tree consisting of
24 directories (which represent template's namespace) and files (which are
25 templates from database). If template name has slash (C</>) in name, deeper
26 directories will be created.
28 Template files will have correct lengths and write permissions which are
29 specified in WebGUI database.
33 C<Fuse::DBI> module (which is core of this utility) uses C<Fuse> perl
34 bindings. Perl bindings are rather new addition to C<Fuse>, so
35 you will need recent CVS version of C<Fuse>. Current stable version doesn't
36 include perl binding, so you will probably have to compile C<Fuse> yourself
37 (see FUSE documentation for details about compilation and installation).
39 After compilation and installation of C<fuse> kernel module and C<Fuse> perl
40 bindings for it, you will have to load C<fuse> module into kernel. For that,
41 you will have to be root. If you are not administrator on particular
42 machine, ask your admin to install and load C<fuse> module for you.
44 If you used C<fusermount> command before running this script, module will be
47 =head2 unsupported operations
49 There is no support for creation of new templates, renaming, or deleting.
50 Although those operations map nicely to file system semantics there are still
51 possible only using WebGUI web interface.
53 =head2 unlink to invalidate cache
55 Unlink command (C<rm>) is implemented on files with special function: it
56 will remove in-memory cache of particular template and reload it from
57 database. That enables usage of web interface to make small changes and then
58 continuing editing using this script without restarting it.
60 In-memory cache is populated with data about available templates when you
61 start this script. Currently only way to refresh template list (after you
62 create copy of template through web interface) is to remove directory using
63 C<rmdir> or C<rm -rf>.
65 B<Don't panic!> Destructive operations in filesystem (C<rm> and C<rmdir>)
66 just invalidate in-memory cache and re-read data from database (this will
67 also change ctime of file, so your editor will probably notice that file has
70 In-memory cache is used to speed up operations like grep on templates. If it
71 wasn't there, grep wouldn't be useful at all. I think this is acceptable
74 =head2 invalidating of on-disk templates
76 Every write operation will erase all templates on disk (so that next reload
77 on browser will show your changes). It would be better if just changed
78 template is erased, but this works well enough. You might notice performance
79 penalty of this simplification if you are running very loaded production
82 You have to have write permission on C<uploads/temp/templates/> directory
83 for your WebGUI instance for this to work. If you don't C<Fuse::DBI> will
86 =head2 supported databases
88 This script have embedded SQL queries for MySQL and PostgreSQL. Other databases
89 could be supported easily. Contributions are welcomed.
91 =head2 database transactions
93 C<Fuse::DBI> uses transactions (if your database supports them) to prevent
94 accidental corruption of data by reading old version. Depending on type of
95 database back-end, MySQL users might be out of luck.
97 =head2 recovering from errors
99 B<Transport endpoint is not connected> is very often error when Fuse perl
100 bindings exit without clean umount (through C<Fuse::DBI> C<umount> method or
101 with C<fusermount -u /mnt> command).
103 This script will automatically run C<fusermount -u /mnt> if it receives
104 above error on startup. If it fails, mount point is still in use (that
105 happens if you changed directory to mount point in other shell). Solution is
106 simple, just change directory in other back to C<$HOME> (with just C<cd>)
107 and re-run this script.
109 =head2 missing Data::Config
111 If this script complains about missing C<Data::Config> module, you will have
112 to point path at top which points to lib directory of WebGUI installation.
113 By default it points to C</data/WebGUI>:
115 use lib '/data/WebGUI/lib/';
119 my ($config_file,$mount) = @ARGV;
121 unless ($config_file && $mount) {
122 print STDERR <<_USAGE_;
123 usage: $0 /data/WebGUI/etc/webgui.conf /mnt
125 For more information see perldoc webgui.pl
130 system "fusermount -u $mount" unless (-w $mount);
133 print STDERR "Current user doesn't have permission on mount point $mount: $!";
137 my $config = new Data::Config $config_file || "can't open config $config_file: $!";
144 namespace||'/'||name||' ['||oid||']' as filename,
145 length(template) as size,
146 iseditable as writable
163 concat(templateid,name) as id,
164 concat(namespace,'/',name,'.html') as filename,
165 length(template) as size,
166 iseditable as writable
172 where concat(templateid,name) = ?;
177 where concat(templateid,name) = ?;
182 my $dsn = $config->param('dsn');
185 if ($dsn =~ m/DBI:(mysql|pg):/i) {
188 print STDERR "can't find supported database (mysql/pg) in dsn: $dsn\n";
192 my $template_dir = $config->param('uploadsPath') . '/temp/templates/';
194 print "using database '$db', template dir '$template_dir' and mountpoint $mount\n";
196 my $mnt = Fuse::DBI->mount({
197 filenames => $sql->{$db}->{'filenames'},
198 read => $sql->{$db}->{'read'},
199 update => $sql->{$db}->{'update'},
200 dsn => $config->param('dsn'),
201 user => $config->param('dbuser'),
202 password => $config->param('dbpass'),
206 print STDERR "invalidating content in $template_dir\n";
207 opendir(DIR, $template_dir) || die "can't opendir $template_dir: $!";
208 map { unlink "$template_dir/$_" || warn "can't remove $template_dir/$_: $!" } grep { !/^\./ && -f "$template_dir/$_" } readdir(DIR);
214 print STDERR "can't mount filesystem!";
218 print "Press enter to exit...";
226 L<http://www.rot13.org/~dpavlin/fuse_dbi.html>
228 C<FUSE (Filesystem in USErspace)> website
229 L<http://fuse.sourceforge.net/>
233 Dobrica Pavlinusic, E<lt>dpavlin@rot13.orgE<gt>
235 =head1 COPYRIGHT AND LICENSE
237 Copyright (C) 2004 by Dobrica Pavlinusic
239 This library is free software; you can redistribute it and/or modify
240 it under the same terms as Perl itself, either Perl version 5.8.4 or,
241 at your option, any later version of Perl 5 you may have available.