1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
bc175c27
|
Assos Assos
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
*/
|
6 |
|
|
|
7 |
85ad3d82
|
Assos Assos
|
/**
|
8 |
|
|
* Implements hook_ctools_plugin_api().
|
9 |
|
|
*/
|
10 |
|
|
function ldap_feeds_ctools_plugin_api($owner, $api) {
|
11 |
|
|
if ($owner == 'feeds' && $api == 'plugins') {
|
12 |
32700c57
|
Assos Assos
|
return ['version' => 1];
|
13 |
85ad3d82
|
Assos Assos
|
}
|
14 |
|
|
}
|
15 |
|
|
|
16 |
|
|
/**
|
17 |
|
|
* Implements hook_feeds_plugins().
|
18 |
|
|
*/
|
19 |
|
|
function ldap_feeds_feeds_plugins() {
|
20 |
|
|
|
21 |
|
|
$path = drupal_get_path('module', 'ldap_feeds');
|
22 |
32700c57
|
Assos Assos
|
$info = [];
|
23 |
85ad3d82
|
Assos Assos
|
|
24 |
32700c57
|
Assos Assos
|
$info['FeedsLdapQueryFetcher'] = [
|
25 |
85ad3d82
|
Assos Assos
|
'name' => 'LDAP Query Fetcher',
|
26 |
|
|
'description' => 'Fetch content from ldap query',
|
27 |
32700c57
|
Assos Assos
|
'handler' => [
|
28 |
|
|
// This is the key name, not the class name.
|
29 |
|
|
'parent' => 'FeedsFetcher',
|
30 |
85ad3d82
|
Assos Assos
|
'class' => 'FeedsLdapQueryFetcher',
|
31 |
|
|
'file' => 'FeedsLdapQueryFetcher.inc',
|
32 |
|
|
'path' => $path,
|
33 |
32700c57
|
Assos Assos
|
],
|
34 |
|
|
];
|
35 |
85ad3d82
|
Assos Assos
|
|
36 |
32700c57
|
Assos Assos
|
$info['FeedsDrupalUserLdapEntryFetcher'] = [
|
37 |
85ad3d82
|
Assos Assos
|
'name' => 'Drupal User LDAP Entry Fetcher',
|
38 |
|
|
'description' => 'Fetches one entry for each LDAP authenticated user. Fetches both LDAP entry attributes such as
|
39 |
|
|
<code>cn, dn,</code> etc.
|
40 |
bc175c27
|
Assos Assos
|
and Drupal user data such as <code>uid, name, mail, created, status, language, </code>and <code>signature</code>.
|
41 |
|
|
Make sure to add dn in your LDAP query for this parser, if you use custom attributes.',
|
42 |
32700c57
|
Assos Assos
|
'handler' => [
|
43 |
|
|
// This is the key name, not the class name.
|
44 |
|
|
'parent' => 'FeedsFetcher',
|
45 |
85ad3d82
|
Assos Assos
|
'class' => 'FeedsDrupalUserLdapEntryFetcher',
|
46 |
|
|
'file' => 'FeedsDrupalUserLdapEntryFetcher.inc',
|
47 |
|
|
'path' => $path,
|
48 |
32700c57
|
Assos Assos
|
],
|
49 |
|
|
];
|
50 |
85ad3d82
|
Assos Assos
|
|
51 |
32700c57
|
Assos Assos
|
$info['FeedsLdapEntryParser'] = [
|
52 |
85ad3d82
|
Assos Assos
|
'name' => t('LDAP Entry Parser for Feeds'),
|
53 |
|
|
'description' => t('Parse an LDAP Entry Array'),
|
54 |
32700c57
|
Assos Assos
|
'handler' => [
|
55 |
85ad3d82
|
Assos Assos
|
'parent' => 'FeedsParser',
|
56 |
|
|
'class' => 'FeedsLdapEntryParser',
|
57 |
|
|
'file' => 'FeedsLdapEntryParser.inc',
|
58 |
|
|
'path' => $path,
|
59 |
32700c57
|
Assos Assos
|
],
|
60 |
|
|
];
|
61 |
85ad3d82
|
Assos Assos
|
|
62 |
|
|
return $info;
|
63 |
|
|
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
/**
|
67 |
|
|
* Implements hook_enable().
|
68 |
|
|
*
|
69 |
|
|
* Clear Feed's plugin cache so that this plugin shows up.
|
70 |
|
|
*/
|
71 |
|
|
function ldap_feeds_enable() {
|
72 |
|
|
cache_clear_all('plugins:feeds:plugins', 'cache');
|
73 |
|
|
}
|
74 |
|
|
|
75 |
32700c57
|
Assos Assos
|
/**
|
76 |
|
|
*
|
77 |
|
|
*/
|
78 |
85ad3d82
|
Assos Assos
|
function ldap_feeds_drupal_user_attributes() {
|
79 |
|
|
|
80 |
32700c57
|
Assos Assos
|
$attributes = [
|
81 |
|
|
'uid' => ['token' => 'drupal.uid', 'description' => 'Drupal used id. e.g. 413'],
|
82 |
|
|
'name' => ['token' => 'drupal.name', 'description' => 'Drupal username. e.g. jdoe'],
|
83 |
|
|
'mail' => ['token' => 'drupal.mail', 'description' => 'Drupal email address. e.g. jdoe@gmail.com'],
|
84 |
|
|
'created' => ['token' => 'drupal.created', 'description' => 'Drupal account created timestamp in unix e.g. 432432432'],
|
85 |
|
|
'status' => ['token' => 'drupal.status', 'description' => 'Drupal user status e.g. 1 or 0'],
|
86 |
|
|
'language' => ['token' => 'drupal.language', 'description' => 'Drupal language.'],
|
87 |
|
|
'signature' => ['token' => 'drupal.signature', 'description' => 'Drupal signature. e.g. Happy Joe'],
|
88 |
|
|
'login' => ['token' => 'drupal.login', 'description' => 'Drupal unix timestamp of last login e.g. 1317494439'],
|
89 |
|
|
'init' => ['token' => 'drupal.init', 'description' => 'Drupal user init e.g. jdoe@gmail.com'],
|
90 |
|
|
];
|
91 |
85ad3d82
|
Assos Assos
|
// ldap_authentication and some other modules may want to add additional drupal user tokens
|
92 |
|
|
// largely derived from the $user->data array, but possibly from related data such as authmaps
|
93 |
32700c57
|
Assos Assos
|
// some use cases for alter are simply edge cases.
|
94 |
85ad3d82
|
Assos Assos
|
drupal_alter('ldap_feeds_drupal_user_attributes', $attributes);
|
95 |
|
|
|
96 |
|
|
return $attributes;
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
/**
|
100 |
32700c57
|
Assos Assos
|
* Show some sample ldap user data to help with mapping interface.
|
101 |
85ad3d82
|
Assos Assos
|
*/
|
102 |
|
|
function ldap_feeds_form_feeds_ui_mapping_form_alter(&$form, &$form_state, $form_id) {
|
103 |
|
|
|
104 |
|
|
$importer = feeds_importer_load($form['#importer']);
|
105 |
|
|
|
106 |
|
|
if ($importer->config['fetcher']['plugin_key'] == 'FeedsDrupalUserLdapEntryFetcher') {
|
107 |
|
|
ldap_feeds_drupal_user_legend($form, $importer);
|
108 |
|
|
}
|
109 |
|
|
elseif ($importer->config['fetcher']['plugin_key'] == 'FeedsLdapQueryFetcher') {
|
110 |
|
|
ldap_feeds_query_legend($form, $importer);
|
111 |
|
|
}
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
/**
|
115 |
32700c57
|
Assos Assos
|
* Add additional data to mapping form for ldap query fetcher.
|
116 |
85ad3d82
|
Assos Assos
|
*/
|
117 |
|
|
function ldap_feeds_query_legend(&$form, $importer) {
|
118 |
|
|
|
119 |
|
|
$source = feeds_source($importer->id);
|
120 |
|
|
$fetcher = feeds_plugin('FeedsLdapQueryFetcher', $source->importer->id);
|
121 |
|
|
}
|
122 |
|
|
|
123 |
32700c57
|
Assos Assos
|
/**
|
124 |
|
|
*
|
125 |
|
|
*/
|
126 |
85ad3d82
|
Assos Assos
|
function _ldap_feeds_query_legend($records, $field_name) {
|
127 |
32700c57
|
Assos Assos
|
$examples = [];
|
128 |
85ad3d82
|
Assos Assos
|
foreach ($records as $i => $record) {
|
129 |
|
|
$examples[] = $record[$field_name];
|
130 |
32700c57
|
Assos Assos
|
if ($i > 5) {
|
131 |
85ad3d82
|
Assos Assos
|
break;
|
132 |
|
|
}
|
133 |
|
|
}
|
134 |
|
|
return join(', ', array_filter($examples));
|
135 |
|
|
}
|
136 |
32700c57
|
Assos Assos
|
|
137 |
85ad3d82
|
Assos Assos
|
/**
|
138 |
32700c57
|
Assos Assos
|
* Add additional data to mapping form for drupal user fetcher.
|
139 |
85ad3d82
|
Assos Assos
|
*/
|
140 |
|
|
function ldap_feeds_drupal_user_legend(&$form, $importer) {
|
141 |
|
|
|
142 |
32700c57
|
Assos Assos
|
$sources = [];
|
143 |
85ad3d82
|
Assos Assos
|
$servers = ldap_servers_get_servers(NULL, 'enabled');
|
144 |
|
|
$form['legendset']['#description'] = "";
|
145 |
|
|
$drupal_user_attributes = $importer->config['fetcher']['config']['availableDrupalUserAttributes'];
|
146 |
|
|
|
147 |
|
|
foreach ($drupal_user_attributes as $attr_name => $attr_conf) {
|
148 |
|
|
$id = $attr_conf['token'];
|
149 |
32700c57
|
Assos Assos
|
$sources[$id] = ['name' => ['#markup' => $id], 'description' => ['#markup' => '']];
|
150 |
85ad3d82
|
Assos Assos
|
}
|
151 |
|
|
|
152 |
|
|
foreach ($servers as $sid => $ldap_server) {
|
153 |
|
|
if ($ldap_server->testingDrupalUsername) {
|
154 |
|
|
$account = user_load_by_name($ldap_server->testingDrupalUsername);
|
155 |
|
|
|
156 |
|
|
foreach ($drupal_user_attributes as $attr_name => $attr_conf) {
|
157 |
|
|
if ($attr_name == 'count') {
|
158 |
|
|
continue;
|
159 |
|
|
}
|
160 |
|
|
$id = $attr_conf['token'];
|
161 |
|
|
if ($account) {
|
162 |
32700c57
|
Assos Assos
|
$sources[$id] = ['name' => ['#markup' => $id], 'description' => ['#markup' => $account->{$attr_name}]];
|
163 |
85ad3d82
|
Assos Assos
|
}
|
164 |
|
|
}
|
165 |
|
|
|
166 |
|
|
$ldap_user = ldap_servers_get_user_ldap_data($ldap_server->testingDrupalUsername, $sid);
|
167 |
|
|
foreach ($ldap_user['attr'] as $id => $value) {
|
168 |
|
|
if (!is_numeric($id) && is_scalar($ldap_user['attr'][$id][0]) && $ldap_user['attr'][$id]['count'] == 1) {
|
169 |
32700c57
|
Assos Assos
|
$sources[$id] = ['name' => ['#markup' => $id], 'description' => ['#markup' => $ldap_user['attr'][$id][0]]];
|
170 |
85ad3d82
|
Assos Assos
|
}
|
171 |
|
|
elseif ($ldap_user['attr'][$id]['count'] > 1) {
|
172 |
|
|
$item = t('MULTIVALUED ATTRIBUTE:') . join(" , \n", $ldap_user['attr'][$id]);
|
173 |
32700c57
|
Assos Assos
|
$sources[$id] = ['name' => ['#markup' => $id], 'description' => ['#markup' => $item]];
|
174 |
85ad3d82
|
Assos Assos
|
}
|
175 |
|
|
}
|
176 |
|
|
$form['legendset']['#description'] .= t('LDAP Attributes in the source "description" column are from testing ldap user (%testing_user) on the server %sid, which is configured in
|
177 |
32700c57
|
Assos Assos
|
the ldap server form.', ['%sid' => $sid, '%testing_user' => $ldap_server->testingDrupalUsername]);
|
178 |
85ad3d82
|
Assos Assos
|
}
|
179 |
|
|
else {
|
180 |
32700c57
|
Assos Assos
|
foreach (['dn' => 'distinguished name', 'cn' => 'cname'] as $id => $value) {
|
181 |
|
|
$sources[$id] = ['name' => ['#markup' => $id], 'description' => ['#markup' => $value]];
|
182 |
85ad3d82
|
Assos Assos
|
}
|
183 |
|
|
}
|
184 |
|
|
}
|
185 |
|
|
$form['legendset']['legend']['sources'] = $sources;
|
186 |
|
|
|
187 |
|
|
} |