This file is indexed.

/usr/share/horde/turba/lib/View/Browse.php is in php-horde-turba 4.2.12-1ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
<?php
/**
 * The Turba_View_Browse class provides the logic for browsing lists
 * of contacts.
 *
 * Copyright 2000-2016 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file LICENSE for license information (ASL).  If you did
 * did not receive this file, see http://www.horde.org/licenses/apache.
 *
 * @author  Chuck Hagenbuch <chuck@horde.org>
 * @package Turba
 */
class Turba_View_Browse
{
    /**
     * @var array
     */
     protected $_params;

    /**
     * Constructor;
     *
     * @param array $params Stuff to import into the view's scope.
     */
    public function __construct(array $params)
    {
        $this->_params = $params;
    }

    public function updateSortOrderFromVars()
    {
        extract($this->_params, EXTR_REFS);
        Turba::setPreferredSortOrder($vars, $source);
    }

    public function run()
    {
        extract($this->_params, EXTR_REFS);

        $this->updateSortOrderFromVars();
        $title = _("Address Book Listing");
        if (!$browse_source_count && $vars->get('key') != '**search') {
            $notification->push(_("There are no browseable address books."), 'horde.warning');
        } else {
            try {
                $driver = $factory->create($source);
            } catch (Turba_Exception $e) {
                $notification->push($e, 'horde.error');
                unset($driver);
            }
        }

        if (isset($driver)) {
            $actionID = $vars->get('actionID');
            switch ($actionID) {
            case 'delete':
                $keys = $vars->get('objectkeys');
                if (!is_array($keys)) {
                    break;
                }

                $key = false;
                if ($vars->exists('key')) {
                    $key = $vars->get('key');
                }
                if ($key && $key != '**search') {
                    // We are removing a contact from a list.
                    $errorCount = 0;
                    $list = $driver->getObject($key);
                    foreach ($keys as $sourceKey) {
                        list($objectSource, $objectKey) = explode(':', $sourceKey, 2);
                        if (!$list->removeMember($objectKey, $objectSource)) {
                            $errorCount++;
                        }
                    }
                    if (!$errorCount) {
                        $notification->push(
                            sprintf(_("Successfully removed %d contact(s) from list."),
                                count($keys)),
                            'horde.success');
                    } elseif (count($keys) == $errorCount) {
                        $notification->push(
                            sprintf(_("Error removing %d contact(s) from list."),
                                 count($keys)),
                            'horde.error');
                    } else {
                        $notification->push(
                            sprintf(_("Error removing %d of %d requested contact(s) from list."),
                                $errorCount,
                                count($keys)),
                            'horde.error');
                    }
                    $list->store();
                } else {
                    // We are deleting an object.
                    $errorCount = 0;
                    foreach ($keys as $sourceKey) {
                        list($objectSource, $objectKey) = explode(':', $sourceKey, 2);
                        try {
                            $driver->delete($objectKey);
                        } catch (Turba_Exception $e) {
                            ++$errorCount;
                        }
                    }
                    if (!$errorCount) {
                        $notification->push(
                            sprintf(ngettext("Successfully deleted %d contact.", "Successfully deleted %d contacts.", count($keys)),
                                count($keys)),
                            'horde.success');
                    } elseif (count($keys) == $errorCount) {
                        $notification->push(
                            sprintf(ngettext("Error deleting %d contact.", "Error deleting %d contacts.", count($keys)),
                                count($keys)),
                            'horde.error');
                    } else {
                        $notification->push(
                            sprintf(ngettext("Error deleting %d of %d requested contact.", "Error deleting %d of %d requested contacts.", count($keys)),
                                $errorCount,
                                count($keys)),
                            'horde.error');
                    }
                }
                break;

            case 'move':
            case 'copy':
                $keys = $vars->get('objectkeys');
                if (!(is_array($keys) && $keys)) {
                    break;
                }

                // If we have data, try loading the target address book driver.
                $targetSource = $vars->get('targetAddressbook');

                try {
                    $targetDriver = $factory->create($targetSource);
                } catch (Turba_Exception $e) {
                    $notification->push($e, 'horde.error');
                    break;
                }

                $max_contacts = Turba::getExtendedPermission($targetDriver, 'max_contacts');
                if ($max_contacts !== true &&
                    $max_contacts <= count($targetDriver)) {
                    Horde::permissionDeniedError(
                        'turba',
                        'max_contacts',
                        sprintf(_("You are not allowed to create more than %d contacts in \"%s\"."), $max_contacts, $cfgSources[$targetSource]['title'])
                    );
                    break;
                }

                foreach ($keys as $sourceKey) {
                    // Split up the key into source and object ids.
                    list($objectSource, $objectKey) = explode(':', $sourceKey, 2);

                    // Ignore this entry if the target is the same as the
                    // source.
                    if ($objectSource == $targetDriver->getName()) {
                        continue;
                    }

                    // Try and load the driver for the source.
                    try {
                        $sourceDriver = $factory->create($objectSource);
                    } catch (Turba_Exception $e) {
                        $notification->push($e, 'horde.error');
                        continue;
                    }

                    try {
                        $object = $sourceDriver->getObject($objectKey);
                    } catch (Horde_Exception_NotFound $e) {
                        $notification->push(
                            _("Failed to find object to be added"),
                            'horde.error'
                        );
                        continue;
                    }

                    if ($object->isGroup()) {
                        if ($actionID == 'move') {
                            $notification->push(
                                sprintf(_("\"%s\" was not moved because it is a list."),
                                    $object->getValue('name')),
                                'horde.warning');
                        } else {
                            $notification->push(
                                sprintf(_("\"%s\" was not copied because it is a list."),
                                    $object->getValue('name')),
                                'horde.warning');
                        }
                        continue;
                    }

                    // Try adding to the target.
                    $objAttributes = array();

                    // Get the values through the Turba_Object class.
                    foreach (array_keys($targetDriver->getCriteria()) as $info_key) {
                        if (!is_array($targetDriver->map[$info_key]) ||
                            isset($targetDriver->map[$info_key]['attribute'])) {
                            $objectValue = $object->getValue($info_key);

                            // Get 'data' value if object type is image, the
                            // direct value in other case.
                            $objAttributes[$info_key] =
                                isset($attributes[$info_key]) &&
                                    $attributes[$info_key]['type'] == 'image'
                                    ? $objectValue['load']['data']
                                    : $objectValue;
                        }
                    }
                    unset($objAttributes['__owner']);
                    if ($actionID == 'copy') {
                        unset($objAttributes['__uid']);
                    }

                    try {
                        $targetDriver->add($objAttributes);
                    } catch (Turba_Exception $e) {
                        $notification->push(
                            sprintf(_("Failed to add %s to %s: %s"),
                                $object->getValue('name'),
                                $targetDriver->title,
                                $e),
                            'horde.error');
                        break;
                    }

                    $notification->push(
                        sprintf(_("Successfully added %s to %s"),
                            $object->getValue('name'),
                            $targetDriver->title),
                        'horde.success');

                    // If we're moving objects, and we succeeded,
                    // delete them from the original source now.
                    if ($actionID == 'move') {
                        try {
                            $sourceDriver->delete($objectKey);
                        } catch (Turba_Exception $e) {
                            $notification->push(
                                sprintf(_("There was an error deleting \"%s\" from the source address book."),
                                    $object->getValue('name')),
                                'horde.error');
                        }

                        /* Log the adding of this item in the history again,
                         * because otherwise the delete log would be after the
                         * add log. */
                        try {
                            $history->log('turba:' . $targetDriver->getName() . ':' . $objAttributes['__uid'],
                                      array('action' => 'add'),
                                      true);
                        } catch (Exception $e) {
                            Horde::log($e, 'ERR');
                        }
                    }
                }
                break;

            case 'add':
                // Add a contact to a list.
                $keys = $vars->get('objectkeys');
                $targetKey = $vars->get('targetList');
                if (empty($targetKey)) {
                    break;
                }

                if (!$vars->exists('targetNew') || $vars->get('targetNew') == '') {
                    list($targetSource, $targetKey) = explode(':', $targetKey, 2);
                    if (!isset($cfgSources[$targetSource])) {
                        break;
                    }

                    try {
                        $targetDriver = $factory->create($targetSource);
                    } catch (Turba_Exception $e) {
                        $notification->push($e, 'horde.error');
                        break;
                    }

                    try {
                        $target = $targetDriver->getObject($targetKey);
                    } catch (Horde_Exception $e) {
                        $notification->push($e);
                        break;
                    }
                } else {
                    $targetSource = $vars->get('targetAddressbook');
                    try {
                        $targetDriver = $factory->create($targetSource);
                    } catch (Turba_Exception $e) {
                        $notification->push($e, 'horde.error');
                        break;
                    }
                }
                if (!empty($target) && $target->isGroup()) {
                    // Adding contact to an existing list.
                    if (is_array($keys)) {
                        $errorCount = 0;
                        foreach ($keys as $sourceKey) {
                            list($objectSource, $objectKey) = explode(':', $sourceKey, 2);
                            try {
                                $target->addMember($objectKey, $objectSource);
                            } catch (Turba_Exception $e) {
                                $notification->push($e, 'horde.error');
                                $errorCount++;
                            }
                        }
                        if (!$errorCount) {
                            $notification->push(
                                sprintf(_("Successfully added %d contact(s) to list."),
                                    count($keys)),
                                'horde.success');
                        } elseif ($errorCount == count($keys)) {
                            $notification->push(
                                sprintf(_("Error adding %d contact(s) to list."),
                                    count($keys)),
                                'horde.error');
                        } else {
                            $notification->push(
                                sprintf(_("Error adding %d of %d requested contact(s) to list."),
                                    $errorCount,
                                    count($keys)),
                                'horde.error');
                        }
                        $target->store();
                    }
                } else {
                    // Check permissions.
                    $max_contacts = Turba::getExtendedPermission($driver, 'max_contacts');
                    if ($max_contacts !== true &&
                        $max_contacts <= count($driver)) {
                        Horde::permissionDeniedError(
                            'turba',
                            'max_contacts',
                            sprintf(_("You are not allowed to create more than %d contacts in \"%s\"."),
                                $max_contacts,
                                $cfgSources[$source]['title'])
                        );
                        break;
                    }

                    // Adding contact to a new list.
                    $newList = array(
                        '__owner' => $targetDriver->getContactOwner(),
                        '__type' => 'Group',
                        'name' => $targetKey
                    );

                    try {
                        $targetKey = $targetDriver->add($newList);
                    } catch (Turba_Exception $e) {
                        $notification->push(_("There was an error creating a new list."), 'horde.error');
                        $targetKey = null;
                    }

                    if ($targetKey) {
                        try {
                            $target = $targetDriver->getObject($targetKey);
                            if ($target->isGroup()) {
                                $notification->push(
                                    sprintf(_("Successfully created the contact list \"%s\"."),
                                        $newList['name']),
                                    'horde.success');
                                if (is_array($keys)) {
                                    $errorCount = 0;
                                    foreach ($keys as $sourceKey) {
                                        list($objectSource, $objectKey) = explode(':', $sourceKey, 2);
                                        try {
                                            $target->addMember($objectKey, $objectSource);
                                        } catch (Turba_Exception $e) {
                                            $notification->push($e, 'horde.error');
                                            ++$errorCount;
                                        }
                                    }
                                    if (!$errorCount) {
                                        $notification->push(
                                            sprintf(_("Successfully added %d contact(s) to list."),
                                                count($keys)),
                                            'horde.success');
                                    } elseif ($errorCount == count($keys)) {
                                        $notification->push(
                                            sprintf(_("Error adding %d contact(s) to list."),
                                                count($keys)),
                                            'horde.error');
                                    } else {
                                        $notification->push(
                                            sprintf(_("Error adding %d of %d requested contact(s) to list."),
                                                $errorCount,
                                                count($keys)),
                                            'horde.error');
                                    }
                                    $target->store();
                                }
                            }
                        } catch (Turba_Exception $e) {}
                    }
                }
                break;
            }

            // We might get here from the search page but are not allowed to browse
            // the current address book.
            if ($actionID && empty($cfgSources[$source]['browse'])) {
                Horde::url($prefs->getValue('initial_page'), true)
                    ->redirect();
            }
        }

        $templates = array();
        if (isset($driver)) {
            Turba::addBrowseJs();

            // Read the columns to display from the preferences.
            $sources = Turba::getColumns();
            $columns = isset($sources[$source]) ? $sources[$source] : array();
            $sortorder = Turba::getPreferredSortOrder();

            if ($vars->get('key')) {
                // We are displaying a list.
                try {
                    $list = $driver->getObject($vars->get('key'));
                } catch (Horde_Exception $e) {
                    $notification->push(_("There was an error displaying the list"), 'horde.error');
                    $list = null;
                }

                if ($list && $list->isGroup()) {
                    $title = sprintf(_("Contacts in list: %s"),
                                     $list->getValue('name'));
                    $templates[] = '/browse/header.inc';

                    // Show List Members.
                    try {
                        $results = $list->listMembers($sortorder);
                        if (count($results) != $list->count()) {
                            $count = $list->count() - count($results);
                            $notification->push(
                                sprintf(ngettext("There is %d contact in this list that is not viewable to you",
                                                 "There are %d contacts in this list that are not viewable to you", $count),
                                $count),
                            'horde.message');
                        }
                        $view = new Turba_View_List($results, null, $columns);
                        $view->setType('list');
                    } catch (Turba_Exception $e) {
                        $notification->push(_("Failed to browse list"), 'horde.error');
                    }
                }
            } else {
                // We are displaying an address book.
                $title = $cfgSources[$source]['title'];
                $templates[] = '/browse/header.inc';
                if (empty($cfgSources[$source]['browse'])) {
                    $notification->push(_("Your default address book is not browseable."), 'horde.warning');
                } else {
                    $type_filter = array();
                    switch ($vars->get('show')) {
                    case 'contacts':
                        $type_filter = array('__type' => 'Object');
                        break;

                    case 'lists':
                        $type_filter = array('__type' => 'Group');
                        break;
                    }

                    try {
                        $results = $driver->search($type_filter, $sortorder, 'AND', array_merge(array('__uid'), $columns ? $columns : array('name')));
                        $view = new Turba_View_List($results, null, $columns);
                        $view->setType('directory');
                    } catch (Turba_Exception $e) {
                        $notification->push($e, 'horde.error');
                    }
                }
            }
        } else {
            $templates[] = '/browse/header.inc';
        }

        $page_output->addScriptFile('quickfinder.js', 'horde');
        $page_output->addScriptFile('scriptaculous/effects.js', 'horde');
        $page_output->addScriptFile('redbox.js', 'horde');
        $page_output->header(array(
            'title' => $title
        ));
        $notification->notify(array('listeners' => 'status'));
        foreach ($templates as $template) {
            require TURBA_TEMPLATES . $template;
        }

        if (isset($view) && is_object($view)) {
            $view->display();
        }

        $page_output->footer();
    }

}