From cb3006e4f4f2f335e4c5cb01effaf77124e2b65f Mon Sep 17 00:00:00 2001 From: nao-pon Date: Sat, 4 Jan 2020 11:19:48 +0900 Subject: [PATCH] [VD:Box,OneDrive] prevent duplicate creation of thumbnails of permanent mounts --- php/elFinderVolumeBox.class.php | 34 +++++++++++++++++++++------- php/elFinderVolumeOneDrive.class.php | 34 +++++++++++++++++++++------- 2 files changed, 52 insertions(+), 16 deletions(-) diff --git a/php/elFinderVolumeBox.class.php b/php/elFinderVolumeBox.class.php index 497352071..8a104436e 100644 --- a/php/elFinderVolumeBox.class.php +++ b/php/elFinderVolumeBox.class.php @@ -230,7 +230,7 @@ class elFinderVolumeBox extends elFinderVolumeDriver throw new \Exception(elFinder::ERROR_REAUTH_REQUIRE); } else { $refresh_token = $this->token->data->refresh_token; - $initialToken = empty($this->token->initialToken)? md5($this->options['client_id'] . $refresh_token) : $this->token->initialToken; + $initialToken = $this->_bd_getInitialToken(); } $url = self::TOKEN_URL; @@ -601,12 +601,22 @@ class elFinderVolumeBox extends elFinderVolumeDriver $this->tmp = $tmp; } if ($tmp) { - $aTokenFile = $tmp . DIRECTORY_SEPARATOR . (empty($this->token->initialToken)? md5($this->options['client_id'] . $this->token->data->refresh_token) : $this->token->initialToken) . '.btoken'; + $aTokenFile = $tmp . DIRECTORY_SEPARATOR . $this->_bd_getInitialToken() . '.btoken'; } } return $aTokenFile; } + /** + * Get Initial Token (MD5 hash) + * + * @return string + */ + protected function _bd_getInitialToken() + { + return (empty($this->token->initialToken)? md5($this->options['client_id'] . (!empty($this->token->data->refresh_token)? $this->token->data->refresh_token : $this->token->data->access_token)) : $this->token->initialToken); + } + /*********************************************************************/ /* OVERRIDE FUNCTIONS */ /*********************************************************************/ @@ -850,6 +860,7 @@ class elFinderVolumeBox extends elFinderVolumeDriver } } + $error = false; try { $this->token = json_decode($this->options['accessToken']); if ($this->aTokenFile = $this->_bd_getATokenFile()) { @@ -870,18 +881,27 @@ class elFinderVolumeBox extends elFinderVolumeDriver $this->_bd_refreshToken(); } catch (Exception $e) { $this->token = null; - - return $this->setError($e->getMessage()); + $error = true; + $this->setError($e->getMessage()); } if (empty($this->options['netkey'])) { // make net mount key - $_tokenKey = isset($this->token->data->refresh_token) ? $this->token->data->refresh_token : $this->token->data->access_token; - $this->netMountKey = md5(implode('-', array('box', $this->options['path'], $_tokenKey))); + $this->netMountKey = $this->_bd_getInitialToken(); } else { $this->netMountKey = $this->options['netkey']; } + $this->tmbPrefix = 'box' . base_convert($this->netMountKey, 10, 32); + + if ($error) { + if (empty($this->options['netkey'])) { + // for delete thumbnail + $this->netunmount(); + } + return false; + } + // normalize root path if ($this->options['path'] == 'root') { $this->options['path'] = '/'; @@ -899,8 +919,6 @@ class elFinderVolumeBox extends elFinderVolumeDriver $this->rootName = $this->options['alias']; - $this->tmbPrefix = 'box' . base_convert($this->netMountKey, 10, 32); - // This driver dose not support `syncChkAsTs` $this->options['syncChkAsTs'] = false; diff --git a/php/elFinderVolumeOneDrive.class.php b/php/elFinderVolumeOneDrive.class.php index cf7f54dd7..b74ae5446 100644 --- a/php/elFinderVolumeOneDrive.class.php +++ b/php/elFinderVolumeOneDrive.class.php @@ -221,7 +221,7 @@ class elFinderVolumeOneDrive extends elFinderVolumeDriver throw new \Exception(elFinder::ERROR_REAUTH_REQUIRE); } else { $refresh_token = $this->token->data->refresh_token; - $initialToken = empty($this->token->initialToken)? md5($this->options['client_id'] . $refresh_token) : $this->token->initialToken; + $initialToken = $this->_od_getInitialToken(); } $url = self::TOKEN_URL; @@ -690,12 +690,22 @@ class elFinderVolumeOneDrive extends elFinderVolumeDriver $this->tmp = $tmp; } if ($tmp) { - $aTokenFile = $tmp . DIRECTORY_SEPARATOR . (empty($this->token->initialToken)? md5($this->options['client_id'] . $this->token->data->refresh_token) : $this->token->initialToken) . '.otoken'; + $aTokenFile = $tmp . DIRECTORY_SEPARATOR . $this->_od_getInitialToken() . '.otoken'; } } return $aTokenFile; } + /** + * Get Initial Token (MD5 hash) + * + * @return string + */ + protected function _od_getInitialToken() + { + return (empty($this->token->initialToken)? md5($this->options['client_id'] . (!empty($this->token->data->refresh_token)? $this->token->data->refresh_token : $this->token->data->access_token)) : $this->token->initialToken); + } + /*********************************************************************/ /* OVERRIDE FUNCTIONS */ /*********************************************************************/ @@ -950,6 +960,7 @@ class elFinderVolumeOneDrive extends elFinderVolumeDriver } } + $error = false; try { $this->token = json_decode($this->options['accessToken']); if ($this->aTokenFile = $this->_od_getATokenFile()) { @@ -970,20 +981,29 @@ class elFinderVolumeOneDrive extends elFinderVolumeDriver $this->_od_refreshToken(); } catch (Exception $e) { $this->token = null; - - return $this->setError($e->getMessage()); + $error = true; + $this->setError($e->getMessage()); } $this->expires = empty($this->token->data->refresh_token) ? (int)$this->token->expires : 0; if (empty($this->options['netkey'])) { // make net mount key - $_tokenKey = isset($this->token->data->refresh_token) ? $this->token->data->refresh_token : $this->token->data->access_token; - $this->netMountKey = md5(implode('-', array('box', $this->options['path'], $_tokenKey))); + $this->netMountKey = $this->_od_getInitialToken(); } else { $this->netMountKey = $this->options['netkey']; } + $this->tmbPrefix = 'onedrive' . base_convert($this->netMountKey, 10, 32); + + if ($error) { + if (empty($this->options['netkey'])) { + // for delete thumbnail + $this->netunmount(); + } + return false; + } + // normalize root path if ($this->options['path'] == 'root') { $this->options['path'] = '/'; @@ -1000,8 +1020,6 @@ class elFinderVolumeOneDrive extends elFinderVolumeDriver $this->rootName = $this->options['alias']; - $this->tmbPrefix = 'onedrive' . base_convert($this->netMountKey, 10, 32); - // This driver dose not support `syncChkAsTs` $this->options['syncChkAsTs'] = false;