]> git.proxmox.com Git - pmg-api.git/commitdiff
add PMG/RuleDB/Virus.pm
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 2 Feb 2017 10:44:44 +0000 (11:44 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 2 Feb 2017 10:44:44 +0000 (11:44 +0100)
Makefile
PMG/DBTools.pm
PMG/RuleDB/Virus.pm [new file with mode: 0644]

index 3391e720a87867a8d4060b9df5bc25ef9f24340b..2a31a54dd178cb0a08ed1410ec8b7cf14392c73c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -39,6 +39,7 @@ LIBSOURCES =                          \
        PMG/RuleDB/TimeFrame.pm         \
        PMG/RuleDB/MatchField.pm        \
        PMG/RuleDB/ContentTypeFilter.pm \
+       PMG/RuleDB/Virus.pm             \
        PMG/RuleDB.pm                   \
        PMG/CLI/pmgdb.pm                \
        ${CLI_CLASSES}                  \
index 33846c4e3b8a3b3ef559a0bf42d458d9802286e9..f5d0dd64b7f7f41de51c542ccc323cd17eb2d712 100644 (file)
@@ -533,60 +533,72 @@ sub init_ruledb {
     # WHEN Objects
 
     # Working hours
-    $obj = Proxmox::RuleDB::TimeFrame->new(8*60, 16*60);
+    $obj = PMG::RuleDB::TimeFrame->new(8*60, 16*60);
     my $working_hours =$ruledb->create_group_with_obj($obj, 'Office Hours' ,
                                                      'Usual office hours');
 
     # WHAT Objects
 
-    die "fixme";
-
     # Images
-    $obj = Proxmox::RuleDB::ContentTypeFilter->new ('image/.*');
-    my $img_content = $ruledb->create_group_with_obj ($obj, 'Images',
-                                                     'All kinds of graphic files');
+    $obj = PMG::RuleDB::ContentTypeFilter->new('image/.*');
+    my $img_content = $ruledb->create_group_with_obj(
+       $obj, 'Images', 'All kinds of graphic files');
+
     # Multimedia
-    $obj = Proxmox::RuleDB::ContentTypeFilter->new ('audio/.*');
-    my $mm_content = $ruledb->create_group_with_obj ($obj, 'Multimedia',
-                                                    'Audio and Video');
+    $obj = PMG::RuleDB::ContentTypeFilter->new('audio/.*');
+    my $mm_content = $ruledb->create_group_with_obj(
+       $obj, 'Multimedia', 'Audio and Video');
 
-    $obj = Proxmox::RuleDB::ContentTypeFilter->new ('video/.*');
-    $ruledb->group_add_object ($mm_content, $obj);
+    $obj = PMG::RuleDB::ContentTypeFilter->new('video/.*');
+    $ruledb->group_add_object($mm_content, $obj);
 
     # Office Files
-    $obj = Proxmox::RuleDB::ContentTypeFilter->new ('application/vnd\.ms-excel');
-    my $office_content = $ruledb->create_group_with_obj ($obj, 'Office Files',
-                                                        'Common Office Files');
-    $obj = Proxmox::RuleDB::ContentTypeFilter->new ('application/vnd\.ms-powerpoint');
-    $ruledb->group_add_object ($office_content, $obj);
-    $obj = Proxmox::RuleDB::ContentTypeFilter->new ('application/msword');
-    $ruledb->group_add_object ($office_content, $obj);
-    $obj = Proxmox::RuleDB::ContentTypeFilter->new ('application/vnd\.openxmlformats-officedocument\..*');
-    $ruledb->group_add_object ($office_content, $obj);
-    $obj = Proxmox::RuleDB::ContentTypeFilter->new ('application/vnd\.oasis\.opendocument\..*');
-    $ruledb->group_add_object ($office_content, $obj);
-    $obj = Proxmox::RuleDB::ContentTypeFilter->new ('application/vnd\.stardivision\..*');
-    $ruledb->group_add_object ($office_content, $obj);
-    $obj = Proxmox::RuleDB::ContentTypeFilter->new ('application/vnd\.sun\.xml\..*');
+    $obj = PMG::RuleDB::ContentTypeFilter->new('application/vnd\.ms-excel');
+    my $office_content = $ruledb->create_group_with_obj(
+       $obj, 'Office Files', 'Common Office Files');
+    
+    $obj = PMG::RuleDB::ContentTypeFilter->new(
+       'application/vnd\.ms-powerpoint');
+    
+    $ruledb->group_add_object($office_content, $obj);
+    
+    $obj = PMG::RuleDB::ContentTypeFilter->new('application/msword');
     $ruledb->group_add_object ($office_content, $obj);
     
+    $obj = PMG::RuleDB::ContentTypeFilter->new(
+       'application/vnd\.openxmlformats-officedocument\..*');
+    $ruledb->group_add_object($office_content, $obj);
+    
+    $obj = PMG::RuleDB::ContentTypeFilter->new(
+       'application/vnd\.oasis\.opendocument\..*');
+    $ruledb->group_add_object($office_content, $obj);
 
+    $obj = PMG::RuleDB::ContentTypeFilter->new(
+       'application/vnd\.stardivision\..*');
+    $ruledb->group_add_object($office_content, $obj);
+    
+    $obj = PMG::RuleDB::ContentTypeFilter->new(
+       'application/vnd\.sun\.xml\..*');
+    $ruledb->group_add_object($office_content, $obj);
+    
     # Dangerous Content
-    $obj = Proxmox::RuleDB::ContentTypeFilter->new ('application/x-ms-dos-executable');
-    my $exe_content = $ruledb->create_group_with_obj ($obj, 'Dangerous Content',
-                                                     'executable files and partial messages');
-    $obj = Proxmox::RuleDB::ContentTypeFilter->new ('application/x-java');
-    $ruledb->group_add_object ($exe_content, $obj);
-    $obj = Proxmox::RuleDB::ContentTypeFilter->new ('application/javascript');
-    $ruledb->group_add_object ($exe_content, $obj);
-    $obj = Proxmox::RuleDB::ContentTypeFilter->new ('application/x-executable');
-    $ruledb->group_add_object ($exe_content, $obj);
-    $obj = Proxmox::RuleDB::ContentTypeFilter->new ('message/partial');
-    $ruledb->group_add_object ($exe_content, $obj);
-    $obj = Proxmox::RuleDB::MatchFilename->new ('.*\.(vbs|pif|lnk|shs|shb)');
-    $ruledb->group_add_object ($exe_content, $obj);
-    $obj = Proxmox::RuleDB::MatchFilename->new ('.*\.{.+}');
-    $ruledb->group_add_object ($exe_content, $obj);
+    $obj = PMG::RuleDB::ContentTypeFilter->new(
+       'application/x-ms-dos-executable');
+    my $exe_content = $ruledb->create_group_with_obj(
+       $obj, 'Dangerous Content', 'executable files and partial messages');
+    
+    $obj = PMG::RuleDB::ContentTypeFilter->new('application/x-java');
+    $ruledb->group_add_object($exe_content, $obj);
+    $obj = PMG::RuleDB::ContentTypeFilter->new('application/javascript');
+    $ruledb->group_add_object($exe_content, $obj);
+    $obj = PMG::RuleDB::ContentTypeFilter->new('application/x-executable');
+    $ruledb->group_add_object($exe_content, $obj);
+    $obj = PMG::RuleDB::ContentTypeFilter->new('message/partial');
+    $ruledb->group_add_object($exe_content, $obj);
+    $obj = PMG::RuleDB::MatchFilename->new('.*\.(vbs|pif|lnk|shs|shb)');
+    $ruledb->group_add_object($exe_content, $obj);
+    $obj = PMG::RuleDB::MatchFilename->new('.*\.{.+}');
+    $ruledb->group_add_object($exe_content, $obj);
 
     # Virus
     $obj = Proxmox::RuleDB::Virus->new ();
@@ -683,14 +695,14 @@ sub init_ruledb {
     ####################### RULES ##################################
 
     ## Block Dangerous  Files
-    my $rule = Proxmox::RuleDB::Rule->new ('Block Dangerous Files', 93, 1, 0);
+    my $rule = PMG::RuleDB::Rule->new ('Block Dangerous Files', 93, 1, 0);
     $ruledb->save_rule ($rule);
 
     $ruledb->rule_add_what_group ($rule, $exe_content);
     $ruledb->rule_add_action ($rule, $remove);
 
     ## Block Viruses
-    $rule = Proxmox::RuleDB::Rule->new ('Block Viruses', 96, 1, 0);
+    $rule = PMG::RuleDB::Rule->new ('Block Viruses', 96, 1, 0);
     $ruledb->save_rule ($rule);
 
     $ruledb->rule_add_what_group ($rule, $virus);
@@ -703,7 +715,7 @@ sub init_ruledb {
     }
 
     ## Virus Alert
-    $rule = Proxmox::RuleDB::Rule->new ('Virus Alert', 96, 1, 1);
+    $rule = PMG::RuleDB::Rule->new ('Virus Alert', 96, 1, 1);
     $ruledb->save_rule ($rule);
 
     $ruledb->rule_add_what_group ($rule, $virus);
@@ -712,7 +724,7 @@ sub init_ruledb {
     $ruledb->rule_add_action ($rule, $block);
     
     ## Blacklist
-    $rule = Proxmox::RuleDB::Rule->new ('Blacklist', 98, 1, 0);
+    $rule = PMG::RuleDB::Rule->new ('Blacklist', 98, 1, 0);
     $ruledb->save_rule ($rule);
 
     $ruledb->rule_add_from_group ($rule, $blacklist);
@@ -720,20 +732,20 @@ sub init_ruledb {
 
     ## Modify header
     if (!$testmode) {
-       $rule = Proxmox::RuleDB::Rule->new ('Modify Header', 90, 1, 0);
+       $rule = PMG::RuleDB::Rule->new ('Modify Header', 90, 1, 0);
        $ruledb->save_rule ($rule);
        $ruledb->rule_add_action ($rule, $mod_spam_level);
     }
 
     ## Whitelist
-    $rule = Proxmox::RuleDB::Rule->new ('Whitelist', 85, 1, 0);
+    $rule = PMG::RuleDB::Rule->new ('Whitelist', 85, 1, 0);
     $ruledb->save_rule ($rule);
 
     $ruledb->rule_add_from_group ($rule, $whitelist);
     $ruledb->rule_add_action ($rule, $accept);
 
     if ($testmode) {
-       $rule = Proxmox::RuleDB::Rule->new ('Mark Spam', 80, 1, 0);
+       $rule = PMG::RuleDB::Rule->new ('Mark Spam', 80, 1, 0);
        $ruledb->save_rule ($rule);
 
        $ruledb->rule_add_what_group ($rule, $spam10);
@@ -741,7 +753,7 @@ sub init_ruledb {
        $ruledb->rule_add_action ($rule, $mod_spam_subject);
     } else {
        # Quarantine/Mark Spam (Level 3)
-       $rule = Proxmox::RuleDB::Rule->new ('Quarantine/Mark Spam (Level 3)', 80, 1, 0);
+       $rule = PMG::RuleDB::Rule->new ('Quarantine/Mark Spam (Level 3)', 80, 1, 0);
        $ruledb->save_rule ($rule);
 
        $ruledb->rule_add_what_group ($rule, $spam3);
@@ -751,7 +763,7 @@ sub init_ruledb {
     }
 
     # Quarantine/Mark Spam (Level 5)
-    $rule = Proxmox::RuleDB::Rule->new ('Quarantine/Mark Spam (Level 5)', 79, 0, 0);
+    $rule = PMG::RuleDB::Rule->new ('Quarantine/Mark Spam (Level 5)', 79, 0, 0);
     $ruledb->save_rule ($rule);
 
     $ruledb->rule_add_what_group ($rule, $spam5);
@@ -759,14 +771,14 @@ sub init_ruledb {
     $ruledb->rule_add_action ($rule, $quarantine);
 
     ## Block Spam Level 10
-    $rule = Proxmox::RuleDB::Rule->new ('Block Spam (Level 10)', 78, 0, 0);
+    $rule = PMG::RuleDB::Rule->new ('Block Spam (Level 10)', 78, 0, 0);
     $ruledb->save_rule ($rule);
 
     $ruledb->rule_add_what_group ($rule, $spam10);
     $ruledb->rule_add_action ($rule, $block);
 
     ## Block Outgoing Spam
-    $rule = Proxmox::RuleDB::Rule->new ('Block outgoing Spam', 70, 0, 1);
+    $rule = PMG::RuleDB::Rule->new ('Block outgoing Spam', 70, 0, 1);
     $ruledb->save_rule ($rule);
 
     $ruledb->rule_add_what_group ($rule, $spam3);
@@ -775,12 +787,12 @@ sub init_ruledb {
     $ruledb->rule_add_action ($rule, $block);
 
     ## Add disclaimer
-    $rule = Proxmox::RuleDB::Rule->new ('Add Disclaimer', 60, 0, 1);
+    $rule = PMG::RuleDB::Rule->new ('Add Disclaimer', 60, 0, 1);
     $ruledb->save_rule ($rule);
     $ruledb->rule_add_action ($rule, $add_discl);
 
     # Block Multimedia Files
-    $rule = Proxmox::RuleDB::Rule->new ('Block Multimedia Files', 87, 0, 2);
+    $rule = PMG::RuleDB::Rule->new ('Block Multimedia Files', 87, 0, 2);
     $ruledb->save_rule ($rule);
 
     $ruledb->rule_add_what_group ($rule, $mm_content);
diff --git a/PMG/RuleDB/Virus.pm b/PMG/RuleDB/Virus.pm
new file mode 100644 (file)
index 0000000..299489b
--- /dev/null
@@ -0,0 +1,101 @@
+package PMG::RuleDB::Virus;
+
+use strict;
+use warnings;
+use Carp;
+use DBI;
+use Digest::SHA;
+
+use PMG::RuleDB::Object;
+
+use base qw(PMG::RuleDB::Object);
+
+sub otype {
+    return 3001;
+}
+
+sub oclass {
+    return 'what';
+}
+
+sub otype_text {
+    return 'Virus Filter';
+}
+
+sub oicon {
+    return 'virusdetect.gif';
+}
+
+sub oisedit {
+    return 0;   
+}
+
+sub new {
+    my ($type, $ogroup) = @_;
+    
+    my $class = ref($type) || $type;
+
+    my $self = $class->SUPER::new(otype(), $ogroup);
+
+    return $self;
+}
+
+sub load_attr {
+    my ($type, $ruledb, $id, $ogroup, $value) = @_;
+    
+    my $class = ref($type) || $type;
+
+    my $obj = $class->new ($ogroup);
+    $obj->{id} = $id;
+
+    $obj->{digest} = Digest::SHA::sha1_hex($id, $ogroup);
+    
+    return $obj;
+}
+
+sub save {
+    my ($self, $ruledb) = @_;
+
+    defined($self->{ogroup}) || return undef;
+
+    if (defined ($self->{id})) {
+       # update
+
+       # nothing to update
+    } else {
+       # insert
+
+       my $sth = $ruledb->{dbh}->prepare(
+           "INSERT INTO Object (Objectgroup_ID, ObjectType) VALUES (?, ?);");
+
+       $sth->execute($self->ogroup, $self->otype);
+
+       $self->{id} = Proxmox::RuleDB::lastid($ruledb->{dbh}, 'object_id_seq');
+    }
+       
+    return $self->{id};
+}
+
+sub what_match {
+    my ($self, $queue, $entity, $msginfo) = @_;
+
+    if ($queue->{vinfo}) {
+       return [];
+    } 
+
+    return undef;
+}
+
+sub short_desc {
+    my $self = shift;
+    
+    return "active";
+}
+
+1;
+
+__END__
+
+=head1 PMG::RuleDB::Virus
+
+Virus filter