]>
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 PMG
:: DBTools
:: reload_ruledb
();
205 $apiclass -> register_method ({
206 name
=> "read_ $name " ,
207 path
=> " $path/ {id}" ,
209 description
=> "Read ' $otype_text ' object settings." ,
212 additionalProperties
=> 0 ,
213 properties
=> $read_properties,
218 id
=> { type
=> 'integer' },
224 my $rdb = PMG
:: RuleDB-
> new ();
226 my $gid = $use_greylist_gid ?
227 $rdb -> greylistexclusion_groupid () : $param ->{ ogroup
};
229 my $obj = $rdb -> load_object_full ( $param ->{ id
}, $gid, $otype );
231 return $obj -> get_data ();
234 $apiclass -> register_method ({
235 name
=> "update_ $name " ,
236 path
=> " $path/ {id}" ,
238 description
=> "Update ' $otype_text ' object." ,
242 additionalProperties
=> 0 ,
243 properties
=> $update_properties,
245 returns
=> { type
=> 'null' },
249 my $rdb = PMG
:: RuleDB-
> new ();
251 my $gid = $use_greylist_gid ?
252 $rdb -> greylistexclusion_groupid () : $param ->{ ogroup
};
254 my $obj = $rdb -> load_object_full ( $param ->{ id
}, $gid, $otype );
256 $obj -> update ( $param );
260 PMG
:: DBTools
:: reload_ruledb
();
271 =head1 PMG::RuleDB::Object
273 The Proxmox Rules consists of Objects. There are several classes of Objects. Ech such class has a method to check if the object 'matches'.
275 =head2 WHO Objects ($obj->oclass() eq 'who')
277 Who sent the mail, who is the receiver?
279 =head3 $obj->who_match ($addr)
281 Returns true if $addr belongs to this objects. $addr is a text string representing the email address you want to check.
287 EMail: the only attribute is a regex to test email addresses
291 =head2 WHEN Objects ($obj->oclass() eq 'when')
293 Used to test for a certain daytime
295 =head3 $obj->when_match ($time)
297 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()).
303 TimeFrame: specifies a start and a end time
307 =head2 WHAT Objects ($obj->oclass() eq 'what')
311 =head2 ACTION Objects ($obj->oclass() eq 'action')
313 actions which can be executed
315 =head3 $obj->execute ($mod_group, $queue, $ruledb, $mod_group, $targets, $msginfo, $vars, $marks)
317 Execute the action code. $target is a array reference containing all
320 =head2 Common Methods
322 =head3 $obj->oclass()
324 Returns 'who', 'when' 'what' or 'action';
326 =head3 $obj->short_desc()
328 Returns a short text describing the contents of the object. This is used
329 for debugging purposes.
333 Returns an integer representing the Type of the objects. This integer
334 is used in the database to uniquely identify object types.
338 Returns the unique database ID of the object. undef means the object is not jet stored in the databse.
342 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.
344 =head3 $obj->priority()
346 Return a priority between 0 and 100. This is currently used to sort action objects by priority.