2014-06-12 17:11:11 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2016-05-05 09:20:07 +02:00
|
|
|
* EGroupware Filemanager: mounting GUI
|
2014-06-12 17:11:11 +02:00
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org/
|
|
|
|
* @package filemanager
|
|
|
|
* @author Ralf Becker <rb-AT-stylite.de>
|
2016-01-21 12:49:50 +01:00
|
|
|
* @copyright (c) 2010-16 by Ralf Becker <rb-AT-stylite.de>
|
2014-06-12 17:11:11 +02:00
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
2016-05-05 09:20:07 +02:00
|
|
|
use EGroupware\Api;
|
|
|
|
use EGroupware\Api\Framework;
|
|
|
|
use EGroupware\Api\Etemplate;
|
2015-04-17 15:44:35 +02:00
|
|
|
use EGroupware\Stylite\Vfs\Versioning;
|
2016-01-21 12:49:50 +01:00
|
|
|
use EGroupware\Api\Vfs;
|
2015-04-17 15:44:35 +02:00
|
|
|
|
2014-06-12 17:11:11 +02:00
|
|
|
/**
|
|
|
|
* Filemanager: mounting GUI
|
|
|
|
*/
|
|
|
|
class filemanager_admin extends filemanager_ui
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Functions callable via menuaction
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $public_functions = array(
|
|
|
|
'index' => true,
|
2014-06-13 11:22:45 +02:00
|
|
|
'fsck' => true,
|
2014-06-12 17:11:11 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Autheticated user is setup config user
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
|
|
|
static protected $is_setup = false;
|
|
|
|
|
|
|
|
/**
|
2015-04-17 15:44:35 +02:00
|
|
|
* Do we have versioning (Versioning\StreamWrapper class) available and with which schema
|
2014-06-12 17:11:11 +02:00
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $versioning;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Do not allow to (un)mount these
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected static $protected_path = array('/apps', '/templates');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
function __construct()
|
|
|
|
{
|
|
|
|
// make sure user has admin rights
|
|
|
|
if (!isset($GLOBALS['egw_info']['user']['apps']['admin']))
|
|
|
|
{
|
2016-05-05 09:20:07 +02:00
|
|
|
throw new Api\Exception\NoPermission\Admin();
|
2014-06-12 17:11:11 +02:00
|
|
|
}
|
|
|
|
// sudo handling
|
|
|
|
parent::__construct();
|
2016-05-05 09:20:07 +02:00
|
|
|
self::$is_setup = Api\Cache::getSession('filemanager', 'is_setup');
|
2014-06-12 17:11:11 +02:00
|
|
|
|
2015-04-17 15:44:35 +02:00
|
|
|
if (class_exists('EGroupware\Stylite\Vfs\Versioning\StreamWrapper'))
|
2014-06-12 17:11:11 +02:00
|
|
|
{
|
2015-04-17 15:44:35 +02:00
|
|
|
$this->versioning = Versioning\StreamWrapper::SCHEME;
|
2014-06-12 17:11:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mount GUI
|
|
|
|
*
|
|
|
|
* @param array $content=null
|
|
|
|
* @param string $msg=''
|
|
|
|
*/
|
|
|
|
public function index(array $content=null, $msg='', $msg_type=null)
|
|
|
|
{
|
|
|
|
if (is_array($content))
|
|
|
|
{
|
|
|
|
//_debug_array($content);
|
|
|
|
if ($content['sudo'])
|
|
|
|
{
|
|
|
|
$msg = $this->sudo($content['user'],$content['password'],self::$is_setup) ?
|
|
|
|
lang('Root access granted.') : lang('Wrong username or password!');
|
2016-01-21 12:49:50 +01:00
|
|
|
$msg_type = Vfs::$is_root ? 'success' : 'error';
|
2014-06-12 17:11:11 +02:00
|
|
|
}
|
2014-12-12 16:54:34 +01:00
|
|
|
elseif ($content['etemplates'] && $GLOBALS['egw_info']['user']['apps']['admin'])
|
|
|
|
{
|
|
|
|
$path = '/etemplates';
|
|
|
|
$url = 'stylite.merge://default/etemplates?merge=.&lang=0&level=1&extension=xet&url=egw';
|
2016-01-21 12:49:50 +01:00
|
|
|
$backup = Vfs::$is_root;
|
|
|
|
Vfs::$is_root = true;
|
|
|
|
$msg = Vfs::mount($url, $path) ?
|
2014-12-12 16:54:34 +01:00
|
|
|
lang('Successful mounted %1 on %2.',$url,$path) : lang('Error mounting %1 on %2!',$url,$path);
|
2016-01-21 12:49:50 +01:00
|
|
|
Vfs::$is_root = $backup;
|
2014-12-12 16:54:34 +01:00
|
|
|
}
|
2016-01-21 12:49:50 +01:00
|
|
|
elseif (Vfs::$is_root)
|
2014-06-12 17:11:11 +02:00
|
|
|
{
|
|
|
|
if ($content['logout'])
|
|
|
|
{
|
|
|
|
$msg = $this->sudo('','',self::$is_setup) ? 'Logout failed!' : lang('Root access stopped.');
|
2016-01-21 12:49:50 +01:00
|
|
|
$msg_type = !Vfs::$is_root ? 'success' : 'error';
|
2014-06-12 17:11:11 +02:00
|
|
|
}
|
|
|
|
if ($content['mounts']['disable'] || self::$is_setup && $content['mounts']['umount'])
|
|
|
|
{
|
|
|
|
if (($unmount = $content['mounts']['umount']))
|
|
|
|
{
|
|
|
|
list($path) = @each($content['mounts']['umount']);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
list($path) = @each($content['mounts']['disable']);
|
|
|
|
}
|
|
|
|
if (!in_array($path, self::$protected_path) && $path != '/')
|
|
|
|
{
|
2016-01-21 12:49:50 +01:00
|
|
|
$msg = Vfs::umount($path) ?
|
2014-06-12 17:11:11 +02:00
|
|
|
lang('%1 successful unmounted.',$path) : lang('Error unmounting %1!',$path);
|
|
|
|
}
|
|
|
|
else // re-mount / with sqlFS, to disable versioning
|
|
|
|
{
|
2016-05-05 09:20:07 +02:00
|
|
|
$msg = Vfs::mount($url=Vfs\Sqlfs\StreamWrapper::SCHEME.'://default'.$path,$path) ?
|
2014-06-12 17:11:11 +02:00
|
|
|
lang('Successful mounted %1 on %2.',$url,$path) : lang('Error mounting %1 on %2!',$url,$path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (($path = $content['mounts']['path']) &&
|
|
|
|
($content['mounts']['enable'] || self::$is_setup && $content['mounts']['mount']))
|
|
|
|
{
|
|
|
|
$url = str_replace('$path',$path,$content['mounts']['url']);
|
2015-04-17 15:44:35 +02:00
|
|
|
if (empty($url) && $this->versioning) $url = Versioning\StreamWrapper::PREFIX.$path;
|
2014-06-12 17:11:11 +02:00
|
|
|
|
|
|
|
if ($content['mounts']['enable'] && !$this->versioning)
|
|
|
|
{
|
|
|
|
$msg = lang('Versioning requires <a href="http://www.egroupware.org/products">Stylite EGroupware Enterprise Line (EPL)</a>!');
|
|
|
|
$msg_type = 'info';
|
|
|
|
}
|
2016-01-21 12:49:50 +01:00
|
|
|
elseif (!Vfs::file_exists($path) || !Vfs::is_dir($path))
|
2014-06-12 17:11:11 +02:00
|
|
|
{
|
|
|
|
$msg = lang('Path %1 not found or not a directory!',$path);
|
|
|
|
$msg_type = 'error';
|
|
|
|
}
|
|
|
|
// dont allow to change mount of /apps or /templates (eg. switching on versioning)
|
|
|
|
elseif (in_array($path, self::$protected_path))
|
|
|
|
{
|
|
|
|
$msg = lang('Permission denied!');
|
|
|
|
$msg_type = 'error';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-01-21 12:49:50 +01:00
|
|
|
$msg = Vfs::mount($url,$path) ?
|
2014-06-12 17:11:11 +02:00
|
|
|
lang('Successful mounted %1 on %2.',$url,$path) : lang('Error mounting %1 on %2!',$url,$path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($content['allow_delete_versions'] != $GLOBALS['egw_info']['server']['allow_delete_versions'])
|
|
|
|
{
|
2016-05-05 09:20:07 +02:00
|
|
|
Api\Config::save_value('allow_delete_versions', $content['allow_delete_versions'], 'phpgwapi');
|
2014-06-12 17:11:11 +02:00
|
|
|
$GLOBALS['egw_info']['server']['allow_delete_versions'] = $content['allow_delete_versions'];
|
|
|
|
$msg = lang('Configuration changed.');
|
|
|
|
}
|
|
|
|
}
|
2016-01-21 12:49:50 +01:00
|
|
|
// delete old versions and deleted files
|
|
|
|
if ($content['delete-versions'])
|
|
|
|
{
|
|
|
|
if (!Versioning\StreamWrapper::check_delete_version(null))
|
|
|
|
{
|
|
|
|
$msg = lang('Permission denied')."\n\n".lang('You are NOT allowed to finally delete older versions and deleted files!');
|
2016-01-22 12:32:17 +01:00
|
|
|
$msg_type = 'error';
|
2016-01-21 12:49:50 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-01-21 13:02:00 +01:00
|
|
|
// we need to be root to delete files independent of permissions and ownership
|
|
|
|
Vfs::$is_root = true;
|
|
|
|
if (!Vfs::file_exists($content['versionedpath']) || !Vfs::is_dir($content['versionedpath']))
|
2016-01-21 12:49:50 +01:00
|
|
|
{
|
2016-01-21 13:02:00 +01:00
|
|
|
$msg = lang('Directory "%1" NOT found!', $content['versionedpath']);
|
2016-01-22 12:32:17 +01:00
|
|
|
$msg_type = 'error';
|
2016-01-21 20:42:30 +01:00
|
|
|
}
|
2016-01-21 13:02:00 +01:00
|
|
|
else
|
|
|
|
{
|
2016-01-21 20:42:30 +01:00
|
|
|
@set_time_limit(0);
|
2016-01-22 12:32:17 +01:00
|
|
|
$starttime = microtime(true);
|
2016-01-21 13:02:00 +01:00
|
|
|
$deleted = $errors = 0;
|
2016-01-22 12:32:17 +01:00
|
|
|
|
|
|
|
// shortcut to efficently delete every old version and deleted file
|
2016-03-03 14:43:42 +01:00
|
|
|
if ($content['versionedpath'] == '/')
|
2016-01-21 12:49:50 +01:00
|
|
|
{
|
2016-03-03 14:43:42 +01:00
|
|
|
$deleted = Versioning\StreamWrapper::purge_all_versioning($content['mtime']);
|
2016-01-22 12:32:17 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Vfs::find($content['versionedpath'], array(
|
|
|
|
'show-deleted' => true,
|
|
|
|
'hidden' => true,
|
|
|
|
'depth' => true,
|
|
|
|
'path_preg' => '#/\.(attic|versions)/#',
|
2016-03-03 14:43:42 +01:00
|
|
|
)+(!(int)$content['mtime'] ? array() : array(
|
|
|
|
'mtime' => ($content['mtime']<0?'-':'+').(int)$content['mtime'],
|
2016-01-22 12:32:17 +01:00
|
|
|
)), function($path) use (&$deleted, &$errors)
|
2016-01-21 13:02:00 +01:00
|
|
|
{
|
2016-01-22 12:32:17 +01:00
|
|
|
if (($is_dir = Vfs::is_dir($path)) && Vfs::rmdir($path) ||
|
|
|
|
!$is_dir && Vfs::unlink($path))
|
|
|
|
{
|
|
|
|
++$deleted;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++$errors;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
$time = number_format(microtime(true)-$starttime, 1);
|
|
|
|
$msg = ($errors ? lang('%1 errors deleting!', $errors)."\n\n" : '').
|
|
|
|
lang('%1 files or directories deleted in %2 seconds.', $deleted, $time);
|
|
|
|
$msg_type = $errors ? 'error' : 'info';
|
2016-01-21 13:02:00 +01:00
|
|
|
}
|
|
|
|
Vfs::$is_root = false;
|
2016-01-21 12:49:50 +01:00
|
|
|
}
|
|
|
|
}
|
2014-06-12 17:11:11 +02:00
|
|
|
}
|
2016-03-03 14:43:42 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// defaults for deleting of older versions
|
|
|
|
$content['versionedpath'] = '/';
|
|
|
|
$content['mtime'] = 100;
|
|
|
|
}
|
2016-01-21 12:49:50 +01:00
|
|
|
if (true) $content = array(
|
|
|
|
'versionedpath' => $content['versionedpath'],
|
2016-03-03 14:43:42 +01:00
|
|
|
'mtime' => $content['mtime'],
|
2016-01-21 12:49:50 +01:00
|
|
|
);
|
2014-06-12 17:11:11 +02:00
|
|
|
if ($this->versioning)
|
|
|
|
{
|
|
|
|
// statistical information
|
2016-01-21 12:49:50 +01:00
|
|
|
$content += Versioning\StreamWrapper::summary();
|
2014-06-12 17:11:11 +02:00
|
|
|
if ($content['total_files']) $content['percent_files'] = number_format(100.0*$content['version_files']/$content['total_files'],1).'%';
|
|
|
|
if ($content['total_size']) $content['percent_size'] = number_format(100.0*$content['version_size']/$content['total_size'],1).'%';
|
|
|
|
}
|
2016-01-21 12:49:50 +01:00
|
|
|
if (!($content['is_root']=Vfs::$is_root))
|
2014-06-12 17:11:11 +02:00
|
|
|
{
|
|
|
|
if (empty($msg))
|
|
|
|
{
|
|
|
|
$msg = lang('You need to become root, to enable or disable versioning on a directory!');
|
|
|
|
$msg_type = 'info';
|
|
|
|
}
|
|
|
|
$readonlys['logout'] = $readonlys['enable'] = $readonlys['allow_delete_versions'] = true;
|
|
|
|
}
|
|
|
|
$content['is_setup'] = self::$is_setup;
|
|
|
|
$content['versioning'] = $this->versioning;
|
|
|
|
$content['allow_delete_versions'] = $GLOBALS['egw_info']['server']['allow_delete_versions'];
|
2016-05-05 09:20:07 +02:00
|
|
|
Framework::message($msg, $msg_type);
|
2014-06-12 17:11:11 +02:00
|
|
|
|
|
|
|
$n = 2;
|
|
|
|
$content['mounts'] = array();
|
2016-01-21 12:49:50 +01:00
|
|
|
foreach(Vfs::mount() as $path => $url)
|
2014-06-12 17:11:11 +02:00
|
|
|
{
|
|
|
|
$content['mounts'][$n++] = array(
|
|
|
|
'path' => $path,
|
|
|
|
'url' => $url,
|
|
|
|
);
|
2016-01-21 12:49:50 +01:00
|
|
|
$readonlys["disable[$path]"] = !$this->versioning || !Vfs::$is_root ||
|
|
|
|
Vfs::parse_url($url,PHP_URL_SCHEME) != $this->versioning;
|
2014-06-12 17:11:11 +02:00
|
|
|
}
|
|
|
|
$readonlys['umount[/]'] = $readonlys['umount[/apps]'] = true; // do not allow to unmount / or /apps
|
|
|
|
$readonlys['url'] = !self::$is_setup;
|
|
|
|
|
|
|
|
$sel_options['allow_delete_versions'] = array(
|
|
|
|
'' => lang('Noone'),
|
|
|
|
'root' => lang('Superuser (root)'),
|
|
|
|
'admins' => lang('Administrators'),
|
|
|
|
'everyone' => lang('Everyone'),
|
|
|
|
);
|
2014-12-12 16:54:34 +01:00
|
|
|
// show [Mount /etemplates] button for admin, if not already mounted and available
|
2015-05-27 16:39:54 +02:00
|
|
|
$readonlys['etemplates'] = !class_exists('\EGroupware\Stylite\Vfs\Merge\StreamWrapper') ||
|
2016-01-21 12:49:50 +01:00
|
|
|
($fs_tab=Vfs::mount($url)) && isset($fs_tab['/etemplates']) ||
|
2014-12-12 16:54:34 +01:00
|
|
|
!isset($GLOBALS['egw_info']['user']['apps']['admin']);
|
2014-06-12 17:11:11 +02:00
|
|
|
//_debug_array($content);
|
|
|
|
|
2016-05-05 09:20:07 +02:00
|
|
|
$tpl = new Etemplate('filemanager.admin');
|
2014-06-12 17:11:11 +02:00
|
|
|
$GLOBALS['egw_info']['flags']['app_header'] = lang('VFS mounts and versioning');
|
|
|
|
$tpl->exec('filemanager.filemanager_admin.index',$content,$sel_options,$readonlys);
|
|
|
|
}
|
2014-06-13 11:22:45 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Run fsck on sqlfs
|
|
|
|
*/
|
|
|
|
function fsck()
|
|
|
|
{
|
|
|
|
if ($_POST['cancel'])
|
|
|
|
{
|
2016-05-05 09:20:07 +02:00
|
|
|
Framework::redirect_link('/admin/index.php', null, 'admin');
|
2014-06-13 11:22:45 +02:00
|
|
|
}
|
|
|
|
$check_only = !isset($_POST['fix']);
|
|
|
|
|
2016-05-05 09:20:07 +02:00
|
|
|
if (!($msgs = Vfs\Sqlfs\Utils::fsck($check_only)))
|
2014-06-13 11:22:45 +02:00
|
|
|
{
|
|
|
|
$msgs = lang('Filesystem check reported no problems.');
|
|
|
|
}
|
|
|
|
$content = '<p>'.implode("</p>\n<p>", (array)$msgs)."</p>\n";
|
|
|
|
|
2016-05-05 20:26:12 +02:00
|
|
|
$content .= Api\Html::form('<p>'.($check_only&&is_array($msgs) ?
|
|
|
|
Api\Html::submit_button('fix', lang('Fix reported problems')) : '').
|
2016-05-05 09:20:07 +02:00
|
|
|
Api\Html::submit_button('cancel', lang('Cancel')).'</p>',
|
2014-06-13 11:22:45 +02:00
|
|
|
'','/index.php',array('menuaction'=>'filemanager.filemanager_admin.fsck'));
|
|
|
|
|
|
|
|
$GLOBALS['egw']->framework->render($content, lang('Admin').' - '.lang('Check virtual filesystem'), true);
|
|
|
|
}
|
2014-06-12 17:11:11 +02:00
|
|
|
}
|