ispman/bin ispman.ldifload,1.5,1.6

Joerg Delker <[email protected]>
Newsgroups gmane.comp.isp.ispman.cvs
Message-ID <[email protected]>
Update of /cvsroot/ispman/ispman/bin
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17528/bin

Modified Files:
	ispman.ldifload 
Log Message:
some code cleanup
made output more user friendly

Index: ispman.ldifload
===================================================================
RCS file: /cvsroot/ispman/ispman/bin/ispman.ldifload,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- ispman.ldifload	21 Jun 2004 20:07:26 -0000	1.5
+++ ispman.ldifload	10 Oct 2004 13:21:08 -0000	1.6
@@ -10,7 +10,7 @@
     unless ( $opts{'f'} ) {
         my ($script) = reverse split( "/", $0 );
         print "$script. A utility to load data from ldif to ldap\n\n";
-        print "Usage: $script  -f filename";
+        print "Usage: $script -f filename";
         print "\n\n";
         exit;
     }
@@ -20,26 +20,31 @@
 
 use Net::LDAP::LDIF;
 use ISPMan::LDAP;
-require "ispman.conf"
-  || die
-  "Cant require ispman.conf";   # this will get us all the Config->{} variables.
 
+require "ispman.conf";
+
+# open LDIF filee
 $ldif = Net::LDAP::LDIF->new( $opts{'f'} );
 
+# FIXME
 # Don't want to log for just this. So lets make ISPMan::LDAP happy.
 sub log_event { 1; }
 print "$Config->{'ldapHost'}\n";
 
+# initiate LDAP connection
 my $ldap = ISPMan::LDAP->new(
     $Config->{'ldapBaseDN'}, $Config->{'ldapHost'},
     $Config->{'ldapRootDN'}, $Config->{'ldapRootPass'}
 );
-$ldap->setConfig($Config);      #pass config to ISPMan::LDAP
+
+#pass config to ISPMan::LDAP
+$ldap->setConfig($Config);
 if ( !$ldap->connected() ) {
     $ldap->connect();
-    print "Connected";
+    print "Connected\n\n";
 }
 
+# read in LDIF data
 while ( not $ldif->eof() ) {
     $entry = $ldif->read_entry();
     if ( $ldif->error() ) {
@@ -47,9 +52,22 @@
         print "Error lines:\n", $ldif->error_lines(), "\n";
     }
     else {
+        # try to add entry to LDAP
         $entry->changetype("add");
-        print $entry->dn(), "\n";
-        ISPMan::LDAP::try( $entry->update($ISPMan::LDAP::LDAP) );
+        print "adding ".$entry->dn();
+        my $result=$entry->update($ISPMan::LDAP::LDAP);
+        if ( $result->code == 0 ) {
+            # add succeeded
+            print "... ok!\n";
+        }
+        elsif ( $result->code == 68 ) {
+            # entry already exists
+            print "... already exists, skipping.\n";
+        }
+        else {
+            # other error
+            print "... failed with error ".$result."\n";
+        }
     }
 }
 $ldif->done();



-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.