]> git.proxmox.com Git - pmg-api.git/blob - PMG/RuleDB/Quarantine.pm
use 'die' instead of 'carp'
[pmg-api.git] / PMG / RuleDB / Quarantine.pm
1 package PMG::RuleDB::Quarantine;
2
3 use strict;
4 use warnings;
5 use DBI;
6 use Digest::SHA;
7
8 use PVE::SafeSyslog;
9
10 use PMG::Utils;
11 use PMG::ModGroup;
12 use PMG::RuleDB::Object;
13
14 use base qw(PMG::RuleDB::Object);
15
16 sub otype {
17 return 4006;
18 }
19
20 sub oclass {
21 return 'action';
22 }
23
24 sub otype_text {
25 return 'Quarantine';
26 }
27
28 sub oinfo {
29 return 'Move to quarantine.';
30 }
31
32 sub oicon {
33 # fixme:
34 return 'accept.gif';
35 }
36
37 sub oisedit {
38 return 0;
39 }
40
41 sub final {
42 return 1;
43 }
44
45 sub priority {
46 return 90;
47 }
48
49 sub new {
50 my ($type, $ogroup) = @_;
51
52 my $class = ref($type) || $type;
53
54 my $self = $class->SUPER::new($class->otype(), $ogroup);
55
56 return $self;
57 }
58
59 sub load_attr {
60 my ($type, $ruledb, $id, $ogroup, $value) = @_;
61
62 my $class = ref($type) || $type;
63
64 my $obj = $class->new($ogroup);
65 $obj->{id} = $id;
66
67 $obj->{digest} = Digest::SHA::sha1_hex($id, $ogroup);
68
69 return $obj;
70 }
71
72 sub save {
73 my ($self, $ruledb) = @_;
74
75 defined($self->{ogroup}) || return undef;
76
77 if (defined ($self->{id})) {
78 # update
79
80 # nothing to update
81
82 } else {
83 # insert
84 my $sth = $ruledb->{dbh}->prepare (
85 "INSERT INTO Object (Objectgroup_ID, ObjectType) VALUES (?, ?);");
86
87 $sth->execute($self->ogroup, $self->otype);
88
89 $self->{id} = PMG::Utils::lastid($ruledb->{dbh}, 'object_id_seq');
90 }
91
92 return $self->{id};
93 }
94
95 sub execute {
96 my ($self, $queue, $ruledb, $mod_group, $targets,
97 $msginfo, $vars, $marks, $ldap) = @_;
98
99 my $subgroups = $mod_group->subgroups($targets, 1);
100
101 foreach my $ta (@$subgroups) {
102 my ($tg, $entity) = (@$ta[0], @$ta[1]);
103
104 PMG::Utils::remove_marks($entity);
105
106 if ($queue->{vinfo}) {
107 if (my $qid = $queue->quarantine_mail($ruledb, 'V', $entity, $tg, $msginfo, $vars, $ldap)) {
108
109 foreach (@$tg) {
110 syslog ('info', "$queue->{logid}: moved mail for <%s> to virus quarantine - $qid", $_);
111 }
112
113 $queue->set_status ($tg, 'delivered');
114 }
115
116 } else {
117 if (my $qid = $queue->quarantine_mail($ruledb, 'S', $entity, $tg, $msginfo, $vars, $ldap)) {
118
119 foreach (@$tg) {
120 syslog ('info', "$queue->{logid}: moved mail for <%s> to spam quarantine - $qid", $_);
121 }
122
123 $queue->set_status($tg, 'delivered');
124 }
125 }
126 }
127
128 # warn if no subgroups
129 }
130
131 sub short_desc {
132 my $self = shift;
133
134 return oinfo();
135 }
136
137 1;