]>
git.proxmox.com Git - pmg-api.git/blob - src/PMG/RuleDB/Object.pm
32c9dcbebe5dccf5473ee4dda34aad94c70f5d83
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." ,
177 permissions
=> { check
=> [ 'admin' ] },
179 additionalProperties
=> 0 ,
180 properties
=> $create_properties,
183 description
=> "The object ID." ,
189 my $rdb = PMG
:: RuleDB-
> new ();
191 my $gid = $use_greylist_gid ?
192 $rdb -> greylistexclusion_groupid () : $param ->{ ogroup
};
194 my $obj = $rdb -> get_object ( $otype );
195 $obj ->{ ogroup
} = $gid ;
197 $obj -> update ( $param );
199 my $id = $obj -> save ( $rdb );
201 if ( $use_greylist_gid ) {
202 PMG
:: DBTools
:: reload_ruledb
( $rdb );
204 PMG
:: DBTools
:: reload_ruledb
();
210 $apiclass -> register_method ({
211 name
=> "read_ $name " ,
212 path
=> " $path/ {id}" ,
214 description
=> "Read ' $otype_text ' object settings." ,
216 permissions
=> { check
=> [ 'admin' , 'audit' ] },
218 additionalProperties
=> 0 ,
219 properties
=> $read_properties,
224 id
=> { type
=> 'integer' },
230 my $rdb = PMG
:: RuleDB-
> new ();
232 my $gid = $use_greylist_gid ?
233 $rdb -> greylistexclusion_groupid () : $param ->{ ogroup
};
235 my $obj = $rdb -> load_object_full ( $param ->{ id
}, $gid, $otype );
237 return $obj -> get_data ();
240 $apiclass -> register_method ({
241 name
=> "update_ $name " ,
242 path
=> " $path/ {id}" ,
244 description
=> "Update ' $otype_text ' object." ,
246 permissions
=> { check
=> [ 'admin' ] },
249 additionalProperties
=> 0 ,
250 properties
=> $update_properties,
252 returns
=> { type
=> 'null' },
256 my $rdb = PMG
:: RuleDB-
> new ();
258 my $gid = $use_greylist_gid ?
259 $rdb -> greylistexclusion_groupid () : $param ->{ ogroup
};
261 my $obj = $rdb -> load_object_full ( $param ->{ id
}, $gid, $otype );
263 $obj -> update ( $param );
267 if ( $use_greylist_gid ) {
268 PMG
:: DBTools
:: reload_ruledb
( $rdb );
270 PMG
:: DBTools
:: reload_ruledb
();
282 =head1 PMG::RuleDB::Object
284 The Proxmox Rules consists of Objects. There are several classes of Objects. Ech such class has a method to check if the object 'matches'.
286 =head2 WHO Objects ($obj->oclass() eq 'who')
288 Who sent the mail, who is the receiver?
290 =head3 $obj->who_match ($addr)
292 Returns true if $addr belongs to this objects. $addr is a text string representing the email address you want to check.
298 EMail: the only attribute is a regex to test email addresses
302 =head2 WHEN Objects ($obj->oclass() eq 'when')
304 Used to test for a certain daytime
306 =head3 $obj->when_match ($time)
308 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()).
314 TimeFrame: specifies a start and a end time
318 =head2 WHAT Objects ($obj->oclass() eq 'what')
322 =head2 ACTION Objects ($obj->oclass() eq 'action')
324 actions which can be executed
326 =head3 $obj->execute ($mod_group, $queue, $ruledb, $mod_group, $targets, $msginfo, $vars, $marks)
328 Execute the action code. $target is a array reference containing all
331 =head2 Common Methods
333 =head3 $obj->oclass()
335 Returns 'who', 'when' 'what' or 'action';
337 =head3 $obj->short_desc()
339 Returns a short text describing the contents of the object. This is used
340 for debugging purposes.
344 Returns an integer representing the Type of the objects. This integer
345 is used in the database to uniquely identify object types.
349 Returns the unique database ID of the object. undef means the object is not jet stored in the databse.
353 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.
355 =head3 $obj->priority()
357 Return a priority between 0 and 100. This is currently used to sort action objects by priority.