]> git.proxmox.com Git - pmg-api.git/blame - PMG/RuleDB/Block.pm
start API for SMTP whitelist
[pmg-api.git] / PMG / RuleDB / Block.pm
CommitLineData
758c7b6b
DM
1package PMG::RuleDB::Block;
2
3use strict;
4use warnings;
5use Carp;
6use DBI;
7use Digest::SHA;
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
29sub oicon {
30 return 'block.gif';
31}
32
33sub oisedit {
34 return 0;
35}
36
37sub final {
38 return 1;
39}
40
41sub priority {
42 return 98;
43}
44
45sub 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
55sub 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
68sub 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
92sub 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
109sub short_desc {
110 my $self = shift;
111
112 return "block message";
113}
114
1151;
116
117__END__
118
119=head1 PMG::RuleDB::Block
120
121Block a message.