Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- #use strict;
- use Getopt::Long;
- use HTTP::Request;
- use LWP::UserAgent;
- use JSON;
- use SOAP::Lite;
- use Data::Dumper;
- use Net::LDAP;
- my $phone = ''; #'SEPXXXXXX';
- my $provision = 0 ;
- GetOptions ('phone=s' => \$phone, 'provision' => \$provision );
- $phone = uc( $phone ) ; # switch to upper
- our $user = 'XXXXX' ;
- our $password = 'XXXXX' ;
- our $ccmuser = 'XXXXXX' ;
- our $ccmpassword = 'xxxxxx' ;
- our $cucxhost = 'ucxpub.xxxx.local' ;
- our $cucmhost = 'ucspub.xxxx.local' ;
- our $ad_userdn = 'CN=theaccount,DC=xxxx,DC=yyy' ;
- our $ad_basedn = 'OU=ouAccounts,DC=xxxx,DC=yyy' ;
- our @ad_srvs = [ 'dc01.xxxx.yyy', 'dc02.xxxx.yyy' ] ;
- my $unity_base_url = 'https://'.$cucxhost.'/vmrest/' ;
- my @rolesrequired = (
- "Standard CCM End Users", # testing roles "fasoulis","fasoulos",
- "Standard CTI Enabled",
- "Standard CTI Allow Control of Phones supporting Connected Xfer and conf",
- "Standard CTI Allow Control of Phones supporting Rollover Mode",
- );
- my $canprovision = 1;
- $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0;
- #SOAP::Lite->import(+trace); ### use to trace calls
- BEGIN {
- package MyDeserializer;
- @MyDeserializer::ISA = 'SOAP::Deserializer';
- sub typecast {
- my( $self, $val, $name, $attrs, $children, $type ) = @_;
- if( $type && $type =~ m@http://schemas.cisco.com/ast/soap/@) {
- return $val;
- }
- return undef;
- };
- }
- sub SOAP::Transport::HTTP::Client::get_basic_credentials {
- return $ccmuser => $ccmpassword ;
- }
- my $soap = SOAP::Lite->new( proxy => 'https://'.$cucmhost.':8443/axl/', ssl_opts => [ SSL_verify_mode => 0 ] );
- $soap->deserializer( MyDeserializer->new );
- $soap->readable( 1 ) ;
- $soap->on_action( sub { join ' ', 'CUCM:DB ver=9.1', $_[1] } ) ;
- $soap->ns("http://www.cisco.com/AXL/API/9.1");
- $soap->{_transport}->{_proxy}->{ssl_opts}->{verify_hostname} = 0;
- $soap->{_transport}->{_proxy}->{ssl_opts}->{ SSL_verify_mode } = 0;
- $soap->ssl_opts( verify_hostname => 0 );
- my $actions_to_take ;
- ### AXL & LDAP initialization
- my $ldap = Net::LDAP->new( @ad_srvs , scheme => 'ldaps' , onerror => 'undef' ) or die "Could not connect to AD because: $@";
- $ldap->bind( $ad_userdn, password => $password ) or die "Could not bind to AD... password is wrong? ";
- print "INFO! Starting queries, phone is $phone \n";
- ### get phone data, the owner and check it exists
- my $getphoneReq = SOAP::Data->name("name" => $phone ) ;
- my $som_getphone = $soap->call( 'getPhone', $getphoneReq ) ;
- my $getphone_soap_error = cucm_soap_error( $som_getphone ) ;
- if ($som_getphone->fault)
- {
- my $axl_error_code = $som_getphone->faultdetail->{'axlError'}->{'axlcode'};
- if ( $axl_error_code eq '5007' )
- {
- die "ERROR! Phone <$phone> does not exist!\n";
- }
- }
- die "Error contacting CUCM" if ( $getphone_soap_error );
- my $getphone = $som_getphone->result;
- my $owner = $getphone->{'phone'}->{'ownerUserName'};
- my $phone_descr = $getphone->{'phone'}->{'description'};
- my $phone_descr_ext = substr($phone_descr, 0, 4);
- #print Dumper($getphone->{'phone'}->{'lines'}->{'line'}) ; die;
- my $phone_lines_hash = $getphone->{'phone'}->{'lines'}->{'line'} ;
- my @phone_lines ;
- if ( ref $phone_lines_hash eq 'ARRAY' ) # Cisco sends array when multiple lines, single value when not
- {
- @phone_lines = @{ $phone_lines_hash } ;
- }
- else
- {
- push( @phone_lines, $phone_lines_hash );
- }
- my $phone_line_pattern = '';
- my $phone_line_partition = '';
- my $phone_line_displayAscii = '';
- print "INFO! Got ".scalar(@phone_lines)." lines for this phone \n";
- foreach my $line (@phone_lines)
- {
- if ( ($line->{'dirn'}->{'pattern'} eq $phone_descr_ext) && !( $line->{'dirn'}->{'routePartitionName'} =~ /anager/ ) )
- {
- # we found a line on the phone with the same number as description / AD etc
- $phone_line_pattern = $line->{ 'dirn' }->{'pattern'} ;
- $phone_line_partition = $line->{ 'dirn' }->{'routePartitionName'} ;
- $phone_line_displayAscii = $line->{'displayAscii'};
- print "INFO! Got line with number <$phone_line_pattern> on partition <$phone_line_partition>\n" ;
- last;
- }
- }
- print "INFO! owner is <$owner>\n";
- die "FATAL! Phone has no owner, please fix this in order to proceed :(" if $owner eq '' ;
- print "HAPPY! owner exists :)\n";
- print "INFO! phone type is <".$getphone->{'phone'}->{'product'}.">\n";
- print "INFO! phone description is <".$phone_descr.">\n";
- print "INFO! phone extension from description is <".$phone_descr_ext.">\n";
- if ( $phone_descr_ext ne $phone_line_pattern )
- {
- print "ERROR! Phone associated lines do not match description \n" ;
- $canprovision = 0;
- }
- print "HAPPY! Found line on phone that matches description \n";
- ### get user details from CUCM and perform some checks
- my $getuserReq = SOAP::Data->name("userid" => $owner ) ;
- my $som_getuser = $soap->call( 'getUser', $getuserReq ) ;
- die "FATAL! Error contacting CUCM" if ( cucm_soap_error( $som_getphone ) );
- my $getuser = $som_getuser->result;
- my $cucm_userphone = $getuser->{'user'}->{'telephoneNumber'};
- my $cucm_phoneext = substr( $cucm_userphone, -4 );
- my $cucm_user_primaryExtension = $getuser->{'user'}->{'primaryExtension'} ;
- my $cucm_user_enableCti = $getuser->{'user'}->{'enableCti'} ;
- my $cucm_user_imAndPresenceEnable = $getuser->{'user'}->{'imAndPresenceEnable'} ;
- my $cucm_user_serviceProfile = $getuser->{'user'}->{'serviceProfile'} ;
- my $cucm_user_presenceGroupName = $getuser->{'user'}->{'presenceGroupName'} ;
- my $cucm_user_homeCluster = $getuser->{'user'}->{'homeCluster'} ;
- my $cucm_user_associatedGroups = $getuser->{'user'}->{'associatedGroups'} ;
- my $cucm_user_associatedDevices = $getuser->{'user'}->{'associatedDevices'} ;
- print "INFO! cucm user telephone is <$cucm_userphone>\n";
- print "INFO! cucm user phone extension telephone is <$cucm_phoneext>\n";
- if ($cucm_phoneext ne $phone_descr_ext)
- {
- print "ERROR! Phone from description does not match phone in cucm user database (comes from AD)\n" ;
- $canprovision = 0;
- }
- print "HAPPY! phone in description matches cucm user database phone (coming from AD)\n";
- ### get user details from AD and perform some checks
- my $ad_result = $ldap->search(
- base => $ad_basedn,
- scope => 'sub',
- filter => '(&(objectclass=person)(sAMAccountName='.$owner.'))',
- attrs => [ 'telephoneNumber', 'physicalDeliveryOfficeName' ]
- );
- my @ad_entries = $ad_result->entries;
- my $num_entries = scalar( @ad_entries );
- if ( $num_entries != 1 )
- {
- print "ERROR! Got more than $num_entries Active directory entries for <$owner>, something is really wrong\n" ;
- $canprovision = 0;
- }
- print "HAPPY! Got 1 AD entry for <$owner>\n";
- my $ad_userphone = $ad_entries[0]->get_value( "telephoneNumber" );
- my $ad_useroffice = $ad_entries[0]->get_value( "physicalDeliveryOfficeName" );
- my $ad_userphone_ext = substr( $ad_userphone, -4 );
- print "INFO! Active directory user telephone is <$ad_userphone>\n";
- print "INFO! Active directory user phone ext is <$ad_userphone_ext>\n";
- if ( $ad_userphone_ext ne $cucm_phoneext )
- {
- print "ERROR! AD telephone number does not match CUCM phone number! That is strange... Maybe wait 12h for CUCM <-> AD resync \n";
- $canprovision = 0;
- }
- print "HAPPY! phone in AD matches cucm user database phone (coming from AD)\n";
- $ldap->disconnect();
- ### Check jabber phone does not exist
- my $jabber_phone = substr("JAB".$owner,0,15) ; # make it JAB
- print "INFO! Jabber phone name is <$jabber_phone>\n";
- my $getjabphoneReq = SOAP::Data->name("name" => $jabber_phone ) ;
- my $som_getjabphone = $soap->call( 'getPhone', $getjabphoneReq ) ;
- my $getjab_soap_error = cucm_soap_error( $som_getjabphone ) ;
- if ( !( ($getjab_soap_error eq 0) || $getjab_soap_error eq '500' ) )
- {
- print "ERROR! Something is not working properly on getPhone for Jabber phone....\n" ;
- $canprovision = 0;
- }
- if ($som_getjabphone->fault)
- {
- my $axl_error_code = $som_getjabphone->faultdetail->{'axlError'}->{'axlcode'};
- if ( $axl_error_code eq '5007' )
- {
- print "HAPPY! jabber phone does not exist\n";
- my $action_to_take = {};
- $action_to_take->{ 'name' } = $jabber_phone ;
- $action_to_take->{ 'description' } = $phone_descr ;
- $action_to_take->{ 'ownerUserName' } = $owner ;
- $action_to_take->{ 'primaryPhoneName' } = $phone ;
- $action_to_take->{'line'}->{'dirn'}->{ 'pattern' } = $phone_line_pattern ;
- $action_to_take->{'line'}->{'dirn'}->{ 'routePartitionName' } = $phone_line_partition ;
- $action_to_take->{'line'}->{ 'displayAscii' } = $phone_line_displayAscii ;
- $actions_to_take->{'add_jabber_phone'}->{'phone'} = $action_to_take ;
- }
- else
- {
- print Dumper( $som_getjabphone->faultdetail );
- print "ERROR! Didn't expect this!... AXL error on getPhone jabber\n" ;
- $canprovision = 0;
- }
- }
- else
- {
- print "INFO! jabber phone $jabber_phone exists!\n" ;
- }
- ### unity connection checks
- my $url_user = $unity_base_url."users/?query=(alias is $owner)&rowsPerPage=0"; # rowsperpage=0 is the way to get only the count
- print "INFO! User url to search is <$url_user>\n" ;
- my $vmuser_resp = ask_unity( $url_user );
- my $url_import_user = $unity_base_url."import/users/ldap?query=(alias is $owner)";
- print "INFO! Import User url to search is <$url_import_user>\n" ;
- my $vm_import_user_resp = ask_unity( $url_import_user );
- my $url_check_dtmf = $unity_base_url."users/?query=(dtmfAccessId is $ad_userphone_ext)";
- print "INFO! Checking existence of voice mailbox with this extension, URL is: <$url_check_dtmf>\n";
- my $vm_check_dtmf = ask_unity( $url_check_dtmf );
- if ( ( $vmuser_resp->{'@total'} eq '0' ) && ( $vm_import_user_resp->{'@total'} eq '1' ) && ( $vm_check_dtmf->{'@total'} eq '0' ) )
- {
- print "HAPPY! User is not already in unity DB and exists as a user to be imported and extension is not used\n";
- my $action_to_take = {};
- $action_to_take->{ 'alias' } = $owner ;
- $action_to_take->{ 'dtmfAccessId' } = $ad_userphone_ext ;
- $action_to_take->{ 'pkid' } = $vm_import_user_resp->{'ImportUser'}->{'pkid'};
- if ( $ad_useroffice eq 'REMOFFICE' )
- {
- $action_to_take->{'template'} = 'VoiceMail_Users_REMOFFICE' ;
- }
- else
- {
- $action_to_take->{'template'} = 'VoiceMail_Users_HQ' ;
- }
- $actions_to_take->{'add_voicemail'}->{'voicemail'} = $action_to_take ;
- }
- else
- {
- print "INFO! User is already in unity DB!\n" if ( $vmuser_resp->{'@total'} ne '0' ) ;
- print "INFO! User does not exist as an AD importable user... Sync required?!\n" if ( $vm_import_user_resp->{'@total'} ne '1' ) ;
- if ( $vm_check_dtmf->{'@total'} ne '0' )
- {
- print "INFO! Voicemail extension is already assigned to user <".$vm_check_dtmf->{'User'}->{'Alias'}."> <".$vm_check_dtmf->{'User'}->{'DisplayName'}.">\n" ;
- if ( ( $vmuser_resp->{'@total'} eq '0' ) && ( $vm_import_user_resp->{'@total'} eq '1' ) )
- {
- print "ERROR! will not provision because of existence of voice mailbox\n";
- $canprovision = 0 ;
- }
- }
- }
- ### We can now provision the settings
- ### looking at user attributes / small flags first
- #if ( !(defined $cucm_user_primaryExtension && defined $cucm_user_primaryExtension->{'pattern'} && defined $cucm_user_primaryExtension->{'routePartitionName'} ) )
- #if ( !(defined $cucm_user_primaryExtension && defined $cucm_user_primaryExtension->{'pattern'} && defined $cucm_user_primaryExtension->{'routePartitionName'} ) )
- if ( $cucm_user_primaryExtension eq '' )
- {
- $actions_to_take->{'update_user'}->{'user'}->{ 'userid' } = $owner if ( ! defined $actions_to_take->{'update_user'} ) ;
- $actions_to_take->{'update_user'}->{'user'}->{ 'primaryExtension' }->{'pattern'} = $phone_line_pattern ;
- $actions_to_take->{'update_user'}->{'user'}->{ 'primaryExtension' }->{'routePartitionName'} = $phone_line_partition ;
- print "INFO! Will create primary extension for the user\n";
- }
- else
- {
- if ( ($cucm_user_primaryExtension->{'pattern'} ne $phone_line_pattern) || ($cucm_user_primaryExtension->{'routePartitionName'} ne $phone_line_partition) )
- {
- $actions_to_take->{'update_user'}->{'user'}->{ 'userid' } = $owner if ( ! defined $actions_to_take->{'update_user'} ) ;
- $actions_to_take->{'update_user'}->{'user'}->{ 'primaryExtension' }->{'pattern'} = $phone_line_pattern ;
- $actions_to_take->{'update_user'}->{'user'}->{ 'primaryExtension' }->{'routePartitionName'} = $phone_line_partition ;
- print "WARNING! User has primary extension but needs to be changed, was: ".$cucm_user_primaryExtension->{'pattern'}."/".$cucm_user_primaryExtension->{'routePartitionName'} ;
- print " will become: ".$phone_line_pattern."/".$phone_line_partition."\n" ;
- }
- }
- if ( $cucm_user_enableCti ne 'true' )
- {
- $actions_to_take->{'update_user'}->{'user'}->{ 'userid' } = $owner if ( ! defined $actions_to_take->{'update_user'} ) ;
- $actions_to_take->{'update_user'}->{'user'}->{ 'enableCti' } = 'true' ;
- print "INFO! Will set enablecti to true\n";
- }
- if ( $cucm_user_imAndPresenceEnable ne 'true' )
- {
- $actions_to_take->{'update_user'}->{'user'}->{ 'userid' } = $owner if ( ! defined $actions_to_take->{'update_user'} ) ;
- $actions_to_take->{'update_user'}->{'user'}->{ 'imAndPresenceEnable' } = 'true' ;
- print "INFO! Will set imandpresenceenable to true\n";
- }
- if ( $cucm_user_homeCluster ne 'true' )
- {
- $actions_to_take->{'update_user'}->{'user'}->{ 'userid' } = $owner if ( ! defined $actions_to_take->{'update_user'} ) ;
- $actions_to_take->{'update_user'}->{'user'}->{ 'homeCluster' } = 'true' ;
- print "INFO! Will set homecluster to true\n";
- }
- if ( $cucm_user_serviceProfile ne 'Jabber' )
- {
- $actions_to_take->{'update_user'}->{'user'}->{ 'userid' } = $owner if ( ! defined $actions_to_take->{'update_user'} ) ;
- $actions_to_take->{'update_user'}->{'user'}->{ 'serviceProfile' } = 'Jabber' ;
- print "INFO! Will set serviceProfile to Jabber\n";
- }
- if ( $cucm_user_presenceGroupName ne 'PGR_HOME' )
- {
- $actions_to_take->{'update_user'}->{'user'}->{ 'userid' } = $owner if ( ! defined $actions_to_take->{'update_user'} ) ;
- $actions_to_take->{'update_user'}->{'user'}->{ 'presenceGroupName' } = 'PGR_HOME' ;
- print "INFO! Will set presencegroupname to PGR_HOME\n";
- }
- ### now looking at roles associated with the user
- my $currentroles ;
- #print Dumper( $cucm_user_associatedGroups );
- if ( $cucm_user_associatedGroups ne '' )
- {
- if ( ref $cucm_user_associatedGroups->{'userGroup'} eq 'ARRAY' ) # Cisco sends array when multiple lines, single value when not
- {
- foreach my $rolename ( @{$cucm_user_associatedGroups->{'userGroup'}} )
- {
- $currentroles->{ $rolename->{'name'} } = "EXISTS" ;
- }
- }
- else
- {
- my $rolename = $cucm_user_associatedGroups->{'userGroup'} ;
- $currentroles->{ $rolename->{'name'} } = "EXISTS" ;
- }
- }
- foreach my $rolename ( @rolesrequired )
- {
- if ( ! ( defined $currentroles->{ $rolename } ) )
- {
- $actions_to_take->{'update_user_group'}->{'add_member_to_role'}->{ $rolename } = $owner ;
- print "INFO! Will give to user $owner the role $rolename \n";
- }
- }
- #print Dumper( $currentroles );
- ### now checking at associated devices
- my @devicesrequired = ( $jabber_phone, $phone ) ;
- my @currentdevices = ();
- if ( $cucm_user_associatedDevices ne '' )
- {
- if ( ref $cucm_user_associatedDevices->{'device'} eq 'ARRAY' ) # Cisco sends array when multiple lines, single value when not
- {
- @currentdevices = @{$cucm_user_associatedDevices->{'device'}} ;
- }
- else
- {
- push( @currentdevices, $cucm_user_associatedDevices->{'device'} )
- }
- }
- my @newdevices ;
- my $currentdeviceshash ;
- foreach my $device ( @currentdevices )
- {
- $currentdeviceshash->{ $device } = "EXISTS" ;
- }
- foreach my $device ( @devicesrequired )
- {
- if ( ! ( defined $currentdeviceshash->{ $device } ) )
- {
- push( @newdevices, $device );
- }
- }
- if ( scalar(@newdevices) > 0 )
- {
- $actions_to_take->{'update_user'}->{'user'}->{ 'userid' } = $owner if ( ! defined $actions_to_take->{'update_user'} ) ;
- foreach my $device (@currentdevices)
- {
- push(@newdevices, $device);
- }
- $actions_to_take->{'update_user'}->{'user'}->{'associatedDevices'}->{ 'device' } = \@newdevices ;
- print "INFO! Will associate the devices ";
- foreach my $device ( @newdevices ) { print $device." " ; };
- print " to user profile\n" ;
- }
- #print Dumper( $cucm_user_associatedDevices );
- ### Here are the actions to enable the user:
- print "INFO! This is what needs to be provisioned\n";
- print Dumper( $actions_to_take );
- if ( defined $actions_to_take )
- {
- if ( $canprovision && $provision )
- {
- print "\n\nINFO! Starting provisioning:\n";
- ### We've got all the data let's provision....
- #die;
- #print Dumper( keys $actions_to_take );
- if ( defined $actions_to_take->{'add_jabber_phone'} ) { add_jabber_phone( $actions_to_take->{'add_jabber_phone'} ) ; }
- if ( defined $actions_to_take->{'update_user'} ) { update_user( $actions_to_take->{'update_user'} ) ; }
- if ( defined $actions_to_take->{'update_user_group'} ) { update_user_group( $actions_to_take->{'update_user_group'} ) ; }
- if ( defined $actions_to_take->{'add_voicemail'} ) { add_voicemail( $actions_to_take->{'add_voicemail'} ) ; }
- print "INFO Check above information to see if everything went ok\n" ;
- }
- else
- {
- if ( !$canprovision )
- {
- print "INFO! Will not provision because of errors\n";
- }
- if ( !$provision )
- {
- print "INFO! Will not provision because you said so\n";
- }
- }
- }
- else
- {
- print "INFO! Nothing needs to be provisioned, everything seems to be in place\n";
- }
- exit(0);
- sub update_user
- {
- # print "update_user: ".Dumper( $_[0] );
- my $udata = $_[0] ;
- my $theuser = $udata->{'user'}->{'userid'} ;
- my $enablecti = $udata->{'user'}->{'enableCti'} ;
- my $homecluster = $udata->{'user'}->{'homeCluster'} ;
- my $enableforim = $udata->{'user'}->{'imAndPresenceEnable'} ;
- my $serviceprofile = $udata->{'user'}->{'serviceProfile'} ;
- my $presencegroup = $udata->{'user'}->{'presenceGroupName'} ;
- my $ext = $udata->{'user'}->{ 'primaryExtension' }->{'pattern'} ;
- my $par = $udata->{'user'}->{ 'primaryExtension' }->{'routePartitionName'} ;
- my @associateddevs = ();
- if ( defined $udata->{'user'}->{'associatedDevices'}->{'device'} )
- {
- @associateddevs = @{ $udata->{'user'}->{'associatedDevices'}->{'device'} } ;
- }
- my @params = ();
- if ( scalar(@associateddevs) gt 0 )
- {
- my @soapdevarr ;
- my $assosdev ;
- foreach my $dev ( @associateddevs )
- {
- push( @soapdevarr, SOAP::Data->name( 'device' => $dev ) );
- }
- $assosdev = SOAP::Data->name("associatedDevices" => \@soapdevarr );
- push( @params, $assosdev);
- }
- my $userSoap = SOAP::Data->name( 'userid' => $theuser ) ;
- if ( (defined $ext) && ($ext ne '') )
- {
- my $param = SOAP::Data->name( 'primaryExtension' => [ SOAP::Data->name( 'pattern' => $ext )->type('string'),
- SOAP::Data->name( 'routePartitionName' => $par) ] ) ;
- push( @params, $param );
- }
- if( (defined $enablecti) && ($enablecti ne '') ) {
- my $param = SOAP::Data->name( 'enableCti' => $enablecti );
- push( @params, $param ) ;
- }
- if( (defined $presencegroup) && ($presencegroup ne '') ) {
- my $param = SOAP::Data->name( 'presenceGroupName' => $presencegroup );
- push( @params, $param ) ;
- }
- if( (defined $homecluster) && ($homecluster ne '') ) {
- my $param = SOAP::Data->name( 'homeCluster' => $homecluster );
- push( @params, $param ) ;
- }
- if( (defined $enableforim) && ($enableforim ne '') ) {
- my $param = SOAP::Data->name( 'imAndPresenceEnable' => $enableforim );
- push( @params, $param ) ;
- }
- if( (defined $serviceprofile) && ($serviceprofile ne '') ) {
- my $param = SOAP::Data->name( 'serviceProfile' => $serviceprofile );
- push( @params, $param ) ;
- }
- if ( scalar(@params) gt 0 )
- {
- my $som_updu = $soap->call( 'updateUser', $userSoap, @params ) ;
- my $updu_soap_error = cucm_soap_error( $som_updu ) ;
- if ( $updu_soap_error )
- {
- print "INFO! error while updating user $theuser \n";
- # print Dumper( $som_updu)."\n";
- }
- else
- {
- print "INFO! success on update user $theuser ".Dumper($som_updu->result)."\n";
- }
- }
- else
- {
- print "WARNING! No updates needed for $theuser ....skipping (but we should not be here)...\n"
- }
- }
- sub update_user_group
- {
- print "on update_user_group\n";
- # print "update_user_group ".Dumper( $_[0] );
- my $roleactions = $_[0];
- my $rolestoadd = $roleactions->{'add_member_to_role'};
- if ( defined $rolestoadd )
- {
- foreach my $role ( keys %{$rolestoadd} )
- {
- my @soapuserarr ;
- push( @soapuserarr, SOAP::Data->name( 'member' => \SOAP::Data->name( 'userId' => $rolestoadd->{$role} )) );
- my $grouprole = SOAP::Data->name("name" => $role );
- my $assosuserstoadd = SOAP::Data->name("addMembers" => \@soapuserarr );
- my $som_updugroup = $soap->call( 'updateUserGroup', $grouprole, $assosuserstoadd ) ;
- my $updugroup_soap_error = cucm_soap_error( $som_updugroup ) ;
- if ( $updugroup_soap_error )
- {
- print "ERROR! error while adding role $role to ".$rolestoadd->{$role}."\n";
- }
- else
- {
- print "INFO! success on adding role $role to ".$rolestoadd->{$role}." ".Dumper($som_updugroup->result)."\n";
- }
- }
- }
- }
- sub add_jabber_phone
- {
- # print "add_jabber_phone ".Dumper( $_[0] );
- my $phdata = $_[0];
- my $phonemask = "9999XXXX";
- my $jabbphonename = $phdata->{'phone'}->{'name'} ;
- my $owneruid = $phdata->{'phone'}->{'ownerUserName'} ;
- my $phonedescr = $phdata->{'phone'}->{'description'} ;
- my $deskphone = $phdata->{'phone'}->{'primaryPhoneName'} ;
- my $dirnpattern = $phdata->{'phone'}->{'line'}->{'dirn'}->{'pattern'} ;
- my $dirnpartition = $phdata->{'phone'}->{'line'}->{'dirn'}->{'routePartitionName'} ;
- my $linedescription = $phdata->{'phone'}->{'line'}->{'displayAscii'};
- my $addphoneSoap = SOAP::Data->name( 'phone' => [
- SOAP::Data->name( 'name' => $jabbphonename ),
- SOAP::Data->name( 'description' => $phonedescr ),
- SOAP::Data->name( 'product' => 'Cisco Unified Client Services Framework' ),
- SOAP::Data->name( 'class' => 'Phone' ),
- SOAP::Data->name( 'protocol' => 'SIP' ),
- SOAP::Data->name( 'protocolSide' => 'User' ),
- SOAP::Data->name( 'devicePoolName' => 'DEV_Phones' ),
- SOAP::Data->name( 'securityProfileName' => 'Cisco Unified Client Services Framework - Standard SIP Non-Secure' ),
- SOAP::Data->name( 'sipProfileName' => 'Jabber Windows SIP Profile' ),
- SOAP::Data->name( 'lines' => [
- SOAP::Data->name( 'line' => [
- SOAP::Data->name( 'index' => '1' )->type('string'),
- SOAP::Data->name( 'label' => $linedescription ),
- SOAP::Data->name( 'asciilabel' => $linedescription ),
- SOAP::Data->name( 'display' => $linedescription ),
- SOAP::Data->name( 'dirn' => [
- SOAP::Data->name( 'pattern' => $dirnpattern )->type('string'),
- SOAP::Data->name( 'routePartitionName' => $dirnpartition )
- ] ),
- SOAP::Data->name( 'displayAscii' => $linedescription ),
- SOAP::Data->name( 'e164Mask' => $phonemask ),
- ] ),
- ] ),
- SOAP::Data->name( 'phoneTemplateName' => 'Standard Client Services Framework' ),
- SOAP::Data->name( 'primaryPhoneName' => $deskphone ),
- SOAP::Data->name( 'ownerUserName' => $owneruid ),
- ] ) ;
- my $som_addphone = $soap->call( 'addPhone', $addphoneSoap ) ;
- my $addphone_soap_error = cucm_soap_error( $som_addphone ) ;
- if ( $addphone_soap_error )
- {
- print "ERROR! error while adding jabber phone $jabbphonename \n";
- }
- else
- {
- print "INFO! success on provisioning jabber phone $jabbphonename ".Dumper($som_addphone->result)."\n";
- }
- }
- sub add_voicemail
- {
- # print "add_voicemail ".Dumper( $_[0] );
- my $vmdata = $_[0] ;
- my $template = $vmdata->{'voicemail'}->{'template'};
- my $importdata ;
- $importdata->{'alias'} = $vmdata->{'voicemail'}->{'alias'} ;
- $importdata->{'dtmfAccessId'} = $vmdata->{'voicemail'}->{'dtmfAccessId'} ;
- $importdata->{'pkid'} = $vmdata->{'voicemail'}->{'pkid'} ;
- my $json_importdata = to_json( $importdata );
- print Dumper( $json_importdata );
- my $url = $unity_base_url."import/users/ldap?templateAlias=$template";
- #my $url = $_[0];
- my $request = HTTP::Request->new(POST => $url);
- $request->header(
- 'Accept' => 'application/json',
- 'Content_type' => 'application/json'
- );
- $request->content( $json_importdata );
- my $ua = LWP::UserAgent->new( ssl_opts => {
- SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE,
- verify_hostname => 0
- }
- );
- $ua->timeout(30);
- $ua->ssl_opts( verify_hostnames => 0 );
- # my $ua = LWP::UserAgent->new;
- # $ua->timeout(30);
- $ua->credentials("$cucxhost:443", "Cisco VTG Realm", $ccmuser, $ccmpassword);
- my $response = $ua->request($request);
- if( !($response->is_success) )
- {
- print "ERROR! error while importing user in Unity via $url\n" ;
- print "ERRORINFO! voicemail: status: ".$response->status_line."\nERRORINFO! voicemail: Response:".$response->content."\n";
- }
- }
- sub cucm_soap_error
- {
- my $som = $_[0];
- # print Dumper($som);
- my $http_code = $som->{'_context'}->{'_transport'}->{_proxy}->{_code};
- if ( $http_code ne '200' )
- {
- print "INFO! CUCM http code is $http_code\n";
- return $http_code ;
- }
- else
- {
- return 0 ; #undef;
- }
- }
- sub ask_unity
- {
- my $url = $_[0];
- my $request = HTTP::Request->new(GET => $url);
- $request->header(
- 'Accept' => 'application/json',
- 'Content_type' => 'application/json'
- );
- my $ua = LWP::UserAgent->new( ssl_opts => {
- SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE,
- verify_hostname => 0
- }
- );
- $ua->timeout(30);
- $ua->ssl_opts( verify_hostnames => 0 );
- # my $ua = LWP::UserAgent->new;
- # $ua->timeout(30);
- $ua->credentials("$cucxhost:443", "Cisco VTG Realm", $ccmuser, $ccmpassword);
- my $response = $ua->request($request);
- if( !($response->is_success) )
- {
- print "ERROR! error while accessing $url status: ".$response->status_line."\n" ;
- }
- return from_json( $response->content );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement