]> git.proxmox.com Git - pmg-api.git/blame - PMG/RuleDB/Block.pm
Add default rulename of 'unknown' to Actions
[pmg-api.git] / PMG / RuleDB / Block.pm
CommitLineData
758c7b6b
DM
1package PMG::RuleDB::Block;
2
3use strict;
4use warnings;
758c7b6b
DM
5use DBI;
6use Digest::SHA;
114655f4 7use Encode;
758c7b6b
DM
8
9use PVE::SafeSyslog;
10
11use PMG::Utils;
12use PMG::ModGroup;
13use PMG::RuleDB::Object;
14
15use base qw(PMG::RuleDB::Object);
16
17sub otype {
18 return 4001;
19}
20
21sub oclass {
22 return 'action';
23}
24
25sub otype_text {
26 return 'Block';
27}
28
758c7b6b
DM
29sub oisedit {
30 return 0;
31}
32
33sub final {
34 return 1;
35}
36
37sub priority {
38 return 98;
39}
40
41sub 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
51sub 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
64sub 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
88sub execute {
89 my ($self, $queue, $ruledb, $mod_group, $targets,
90 $msginfo, $vars, $marks) = @_;
91
6c65ab40 92 my $rulename = $vars->{RULE} // 'unknown';
365d5b95 93
758c7b6b
DM
94 if ($msginfo->{testmode}) {
95 my $fh = $msginfo->{test_fh};
96 print $fh "block from: $msginfo->{sender}\n";
97 printf $fh "block to: %s\n", join (',', @$targets);
98 }
99
100 foreach my $to (@$targets) {
365d5b95 101 syslog('info', "%s: block mail to <%s> (rule: %s)", $queue->{logid}, encode('UTF-8', $to), $rulename);
758c7b6b
DM
102 }
103
104 $queue->set_status($targets, 'blocked');
105}
106
107sub short_desc {
108 my $self = shift;
109
110 return "block message";
111}
112
1131;
114
115__END__
116
117=head1 PMG::RuleDB::Block
118
119Block a message.