File: ScanContext.pm

package info (click to toggle)
ndiff 0.05beta4-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny, sarge
  • size: 300 kB
  • ctags: 254
  • sloc: perl: 1,806; makefile: 56
file content (122 lines) | stat: -rw-r--r-- 2,383 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/perl
#
# $Id: ScanContext.pm,v 1.12 2001/11/24 02:55:56 levine Exp $
#
# Copyright (C) 2000  James D. Levine (jdl@vinecorp.com)
#
#
#   This program is free software; you can redistribute it and/or
#   modify it under the terms of the GNU General Public License
#   as published by the Free Software Foundation; either version 2
#   of the License, or (at your option) any later version.
# 
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
# 
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 
#   02111-1307, USA.
#
####################################################################


#
# Provides access to user settings though an ndiff.conf file.
# Requires some simplification.
#

use strict;

package PortScan::ScanContext;

my $config = {};

&_init;

#
# any property may be queried by a method call of the same name
# on a ScanContext instance; the AUTOLOAD method will return the property.
#

sub AUTOLOAD
{
    my $prop = $PortScan::ScanContext::AUTOLOAD;

    $prop =~ s/PortScan::ScanContext:://g;

    return $config->{$prop};
}




sub _require
{
    my $f = shift;
#print "attempting to load $f \n"
#    ;
    (-r $f) ? (require $f) : 0;
}


#
# Suck up an ndiff.conf file, if found.  _init executes before almost
# everything else.  If no ndiff.conf file is found, install a couple defaults.
# 

sub _init
  {
    my $self = shift;

    if (  (! _require $ENV{"HOME"} . "/.ndiff/ndiff.conf" ) 
	  && (! _require $ENV{"NDIFF_ROOT"} . "/ndiff.conf")
	  && (! _require "/usr/local/lib/ndiff/ndiff.conf")
	  && (! _require "./ndiff.conf")  
	  )
    {
	$config = 
	{
	    default_data_store_type => "PortScan::NmapFile",
	    default_data_store_props => "root=/tmp/ndiff_data",
	};
    }
    else
    {
	$config = get_config();
    }

    $config->{root};
  }


sub split_property
{
    my $prop_string = shift;
    $prop_string =~ s/,/=/g;

    return { split /=/, $prop_string }
}


sub _tests
{
    print "default_data_store_type: " . &PortScan::ScanContext::default_data_store_type ."\n";

}

1;