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