#!/usr/bin/perl use strict; use CGI; use Net::LDAP; use IPC::System::Simple qw(system capture); #create CGI query object to get the SSO from URL #my $query = new CGI; #my $sso = $query->param( "sso" ); my $sso = shift; if( $sso == "" ) { print ""; print ""; print "

\n\n ERROR: Entered SSO is EMPTY!

\n\n"; die "Empty SSO"; } else { print "

Processing: $sso

\n\n"; #LDAP server with port my $LDAP_SERVER = 'ldaps://ldap.hostname.com:636/ou=enterprise,dc=vds,dc=logon'; my $LDAP_USER = 'bind_user'; my $LDAP_PWD = 'bindpwd'; #base tree to start searching my $BASE = "ou=users,ou=enterprise,dc=vds,dc=logon"; #Just search for the SSO - no group search required. my $FILTER = "(cn=$sso)"; #values to return - we need CN - SSO, First Name, Last Name, and Email my $ATRBS = ['cn', 'givenName', 'sn', 'mail']; #Start LDAP session and bind to LDAP my $ldap = Net::LDAP->new($LDAP_SERVER) or die "$@"; my $mesg = $ldap->bind($LDAP_USER, password=>$LDAP_PWD); my $result = $ldap->search(base => $BASE, filter => $FILTER, attrs => $ATRBS ); my @entries = $result->entries; #only one result should be returned if(@entries == 1) { print "\n\t

Found user $sso in LDAP

\n"; my $usr = $entries[0]; my $firstName = $usr->get_value('givenName'); my $lastName = $usr->get_value('sn'); my $email = $usr->get_value('mail'); print "\t

Creating User account in Application with \n Login name:- $sso \n FullName:- $firstName $lastName \n Email ID:- $email \n

\n\n"; #*********SYSTEM CALL ********** #script within a script both files in same path #This is required because the main script runs with ActiveState Extended Perl v5.24.1 #Whereas cqperl runs with v5.16.1 (limited features), cannot use ActiveState for this one. #*********SYSTEM CALL ********** system( "cqperl NewLdapUser.pl $sso $firstName $lastName $email" ); print "\n\t

Application account created for $sso - $firstName $lastName - $email

\n\n"; } else { #error print "\t

ERROR: Wrong SSO or User doesn't exist in OneAD LDAP

\n\n"; } $mesg = $ldap->unbind; } print "\t

DONE!

\n"; print "";