]>
git.proxmox.com Git - pmg-api.git/blob - PMG/RuleDB/Object.pm
1 package PMG
:: RuleDB
:: Object
;
11 my ( $type, $otype, $ogroup ) = @_ ;
26 die "never call this method: ERROR" ;
30 my ( $self, $param ) = @_ ;
32 die "never call this method: ERROR" ;
36 die "never call this method: ERROR" ;
40 die "never call this method: ERROR" ;
44 die "never call this method: ERROR" ;
48 die "never call this method: ERROR" ;
52 die "never call this method: ERROR" ;
89 # some who object only matches 'receivers'
95 die "never call this method: ERROR" ;
105 return "basic object" ;
109 die "never call this method: ERROR" ;
121 my $data = $self -> get () // {};
123 $data ->{ id
} = $self ->{ id
};
124 $data ->{ ogroup
} = $self ->{ ogroup
};
125 $data ->{ otype
} = $self -> otype ();
126 $data ->{ otype_text
} = $self -> otype_text ();
127 $data ->{ receivertest
} = $self -> receivertest ();
128 $data ->{ descr
} = $self -> short_desc ();
134 my ( $class, $apiclass, $name, $path, $use_greylist_gid ) = @_ ;
138 my $otype = $class -> otype ();
140 my $otype_text = $class -> otype_text ();
142 my $properties = $class -> properties ();
144 my $create_properties = {};
145 my $update_properties = {
147 description
=> "Object ID." ,
151 my $read_properties = {
153 description
=> "Object ID." ,
158 if (! $use_greylist_gid ) {
159 $read_properties ->{ ogroup
} = $create_properties ->{ ogroup
} = $update_properties ->{ ogroup
} = {
160 description
=> "Object Groups ID." ,
165 foreach my $key ( keys %$properties ) {
166 $create_properties ->{ $key } = $properties ->{ $key };
167 $update_properties ->{ $key } = $properties ->{ $key };
170 $apiclass -> register_method ({
174 description
=> "Add ' $otype_text ' object." ,
178 additionalProperties
=> 0 ,
179 properties
=> $create_properties,
182 description
=> "The object ID." ,
188 my $rdb = PMG
:: RuleDB-
> new ();
190 my $gid = $use_greylist_gid ?
191 $rdb -> greylistexclusion_groupid () : $param ->{ ogroup
};
193 my $obj = $rdb -> get_object ( $otype );
194 $obj ->{ ogroup
} = $gid ;
196 $obj -> update ( $param );
198 my $id = $obj -> save ( $rdb );
200 if ( $use_greylist_gid ) {
201 PMG
:: DBTools
:: reload_ruledb
( $rdb );
203 PMG
:: DBTools
:: reload_ruledb
();
209 $apiclass -> register_method ({
210 name
=> "read_ $name " ,
211 path
=> " $path/ {id}" ,
213 description
=> "Read ' $otype_text ' object settings." ,
216 additionalProperties
=> 0 ,
217 properties
=> $read_properties,
222 id
=> { type
=> 'integer' },
228 my $rdb = PMG
:: RuleDB-
> new ();
230 my $gid = $use_greylist_gid ?
231 $rdb -> greylistexclusion_groupid () : $param ->{ ogroup
};
233 my $obj = $rdb -> load_object_full ( $param ->{ id
}, $gid, $otype );
235 return $obj -> get_data ();
238 $apiclass -> register_method ({
239 name
=> "update_ $name " ,
240 path
=> " $path/ {id}" ,
242 description
=> "Update ' $otype_text ' object." ,
246 additionalProperties
=> 0 ,
247 properties
=> $update_properties,
249 returns
=> { type
=> 'null' },
253 my $rdb = PMG
:: RuleDB-
> new ();
255 my $gid = $use_greylist_gid ?
256 $rdb -> greylistexclusion_groupid () : $param ->{ ogroup
};
258 my $obj = $rdb -> load_object_full ( $param ->{ id
}, $gid, $otype );
260 $obj -> update ( $param );
264 if ( $use_greylist_gid ) {
265 PMG
:: DBTools
:: reload_ruledb
( $rdb );
267 PMG
:: DBTools
:: reload_ruledb
();
279 =head1 PMG::RuleDB::Object
281 The Proxmox Rules consists of Objects. There are several classes of Objects. Ech such class has a method to check if the object 'matches'.
283 =head2 WHO Objects ($obj->oclass() eq 'who')
285 Who sent the mail, who is the receiver?
287 =head3 $obj->who_match ($addr)
289 Returns true if $addr belongs to this objects. $addr is a text string representing the email address you want to check.
295 EMail: the only attribute is a regex to test email addresses
299 =head2 WHEN Objects ($obj->oclass() eq 'when')
301 Used to test for a certain daytime
303 =head3 $obj->when_match ($time)
305 Return true if $time matches the when object constraints. $time is an integer like returned by the time() system call (or generated with POSIX::mktime()).
311 TimeFrame: specifies a start and a end time
315 =head2 WHAT Objects ($obj->oclass() eq 'what')
319 =head2 ACTION Objects ($obj->oclass() eq 'action')
321 actions which can be executed
323 =head3 $obj->execute ($mod_group, $queue, $ruledb, $mod_group, $targets, $msginfo, $vars, $marks)
325 Execute the action code. $target is a array reference containing all
328 =head2 Common Methods
330 =head3 $obj->oclass()
332 Returns 'who', 'when' 'what' or 'action';
334 =head3 $obj->short_desc()
336 Returns a short text describing the contents of the object. This is used
337 for debugging purposes.
341 Returns an integer representing the Type of the objects. This integer
342 is used in the database to uniquely identify object types.
346 Returns the unique database ID of the object. undef means the object is not jet stored in the databse.
350 Return true if the object is an action and the action is final, i.e. the action stops further rule processing for all matching targets.
352 =head3 $obj->priority()
354 Return a priority between 0 and 100. This is currently used to sort action objects by priority.