my_collab_lab

User Input Update

I was working with a customer recently that required a zero out option for all users in VM. This is a bit of a task since you cannot adjust via the normal import/export process, but you can “bulk edit by csv” in order to change multiple users at one. This is still a bit of a task since each user import we do have 5-10 different groups with the same zero option, but still doable. The tough question came when they requested a report of wha user zero outs to what extension so they could check a bunch of users they added were in correct. Because you can’t see these options in export your left searching on ciscounitytools.com for a solution, or use the API.

Here are 2 scripts I used to first pull each user with zero options and some other info so that the customer could update a csv file. The second script takes that csv file and updates users accordingly.

Note that this is a sub 1k user setup. The first script pulls all users at once. In a large enviroment this would need to be looped through 1k at a time until complete. Also the update file doesn’t check for fields that don’t exist. So if you tell it to update to nothing, it will. Make sure all “new options” are filled out in the csv or better, delete lines that dont need updated.

Get User Options:


#!/usr/bin/php -q
<?php

function send_cupi($method,$uri,$data) {

  $api['url']           = "https://10.10.10.10";
  $api['auth_token']  = base64_encode('ucadmin:StuffHere');

    $uri .= $data;
    $options = array(
            'http' => array(
                'header'  => "Authorization: Basic ".$api['auth_token'].
                     " \r\nAccept: application/json \r\nContent-type: application/json\r\n",
                'method'  => 'GET',
            ),
        "ssl"=>array(
            "verify_peer"=>false,
            "verify_peer_name"=>false,
            )
        );

    $context  = stream_context_create($options);
    $result = json_decode(file_get_contents($api['url'].$uri, false, $context));

    return $result;
}

$cupiResponse = send_cupi("get","/vmrest/users","");
$count = 0;
foreach ( $cupiResponse->User as $vmUser ) {

    $menuResponse = send_cupi("get","/vmrest/handlers/callhandlers/".$vmUser->CallHandlerObjectId."/menuentries/0","");

    if ( $menuResponse->Action = '7' ){
        $TransferNumber = $menuResponse->TransferNumber;
    } else {
        $TransferNumber = "Not Configured";
    }

    $vmUserList[$count] = array( "Alias"=>$vmUser->Alias
                ,"FirstName"=>@$vmUser->FirstName
                ,"LastName"=>@$vmUser->LastName
                ,"Department"=>@$vmUser->Department
                ,"DtmfAccessId"=>@$vmUser->DtmfAccessId
                ,"ZeroOption"=>@$TransferNumber
                ,"CallHandlerObjectId"=>@$vmUser->CallHandlerObjectId
        );

    foreach ($vmUserList[$count] as $csv) {
        echo $csv.",";
    }
    echo "\n";
    $count++;
}

?>

Update User Options:


#!/usr/bin/php -q
<?php

function send_cupi($method,$uri,$data) {

  $api['url']           = "https://10.10.10.10";
  $api['auth_token']  = base64_encode('ucadmin:password');

    switch ($method) {
        case "get":
            $uri .= $data;
            $options = array(
                'http' => array(
                    'header'  => "Authorization: Basic ".$api['auth_token'].
                         " \r\nAccept: application/json \r\nContent-type: application/json\r\n",
                    'method'  => 'GET',
                ),
                "ssl"=>array(
                    "verify_peer"=>false,
                    "verify_peer_name"=>false,
                    )
                );
        break;
        case "put":
            $options = array(
                'http' => array(
                    'header'  => "Authorization: Basic ".$api['auth_token']." \r\nContent-type: application/json\r\n",
                    'method'  => 'PUT',
                    'content' => json_encode($data),
                ),
            "ssl"=>array(
                "verify_peer"=>false,
                "verify_peer_name"=>false,
                )
            );
        break;
    }
    $context  = stream_context_create($options);
    $result = json_decode(file_get_contents($api['url'].$uri, false, $context));

    return $result;
}

if (($handle = fopen('./update.csv', "r")) !== FALSE) {
    while ( ($data = fgetcsv($handle, 1000, ",")) !== FALSE ) {
        echo $data[6]." - ".$data[7]."\n";

        $updateInfo = array("Action"=>"7","TransferNumber"=>$data[6]);
        $getZeroOut = send_cupi("put","/vmrest/handlers/callhandlers/".$data[7]."/menuentries/0",$updateInfo);

        echo $getZeroOut;

        echo "\n";
    }
    fclose($handle);
}

?>

Posted

in

,

by