2018-05-30 17:37:16 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* EGroupware Sharing base class
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Ralf Becker <rb@stylite.de>
|
|
|
|
* @copyright (c) 2014-16 by Ralf Becker <rb@stylite.de>
|
|
|
|
* @package api
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace EGroupware\Api;
|
|
|
|
|
2020-03-25 18:39:22 +01:00
|
|
|
use EGroupware\Api\Vfs\HiddenUploadSharing;
|
|
|
|
|
2018-05-30 17:37:16 +02:00
|
|
|
/**
|
|
|
|
* VFS sharing
|
|
|
|
*
|
|
|
|
* Token generation uses openssl_random_pseudo_bytes, if available, otherwise
|
|
|
|
* mt_rand based Api\Auth::randomstring is used.
|
|
|
|
*
|
|
|
|
* Existing user sessions are kept whenever possible by an additional mount into regular VFS:
|
|
|
|
* - share owner is current user (no problems with rights, they simply match)
|
|
|
|
* - share owner has owner-right for share: we create a temp. eACL for current user
|
|
|
|
* --> in all other cases session will be replaced with one of the anonymous user,
|
|
|
|
* as we dont support mounting with rights of share owner (VFS uses Vfs::$user!)
|
|
|
|
*
|
|
|
|
* @todo handle mounts of an entry directory /apps/$app/$id
|
|
|
|
* @todo handle mounts inside shared directory (they get currently lost)
|
|
|
|
* @todo handle absolute symlinks (wont work as we use share as root)
|
|
|
|
*/
|
|
|
|
class Sharing
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Length of base64 encoded token (real length is only 3/4 of it)
|
|
|
|
*
|
|
|
|
* Dropbox uses just 15 chars (letters/numbers 5-6 bit), php sessions use 32 chars (hex = 4bits),
|
|
|
|
* so 32 chars of base64 = 6bits should be plenty.
|
|
|
|
*/
|
|
|
|
const TOKEN_LENGTH = 32;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Name of table used for storing tokens
|
|
|
|
*/
|
|
|
|
const TABLE = 'egw_sharing';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reference to global db object
|
|
|
|
*
|
2021-03-31 17:49:43 +02:00
|
|
|
* @var Db
|
2018-05-30 17:37:16 +02:00
|
|
|
*/
|
|
|
|
protected static $db;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Share we are instanciated for
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $share;
|
|
|
|
|
|
|
|
const READONLY = 'share_ro';
|
|
|
|
const WRITABLE = 'share_rw';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Modes for sharing files
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
static $modes = array(
|
|
|
|
self::READONLY => array(
|
|
|
|
'label' => 'Readonly share',
|
2018-06-01 23:24:02 +02:00
|
|
|
'title' => 'Link is generated allowing recipients to view entries',
|
2018-05-30 17:37:16 +02:00
|
|
|
),
|
|
|
|
self::WRITABLE => array(
|
|
|
|
'label' => 'Writable share',
|
2018-06-01 23:24:02 +02:00
|
|
|
'title' => 'Link is generated allowing recipients to view and modify entries'
|
2018-05-30 17:37:16 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Protected constructor called via self::create_session
|
|
|
|
*
|
|
|
|
* @param string $token
|
|
|
|
* @param array $share
|
|
|
|
*/
|
|
|
|
protected function __construct(array $share)
|
|
|
|
{
|
|
|
|
static::$db = $GLOBALS['egw']->db;
|
|
|
|
$this->share = $share;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get token from url
|
|
|
|
*/
|
2021-03-16 14:02:46 +01:00
|
|
|
public static function get_token($path=null)
|
2018-05-30 17:37:16 +02:00
|
|
|
{
|
2021-03-16 14:02:46 +01:00
|
|
|
if (!empty($path) && preg_match('|/share.php/([^/]+)|', $path, $matches))
|
|
|
|
{
|
|
|
|
return $matches[1];
|
|
|
|
}
|
2020-10-08 11:24:34 +02:00
|
|
|
// WebDAV has no concept of a query string and clients (including cadaver)
|
|
|
|
// seem to pass '?' unencoded, so we need to extract the path info out
|
|
|
|
// of the request URI ourselves
|
|
|
|
// if request URI contains a full url, remove schema and domain
|
2018-05-30 17:37:16 +02:00
|
|
|
$matches = null;
|
2020-10-08 11:24:34 +02:00
|
|
|
if (preg_match('|^https?://[^/]+(/.*)$|', $path_info=$_SERVER['REQUEST_URI'], $matches))
|
|
|
|
{
|
|
|
|
$path_info = $matches[1];
|
|
|
|
}
|
|
|
|
$path_info = substr($path_info, strlen($_SERVER['SCRIPT_NAME']));
|
2022-04-26 20:24:37 +02:00
|
|
|
list(, $token/*, $path*/) = preg_split('|[/?]|', $path_info, 3)+[null,null,null];
|
2018-05-30 17:37:16 +02:00
|
|
|
|
2019-02-04 23:51:14 +01:00
|
|
|
list($token) = explode(':', $token);
|
2018-05-30 17:37:16 +02:00
|
|
|
return $token;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get root of share
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_root()
|
|
|
|
{
|
|
|
|
return $this->share['share_root'];
|
|
|
|
}
|
|
|
|
|
2019-08-23 22:19:10 +02:00
|
|
|
/**
|
|
|
|
* Get share path
|
|
|
|
*/
|
|
|
|
public function get_path()
|
|
|
|
{
|
|
|
|
return $this->share['share_path'];
|
|
|
|
}
|
2019-10-08 22:43:17 +02:00
|
|
|
|
2018-06-06 23:51:46 +02:00
|
|
|
/**
|
|
|
|
* Get share with email addresses
|
|
|
|
*/
|
|
|
|
public function get_share_with()
|
|
|
|
{
|
|
|
|
return $this->share['share_with'];
|
|
|
|
}
|
|
|
|
|
2018-05-30 17:37:16 +02:00
|
|
|
/**
|
|
|
|
* Create sharing session
|
|
|
|
*
|
2020-10-08 11:24:34 +02:00
|
|
|
* There are two cases:
|
|
|
|
*
|
|
|
|
* 1) there is no session $keep_session === null
|
|
|
|
* --> create new anon session with just filemanager rights and resolved share incl. sharee as only fstab entry
|
|
|
|
*
|
|
|
|
* 2) there is a (non-anonymous) session $keep_session === true
|
|
|
|
* --> mount share with sharing stream-wrapper into users "shares" subdirectory of home directory
|
|
|
|
* and ask user if he wants the share permanently mounted there
|
|
|
|
*
|
|
|
|
* Even with sharing stream-wrapper a) and b) need to be different, as sharing SW needs an intact fstab!
|
|
|
|
*
|
|
|
|
* Not yet sure if this still needs extra handling:
|
|
|
|
*
|
|
|
|
* 2a) single file or WebDAV
|
2018-05-30 17:37:16 +02:00
|
|
|
* --> modify EGroupware enviroment for that request only, no change in session
|
|
|
|
*
|
|
|
|
* @param boolean $keep_session =null null: create a new session, true: try mounting it into existing (already verified) session
|
|
|
|
* @return string with sessionid
|
|
|
|
*/
|
|
|
|
public static function create_session($keep_session=null)
|
|
|
|
{
|
|
|
|
$share = array();
|
|
|
|
static::check_token($keep_session, $share);
|
|
|
|
if($share)
|
|
|
|
{
|
|
|
|
$classname = static::get_share_class($share);
|
|
|
|
$classname::setup_share($keep_session, $share);
|
|
|
|
return $classname::login($keep_session, $share);
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2020-10-08 11:24:34 +02:00
|
|
|
/**
|
|
|
|
* Check sharing token
|
|
|
|
*
|
|
|
|
* @param boolean $keep_session false: does NOT check/fidle with session, true: return if session belongs to token
|
|
|
|
* @param array& $share on return information about the share
|
|
|
|
* @param ?string $token default call self::get_token() to get it from the URL
|
|
|
|
* @param ?string $password default $_SERVER['PHP_AUTH_PW']
|
|
|
|
* @throws Exception
|
|
|
|
* @throws Exception\NoPermission
|
|
|
|
* @throws Exception\NotFound
|
|
|
|
*/
|
|
|
|
public static function check_token($keep_session, &$share, $token=null, $password=null)
|
2018-05-30 17:37:16 +02:00
|
|
|
{
|
|
|
|
self::$db = $GLOBALS['egw']->db;
|
|
|
|
|
2020-10-08 11:24:34 +02:00
|
|
|
if (!isset($token)) $token = static::get_token();
|
2018-05-30 17:37:16 +02:00
|
|
|
|
|
|
|
// are we called from header include, because session did not verify
|
|
|
|
// --> check if it verifys for our token
|
|
|
|
if ($token && !$keep_session)
|
|
|
|
{
|
|
|
|
$_SERVER['PHP_AUTH_USER'] = $token;
|
|
|
|
if (!isset($_SERVER['PHP_AUTH_PW'])) $_SERVER['PHP_AUTH_PW'] = '';
|
|
|
|
|
|
|
|
unset($GLOBALS['egw_info']['flags']['autocreate_session_callback']);
|
|
|
|
if (isset($GLOBALS['egw']->session) && $GLOBALS['egw']->session->verify()
|
2021-03-12 01:00:16 +01:00
|
|
|
&& isset($GLOBALS['egw']->sharing) && array_key_exists($token, $GLOBALS['egw']->sharing))
|
2018-05-30 17:37:16 +02:00
|
|
|
{
|
|
|
|
return $GLOBALS['egw']->session->sessionid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-23 18:15:31 +02:00
|
|
|
// Load lang preference for error translations
|
|
|
|
if(empty($GLOBALS['egw_info']['user']['preferences']['common']['lang']))
|
|
|
|
{
|
|
|
|
$GLOBALS['egw_info']['user']['preferences'] = (new Preferences(Accounts::id2name('anonymous', 'account_id')))->read();
|
|
|
|
}
|
2018-05-30 17:37:16 +02:00
|
|
|
if (empty($token) || !($share = self::$db->select(self::TABLE, '*', array(
|
|
|
|
'share_token' => $token,
|
|
|
|
'(share_expires IS NULL OR share_expires > '.self::$db->quote(time(), 'date').')',
|
2020-09-10 19:11:23 +02:00
|
|
|
), __LINE__, __FILE__,false,'',Db::API_APPNAME)->fetch()) ||
|
2018-05-30 17:37:16 +02:00
|
|
|
!$GLOBALS['egw']->accounts->exists($share['share_owner']))
|
|
|
|
{
|
|
|
|
sleep(1);
|
|
|
|
|
|
|
|
return static::share_fail(
|
|
|
|
'404 Not Found',
|
2023-08-16 18:05:23 +02:00
|
|
|
lang("Requested resource '%1' does not exist or has expired", htmlspecialchars($token)) . "\n"
|
2018-05-30 17:37:16 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
// check password, if required
|
2020-10-08 11:24:34 +02:00
|
|
|
if(!static::check_password($share, $password))
|
2018-05-30 17:37:16 +02:00
|
|
|
{
|
|
|
|
$realm = 'EGroupware share '.$share['share_token'];
|
|
|
|
header('WWW-Authenticate: Basic realm="'.$realm.'"');
|
|
|
|
return static::share_fail(
|
|
|
|
'401 Unauthorized',
|
2020-02-14 13:43:50 +01:00
|
|
|
"Authorization failed."
|
2018-05-30 17:37:16 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-10-11 18:51:40 +02:00
|
|
|
/**
|
|
|
|
* Check to see if the share needs a password, and if it does that the password
|
|
|
|
* provided matches.
|
|
|
|
*
|
2021-03-31 17:49:43 +02:00
|
|
|
* @param array $share
|
2020-10-08 11:24:34 +02:00
|
|
|
* @param ?string $password default $_SERVER['PHP_AUTH_PW']
|
2019-10-11 18:51:40 +02:00
|
|
|
* @return boolean Password OK (or not needed)
|
|
|
|
*/
|
2020-10-08 11:24:34 +02:00
|
|
|
protected static function check_password(Array $share, $password=null)
|
2019-10-11 18:51:40 +02:00
|
|
|
{
|
2020-10-08 11:24:34 +02:00
|
|
|
if (!isset($password)) $password = $_SERVER['PHP_AUTH_PW'];
|
|
|
|
|
|
|
|
if ($share['share_passwd'] && (empty($password) ||
|
|
|
|
!(Auth::compare_password($password, $share['share_passwd'], 'crypt') ||
|
|
|
|
Header\Authenticate::decode_password($password) &&
|
|
|
|
Auth::compare_password($password, $share['share_passwd'], 'crypt'))))
|
2019-10-11 18:51:40 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-05-30 17:37:16 +02:00
|
|
|
/**
|
|
|
|
* Sub-class specific things needed to be done to the share before we try
|
|
|
|
* to login
|
|
|
|
*
|
|
|
|
* @param boolean $keep_session
|
2021-03-31 17:49:43 +02:00
|
|
|
* @param array $share
|
2018-05-30 17:37:16 +02:00
|
|
|
*/
|
|
|
|
protected static function setup_share($keep_session, &$share) {}
|
|
|
|
/**
|
|
|
|
* Sub-class specific things needed to be done to the share (or session)
|
|
|
|
* after we login but before we start actually doing anything
|
|
|
|
*/
|
2020-10-08 11:24:34 +02:00
|
|
|
protected static function after_login(array $share) {}
|
2018-05-30 17:37:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
protected static function login($keep_session, &$share)
|
|
|
|
{
|
|
|
|
// update accessed timestamp
|
|
|
|
self::$db->update(self::TABLE, array(
|
|
|
|
'share_last_accessed' => $share['share_last_accessed']=time(),
|
|
|
|
), array(
|
|
|
|
'share_id' => $share['share_id'],
|
|
|
|
), __LINE__, __FILE__);
|
|
|
|
|
|
|
|
// store sharing object in egw object and therefore in session
|
2021-03-12 01:00:16 +01:00
|
|
|
if(!isset($GLOBALS['egw']->sharing))
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->sharing = Array();
|
|
|
|
}
|
|
|
|
$GLOBALS['egw']->sharing[$share['share_token']] = static::factory($share);
|
2018-05-30 17:37:16 +02:00
|
|
|
|
|
|
|
// we have a session we want to keep, but share owner is different from current user and we need filemanager UI, or no session
|
|
|
|
// --> create a new anon session
|
2021-03-12 01:00:16 +01:00
|
|
|
if ($keep_session === false && $GLOBALS['egw']->sharing[$share['share_token']]->need_session() || is_null($keep_session))
|
2018-05-30 17:37:16 +02:00
|
|
|
{
|
2019-04-24 22:14:35 +02:00
|
|
|
$sessionid = static::create_new_session();
|
|
|
|
|
2020-10-08 11:24:34 +02:00
|
|
|
static::after_login($share);
|
2018-05-30 17:37:16 +02:00
|
|
|
}
|
|
|
|
// we have a session we want to keep, but share owner is different from current user and we dont need filemanager UI
|
|
|
|
// --> we dont need session and close it, to not modifiy it
|
|
|
|
elseif ($keep_session === false)
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->session->commit_session();
|
|
|
|
}
|
2020-10-08 11:24:34 +02:00
|
|
|
// need to store new fstab in session to allow GET requests / downloads via WebDAV
|
2018-05-30 17:37:16 +02:00
|
|
|
$GLOBALS['egw_info']['server']['vfs_fstab'] = Vfs::mount();
|
|
|
|
|
|
|
|
// update modified egw and egw_info again in session, if neccessary
|
|
|
|
if ($keep_session || $sessionid)
|
|
|
|
{
|
|
|
|
$_SESSION[Session::EGW_INFO_CACHE] = $GLOBALS['egw_info'];
|
|
|
|
unset($_SESSION[Session::EGW_INFO_CACHE]['flags']); // dont save the flags, they change on each request
|
|
|
|
|
|
|
|
$_SESSION[Session::EGW_OBJECT_CACHE] = serialize($GLOBALS['egw']);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $sessionid;
|
|
|
|
}
|
|
|
|
|
2019-04-24 22:14:35 +02:00
|
|
|
public static function create_new_session()
|
|
|
|
{
|
|
|
|
// create session without checking auth: create(..., false, false)
|
|
|
|
if (!($sessionid = $GLOBALS['egw']->session->create('anonymous@'.$GLOBALS['egw_info']['user']['domain'],
|
|
|
|
'', 'text', false, false)))
|
|
|
|
{
|
|
|
|
sleep(1);
|
|
|
|
return static::share_fail(
|
|
|
|
'500 Internal Server Error',
|
|
|
|
"Failed to create session: ".$GLOBALS['egw']->session->reason."\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return $sessionid;
|
|
|
|
}
|
|
|
|
|
2018-06-13 22:45:43 +02:00
|
|
|
/**
|
|
|
|
* Factory method to instanciate a share
|
|
|
|
*
|
|
|
|
* @param array $share
|
|
|
|
*
|
|
|
|
* @return Sharing
|
|
|
|
*/
|
|
|
|
public static function factory($share)
|
|
|
|
{
|
|
|
|
$class = static::get_share_class($share);
|
|
|
|
|
|
|
|
return new $class($share);
|
|
|
|
}
|
|
|
|
|
2018-05-30 17:37:16 +02:00
|
|
|
/**
|
|
|
|
* Get the namespaced class for the given share
|
|
|
|
*
|
2021-05-21 18:43:09 +02:00
|
|
|
* @param array $share
|
|
|
|
* @return string
|
|
|
|
* @throws Exception
|
2018-05-30 17:37:16 +02:00
|
|
|
*/
|
2021-05-21 18:43:09 +02:00
|
|
|
protected static function get_share_class(array $share)
|
2018-05-30 17:37:16 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2018-06-13 22:45:43 +02:00
|
|
|
if(self::is_entry($share))
|
2018-05-30 17:37:16 +02:00
|
|
|
{
|
2018-06-13 22:45:43 +02:00
|
|
|
list($app, $id) = explode('::', $share['share_path']);
|
|
|
|
if($app && class_exists('\EGroupware\\'. ucfirst($app) . '\Sharing'))
|
|
|
|
{
|
|
|
|
return '\EGroupware\\'. ucfirst($app) . '\Sharing';
|
|
|
|
}
|
|
|
|
else if(class_exists('\EGroupware\Stylite\Link\Sharing'))
|
|
|
|
{
|
|
|
|
return '\\EGroupware\\Stylite\\Link\\Sharing';
|
|
|
|
}
|
2018-05-30 17:37:16 +02:00
|
|
|
}
|
2020-03-25 18:39:22 +01:00
|
|
|
else if (class_exists ('\EGroupware\Collabora\Wopi') && (int)$share['share_writable'] === \EGroupware\Collabora\Wopi::WOPI_SHARED)
|
2019-10-08 22:43:17 +02:00
|
|
|
{
|
|
|
|
return '\\EGroupware\\Collabora\\Wopi';
|
|
|
|
}
|
2020-03-25 18:39:22 +01:00
|
|
|
else if ((int)$share['share_writable'] == HiddenUploadSharing::HIDDEN_UPLOAD)
|
|
|
|
{
|
|
|
|
return '\\'.__NAMESPACE__ . '\\'. 'Vfs\\HiddenUploadSharing';
|
|
|
|
}
|
2018-05-30 17:37:16 +02:00
|
|
|
}
|
|
|
|
catch(Exception $e){throw $e;}
|
|
|
|
return '\\'.__NAMESPACE__ . '\\'. (self::is_entry($share) ? 'Link' : 'Vfs'). '\\Sharing';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Something failed, stop everything
|
|
|
|
*
|
|
|
|
* @param String $status
|
|
|
|
* @param String $message
|
|
|
|
*/
|
|
|
|
public static function share_fail($status, $message)
|
|
|
|
{
|
|
|
|
header("HTTP/1.1 $status");
|
|
|
|
header("X-WebDAV-Status: $status", true);
|
|
|
|
echo $message;
|
|
|
|
|
|
|
|
$class = strpos($status, '404') === 0 ? 'EGroupware\Api\Exception\NotFound' :
|
2021-03-21 21:46:10 +01:00
|
|
|
(strpos($status, '401') === 0 ? 'EGroupware\Api\Exception\NoPermission' :
|
|
|
|
'EGroupware\Api\Exception');
|
2021-11-08 11:36:25 +01:00
|
|
|
throw new $class($message, (int)$status);
|
2018-05-30 17:37:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if we use filemanager UI
|
|
|
|
*
|
|
|
|
* Only for directories, if browser supports it and filemanager is installed
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function use_filemanager()
|
|
|
|
{
|
|
|
|
return !(!Vfs::is_dir($this->share['share_root']) || $_SERVER['REQUEST_METHOD'] != 'GET' ||
|
|
|
|
// or unsupported browsers like ie < 10
|
|
|
|
Header\UserAgent::type() == 'msie' && Header\UserAgent::version() < 10.0 ||
|
|
|
|
// or if no filemanager installed (WebDAV has own autoindex)
|
|
|
|
!file_exists(__DIR__.'/../../filemanager/inc/class.filemanager_ui.inc.php'));
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Check if we should use Collabora UI
|
|
|
|
*
|
|
|
|
* Only for files, if URL says so, and Collabora & Stylite apps are installed
|
|
|
|
*/
|
|
|
|
public function use_collabora()
|
|
|
|
{
|
|
|
|
return !Vfs::is_dir($this->share['share_root']) &&
|
|
|
|
array_key_exists('edit', $_REQUEST) &&
|
|
|
|
array_key_exists('collabora', $GLOBALS['egw_info']['apps']) &&
|
|
|
|
array_key_exists('stylite', $GLOBALS['egw_info']['apps']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-03-31 17:49:43 +02:00
|
|
|
public static function is_entry($share = false)
|
2018-05-30 17:37:16 +02:00
|
|
|
{
|
|
|
|
list($app, $id) = explode('::', $share['share_path']);
|
|
|
|
return $share && $share['share_path'] &&
|
2019-04-05 17:34:47 +02:00
|
|
|
$app && $id && !in_array($app, array('filemanager', 'vfs')) ;//&& array_key_exists($app, $GLOBALS['egw_info']['apps']);
|
2018-05-30 17:37:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function need_session()
|
|
|
|
{
|
2019-07-18 23:25:28 +02:00
|
|
|
return $this->use_filemanager() || static::is_entry($this->session);
|
2018-05-30 17:37:16 +02:00
|
|
|
}
|
|
|
|
|
2018-06-01 18:55:40 +02:00
|
|
|
/**
|
|
|
|
* Get actions for sharing an entry from the given app
|
|
|
|
*
|
|
|
|
* @param string $appname
|
|
|
|
* @param int $group Current menu group
|
|
|
|
*/
|
|
|
|
public static function get_actions($appname, $group = 6)
|
|
|
|
{
|
2019-07-11 20:07:20 +02:00
|
|
|
Translation::add_app('api');
|
2018-06-01 18:55:40 +02:00
|
|
|
$actions = array(
|
|
|
|
'share' => array(
|
|
|
|
'caption' => lang('Share'),
|
|
|
|
'icon' => 'api/share',
|
|
|
|
'group' => $group,
|
|
|
|
'allowOnMultiple' => false,
|
|
|
|
'children' => array(
|
|
|
|
'shareReadonlyLink' => array(
|
2018-10-11 18:09:16 +02:00
|
|
|
'caption' => lang('Share link'),
|
2018-06-01 18:55:40 +02:00
|
|
|
'group' => 1,
|
2019-07-29 15:36:57 +02:00
|
|
|
'icon' => 'link',
|
2018-06-01 18:55:40 +02:00
|
|
|
'order' => 11,
|
|
|
|
'enabled' => "javaScript:app.$appname.is_share_enabled",
|
2020-03-31 18:36:50 +02:00
|
|
|
'onExecute' => "javaScript:app.$appname.share_link",
|
|
|
|
'hint' => lang("Share this %1 via URL", Link::get_registry($appname, 'entry'))
|
2018-06-01 18:55:40 +02:00
|
|
|
),
|
2018-10-11 18:09:16 +02:00
|
|
|
'shareWritable' => array(
|
|
|
|
'caption' => lang('Writable'),
|
|
|
|
'group' => 2,
|
2018-06-01 18:55:40 +02:00
|
|
|
'icon' => 'edit',
|
2018-10-11 18:09:16 +02:00
|
|
|
'allowOnMultiple' => true,
|
2018-06-01 18:55:40 +02:00
|
|
|
'enabled' => "javaScript:app.$appname.is_share_enabled",
|
2020-03-31 18:36:50 +02:00
|
|
|
'checkbox' => true,
|
|
|
|
'hint' => lang("Allow editing the %1", Link::get_registry($appname, 'entry'))
|
2018-06-01 18:55:40 +02:00
|
|
|
),
|
|
|
|
'shareFiles' => array(
|
|
|
|
'caption' => lang('Share files'),
|
|
|
|
'group' => 2,
|
2018-10-11 18:09:16 +02:00
|
|
|
'allowOnMultiple' => true,
|
2018-06-01 18:55:40 +02:00
|
|
|
'enabled' => "javaScript:app.$appname.is_share_enabled",
|
2020-03-31 18:36:50 +02:00
|
|
|
'checkbox' => true,
|
|
|
|
'hint' => lang('Include access to any linked files (Links tab)')
|
2019-08-22 23:18:40 +02:00
|
|
|
),
|
|
|
|
'shareFilemanager' => array(
|
2020-03-31 18:49:36 +02:00
|
|
|
'caption' => lang('share filemanager directory'),
|
2019-08-22 23:18:40 +02:00
|
|
|
'group' => 10,
|
|
|
|
'icon' => 'link',
|
|
|
|
'order' => 20,
|
|
|
|
'enabled' => "javaScript:app.$appname.is_share_enabled",
|
2020-03-31 18:36:50 +02:00
|
|
|
'onExecute' => "javaScript:app.$appname.share_link",
|
|
|
|
'hint' => lang('Share just the associated filemanager directory, not the %1', Link::get_registry($appname, 'entry'))
|
2019-08-22 23:18:40 +02:00
|
|
|
),
|
2018-06-01 18:55:40 +02:00
|
|
|
),
|
|
|
|
));
|
2019-08-22 23:18:40 +02:00
|
|
|
if(!$GLOBALS['egw_info']['user']['apps']['filemanager'])
|
|
|
|
{
|
|
|
|
unset($actions['share']['children']['shareFilemanager']);
|
|
|
|
}
|
2018-10-11 18:09:16 +02:00
|
|
|
if(!$GLOBALS['egw_info']['user']['apps']['stylite'])
|
2018-06-01 18:55:40 +02:00
|
|
|
{
|
|
|
|
array_unshift($actions['share']['children'], array(
|
|
|
|
'caption' => lang('EPL Only'),
|
|
|
|
'group' => 0
|
|
|
|
));
|
|
|
|
foreach($actions['share']['children'] as &$child)
|
|
|
|
{
|
|
|
|
$child['enabled'] = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $actions;
|
|
|
|
}
|
|
|
|
|
2018-05-30 17:37:16 +02:00
|
|
|
/**
|
2020-09-10 19:11:23 +02:00
|
|
|
* Serve a request on a share specified in REQUEST_URI
|
2018-05-30 17:37:16 +02:00
|
|
|
*/
|
|
|
|
public function ServeRequest()
|
|
|
|
{
|
|
|
|
// sharing is for a different share, change to current share
|
2021-03-03 22:23:42 +01:00
|
|
|
if (empty($this->share['skip_validate_token']) && self::get_token() && $this->share['share_token'] !== self::get_token())
|
2018-05-30 17:37:16 +02:00
|
|
|
{
|
2020-04-06 09:05:39 +02:00
|
|
|
// to keep the session we require the regular user flag "N" AND a user-name not equal to "anonymous"
|
|
|
|
self::create_session($GLOBALS['egw']->session->session_flags === 'N' &&
|
|
|
|
$GLOBALS['egw_info']['user']['account_lid'] !== 'anonymous');
|
2018-05-30 17:37:16 +02:00
|
|
|
|
2021-03-12 01:00:16 +01:00
|
|
|
return $GLOBALS['egw']->sharing[static::get_token()]->ServeRequest();
|
2018-05-30 17:37:16 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 11:24:34 +02:00
|
|
|
/* No extended ACL for readonly shares, disable eacl by setting session cache
|
2018-05-30 17:37:16 +02:00
|
|
|
if(!($this->share['share_writable'] & 1))
|
|
|
|
{
|
|
|
|
Cache::setSession(Vfs\Sqlfs\StreamWrapper::EACL_APPNAME, 'extended_acl', array(
|
|
|
|
'/' => 1,
|
|
|
|
$this->share['share_path'] => 1
|
|
|
|
));
|
2020-10-08 11:24:34 +02:00
|
|
|
}*/
|
2018-05-30 17:37:16 +02:00
|
|
|
if($this->use_collabora())
|
|
|
|
{
|
|
|
|
$ui = new \EGroupware\Collabora\Ui();
|
|
|
|
return $ui->editor($this->share['share_path']);
|
|
|
|
}
|
|
|
|
// use pure WebDAV for everything but GET requests to directories
|
2019-07-18 23:25:28 +02:00
|
|
|
else if (!$this->use_filemanager() && !static::is_entry($this->share))
|
2018-05-30 17:37:16 +02:00
|
|
|
{
|
|
|
|
// send a content-disposition header, so browser knows how to name downloaded file
|
|
|
|
if (!Vfs::is_dir($this->share['share_root']))
|
|
|
|
{
|
|
|
|
Header\Content::disposition(Vfs::basename($this->share['share_path']), false);
|
|
|
|
}
|
2018-06-06 23:51:46 +02:00
|
|
|
$GLOBALS['egw']->session->commit_session();
|
2020-04-08 19:38:57 +02:00
|
|
|
|
|
|
|
// WebDAV always looks at the original request for a single file so make sure the file is found at the root
|
|
|
|
Vfs::$is_root = true;
|
|
|
|
unset($GLOBALS['egw_info']['server']['vfs_fstab']);
|
2021-03-12 01:00:16 +01:00
|
|
|
|
|
|
|
// Make SURE resolve_url is set, otherwise webdav will give full access to /
|
|
|
|
if(!$this->share['resolve_url'])
|
|
|
|
{
|
|
|
|
$this->share['resolve_url'] = Vfs::resolve_url($this->share['share_path'], true, true, true, true);
|
|
|
|
}
|
2020-04-08 19:38:57 +02:00
|
|
|
Vfs::mount($this->share['resolve_url'], '/', false, false, true);
|
|
|
|
Vfs::clearstatcache();
|
|
|
|
|
2018-05-30 17:37:16 +02:00
|
|
|
$webdav_server = new Vfs\WebDAV();
|
2022-10-12 19:45:05 +02:00
|
|
|
$webdav_server->ServeRequest('/');
|
2018-05-30 17:37:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
return $this->get_ui();
|
|
|
|
}
|
|
|
|
|
2018-06-06 17:54:49 +02:00
|
|
|
/**
|
|
|
|
* Get the user interface for this share
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function get_ui()
|
|
|
|
{
|
|
|
|
echo 'Error: missing subclass';
|
|
|
|
}
|
|
|
|
|
2018-05-30 17:37:16 +02:00
|
|
|
/**
|
|
|
|
* Generate a new token
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function token()
|
|
|
|
{
|
|
|
|
// generate random token (using oppenssl if available otherwise mt_rand based Api\Auth::randomstring)
|
|
|
|
do {
|
|
|
|
$token = function_exists('openssl_random_pseudo_bytes') ?
|
|
|
|
base64_encode(openssl_random_pseudo_bytes(3*self::TOKEN_LENGTH/4)) :
|
2018-06-05 23:01:09 +02:00
|
|
|
Auth::randomstring(self::TOKEN_LENGTH);
|
2018-05-30 17:37:16 +02:00
|
|
|
// base64 can contain chars not allowed in our vfs-urls eg. / or #
|
|
|
|
} while ($token != urlencode($token));
|
|
|
|
|
|
|
|
return $token;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Name of the async job for cleaning up shares
|
|
|
|
*/
|
|
|
|
const ASYNC_JOB_ID = 'egw_sharing-tmp_cleanup';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new share
|
|
|
|
*
|
2021-09-20 13:27:31 +02:00
|
|
|
* Only for shares with identical attributes AND recipients an existing share-token is returned.
|
|
|
|
*
|
2020-03-25 03:34:04 +01:00
|
|
|
* @param string $action_id Specific type of share being created, default ''
|
2018-05-30 17:37:16 +02:00
|
|
|
* @param string $path either path in temp_dir or vfs with optional vfs scheme
|
|
|
|
* @param string $mode self::LINK: copy file in users tmp-dir or self::READABLE share given vfs file,
|
2020-03-25 03:34:04 +01:00
|
|
|
* if no vfs behave as self::LINK
|
2018-05-30 17:37:16 +02:00
|
|
|
* @param string $name filename to use for $mode==self::LINK, default basename of $path
|
|
|
|
* @param string|array $recipients one or more recipient email addresses
|
|
|
|
* @param array $extra =array() extra data to store
|
2020-03-25 03:34:04 +01:00
|
|
|
* @return array with share data, eg. value for key 'share_token'
|
2018-05-30 17:37:16 +02:00
|
|
|
* @throw Api\Exception\NotFound if $path not found
|
|
|
|
* @throw Api\Exception\AssertionFailed if user temp. directory does not exist and can not be created
|
|
|
|
*/
|
2020-03-25 03:34:04 +01:00
|
|
|
public static function create(string $action_id, $path, $mode, $name, $recipients, $extra = array())
|
2018-05-30 17:37:16 +02:00
|
|
|
{
|
|
|
|
if (!isset(static::$db)) static::$db = $GLOBALS['egw']->db;
|
|
|
|
|
|
|
|
if (empty($name)) $name = $path;
|
|
|
|
|
2020-09-10 19:11:23 +02:00
|
|
|
$table_def = static::$db->get_table_definitions(Db::API_APPNAME,static::TABLE);
|
2018-10-15 22:57:24 +02:00
|
|
|
$extra = array_intersect_key($extra, $table_def['fd']);
|
|
|
|
|
2019-01-31 22:14:03 +01:00
|
|
|
// Check if path is mounted somewhere that needs a password
|
|
|
|
static::path_needs_password($path);
|
|
|
|
|
2021-09-20 13:27:31 +02:00
|
|
|
// check if file has been shared before, with identical attributes AND recipients
|
2018-05-30 17:37:16 +02:00
|
|
|
if (($share = static::$db->select(static::TABLE, '*', $extra+array(
|
|
|
|
'share_path' => $path,
|
|
|
|
'share_owner' => Vfs::$user,
|
|
|
|
'share_expires' => null,
|
|
|
|
'share_passwd' => null,
|
|
|
|
'share_writable'=> false,
|
2021-09-20 13:27:31 +02:00
|
|
|
'share_with' => implode(',', (array)$recipients),
|
2020-09-10 19:11:23 +02:00
|
|
|
), __LINE__, __FILE__, Db::API_APPNAME)->fetch()))
|
2018-05-30 17:37:16 +02:00
|
|
|
{
|
2021-09-20 13:27:31 +02:00
|
|
|
// if yes, nothing to do
|
2018-05-30 17:37:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$i = 0;
|
|
|
|
while(true) // self::token() can return an existing value
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
static::$db->insert(static::TABLE, $share = array(
|
|
|
|
'share_token' => self::token(),
|
|
|
|
'share_path' => $path,
|
|
|
|
'share_owner' => Vfs::$user,
|
2023-08-21 22:23:21 +02:00
|
|
|
'share_modified' => (new DateTime('now', DateTime::$server_timezone))->format('ts'),
|
|
|
|
'share_modifier' => Vfs::$user,
|
2018-05-30 17:37:16 +02:00
|
|
|
'share_with' => implode(',', (array)$recipients),
|
|
|
|
'share_created' => time(),
|
2020-09-10 19:11:23 +02:00
|
|
|
)+$extra, false, __LINE__, __FILE__, Db::API_APPNAME);
|
2018-05-30 17:37:16 +02:00
|
|
|
|
|
|
|
$share['share_id'] = static::$db->get_last_insert_id(static::TABLE, 'share_id');
|
|
|
|
break;
|
|
|
|
}
|
2018-06-05 23:01:09 +02:00
|
|
|
catch(Db\Exception $e) {
|
2018-05-30 17:37:16 +02:00
|
|
|
if ($i++ > 3) throw $e;
|
|
|
|
unset($e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if not already installed, install periodic cleanup of shares
|
|
|
|
$async = new Asyncservice();
|
2019-07-18 23:25:28 +02:00
|
|
|
$method = 'EGroupware\\Api\\Sharing::tmp_cleanup';
|
|
|
|
if (!($job = $async->read(self::ASYNC_JOB_ID)) || $job[self::ASYNC_JOB_ID]['method'] !== $method)
|
2018-05-30 17:37:16 +02:00
|
|
|
{
|
|
|
|
if ($job) $async->delete(self::ASYNC_JOB_ID); // update not working old class-name
|
|
|
|
|
2019-07-18 23:25:28 +02:00
|
|
|
$async->set_timer(array('day' => 28), self::ASYNC_JOB_ID, $method ,null);
|
2018-05-30 17:37:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $share;
|
|
|
|
}
|
|
|
|
|
2018-06-01 18:53:00 +02:00
|
|
|
/**
|
|
|
|
* Create a share via AJAX
|
|
|
|
*
|
|
|
|
* @param String $action
|
|
|
|
* @param String $path
|
2020-03-25 03:34:04 +01:00
|
|
|
* @param boolean $writable Allow editing the shared entry / folder / file
|
|
|
|
* @param boolean $files For sharing an application entry, allow access to the linked files
|
2021-05-21 18:43:09 +02:00
|
|
|
* @param array $extra Additional extra parameters
|
2018-06-01 18:53:00 +02:00
|
|
|
*/
|
2018-10-15 22:57:24 +02:00
|
|
|
public static function ajax_create($action, $path, $writable = false, $files = false, $extra = array())
|
2018-06-01 18:53:00 +02:00
|
|
|
{
|
2019-07-31 17:46:55 +02:00
|
|
|
if(!$path)
|
|
|
|
{
|
|
|
|
throw new Exception\WrongParameter('Missing share path. Unable to create share.');
|
|
|
|
}
|
2020-03-31 18:21:26 +02:00
|
|
|
$extra = (array)$extra + array(
|
2018-10-15 22:57:24 +02:00
|
|
|
'share_writable' => $writable,
|
|
|
|
'include_files' => $files
|
|
|
|
);
|
2020-03-25 18:39:22 +01:00
|
|
|
$class = self::get_share_class(array('share_path' => $path) + $extra);
|
2018-06-01 18:53:00 +02:00
|
|
|
$share = $class::create(
|
2020-03-25 03:34:04 +01:00
|
|
|
$action,
|
2018-06-01 18:53:00 +02:00
|
|
|
$path,
|
2018-10-15 22:57:24 +02:00
|
|
|
$writable ? Sharing::WRITABLE : Sharing::READONLY,
|
2018-10-11 18:09:16 +02:00
|
|
|
basename($path),
|
2018-06-01 18:53:00 +02:00
|
|
|
array(),
|
2018-10-15 22:57:24 +02:00
|
|
|
$extra
|
2018-06-01 18:53:00 +02:00
|
|
|
);
|
|
|
|
|
2018-10-11 18:09:16 +02:00
|
|
|
// Store share in session so Merge can find this one and not create a read-only one
|
2021-05-21 18:43:09 +02:00
|
|
|
Cache::setSession(__CLASS__, $path, $share);
|
2018-06-01 18:53:00 +02:00
|
|
|
$arr = array(
|
2018-06-01 19:55:27 +02:00
|
|
|
'action' => $action,
|
2018-10-11 18:09:16 +02:00
|
|
|
'writable' => $writable,
|
2018-06-01 18:53:00 +02:00
|
|
|
'share_link' => $class::share2link($share),
|
|
|
|
'template' => Etemplate\Widget\Template::rel2url('/filemanager/templates/default/share_dialog.xet')
|
|
|
|
);
|
2019-08-22 23:56:17 +02:00
|
|
|
switch($action)
|
|
|
|
{
|
|
|
|
case 'shareFilemanager':
|
|
|
|
$arr['title'] = lang('Filemanager directory');
|
2020-03-25 18:39:22 +01:00
|
|
|
break;
|
|
|
|
case 'shareUploadDir':
|
2020-03-26 20:20:20 +01:00
|
|
|
case 'mail_shareUploadDir':
|
2020-03-25 18:39:22 +01:00
|
|
|
$arr['title'] = lang('Upload directory');
|
|
|
|
break;
|
2019-08-22 23:56:17 +02:00
|
|
|
}
|
2018-06-01 18:53:00 +02:00
|
|
|
$response = Json\Response::get();
|
|
|
|
$response->data($arr);
|
|
|
|
}
|
|
|
|
|
2018-05-30 17:37:16 +02:00
|
|
|
/**
|
|
|
|
* Api\Storage\Base instance for egw_sharing table
|
|
|
|
*
|
2021-05-21 18:43:09 +02:00
|
|
|
* @var Storage\Base
|
2018-05-30 17:37:16 +02:00
|
|
|
*/
|
|
|
|
protected static $so;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a so_sql instance initialised for shares
|
|
|
|
*/
|
|
|
|
public static function so()
|
|
|
|
{
|
|
|
|
if (!isset(self::$so))
|
|
|
|
{
|
2018-09-10 23:26:53 +02:00
|
|
|
self::$so = new Storage\Base('phpgwapi', self::TABLE, null, '', true);
|
2018-05-30 17:37:16 +02:00
|
|
|
self::$so->set_times('string');
|
|
|
|
}
|
|
|
|
return self::$so;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete specified shares and unlink temp. files
|
|
|
|
*
|
|
|
|
* @param int|array $keys
|
|
|
|
* @return int number of deleted shares
|
|
|
|
*/
|
|
|
|
public static function delete($keys)
|
|
|
|
{
|
|
|
|
self::$db = $GLOBALS['egw']->db;
|
|
|
|
|
|
|
|
if (is_scalar($keys)) $keys = array('share_id' => $keys);
|
|
|
|
|
|
|
|
// delete specified shares
|
2020-09-10 19:11:23 +02:00
|
|
|
self::$db->delete(self::TABLE, $keys, __LINE__, __FILE__, Db::API_APPNAME);
|
2018-05-30 17:37:16 +02:00
|
|
|
$deleted = self::$db->affected_rows();
|
|
|
|
|
|
|
|
return $deleted;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Home long to keep temp. files: 100 day
|
|
|
|
*/
|
|
|
|
const TMP_KEEP = 8640000;
|
|
|
|
/**
|
|
|
|
* How long to keep automatic created Wopi shares
|
|
|
|
*/
|
|
|
|
const WOPI_KEEP = '-3month';
|
|
|
|
|
|
|
|
/**.
|
|
|
|
* Periodic (monthly) cleanup of temporary sharing files (download link)
|
|
|
|
*
|
|
|
|
* Exlicit expireds shares are delete, as ones created over 100 days ago and last accessed over 100 days ago.
|
|
|
|
*/
|
|
|
|
public static function tmp_cleanup()
|
|
|
|
{
|
|
|
|
if (!isset(self::$db)) self::$db = $GLOBALS['egw']->db;
|
|
|
|
Vfs::$is_root = true;
|
|
|
|
|
|
|
|
try {
|
|
|
|
$cols = array(
|
|
|
|
'share_path',
|
|
|
|
'MAX(share_expires) AS share_expires',
|
|
|
|
'MAX(share_created) AS share_created',
|
|
|
|
'MAX(share_last_accessed) AS share_last_accessed',
|
|
|
|
);
|
|
|
|
if (($group_concat = self::$db->group_concat('share_id'))) $cols[] = $group_concat.' AS share_id';
|
|
|
|
// remove expired tmp-files unconditionally
|
|
|
|
$having = 'HAVING MAX(share_expires) < '.self::$db->quote(self::$db->to_timestamp(time())).' OR '.
|
|
|
|
// remove without expiration date, when created over 100 days ago AND
|
|
|
|
'MAX(share_expires) IS NULL AND MAX(share_created) < '.self::$db->quote(self::$db->to_timestamp(time()-self::TMP_KEEP)). ' AND '.
|
|
|
|
// (last accessed over 100 days ago OR never)
|
|
|
|
'(MAX(share_last_accessed) IS NULL OR MAX(share_last_accessed) < '.self::$db->quote(self::$db->to_timestamp(time()-self::TMP_KEEP)).')';
|
|
|
|
|
|
|
|
foreach(self::$db->select(self::TABLE, $cols, array(
|
|
|
|
"share_path LIKE '/home/%/.tmp/%'",
|
|
|
|
), __LINE__, __FILE__, false, 'GROUP BY share_path '.$having) as $row)
|
|
|
|
{
|
|
|
|
Vfs::remove($row['share_path']);
|
|
|
|
|
|
|
|
if ($group_concat)
|
|
|
|
{
|
|
|
|
$share_ids = $row['share_id'] ? explode(',', $row['share_id']) : array();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$share_ids = array();
|
2019-07-18 23:25:28 +02:00
|
|
|
foreach(self::$db->select(self::TABLE, 'share_id', array(
|
2018-05-30 17:37:16 +02:00
|
|
|
'share_path' => $row['share_path'],
|
|
|
|
), __LINE__, __FILE__) as $id)
|
|
|
|
{
|
|
|
|
$share_ids[] = $id['share_id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($share_ids)
|
|
|
|
{
|
2019-07-18 23:25:28 +02:00
|
|
|
$class = self::get_share_class($row);
|
2020-03-06 14:33:34 +01:00
|
|
|
$class::delete(['share_id' => $share_ids]);
|
2018-05-30 17:37:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete automatic created and expired Collabora shares older then 3 month
|
|
|
|
if (class_exists('EGroupware\\Collabora\\Wopi'))
|
|
|
|
{
|
|
|
|
self::$db->delete(self::TABLE, array(
|
2019-07-18 23:25:28 +02:00
|
|
|
'share_expires < '.self::$db->quote(DateTime::to(self::WOPI_KEEP, 'Y-m-d')),
|
|
|
|
'share_writable IN ('.\EGroupware\Collabora\Wopi::WOPI_WRITABLE.','.\EGroupware\Collabora\Wopi::WOPI_READONLY.')',
|
2018-05-30 17:37:16 +02:00
|
|
|
), __LINE__, __FILE__);
|
|
|
|
}
|
2019-07-18 23:25:28 +02:00
|
|
|
|
|
|
|
// Now check the remaining shares
|
2020-03-05 23:03:34 +01:00
|
|
|
static::cleanup_missing_paths();
|
2018-05-30 17:37:16 +02:00
|
|
|
}
|
|
|
|
catch (\Exception $e) {
|
|
|
|
_egw_log_exception($e);
|
|
|
|
}
|
|
|
|
Vfs::$is_root = false;
|
|
|
|
}
|
|
|
|
|
2019-07-18 23:25:28 +02:00
|
|
|
/**
|
|
|
|
* Check share paths and if the path is no longer there / valid, remove the share
|
|
|
|
*/
|
|
|
|
public static function cleanup_missing_paths()
|
|
|
|
{
|
|
|
|
if (!isset(self::$db)) self::$db = $GLOBALS['egw']->db;
|
|
|
|
|
|
|
|
foreach(self::$db->select(self::TABLE, array(
|
2020-03-30 17:35:59 +02:00
|
|
|
'share_id','share_path', 'share_writable'
|
2019-07-18 23:25:28 +02:00
|
|
|
), array(), __LINE__, __FILE__, false) as $share)
|
|
|
|
{
|
|
|
|
$class = self::get_share_class($share);
|
|
|
|
|
|
|
|
if(!$class::check_path($share))
|
|
|
|
{
|
|
|
|
$class::delete($share);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that the share path is still valid, and if not, delete it.
|
|
|
|
* This should be overridden.
|
|
|
|
*
|
2021-05-21 18:43:09 +02:00
|
|
|
* @param array share
|
2019-07-18 23:25:28 +02:00
|
|
|
*
|
|
|
|
* @return boolean Is the share still valid
|
|
|
|
*/
|
|
|
|
protected static function check_path($share)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-05-30 17:37:16 +02:00
|
|
|
/**
|
|
|
|
* Generate link from share or share-token
|
|
|
|
*
|
|
|
|
* @param string|array $share share or share-token
|
|
|
|
* @return string full Url incl. schema and host
|
|
|
|
*/
|
|
|
|
public static function share2link($share)
|
|
|
|
{
|
|
|
|
if (is_array($share)) $share = $share['share_token'];
|
|
|
|
|
|
|
|
return Framework::getUrl(Framework::link('/share.php')).'/'.$share;
|
|
|
|
}
|
2019-01-31 22:14:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check to see if the path has a password required for it's mounting (eg: Samba)
|
|
|
|
* we need to deal with it specially. In general, we just throw an exception
|
|
|
|
* if the mount has $pass in it.
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
*
|
2021-05-21 18:43:09 +02:00
|
|
|
* @throws Exception\WrongParameter if you try to share a path that needs a password
|
2019-01-31 22:14:03 +01:00
|
|
|
*/
|
|
|
|
public static function path_needs_password($path)
|
|
|
|
{
|
|
|
|
$mounts = array_reverse(Vfs::mount());
|
|
|
|
$parts = Vfs::parse_url($path);
|
|
|
|
|
|
|
|
foreach($mounts as $mounted => $url)
|
|
|
|
{
|
|
|
|
if(($mounted == $parts['path'] || $mounted.'/' == substr($parts['path'],0,strlen($mounted)+1)) && strpos($url, '$pass') !== FALSE)
|
|
|
|
{
|
|
|
|
throw new Exception\WrongParameter(
|
|
|
|
'Cannot share a file that needs a password. (' .
|
|
|
|
$path . ' mounted from '. $url . ')'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2018-05-30 17:37:16 +02:00
|
|
|
}
|