]>
Commit | Line | Data |
---|---|---|
758c7b6b DM |
1 | package PMG::RuleDB::Block; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
758c7b6b DM |
5 | use DBI; |
6 | use Digest::SHA; | |
7 | ||
8 | use PVE::SafeSyslog; | |
9 | ||
10 | use PMG::Utils; | |
11 | use PMG::ModGroup; | |
12 | use PMG::RuleDB::Object; | |
13 | ||
14 | use base qw(PMG::RuleDB::Object); | |
15 | ||
16 | sub otype { | |
17 | return 4001; | |
18 | } | |
19 | ||
20 | sub oclass { | |
21 | return 'action'; | |
22 | } | |
23 | ||
24 | sub otype_text { | |
25 | return 'Block'; | |
26 | } | |
27 | ||
758c7b6b DM |
28 | sub oisedit { |
29 | return 0; | |
30 | } | |
31 | ||
32 | sub final { | |
33 | return 1; | |
34 | } | |
35 | ||
36 | sub priority { | |
37 | return 98; | |
38 | } | |
39 | ||
40 | sub new { | |
41 | my ($type, $ogroup) = @_; | |
42 | ||
43 | my $class = ref($type) || $type; | |
44 | ||
7a2cf7e6 | 45 | my $self = $class->SUPER::new($class->otype(), $ogroup); |
758c7b6b DM |
46 | |
47 | return $self; | |
48 | } | |
49 | ||
50 | sub load_attr { | |
51 | my ($type, $ruledb, $id, $ogroup, $value) = @_; | |
52 | ||
53 | my $class = ref($type) || $type; | |
54 | ||
55 | my $obj = $class->new ($ogroup); | |
56 | $obj->{id} = $id; | |
57 | ||
58 | $obj->{digest} = Digest::SHA::sha1_hex($id, $ogroup); | |
59 | ||
60 | return $obj; | |
61 | } | |
62 | ||
63 | sub save { | |
64 | my ($self, $ruledb) = @_; | |
65 | ||
66 | defined($self->{ogroup}) || return undef; | |
67 | ||
68 | if (defined ($self->{id})) { | |
69 | # update | |
70 | ||
71 | # nothing to update | |
72 | ||
73 | } else { | |
74 | # insert | |
75 | ||
76 | my $sth = $ruledb->{dbh}->prepare( | |
77 | "INSERT INTO Object (Objectgroup_ID, ObjectType) VALUES (?, ?);"); | |
78 | ||
79 | $sth->execute($self->ogroup, $self->otype); | |
80 | ||
81 | $self->{id} = PMG::Utils::lastid($ruledb->{dbh}, 'object_id_seq'); | |
82 | } | |
83 | ||
84 | return $self->{id}; | |
85 | } | |
86 | ||
87 | sub execute { | |
88 | my ($self, $queue, $ruledb, $mod_group, $targets, | |
89 | $msginfo, $vars, $marks) = @_; | |
90 | ||
91 | if ($msginfo->{testmode}) { | |
92 | my $fh = $msginfo->{test_fh}; | |
93 | print $fh "block from: $msginfo->{sender}\n"; | |
94 | printf $fh "block to: %s\n", join (',', @$targets); | |
95 | } | |
96 | ||
97 | foreach my $to (@$targets) { | |
98 | syslog('info', "%s: block mail to <%s>", $queue->{logid}, $to); | |
99 | } | |
100 | ||
101 | $queue->set_status($targets, 'blocked'); | |
102 | } | |
103 | ||
104 | sub short_desc { | |
105 | my $self = shift; | |
106 | ||
107 | return "block message"; | |
108 | } | |
109 | ||
110 | 1; | |
111 | ||
112 | __END__ | |
113 | ||
114 | =head1 PMG::RuleDB::Block | |
115 | ||
116 | Block a message. |