]> git.proxmox.com Git - pmg-api.git/blame - PMG/RuleDB/Block.pm
remove sub oicon() - no longer needed
[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;
7
8use PVE::SafeSyslog;
9
10use PMG::Utils;
11use PMG::ModGroup;
12use PMG::RuleDB::Object;
13
14use base qw(PMG::RuleDB::Object);
15
16sub otype {
17 return 4001;
18}
19
20sub oclass {
21 return 'action';
22}
23
24sub otype_text {
25 return 'Block';
26}
27
758c7b6b
DM
28sub oisedit {
29 return 0;
30}
31
32sub final {
33 return 1;
34}
35
36sub priority {
37 return 98;
38}
39
40sub 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
50sub 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
63sub 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
87sub 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
104sub short_desc {
105 my $self = shift;
106
107 return "block message";
108}
109
1101;
111
112__END__
113
114=head1 PMG::RuleDB::Block
115
116Block a message.