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