/usr/share/horde/gollem/lib/Application.php is in php-horde-gollem 3.0.7-1build1.
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 | <?php
/**
* Gollem application API.
*
* This file defines Horde's core API interface. Other core Horde libraries
* can interact with Horde through this API.
*
* Copyright 2010-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @author Jan Schneider <jan@horde.org>
* @author Michael Slusarz <slusarz@horde.org>
* @author Ben Klang <bklang@horde.org>
* @author Amith Varghese <amith@xalan.com>
* @category Horde
* @license http://www.horde.org/licenses/gpl GPL
* @package Gollem
*/
/* Determine the base directories. */
if (!defined('GOLLEM_BASE')) {
define('GOLLEM_BASE', realpath(__DIR__ . '/..'));
}
if (!defined('HORDE_BASE')) {
/* If Horde does not live directly under the app directory, the HORDE_BASE
* constant should be defined in config/horde.local.php. */
if (file_exists(GOLLEM_BASE . '/config/horde.local.php')) {
include GOLLEM_BASE . '/config/horde.local.php';
} else {
define('HORDE_BASE', realpath(GOLLEM_BASE . '/..'));
}
}
/* Load the Horde Framework core (needed to autoload
* Horde_Registry_Application::). */
require_once HORDE_BASE . '/lib/core.php';
class Gollem_Application extends Horde_Registry_Application
{
/**
*/
public $auth = array(
'authenticate',
'transparent',
'validate'
);
/**
*/
public $version = 'H5 (3.0.7)';
/**
* Server key used in logged out session.
*
* @var string
*/
protected $_oldbackend = null;
protected function _bootstrap()
{
$GLOBALS['injector']->bindFactory('Gollem_Vfs', 'Gollem_Factory_VfsDefault', 'create');
$GLOBALS['injector']->bindFactory('Gollem_Shares', 'Gollem_Factory_Shares', 'create');
}
/**
*/
protected function _init()
{
if ($backend_key = $GLOBALS['session']->get('gollem', 'backend_key')) {
Gollem_Auth::changeBackend($backend_key);
}
}
/**
*/
public function perms()
{
$perms = array(
'backends' => array(
'title' => _("Backends")
)
);
// Run through every backend.
foreach (Gollem_Auth::getBackend() as $key => $val) {
$perms['backends:' . $key] = array(
'title' => $val['name']
);
}
return $perms;
}
/* Horde_Core_Auth_Application methods. */
/**
* Return login parameters used on the login page.
*
* @return array See Horde_Core_Auth_Application#authLoginParams().
*/
public function authLoginParams()
{
$params = array();
if ($GLOBALS['conf']['backend']['backend_list'] == 'shown') {
$backend_list = array();
$selected = is_null($this->_oldbackend)
? Horde_Util::getFormData('backend_key', Gollem_Auth::getPreferredBackend())
: $this->_oldbackend;
foreach (Gollem_Auth::getBackend() as $key => $val) {
$backend_list[$key] = array(
'name' => $val['name'],
'selected' => ($selected == $key)
);
if ($selected == $key) {
if (!empty($val['loginparams'])) {
foreach ($val['loginparams'] as $param => $label) {
$params[$param] = array(
'label' => $label,
'type' => 'text',
'value' => isset($val['params'][$param]) ? $val['params'][$param] : ''
);
}
}
if (Gollem_Auth::canAutoLogin($key)) {
$params['horde_user'] = null;
$params['horde_pass'] = null;
}
}
}
$params['backend_key'] = array(
'label' => _("Backend"),
'type' => 'select',
'value' => $backend_list
);
}
return array(
'js_code' => array(),
'js_files' => array(array('login.js', 'gollem'),
array('scriptaculous/effects.js', 'horde'),
array('redbox.js', 'horde')),
'params' => $params
);
}
/**
* Tries to authenticate with the server and create a session.
*
* @param string $userId The username of the user.
* @param array $credentials Credentials of the user. Allowed keys:
* 'backend', 'password'.
*
* @throws Horde_Auth_Exception
*/
public function authAuthenticate($userId, $credentials)
{
$this->init();
if (empty($credentials['backend_key'])) {
$credentials['backend_key'] = Gollem_Auth::getPreferredBackend();
}
$credentials['userId'] = $userId;
$this->_addSessVars(Gollem_Auth::authenticate($credentials));
}
/**
* Tries to transparently authenticate with the server and create a
* session.
*
* @param Horde_Core_Auth_Application $auth_ob The authentication object.
*
* @return boolean Whether transparent login is supported.
* @throws Horde_Auth_Exception
*/
public function authTransparent($auth_ob)
{
$this->init();
if ($result = Gollem_Auth::transparent($auth_ob)) {
$this->_addSessVars($result);
return true;
}
return false;
}
/**
* Validates an existing authentication.
*
* @return boolean Whether the authentication is still valid.
*/
public function authValidate()
{
if (($backend_key = Horde_Util::getFormData('backend_key')) &&
$backend_key != $GLOBALS['session']->get('gollem', 'backend_key')) {
Gollem_Auth::changeBackend($backend_key);
}
return !empty(Gollem::$backend['auth']);
}
/**
*/
public function menu($menu)
{
$backend_key = Gollem_Auth::getPreferredBackend();
$menu->add(
Horde::url('manager.php')->add('dir', Gollem::$backend['home']),
_("Start Folder"),
'gollem-home',
null,
null,
null,
'__noselection');
if (Gollem::checkPermissions('backend', Horde_Perms::EDIT) &&
Gollem::checkPermissions('directory', Horde_Perms::EDIT, Gollem::$backend['dir']) &&
$GLOBALS['session']->get('gollem', 'clipboard', Horde_Session::TYPE_ARRAY)) {
$menu->add(
Horde::url('clipboard.php')->add('dir', Gollem::$backend['dir']),
_("Clipboard"),
'gollem-clipboard');
}
if (!empty(Gollem::$backend['quota'])) {
if ($GLOBALS['browser']->hasFeature('javascript')) {
$quota_url = 'javascript:' . Horde::popupJs(
Horde::url('quota.php'),
array('params' => array('backend' => $backend_key),
'height' => 300,
'width' => 300,
'urlencode' => true)
);
} else {
$quota_url = Horde::url('quota.php')
->add('backend', $backend_key);
}
$menu->add($quota_url, _("Check Quota"), 'gollem-quota');
}
if ($GLOBALS['registry']->isAdmin() &&
!($GLOBALS['injector']->getInstance('Horde_Perms') instanceof Horde_Perms_Null)) {
$menu->add(
Horde::url('permissions.php')->add('backend', $backend_key),
_("_Permissions"), 'horde-perms');
}
}
/**
* Add additional items to the sidebar.
*
* @param Horde_View_Sidebar $sidebar The sidebar object.
*/
public function sidebar($sidebar)
{
$backend = Gollem_Auth::getPreferredBackend();
$url = $GLOBALS['registry']->getServiceLink('login', 'horde')
->add(array('url' => (string)Horde::url('manager.php', true),
'app' => 'gollem'));
if ($GLOBALS['conf']['backend']['backend_list'] == 'shown') {
foreach (Gollem_Auth::getBackend() as $key => $val) {
$row = array(
'selected' => $backend == $key,
'url' => $url->add('backend_key', $key),
'label' => $val['name'],
'type' => 'radiobox',
);
$sidebar->addRow($row, 'backends');
}
}
}
/* Topbar method. */
/**
*/
public function topbarCreate(Horde_Tree_Renderer_Base $tree, $parent = null,
array $params = array())
{
$icon = Horde_Themes::img('gollem.png');
$url = Horde::url('manager.php');
foreach (Gollem_Auth::getBackend() as $key => $val) {
$tree->addNode(array(
'id' => $parent . $key,
'parent' => $parent,
'label' => $val['name'],
'expanded' => false,
'params' => array(
'icon' => $icon,
'url' => $url->add(array('backend_key' => $key))
)
));
}
}
/* Download data. */
/**
* URL parameters needed:
* - dir
* - driver
*
* @throws Horde_Vfs_Exception
*/
public function download(Horde_Variables $vars)
{
$vfs = $GLOBALS['injector']
->getInstance('Gollem_Factory_Vfs')
->create($vars->backend);
$res = array(
'data' => is_callable(array($vfs, 'readStream'))
? $vfs->readStream($vars->dir, $vars->filename)
: $vfs->read($vars->dir, $vars->filename)
);
try {
$res['size'] = $vfs->size($vars->dir, $vars->filename);
} catch (Horde_Vfs_Exception $e) {}
return $res;
}
}
|