Copyright 2002-2016 Horde LLC (http://www.horde.org/) See the enclosed file COPYING for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.
Author: Chuck Hagenbuch (chuck@horde.org)
Exemple #1
0
/**
 * Does an FTP upload to save the configuration.
 */
function _uploadFTP($params)
{
    global $registry, $notification;
    $params['hostspec'] = 'localhost';
    try {
        $vfs = Horde_Vfs::factory('ftp', $params);
    } catch (Horde_Vfs_Exception $e) {
        $notification->push(sprintf(_("Could not connect to server \"%s\" using FTP: %s"), $params['hostspec'], $e->getMessage()), 'horde.error');
        return false;
    }
    /* Loop through the config and write to FTP. */
    $no_errors = true;
    foreach ($GLOBALS['session']->get('horde', 'config/') as $app => $config) {
        $path = $registry->get('fileroot', $app) . '/config';
        /* Try to back up the current conf.php. */
        if ($vfs->exists($path, 'conf.php')) {
            try {
                $vfs->rename($path, 'conf.php', $path, '/conf.bak.php');
                $notification->push(_("Successfully saved backup configuration."), 'horde.success');
            } catch (Horde_Vfs_Exception $e) {
                $notification->push(sprintf(_("Could not save a backup configuation: %s"), $e->getMessage()), 'horde.error');
            }
        }
        try {
            $vfs->writeData($path, 'conf.php', $config);
            $notification->push(sprintf(_("Successfully wrote %s"), Horde_Util::realPath($path . '/conf.php')), 'horde.success');
            $GLOBALS['session']->remove('horde', 'config/' . $app);
        } catch (Horde_Vfs_Exception $e) {
            $no_errors = false;
            $notification->push(sprintf(_("Could not write configuration for \"%s\": %s"), $app, $e->getMessage()), 'horde.error');
        }
    }
    $registry->rebuild();
    return $no_errors;
}
Exemple #2
0
 /**
  * Test setup.
  *
  * @return NULL
  */
 public function setUp()
 {
     $this->markTestIncomplete('Convert to Horde4');
     $world = $this->prepareBasicSetup();
     $this->assertTrue($world['auth']->authenticate('*****@*****.**', array('password' => 'none')));
     $this->_vfs = Horde_Vfs::factory('kolab');
 }
Exemple #3
0
 public static function setUpBeforeClass()
 {
     $config = self::getConfig('VFS_FTP_TEST_CONFIG', __DIR__);
     if ($config && !empty($config['vfs']['smb'])) {
         if (!is_executable($config['vfs']['smb']['smbclient'])) {
             self::$reason = 'No executable smbclient';
             return;
         }
         self::$vfs = Horde_Vfs::factory('Smb', $config['vfs']['smb']);
     } else {
         self::$reason = 'No smb configuration';
     }
 }
Exemple #4
0
 /**
  * Connects to the FTP server.
  *
  * @throws Passwd_Exception
  */
 protected function _connect($user, $password)
 {
     if ($this->_connected) {
         return;
     }
     $params = array('username' => $user, 'password' => $password, 'hostspec' => $this->_params['host'], 'port' => $this->_params['port']);
     try {
         $this->_ftp = Horde_Vfs::factory('ftp', $params);
         $this->_ftp->checkCredentials();
     } catch (Horde_Vfs_Exception $e) {
         throw new Passwd_Exception($e);
     }
     $this->_connected = true;
 }
Exemple #5
0
 /**
  */
 protected function _init()
 {
     try {
         $this->storage = Shout_Driver::factory('storage');
         $this->extensions = Shout_Driver::factory('extensions');
         $this->devices = Shout_Driver::factory('devices');
         $this->dialplan = Shout_Driver::factory('dialplan');
         $conf = $GLOBALS['conf'];
         $this->vfs = Horde_Vfs::factory($conf['ivr']['driver'], $conf['ivr']['params']);
         $accounts = $this->storage->getAccounts();
     } catch (Shout_Exception $e) {
         $GLOBALS['notification']->push($e);
         $accounts = false;
         return false;
     }
     $account = Horde_Util::getFormData('account');
     if (empty($account)) {
         $account = $GLOBALS['session']->get('shout', 'curaccount_code');
     }
     if (!empty($account) && !in_array($account, array_keys($accounts))) {
         // Requested account not available
         $GLOBALS['notification']->push(_("You do not have permission to access that account."), 'horde.error');
         $account = false;
     }
     if (empty($account)) {
         if (count($accounts)) {
             // Default to the user's first account
             $account = reset(array_keys($accounts));
         } else {
             // No account requested and/or no accounts available anyway
             $GLOBALS['notification']->push("Please select a account to continue.", 'horde.info');
             $account = false;
         }
     }
     $session->set('shout', 'curaccount_code', $accounts[$account]['code']);
     $session->set('shout', 'curaccount_name', $accounts[$account]['name']);
 }
Exemple #6
0
 /**
  * Returns the VFS instance.
  *
  * @param string $backend  The backend to return.
  *
  * @return Horde_Vfs  The VFS object.
  */
 public function create($backend)
 {
     if (empty($this->_instances[$backend])) {
         $be_config = Gollem_Auth::getBackend($backend);
         $params = $be_config['params'];
         switch (Horde_String::lower($be_config['driver'])) {
             case 'sql':
             case 'sqlfile':
             case 'musql':
                 $db_params = $params;
                 unset($db_params['table']);
                 $params['db'] = $this->_injector->getInstance('Horde_Core_Factory_Db')->create('gollem', $db_params);
                 $params['user'] = $GLOBALS['registry']->getAuth();
                 break;
         }
         $vfs = Horde_Vfs::factory($be_config['driver'], $params);
         if (!empty($be_config['quota'])) {
             $vfs->setQuotaRoot($be_config['root'] == '/' ? '' : $be_config['root']);
             if (isset($be_config['quota_val'])) {
                 $vfs->setQuota($be_config['quota_val'], $be_config['quota_metric']);
             } else {
                 $quota_metric = array('B' => Horde_Vfs::QUOTA_METRIC_BYTE, 'KB' => Horde_Vfs::QUOTA_METRIC_KB, 'MB' => Horde_Vfs::QUOTA_METRIC_MB, 'GB' => Horde_Vfs::QUOTA_METRIC_GB);
                 $quota_str = explode(' ', $be_config['quota'], 2);
                 if (is_numeric($quota_str[0])) {
                     $metric = trim(Horde_String::upper($quota_str[1]));
                     if (!isset($quota_metric[$metric])) {
                         $metric = 'B';
                     }
                     $vfs->setQuota($quota_str[0], $quota_metric[$metric]);
                 }
             }
         }
         $this->_instances[$backend] = $vfs;
     }
     return $this->_instances[$backend];
 }
Exemple #7
0
 public function testHostspecWithPath()
 {
     self::$vfs->createFolder('', 'hostspectest');
     self::$vfs->createFolder('hostspectest', 'directory');
     self::$vfs->createFolder('hostspectest/directory', 'subdir');
     $config = self::getConfig('VFS_FTP_TEST_CONFIG', __DIR__);
     $config['vfs']['smb']['share'] .= '/hostspectest';
     $vfs = Horde_Vfs::factory('Smb', $config['vfs']['smb']);
     $this->assertEquals(array('subdir'), array_keys($vfs->listFolder('directory')));
 }
Exemple #8
0
 public static function setUpBeforeClass()
 {
     if (!extension_loaded('ftp')) {
         self::$reason = 'No ftp extension';
         return;
     }
     $config = self::getConfig('VFS_FTP_TEST_CONFIG', __DIR__);
     if ($config && !empty($config['vfs']['ftp'])) {
         self::$vfs = Horde_Vfs::factory('Ftp', $config['vfs']['ftp']);
     } else {
         self::$reason = 'No ftp configuration';
     }
 }
Exemple #9
0
 public static function setUpBeforeClass()
 {
     self::$vfs = Horde_Vfs::factory('File', array('vfsroot' => sys_get_temp_dir() . '/vfsfiletest'));
 }
Exemple #10
0
 public static function setUpBeforeClass()
 {
     if (($config = self::getConfig('VFS_MONGO_TEST_CONFIG', __DIR__)) && isset($config['vfs']['mongo']['hostspec'])) {
         $factory = new Horde_Test_Factory_Mongo();
         self::$_mongo = $factory->create(array('config' => $config['vfs']['mongo']['hostspec'], 'dbname' => 'horde_vfs_mongodbtest'));
     }
     if (empty(self::$_mongo)) {
         self::$reason = 'MongoDB not available.';
     } else {
         self::$vfs = Horde_Vfs::factory('Mongo', array('mongo_db' => self::$_mongo));
     }
 }