Firewall.pm untested

filter: Statementstmt 0.0% 0 / 47 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 55 CC 1 SCAR 6.9
CC
1
Cov
0%
init
2.0
meta
2.0
c_sec
2.0
CRAP 2.0
1 package VUser::Firewall;
2 use warnings;
3 use strict;
4  
5 # Copyright 2005 Randy Smith <perlstalker@vuser.org>
6 # $Id: Firewall.pm,v 1.1 2006/01/04 18:45:40 perlstalker Exp $
7  
8 our $VERSION = '0.1.0';
9  
10 our $c_sec = 'Extension Firewall';
11 our %meta = (
12 'network' => VUser::Meta->new('name' => 'network',
13 'type' => 'string',
14 'description' => 'Network to work with (a.b.c.d/mask)'),
15 'port' => VUser::Meta->new('name' => 'port',
16 'type' => 'int',
17 'description' => 'TCP/UDP port to work with'),
18 'protocol' => VUser::Meta->new('name' => 'protocol',
19 'type' => 'string',
20 'description' => 'udp or tcp'),
21 'host' => VUser::Meta->new('name' => 'host',
22 'type' => 'string',
23 'description' => 'Firewall host')
24 );
25  
26 $meta{'source'} = $meta{'network'}->new(name => 'source');
27 $meta{'destination'} = $meta{'network'}->new(name => 'destination');
28 $meta{'sport'} = $meta{'port'}->new(name => 'sport');
29 $meta{'dport'} = $meta{'port'}->new(name => 'dport');
30  
31 my $log;
32  
33 sub init
34 {
35 my $eh = shift;
36 my %cfg = @_;
37  
38 $log = $main::log;
39  
40 # firewall
41 $eh->register_keyword('firewall', 'Manage firewalls');
42  
43 # firewall-block
44 $eh->register_action('firewall', 'block', 'Block a network and/or a port');
45 $eh->register_option('firewall', 'block', $meta{'source'});
46 $eh->register_option('firewall', 'block', $meta{'sport'});
47 $eh->register_option('firewall', 'block', $meta{'destination'});
48 $eh->register_option('firewall', 'block', $meta{'dport'});
49 $eh->register_option('firewall', 'block', $meta{'protocol'});
50  
51 # firewall-unblock
52 $eh->register_action('firewall', 'unblock', 'Unblock a previously blocked network and/or port');
53 $eh->register_option('firewall', 'unblock', $meta{'source'});
54 $eh->register_option('firewall', 'unblock', $meta{'sport'});
55 $eh->register_option('firewall', 'unblock', $meta{'destination'});
56 $eh->register_option('firewall', 'unblock', $meta{'dport'});
57 $eh->register_option('firewall', 'unblock', $meta{'protocol'});
58  
59 # firewall-allow
60 $eh->register_action('firewall', 'allow', 'Allow a network and/or port');
61 $eh->register_option('firewall', 'allow', $meta{'source'});
62 $eh->register_option('firewall', 'allow', $meta{'sport'});
63 $eh->register_option('firewall', 'allow', $meta{'destination'});
64 $eh->register_option('firewall', 'allow', $meta{'dport'});
65 $eh->register_option('firewall', 'allow', $meta{'protocol'});
66  
67 # firewall-unallow
68 $eh->register_action('firewall', 'unallow', 'Stop allowing an allowed network and/or port');
69 $eh->register_option('firewall', 'unallow', $meta{'source'});
70 $eh->register_option('firewall', 'unallow', $meta{'sport'});
71 $eh->register_option('firewall', 'unallow', $meta{'destination'});
72 $eh->register_option('firewall', 'unallow', $meta{'dport'});
73 $eh->register_option('firewall', 'unallow', $meta{'protocol'});
74  
75 # firewall-restart
76 $eh->register_action('firewall', 'restart', 'Restart the firewall(s)');
77  
78 # firewall-flush
79 $eh->register_action('firewall', 'flush', 'Flush the firewall rules. Use with care');
80 }
81  
82 sub meta { return %meta; }
83 sub c_sec { return $c_sec; }
84  
85 1;
86  
87 __END__