forked from lukebeer/ocip-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
userList.php
101 lines (88 loc) · 4.27 KB
/
userList.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
* Description: User list and device report to csv by enterprise or system
* Date: 27/05/14
* Time: 12:30
* Author: Luke Beer
* Usage: 'php userList.php [enterpriseID]' Leave [enterpriseID] null for system report
*/
#error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
error_reporting(E_ALL);
echo "Begin...\n";
echo "Including config...\n";
require_once 'config.php';
echo "Including progress bar...\n";
require_once 'Console/ProgressBar.php';
echo "Initial setup...\n";
ini_set("max_execution_time", 0);
date_default_timezone_set('Europe/London');
Factory::getOCISchemaServiceProvider();
Factory::getOCISchemaGroup();
echo "Generating client...\n";
$client = CoreFactory::getOCIClient(OCIP_HOST);
echo "Login...\n";
$client->login(OCIP_USER, OCIP_PASS);
$client->setTimeout(60);
$enterpriseId = $argv[1];
$request = (empty($enterpriseId))
? OCISchemaUser::UserGetListInSystemRequest()
: OCISchemaUser::UserGetListInServiceProviderRequest($enterpriseId);
$filename = (empty($enterpriseId))
? 'system_'.date('d-m-Y_H-i-s').'_enterpriseList.csv'
: $enterpriseId.'_'.date('d-m-Y_H-i-s').'_enterpriseList.csv';
$fh = fopen($filename, 'w');
fputcsv($fh, ['userId', 'serviceProviderId', 'groupId', 'lastName', 'firstName', 'callingLineIdLastName', 'callingLineIdFirstName',
'callingLineIdPhoneNumber', 'phoneNumber', 'departmentFullPath', 'language', 'timeZone', 'countryCode', 'nationalPrefix',
'macAddress', 'deviceType', 'URI', 'currentTime', 'Expiration', 'LinePort']);
$msg = "Fetching users......";
echo $msg;
$client->send($request);
$userTable = $client->getResponse()->userTable['row'];
$totalUsers = count($userTable);
$current = 0;
echo str_repeat(chr(8), strlen($msg));
$bar = new Console_ProgressBar('[%bar%] [current:%current% -%percent% elapsed: %elapsed% remaining: %estimate%]', '=>', ' ', 100, $totalUsers);
foreach ($userTable as $row) {
$userDetails = null;
$client->send(OCISchemaUser::UserGetRequest17sp4($row['col'][0]));
$userResponse = $client->getResponse();
$client->send(OCISchemaUser::UserGetRegistrationListRequest($row['col'][0]));
$registrationResponse = $client->getResponse();
$userDetails['userId'] = $row['col'][0];
$userDetails['serviceProviderId'] = $userResponse->serviceProviderId;
$userDetails['groupId'] = $userResponse->groupId;
$userDetails['lastName'] = $userResponse->lastName;
$userDetails['firstName'] = $userResponse->firstName;
$userDetails['callingLineIdLastName'] = $userResponse->callingLineIdLastName;
$userDetails['callingLineIdFirstName'] = $userResponse->callingLineIdFirstName;
$userDetails['callingLineIdPhoneNumber'] = $userResponse->callingLineIdPhoneNumber;
$userDetails['phoneNumber'] = $userResponse->phoneNumber;
$userDetails['departmentFullPath'] = $userResponse->departmentFullPath;
$userDetails['language'] = $userResponse->language;
$userDetails['timeZone'] = $userResponse->timeZone;
$userDetails['countryCode'] = $userResponse->countryCode;
$userDetails['nationalPrefix'] = $userResponse->nationalPrefix;
if (property_exists($userResponse, 'accessDeviceEndpoint')) {
$client->send(OCISchemaGroup::GroupAccessDeviceGetRequest16($userResponse->serviceProviderId, $userResponse->groupId,
$userResponse->accessDeviceEndpoint['accessDevice']['deviceName']));
$deviceResponse = $client->getResponse();
$userDetails['macAddress'] = $deviceResponse->macAddress;
$userDetails['deviceType'] = $deviceResponse->deviceType;
if (array_key_exists('row', $registrationResponse->registrationTable)) {
foreach ($registrationResponse->registrationTable['row'] as $registration) {
$registration = (array_key_exists('col', $registration)) ? $registration['col'] : $registration;
if ($registration[1] == $userResponse->accessDeviceEndpoint['accessDevice']['deviceName']) {
$userDetails['URI'] = $registration[3];
$userDetails['currentTime'] = date("D M j G:i:s T Y");
$userDetails['Expiration'] = $registration[4];
$userDetails['LinePort'] = $registration[5];
}
}
}
}
$current++;
$bar->update($current);
fputcsv($fh, $userDetails);
}
echo "\nWrote file: $filename\n";
?>