import torrus 1.0.9
[freeside.git] / torrus / perllib / Torrus / ACL / Export.pm
1 #  Copyright (C) 2002  Stanislav Sinyagin
2 #
3 #  This program is free software; you can redistribute it and/or modify
4 #  it under the terms of the GNU General Public License as published by
5 #  the Free Software Foundation; either version 2 of the License, or
6 #  (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software
15 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
16
17 # $Id: Export.pm,v 1.1 2010-12-27 00:03:59 ivan Exp $
18 # Stanislav Sinyagin <ssinyagin@yahoo.com>
19
20
21 package Torrus::ACL::Export;
22
23 use Torrus::ACL;
24 use Torrus::ACL::Edit;
25 use Torrus::Log;
26
27 use Template;
28
29 use strict;
30
31
32 sub exportACL
33 {
34     my $self = shift;
35     my $exportfile = shift;
36     my $exporttemplate = shift;
37
38     my $tt = new Template(INCLUDE_PATH => $Torrus::Global::templateDirs,
39                           TRIM => 1);
40
41     my $vars = {
42         'groups'      => sub { return $self->listGroups(); },
43         'users'       => sub { return $self->listUsers(); },
44         'memberof'    => sub { return $self->memberOf($_[0]); },
45         'uattrlist'   => sub { return $self->listUserAttributes($_[0]); },
46         'uattr'       => sub { return $self->userAttribute($_[0], $_[1]); },
47         'gattrlist'   => sub { return $self->listGroupAttributes($_[0]); },
48         'gattr'       => sub { return $self->groupAttribute($_[0], $_[1]); },
49         'privileges'  => sub { return $self->listPrivileges($_[0]); },
50         'version'    => $Torrus::Global::version,
51         'xmlnorm'     => \&xmlnormalize
52         };
53
54     my $ok = $tt->process($exporttemplate, $vars, $exportfile);
55
56     if( not $ok )
57     {
58         print STDERR "Error while processing template: ".$tt->error()."\n";
59     }
60     else
61     {
62         Info('Wrote ' . $exportfile);
63     }
64
65     return $ok;
66 }
67
68
69 sub xmlnormalize
70 {
71     my( $txt )= @_;
72
73     $txt =~ s/\&/\&amp\;/gm;
74     $txt =~ s/\</\&lt\;/gm;
75     $txt =~ s/\>/\&gt\;/gm;
76     $txt =~ s/\'/\&apos\;/gm;
77     $txt =~ s/\"/\&quot\;/gm;
78
79     return $txt;
80 }
81
82
83
84 1;
85
86
87 # Local Variables:
88 # mode: perl
89 # indent-tabs-mode: nil
90 # perl-indent-level: 4
91 # End: