/usr/share/horde/gollem/manager.php is in php-horde-gollem 3.0.10-1.
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 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 | <?php
/**
* Gollem main file manager script.
*
* Copyright 1999-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did notcan receive this file, see http://www.horde.org/licenses/gpl.
*
* @author Max Kalika <max@horde.org>
* @author Chuck Hagenbuch <chuck@horde.org>
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/gpl GPL
* @package Gollem
*/
require_once __DIR__ . '/lib/Application.php';
Horde_Registry::appInit('gollem');
$backkey = $session->get('gollem', 'backend_key');
$clipboard = $session->get('gollem', 'clipboard', Horde_Session::TYPE_ARRAY);
$vars = Horde_Variables::getDefaultVariables();
/* Set directory. */
try {
Gollem::changeDir();
} catch (Gollem_Exception $e) {
$notification->push($e);
}
$old_dir = Gollem::$backend['dir'];
/* Get permissions. */
$delete_perms = Gollem::checkPermissions('backend', Horde_Perms::DELETE) &&
Gollem::checkPermissions('directory', Horde_Perms::DELETE, Gollem::$backend['dir']);
$edit_perms = Gollem::checkPermissions('backend', Horde_Perms::EDIT) &&
Gollem::checkPermissions('directory', Horde_Perms::EDIT, Gollem::$backend['dir']);
$read_perms = Gollem::checkPermissions('backend', Horde_Perms::READ) &&
Gollem::checkPermissions('directory', Horde_Perms::READ, Gollem::$backend['dir']);
/* Get VFS object. */
$gollem_vfs = $injector->getInstance('Gollem_Vfs');
/* Run through the action handlers. */
switch ($vars->actionID) {
case 'create_folder':
if ($edit_perms && isset($vars->new_folder)) {
try {
Gollem::createFolder($old_dir, $vars->new_folder);
$notification->push(_("New folder created: ") . $vars->new_folder, 'horde.success');
} catch (Gollem_Exception $e) {
$notification->push($e, 'horde.error');
}
}
break;
case 'rename_items':
if ($edit_perms && isset($vars->new_names) && isset($vars->old_names)) {
$new = explode('|', $vars->new_names);
$old = explode('|', $vars->old_names);
if (count($new) == count($old)) {
for ($i = 0, $iMax = count($new); $i < $iMax; ++$i) {
try {
Gollem::renameItem($old_dir, $old[$i], $old_dir, $new[$i]);
$notification->push(sprintf(_("\"%s\" renamed to \"%s\""), $old[$i], $new[$i]), 'horde.success');
} catch (Gollem_Exception $e) {
$notification->push($e, 'horde.error');
}
}
Gollem::expireCache($old_dir);
}
}
break;
case 'chmod_modify':
case 'delete_items':
if ($delete_perms && is_array($vars->items) && count($vars->items)) {
foreach ($vars->items as $item) {
if (($vars->actionID == 'chmod_modify') && $vars->chmod) {
try {
Gollem::changePermissions(Gollem::$backend['dir'], $item, $vars->chmod);
Gollem::expireCache($old_dir);
$notification->push(_("Chmod done: ") . $item, 'horde.success');
} catch (Gollem_Exception $e) {
$notification->push(sprintf(_("Cannot chmod %s: %s"), $item, $e->getMessage()), 'horde.error');
}
} elseif ($vars->actionID == 'delete_items') {
if ($gollem_vfs->isFolder($old_dir, $item)) {
try {
Gollem::deleteFolder($old_dir, $item);
Gollem::expireCache($old_dir);
$notification->push(_("Folder removed: ") . $item, 'horde.success');
} catch (Gollem_Exception $e) {
$notification->push(sprintf(_("Unable to delete folder %s: %s"), $item, $e->getMessage()), 'horde.error');
}
} else {
try {
Gollem::deleteFile($old_dir, $item);
Gollem::expireCache($old_dir);
$notification->push(_("File deleted: ") . $item, 'horde.success');
} catch (Gollem_Exception $e) {
$notification->push(sprintf(_("Unable to delete file %s: %s"), $item, $e->getMessage()), 'horde.error');
}
}
}
}
}
break;
case 'upload_file':
if ($edit_perms) {
for ($i = 1, $l = count($_FILES); $i <= $l; ++$i) {
$val = 'file_upload_' . $i;
if (isset($_FILES[$val]) && ($_FILES[$val]['error'] != 4)) {
try {
$browser->wasFileUploaded($val);
$filename = Horde_Util::dispelMagicQuotes($_FILES[$val]['name']);
Gollem::writeFile($old_dir, $filename, $_FILES[$val]['tmp_name']);
Gollem::expireCache($old_dir);
$notification->push(sprintf(_("File received: %s"), $filename), 'horde.success');
} catch (Gollem_Exception $e) {
$notification->push($e, 'horde.error');
}
}
}
}
break;
case 'copy_items':
case 'cut_items':
if ($edit_perms) {
$action = ($vars->actionID == 'copy_items') ? 'copy' : 'cut';
if (is_array($vars->items) && count($vars->items)) {
foreach ($vars->items as $item) {
$file = array(
'action' => $action,
'backend' => $backkey,
'display' => Gollem::getDisplayPath($old_dir . '/' . $item),
'name' => $item,
'path' => $old_dir
);
$clipboard[] = $file;
$session->set('gollem', 'clipboard', $clipboard);
if ($action == 'copy') {
$notification->push(sprintf(_("Item copied to clipboard: %s"), $item), 'horde.success');
} else {
$notification->push(sprintf(_("Item cut to clipboard: %s"), $item), 'horde.success');
}
}
} elseif ($action == 'copy') {
$notification->push(_("Cannot copy items onto clipboard."), 'horde.error');
} else {
$notification->push(_("Cannot cut items onto clipboard."), 'horde.error');
}
}
break;
case 'clear_items':
case 'paste_items':
if ($edit_perms && is_array($vars->items) && count($vars->items)) {
foreach ($vars->items as $val) {
if (isset($clipboard[$val])) {
$file = $clipboard[$val];
if ($vars->actionID == 'paste_items') {
try {
if ($file['action'] == 'cut') {
Gollem::moveFile($file['backend'], $file['path'], $file['name'], $backkey, $old_dir);
} else {
Gollem::copyFile($file['backend'], $file['path'], $file['name'], $backkey, $old_dir);
}
Gollem::expireCache($old_dir);
if ($file['action'] == 'cut') {
Gollem::expireCache($file['path']);
}
$notification->push(sprintf(_("%s was successfully pasted."), $file['name'], $old_dir), 'horde.success');
} catch (Horde_Vfs_Exception $e) {
$notification->push(sprintf(_("Cannot paste \"%s\" (file cleared from clipboard): %s"), $file['name'], $e->getMessage()), 'horde.error');
}
}
unset($clipboard[$val]);
}
}
$session->set('gollem', 'clipboard', array_values($clipboard));
}
break;
case 'change_sortby':
if (isset($vars->sortby)) {
$prefs->setValue('sortby', $vars->sortby);
}
break;
case 'change_sortdir':
if (isset($vars->sortdir)) {
$prefs->setValue('sortdir', $vars->sortdir);
}
break;
}
/* First loop through getting folder lists, setting the directory,
* etc., to make sure we can catch any errors. */
$list = null;
try {
$list = Gollem::listFolder(Gollem::$backend['dir']);
} catch (Horde_Exception $e) {
/* If this is a user's home directory, try autocreating it. */
if (Gollem::$backend['dir'] == Gollem::$backend['home']) {
try {
Gollem::createFolder('', Gollem::$backend['dir']);
try {
$list = Gollem::listFolder(Gollem::$backend['dir']);
} catch (Horde_Exception $e) {
/* If that didn't work, fall back to the parent or the home
* directory. */
$notification->push(sprintf(_("Permission denied to folder \"%s\": %s"), Gollem::$backend['dir'], $e->getMessage()), 'horde.error');
$loc = strrpos(Gollem::$backend['dir'], '/');
Gollem::setDir(($loc !== false) ? substr(Gollem::$backend['dir'], 0, $loc) : Gollem::$backend['home']);
$list = Gollem::listFolder(Gollem::$backend['dir']);
}
} catch (Gollem_Exception $e) {
$notification->push(sprintf(_("Cannot create home directory: %s"), $e->getMessage()), 'horde.error');
}
}
}
$numitem = count($list);
$title = Gollem::$backend['name'];
/* Commonly used URLs. */
$view_url = Horde::url('view.php');
$edit_url = Horde::url('edit.php');
$manager_url = Horde::url('manager.php');
$refresh_url = Horde::selfUrl(true, true);
/* Init some form vars. */
if ($session->get('gollem', 'filter') != $vars->searchfield) {
if (strlen($vars->searchfield)) {
$refresh_url->add('searchfield', $vars->searchfield);
} else {
$refresh_url->remove('searchfield');
}
$page = 0;
} else {
$page = $vars->get('page', 0);
}
$session->set('gollem', 'filter', strval($vars->searchfield));
/* Get the list of copy/cut files in this directory. */
$clipboard_files = array();
foreach ($clipboard as $val) {
if (($backkey == $val['backend']) &&
($val['path'] == Gollem::$backend['dir'])) {
$clipboard_files[$val['name']] = 1;
}
}
/* Read the columns to display from the preferences. */
$columns = Gollem::getColumns($backkey);
/* Prepare the template. */
$template = $injector->createInstance('Horde_View');
$attrib = $gollem_vfs->getModifiablePermissions();
foreach (array('owner', 'group', 'all') as $val) {
foreach (array('read', 'write', 'execute') as $val2) {
if (isset($attrib[$val][$val2])) {
$template->{$val . '_' . $val2} = !$attrib[$val][$val2];
}
}
}
$all_columns = array('type', 'name', 'share', 'edit', 'download', 'modified', 'size', 'permission', 'owner', 'group');
foreach ($all_columns as $column) {
$template->{'columns_' . $column} = in_array($column, $columns);
}
$template->action = $refresh_url;
$template->forminput = Horde_Util::formInput();
$template->dir = Gollem::$backend['dir'];
$template->navlink = Gollem::directoryNavLink(Gollem::$backend['dir'], $manager_url);
$template->refresh = Horde::widget(array(
'url' => $refresh_url,
'title' => _("Refresh"),
'id' => 'gollem-refresh'
));
$template->hasclipboard = $edit_perms;
$shares_enabled = !empty(Gollem::$backend['shares']) &&
strpos(Gollem::$backend['dir'], Gollem::$backend['home']) === 0;
if ($shares_enabled) {
$shares = $injector->getInstance('Gollem_Shares');
$perms_url_base = Horde::url('share.php', true)->add('app', 'gollem');
$share_name = $backkey . '|' . Gollem::$backend['dir'];
$template->share_folder = Horde::widget(array(
'url' => $perms_url_base->add('share', $share_name),
'title' => _("Share Folder"),
'target' => '_blank',
'class' => 'gollem-sharefolder',
'onclick' => Horde::popupJs(
$perms_url_base,
array('params' => array('share' => $share_name),
'urlencode' => true)) . 'return false;'
));
}
if ($edit_perms) {
$template->perms_edit = true;
$template->upload_file = _("Upload File(s)");
$template->upload_identifier = session_id();
$template->upload_help = Horde_Help::link('gollem', 'file-upload');
$template->perms_chmod = in_array('permission', $columns);
$injector->getInstance('Horde_View_Sidebar')->addNewButton(
_("Create Folder"),
Horde::url('#'),
array('id' => 'gollem-createfolder')
);
} else {
$template->perms_edit = false;
$template->perms_chmod = false;
}
if ($read_perms) {
$template->change_folder = Horde::widget(array(
'url' => Horde::url('#'),
'title' => _("Change Folder"),
'id' => 'gollem-changefolder'
));
}
if ($numitem) {
$template->list_count = true;
$template->perms_delete = $delete_perms;
$topbar = $injector->getInstance('Horde_View_Topbar');
$topbar->search = true;
$topbar->searchAction = $refresh_url;
$topbar->searchLabel = $session->get('gollem', 'filter') ?: _("Filter");
$topbar->searchIcon = Horde_Themes::img('filter-topbar.png');
} else {
$template->list_count = false;
}
$icon_cache = array();
$total = 0;
if (is_array($list) && $numitem && $read_perms) {
$entry = array();
$page_caption = '';
$template->empty_dir = false;
/* Set list min/max values */
$perpage = $prefs->getValue('perpage');
$min = $page * $perpage;
while ($min > $numitem) {
--$page;
$min = $page * $perpage;
}
$max = $min + $perpage;
foreach ($list as $key => $val) {
/* Check if a filter is not empty and filter matches filename. */
if (strlen($vars->searchfield) &&
!preg_match('/' . preg_quote($vars->searchfield, '/') . '/', $val['name'])) {
continue;
}
/* Continue if item not in min/max range. */
if (($total++ < $min) || ($total > $max)) {
continue;
}
$item = array(
'date' => htmlspecialchars(strftime($prefs->getValue('date_format_mini'), $val['date'])),
'dl' => false,
'edit' => false,
'group' => empty($val['group']) ? '-' : htmlspecialchars($val['group']),
'name' => htmlspecialchars($val['name']),
'on_clipboard' => false,
'owner' => empty($val['owner']) ? '-' : htmlspecialchars($val['owner']),
'perms' => empty($val['perms']) ? '-' : htmlspecialchars($val['perms']),
'size' => ($val['type'] == '**dir') ? '-' : number_format($val['size'], 0, '.', ','),
'type' => htmlspecialchars($val['type'])
);
$name = str_replace(' ', ' ', $item['name']);
/* Is this file on the clipboard? */
if (isset($clipboard_files[$val['name']])) {
$item['on_clipboard'] = true;
}
/* Determine graphic to use. */
if (!empty($val['link'])) {
$item['graphic'] = '<span class="iconImg gollem-symlink"></span>';
} elseif ($val['type'] == '**dir') {
$item['graphic'] = '<span class="iconImg gollem-folder"></span>';
} else {
if (empty($icon_cache[$val['type']])) {
$icon_cache[$val['type']] = Horde::img($injector->getInstance('Horde_Core_Factory_MimeViewer')->getIcon(Horde_Mime_Magic::extToMime($val['type'])), '', '', '');
}
$item['graphic'] = $icon_cache[$val['type']];
}
/* Create proper link. */
switch ($val['type']) {
case '**dir':
$subdir = Gollem::subdirectory(Gollem::$backend['dir'], $val['name']);
if (!Gollem::checkPermissions('directory', Horde_Perms::SHOW, $subdir)) {
continue 2;
}
$item['link'] = $manager_url->copy()->add('dir', $subdir)->link()
. $name . '</a>';
if ($shares_enabled) {
$share = $backkey . '|' . $subdir;
$item['share'] = $perms_url_base->add('share', $share)->link(array('title' => $shares->exists($share) ? _("Shared Folder") : _("Share Folder"), 'target' => '_blank', 'onclick' => Horde::popupJs($perms_url_base, array('params' => array('share' => $share), 'urlencode' => true)) . 'return false;'));
$item['share_disabled'] = !$shares->exists($share);
}
break;
case '**broken':
$item['link'] = $name;
break;
case '**sym':
if ($val['linktype'] === '**dir') {
if (substr($val['link'], 0, 1) == '/') {
$parts = explode('/', $val['link']);
$name = array_pop($parts);
$dir = implode('/', $parts);
} else {
$name = $val['link'];
$dir = Gollem::$backend['dir'];
}
$url = $manager_url->copy()->add('dir', Gollem::subdirectory($dir, $name));
$item['link'] = $item['name'] . ' -> ' . $url->link() . $val['link'] . '</a>';
} else {
$item['link'] = $item['name'] . ' -> ' . $val['link'];
}
break;
default:
$mime_type = Horde_Mime_Magic::extToMime($val['type']);
// Edit link if possible.
if (strpos($mime_type, 'text/') === 0) {
$url = $edit_url->copy()->add(array(
'actionID' => 'edit_file',
'type' => $val['type'],
'file' => $val['name'],
'dir' => Gollem::$backend['dir'],
'driver' => Gollem::$backend['driver']
));
$item['edit'] = Horde::link('#', '', '', '_blank', Horde::popupJs($url));
}
// We can always download files.
$item['dl'] = $registry->downloadUrl($val['name'], array('dir' => Gollem::$backend['dir'], 'backend' => $GLOBALS['session']->get('gollem', 'backend_key')))->link(array('title' => sprintf(_("Download %s"), $val['name'])));
// Try a view link.
$url = $view_url->copy()->add(array(
'type' => $val['type'],
'file' => $val['name'],
'dir' => Gollem::$backend['dir'],
'driver' => Gollem::$backend['driver']
));
$item['link'] = Horde::link('#', '', '', '_blank', Horde::popupJs($url)) . $name . '</a>';
break;
}
$entry[] = $item;
}
/* Set up the variables needed for the header row. */
$sortby = $prefs->getValue('sortby');
$sortdir = $prefs->getValue('sortdir');
if ($total) {
// Set start/end items (according to current page)
$start = ($page * $perpage) + 1;
$end = min($total, $start + $perpage - 1);
$vars->set('page', $page);
$pager = new Horde_Core_Ui_Pager('page', $vars, array(
'num' => $total,
'url' => $refresh_url,
'page_count' => 10,
'perpage' => $perpage
));
$page_caption = $pager->render();
}
$headers = array();
foreach ($columns as $head) {
$hdr = array('class' => '');
$sort = null;
switch ($head) {
case 'type':
$hdr['width'] = '3%';
$hdr['label'] = _("Type");
$hdr['align'] = 'right';
$hdr['id'] = 's' . Gollem::SORT_TYPE;
$sort = Gollem::SORT_TYPE;
break;
case 'name':
$hdr['width'] = '57%';
$hdr['label'] = _("Name");
$hdr['align'] = 'left';
$hdr['id'] = 's' . Gollem::SORT_NAME;
$sort = Gollem::SORT_NAME;
break;
case 'share':
$hdr['width'] = '1%';
$hdr['label'] = ' ';
$hdr['align'] = 'center';
break;
case 'edit':
$hdr['width'] = '1%';
$hdr['label'] = ' ';
$hdr['align'] = 'center';
break;
case 'download':
$hdr['width'] = '1%';
$hdr['label'] = ' ';
$hdr['align'] = 'center';
break;
case 'modified':
$hdr['width'] = '7%';
$hdr['label'] = _("Modified");
$hdr['align'] = 'left';
$hdr['id'] = 's' . Gollem::SORT_DATE;
$sort = Gollem::SORT_DATE;
break;
case 'size':
$hdr['width'] = '7%';
$hdr['label'] = _("Size");
$hdr['align'] = 'right';
$hdr['id'] = 's' . Gollem::SORT_SIZE;
$sort = Gollem::SORT_SIZE;
break;
case 'permission':
$hdr['width'] = '7%';
$hdr['label'] = _("Permission");
$hdr['align'] = 'right';
break;
case 'owner':
$hdr['width'] = '7%';
$hdr['label'] = _("Owner");
$hdr['align'] = 'right';
break;
case 'group':
$hdr['width'] = '7%';
$hdr['label'] = _("Group");
$hdr['align'] = 'right';
break;
}
if ($sort !== null) {
if ($sortby == $sort) {
$hdr['class'] = ($sortdir ? 'sortup' : 'sortdown');
$params = array('actionID' => 'change_sortdir', 'sortdir' => 1 - $sortdir);
} else {
$params = array('actionID' => 'change_sortby', 'sortby' => $sort);
}
$hdr['label'] = '<a href="' . Horde::selfUrl()->add($params) . '" class="sortlink">' . htmlspecialchars($hdr['label']) . '</a>';
}
$headers[] = $hdr;
}
/* Set up the template tags. */
$template->headers = $headers;
$template->entries = $entry;
$template->page_caption = $page_caption;
$template->checkall = Horde::getAccessKeyAndTitle(_("Check _All/None"));
} else {
$template->empty_dir = true;
}
$template->itemcount = sprintf(ngettext(_("%d item"), _("%d items"), $total), $total);
$page_output->addScriptFile('manager.js');
$page_output->addScriptPackage('Horde_Core_Script_Package_Dialog');
$page_output->addInlineJsVars(array(
'var GollemVar' => array(
'actionUrl' => strval(Horde::url('manager.php')),
'empty_input' => intval($GLOBALS['browser']->hasQuirk('empty_file_input_value')),
'warn_recursive' => intval($prefs->getValue('recursive_deletes') == 'warn')
),
'var GollemText' => array(
'change_directory' => _("Change Folder"),
'create_folder' => _("Create Folder"),
'delete_confirm_1' => _("The following items will be permanently deleted:"),
'delete_confirm_2' => _("Are you sure?"),
'delete_recurs_1' => _("The following item(s) are folders:"),
'delete_recurs_2' => _("Are you sure you wish to continue?"),
'file' => _("File"),
'permissions' => _("Permissions"),
'rename' => _("Rename"),
'select_item' => _("Please select an item before this action."),
'specify_upload' => _("Please specify at least one file to upload."),
)
));
$page_output->header(array(
'title' => $title
));
$notification->notify(array('listeners' => 'status'));
echo $template->render('manager');
$page_output->footer();
|