/** * Prepare FTP connection * Connect to remote server and check if credentials are correct, if so, store the connection id in $ftp_conn * * @return bool * @author Dmitry (dio) Levashov * @author Cem (DiscoFever) **/ protected function init() { if (!class_exists('PDO', false)) { return $this->setError('PHP PDO class is require.'); } if (!$this->options['consumerKey'] || !$this->options['consumerSecret'] || !$this->options['accessToken'] || !$this->options['accessTokenSecret']) { return $this->setError('Required options undefined.'); } if (empty($this->options['metaCachePath']) && defined('ELFINDER_DROPBOX_META_CACHE_PATH')) { $this->options['metaCachePath'] = ELFINDER_DROPBOX_META_CACHE_PATH; } // make net mount key $this->netMountKey = md5(join('-', array('dropbox', $this->options['path']))); if (!$this->oauth) { if (defined('ELFINDER_DROPBOX_USE_CURL_PUT')) { $this->oauth = new Dropbox_OAuth_Curl($this->options['consumerKey'], $this->options['consumerSecret']); } else { if (class_exists('OAuth', false)) { $this->oauth = new Dropbox_OAuth_PHP($this->options['consumerKey'], $this->options['consumerSecret']); } else { if (!class_exists('HTTP_OAuth_Consumer')) { // We're going to try to load in manually include 'HTTP/OAuth/Consumer.php'; } if (class_exists('HTTP_OAuth_Consumer', false)) { $this->oauth = new Dropbox_OAuth_PEAR($this->options['consumerKey'], $this->options['consumerSecret']); } } } } if (!$this->oauth) { return $this->setError('OAuth extension not loaded.'); } // normalize root path $this->root = $this->options['path'] = $this->_normpath($this->options['path']); if (empty($this->options['alias'])) { $this->options['alias'] = $this->options['path'] === '/' ? 'Dropbox.com' : 'Dropbox' . $this->options['path']; } $this->rootName = $this->options['alias']; try { $this->oauth->setToken($this->options['accessToken'], $this->options['accessTokenSecret']); $this->dropbox = new Dropbox_API($this->oauth, $this->options['root']); } catch (Dropbox_Exception $e) { $this->session->remove('DropboxTokens'); return $this->setError('Dropbox error: ' . $e->getMessage()); } // user if (empty($this->options['dropboxUid'])) { try { $res = $this->dropbox->getAccountInfo(); $this->options['dropboxUid'] = $res['uid']; } catch (Dropbox_Exception $e) { $this->session->remove('DropboxTokens'); return $this->setError('Dropbox error: ' . $e->getMessage()); } } $this->dropboxUid = $this->options['dropboxUid']; $this->tmbPrefix = 'dropbox' . base_convert($this->dropboxUid, 10, 32); if (!empty($this->options['tmpPath'])) { if ((is_dir($this->options['tmpPath']) || mkdir($this->options['tmpPath'])) && is_writable($this->options['tmpPath'])) { $this->tmp = $this->options['tmpPath']; } } if (!$this->tmp && is_writable($this->options['tmbPath'])) { $this->tmp = $this->options['tmbPath']; } if (!$this->tmp && ($tmp = elFinder::getStaticVar('commonTempPath'))) { $this->tmp = $tmp; } if (!empty($this->options['metaCachePath'])) { if ((is_dir($this->options['metaCachePath']) || mkdir($this->options['metaCachePath'])) && is_writable($this->options['metaCachePath'])) { $this->metaCache = $this->options['metaCachePath']; } } if (!$this->metaCache && $this->tmp) { $this->metaCache = $this->tmp; } if (!$this->metaCache) { return $this->setError('Cache dirctory (metaCachePath or tmp) is require.'); } // setup PDO if (!$this->options['PDO_DSN']) { $this->options['PDO_DSN'] = 'sqlite:' . $this->metaCache . DIRECTORY_SEPARATOR . '.elFinder_dropbox_db_' . md5($this->dropboxUid . $this->options['consumerSecret']); } // DataBase table name $this->DB_TableName = $this->options['PDO_DBName']; // DataBase check or make table try { $this->DB = new PDO($this->options['PDO_DSN'], $this->options['PDO_User'], $this->options['PDO_Pass'], $this->options['PDO_Options']); if (!$this->checkDB()) { return $this->setError('Can not make DB table'); } } catch (PDOException $e) { return $this->setError('PDO connection failed: ' . $e->getMessage()); } $res = $this->deltaCheck($this->isMyReload()); if ($res !== true) { if (is_string($res)) { return $this->setError($res); } else { return $this->setError('Could not check API "delta"'); } } if (is_null($this->options['syncChkAsTs'])) { $this->options['syncChkAsTs'] = true; } if ($this->options['syncChkAsTs']) { // 'tsPlSleep' minmum 5 sec $this->options['tsPlSleep'] = max(5, $this->options['tsPlSleep']); } else { // 'lsPlSleep' minmum 10 sec $this->options['lsPlSleep'] = max(10, $this->options['lsPlSleep']); } return true; }
/** * Prepare FTP connection * Connect to remote server and check if credentials are correct, if so, store the connection id in $ftp_conn * * @return bool * @author Dmitry (dio) Levashov * @author Cem (DiscoFever) **/ protected function init() { $this->netmountPrepare($this->options); if (!$this->options['consumerKey'] || !$this->options['consumerSecret'] || !$this->options['accessToken'] || !$this->options['accessTokenSecret']) { return $this->setError('Required options undefined.'); } // make net mount key $this->netMountKey = md5(join('-', array('dropbox', $this->options['path']))); if (!$this->oauth) { if (class_exists('OAuth')) { $this->oauth = new Dropbox_OAuth_PHP($this->options['consumerKey'], $this->options['consumerSecret']); } else { if (!class_exists('HTTP_OAuth_Consumer')) { // We're going to try to load in manually include 'HTTP/OAuth/Consumer.php'; } if (class_exists('HTTP_OAuth_Consumer')) { $this->oauth = new Dropbox_OAuth_PEAR($this->options['consumerKey'], $this->options['consumerSecret']); } } } if (!$this->oauth) { return $this->setError('OAuth extension not loaded.'); } // normalize root path $this->root = $this->options['path'] = $this->_normpath($this->options['path']); if (empty($this->options['alias'])) { $this->options['alias'] = $this->options['path'] === '/' ? 'Dropbox.com' : 'Dropbox' . $this->options['path']; } $this->rootName = $this->options['alias']; $this->options['separator'] = '/'; try { $this->oauth->setToken($this->options['accessToken'], $this->options['accessTokenSecret']); $this->dropbox = new Dropbox_API($this->oauth, $this->options['root']); } catch (Dropbox_Exception $e) { unset($_SESSION['elFinderDropboxTokens']); return $this->setError('Dropbox error: ' . $e->getMessage()); } // user if (empty($this->options['dropboxUid'])) { try { $res = $this->dropbox->getAccountInfo(); $this->options['dropboxUid'] = $res['uid']; } catch (Dropbox_Exception $e) { unset($_SESSION['elFinderDropboxTokens']); return $this->setError('Dropbox error: ' . $e->getMessage()); } } $this->dropboxUid = $this->options['dropboxUid']; if (!empty($this->options['tmpPath'])) { if ((is_dir($this->options['tmpPath']) || @mkdir($this->options['tmpPath'])) && is_writable($this->options['tmpPath'])) { $this->tmp = $this->options['tmpPath']; } } if (!$this->tmp && is_writable($this->options['tmbPath'])) { $this->tmp = $this->options['tmbPath']; } if (!empty($this->options['metaCachePath'])) { if ((is_dir($this->options['metaCachePath']) || @mkdir($this->options['metaCachePath'])) && is_writable($this->options['metaCachePath'])) { $this->metaCache = $this->options['metaCachePath']; } } if (!$this->metaCache && $this->tmp) { $this->metaCache = $this->tmp; } if (!$this->tmp) { $this->disabled[] = 'archive'; $this->disabled[] = 'extract'; } if (!$this->metaCache) { return $this->setError('Cache dirctory (metaCachePath or tmp) is require.'); } $this->metaCacheFile = $this->metaCache . DIRECTORY_SEPARATOR . '.elFinder_dropbox_metaCache_' . md5($this->dropboxUid . $this->options['consumerSecret']); $this->metaCacheGet(!empty($_REQUEST['init'])); return true; }
/** * Prepare FTP connection * Connect to remote server and check if credentials are correct, if so, store the connection id in $ftp_conn * * @return bool * @author Dmitry (dio) Levashov * @author Cem (DiscoFever) **/ protected function init() { if (!$this->options['consumerKey'] || !$this->options['consumerSecret'] || !$this->options['accessToken'] || !$this->options['accessTokenSecret']) { return $this->setError('Required options undefined.'); } if (empty($this->options['metaCachePath']) && defined('ELFINDER_DROPBOX_META_CACHE_PATH')) { $this->options['metaCachePath'] = ELFINDER_DROPBOX_META_CACHE_PATH; } // make net mount key $this->netMountKey = md5(join('-', array('dropbox', $this->options['path']))); if (!$this->oauth) { if (class_exists('OAuth')) { $this->oauth = new Dropbox_OAuth_PHP($this->options['consumerKey'], $this->options['consumerSecret']); } else { if (!class_exists('HTTP_OAuth_Consumer')) { // We're going to try to load in manually include 'HTTP/OAuth/Consumer.php'; } if (class_exists('HTTP_OAuth_Consumer')) { $this->oauth = new Dropbox_OAuth_PEAR($this->options['consumerKey'], $this->options['consumerSecret']); } } } if (!$this->oauth) { return $this->setError('OAuth extension not loaded.'); } // normalize root path $this->root = $this->options['path'] = $this->_normpath($this->options['path']); if (empty($this->options['alias'])) { $this->options['alias'] = $this->options['path'] === '/' ? 'Dropbox.com' : 'Dropbox' . $this->options['path']; } $this->rootName = $this->options['alias']; $this->options['separator'] = '/'; try { $this->oauth->setToken($this->options['accessToken'], $this->options['accessTokenSecret']); $this->dropbox = new Dropbox_API($this->oauth, $this->options['root']); } catch (Dropbox_Exception $e) { unset($_SESSION['elFinderDropboxTokens']); return $this->setError('Dropbox error: ' . $e->getMessage()); } // user if (empty($this->options['dropboxUid'])) { try { $res = $this->dropbox->getAccountInfo(); $this->options['dropboxUid'] = $res['uid']; } catch (Dropbox_Exception $e) { unset($_SESSION['elFinderDropboxTokens']); return $this->setError('Dropbox error: ' . $e->getMessage()); } } $this->dropboxUid = $this->options['dropboxUid']; $this->tmbPrefix = 'dropbox' . base_convert($this->dropboxUid, 10, 32); if (!empty($this->options['tmpPath'])) { if ((is_dir($this->options['tmpPath']) || @mkdir($this->options['tmpPath'])) && is_writable($this->options['tmpPath'])) { $this->tmp = $this->options['tmpPath']; } } if (!$this->tmp && is_writable($this->options['tmbPath'])) { $this->tmp = $this->options['tmbPath']; } if (!empty($this->options['metaCachePath'])) { if ((is_dir($this->options['metaCachePath']) || @mkdir($this->options['metaCachePath'])) && is_writable($this->options['metaCachePath'])) { $this->metaCache = $this->options['metaCachePath']; } } if (!$this->metaCache && $this->tmp) { $this->metaCache = $this->tmp; } if (!$this->tmp) { $this->disabled[] = 'archive'; $this->disabled[] = 'extract'; } if (!$this->metaCache) { return $this->setError('Cache dirctory (metaCachePath or tmp) is require.'); } // setup PDO if (!$this->options['PDO_DSN']) { $this->options['PDO_DSN'] = 'sqlite:' . $this->metaCache . DIRECTORY_SEPARATOR . '.elFinder_dropbox_db_' . md5($this->dropboxUid . $this->options['consumerSecret']); } // DataBase table name $this->DB_TableName = $this->options['PDO_DBName']; // DataBase check or make table if ($this->DB = new PDO($this->options['PDO_DSN'], $this->options['PDO_User'], $this->options['PDO_Pass'], $this->options['PDO_Options'])) { if (!$this->checkDB()) { return $this->setError('Can not make DB table'); } } else { return $this->setError('Could not use PDO'); } $res = $this->deltaCheck(!empty($_REQUEST['init'])); if ($res !== true) { if (is_string($res)) { return $this->setError($res); } else { return $this->setError('Could not check API "delta"'); } } return true; }