Wizard-LDAP

 view release on metacpan or  search on metacpan

Makefile.PL  view on Meta::CPAN

  );


my $cfg;
# Make sure a Makefile is generated; the CPAN module depends on it
eval {
  if (-f "lib/Wizard/LDAP/Config.pm") {
    $cfg = eval { require "lib/Wizard/LDAP/Config.pm" };
  }
  if (!$cfg  ||  $opt_config) {
    my $prefsfile = $cfg->{'ldap-prefs-file'} || '/etc/Wizard-LDAP/prefs';
    $cfg->{'ldap-prefs-file'} =
      prompt("Enter path of the LDAP Wizard prefs file:", $prefsfile);
  }
  die "Failed to create directory lib/Wizard/LDAP: $!"
    unless ((-d "lib/Wizard/LDAP")  or
	    mkdir("lib/Wizard/LDAP", 0755));
  require Data::Dumper;
  my $dump = Data::Dumper->new
    ([$cfg], ["Wizard::LDAP::Config::config"])->Indent(1)->Dump();
  if (!open(FILE, ">lib/Wizard/LDAP/Config.pm")  or
      !(print FILE ("package Wizard::LDAP::Config;\n",
		    $dump))  or

README  view on Meta::CPAN


      http://localhost/admin/ldap.ep

    Start with modifying the preferences. See the section on "THE
    LDAP-WIZARD PREFERENCES".

THE LDAP-WIZARD PREFERENCES
    The system wide preferences are accessible via the web form
    ldap.ep. The following items can be configured:

  item_ldap_prefs_serverip

    This is the IP address of the LDAP server being used, typically

      127.0.0.1.

    No default is set.

  item_ldap_prefs_serverport

    Likewise, this is the LDAP servers port number. The default is

      389

  item_ldap_prefs_adminDN

    This is the distinguished name to use for accessing the LDAP
    server as root. No default is set. Example:

      cn=root, dc=ispsoft, dc=de

  item_ldap_prefs_adminPassword

    This is the password to use for binding to the LDAP server as
    root. Currently the password *must* be stored in clear text.
    (This is subject to change.)

  item_ldap_prefs_nextuid

    This the next numeric UID, that will assigned to a new user. By
    default the value

      500

    is choosen. The value is incremented with any new user, so after
    inserting the next users it will be 501, 502, 503 and so on. You
    typically should reserve some block of Unix UID's for users
    managed by the LDAP server.

  item_ldap_prefs_gid

    This is the numeric GID, that your LDAP users will have under
    Unix. The default is

      500

  item_ldap_prefs_home

    This is the prefix to use for the users home directories, for
    example

      /home

    (the default). The users login names will be appended.

  item_ldap_prefs_userbase

    This is a suffix for constructing the distinguished names of
    your users. Example:

      dc=ispsoft, dc=de

  item_ldap_prefs_netbase

    A similar suffix for constructing the distinguished names of
    nets. Example:

      dc=ispsoft, dc=de

  item_ldap_prefs_domain

    The mail domain appended to unclassified email adresses. For
    example, if you have a user "joe" and the domain is
    "ispsoft.de", then its email adress will be joe@ispsoft.de.

  item_ldap_prefs_prefschange

    If you enter a shell command here, then this command will be
    launched after any change of the preferences. Example:

      /usr/bin/ldapAdmin --prefs

  item_ldap_prefs_hostchange

    This is a similar shell command that will be called after hosts
    have changed. Example:

      /usr/bin/ldapAdmin --hosts

  item_ldap_prefs_netchange

    A shell command to issue after network definitions have changed.
    Example:

      /usr/bin/ldapAdmin --nets

  item_ldap_prefs_userchange_new

    This is a special case of the command for changing users. If
    defined, it will be issued after a user was created. The users
    name will be appended as the last argument. If not defined, the
    above and more generic command will be executed.

  item_ldap_prefs_userchange_modify

    Similar to item_ldap_prefs_userchange_new, but for modified
    users. Again, the users name will be appended as a last
    argument.

  item_ldap_prefs_userchange_delete

    Finally a shell command being executed after a user has been
    deleted. The users name will be appended as a last argument.

AUTHORS AND COPYRIGHT
    This module is

      Copyright (C) 1999     Jochen Wiedmann
                             Am Eisteich 9
                             72555 Metzingen

ldapAdmin.PL  view on Meta::CPAN


sub Usage {
    print <<"EOF";
Usage: $0 <action> [options]

Read system settings from the LDAP server and fix them into the current
configuration.

Possible actions are:

  --prefs		Preferences have changes, read and fix everything.
			Implies --nets and --hosts.
  --nets        	Networks have changed, read and fix network and host
			settings. Implies --hosts.
  --hosts		Hosts have changed, read and fix host settings.
  --help		Print this message
  --add-user=<user>	Add the given user

Possible options are:

  --debug	Turn on debugging mode: Print what would have been done

ldapAdmin.PL  view on Meta::CPAN

    exit 1;
}


############################################################################
#
#   Name:    LdapConnect
#
#   Purpose: Connect to the LDAP server
#
#   Inputs:  $prefs - LDAP wizard prefs
#
#   Returns: Net::LDAP object; dies in case of problems
#
############################################################################

sub LdapConnect {
    my $prefs = shift;
    my $server = $prefs->{'ldap-prefs-serverip'};
    my $port = $prefs->{'ldap-prefs-serverport'} || 0;
    my $ldap = Net::LDAP->new($server, 'port' => $port)
        or die "Failed to connect to LDAP server $server"
	    . ($port ? ":$port" : "") . ": $!";
    my $adminDN = $prefs->{'ldap-prefs-adminDN'};
    my $adminPassword = $prefs->{'ldap-prefs-adminPassword'};
    $ldap->bind('dn' => $adminDN, 'password' => $adminPassword)
        or die "Failed to bind as $adminDN: $!";
    $ldap;
}


############################################################################
#
#   Name:    AddUser
#
#   Purpose: Add a new user
#
#   Inputs:  $prefs - LDAP wizard prefs
#            $user - User being added
#
#   Returns: Nothing; exits in case of problems
#
############################################################################

sub AddUser {
    my($options, $prefs, $user) = @_;
    my $uidnumber = $options->{'uidnumber'};
    die "Invalid UID number: $uidnumber" unless $uidnumber =~ /^(\d+)$/;
    my $gidnumber = $options->{'gidnumber'};
    die "Invalid GID number: $gidnumber" unless $gidnumber =~ /^(\d+)$/;
    my $homedir = $options->{'homedir'};
    if (-d $homedir) {
	print STDERR "A directory $homedir already exists. Please decide\n";
	print STDERR "manually, what to do.\n";
	return;
    }

ldapAdmin.PL  view on Meta::CPAN

    system "chown", "-R", "$uidnumber.$gidnumber", $homedir unless $debug;
}


############################################################################
#
#   Name:    ItemList
#
#   Purpose: Read a list of items from the LDAP server
#
#   Inputs:  $prefs - LDAP wizard prefs
#	     $base - Base DN
#            $filter - Filter string
#
#   Returns: Array of items, aborts in case of trouble
#
############################################################################

sub ItemList {
    my($prefs, $base, $filter, $ldap) = @_;
    $ldap ||= LdapConnect($prefs);
    my $msg = $ldap->search('base' => $base, 'filter' => $filter,
			    'scope' => 1);
    die sprintf("Error while searching: code=%s, error=%s",
		$msg->code(), $msg->error())
        if $msg->code() and $msg->code() ne 32;
    ($ldap, $msg->entries());
}


############################################################################

ldapAdmin.PL  view on Meta::CPAN

#   Inputs:  $o - Option list
#            $cfg - LDAP Prefs
#
#   Returns: Nothing, aborts in case of trouble
#
############################################################################

sub FindNets {
    my $o = shift;  my $cfg = shift;

    my($ldap, @entries) = ItemList($cfg, $cfg->{'ldap-prefs-netbase'},
                                   '(objectclass=*)');
    my %a_nets;
    my %ptr_nets;
    foreach my $e (@entries) {
	my $mask = Net::Netmask->new($e->get('mask'));
	my @nets = $mask->inaddr();
	while (@nets) {
	    my $ina = shift @nets;
	    my $firstip = shift @nets;
	    my $lastip = shift @nets;

ldapAdmin.PL  view on Meta::CPAN

#            $nets - MakeNets or FindNets result
#
#   Returns: Nothing, aborts in case of trouble
#
############################################################################

sub MakeHosts {
    my($o, $cfg, $nets) = @_;
    my $a_nets = $nets->{'a_nets'};
    my $ptr_nets = $nets->{'ptr_nets'};
    my $adminDN = $cfg->{'ldap-prefs-adminDN'};
    foreach my $e (@{$nets->{'entries'}}) {
	my $netname = $e->get('netname');
	my @netnames = ref($netname) ? @$netname : ($netname);
	foreach $netname (@netnames) {
	    my $dn = "network=$netname, $cfg->{'ldap-prefs-netbase'}";
	    my($ldap, @hosts) = ItemList($cfg, $dn, "(objectclass=*)",
					 $nets->{'ldap'});
	    foreach my $h (@hosts) {
	        my $name = $h->get('dnsname');
		my @names = ref($name) ? @$name : ($name);
		my $ip = $h->get('ip');
		my @ips = ref($ip) ? @$ip : ($ip);
		foreach $name (@names) {
		    my $found;
		    foreach my $a (sort {length $b <=> length $a}

ldapAdmin.PL  view on Meta::CPAN

}


############################################################################
#
#   This is main()
#
############################################################################

eval {
    my $pfile = $Wizard::LDAP::Config::config->{'ldap-prefs-file'};
    my $cfg = eval { require $pfile }
        or die "Failed to read LDAP prefs from $pfile: $@";

    my %o = (
	'debug' => \$debug,
	'verbose' => \$verbose
    );
    Getopt::Long::GetOptions(\%o, 'debug', 'help', 'hosts', 'nets', 'prefs',
			     'add-user=s', 'homedir=s', 'uidnumber=i',
			     'gidnumber=i', 'verbose');
    $verbose = 1 if $debug and not $verbose;

    if ($o{'help'}) {
	Usage();
    } elsif ($o{'prefs'}) {
	MakePrefs(\%o, $cfg);
	my $nets = MakeNets(\%o, $cfg);
	MakeHosts(\%o, $cfg, $nets);
    } elsif ($o{'nets'}) {
	my $nets = MakeNets(\%o, $cfg);
	MakeHosts(\%o, $cfg, $nets);
    } elsif ($o{'hosts'}) {
	my $nets = FindNets(\%o, $cfg);
	MakeHosts(\%o, $cfg, $nets);
    } elsif (my $user = $o{'add-user'}) {

lib/Wizard/LDAP.pm  view on Meta::CPAN

use Wizard::SaveAble();
use Wizard::LDAP::Config ();

package Wizard::LDAP;

@Wizard::LDAP::ISA = qw(Wizard::State);
$Wizard::LDAP::VERSION = '0.1008';

sub init {
    my $self = shift; 
    my $item = $self->{'prefs'} || die "Missing prefs";
    my $admin = { 'ldap-admin-dn' => $item->{'ldap-prefs-adminDN'},
		  'ldap-admin-password' => $item->{'ldap-prefs-adminPassword'} };
    ($item, $admin);
}

sub Action_Reset {
    my($self, $wiz) = @_;

    # Load prefs, if required.
    unless ($self->{'prefs'}) {
	my $cfg = $Wizard::LDAP::Config::config;
	my $file = $cfg->{'ldap-prefs-file'};
	$self->{'prefs'} = Wizard::SaveAble->new('file' => $file, 'load' => 1);
    }
    $self->Store($wiz);

    # Return the initial menu.
    (['Wizard::Elem::Title', 'value' => 'LDAP Wizard Menu '],
     ['Wizard::Elem::Submit', 'value' => 'User Menu',
      'name' => 'Wizard::LDAP::User::Action_Reset',
      'id' => 1],
     ['Wizard::Elem::Submit', 'value' => 'Net Menu',
      'name' => 'Wizard::LDAP::Net::Action_Reset',

lib/Wizard/LDAP.pm  view on Meta::CPAN

     ['Wizard::Elem::Submit', 'value' => 'LDAP Wizard preferences',
      'name' => 'Action_Preferences',
      'id' => 3],
     ['Wizard::Elem::BR'],
     ['Wizard::Elem::Submit', 'value' => 'Exit LDAP Wizard',
      'id' => 99]);
}

sub Action_Preferences {
    my($self, $wiz) = @_;
    my ($prefs, $admin)  = $self->init();

    # Return a list of input elements.
    (['Wizard::Elem::Title', 'value' => 'LDAP Wizard Preferences'],
     ['Wizard::Elem::Text', 'name' => 'ldap-prefs-serverip',
      'value' => $prefs->{'ldap-prefs-serverip'},
      'descr' => 'Server DNS name or IP Adress of the LDAP Server'],
     ['Wizard::Elem::Text', 'name' => 'ldap-prefs-serverport',
      'value' => $prefs->{'ldap-prefs-serverport'},
      'descr' => 'Server Port of the LDAP Server (default LDAP port on 0)'],
     ['Wizard::Elem::Text', 'name' => 'ldap-prefs-adminDN',
      'value' => $prefs->{'ldap-prefs-adminDN'},
      'descr' => 'Distinguished name of the admin object we bind as ' .
                 'to the server'],
     ['Wizard::Elem::Text', 'name' => 'ldap-prefs-adminPassword',
      'value' => $prefs->{'ldap-prefs-adminPassword'},
      'descr' => 'Password of the admin object'],
     ['Wizard::Elem::Text', 'name' => 'ldap-prefs-nextuid',
      'value' => $prefs->{'ldap-prefs-nextuid'} || '500',
      'descr' => 'Next UID that will be assigned (increased automatically'],
     ['Wizard::Elem::Text', 'name' => 'ldap-prefs-gid',
      'value' => $prefs->{'ldap-prefs-gid'} || '500',
      'descr' => 'Group ID of the group the users will belong to'],
     ['Wizard::Elem::Text', 'name' => 'ldap-prefs-home',
      'value' => $prefs->{'ldap-prefs-home'} || '/home',
      'descr' => 'Homedir prefix'],
     ['Wizard::Elem::Text', 'name' => 'ldap-prefs-userbase',
      'value' => $prefs->{'ldap-prefs-userbase'} || 'dc=ispsoft, c=de',
      'descr' => 'LDAP base for user administration'],
     ['Wizard::Elem::Text', 'name' => 'ldap-prefs-netbase',
      'value' => $prefs->{'ldap-prefs-netbase'} || 'dc=ispsoft, c=de',
      'descr' => 'LDAP base for net administration'],
     ['Wizard::Elem::Text', 'name' => 'ldap-prefs-domain',
      'value' => $prefs->{'ldap-prefs-domain'} || '',
      'descr' => 'Default domain for user administration'],
     ['Wizard::Elem::Text', 'name' => 'ldap-prefs-prefschange',
      'value' => $prefs->{'ldap-prefs-prefschange'} || '',
      'descr' => 'Shell command after the prefs have been changed'],
     ['Wizard::Elem::Text', 'name' => 'ldap-prefs-hostchange',
      'value' => $prefs->{'ldap-prefs-hostchange'} || '',
      'descr' => 'Shell command after Hosts have been changed'],
     ['Wizard::Elem::Text', 'name' => 'ldap-prefs-netchange',
      'value' => $prefs->{'ldap-prefs-netchange'} || '',
      'descr' => 'Shell command after Nets have been changed'],
     ['Wizard::Elem::Text', 'name' => 'ldap-prefs-userchange-new',
      'value' => $prefs->{'ldap-prefs-userchange-new'} || '',
      'descr' => 'Shell command after an user has been created'],
     ['Wizard::Elem::Text', 'name' => 'ldap-prefs-userchange-modify',
      'value' => $prefs->{'ldap-prefs-userchange-modify'} || '',
      'descr' => 'Shell command after an user has been modified'],
     ['Wizard::Elem::Text', 'name' => 'ldap-prefs-userchange-delete',
      'value' => $prefs->{'ldap-prefs-userchange-delete'} || '',
      'descr' => 'Shell command after an user has been deleted'],
     ['Wizard::Elem::Submit', 'name' => 'Action_PreferencesSave',
      'value' => 'Save these settings', 'id' => 1],
     ['Wizard::Elem::Submit', 'name' => 'Action_PreferencesReset',
      'value' => 'Reset this form', 'id' => 98],
     ['Wizard::Elem::Submit', 'name' => 'Action_Reset',
      'value' => 'Return to top menu', 'id' => 99]);
}


#
# universal method, that is supposed to be used by subclasses
#
sub ItemList {
    my($self, $prefs, $admin, $base, $key) = @_;

    my $ldap = Net::LDAP->new($prefs->{'ldap-prefs-serverip'},
			      (($prefs->{'ldap-prefs-serverport'} >0) ?
			       (port => $prefs->{'ldap-prefs-serverport'}) : ()));
    die "Could not create LDAP object, maybe connecting is currently not "
	. "possible , probable cause: $@" 
	    unless ref($ldap);

    my $dn = $admin->{'ldap-admin-dn'};
    my $password = $admin->{'ldap-admin-password'};
    $ldap->bind(dn      => $dn,	password => $password)
	|| die "Cannot bind to LDAP server $@";
    my $mesg = $ldap->search(base => $base,
			     filter => $key . '=*',

lib/Wizard/LDAP.pm  view on Meta::CPAN

	 $mesg->code, ", error=", $mesg->error)  if $mesg->code;

    my @items = map { ($_->get($key)) } $mesg->entries;
    $ldap->unbind();
    wantarray ? @items : $mesg;
}


sub Action_PreferencesSave {
    my($self, $wiz) = @_;
    my ($prefs, $admin) = $self->init();
    foreach my $opt ($wiz->param()) {
	$prefs->{$opt} = $wiz->param($opt) 
	    if (($opt =~ /^ldap\-prefs/) && (defined($wiz->param($opt))));
    }

    my $errors = '';
    my $ip = $prefs->{'ldap-prefs-serverip'} 
        or ($errors .= "Missing Server IP or DNS name.\n");
    my $adminDN = $prefs->{'ldap-prefs-adminDN'}
        or ($errors .= "Missing admin DN.\n");
    my $port = $prefs->{'ldap-prefs-serverport'};
    my $uid = $prefs->{'ldap-prefs-nextuid'};
    my $gid = $prefs->{'ldap-prefs-gid'};
    my $home = $prefs->{'ldap-prefs-home'};
    if($ip) {
	unless(Socket::inet_aton($ip)) {
	    $errors .= "Unresolveable server DNS name $ip.\n";
	}
    }
    $port = 0 if $port eq '';
    $errors .= "Invalid port $port.\n" unless $port =~ /^[\d]*$/;
    $errors .= "Invalid UID $uid" unless $uid =~ /^[\d]+$/;
    $errors .= "Invalid GID $gid" unless $gid =~ /^[\d]+$/;
    if ($home =~ /^((\/[^\/]+)+)\/?$/) {
	$prefs->{'ldap-prefs-home'} = $home = $1;
    } else {
	$errors .= "Invalid home $home";
    }
    die $errors if $errors;
    $prefs->Modified(1);
    $self->Store($wiz, 1);
    $self->OnChange('prefs');
    $self->Action_Reset($wiz);
}

sub Action_PreferencesReset {
    my($self, $wiz) = @_;
    $self->Action_Reset($wiz);
    $self->Action_Preferences($wiz);
}

sub OnChange {
    my $self = shift; my $topic = shift;
    my $mode = shift || '';
    my $subst = shift || {};
    my($prefs) = $self->init();
    my $cmd = $prefs->{'ldap-prefs-' . $topic . 'change' . $mode};
    my ($k, $s);
    while(($k, $s) = each %$subst) {
	$cmd =~ s/\$$k/$s/g;
    }
    my $file = $cmd; $file =~ s/\ .*//g;
    `$cmd` if(-f $file);
}


1;

lib/Wizard/LDAP.pod  view on Meta::CPAN

  http://localhost/admin/ldap.ep

Start with modifying the preferences. See L<THE LDAP-WIZARD PREFERENCES>.


=head1 THE LDAP-WIZARD PREFERENCES

The system wide preferences are accessible via the web form ldap.ep.
The following items can be configured:

=head2 item_ldap_prefs_serverip

This is the IP address of the LDAP server being used, typically

  127.0.0.1.

No default is set.

=head2 item_ldap_prefs_serverport

Likewise, this is the LDAP servers port number. The default is

  389

=head2 item_ldap_prefs_adminDN

This is the distinguished name to use for accessing the LDAP server
as root. No default is set. Example:

  cn=root, dc=ispsoft, dc=de

=head2 item_ldap_prefs_adminPassword

This is the password to use for binding to the LDAP server as root.
Currently the password *must* be stored in clear text. (This is subject
to change.)

=head2 item_ldap_prefs_nextuid

This the next numeric UID, that will assigned to a new user. By default
the value

  500

is choosen. The value is incremented with any new user, so after inserting
the next users it will be 501, 502, 503 and so on. You typically should
reserve some block of Unix UID's for users managed by the LDAP server.

=head2 item_ldap_prefs_gid

This is the numeric GID, that your LDAP users will have under Unix.
The default is

  500

=head2 item_ldap_prefs_home

This is the prefix to use for the users home directories, for example

  /home

(the default). The users login names will be appended.

=head2 item_ldap_prefs_userbase

This is a suffix for constructing the distinguished names of your
users. Example:

  dc=ispsoft, dc=de

=head2 item_ldap_prefs_netbase

A similar suffix for constructing the distinguished names of nets.
Example:

  dc=ispsoft, dc=de


=head2 item_ldap_prefs_domain

The mail domain appended to unclassified email adresses. For example,
if you have a user "joe" and the domain is "ispsoft.de", then its
email adress will be joe@ispsoft.de.


=head2 item_ldap_prefs_prefschange

If you enter a shell command here, then this command will be launched
after any change of the preferences. Example:

  /usr/bin/ldapAdmin --prefs

=head2 item_ldap_prefs_hostchange

This is a similar shell command that will be called after hosts have
changed. Example:

  /usr/bin/ldapAdmin --hosts

=head2 item_ldap_prefs_netchange

A shell command to issue after network definitions have changed. Example:

  /usr/bin/ldapAdmin --nets

=head2 item_ldap_prefs_userchange_new

This is a special case of the command for changing users. If defined, it
will be issued after a user was created. The users name will be appended
as the last argument. If not defined, the above and more generic command
will be executed.

=head2 item_ldap_prefs_userchange_modify

Similar to item_ldap_prefs_userchange_new, but for modified users. Again,
the users name will be appended as a last argument.

=head2 item_ldap_prefs_userchange_delete

Finally a shell command being executed after a user has been deleted.
The users name will be appended as a last argument.

=head1 AUTHORS AND COPYRIGHT

This module is

  Copyright (C) 1999     Jochen Wiedmann
                         Am Eisteich 9

lib/Wizard/LDAP/Config.pm  view on Meta::CPAN

package Wizard::LDAP::Config;
$Wizard::LDAP::Config::config = {
  'ldap-prefs-file' => '/etc/Wizard-LDAP/prefs'
};

lib/Wizard/LDAP/Host.pm  view on Meta::CPAN


sub init {
    my $self = shift; 
    return ($self->SUPER::init(1)) unless shift;
    my $item = $self->{'host'} || die "Missing host";
    ($self->SUPER::init(1), $item);
}


sub ShowMe {
    my($self, $wiz, $prefs, $host) = @_;
    (['Wizard::Elem::Title',
      'value' => $host->CreateMe() ?
          'LDAP Wizard: Create a new host' :
          'LDAP Wizard: Edit an existing host'],
     ['Wizard::Elem::Text', 'name' => 'ldap-host-hostname',
      'value' => $host->{'ldap-host-hostname'},
      'descr' => 'Name of Host'],
     ['Wizard::Elem::Text', 'name' => 'ldap-host-dnsname',
      'value' => $host->{'ldap-host-dnsname'},
      'descr' => 'DNS entry of the host'],

lib/Wizard/LDAP/Host.pm  view on Meta::CPAN

      'value' => 'Return to Host menu', 'id' => 97],
     ['Wizard::Elem::Submit', 'name' => 'Wizard::LDAP::Net::Action_Reset',
      'value' => 'Return to Net menu', 'id' => 98],
     ['Wizard::Elem::Submit', 'name' => 'Wizard::LDAP::Action_Reset',
      'value' => 'Return to top menu', 'id' => 99]);
}


sub Action_Enter {
    my($self, $wiz) = @_;
    my($prefs, $admin) = $self->SUPER::init();
    my $dn = $wiz->param('ldap-net') || die "Missing net name";
    $dn = 'network=' . $dn . ', ' . $prefs->{'ldap-prefs-netbase'};
    my $net = $self->SUPER::Load($wiz, $prefs, $admin, $dn);
    $self->Action_Reset($wiz);
}

sub Action_Reset {
    my($self, $wiz) = @_;
    $self->init();

    delete $self->{'host'};
    $self->Store($wiz);

lib/Wizard/LDAP/Host.pm  view on Meta::CPAN

      'id' => 97],
     ['Wizard::Elem::Submit', 'value' => 'Return to Net Menu',
      'name' => 'Wizard::LDAP::Net::Action_Reset',
      'id' => 98],
     ['Wizard::Elem::Submit', 'value' => 'Exit LDAP Wizard',
      'id' => 99]);
}

sub Action_CreateHost {
    my($self, $wiz) = @_;
    my ($prefs, $admin, $net) = $self->init();
    my $host = Wizard::SaveAble::LDAP->new('adminDN' => $admin->{'ldap-admin-dn'},
					   'adminPassword' => $admin->{'ldap-admin-password'},
					   'prefix' => 'ldap-host-',
					   'serverip' => $prefs->{'ldap-prefs-serverip'},
					   'serverport' => $prefs->{'ldap-prefs-serverport'},
					   );
    my $base = 'network=' . $net->{'ldap-net-netname'} . ', ' 
	     . $prefs->{'ldap-prefs-netbase'};
    my $mesg = $self->ItemList($prefs, $admin, $base, 'hostName');
    my $ip = {}; my $dns = {}; my $hname;
    foreach my $entry ($mesg->entries) {
	my $hname = $entry->get('hostname');
	my @ips = $entry->get('ip'); my @dnss = $entry->get('dnsname');
	map { $ip->{$_} = $hname; } @ips;
	map { $dns->{$_} = $hname; } @dnss;
    }
    my $domain = $net->{'ldap-net-domain'};
    my $ripb = Socket::inet_aton($net->{'ldap-net-reservedipbegin'});
    my $ripe = Socket::inet_aton($net->{'ldap-net-reservedipend'});

lib/Wizard/LDAP/Host.pm  view on Meta::CPAN

	    last;
	}
    }
    my $i = 0;
    while(exists($dns->{"pc" . (++$i) . ".$domain"})) {};
    $host->{'ldap-host-dnsname'} = "pc" . $i . ".$domain";
    
    $host->CreateMe(1);
    $self->{'host'} = $host;
    $self->Store($wiz);
    $self->ShowMe($wiz, $prefs, $host);
}

sub Action_HostSave {
    my($self, $wiz) = @_;
    my ($prefs, $admin, $net, $host) = $self->init(1);
    my $base = "network=" . $net->{'ldap-net-netname'} . ', ' . $prefs->{'ldap-prefs-netbase'};

    foreach my $opt ($wiz->param()) {
	$host->{$opt} = $wiz->param($opt) 
	    if (($opt =~ /^ldap\-host/) && (defined($wiz->param($opt))));
    }

    # Verify settings
    my $errors = '';
    my $name = $host->{'ldap-host-hostname'} 
       or ($errors .= "Missing host name.\n");

lib/Wizard/LDAP/Host.pm  view on Meta::CPAN

    $self->Store($wiz, 1);
    $self->OnChange('host');
    $self->Action_Reset($wiz);
}


sub Action_ModifyHost {
    my $self = shift; my $wiz = shift; 
    my $button = shift || 'Modify Host';
    my $action = shift || 'Action_EditHost'; 
    my ($prefs, $admin, $net) = $self->init();
    my $base = "network=" . $net->{'ldap-net-netname'} . ', ' . $prefs->{'ldap-prefs-netbase'};

    my @items = $self->ItemList($prefs, $admin, $base, 'hostname');
    return $self->Action_Reset($wiz) unless @items;
    @items = sort @items;
    if(@items == 1) {
	$wiz->param('ldap-host', $items[0]);
	return $self->$action($wiz);
    }
    # Return the initial menu.
    (['Wizard::Elem::Title', 'value' => "LDAP Wizard Host Selection"],
     ['Wizard::Elem::Select', 'options' => \@items, 'name' => 'ldap-host',
      'descr' => 'Select a host'],
     ['Wizard::Elem::Submit', 'value' => $button, 'name' => $action,
      'id' => 1]);
}

sub Load {
    my($self, $wiz, $prefs, $admin, $dn) = @_;
    my $host = Wizard::SaveAble::LDAP->new('adminDN' => $admin->{'ldap-admin-dn'},
					   'adminPassword' => $admin->{'ldap-admin-password'},
					   'prefix' => 'ldap-host-',
					   'serverip' => $prefs->{'ldap-prefs-serverip'},
					   'serverport' => $prefs->{'ldap-prefs-serverport'},
					   'dn' => $dn, 'load' => 1);
    $host->AttrRef2Scalar('ip', 'dnsname');
    $host->DN($dn);
    $self->{'host'} = $host;
    $self->Store($wiz);
    $host;
}


sub Action_EditHost {
    my($self, $wiz) = @_;
    my($prefs, $admin, $net) = $self->init();
    my $host = $wiz->param('ldap-host') || die "Missing host name.";
    my $dn = "host=$host, network=" . $net->{'ldap-net-netname'} . ', ' . $prefs->{'ldap-prefs-netbase'};
    $self->ShowMe($wiz, $prefs, $self->Load($wiz, $prefs, $admin, $dn));
}

sub Action_DeleteHost {
    shift->Action_ModifyHost(shift, 'Delete Host', 'Action_DeleteHost2');
}

sub Action_DeleteHost2 {
    my ($self, $wiz) = @_;
    my($prefs, $admin, $net) = $self->init();
    my $hostname = $wiz->param('ldap-host') || die "Missing host.";
    my $dn = "host=$hostname, network=" . $net->{'ldap-net-netname'} . ', ' . $prefs->{'ldap-prefs-netbase'};
    my $host = $self->Load($wiz, $prefs, $admin, $dn);

    (['Wizard::Elem::Title', 'value' => 'Deleting an LDAP Host'],
     ['Wizard::Elem::Data', 'descr' => 'Host name',
      'value' => $host->{'ldap-host-hostname'}],
     ['Wizard::Elem::Data', 'descr' => 'Host dnsname',
      'value' => $host->{'ldap-host-dnsname'}],
     ['Wizard::Elem::Data', 'descr' => 'Host ip',
      'value' => $host->{'ldap-host-ip'}],
     ['Wizard::Elem::Data', 'descr' => 'Host MAC address',
      'value' => $host->{'ldap-host-mac'}],

lib/Wizard/LDAP/Host.pm  view on Meta::CPAN

     ['Wizard::Elem::Submit', 'value' => 'Return to Host Menu',
      'id' => 97, 'name' => 'Action_Reset'],
     ['Wizard::Elem::Submit', 'value' => 'Return to Net Menu',
      'id' => 98, 'name' => 'Wizard::LDAP::Net::Action_Reset'],
     ['Wizard::Elem::Submit', 'value' => 'Return to Top Menu',
      'id' => 99, 'name' => 'Wizard::LDAP::Action_Reset']);
}

sub Action_DeleteHost3 {
    my($self, $wiz) = @_;
    my($prefs, $admin, $net, $host) = $self->init(1);
    $host->Delete();
    $self->OnChange('host');
    $self->Action_Reset($wiz);
}

lib/Wizard/LDAP/Net.pm  view on Meta::CPAN


sub init {
    my $self = shift; 
    return ($self->SUPER::init(1)) unless shift;
    my $item = $self->{'net'} || die "Missing net";
    ($self->SUPER::init(1), $item);
}


sub ShowMe {
    my($self, $wiz, $prefs, $net) = @_;
    (['Wizard::Elem::Title',
      'value' => $net->CreateMe() ?
          'LDAP Wizard: Create a new net' :
          'LDAP Wizard: Edit an existing net'],
     ($net->CreateMe() ? 
        ['Wizard::Elem::Text', 'name' => 'ldap-net-netname',
	 'value' => $net->{'ldap-net-netname'},
	 'descr' => 'Name of net']
      : ['Wizard::Elem::Data' => 'value' => $net->{'ldap-net-netname'},
	 'descr' => 'Name of net']),

lib/Wizard/LDAP/Net.pm  view on Meta::CPAN

     ['Wizard::Elem::BR'],
     ['Wizard::Elem::Submit', 'value' => 'Return to Top Menu',
      'name' => 'Wizard::LDAP::Action_Reset',
      'id' => 98],
     ['Wizard::Elem::Submit', 'value' => 'Exit LDAP Wizard',
      'id' => 99]);
}

sub Action_CreateNet {
    my($self, $wiz) = @_;
    my ($prefs, $admin) = $self->init();
    my $net = Wizard::SaveAble::LDAP->new('adminDN' => $admin->{'ldap-admin-dn'},
					   'adminPassword' => $admin->{'ldap-admin-password'},
					   'prefix' => 'ldap-net-',
					   'serverip' => $prefs->{'ldap-prefs-serverip'},
					   'serverport' => $prefs->{'ldap-prefs-serverport'},
					   );
    $net->CreateMe(1);
    $self->{'net'} = $net;
    $self->Store($wiz);
    $self->ShowMe($wiz, $prefs, $net);
}

sub Action_NetSave {
    my($self, $wiz) = @_;
    my ($prefs, $admin, $net) = $self->init(1);
    my $base = $prefs->{'ldap-prefs-netbase'};
    local $SIG{'__WARN__'} = 'IGNORE';

    foreach my $opt ($wiz->param()) {
	$net->{$opt} = $wiz->param($opt) 
	    if (($opt =~ /^ldap\-net/) && (defined($wiz->param($opt))));
    }

    # Verify settings
    my $errors = '';
    my $name = $net->{'ldap-net-netname'} 

lib/Wizard/LDAP/Net.pm  view on Meta::CPAN

sub Action_HostMenu {
    my $self = shift; my $wiz = shift;
    $self->Action_ModifyNet($wiz, 'Manage hosts in this net',
			     'Wizard::LDAP::Host::Action_Enter');
}

sub Action_ModifyNet {
    my $self = shift; my $wiz = shift; 
    my $button = shift || 'Modify Net';
    my $action = shift || 'Action_EditNet'; 
    my ($prefs, $admin) = $self->init();
    my $base = $prefs->{'ldap-prefs-netbase'};

    my @items = $self->ItemList($prefs, $admin, $base, 'netName');
    return $self->Action_Reset($wiz) unless @items;
    if(@items == 1) {
	# Hack: If there's only one net, pick it up immediately.
	# We need to load the class and bless ... :-(
	if ($action =~ /(.*)::/) {
	    my $class = $1;
	    my $cl = "$class.pm";
	    $cl =~ s/\:\:/\//g;
	    require $cl;
	    bless $self, $class;

lib/Wizard/LDAP/Net.pm  view on Meta::CPAN

    @items = sort @items;
    # Return the initial menu.
    (['Wizard::Elem::Title', 'value' => "LDAP Wizard Net Selection"],
     ['Wizard::Elem::Select', 'options' => \@items, 'name' => 'ldap-net',
      'descr' => 'Select an net'],
     ['Wizard::Elem::Submit', 'value' => $button, 'name' => $action,
      'id' => 1]);
}

sub Load {
    my($self, $wiz, $prefs, $admin, $dn) = @_;
    my $net = Wizard::SaveAble::LDAP->new('adminDN' => $admin->{'ldap-admin-dn'},
					   'adminPassword' => $admin->{'ldap-admin-password'},
					   'prefix' => 'ldap-net-',
					   'serverip' => $prefs->{'ldap-prefs-serverip'},
					   'serverport' => $prefs->{'ldap-prefs-serverport'},
					   'dn' => $dn, 'load' => 1);
    $net->DN($dn);
    $self->{'net'} = $net;
    $self->Store($wiz);
    $net->AttrRef2Scalar('dns', 'wins');
    $net;
}


sub Action_EditNet {
    my($self, $wiz) = @_;
    my($prefs, $admin) = $self->init();
    my $net = $wiz->param('ldap-net') || die "Missing net name.";
    my $dn = "network=$net, " . $prefs->{'ldap-prefs-netbase'};
    my $n = $self->Load($wiz, $prefs, $admin, $dn);
    $self->ShowMe($wiz, $prefs, $n);
}

sub Action_DeleteNet {
    shift->Action_ModifyNet(shift, 'Delete Net', 'Action_DeleteNet2');
}

sub Action_DeleteNet2 {
    my ($self, $wiz) = @_;
    my($prefs, $admin) = $self->init();
    my $netname = $wiz->param('ldap-net') || die "Missing net.";
    my $dn = "network=$netname, " . $prefs->{'ldap-prefs-netbase'};
    my $net = $self->Load($wiz, $prefs, $admin, $dn);

    (['Wizard::Elem::Title', 'value' => 'Deleting an LDAP Net ' . 
      '(and all the hosts belonging to it)'],
     ['Wizard::Elem::Data', 'descr' => 'Net name',
      'value' => $net->{'ldap-net-netname'}],
     ['Wizard::Elem::Data', 'descr' => 'Netmask',
      'value' => $net->{'ldap-net-mask'}],
     ['Wizard::Elem::Data', 'descr' => 'Net domain',
      'value' => $net->{'ldap-net-domain'}],
     ['Wizard::Elem::Data', 'descr' => 'Net DNS server(s)',

lib/Wizard/LDAP/Net.pm  view on Meta::CPAN

     ['Wizard::Elem::Submit', 'value' => 'Yes, delete it',
      'id' => 1, 'name' => 'Action_DeleteNet3'],
     ['Wizard::Elem::Submit', 'value' => 'Return to Net Menu',
      'id' => 98, 'name' => 'Action_Reset'],
     ['Wizard::Elem::Submit', 'value' => 'Return to Top Menu',
      'id' => 99, 'name' => 'Wizard::LDAP::Action_Reset']);
}

sub Action_DeleteNet3 {
    my($self, $wiz) = @_;
    my($prefs, $admin, $net) = $self->init(1);
    ($prefs, $admin) = $self->init();
    my $base =  "network=" . $net->{'ldap-net-netname'} . ", " . $prefs->{'ldap-prefs-netbase'};
    my $mesg = $self->ItemList($prefs, $admin, $base, 'objectClass');
    my $entry;
    my $item = Wizard::SaveAble::LDAP->new('adminDN' => $admin->{'ldap-admin-dn'},
					   'adminPassword' => $admin->{'ldap-admin-password'},
					   'prefix' => 'NONE',
					   'serverip' => $prefs->{'ldap-prefs-serverip'},
					   'serverport' => $prefs->{'ldap-prefs-serverport'});
	
    foreach $entry ($mesg->entries) {
	$item->DN($entry->dn());
	$item->Delete();
    }
    
    $net->Delete();
    $self->OnChange('net');
    $self->Action_Reset($wiz);
}

lib/Wizard/LDAP/User.pm  view on Meta::CPAN


sub init {
    my $self = shift; 
    return ($self->SUPER::init(1)) unless shift;
    my $item = $self->{'user'} || die "Missing user";
    ($self->SUPER::init(1), $item);
}


sub ShowMe {
    my($self, $wiz, $prefs, $user) = @_;
    (['Wizard::Elem::Title',
      'value' => $user->CreateMe() ?
          'LDAP Wizard: Create a new user' :
          'LDAP Wizard: Edit an existing user'],
     ['Wizard::Elem::Data',
      'value' => $user->{'ldap-user-uidnumber'},
      'descr' => 'Users UID'],
     ['Wizard::Elem::Data', 
      'value' => $user->{'ldap-user-gidnumber'},
      'descr' => 'Users GID'],

lib/Wizard/LDAP/User.pm  view on Meta::CPAN

     ['Wizard::Elem::BR'],
     ['Wizard::Elem::Submit', 'value' => 'Return to Top Menu',
      'name' => 'Wizard::LDAP::Action_Reset',
      'id' => 98],
     ['Wizard::Elem::Submit', 'value' => 'Exit LDAP Wizard',
      'id' => 99]);
}

sub Action_CreateUser {
    my($self, $wiz) = @_;
    my ($prefs, $admin) = $self->init();
    my $attr = { 'ldap-user-uidnumber' => $prefs->{'ldap-prefs-nextuid'},
		 'ldap-user-gidnumber' => $prefs->{'ldap-prefs-gid'},
		 'ldap-user-homedirectory' => $prefs->{'ldap-prefs-home'} . '/<login>'};
    my $user = Wizard::SaveAble::LDAP->new('adminDN' => $admin->{'ldap-admin-dn'},
					   'adminPassword' => $admin->{'ldap-admin-password'},
					   'prefix' => 'ldap-user-',
					   'serverip' => $prefs->{'ldap-prefs-serverip'},
					   'serverport' => $prefs->{'ldap-prefs-serverport'},
					   %$attr);
    $user->CreateMe(1);
    $self->{'user'} = $user;
    $self->Store($wiz);
    $self->ShowMe($wiz, $prefs, $user);
}

sub Action_UserSave {
    my($self, $wiz) = @_;
    my ($prefs, $admin, $user) = $self->init(1);
    my $base = $prefs->{'ldap-prefs-userbase'};
    my $oldlogin = $user->{'ldap-user-uid'} || '';

    foreach my $opt ($wiz->param()) {
	$user->{$opt} = $wiz->param($opt) 
	    if (($opt =~ /^ldap\-user/) && (defined($wiz->param($opt))));
    }

    # Verify settings
    my $errors = '';
    my $login = $user->{'ldap-user-uid'} 
       or ($errors .= "Missing user login.\n");
    my $pwd = $user->{'ldap-user-userpassword'};
    $errors .= "Empty user password.\n"
	if $pwd eq '' && $prefs->{'ldap-prefs-passwordcheck'};
    my $uid = $user->{'ldap-user-uidnumber'} 
       or ($errors .= "Missing user UID (internal error).\n");
    my $gid = $user->{'ldap-user-gidnumber'} 
       or ($errors .= "Missing user GID (internal error).\n");
    my $home = $user->{'ldap-user-homedirectory'} 
       or ($errors .= "Missing user home (internal error).\n");
    my $name = $user->{'ldap-user-cn'} 
       or ($errors .= "Missing users name.\n");
    my $status = $user->{'ldap-user-status'} 
       or ($errors .= "Missing users status.\n");
    my $mail = $user->{'ldap-user-mail'} 
       or ($errors .= "Missing users email adress.\n");
    $mail .= $prefs->{'ldap-prefs-domain'} unless $mail =~ /\@/;
    my $mailforward = $user->{'ldap-user-mailforward'};
    my $mailforwardtype = $user->{'ldap-user-mailforwardtype'};
    $user->{'ldap-user-objectClass'} = 'posixAccount';
    $errors .= "Invalid login name: $login.\n"
	unless ($login =~ /^[\d\w]{1,8}$/);
    $errors .= "Invalid status: $status.\n"
	unless exists($RESOLVE_SHELL->{$status});
    die $errors if $errors;
    $user->{'ldap-user-maildrop'} = $login;
    $user->{'ldap-user-maildrop'} = $mailforward
	if(($mailforwardtype eq 'always') && ($mailforward ne ''));

    $user->{'ldap-user-gecos'} = $name;
    $user->{'ldap-user-loginshell'} = $RESOLVE_SHELL->{$status};
    $user->{'ldap-user-homedirectory'} = $prefs->{'ldap-prefs-home'} . '/' . $login;
    $user->AttrScalar2Ref('mail', 'mailforward', 'maildrop');

    my $cmd;
    if ($user->CreateMe()) {
	$prefs->{'ldap-prefs-nextuid'} = $uid + 1;
	$prefs->Modified(1);
	$cmd = $prefs->{'ldap-prefs-userchange-new'};
    } else {
	$cmd = $prefs->{'ldap-prefs-userchange-modify'};
    }
    $user->DN('cn=' . $login . ', ' . $base);

    $cmd =~ s/\$olduid\b/$oldlogin/g;
    $cmd =~ s/\$(\w+)/$user->{"ldap-user-$1"}/g;
    my $opts = delete $user->{'_options'} || {};
    my $opt = delete $user->{'ldap-user-chooseopt'} || '';
    $opt = $opts->{$opt} if exists($opts->{$opt});
    my $program = $cmd;
    $program =~ s/\s.*//;

lib/Wizard/LDAP/User.pm  view on Meta::CPAN

     ['Wizard::Elem::Submit', 'value' => 'Proceed',
      'name' => 'Action_UserSave',
      'id' => 1]);
}


sub Action_ModifyUser {
    my $self = shift; my $wiz = shift; 
    my $button = shift || 'Modify User';
    my $action = shift || 'Action_EditUser'; 
    my ($prefs, $admin) = $self->init();
    my $base = $prefs->{'ldap-prefs-userbase'};

    my @items = $self->ItemList($prefs, $admin,
				$prefs->{'ldap-prefs-userbase'}, 'uid');
    return $self->Action_Reset($wiz) unless @items;
    if(@items == 1) {
	$wiz->param('ldap-user', $items[0]);
	return $self->$action($wiz);
    }
    @items = sort @items;
    
    # Return the initial menu.
    (['Wizard::Elem::Title', 'value' => "LDAP Wizard User Selection"],
     ['Wizard::Elem::Select', 'options' => \@items, 'name' => 'ldap-user',
      'descr' => 'Select an user'],
     ['Wizard::Elem::Submit', 'value' => $button, 'name' => $action,
      'id' => 1]);
}

sub Load {
    my($self, $wiz, $prefs, $admin, $dn) = @_;
    my $user = Wizard::SaveAble::LDAP->new('adminDN' => $admin->{'ldap-admin-dn'},
					   'adminPassword' => $admin->{'ldap-admin-password'},
					   'prefix' => 'ldap-user-',
					   'serverip' => $prefs->{'ldap-prefs-serverip'},
					   'serverport' => $prefs->{'ldap-prefs-serverport'},
					   'dn' => $dn, 'load' => 1);
    $user->DN($dn);
    $self->{'user'} = $user;
    $self->Store($wiz);
    $user->AttrRef2Scalar('mail', 'mailforward');
    $user;
}


sub Action_EditUser {
    my($self, $wiz) = @_;
    my($prefs, $admin) = $self->init();
    my $login = $wiz->param('ldap-user') || die "Missing login.";
    my $dn = "cn=$login, " . $prefs->{'ldap-prefs-userbase'};
    my $user = $self->Load($wiz, $prefs, $admin, $dn);
    $self->ShowMe($wiz, $prefs, $user);
}

sub Action_DeleteUser {
    shift->Action_ModifyUser(shift, 'Delete user', 'Action_DeleteUser2');
}

sub Action_DeleteUser2 {
    my ($self, $wiz) = @_;
    my($prefs, $admin) = $self->init();
    my $login = $wiz->param('ldap-user') || die "Missing login.";
    my $dn = "cn=$login, " . $prefs->{'ldap-prefs-userbase'};
    my $user = $self->Load($wiz, $prefs, $admin, $dn);
    
    (['Wizard::Elem::Title', 'value' => 'Deleting an LDAP user'],
     ['Wizard::Elem::Data', 'descr' => 'Users login',
      'value' => $user->{'ldap-user-uid'}],
     ['Wizard::Elem::Data', 
      'value' => $user->{'ldap-user-userpassword'},
      'descr' => 'Users password'],
     ['Wizard::Elem::Data', 
      'value' => $user->{'ldap-user-uidnumber'},
      'descr' => 'Users UID'],

lib/Wizard/LDAP/User.pm  view on Meta::CPAN

     ['Wizard::Elem::Submit', 'value' => 'Yes, delete it',
      'id' => 1, 'name' => 'Action_DeleteUser3'],
     ['Wizard::Elem::Submit', 'value' => 'Return to User Menu',
      'id' => 98, 'name' => 'Action_Reset'],
     ['Wizard::Elem::Submit', 'value' => 'Return to Top Menu',
      'id' => 99, 'name' => 'Wizard::LDAP::Action_Reset']);
}

sub Action_DeleteUser3 {
    my($self, $wiz) = @_;
    my($prefs, $admin, $user) = $self->init(1);
    $user->Delete();
    $self->OnChange('user', '-delete', {'user' => $user->{'ldap-user-uid'}, 'options' => 
''});
    $self->Action_Reset($wiz);
}



( run in 1.887 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )