]> git.proxmox.com Git - pmg-api.git/blame - PMG/RuleDB/Quarantine.pm
remove sub oicon() - no longer needed
[pmg-api.git] / PMG / RuleDB / Quarantine.pm
CommitLineData
0a580593
DM
1package PMG::RuleDB::Quarantine;
2
3use strict;
4use warnings;
0a580593
DM
5use DBI;
6use Digest::SHA;
7
8use PVE::SafeSyslog;
758c7b6b
DM
9
10use PMG::Utils;
11use PMG::ModGroup;
0a580593
DM
12use PMG::RuleDB::Object;
13
14use base qw(PMG::RuleDB::Object);
15
16sub otype {
17 return 4006;
18}
19
20sub oclass {
21 return 'action';
22}
23
24sub otype_text {
25 return 'Quarantine';
26}
27
0a580593
DM
28sub oisedit {
29 return 0;
30}
31
32sub final {
33 return 1;
34}
35
36sub priority {
37 return 90;
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);
0a580593
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 my $sth = $ruledb->{dbh}->prepare (
76 "INSERT INTO Object (Objectgroup_ID, ObjectType) VALUES (?, ?);");
77
78 $sth->execute($self->ogroup, $self->otype);
79
758c7b6b 80 $self->{id} = PMG::Utils::lastid($ruledb->{dbh}, 'object_id_seq');
0a580593
DM
81 }
82
83 return $self->{id};
84}
85
86sub execute {
87 my ($self, $queue, $ruledb, $mod_group, $targets,
88 $msginfo, $vars, $marks, $ldap) = @_;
0a580593
DM
89
90 my $subgroups = $mod_group->subgroups($targets, 1);
91
92 foreach my $ta (@$subgroups) {
93 my ($tg, $entity) = (@$ta[0], @$ta[1]);
94
758c7b6b 95 PMG::Utils::remove_marks($entity);
0a580593
DM
96
97 if ($queue->{vinfo}) {
98 if (my $qid = $queue->quarantine_mail($ruledb, 'V', $entity, $tg, $msginfo, $vars, $ldap)) {
99
100 foreach (@$tg) {
101 syslog ('info', "$queue->{logid}: moved mail for <%s> to virus quarantine - $qid", $_);
102 }
103
104 $queue->set_status ($tg, 'delivered');
105 }
106
107 } else {
108 if (my $qid = $queue->quarantine_mail($ruledb, 'S', $entity, $tg, $msginfo, $vars, $ldap)) {
109
110 foreach (@$tg) {
111 syslog ('info', "$queue->{logid}: moved mail for <%s> to spam quarantine - $qid", $_);
112 }
113
114 $queue->set_status($tg, 'delivered');
115 }
116 }
117 }
118
119 # warn if no subgroups
120}
121
122sub short_desc {
123 my $self = shift;
124
9578dcd7 125 return 'Move to quarantine.';
0a580593
DM
126}
127
1281;