-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync.php
More file actions
128 lines (109 loc) · 4.23 KB
/
Copy pathsync.php
File metadata and controls
128 lines (109 loc) · 4.23 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
require_once './fusiondirectory/jsonRPCClient.php'; // fichier venant de l'installation de FusionDirectory.
require_once './google/googleapi.php';
require_once './fusiondirectory/fusionapi.php';
// Instanciation API client and construct the service object.
$gapi = new googleapi();
$fusion = new fusionapi();
$clientGoogle = googleapi::getClient();
$service = new Google_Service_Directory($clientGoogle);
$GLOBALS['results'] = $service->users->listUsers(optParams);
//Initialisation des variables
$GLOBALS['googleTab'] = array();
$GLOBALS['fusionTab'] = array();
$GLOBALS['syncTab'] = array();
//------------------------------------------------------------------MAIN----------------------------------------------------------------------------------------------------------------
//Step 1
if (count($results->getUsers()) == 0) {
print "No users found.\n";
} else {
searchUsers();
}
//Step 2
fusionDir();
//Step 3
crudUser();
//------------------------------------------------------------------Fonctions-----------------------------------------------------------------------------------------------------------------------
/**
* Recherche de l'ensemble des users
*/
function searchUsers() {
print "Users:\n";
foreach ($GLOBALS['results']->getUsers() as $user) {
$googleUsers = array(
'name' => $user->getName()->getGivenName(),
'familyname' => $user->getName()->getFamilyName(),
'mail' => $user->getPrimaryEmail(),
);
array_push($GLOBALS['googleTab'], $googleUsers);
}
}
/**
* Récupération des utilisateurs FusionDirectory
*/
function fusionDir() {
//Instanciation
$client = fusionapi::connecRPCClient();
/* Then we need to login. Here we log in the default LDAP */
$session_id = $client->login(NULL, login, password);
$attr = array(
'mail' => 1,
'givenName' => 1,
'sn' => 1,
'uid' => 1,
);
/* Once we have a session ID, we can ask for the list of users */
$users = $client->ls($session_id, 'user', $attr);
foreach ($users as $dn => $user) {
if (isset($user['mail'])) {
$fdMail = $user['mail'];
} else {
$fdMail = '';
}
$fusionUsers = array(
'name' => $user['givenName'],
'familyname' => $user['sn'],
'mail' => $fdMail,
);
array_push($GLOBALS['fusionTab'], $fusionUsers);
}
}
/**
* Fonction de modification et ajout d'utilisateur de Google Apps vers Fusion Directory
*/
function crudUser() {
// merci kim !
echo '----------------------';
echo "\n";
$nbr = 0;
foreach ($GLOBALS['googleTab'] as $value1) {
if (in_array($value1, $GLOBALS['fusionTab'])) {
$nbr++;
echo $value1['familyname'];
echo ' - ';
echo 'Nothing to do';
echo "\n";
} else {
$exist = FALSE;
foreach ($GLOBALS['fusionTab'] as $valueFusion) {
if ($valueFusion['mail'] == $value1['mail']) {
$exist = TRUE;
echo 'Modifier user ';
echo $value1['mail'];
echo ' => ';
fusionapi::modifyUser($value1['name'], $value1['familyname'], $value1['mail']);
break;
}
}
if ($exist == FALSE) {
array_push($GLOBALS['syncTab'], $valueFusion);
echo 'Ajouter user ';
echo $value1['mail'];
echo ' - ';
fusionapi::addUser($value1['name'], $value1['familyname'], $value1['mail']);
}
echo "\n";
}
}
}
// Remerciements : Kim, Antoine, Samia