]> git.proxmox.com Git - pmg-api.git/blob - PMG/RuleDB/Object.pm
add more ruledb classes
[pmg-api.git] / PMG / RuleDB / Object.pm
1 package PMG::RuleDB::Object;
2
3 use strict;
4 use warnings;
5 use Carp;
6 use DBI;
7
8 use PMG::Utils;
9
10 sub new {
11 my ($type, $otype, $ogroup) = @_;
12
13 $otype //= 0;
14
15 my $self = {
16 otype => $otype,
17 ogroup => $ogroup,
18 };
19
20 bless $self, $type;
21
22 return $self;
23 }
24
25 sub save {
26 croak "never call this method: ERROR";
27 }
28
29 sub load_attr {
30 croak "never call this method: ERROR";
31 }
32
33 sub load {
34 my ($ruledb, $objid) = @_;
35
36 return $ruledb->load_object($objid);
37 }
38
39 sub who_match {
40 croak "never call this method: ERROR";
41 }
42
43 sub when_match {
44 croak "never call this method: ERROR";
45 }
46
47 sub what_match {
48 croak "never call this method: ERROR";
49 }
50
51 sub execute {
52 croak "never call this method: ERROR";
53 }
54
55 sub final {
56 return undef;
57 }
58
59 sub priority {
60 return 0;
61 }
62
63 sub oisedit {
64 return 1;
65 }
66
67 sub ogroup {
68 my ($self, $v) = @_;
69
70 if (defined ($v)) {
71 $self->{ogroup} = $v;
72 }
73
74 $self->{ogroup};
75 }
76
77 sub otype {
78 my $self = shift;
79
80 $self->{otype};
81 }
82
83 sub otype_text {
84 my $self = shift;
85
86 return "object";
87 }
88
89 sub oicon {
90 my $self = shift;
91
92 return "def_icon.gif";
93 }
94
95 sub oconfigsite {
96 return undef;
97 }
98
99 sub oinfo {
100 return 'object';
101 }
102
103 # some who object only matches 'receivers'
104 sub receivertest {
105 return 0;
106 }
107
108 sub oclass {
109 croak "never call this method: ERROR";
110 }
111
112 sub id {
113 my $self = shift;
114
115 $self->{id};
116 }
117
118 sub short_desc {
119 return "basic object";
120 }
121
122 1;
123
124 __END__
125
126 =head1 PMG::RuleDB::Object
127
128 The Proxmox Rules consists of Objects. There are several classes of Objects. Ech such class has a method to check if the object 'matches'.
129
130 =head2 WHO Objects ($obj->oclass() eq 'who')
131
132 Who sent the mail, who is the receiver?
133
134 =head3 $obj->who_match ($addr)
135
136 Returns true if $addr belongs to this objects. $addr is a text string representing the email address you want to check.
137
138 =over
139
140 =item *
141
142 EMail: the only attribute is a regex to test email addresses
143
144 =back
145
146 =head2 WHEN Objects ($obj->oclass() eq 'when')
147
148 Used to test for a certain daytime
149
150 =head3 $obj->when_match ($time)
151
152 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()).
153
154 =over
155
156 =item *
157
158 TimeFrame: specifies a start and a end time
159
160 =back
161
162 =head2 WHAT Objects ($obj->oclass() eq 'what')
163
164 mail content tests
165
166 =head2 ACTION Objects ($obj->oclass() eq 'action')
167
168 actions which can be executed
169
170 =head3 $obj->execute ($mod_group, $queue, $ruledb, $mod_group, $targets, $msginfo, $vars, $marks)
171
172 Execute the action code. $target is a array reference containing all
173 matching targets.
174
175 =head2 Common Methods
176
177 =head3 $obj->oclass()
178
179 Returns 'who', 'when' 'what' or 'action';
180
181 =head3 $obj->short_desc()
182
183 Returns a short text describing the contents of the object. This is used
184 for debugging purposes.
185
186 =head3 $obj->otype
187
188 Returns an integer representing the Type of the objects. This integer
189 is used in the database to uniquely identify object types.
190
191 =head3 $obj->id
192
193 Returns the unique database ID of the object. undef means the object is not jet stored in the databse.
194
195 =head3 $obj->final()
196
197 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.
198
199 =head3 $obj->priority()
200
201 Return a priority between 0 and 100. This is currently used to sort action objects by priority.
202