Exemplo n.º 1
0
 protected function setUp()
 {
     parent::setUp();
     $manager = \OC\Files\Filesystem::getMountManager();
     \OC_Hook::clear('OC_Filesystem');
     \OC_Hook::connect('OC_Filesystem', 'post_write', '\\OC\\Files\\Cache\\Updater', 'writeHook');
     \OC_Hook::connect('OC_Filesystem', 'post_delete', '\\OC\\Files\\Cache\\Updater', 'deleteHook');
     \OC_Hook::connect('OC_Filesystem', 'post_rename', '\\OC\\Files\\Cache\\Updater', 'renameHook');
     \OC_Hook::connect('OC_Filesystem', 'post_touch', '\\OC\\Files\\Cache\\Updater', 'touchHook');
     $user = new User($this->getUniqueID('user'), new \OC_User_Dummy());
     $this->loginAsUser($user->getUID());
     $this->view = new View();
     $this->root = new Root($manager, $this->view, $user);
     $storage = new Temporary(array());
     $subStorage = new Temporary(array());
     $this->storages[] = $storage;
     $this->storages[] = $subStorage;
     $this->root->mount($storage, '/');
     $this->root->mount($subStorage, '/substorage/');
 }
Exemplo n.º 2
0
 /**
  * To be called from setupFS trough a hook
  *
  * Sets up listening to changes made to shares owned by the current user
  */
 public function globalSetup()
 {
     $user = $this->userSession->getUser();
     if (!$user) {
         return;
     }
     $recipientPropagator = $this->getSharePropagator($user->getUID());
     $watcher = new ChangeWatcher(Filesystem::getView(), $recipientPropagator);
     // for marking shares owned by the active user as dirty when a file inside them changes
     $this->listenToOwnerChanges($user->getUID(), $user->getUID());
     \OC_Hook::connect('OC_Filesystem', 'post_write', $watcher, 'writeHook');
     \OC_Hook::connect('OC_Filesystem', 'post_delete', $watcher, 'writeHook');
     \OC_Hook::connect('OC_Filesystem', 'post_rename', $watcher, 'renameHook');
 }
Exemplo n.º 3
0
 /**
  * connects a function to a hook
  *
  * @param string $signalClass class name of emitter
  * @param string $signalName name of signal
  * @param string|object $slotClass class name of slot
  * @param string $slotName name of slot
  * @return bool
  *
  * This function makes it very easy to connect to use hooks.
  *
  * TODO: write example
  * @since 4.0.0
  */
 public static function connectHook($signalClass, $signalName, $slotClass, $slotName)
 {
     return \OC_Hook::connect($signalClass, $signalName, $slotClass, $slotName);
 }
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*  
* You should have received a copy of the GNU Lesser General Public 
* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
* 
*/
//we need to have the sha256 hash of passwords for ampache
OC_Hook::connect('OC_User', 'post_login', 'OC_MEDIA', 'loginListener');
//connect to the filesystem for auto updating
OC_Hook::connect('OC_Filesystem', 'post_write', 'OC_MEDIA', 'updateFile');
//listen for file deletions to clean the database if a song is deleted
OC_Hook::connect('OC_Filesystem', 'delete', 'OC_MEDIA', 'deleteFile');
//list for file moves to update the database
OC_Hook::connect('OC_Filesystem', 'post_rename', 'OC_MEDIA', 'moveFile');
class OC_MEDIA
{
    /**
     * get the sha256 hash of the password needed for ampache
     * @param array $params, parameters passed from OC_Hook
     */
    public static function loginListener($params)
    {
        if (isset($_POST['user']) and $_POST['password']) {
            if (defined("DEBUG") && DEBUG) {
                error_log('postlogin');
            }
            $name = $_POST['user'];
            $query = OC_DB::prepare("SELECT user_id from *PREFIX*media_users WHERE user_id LIKE ?");
            $uid = $query->execute(array($name))->fetchAll();
Exemplo n.º 5
0
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */
if (\OC::$server->getConfig()->getSystemValue('updatechecker', true) === true) {
    $updater = new \OC\Updater\VersionCheck(\OC::$server->getHTTPClientService(), \OC::$server->getConfig());
    $updateChecker = new \OCA\UpdateNotification\UpdateChecker($updater);
    $userObject = \OC::$server->getUserSession()->getUser();
    if ($userObject !== null) {
        if (\OC::$server->getGroupManager()->isAdmin($userObject->getUID())) {
            if ($updateChecker->getUpdateState() !== []) {
                \OCP\Util::addScript('updatenotification', 'notification');
                OC_Hook::connect('\\OCP\\Config', 'js', $updateChecker, 'getJavaScript');
            }
            \OC_App::registerAdmin('updatenotification', 'admin');
        }
    }
    $manager = \OC::$server->getNotificationManager();
    $manager->registerNotifier(function () use($manager) {
        return new \OCA\UpdateNotification\Notification\Notifier($manager, \OC::$server->getL10NFactory());
    }, function () {
        $l = \OC::$server->getL10N('updatenotification');
        return ['id' => 'updatenotification', 'name' => $l->t('Update notifications')];
    });
}
Exemplo n.º 6
0
 /**
  * register hooks for sharing
  */
 public static function registerShareHooks()
 {
     if (\OC_Config::getValue('installed')) {
         OC_Hook::connect('OC_User', 'post_deleteUser', 'OCP\\Share', 'post_deleteUser');
         OC_Hook::connect('OC_User', 'post_addToGroup', 'OCP\\Share', 'post_addToGroup');
         OC_Hook::connect('OC_User', 'post_removeFromGroup', 'OCP\\Share', 'post_removeFromGroup');
         OC_Hook::connect('OC_User', 'post_deleteGroup', 'OCP\\Share', 'post_deleteGroup');
     }
 }
Exemplo n.º 7
0
 * 
 * NOTE: to make sure that the hooks are called everytime that a file is written, the application
 * must be registered with type "filesystem". Otherwise, those hooks will be called only when uploading from the web interface
 * 
 * to register the application as a filesystem type, put in info.xml * 
 * <types><filesystem/></types>
 *
 */
#OC_Hook::connect(OC\Files\Filesystem::CLASSNAME, OC\Files\Filesystem::signal_write, "OC_Neurocloud", "beforeFileWrite");
#OC_Hook::connect(OC\Files\Filesystem::CLASSNAME, OC\Files\Filesystem::signal_post_write, "OC_Neurocloud", "afterFileWrite");
OC_Hook::connect(OC\Files\Filesystem::CLASSNAME, 'post_delete', "OC_Neurocloud", "fileDeleted");
OC_Hook::connect(OC\Files\Filesystem::CLASSNAME, OC\Files\Filesystem::signal_post_rename, "OC_Neurocloud", "fileRenamed");
// hooks for delete/rename, do not allow deleting of directory if there is a running job
OC_Hook::connect(OC\Files\Filesystem::CLASSNAME, OC\Files\Filesystem::signal_delete, "OC_Neurocloud", "beforeFileRenameDelete");
OC_Hook::connect(OC\Files\Filesystem::CLASSNAME, OC\Files\Filesystem::signal_rename, "OC_Neurocloud", "beforeFileRenameDelete");
/**
 * User hooks:
 * - before login, check if the user has a home folder correctly mounted on the kore storage. Abort login if not.
 * - before creating the user, generate a RSA private key
 * - after deleting the user, delete the private key
 */
OC_Hook::connect("OC_User", "pre_createUser", "OC_Neurocloud", "beforeCreateUser");
OC_Hook::connect("OC_User", "post_deleteUser", "OC_Neurocloud", "afterDeleteUser");
OC_Hook::connect("OC_User", "pre_login", "OC_Neurocloud", "beforeLogin");
/**
 * add Javascript code
 */
OC_Util::addScript("neurocloud", "neurocloud");
// register the fileproxy implementation. This subtitutes the old pre/post write hook because of implementation changes of owncloud 5.0.0
include_once 'neurocloud/lib/proxy.php';
OC_FileProxy::register(new NC_FileProxy());
Exemplo n.º 8
0
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
/**
 * Public interface of ownCloud for apps to use.
 * Tags interface
 *
 */
// use OCP namespace for all classes that are considered public.
// This means that they should be used by apps instead of the internal ownCloud classes
namespace OCP;

// FIXME: Where should I put this? Or should it be implemented as a Listener?
\OC_Hook::connect('OC_User', 'post_deleteUser', 'OC\\Tags', 'post_deleteUser');
/**
 * Class for easily tagging objects by their id
 *
 * A tag can be e.g. 'Family', 'Work', 'Chore', 'Special Occation' or
 * anything else that is either parsed from a vobject or that the user chooses
 * to add.
 * Tag names are not case-sensitive, but will be saved with the case they
 * are entered in. If a user already has a tag 'family' for a type, and
 * tries to add a tag named 'Family' it will be silently ignored.
 */
interface ITags
{
    /**
     * Check if any tags are saved for this type and user.
     *
Exemplo n.º 9
0
<?php

set_time_limit(0);
$RUNTIME_NOAPPS = true;
require_once '../../lib/base.php';
if (OC::checkUpgrade(false)) {
    \OC_DB::enableCaching(false);
    // initialize the event source before we enter maintenance mode because CSRF protection can terminate the script
    $updateEventSource = new OC_EventSource();
    OC_Config::setValue('maintenance', true);
    $installedVersion = OC_Config::getValue('version', '0.0.0');
    $currentVersion = implode('.', OC_Util::getVersion());
    OC_Log::write('core', 'starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, OC_Log::WARN);
    $watcher = new UpdateWatcher($updateEventSource);
    OC_Hook::connect('update', 'success', $watcher, 'success');
    OC_Hook::connect('update', 'failure', $watcher, 'failure');
    $watcher->success('Turned on maintenance mode');
    try {
        $result = OC_DB::updateDbFromStructure(OC::$SERVERROOT . '/db_structure.xml');
        $watcher->success('Updated database');
        // do a file cache upgrade for users with files
        // this can take loooooooooooooooooooooooong
        __doFileCacheUpgrade($watcher);
    } catch (Exception $exception) {
        $watcher->failure($exception->getMessage());
    }
    OC_Config::setValue('version', implode('.', OC_Util::getVersion()));
    OC_App::checkAppsRequirements();
    // load all apps to also upgrade enabled apps
    OC_App::loadApps();
    OC_Config::setValue('maintenance', false);
Exemplo n.º 10
0
<?php

OC::$CLASSPATH['OC_Share_Backend_File'] = 'files_sharing/lib/share/file.php';
OC::$CLASSPATH['OC_Share_Backend_Folder'] = 'files_sharing/lib/share/folder.php';
OC::$CLASSPATH['OC\\Files\\Storage\\Shared'] = 'files_sharing/lib/sharedstorage.php';
OC::$CLASSPATH['OC\\Files\\Cache\\Shared_Cache'] = 'files_sharing/lib/cache.php';
OC::$CLASSPATH['OC\\Files\\Cache\\Shared_Permissions'] = 'files_sharing/lib/permissions.php';
OC::$CLASSPATH['OC\\Files\\Cache\\Shared_Updater'] = 'files_sharing/lib/updater.php';
OC::$CLASSPATH['OC\\Files\\Cache\\Shared_Watcher'] = 'files_sharing/lib/watcher.php';
OC::$CLASSPATH['OCA\\Files\\Share\\Api'] = 'files_sharing/lib/api.php';
OC::$CLASSPATH['OCA\\Files\\Share\\Maintainer'] = 'files_sharing/lib/maintainer.php';
OCP\Util::connectHook('OC_Filesystem', 'setup', '\\OC\\Files\\Storage\\Shared', 'setup');
OCP\Share::registerBackend('file', 'OC_Share_Backend_File');
OCP\Share::registerBackend('folder', 'OC_Share_Backend_Folder', 'file');
OCP\Util::addScript('files_sharing', 'share');
\OC_Hook::connect('OC_Filesystem', 'post_write', '\\OC\\Files\\Cache\\Shared_Updater', 'writeHook');
\OC_Hook::connect('OC_Filesystem', 'post_delete', '\\OC\\Files\\Cache\\Shared_Updater', 'postDeleteHook');
\OC_Hook::connect('OC_Filesystem', 'delete', '\\OC\\Files\\Cache\\Shared_Updater', 'deleteHook');
\OC_Hook::connect('OC_Filesystem', 'post_rename', '\\OC\\Files\\Cache\\Shared_Updater', 'renameHook');
\OC_Hook::connect('OCP\\Share', 'post_shared', '\\OC\\Files\\Cache\\Shared_Updater', 'shareHook');
\OC_Hook::connect('OCP\\Share', 'pre_unshare', '\\OC\\Files\\Cache\\Shared_Updater', 'shareHook');
\OC_Hook::connect('OC_Appconfig', 'post_set_value', '\\OCA\\Files\\Share\\Maintainer', 'configChangeHook');
Exemplo n.º 11
0
<?php

/**
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
$l = new OC_l10n('collaboration');
OC::$CLASSPATH['OC_Collaboration_Project'] = 'collaboration/lib/projects.php';
OC::$CLASSPATH['OC_Collaboration_Post'] = 'collaboration/lib/posts.php';
OC::$CLASSPATH['OC_Collaboration_Time'] = 'collaboration/lib/time.php';
OC::$CLASSPATH['OC_Collaboration_Comment'] = 'collaboration/lib/comments.php';
OC::$CLASSPATH['OC_Collaboration_Task'] = 'collaboration/lib/tasks.php';
OC::$CLASSPATH['OC_Collaboration_Mail'] = 'collaboration/lib/mail_templates.php';
OC::$CLASSPATH['OC_Collaboration_Hooks'] = 'collaboration/lib/hooks.php';
OC::$CLASSPATH['OC_Collaboration_Skillset'] = 'collaboration/lib/skillset.php';
OC::$CLASSPATH['OC_Collaboration_Report'] = 'collaboration/lib/reports.php';
OC::$CLASSPATH['OC_Collaboration_Calendar'] = 'collaboration/lib/calendar_support.php';
OC_Hook::connect('OC_User', 'post_deleteUser', 'OC_Collaboration_Hooks', 'notifyUserDeletion');
OC_Hook::connect('OCP\\Share', 'post_shared', 'OC_Collaboration_Hooks', 'notifyFileShare');
$gid = "Collaboration Admin";
if (!OC_Group::groupExists($gid)) {
    OC_Group::createGroup($gid);
}
\OCP\App::addNavigationEntry(array('id' => 'collaboration', 'order' => 0, 'href' => \OCP\Util::linkToRoute('collaboration_route', array('rel_path' => '')), 'icon' => \OCP\Util::imagePath('collaboration', 'collaboration.svg'), 'name' => $l->t('Collaboration')));
Exemplo n.º 12
0
 case 'get_collection':
     $data = array();
     $data['artists'] = $collection->getArtists();
     $data['albums'] = $collection->getAlbums();
     $data['songs'] = $collection->getSongs();
     \OCP\JSON::encodedPrint($data);
     break;
 case 'scan':
     \OCP\DB::beginTransaction();
     set_time_limit(0);
     //recursive scan can take a while
     $eventSource = new \OC_EventSource();
     $watcher = new ScanWatcher($eventSource);
     $scanner = new Scanner($collection);
     \OC_Hook::connect('media', 'song_count', $watcher, 'count');
     \OC_Hook::connect('media', 'song_scanned', $watcher, 'scanned');
     $scanner->scanCollection();
     $watcher->done();
     $eventSource->close();
     \OCP\DB::commit();
     break;
 case 'scanFile':
     $scanner = new Scanner($collection);
     echo $scanner->scanFile($arguments['path']) ? 'true' : 'false';
     break;
 case 'get_artists':
     \OCP\JSON::encodedPrint($collection->getArtists($arguments['search']));
     break;
 case 'get_albums':
     \OCP\JSON::encodedPrint($collection->getAlbums($arguments['artist'], $arguments['search']));
     break;
Exemplo n.º 13
0
 public function testHooks()
 {
     if (OC_Filesystem::getView()) {
         $user = OC_User::getUser();
     } else {
         $user = uniqid();
         OC_Filesystem::init('/' . $user . '/files');
     }
     OC_Hook::clear('OC_Filesystem');
     OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook');
     OC_Filesystem::mount('OC_Filestorage_Temporary', array(), '/');
     $rootView = new OC_FilesystemView('');
     $rootView->mkdir('/' . $user);
     $rootView->mkdir('/' . $user . '/files');
     OC_Filesystem::file_put_contents('/foo', 'foo');
     OC_Filesystem::mkdir('/bar');
     OC_Filesystem::file_put_contents('/bar//foo', 'foo');
     $tmpFile = OC_Helper::tmpFile();
     file_put_contents($tmpFile, 'foo');
     $fh = fopen($tmpFile, 'r');
     OC_Filesystem::file_put_contents('/bar//foo', $fh);
 }
Exemplo n.º 14
0
 public static function init()
 {
     // register autoloader
     spl_autoload_register(array('OC', 'autoload'));
     setlocale(LC_ALL, 'en_US.UTF-8');
     // set some stuff
     //ob_start();
     error_reporting(E_ALL | E_STRICT);
     if (defined('DEBUG') && DEBUG) {
         ini_set('display_errors', 1);
     }
     date_default_timezone_set('UTC');
     ini_set('arg_separator.output', '&amp;');
     // try to switch magic quotes off.
     if (function_exists('set_magic_quotes_runtime')) {
         @set_magic_quotes_runtime(false);
     }
     //try to configure php to enable big file uploads.
     //this doesn´t work always depending on the webserver and php configuration.
     //Let´s try to overwrite some defaults anyways
     //try to set the maximum execution time to 60min
     @set_time_limit(3600);
     @ini_set('max_execution_time', 3600);
     @ini_set('max_input_time', 3600);
     //try to set the maximum filesize to 10G
     @ini_set('upload_max_filesize', '10G');
     @ini_set('post_max_size', '10G');
     @ini_set('file_uploads', '50');
     //try to set the session lifetime to 60min
     @ini_set('gc_maxlifetime', '3600');
     //set http auth headers for apache+php-cgi work around
     if (isset($_SERVER['HTTP_AUTHORIZATION']) && preg_match('/Basic\\s+(.*)$/i', $_SERVER['HTTP_AUTHORIZATION'], $matches)) {
         list($name, $password) = explode(':', base64_decode($matches[1]));
         $_SERVER['PHP_AUTH_USER'] = strip_tags($name);
         $_SERVER['PHP_AUTH_PW'] = strip_tags($password);
     }
     //set http auth headers for apache+php-cgi work around if variable gets renamed by apache
     if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) && preg_match('/Basic\\s+(.*)$/i', $_SERVER['REDIRECT_HTTP_AUTHORIZATION'], $matches)) {
         list($name, $password) = explode(':', base64_decode($matches[1]));
         $_SERVER['PHP_AUTH_USER'] = strip_tags($name);
         $_SERVER['PHP_AUTH_PW'] = strip_tags($password);
     }
     self::initPaths();
     // register the stream wrappers
     require_once 'streamwrappers.php';
     stream_wrapper_register("fakedir", "OC_FakeDirStream");
     stream_wrapper_register('static', 'OC_StaticStreamWrapper');
     stream_wrapper_register('close', 'OC_CloseStreamWrapper');
     self::checkInstalled();
     self::checkSSL();
     // CSRF protection
     if (isset($_SERVER['HTTP_REFERER'])) {
         $referer = $_SERVER['HTTP_REFERER'];
     } else {
         $referer = '';
     }
     $refererhost = parse_url($referer);
     if (isset($refererhost['host'])) {
         $refererhost = $refererhost['host'];
     } else {
         $refererhost = '';
     }
     $server = OC_Helper::serverHost();
     $serverhost = explode(':', $server);
     $serverhost = $serverhost['0'];
     if ($_SERVER['REQUEST_METHOD'] == 'POST' and $refererhost != $serverhost) {
         $url = OC_Helper::serverProtocol() . '://' . $server . OC::$WEBROOT . '/index.php';
         header("Location: {$url}");
         exit;
     }
     self::initSession();
     self::initTemplateEngine();
     self::checkUpgrade();
     $errors = OC_Util::checkServer();
     if (count($errors) > 0) {
         OC_Template::printGuestPage('', 'error', array('errors' => $errors));
         exit;
     }
     // TODO: we should get rid of this one, too
     // WARNING: to make everything even more confusing,
     //   DATADIRECTORY is a var that changes and DATADIRECTORY_ROOT
     //   stays the same, but is set by "datadirectory".
     //   Any questions?
     OC::$CONFIG_DATADIRECTORY = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data");
     // User and Groups
     if (!OC_Config::getValue("installed", false)) {
         $_SESSION['user_id'] = '';
     }
     OC_User::useBackend(OC_Config::getValue("userbackend", "database"));
     OC_Group::useBackend(new OC_Group_Database());
     // Set up file system unless forbidden
     global $RUNTIME_NOSETUPFS;
     if (!$RUNTIME_NOSETUPFS) {
         OC_Util::setupFS();
     }
     // Load Apps
     // This includes plugins for users and filesystems as well
     global $RUNTIME_NOAPPS;
     global $RUNTIME_APPTYPES;
     if (!$RUNTIME_NOAPPS) {
         if ($RUNTIME_APPTYPES) {
             OC_App::loadApps($RUNTIME_APPTYPES);
         } else {
             OC_App::loadApps();
         }
     }
     // Check for blacklisted files
     OC_Hook::connect('OC_Filesystem', 'write', 'OC_Filesystem', 'isBlacklisted');
     //make sure temporary files are cleaned up
     register_shutdown_function(array('OC_Helper', 'cleanTmp'));
     //parse the given parameters
     self::$REQUESTEDAPP = isset($_GET['app']) && trim($_GET['app']) != '' && !is_null($_GET['app']) ? str_replace(array('\\0', '/', '\\', '..'), '', strip_tags($_GET['app'])) : OC_Config::getValue('defaultapp', 'files');
     if (substr_count(self::$REQUESTEDAPP, '?') != 0) {
         $app = substr(self::$REQUESTEDAPP, 0, strpos(self::$REQUESTEDAPP, '?'));
         $param = substr(self::$REQUESTEDAPP, strpos(self::$REQUESTEDAPP, '?') + 1);
         parse_str($param, $get);
         $_GET = array_merge($_GET, $get);
         self::$REQUESTEDAPP = $app;
         $_GET['app'] = $app;
     }
     self::$REQUESTEDFILE = isset($_GET['getfile']) ? $_GET['getfile'] : null;
     if (substr_count(self::$REQUESTEDFILE, '?') != 0) {
         $file = substr(self::$REQUESTEDFILE, 0, strpos(self::$REQUESTEDFILE, '?'));
         $param = substr(self::$REQUESTEDFILE, strpos(self::$REQUESTEDFILE, '?') + 1);
         parse_str($param, $get);
         $_GET = array_merge($_GET, $get);
         self::$REQUESTEDFILE = $file;
         $_GET['getfile'] = $file;
     }
     if (!is_null(self::$REQUESTEDFILE)) {
         $subdir = OC::$APPSROOT . '/apps/' . self::$REQUESTEDAPP . '/' . self::$REQUESTEDFILE;
         $parent = OC::$APPSROOT . '/apps/' . self::$REQUESTEDAPP;
         if (!OC_Helper::issubdirectory($subdir, $parent)) {
             self::$REQUESTEDFILE = null;
             header('HTTP/1.0 404 Not Found');
             exit;
         }
     }
 }
Exemplo n.º 15
0
 /**
  * register hooks for sharing
  */
 public static function registerShareHooks()
 {
     OC_Hook::connect('OC_User', 'post_deleteUser', 'OCP\\Share', 'post_deleteUser');
     OC_Hook::connect('OC_User', 'post_addToGroup', 'OCP\\Share', 'post_addToGroup');
     OC_Hook::connect('OC_User', 'post_removeFromGroup', 'OCP\\Share', 'post_removeFromGroup');
     OC_Hook::connect('OC_User', 'post_deleteGroup', 'OCP\\Share', 'post_deleteGroup');
 }
Exemplo n.º 16
0
<?php

OC::$CLASSPATH['OC_Share_Backend_File'] = 'files_sharing/lib/share/file.php';
OC::$CLASSPATH['OC_Share_Backend_Folder'] = 'files_sharing/lib/share/folder.php';
OC::$CLASSPATH['OC\\Files\\Storage\\Shared'] = 'files_sharing/lib/sharedstorage.php';
OC::$CLASSPATH['OC\\Files\\Cache\\Shared_Cache'] = 'files_sharing/lib/cache.php';
OC::$CLASSPATH['OC\\Files\\Cache\\Shared_Permissions'] = 'files_sharing/lib/permissions.php';
OC::$CLASSPATH['OC\\Files\\Cache\\Shared_Updater'] = 'files_sharing/lib/updater.php';
OC::$CLASSPATH['OC\\Files\\Cache\\Shared_Watcher'] = 'files_sharing/lib/watcher.php';
OCP\Util::connectHook('OC_Filesystem', 'setup', '\\OC\\Files\\Storage\\Shared', 'setup');
OCP\Share::registerBackend('file', 'OC_Share_Backend_File');
OCP\Share::registerBackend('folder', 'OC_Share_Backend_Folder', 'file');
OCP\Util::addScript('files_sharing', 'share');
\OC_Hook::connect('OC_Filesystem', 'post_write', '\\OC\\Files\\Cache\\Shared_Updater', 'writeHook');
\OC_Hook::connect('OC_Filesystem', 'delete', '\\OC\\Files\\Cache\\Shared_Updater', 'deleteHook');
\OC_Hook::connect('OC_Filesystem', 'post_rename', '\\OC\\Files\\Cache\\Shared_Updater', 'renameHook');
\OC_Hook::connect('OCP\\Share', 'post_shared', '\\OC\\Files\\Cache\\Shared_Updater', 'shareHook');
\OC_Hook::connect('OCP\\Share', 'pre_unshare', '\\OC\\Files\\Cache\\Shared_Updater', 'shareHook');
Exemplo n.º 17
0
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*
*/
OC_Hook::connect('OC_User', 'post_deleteUser', 'OC_VCategories', 'post_deleteUser');
/**
 * Class for easy access to categories in VCARD, VEVENT, VTODO and VJOURNAL.
 * A Category can be e.g. 'Family', 'Work', 'Chore', 'Special Occation' or
 * anything else that is either parsed from a vobject or that the user chooses
 * to add.
 * Category names are not case-sensitive, but will be saved with the case they
 * are entered in. If a user already has a category 'family' for a type, and
 * tries to add a category named 'Family' it will be silently ignored.
 */
class OC_VCategories
{
    /**
     * Categories
     */
    private $categories = array();
Exemplo n.º 18
0
     */
    public static function clear($user = '')
    {
        if ($user) {
            $query = OC_DB::prepare('DELETE FROM `*PREFIX*fscache` WHERE `user`=?');
            $query->execute(array($user));
        } else {
            $query = OC_DB::prepare('DELETE FROM `*PREFIX*fscache`');
            $query->execute();
        }
    }
    /**
     * trigger an update for the cache by setting the mtimes to 0
     * @param string $user (optional)
     */
    public static function triggerUpdate($user = '')
    {
        if ($user) {
            $query = OC_DB::prepare('UPDATE `*PREFIX*fscache` SET `mtime`=0 WHERE `user`=? AND `mimetype`="httpd/unix-directory"');
            $query->execute(array($user));
        } else {
            $query = OC_DB::prepare('UPDATE `*PREFIX*fscache` SET `mtime`=0 AND `mimetype`="httpd/unix-directory"');
            $query->execute();
        }
    }
}
//watch for changes and try to keep the cache up to date
OC_Hook::connect('OC_Filesystem', 'post_write', 'OC_FileCache_Update', 'fileSystemWatcherWrite');
OC_Hook::connect('OC_Filesystem', 'post_delete', 'OC_FileCache_Update', 'fileSystemWatcherDelete');
OC_Hook::connect('OC_Filesystem', 'post_rename', 'OC_FileCache_Update', 'fileSystemWatcherRename');
Exemplo n.º 19
0
<?php

$l = OC_L10N::get('files');
OCP\App::registerAdmin('files', 'admin');
OCP\App::addNavigationEntry(array("id" => "files_index", "order" => 0, "href" => OCP\Util::linkTo("files", "index.php"), "icon" => OCP\Util::imagePath("core", "places/files.png"), "name" => $l->t("Files")));
OC_Search::registerProvider('OC_Search_Provider_File');
// cache hooks must be connected before all other apps.
// since 'files' is always loaded first the hooks need to be connected here
\OC_Hook::connect('OC_Filesystem', 'post_write', '\\OC\\Files\\Cache\\Updater', 'writeHook');
\OC_Hook::connect('OC_Filesystem', 'post_touch', '\\OC\\Files\\Cache\\Updater', 'touchHook');
\OC_Hook::connect('OC_Filesystem', 'post_delete', '\\OC\\Files\\Cache\\Updater', 'deleteHook');
\OC_Hook::connect('OC_Filesystem', 'post_rename', '\\OC\\Files\\Cache\\Updater', 'renameHook');
\OCP\BackgroundJob::addRegularTask('\\OC\\Files\\Cache\\BackgroundWatcher', 'checkNext');
$templateManager = OC_Helper::getFileTemplateManager();
$templateManager->registerTemplate('text/html', 'core/templates/filetemplates/template.html');
$templateManager->registerTemplate('application/vnd.oasis.opendocument.presentation', 'core/templates/filetemplates/template.odp');
$templateManager->registerTemplate('application/vnd.oasis.opendocument.text', 'core/templates/filetemplates/template.odt');
$templateManager->registerTemplate('application/vnd.oasis.opendocument.spreadsheet', 'core/templates/filetemplates/template.ods');
<?php

require_once 'apps/files_sharing/sharedstorage.php';
OC::$CLASSPATH['OC_Share'] = "apps/files_sharing/lib_share.php";
OC_Hook::connect("OC_Filesystem", "post_delete", "OC_Share", "deleteItem");
OC_Hook::connect("OC_Filesystem", "post_rename", "OC_Share", "renameItem");
OC_Filesystem::registerStorageType("shared", "OC_Filestorage_Shared", array("datadir" => "string"));
OC_Util::addScript("files_sharing", "share");
OC_Util::addScript("3rdparty", "chosen/chosen.jquery.min");
OC_Util::addStyle('files_sharing', 'sharing');
OC_Util::addStyle("3rdparty", "chosen/chosen");
Exemplo n.º 21
0
 public function testHooks()
 {
     if (\OC\Files\Filesystem::getView()) {
         $user = \OC_User::getUser();
     } else {
         $user = self::TEST_FILESYSTEM_USER1;
         $backend = new \Test\Util\User\Dummy();
         \OC_User::useBackend($backend);
         $backend->createUser($user, $user);
         $userObj = \OC::$server->getUserManager()->get($user);
         \OC::$server->getUserSession()->setUser($userObj);
         \OC\Files\Filesystem::init($user, '/' . $user . '/files');
     }
     \OC_Hook::clear('OC_Filesystem');
     \OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook');
     \OC\Files\Filesystem::mount('OC\\Files\\Storage\\Temporary', array(), '/');
     $rootView = new \OC\Files\View('');
     $rootView->mkdir('/' . $user);
     $rootView->mkdir('/' . $user . '/files');
     //		\OC\Files\Filesystem::file_put_contents('/foo', 'foo');
     \OC\Files\Filesystem::mkdir('/bar');
     //		\OC\Files\Filesystem::file_put_contents('/bar//foo', 'foo');
     $tmpFile = \OC::$server->getTempManager()->getTemporaryFile();
     file_put_contents($tmpFile, 'foo');
     $fh = fopen($tmpFile, 'r');
     //		\OC\Files\Filesystem::file_put_contents('/bar//foo', $fh);
 }
Exemplo n.º 22
0
 public function testHooks()
 {
     if (\OC\Files\Filesystem::getView()) {
         $user = \OC_User::getUser();
     } else {
         $user = $this->getUniqueID();
         \OC\Files\Filesystem::init($user, '/' . $user . '/files');
     }
     \OC_Hook::clear('OC_Filesystem');
     \OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook');
     \OC\Files\Filesystem::mount('OC\\Files\\Storage\\Temporary', array(), '/');
     $rootView = new \OC\Files\View('');
     $rootView->mkdir('/' . $user);
     $rootView->mkdir('/' . $user . '/files');
     //		\OC\Files\Filesystem::file_put_contents('/foo', 'foo');
     \OC\Files\Filesystem::mkdir('/bar');
     //		\OC\Files\Filesystem::file_put_contents('/bar//foo', 'foo');
     $tmpFile = \OC_Helper::tmpFile();
     file_put_contents($tmpFile, 'foo');
     $fh = fopen($tmpFile, 'r');
     //		\OC\Files\Filesystem::file_put_contents('/bar//foo', $fh);
 }
Exemplo n.º 23
0
 /**
  * register hooks for sharing
  */
 public static function registerShareHooks()
 {
     if (\OC::$server->getSystemConfig()->getValue('installed')) {
         OC_Hook::connect('OC_User', 'post_deleteUser', 'OC\\Share\\Hooks', 'post_deleteUser');
         OC_Hook::connect('OC_User', 'post_addToGroup', 'OC\\Share\\Hooks', 'post_addToGroup');
         OC_Hook::connect('OC_Group', 'pre_addToGroup', 'OC\\Share\\Hooks', 'pre_addToGroup');
         OC_Hook::connect('OC_User', 'post_removeFromGroup', 'OC\\Share\\Hooks', 'post_removeFromGroup');
         OC_Hook::connect('OC_User', 'post_deleteGroup', 'OC\\Share\\Hooks', 'post_deleteGroup');
     }
 }
Exemplo n.º 24
0
 public static function init()
 {
     // register autoloader
     spl_autoload_register(array('OC', 'autoload'));
     setlocale(LC_ALL, 'en_US.UTF-8');
     // set some stuff
     //ob_start();
     error_reporting(E_ALL | E_STRICT);
     if (defined('DEBUG') && DEBUG) {
         ini_set('display_errors', 1);
     }
     self::$CLI = php_sapi_name() == 'cli';
     date_default_timezone_set('UTC');
     ini_set('arg_separator.output', '&amp;');
     // try to switch magic quotes off.
     if (function_exists('set_magic_quotes_runtime')) {
         @set_magic_quotes_runtime(false);
     }
     //try to configure php to enable big file uploads.
     //this doesn´t work always depending on the webserver and php configuration.
     //Let´s try to overwrite some defaults anyways
     //try to set the maximum execution time to 60min
     @set_time_limit(3600);
     @ini_set('max_execution_time', 3600);
     @ini_set('max_input_time', 3600);
     //try to set the maximum filesize to 10G
     @ini_set('upload_max_filesize', '10G');
     @ini_set('post_max_size', '10G');
     @ini_set('file_uploads', '50');
     //try to set the session lifetime to 60min
     @ini_set('gc_maxlifetime', '3600');
     //set http auth headers for apache+php-cgi work around
     if (isset($_SERVER['HTTP_AUTHORIZATION']) && preg_match('/Basic\\s+(.*)$/i', $_SERVER['HTTP_AUTHORIZATION'], $matches)) {
         list($name, $password) = explode(':', base64_decode($matches[1]), 2);
         $_SERVER['PHP_AUTH_USER'] = strip_tags($name);
         $_SERVER['PHP_AUTH_PW'] = strip_tags($password);
     }
     //set http auth headers for apache+php-cgi work around if variable gets renamed by apache
     if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) && preg_match('/Basic\\s+(.*)$/i', $_SERVER['REDIRECT_HTTP_AUTHORIZATION'], $matches)) {
         list($name, $password) = explode(':', base64_decode($matches[1]), 2);
         $_SERVER['PHP_AUTH_USER'] = strip_tags($name);
         $_SERVER['PHP_AUTH_PW'] = strip_tags($password);
     }
     self::initPaths();
     // set debug mode if an xdebug session is active
     if (!defined('DEBUG') || !DEBUG) {
         if (isset($_COOKIE['XDEBUG_SESSION'])) {
             define('DEBUG', true);
         }
     }
     // register the stream wrappers
     require_once 'streamwrappers.php';
     stream_wrapper_register("fakedir", "OC_FakeDirStream");
     stream_wrapper_register('static', 'OC_StaticStreamWrapper');
     stream_wrapper_register('close', 'OC_CloseStreamWrapper');
     self::checkInstalled();
     self::checkSSL();
     self::initSession();
     self::initTemplateEngine();
     self::checkUpgrade();
     $errors = OC_Util::checkServer();
     if (count($errors) > 0) {
         OC_Template::printGuestPage('', 'error', array('errors' => $errors));
         exit;
     }
     // User and Groups
     if (!OC_Config::getValue("installed", false)) {
         $_SESSION['user_id'] = '';
     }
     OC_User::useBackend(new OC_User_Database());
     OC_Group::useBackend(new OC_Group_Database());
     if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SESSION['user_id']) && $_SERVER['PHP_AUTH_USER'] != $_SESSION['user_id']) {
         OC_User::logout();
     }
     // Load Apps
     // This includes plugins for users and filesystems as well
     global $RUNTIME_NOAPPS;
     global $RUNTIME_APPTYPES;
     if (!$RUNTIME_NOAPPS) {
         if ($RUNTIME_APPTYPES) {
             OC_App::loadApps($RUNTIME_APPTYPES);
         } else {
             OC_App::loadApps();
         }
     }
     //setup extra user backends
     OC_User::setupBackends();
     // register cache cleanup jobs
     OC_BackgroundJob_RegularTask::register('OC_Cache_FileGlobal', 'gc');
     OC_Hook::connect('OC_User', 'post_login', 'OC_Cache_File', 'loginListener');
     // Check for blacklisted files
     OC_Hook::connect('OC_Filesystem', 'write', 'OC_Filesystem', 'isBlacklisted');
     OC_Hook::connect('OC_Filesystem', 'rename', 'OC_Filesystem', 'isBlacklisted');
     //make sure temporary files are cleaned up
     register_shutdown_function(array('OC_Helper', 'cleanTmp'));
     //parse the given parameters
     self::$REQUESTEDAPP = isset($_GET['app']) && trim($_GET['app']) != '' && !is_null($_GET['app']) ? str_replace(array('\\0', '/', '\\', '..'), '', strip_tags($_GET['app'])) : OC_Config::getValue('defaultapp', 'files');
     if (substr_count(self::$REQUESTEDAPP, '?') != 0) {
         $app = substr(self::$REQUESTEDAPP, 0, strpos(self::$REQUESTEDAPP, '?'));
         $param = substr($_GET['app'], strpos($_GET['app'], '?') + 1);
         parse_str($param, $get);
         $_GET = array_merge($_GET, $get);
         self::$REQUESTEDAPP = $app;
         $_GET['app'] = $app;
     }
     self::$REQUESTEDFILE = isset($_GET['getfile']) ? $_GET['getfile'] : null;
     if (substr_count(self::$REQUESTEDFILE, '?') != 0) {
         $file = substr(self::$REQUESTEDFILE, 0, strpos(self::$REQUESTEDFILE, '?'));
         $param = substr(self::$REQUESTEDFILE, strpos(self::$REQUESTEDFILE, '?') + 1);
         parse_str($param, $get);
         $_GET = array_merge($_GET, $get);
         self::$REQUESTEDFILE = $file;
         $_GET['getfile'] = $file;
     }
     if (!is_null(self::$REQUESTEDFILE)) {
         $subdir = OC_App::getAppPath(OC::$REQUESTEDAPP) . '/' . self::$REQUESTEDFILE;
         $parent = OC_App::getAppPath(OC::$REQUESTEDAPP);
         if (!OC_Helper::issubdirectory($subdir, $parent)) {
             self::$REQUESTEDFILE = null;
             header('HTTP/1.0 404 Not Found');
             exit;
         }
     }
 }
Exemplo n.º 25
0
 /**
  * @brief connects a function to a hook
  * @param string $signalclass class name of emitter
  * @param string $signalname name of signal
  * @param string $slotclass class name of slot
  * @param string $slotname name of slot
  * @returns bool
  *
  * This function makes it very easy to connect to use hooks.
  *
  * TODO: write example
  */
 public static function connectHook($signalclass, $signalname, $slotclass, $slotname)
 {
     return \OC_Hook::connect($signalclass, $signalname, $slotclass, $slotname);
 }
Exemplo n.º 26
0
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*/
namespace OCP;

\OC_Hook::connect('OC_User', 'post_deleteUser', 'OCP\\Share', 'post_deleteUser');
\OC_Hook::connect('OC_User', 'post_addToGroup', 'OCP\\Share', 'post_addToGroup');
\OC_Hook::connect('OC_User', 'post_removeFromGroup', 'OCP\\Share', 'post_removeFromGroup');
\OC_Hook::connect('OC_User', 'post_deleteGroup', 'OCP\\Share', 'post_deleteGroup');
/**
* This class provides the ability for apps to share their content between users.
* Apps must create a backend class that implements OCP\Share_Backend and register it with this class.
*/
class Share
{
    const SHARE_TYPE_USER = 0;
    const SHARE_TYPE_GROUP = 1;
    const SHARE_TYPE_LINK = 3;
    const SHARE_TYPE_EMAIL = 4;
    const SHARE_TYPE_CONTACT = 5;
    const SHARE_TYPE_REMOTE = 6;
    /** CRUDS permissions (Create, Read, Update, Delete, Share) using a bitmask
     * Construct permissions for share() and setPermissions with Or (|) e.g. Give user read and update permissions: PERMISSION_READ | PERMISSION_UPDATE
     * Check if permission is granted with And (&) e.g. Check if delete is granted: if ($permissions & PERMISSION_DELETE)
Exemplo n.º 27
0
 public function testLegacyArguments()
 {
     \OC_Hook::connect('Test', 'test', '\\Test\\Hooks\\LegacyEmitter', 'staticLegacyArgumentsCallBack');
     $this->emitter->emitEvent('Test', 'test', array('foo' => 'foo', 'bar' => 'bar'));
     $this->assertEquals(true, self::$emitted);
 }
Exemplo n.º 28
0
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */
OC_Hook::connect('OC_User', 'post_deleteUser', 'OC_SubAdmin', 'post_deleteUser');
OC_Hook::connect('OC_User', 'post_deleteGroup', 'OC_SubAdmin', 'post_deleteGroup');
/**
 * This class provides all methods needed for managing groups.
 *
 * Hooks provided:
 *   post_createSubAdmin($gid)
 *   post_deleteSubAdmin($gid)
 */
class OC_SubAdmin
{
    /**
     * add a SubAdmin
     * @param string $uid uid of the SubAdmin
     * @param string $gid gid of the group
     * @return boolean
     */
Exemplo n.º 29
0
 public function testEditNoCreateHook()
 {
     $storage1 = $this->getTestStorage();
     $storage2 = $this->getTestStorage();
     $defaultRoot = \OC\Files\Filesystem::getRoot();
     \OC\Files\Filesystem::mount($storage1, array(), '/');
     \OC\Files\Filesystem::mount($storage2, array(), $defaultRoot);
     \OC_Hook::connect('OC_Filesystem', 'post_create', $this, 'dummyHookCreate');
     \OC_Hook::connect('OC_Filesystem', 'post_update', $this, 'dummyHookUpdate');
     \OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHookWrite');
     $view = new \OC\Files\View($defaultRoot);
     $this->hookWritePath = $this->hookUpdatePath = $this->hookCreatePath = null;
     $view->file_put_contents('/asd.txt', 'foo');
     $this->assertEquals('/asd.txt', $this->hookCreatePath);
     $this->assertNull($this->hookUpdatePath);
     $this->assertEquals('/asd.txt', $this->hookWritePath);
     $this->hookWritePath = $this->hookUpdatePath = $this->hookCreatePath = null;
     $view->file_put_contents('/asd.txt', 'foo');
     $this->assertNull($this->hookCreatePath);
     $this->assertEquals('/asd.txt', $this->hookUpdatePath);
     $this->assertEquals('/asd.txt', $this->hookWritePath);
     \OC_Hook::clear('OC_Filesystem', 'post_create');
     \OC_Hook::clear('OC_Filesystem', 'post_update');
     \OC_Hook::clear('OC_Filesystem', 'post_write');
 }
Exemplo n.º 30
0
    public static function clear($user = '')
    {
        if ($user) {
            $query = OC_DB::prepare('DELETE FROM `*PREFIX*fscache` WHERE `user`=?');
            $query->execute(array($user));
        } else {
            $query = OC_DB::prepare('DELETE FROM `*PREFIX*fscache`');
            $query->execute();
        }
    }
    /**
     * trigger an update for the cache by setting the mtimes to 0
     * @param string $user (optional)
     */
    public static function triggerUpdate($user = '')
    {
        if ($user) {
            $query = OC_DB::prepare('UPDATE `*PREFIX*fscache` SET `mtime`=0 WHERE `user`=? AND `mimetype`= ?  ');
            $query->execute(array($user, 'httpd/unix-directory'));
        } else {
            $query = OC_DB::prepare('UPDATE `*PREFIX*fscache` SET `mtime`=0 AND `mimetype`= ? ');
            $query->execute(array('httpd/unix-directory'));
        }
    }
}
//watch for changes and try to keep the cache up to date
OC_Hook::connect('OC_Filesystem', 'post_write', 'OC_FileCache_Update', 'fileSystemWatcherWrite');
OC_Hook::connect('OC_Filesystem', 'post_delete', 'OC_FileCache_Update', 'fileSystemWatcherDelete');
OC_Hook::connect('OC_Filesystem', 'post_rename', 'OC_FileCache_Update', 'fileSystemWatcherRename');
OC_Hook::connect('OC_User', 'post_deleteUser', 'OC_FileCache_Update', 'deleteFromUser');