/
if_mm.coretag
195 lines (180 loc) · 4.89 KB
/
if_mm.coretag
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# Copyright 2002-2007 Interchange Development Group and others
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: if_mm.coretag,v 1.6 2007-03-30 23:40:54 pajamian Exp $
UserTag if-mm Order function name
UserTag if-mm addAttr
UserTag if-mm attrAlias key name
UserTag if-mm hasEndTag
UserTag if-mm Version $Revision: 1.6 $
UserTag if-mm Routine <<EOR
sub {
my($func, $field, $opt, $text) = @_;
my $record;
my $status;
my $reverse;
$reverse = $func =~ s/^\s*!\s*//;
my $extended = '';
$extended = $1 if $field =~ s/(=.*)//;
my ($group, @groups);
$text = 1 if ! $text;
CHECKIT: {
if ($group or ! ($record = $Vend::UI_entry) ) {
$record = ui_acl_enabled($group);
if ( ! ref $record) {
$status = $record;
last CHECKIT;
}
}
($status = 0, last CHECKIT) if ! UI::Primitive::is_logged();
($status = 1, last CHECKIT) if $record->{super};
$func = lc $func;
($status = 1, last CHECKIT) if $func eq 'logged_in';
my %acl_func = qw/
fields fields
field fields
columns fields
column fields
col fields
row keys
rows keys
key keys
keys keys
owner_field owner_field
owner owner_field
/;
my %file_func = qw/
page pages
file files
pages pages
files files
/;
my %bool_func = qw/
config 1
reconfig 1
/;
my %paranoid = qw/
mml 1
sql 1
report 1
add_delete 1
add_field 1
journal_update 1
/;
my %yesno_func = qw/
functions functions
advanced functions
tables tables
table tables
/;
my %prefix_func = qw/
filematch files
pagematch pages
/;
my $table = $CGI::values{mv_data_table} || $::Values->{mv_data_table};
if($yesno_func{$func} eq 'tables') {
$opt->{table} = $field if ! $opt->{table};
$opt->{table} =~ s/^=/$table/;
}
elsif($yesno_func{$func} eq 'functions') {
$opt->{table} = $field;
}
$table = $opt->{table} || $table;
my $acl;
my $check;
$status = 0, last CHECKIT if $func eq 'super';
if($check = $file_func{$func}) {
$status = 1, last CHECKIT unless $record->{$check};
my $file = $field || $Global::Variable->{MV_PAGE};
# strip trailing slashes for checks on directories
$file =~ s%/+$%%;
#::logDebug("check=$check file=$file record=$record->{$check} prefix=$opt->{prefix}");
my @files = UI::Primitive::list_glob($record->{$check}, $opt->{prefix});
#::logDebug("check yielded files=" . join(",", @files));
if(! @files) {
$status = '';
last CHECKIT;
}
$status = ui_check_acl("$file$extended", join(" ", @files));
#::logDebug("check status=$status");
last CHECKIT;
}
if($check = $prefix_func{$func}) {
$status = '', last CHECKIT unless $record->{$check};
my $file = $field;
# strip trailing slashes for checks on directories
#::logDebug("check=$check file=$file record=$record->{$check}");
my @allow = split /\s+/, $record->{$check};
$status = '';
for(@allow) {
#::logDebug("check file=$file against allow=$_");
if(s/^\!//) {
if ($file =~ /^$_/) {
#::logDebug("denied based on $_");
$status = '';
last CHECKIT;
}
}
else {
next unless $file =~ /^$_\b/;
$status = 1;
}
}
#::logDebug("check Yielded status=$status");
last CHECKIT;
}
if($bool_func{$func} ) {
$status = $record->{$func};
last CHECKIT;
}
if($check = $yesno_func{$func} ) {
my $v;
if($v = $record->{"yes_$check"}) {
$status = ui_check_acl("$table$extended", $v);
}
else {
$status = 1;
}
if($v = $record->{"no_$check"}) {
$status &&= ! ui_check_acl("$table$extended", $v);
}
last CHECKIT;
}
if(! ($check = $acl_func{$func}) ) {
my $default = $func =~ /^no_/ ? 0 : 1;
$status = $default, last CHECKIT unless $record->{$func};
$status = ui_check_acl("$table$extended", $record->{$func});
last CHECKIT;
}
# Now it is definitely a job for table_control;
$acl = UI::Primitive::get_ui_table_acl($table);
$status = 1, last CHECKIT unless $acl;
my $val;
if($acl->{owner_field} and $check eq 'keys') {
$status = ::tag_data($table, $acl->{owner_field}, $field)
eq $Vend::username;
last CHECKIT;
}
elsif ($check eq 'owner_field') {
$status = length $acl->{owner_field};
last CHECKIT;
}
$status = UI::Primitive::ui_acl_atom($acl, $check, $field);
}
if(! $status and $record and (@groups or $record->{groups}) ) {
goto CHECKIT if $group = shift @groups;
(@groups) = grep /\S/, split /[\0,\s]+/, $record->{groups};
($group, @groups) = map { s/^/:/; $_ } @groups;
goto CHECKIT;
}
return $status
? (
Vend::Interpolate::pull_if($text, $reverse)
)
: Vend::Interpolate::pull_else($text, $reverse);
}
EOR