Difference between revisions of "Esmith::NetworksDB"

From SME Server
Jump to navigationJump to search
 
(4 intermediate revisions by the same user not shown)
Line 7: Line 7:
 
           use esmith::NetworksDB;
 
           use esmith::NetworksDB;
 
           my $c = esmith::NetworksDB->open;
 
           my $c = esmith::NetworksDB->open;
 
+
 
           # everything else works just like esmith::DB::db
 
           # everything else works just like esmith::DB::db
  
Line 40: Line 40:
  
 
If called in list context, returns the array of addresses and network/netmask strings. It’s trivial, of course, to convert an array to a comma separated list :-)
 
If called in list context, returns the array of addresses and network/netmask strings. It’s trivial, of course, to convert an array to a comma separated list :-)
 +
 +
my $ndb = esmith::NetworksDB->open_ro;
 +
my @access = $ndb->local_access_spec;
 +
then
 +
my $access = join ( ",", @access);
  
 
=== AUTHOR ===
 
=== AUTHOR ===

Latest revision as of 11:07, 7 February 2015

NAME

esmith::NetworksDB - interface to esmith networks database

In a root terminal you can do the command below if you want to display the up-to-date content

perldoc -U esmith::NetworksDB

SYNOPSIS

          use esmith::NetworksDB;
          my $c = esmith::NetworksDB->open;

          # everything else works just like esmith::DB::db

DESCRIPTION

This module provides an abstracted interface to the esmith master configuration database.

Unless otherwise noted, esmith::NetworksDB acts like esmith::DB::db.

open()

Like esmith::DB->open, but if given no $file it will try to open the file in the ESMITH_NETWORKS_DB environment variable or networks.

open_ro()

Like esmith::DB->open_ro, but if given no $file it will try to open the file in the ESMITH_NETWORKS_DB environment variable or networks.

networks

Return a list of all objects of type "network".

local_access_spec ([$access])

Compute the network/netmask entries which are to treated as local access.

There is also an optional access parameter which can further restrict the values returned. If "access" is "localhost", this routine will only return a single value, equating to access from localhost only.

If called in scalar context, the returned string is suitable for use in /etc/hosts.allow, smb.conf and httpd.conf, for example:

      127.0.0.1 192.168.1.1/255.255.255.0

Note: The elements are space separated, which is suitable for use in hosts.allow, smb.conf and httpd.conf. httpd.conf does not permit comma separated lists in "allow from" directives. Each element is either an IP address, or a network/netmask string.

If called in list context, returns the array of addresses and network/netmask strings. It’s trivial, of course, to convert an array to a comma separated list :-)

my $ndb = esmith::NetworksDB->open_ro;
my @access = $ndb->local_access_spec;

then

my $access = join ( ",", @access);

AUTHOR

      SME Server Developers <bugs@e-smith.com>