@@ -34,93 +34,93 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | class CredentialsManager implements ICredentialsManager { |
| 36 | 36 | |
| 37 | - const DB_TABLE = 'credentials'; |
|
| 37 | + const DB_TABLE = 'credentials'; |
|
| 38 | 38 | |
| 39 | - /** @var ICrypto */ |
|
| 40 | - protected $crypto; |
|
| 39 | + /** @var ICrypto */ |
|
| 40 | + protected $crypto; |
|
| 41 | 41 | |
| 42 | - /** @var IDBConnection */ |
|
| 43 | - protected $dbConnection; |
|
| 42 | + /** @var IDBConnection */ |
|
| 43 | + protected $dbConnection; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @param ICrypto $crypto |
|
| 47 | - * @param IDBConnection $dbConnection |
|
| 48 | - */ |
|
| 49 | - public function __construct(ICrypto $crypto, IDBConnection $dbConnection) { |
|
| 50 | - $this->crypto = $crypto; |
|
| 51 | - $this->dbConnection = $dbConnection; |
|
| 52 | - } |
|
| 45 | + /** |
|
| 46 | + * @param ICrypto $crypto |
|
| 47 | + * @param IDBConnection $dbConnection |
|
| 48 | + */ |
|
| 49 | + public function __construct(ICrypto $crypto, IDBConnection $dbConnection) { |
|
| 50 | + $this->crypto = $crypto; |
|
| 51 | + $this->dbConnection = $dbConnection; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Store a set of credentials |
|
| 56 | - * |
|
| 57 | - * @param string|null $userId Null for system-wide credentials |
|
| 58 | - * @param string $identifier |
|
| 59 | - * @param mixed $credentials |
|
| 60 | - */ |
|
| 61 | - public function store($userId, $identifier, $credentials) { |
|
| 62 | - $value = $this->crypto->encrypt(json_encode($credentials)); |
|
| 54 | + /** |
|
| 55 | + * Store a set of credentials |
|
| 56 | + * |
|
| 57 | + * @param string|null $userId Null for system-wide credentials |
|
| 58 | + * @param string $identifier |
|
| 59 | + * @param mixed $credentials |
|
| 60 | + */ |
|
| 61 | + public function store($userId, $identifier, $credentials) { |
|
| 62 | + $value = $this->crypto->encrypt(json_encode($credentials)); |
|
| 63 | 63 | |
| 64 | - $this->dbConnection->setValues(self::DB_TABLE, [ |
|
| 65 | - 'user' => $userId, |
|
| 66 | - 'identifier' => $identifier, |
|
| 67 | - ], [ |
|
| 68 | - 'credentials' => $value, |
|
| 69 | - ]); |
|
| 70 | - } |
|
| 64 | + $this->dbConnection->setValues(self::DB_TABLE, [ |
|
| 65 | + 'user' => $userId, |
|
| 66 | + 'identifier' => $identifier, |
|
| 67 | + ], [ |
|
| 68 | + 'credentials' => $value, |
|
| 69 | + ]); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Retrieve a set of credentials |
|
| 74 | - * |
|
| 75 | - * @param string|null $userId Null for system-wide credentials |
|
| 76 | - * @param string $identifier |
|
| 77 | - * @return mixed |
|
| 78 | - */ |
|
| 79 | - public function retrieve($userId, $identifier) { |
|
| 80 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 81 | - $qb->select('credentials') |
|
| 82 | - ->from(self::DB_TABLE) |
|
| 83 | - ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
| 84 | - ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier))) |
|
| 85 | - ; |
|
| 86 | - $result = $qb->execute()->fetch(); |
|
| 72 | + /** |
|
| 73 | + * Retrieve a set of credentials |
|
| 74 | + * |
|
| 75 | + * @param string|null $userId Null for system-wide credentials |
|
| 76 | + * @param string $identifier |
|
| 77 | + * @return mixed |
|
| 78 | + */ |
|
| 79 | + public function retrieve($userId, $identifier) { |
|
| 80 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 81 | + $qb->select('credentials') |
|
| 82 | + ->from(self::DB_TABLE) |
|
| 83 | + ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
| 84 | + ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier))) |
|
| 85 | + ; |
|
| 86 | + $result = $qb->execute()->fetch(); |
|
| 87 | 87 | |
| 88 | - if (!$result) { |
|
| 89 | - return null; |
|
| 90 | - } |
|
| 91 | - $value = $result['credentials']; |
|
| 88 | + if (!$result) { |
|
| 89 | + return null; |
|
| 90 | + } |
|
| 91 | + $value = $result['credentials']; |
|
| 92 | 92 | |
| 93 | - return json_decode($this->crypto->decrypt($value), true); |
|
| 94 | - } |
|
| 93 | + return json_decode($this->crypto->decrypt($value), true); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Delete a set of credentials |
|
| 98 | - * |
|
| 99 | - * @param string|null $userId Null for system-wide credentials |
|
| 100 | - * @param string $identifier |
|
| 101 | - * @return int rows removed |
|
| 102 | - */ |
|
| 103 | - public function delete($userId, $identifier) { |
|
| 104 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 105 | - $qb->delete(self::DB_TABLE) |
|
| 106 | - ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
| 107 | - ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier))) |
|
| 108 | - ; |
|
| 109 | - return $qb->execute(); |
|
| 110 | - } |
|
| 96 | + /** |
|
| 97 | + * Delete a set of credentials |
|
| 98 | + * |
|
| 99 | + * @param string|null $userId Null for system-wide credentials |
|
| 100 | + * @param string $identifier |
|
| 101 | + * @return int rows removed |
|
| 102 | + */ |
|
| 103 | + public function delete($userId, $identifier) { |
|
| 104 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 105 | + $qb->delete(self::DB_TABLE) |
|
| 106 | + ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
| 107 | + ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier))) |
|
| 108 | + ; |
|
| 109 | + return $qb->execute(); |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * Erase all credentials stored for a user |
|
| 114 | - * |
|
| 115 | - * @param string $userId |
|
| 116 | - * @return int rows removed |
|
| 117 | - */ |
|
| 118 | - public function erase($userId) { |
|
| 119 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
| 120 | - $qb->delete(self::DB_TABLE) |
|
| 121 | - ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
| 122 | - ; |
|
| 123 | - return $qb->execute(); |
|
| 124 | - } |
|
| 112 | + /** |
|
| 113 | + * Erase all credentials stored for a user |
|
| 114 | + * |
|
| 115 | + * @param string $userId |
|
| 116 | + * @return int rows removed |
|
| 117 | + */ |
|
| 118 | + public function erase($userId) { |
|
| 119 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
| 120 | + $qb->delete(self::DB_TABLE) |
|
| 121 | + ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
| 122 | + ; |
|
| 123 | + return $qb->execute(); |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | 126 | } |
@@ -27,104 +27,104 @@ |
||
| 27 | 27 | use OCP\ICertificate; |
| 28 | 28 | |
| 29 | 29 | class Certificate implements ICertificate { |
| 30 | - protected $name; |
|
| 31 | - |
|
| 32 | - protected $commonName; |
|
| 33 | - |
|
| 34 | - protected $organization; |
|
| 35 | - |
|
| 36 | - protected $serial; |
|
| 37 | - |
|
| 38 | - protected $issueDate; |
|
| 39 | - |
|
| 40 | - protected $expireDate; |
|
| 41 | - |
|
| 42 | - protected $issuerName; |
|
| 43 | - |
|
| 44 | - protected $issuerOrganization; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @param string $data base64 encoded certificate |
|
| 48 | - * @param string $name |
|
| 49 | - * @throws \Exception If the certificate could not get parsed |
|
| 50 | - */ |
|
| 51 | - public function __construct($data, $name) { |
|
| 52 | - $this->name = $name; |
|
| 53 | - $gmt = new \DateTimeZone('GMT'); |
|
| 54 | - |
|
| 55 | - // If string starts with "file://" ignore the certificate |
|
| 56 | - $query = 'file://'; |
|
| 57 | - if(strtolower(substr($data, 0, strlen($query))) === $query) { |
|
| 58 | - throw new \Exception('Certificate could not get parsed.'); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - $info = openssl_x509_parse($data); |
|
| 62 | - if(!is_array($info)) { |
|
| 63 | - throw new \Exception('Certificate could not get parsed.'); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - $this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null; |
|
| 67 | - $this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null; |
|
| 68 | - $this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt); |
|
| 69 | - $this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt); |
|
| 70 | - $this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null; |
|
| 71 | - $this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @return string |
|
| 76 | - */ |
|
| 77 | - public function getName() { |
|
| 78 | - return $this->name; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @return string|null |
|
| 83 | - */ |
|
| 84 | - public function getCommonName() { |
|
| 85 | - return $this->commonName; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @return string |
|
| 90 | - */ |
|
| 91 | - public function getOrganization() { |
|
| 92 | - return $this->organization; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * @return \DateTime |
|
| 97 | - */ |
|
| 98 | - public function getIssueDate() { |
|
| 99 | - return $this->issueDate; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @return \DateTime |
|
| 104 | - */ |
|
| 105 | - public function getExpireDate() { |
|
| 106 | - return $this->expireDate; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @return bool |
|
| 111 | - */ |
|
| 112 | - public function isExpired() { |
|
| 113 | - $now = new \DateTime(); |
|
| 114 | - return $this->issueDate > $now or $now > $this->expireDate; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @return string|null |
|
| 119 | - */ |
|
| 120 | - public function getIssuerName() { |
|
| 121 | - return $this->issuerName; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * @return string|null |
|
| 126 | - */ |
|
| 127 | - public function getIssuerOrganization() { |
|
| 128 | - return $this->issuerOrganization; |
|
| 129 | - } |
|
| 30 | + protected $name; |
|
| 31 | + |
|
| 32 | + protected $commonName; |
|
| 33 | + |
|
| 34 | + protected $organization; |
|
| 35 | + |
|
| 36 | + protected $serial; |
|
| 37 | + |
|
| 38 | + protected $issueDate; |
|
| 39 | + |
|
| 40 | + protected $expireDate; |
|
| 41 | + |
|
| 42 | + protected $issuerName; |
|
| 43 | + |
|
| 44 | + protected $issuerOrganization; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @param string $data base64 encoded certificate |
|
| 48 | + * @param string $name |
|
| 49 | + * @throws \Exception If the certificate could not get parsed |
|
| 50 | + */ |
|
| 51 | + public function __construct($data, $name) { |
|
| 52 | + $this->name = $name; |
|
| 53 | + $gmt = new \DateTimeZone('GMT'); |
|
| 54 | + |
|
| 55 | + // If string starts with "file://" ignore the certificate |
|
| 56 | + $query = 'file://'; |
|
| 57 | + if(strtolower(substr($data, 0, strlen($query))) === $query) { |
|
| 58 | + throw new \Exception('Certificate could not get parsed.'); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + $info = openssl_x509_parse($data); |
|
| 62 | + if(!is_array($info)) { |
|
| 63 | + throw new \Exception('Certificate could not get parsed.'); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + $this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null; |
|
| 67 | + $this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null; |
|
| 68 | + $this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt); |
|
| 69 | + $this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt); |
|
| 70 | + $this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null; |
|
| 71 | + $this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @return string |
|
| 76 | + */ |
|
| 77 | + public function getName() { |
|
| 78 | + return $this->name; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @return string|null |
|
| 83 | + */ |
|
| 84 | + public function getCommonName() { |
|
| 85 | + return $this->commonName; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @return string |
|
| 90 | + */ |
|
| 91 | + public function getOrganization() { |
|
| 92 | + return $this->organization; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @return \DateTime |
|
| 97 | + */ |
|
| 98 | + public function getIssueDate() { |
|
| 99 | + return $this->issueDate; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @return \DateTime |
|
| 104 | + */ |
|
| 105 | + public function getExpireDate() { |
|
| 106 | + return $this->expireDate; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @return bool |
|
| 111 | + */ |
|
| 112 | + public function isExpired() { |
|
| 113 | + $now = new \DateTime(); |
|
| 114 | + return $this->issueDate > $now or $now > $this->expireDate; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @return string|null |
|
| 119 | + */ |
|
| 120 | + public function getIssuerName() { |
|
| 121 | + return $this->issuerName; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * @return string|null |
|
| 126 | + */ |
|
| 127 | + public function getIssuerOrganization() { |
|
| 128 | + return $this->issuerOrganization; |
|
| 129 | + } |
|
| 130 | 130 | } |
@@ -54,19 +54,19 @@ |
||
| 54 | 54 | |
| 55 | 55 | // If string starts with "file://" ignore the certificate |
| 56 | 56 | $query = 'file://'; |
| 57 | - if(strtolower(substr($data, 0, strlen($query))) === $query) { |
|
| 57 | + if (strtolower(substr($data, 0, strlen($query))) === $query) { |
|
| 58 | 58 | throw new \Exception('Certificate could not get parsed.'); |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | $info = openssl_x509_parse($data); |
| 62 | - if(!is_array($info)) { |
|
| 62 | + if (!is_array($info)) { |
|
| 63 | 63 | throw new \Exception('Certificate could not get parsed.'); |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | $this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null; |
| 67 | 67 | $this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null; |
| 68 | - $this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt); |
|
| 69 | - $this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt); |
|
| 68 | + $this->issueDate = new \DateTime('@'.$info['validFrom_time_t'], $gmt); |
|
| 69 | + $this->expireDate = new \DateTime('@'.$info['validTo_time_t'], $gmt); |
|
| 70 | 70 | $this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null; |
| 71 | 71 | $this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null; |
| 72 | 72 | } |
@@ -65,13 +65,13 @@ discard block |
||
| 65 | 65 | * @return string |
| 66 | 66 | */ |
| 67 | 67 | private function buildFileNameWithSuffix($absolutePath, $postFix = '') { |
| 68 | - if($postFix !== '') { |
|
| 69 | - $postFix = '.' . ltrim($postFix, '.'); |
|
| 68 | + if ($postFix !== '') { |
|
| 69 | + $postFix = '.'.ltrim($postFix, '.'); |
|
| 70 | 70 | $postFix = str_replace(['\\', '/'], '', $postFix); |
| 71 | 71 | $absolutePath .= '-'; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - return $absolutePath . $postFix; |
|
| 74 | + return $absolutePath.$postFix; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | // If a postfix got specified sanitize it and create a postfixed |
| 93 | 93 | // temporary file |
| 94 | - if($postFix !== '') { |
|
| 94 | + if ($postFix !== '') { |
|
| 95 | 95 | $fileNameWithPostfix = $this->buildFileNameWithSuffix($file, $postFix); |
| 96 | 96 | touch($fileNameWithPostfix); |
| 97 | 97 | chmod($fileNameWithPostfix, 0600); |
@@ -127,11 +127,11 @@ discard block |
||
| 127 | 127 | $this->current[] = $uniqueFileName; |
| 128 | 128 | |
| 129 | 129 | // Build a name without postfix |
| 130 | - $path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix); |
|
| 130 | + $path = $this->buildFileNameWithSuffix($uniqueFileName.'-folder', $postFix); |
|
| 131 | 131 | mkdir($path, 0700); |
| 132 | 132 | $this->current[] = $path; |
| 133 | 133 | |
| 134 | - return $path . '/'; |
|
| 134 | + return $path.'/'; |
|
| 135 | 135 | } else { |
| 136 | 136 | $this->log->warning( |
| 137 | 137 | 'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions', |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | if ($dh) { |
| 191 | 191 | while (($file = readdir($dh)) !== false) { |
| 192 | 192 | if (substr($file, 0, 7) === self::TMP_PREFIX) { |
| 193 | - $path = $this->tmpBaseDir . '/' . $file; |
|
| 193 | + $path = $this->tmpBaseDir.'/'.$file; |
|
| 194 | 194 | $mtime = filemtime($path); |
| 195 | 195 | if ($mtime < $cutOfTime) { |
| 196 | 196 | $files[] = $path; |
@@ -34,246 +34,246 @@ |
||
| 34 | 34 | use OCP\ITempManager; |
| 35 | 35 | |
| 36 | 36 | class TempManager implements ITempManager { |
| 37 | - /** @var string[] Current temporary files and folders, used for cleanup */ |
|
| 38 | - protected $current = []; |
|
| 39 | - /** @var string i.e. /tmp on linux systems */ |
|
| 40 | - protected $tmpBaseDir; |
|
| 41 | - /** @var ILogger */ |
|
| 42 | - protected $log; |
|
| 43 | - /** @var IConfig */ |
|
| 44 | - protected $config; |
|
| 37 | + /** @var string[] Current temporary files and folders, used for cleanup */ |
|
| 38 | + protected $current = []; |
|
| 39 | + /** @var string i.e. /tmp on linux systems */ |
|
| 40 | + protected $tmpBaseDir; |
|
| 41 | + /** @var ILogger */ |
|
| 42 | + protected $log; |
|
| 43 | + /** @var IConfig */ |
|
| 44 | + protected $config; |
|
| 45 | 45 | |
| 46 | - /** Prefix */ |
|
| 47 | - const TMP_PREFIX = 'oc_tmp_'; |
|
| 46 | + /** Prefix */ |
|
| 47 | + const TMP_PREFIX = 'oc_tmp_'; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @param \OCP\ILogger $logger |
|
| 51 | - * @param \OCP\IConfig $config |
|
| 52 | - */ |
|
| 53 | - public function __construct(ILogger $logger, IConfig $config) { |
|
| 54 | - $this->log = $logger; |
|
| 55 | - $this->config = $config; |
|
| 56 | - $this->tmpBaseDir = $this->getTempBaseDir(); |
|
| 57 | - } |
|
| 49 | + /** |
|
| 50 | + * @param \OCP\ILogger $logger |
|
| 51 | + * @param \OCP\IConfig $config |
|
| 52 | + */ |
|
| 53 | + public function __construct(ILogger $logger, IConfig $config) { |
|
| 54 | + $this->log = $logger; |
|
| 55 | + $this->config = $config; |
|
| 56 | + $this->tmpBaseDir = $this->getTempBaseDir(); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Builds the filename with suffix and removes potential dangerous characters |
|
| 61 | - * such as directory separators. |
|
| 62 | - * |
|
| 63 | - * @param string $absolutePath Absolute path to the file / folder |
|
| 64 | - * @param string $postFix Postfix appended to the temporary file name, may be user controlled |
|
| 65 | - * @return string |
|
| 66 | - */ |
|
| 67 | - private function buildFileNameWithSuffix($absolutePath, $postFix = '') { |
|
| 68 | - if($postFix !== '') { |
|
| 69 | - $postFix = '.' . ltrim($postFix, '.'); |
|
| 70 | - $postFix = str_replace(['\\', '/'], '', $postFix); |
|
| 71 | - $absolutePath .= '-'; |
|
| 72 | - } |
|
| 59 | + /** |
|
| 60 | + * Builds the filename with suffix and removes potential dangerous characters |
|
| 61 | + * such as directory separators. |
|
| 62 | + * |
|
| 63 | + * @param string $absolutePath Absolute path to the file / folder |
|
| 64 | + * @param string $postFix Postfix appended to the temporary file name, may be user controlled |
|
| 65 | + * @return string |
|
| 66 | + */ |
|
| 67 | + private function buildFileNameWithSuffix($absolutePath, $postFix = '') { |
|
| 68 | + if($postFix !== '') { |
|
| 69 | + $postFix = '.' . ltrim($postFix, '.'); |
|
| 70 | + $postFix = str_replace(['\\', '/'], '', $postFix); |
|
| 71 | + $absolutePath .= '-'; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - return $absolutePath . $postFix; |
|
| 75 | - } |
|
| 74 | + return $absolutePath . $postFix; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Create a temporary file and return the path |
|
| 79 | - * |
|
| 80 | - * @param string $postFix Postfix appended to the temporary file name |
|
| 81 | - * @return string |
|
| 82 | - */ |
|
| 83 | - public function getTemporaryFile($postFix = '') { |
|
| 84 | - if (is_writable($this->tmpBaseDir)) { |
|
| 85 | - // To create an unique file and prevent the risk of race conditions |
|
| 86 | - // or duplicated temporary files by other means such as collisions |
|
| 87 | - // we need to create the file using `tempnam` and append a possible |
|
| 88 | - // postfix to it later |
|
| 89 | - $file = tempnam($this->tmpBaseDir, self::TMP_PREFIX); |
|
| 90 | - $this->current[] = $file; |
|
| 77 | + /** |
|
| 78 | + * Create a temporary file and return the path |
|
| 79 | + * |
|
| 80 | + * @param string $postFix Postfix appended to the temporary file name |
|
| 81 | + * @return string |
|
| 82 | + */ |
|
| 83 | + public function getTemporaryFile($postFix = '') { |
|
| 84 | + if (is_writable($this->tmpBaseDir)) { |
|
| 85 | + // To create an unique file and prevent the risk of race conditions |
|
| 86 | + // or duplicated temporary files by other means such as collisions |
|
| 87 | + // we need to create the file using `tempnam` and append a possible |
|
| 88 | + // postfix to it later |
|
| 89 | + $file = tempnam($this->tmpBaseDir, self::TMP_PREFIX); |
|
| 90 | + $this->current[] = $file; |
|
| 91 | 91 | |
| 92 | - // If a postfix got specified sanitize it and create a postfixed |
|
| 93 | - // temporary file |
|
| 94 | - if($postFix !== '') { |
|
| 95 | - $fileNameWithPostfix = $this->buildFileNameWithSuffix($file, $postFix); |
|
| 96 | - touch($fileNameWithPostfix); |
|
| 97 | - chmod($fileNameWithPostfix, 0600); |
|
| 98 | - $this->current[] = $fileNameWithPostfix; |
|
| 99 | - return $fileNameWithPostfix; |
|
| 100 | - } |
|
| 92 | + // If a postfix got specified sanitize it and create a postfixed |
|
| 93 | + // temporary file |
|
| 94 | + if($postFix !== '') { |
|
| 95 | + $fileNameWithPostfix = $this->buildFileNameWithSuffix($file, $postFix); |
|
| 96 | + touch($fileNameWithPostfix); |
|
| 97 | + chmod($fileNameWithPostfix, 0600); |
|
| 98 | + $this->current[] = $fileNameWithPostfix; |
|
| 99 | + return $fileNameWithPostfix; |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - return $file; |
|
| 103 | - } else { |
|
| 104 | - $this->log->warning( |
|
| 105 | - 'Can not create a temporary file in directory {dir}. Check it exists and has correct permissions', |
|
| 106 | - [ |
|
| 107 | - 'dir' => $this->tmpBaseDir, |
|
| 108 | - ] |
|
| 109 | - ); |
|
| 110 | - return false; |
|
| 111 | - } |
|
| 112 | - } |
|
| 102 | + return $file; |
|
| 103 | + } else { |
|
| 104 | + $this->log->warning( |
|
| 105 | + 'Can not create a temporary file in directory {dir}. Check it exists and has correct permissions', |
|
| 106 | + [ |
|
| 107 | + 'dir' => $this->tmpBaseDir, |
|
| 108 | + ] |
|
| 109 | + ); |
|
| 110 | + return false; |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * Create a temporary folder and return the path |
|
| 116 | - * |
|
| 117 | - * @param string $postFix Postfix appended to the temporary folder name |
|
| 118 | - * @return string |
|
| 119 | - */ |
|
| 120 | - public function getTemporaryFolder($postFix = '') { |
|
| 121 | - if (is_writable($this->tmpBaseDir)) { |
|
| 122 | - // To create an unique directory and prevent the risk of race conditions |
|
| 123 | - // or duplicated temporary files by other means such as collisions |
|
| 124 | - // we need to create the file using `tempnam` and append a possible |
|
| 125 | - // postfix to it later |
|
| 126 | - $uniqueFileName = tempnam($this->tmpBaseDir, self::TMP_PREFIX); |
|
| 127 | - $this->current[] = $uniqueFileName; |
|
| 114 | + /** |
|
| 115 | + * Create a temporary folder and return the path |
|
| 116 | + * |
|
| 117 | + * @param string $postFix Postfix appended to the temporary folder name |
|
| 118 | + * @return string |
|
| 119 | + */ |
|
| 120 | + public function getTemporaryFolder($postFix = '') { |
|
| 121 | + if (is_writable($this->tmpBaseDir)) { |
|
| 122 | + // To create an unique directory and prevent the risk of race conditions |
|
| 123 | + // or duplicated temporary files by other means such as collisions |
|
| 124 | + // we need to create the file using `tempnam` and append a possible |
|
| 125 | + // postfix to it later |
|
| 126 | + $uniqueFileName = tempnam($this->tmpBaseDir, self::TMP_PREFIX); |
|
| 127 | + $this->current[] = $uniqueFileName; |
|
| 128 | 128 | |
| 129 | - // Build a name without postfix |
|
| 130 | - $path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix); |
|
| 131 | - mkdir($path, 0700); |
|
| 132 | - $this->current[] = $path; |
|
| 129 | + // Build a name without postfix |
|
| 130 | + $path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix); |
|
| 131 | + mkdir($path, 0700); |
|
| 132 | + $this->current[] = $path; |
|
| 133 | 133 | |
| 134 | - return $path . '/'; |
|
| 135 | - } else { |
|
| 136 | - $this->log->warning( |
|
| 137 | - 'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions', |
|
| 138 | - [ |
|
| 139 | - 'dir' => $this->tmpBaseDir, |
|
| 140 | - ] |
|
| 141 | - ); |
|
| 142 | - return false; |
|
| 143 | - } |
|
| 144 | - } |
|
| 134 | + return $path . '/'; |
|
| 135 | + } else { |
|
| 136 | + $this->log->warning( |
|
| 137 | + 'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions', |
|
| 138 | + [ |
|
| 139 | + 'dir' => $this->tmpBaseDir, |
|
| 140 | + ] |
|
| 141 | + ); |
|
| 142 | + return false; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - /** |
|
| 147 | - * Remove the temporary files and folders generated during this request |
|
| 148 | - */ |
|
| 149 | - public function clean() { |
|
| 150 | - $this->cleanFiles($this->current); |
|
| 151 | - } |
|
| 146 | + /** |
|
| 147 | + * Remove the temporary files and folders generated during this request |
|
| 148 | + */ |
|
| 149 | + public function clean() { |
|
| 150 | + $this->cleanFiles($this->current); |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - /** |
|
| 154 | - * @param string[] $files |
|
| 155 | - */ |
|
| 156 | - protected function cleanFiles($files) { |
|
| 157 | - foreach ($files as $file) { |
|
| 158 | - if (file_exists($file)) { |
|
| 159 | - try { |
|
| 160 | - \OC_Helper::rmdirr($file); |
|
| 161 | - } catch (\UnexpectedValueException $ex) { |
|
| 162 | - $this->log->warning( |
|
| 163 | - "Error deleting temporary file/folder: {file} - Reason: {error}", |
|
| 164 | - [ |
|
| 165 | - 'file' => $file, |
|
| 166 | - 'error' => $ex->getMessage(), |
|
| 167 | - ] |
|
| 168 | - ); |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - } |
|
| 172 | - } |
|
| 153 | + /** |
|
| 154 | + * @param string[] $files |
|
| 155 | + */ |
|
| 156 | + protected function cleanFiles($files) { |
|
| 157 | + foreach ($files as $file) { |
|
| 158 | + if (file_exists($file)) { |
|
| 159 | + try { |
|
| 160 | + \OC_Helper::rmdirr($file); |
|
| 161 | + } catch (\UnexpectedValueException $ex) { |
|
| 162 | + $this->log->warning( |
|
| 163 | + "Error deleting temporary file/folder: {file} - Reason: {error}", |
|
| 164 | + [ |
|
| 165 | + 'file' => $file, |
|
| 166 | + 'error' => $ex->getMessage(), |
|
| 167 | + ] |
|
| 168 | + ); |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | - /** |
|
| 175 | - * Remove old temporary files and folders that were failed to be cleaned |
|
| 176 | - */ |
|
| 177 | - public function cleanOld() { |
|
| 178 | - $this->cleanFiles($this->getOldFiles()); |
|
| 179 | - } |
|
| 174 | + /** |
|
| 175 | + * Remove old temporary files and folders that were failed to be cleaned |
|
| 176 | + */ |
|
| 177 | + public function cleanOld() { |
|
| 178 | + $this->cleanFiles($this->getOldFiles()); |
|
| 179 | + } |
|
| 180 | 180 | |
| 181 | - /** |
|
| 182 | - * Get all temporary files and folders generated by oc older than an hour |
|
| 183 | - * |
|
| 184 | - * @return string[] |
|
| 185 | - */ |
|
| 186 | - protected function getOldFiles() { |
|
| 187 | - $cutOfTime = time() - 3600; |
|
| 188 | - $files = []; |
|
| 189 | - $dh = opendir($this->tmpBaseDir); |
|
| 190 | - if ($dh) { |
|
| 191 | - while (($file = readdir($dh)) !== false) { |
|
| 192 | - if (substr($file, 0, 7) === self::TMP_PREFIX) { |
|
| 193 | - $path = $this->tmpBaseDir . '/' . $file; |
|
| 194 | - $mtime = filemtime($path); |
|
| 195 | - if ($mtime < $cutOfTime) { |
|
| 196 | - $files[] = $path; |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - return $files; |
|
| 202 | - } |
|
| 181 | + /** |
|
| 182 | + * Get all temporary files and folders generated by oc older than an hour |
|
| 183 | + * |
|
| 184 | + * @return string[] |
|
| 185 | + */ |
|
| 186 | + protected function getOldFiles() { |
|
| 187 | + $cutOfTime = time() - 3600; |
|
| 188 | + $files = []; |
|
| 189 | + $dh = opendir($this->tmpBaseDir); |
|
| 190 | + if ($dh) { |
|
| 191 | + while (($file = readdir($dh)) !== false) { |
|
| 192 | + if (substr($file, 0, 7) === self::TMP_PREFIX) { |
|
| 193 | + $path = $this->tmpBaseDir . '/' . $file; |
|
| 194 | + $mtime = filemtime($path); |
|
| 195 | + if ($mtime < $cutOfTime) { |
|
| 196 | + $files[] = $path; |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + return $files; |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - /** |
|
| 205 | - * Get the temporary base directory configured on the server |
|
| 206 | - * |
|
| 207 | - * @return string Path to the temporary directory or null |
|
| 208 | - * @throws \UnexpectedValueException |
|
| 209 | - */ |
|
| 210 | - public function getTempBaseDir() { |
|
| 211 | - if ($this->tmpBaseDir) { |
|
| 212 | - return $this->tmpBaseDir; |
|
| 213 | - } |
|
| 204 | + /** |
|
| 205 | + * Get the temporary base directory configured on the server |
|
| 206 | + * |
|
| 207 | + * @return string Path to the temporary directory or null |
|
| 208 | + * @throws \UnexpectedValueException |
|
| 209 | + */ |
|
| 210 | + public function getTempBaseDir() { |
|
| 211 | + if ($this->tmpBaseDir) { |
|
| 212 | + return $this->tmpBaseDir; |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - $directories = []; |
|
| 216 | - if ($temp = $this->config->getSystemValue('tempdirectory', null)) { |
|
| 217 | - $directories[] = $temp; |
|
| 218 | - } |
|
| 219 | - if ($temp = \OC::$server->getIniWrapper()->get('upload_tmp_dir')) { |
|
| 220 | - $directories[] = $temp; |
|
| 221 | - } |
|
| 222 | - if ($temp = getenv('TMP')) { |
|
| 223 | - $directories[] = $temp; |
|
| 224 | - } |
|
| 225 | - if ($temp = getenv('TEMP')) { |
|
| 226 | - $directories[] = $temp; |
|
| 227 | - } |
|
| 228 | - if ($temp = getenv('TMPDIR')) { |
|
| 229 | - $directories[] = $temp; |
|
| 230 | - } |
|
| 231 | - if ($temp = sys_get_temp_dir()) { |
|
| 232 | - $directories[] = $temp; |
|
| 233 | - } |
|
| 215 | + $directories = []; |
|
| 216 | + if ($temp = $this->config->getSystemValue('tempdirectory', null)) { |
|
| 217 | + $directories[] = $temp; |
|
| 218 | + } |
|
| 219 | + if ($temp = \OC::$server->getIniWrapper()->get('upload_tmp_dir')) { |
|
| 220 | + $directories[] = $temp; |
|
| 221 | + } |
|
| 222 | + if ($temp = getenv('TMP')) { |
|
| 223 | + $directories[] = $temp; |
|
| 224 | + } |
|
| 225 | + if ($temp = getenv('TEMP')) { |
|
| 226 | + $directories[] = $temp; |
|
| 227 | + } |
|
| 228 | + if ($temp = getenv('TMPDIR')) { |
|
| 229 | + $directories[] = $temp; |
|
| 230 | + } |
|
| 231 | + if ($temp = sys_get_temp_dir()) { |
|
| 232 | + $directories[] = $temp; |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | - foreach ($directories as $dir) { |
|
| 236 | - if ($this->checkTemporaryDirectory($dir)) { |
|
| 237 | - return $dir; |
|
| 238 | - } |
|
| 239 | - } |
|
| 235 | + foreach ($directories as $dir) { |
|
| 236 | + if ($this->checkTemporaryDirectory($dir)) { |
|
| 237 | + return $dir; |
|
| 238 | + } |
|
| 239 | + } |
|
| 240 | 240 | |
| 241 | - $temp = tempnam(dirname(__FILE__), ''); |
|
| 242 | - if (file_exists($temp)) { |
|
| 243 | - unlink($temp); |
|
| 244 | - return dirname($temp); |
|
| 245 | - } |
|
| 246 | - throw new \UnexpectedValueException('Unable to detect system temporary directory'); |
|
| 247 | - } |
|
| 241 | + $temp = tempnam(dirname(__FILE__), ''); |
|
| 242 | + if (file_exists($temp)) { |
|
| 243 | + unlink($temp); |
|
| 244 | + return dirname($temp); |
|
| 245 | + } |
|
| 246 | + throw new \UnexpectedValueException('Unable to detect system temporary directory'); |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - /** |
|
| 250 | - * Check if a temporary directory is ready for use |
|
| 251 | - * |
|
| 252 | - * @param mixed $directory |
|
| 253 | - * @return bool |
|
| 254 | - */ |
|
| 255 | - private function checkTemporaryDirectory($directory) { |
|
| 256 | - // suppress any possible errors caused by is_writable |
|
| 257 | - // checks missing or invalid path or characters, wrong permissions etc |
|
| 258 | - try { |
|
| 259 | - if (is_writable($directory)) { |
|
| 260 | - return true; |
|
| 261 | - } |
|
| 262 | - } catch (\Exception $e) { |
|
| 263 | - } |
|
| 264 | - $this->log->warning('Temporary directory {dir} is not present or writable', |
|
| 265 | - ['dir' => $directory] |
|
| 266 | - ); |
|
| 267 | - return false; |
|
| 268 | - } |
|
| 249 | + /** |
|
| 250 | + * Check if a temporary directory is ready for use |
|
| 251 | + * |
|
| 252 | + * @param mixed $directory |
|
| 253 | + * @return bool |
|
| 254 | + */ |
|
| 255 | + private function checkTemporaryDirectory($directory) { |
|
| 256 | + // suppress any possible errors caused by is_writable |
|
| 257 | + // checks missing or invalid path or characters, wrong permissions etc |
|
| 258 | + try { |
|
| 259 | + if (is_writable($directory)) { |
|
| 260 | + return true; |
|
| 261 | + } |
|
| 262 | + } catch (\Exception $e) { |
|
| 263 | + } |
|
| 264 | + $this->log->warning('Temporary directory {dir} is not present or writable', |
|
| 265 | + ['dir' => $directory] |
|
| 266 | + ); |
|
| 267 | + return false; |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | - /** |
|
| 271 | - * Override the temporary base directory |
|
| 272 | - * |
|
| 273 | - * @param string $directory |
|
| 274 | - */ |
|
| 275 | - public function overrideTempBaseDir($directory) { |
|
| 276 | - $this->tmpBaseDir = $directory; |
|
| 277 | - } |
|
| 270 | + /** |
|
| 271 | + * Override the temporary base directory |
|
| 272 | + * |
|
| 273 | + * @param string $directory |
|
| 274 | + */ |
|
| 275 | + public function overrideTempBaseDir($directory) { |
|
| 276 | + $this->tmpBaseDir = $directory; |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | 279 | } |
@@ -28,20 +28,20 @@ |
||
| 28 | 28 | class Errorlog { |
| 29 | 29 | |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Init class data |
|
| 33 | - */ |
|
| 34 | - public static function init() { |
|
| 35 | - } |
|
| 31 | + /** |
|
| 32 | + * Init class data |
|
| 33 | + */ |
|
| 34 | + public static function init() { |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * write a message in the log |
|
| 39 | - * @param string $app |
|
| 40 | - * @param string $message |
|
| 41 | - * @param int $level |
|
| 42 | - */ |
|
| 43 | - public static function write($app, $message, $level) { |
|
| 44 | - error_log('[owncloud]['.$app.']['.$level.'] '.$message); |
|
| 45 | - } |
|
| 37 | + /** |
|
| 38 | + * write a message in the log |
|
| 39 | + * @param string $app |
|
| 40 | + * @param string $message |
|
| 41 | + * @param int $level |
|
| 42 | + */ |
|
| 43 | + public static function write($app, $message, $level) { |
|
| 44 | + error_log('[owncloud]['.$app.']['.$level.'] '.$message); |
|
| 45 | + } |
|
| 46 | 46 | } |
| 47 | 47 | |
@@ -26,31 +26,31 @@ |
||
| 26 | 26 | namespace OC\Log; |
| 27 | 27 | |
| 28 | 28 | class Syslog { |
| 29 | - static protected $levels = array( |
|
| 30 | - \OCP\Util::DEBUG => LOG_DEBUG, |
|
| 31 | - \OCP\Util::INFO => LOG_INFO, |
|
| 32 | - \OCP\Util::WARN => LOG_WARNING, |
|
| 33 | - \OCP\Util::ERROR => LOG_ERR, |
|
| 34 | - \OCP\Util::FATAL => LOG_CRIT, |
|
| 35 | - ); |
|
| 29 | + static protected $levels = array( |
|
| 30 | + \OCP\Util::DEBUG => LOG_DEBUG, |
|
| 31 | + \OCP\Util::INFO => LOG_INFO, |
|
| 32 | + \OCP\Util::WARN => LOG_WARNING, |
|
| 33 | + \OCP\Util::ERROR => LOG_ERR, |
|
| 34 | + \OCP\Util::FATAL => LOG_CRIT, |
|
| 35 | + ); |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Init class data |
|
| 39 | - */ |
|
| 40 | - public static function init() { |
|
| 41 | - openlog(\OC::$server->getSystemConfig()->getValue("syslog_tag", "ownCloud"), LOG_PID | LOG_CONS, LOG_USER); |
|
| 42 | - // Close at shutdown |
|
| 43 | - register_shutdown_function('closelog'); |
|
| 44 | - } |
|
| 37 | + /** |
|
| 38 | + * Init class data |
|
| 39 | + */ |
|
| 40 | + public static function init() { |
|
| 41 | + openlog(\OC::$server->getSystemConfig()->getValue("syslog_tag", "ownCloud"), LOG_PID | LOG_CONS, LOG_USER); |
|
| 42 | + // Close at shutdown |
|
| 43 | + register_shutdown_function('closelog'); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * write a message in the log |
|
| 48 | - * @param string $app |
|
| 49 | - * @param string $message |
|
| 50 | - * @param int $level |
|
| 51 | - */ |
|
| 52 | - public static function write($app, $message, $level) { |
|
| 53 | - $syslog_level = self::$levels[$level]; |
|
| 54 | - syslog($syslog_level, '{'.$app.'} '.$message); |
|
| 55 | - } |
|
| 46 | + /** |
|
| 47 | + * write a message in the log |
|
| 48 | + * @param string $app |
|
| 49 | + * @param string $message |
|
| 50 | + * @param int $level |
|
| 51 | + */ |
|
| 52 | + public static function write($app, $message, $level) { |
|
| 53 | + $syslog_level = self::$levels[$level]; |
|
| 54 | + syslog($syslog_level, '{'.$app.'} '.$message); |
|
| 55 | + } |
|
| 56 | 56 | } |
@@ -28,74 +28,74 @@ |
||
| 28 | 28 | use OCP\ILogger; |
| 29 | 29 | |
| 30 | 30 | class ErrorHandler { |
| 31 | - /** @var ILogger */ |
|
| 32 | - private static $logger; |
|
| 31 | + /** @var ILogger */ |
|
| 32 | + private static $logger; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * remove password in URLs |
|
| 36 | - * @param string $msg |
|
| 37 | - * @return string |
|
| 38 | - */ |
|
| 39 | - protected static function removePassword($msg) { |
|
| 40 | - return preg_replace('/\/\/(.*):(.*)@/', '//xxx:xxx@', $msg); |
|
| 41 | - } |
|
| 34 | + /** |
|
| 35 | + * remove password in URLs |
|
| 36 | + * @param string $msg |
|
| 37 | + * @return string |
|
| 38 | + */ |
|
| 39 | + protected static function removePassword($msg) { |
|
| 40 | + return preg_replace('/\/\/(.*):(.*)@/', '//xxx:xxx@', $msg); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public static function register($debug=false) { |
|
| 44 | - $handler = new ErrorHandler(); |
|
| 43 | + public static function register($debug=false) { |
|
| 44 | + $handler = new ErrorHandler(); |
|
| 45 | 45 | |
| 46 | - if ($debug) { |
|
| 47 | - set_error_handler(array($handler, 'onAll'), E_ALL); |
|
| 48 | - if (\OC::$CLI) { |
|
| 49 | - set_exception_handler(array('OC_Template', 'printExceptionErrorPage')); |
|
| 50 | - } |
|
| 51 | - } else { |
|
| 52 | - set_error_handler(array($handler, 'onError')); |
|
| 53 | - } |
|
| 54 | - register_shutdown_function(array($handler, 'onShutdown')); |
|
| 55 | - set_exception_handler(array($handler, 'onException')); |
|
| 56 | - } |
|
| 46 | + if ($debug) { |
|
| 47 | + set_error_handler(array($handler, 'onAll'), E_ALL); |
|
| 48 | + if (\OC::$CLI) { |
|
| 49 | + set_exception_handler(array('OC_Template', 'printExceptionErrorPage')); |
|
| 50 | + } |
|
| 51 | + } else { |
|
| 52 | + set_error_handler(array($handler, 'onError')); |
|
| 53 | + } |
|
| 54 | + register_shutdown_function(array($handler, 'onShutdown')); |
|
| 55 | + set_exception_handler(array($handler, 'onException')); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - public static function setLogger(ILogger $logger) { |
|
| 59 | - self::$logger = $logger; |
|
| 60 | - } |
|
| 58 | + public static function setLogger(ILogger $logger) { |
|
| 59 | + self::$logger = $logger; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - //Fatal errors handler |
|
| 63 | - public static function onShutdown() { |
|
| 64 | - $error = error_get_last(); |
|
| 65 | - if($error && self::$logger) { |
|
| 66 | - //ob_end_clean(); |
|
| 67 | - $msg = $error['message'] . ' at ' . $error['file'] . '#' . $error['line']; |
|
| 68 | - self::$logger->critical(self::removePassword($msg), array('app' => 'PHP')); |
|
| 69 | - } |
|
| 70 | - } |
|
| 62 | + //Fatal errors handler |
|
| 63 | + public static function onShutdown() { |
|
| 64 | + $error = error_get_last(); |
|
| 65 | + if($error && self::$logger) { |
|
| 66 | + //ob_end_clean(); |
|
| 67 | + $msg = $error['message'] . ' at ' . $error['file'] . '#' . $error['line']; |
|
| 68 | + self::$logger->critical(self::removePassword($msg), array('app' => 'PHP')); |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Uncaught exception handler |
|
| 74 | - * |
|
| 75 | - * @param \Exception $exception |
|
| 76 | - */ |
|
| 77 | - public static function onException($exception) { |
|
| 78 | - $class = get_class($exception); |
|
| 79 | - $msg = $exception->getMessage(); |
|
| 80 | - $msg = "$class: $msg at " . $exception->getFile() . '#' . $exception->getLine(); |
|
| 81 | - self::$logger->critical(self::removePassword($msg), ['app' => 'PHP']); |
|
| 82 | - } |
|
| 72 | + /** |
|
| 73 | + * Uncaught exception handler |
|
| 74 | + * |
|
| 75 | + * @param \Exception $exception |
|
| 76 | + */ |
|
| 77 | + public static function onException($exception) { |
|
| 78 | + $class = get_class($exception); |
|
| 79 | + $msg = $exception->getMessage(); |
|
| 80 | + $msg = "$class: $msg at " . $exception->getFile() . '#' . $exception->getLine(); |
|
| 81 | + self::$logger->critical(self::removePassword($msg), ['app' => 'PHP']); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - //Recoverable errors handler |
|
| 85 | - public static function onError($number, $message, $file, $line) { |
|
| 86 | - if (error_reporting() === 0) { |
|
| 87 | - return; |
|
| 88 | - } |
|
| 89 | - $msg = $message . ' at ' . $file . '#' . $line; |
|
| 90 | - self::$logger->error(self::removePassword($msg), array('app' => 'PHP')); |
|
| 84 | + //Recoverable errors handler |
|
| 85 | + public static function onError($number, $message, $file, $line) { |
|
| 86 | + if (error_reporting() === 0) { |
|
| 87 | + return; |
|
| 88 | + } |
|
| 89 | + $msg = $message . ' at ' . $file . '#' . $line; |
|
| 90 | + self::$logger->error(self::removePassword($msg), array('app' => 'PHP')); |
|
| 91 | 91 | |
| 92 | - } |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - //Recoverable handler which catch all errors, warnings and notices |
|
| 95 | - public static function onAll($number, $message, $file, $line) { |
|
| 96 | - $msg = $message . ' at ' . $file . '#' . $line; |
|
| 97 | - self::$logger->debug(self::removePassword($msg), array('app' => 'PHP')); |
|
| 94 | + //Recoverable handler which catch all errors, warnings and notices |
|
| 95 | + public static function onAll($number, $message, $file, $line) { |
|
| 96 | + $msg = $message . ' at ' . $file . '#' . $line; |
|
| 97 | + self::$logger->debug(self::removePassword($msg), array('app' => 'PHP')); |
|
| 98 | 98 | |
| 99 | - } |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | 101 | } |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | return preg_replace('/\/\/(.*):(.*)@/', '//xxx:xxx@', $msg); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - public static function register($debug=false) { |
|
| 43 | + public static function register($debug = false) { |
|
| 44 | 44 | $handler = new ErrorHandler(); |
| 45 | 45 | |
| 46 | 46 | if ($debug) { |
@@ -62,9 +62,9 @@ discard block |
||
| 62 | 62 | //Fatal errors handler |
| 63 | 63 | public static function onShutdown() { |
| 64 | 64 | $error = error_get_last(); |
| 65 | - if($error && self::$logger) { |
|
| 65 | + if ($error && self::$logger) { |
|
| 66 | 66 | //ob_end_clean(); |
| 67 | - $msg = $error['message'] . ' at ' . $error['file'] . '#' . $error['line']; |
|
| 67 | + $msg = $error['message'].' at '.$error['file'].'#'.$error['line']; |
|
| 68 | 68 | self::$logger->critical(self::removePassword($msg), array('app' => 'PHP')); |
| 69 | 69 | } |
| 70 | 70 | } |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | public static function onException($exception) { |
| 78 | 78 | $class = get_class($exception); |
| 79 | 79 | $msg = $exception->getMessage(); |
| 80 | - $msg = "$class: $msg at " . $exception->getFile() . '#' . $exception->getLine(); |
|
| 80 | + $msg = "$class: $msg at ".$exception->getFile().'#'.$exception->getLine(); |
|
| 81 | 81 | self::$logger->critical(self::removePassword($msg), ['app' => 'PHP']); |
| 82 | 82 | } |
| 83 | 83 | |
@@ -86,14 +86,14 @@ discard block |
||
| 86 | 86 | if (error_reporting() === 0) { |
| 87 | 87 | return; |
| 88 | 88 | } |
| 89 | - $msg = $message . ' at ' . $file . '#' . $line; |
|
| 89 | + $msg = $message.' at '.$file.'#'.$line; |
|
| 90 | 90 | self::$logger->error(self::removePassword($msg), array('app' => 'PHP')); |
| 91 | 91 | |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | //Recoverable handler which catch all errors, warnings and notices |
| 95 | 95 | public static function onAll($number, $message, $file, $line) { |
| 96 | - $msg = $message . ' at ' . $file . '#' . $line; |
|
| 96 | + $msg = $message.' at '.$file.'#'.$line; |
|
| 97 | 97 | self::$logger->debug(self::removePassword($msg), array('app' => 'PHP')); |
| 98 | 98 | |
| 99 | 99 | } |
@@ -34,7 +34,7 @@ |
||
| 34 | 34 | private $max_log_size; |
| 35 | 35 | public function run($dummy) { |
| 36 | 36 | $systemConfig = \OC::$server->getSystemConfig(); |
| 37 | - $logFile = $systemConfig->getValue('logfile', $systemConfig->getValue('datadirectory', \OC::$SERVERROOT . '/data') . '/nextcloud.log'); |
|
| 37 | + $logFile = $systemConfig->getValue('logfile', $systemConfig->getValue('datadirectory', \OC::$SERVERROOT.'/data').'/nextcloud.log'); |
|
| 38 | 38 | $this->max_log_size = \OC::$server->getConfig()->getSystemValue('log_rotate_size', false); |
| 39 | 39 | if ($this->max_log_size) { |
| 40 | 40 | $filesize = @filesize($logFile); |
@@ -32,23 +32,23 @@ |
||
| 32 | 32 | * location and manage that with your own tools. |
| 33 | 33 | */ |
| 34 | 34 | class Rotate extends \OC\BackgroundJob\Job { |
| 35 | - private $max_log_size; |
|
| 36 | - public function run($dummy) { |
|
| 37 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
| 38 | - $logFile = $systemConfig->getValue('logfile', $systemConfig->getValue('datadirectory', \OC::$SERVERROOT . '/data') . '/nextcloud.log'); |
|
| 39 | - $this->max_log_size = \OC::$server->getConfig()->getSystemValue('log_rotate_size', false); |
|
| 40 | - if ($this->max_log_size) { |
|
| 41 | - $filesize = @filesize($logFile); |
|
| 42 | - if ($filesize >= $this->max_log_size) { |
|
| 43 | - $this->rotate($logFile); |
|
| 44 | - } |
|
| 45 | - } |
|
| 46 | - } |
|
| 35 | + private $max_log_size; |
|
| 36 | + public function run($dummy) { |
|
| 37 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
| 38 | + $logFile = $systemConfig->getValue('logfile', $systemConfig->getValue('datadirectory', \OC::$SERVERROOT . '/data') . '/nextcloud.log'); |
|
| 39 | + $this->max_log_size = \OC::$server->getConfig()->getSystemValue('log_rotate_size', false); |
|
| 40 | + if ($this->max_log_size) { |
|
| 41 | + $filesize = @filesize($logFile); |
|
| 42 | + if ($filesize >= $this->max_log_size) { |
|
| 43 | + $this->rotate($logFile); |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - protected function rotate($logfile) { |
|
| 49 | - $rotatedLogfile = $logfile.'.1'; |
|
| 50 | - rename($logfile, $rotatedLogfile); |
|
| 51 | - $msg = 'Log file "'.$logfile.'" was over '.$this->max_log_size.' bytes, moved to "'.$rotatedLogfile.'"'; |
|
| 52 | - \OCP\Util::writeLog(Rotate::class, $msg, \OCP\Util::WARN); |
|
| 53 | - } |
|
| 48 | + protected function rotate($logfile) { |
|
| 49 | + $rotatedLogfile = $logfile.'.1'; |
|
| 50 | + rename($logfile, $rotatedLogfile); |
|
| 51 | + $msg = 'Log file "'.$logfile.'" was over '.$this->max_log_size.' bytes, moved to "'.$rotatedLogfile.'"'; |
|
| 52 | + \OCP\Util::writeLog(Rotate::class, $msg, \OCP\Util::WARN); |
|
| 53 | + } |
|
| 54 | 54 | } |
@@ -59,9 +59,9 @@ discard block |
||
| 59 | 59 | public function searchPaged($query, array $inApps = array(), $page = 1, $size = 30) { |
| 60 | 60 | $this->initProviders(); |
| 61 | 61 | $results = array(); |
| 62 | - foreach($this->providers as $provider) { |
|
| 62 | + foreach ($this->providers as $provider) { |
|
| 63 | 63 | /** @var $provider Provider */ |
| 64 | - if ( ! $provider->providesResultsFor($inApps) ) { |
|
| 64 | + if (!$provider->providesResultsFor($inApps)) { |
|
| 65 | 65 | continue; |
| 66 | 66 | } |
| 67 | 67 | if ($provider instanceof PagedProvider) { |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | public function removeProvider($provider) { |
| 97 | 97 | $this->registeredProviders = array_filter( |
| 98 | 98 | $this->registeredProviders, |
| 99 | - function ($element) use ($provider) { |
|
| 99 | + function($element) use ($provider) { |
|
| 100 | 100 | return ($element['class'] != $provider); |
| 101 | 101 | } |
| 102 | 102 | ); |
@@ -117,10 +117,10 @@ discard block |
||
| 117 | 117 | * Create instances of all the registered search providers |
| 118 | 118 | */ |
| 119 | 119 | private function initProviders() { |
| 120 | - if( ! empty($this->providers) ) { |
|
| 120 | + if (!empty($this->providers)) { |
|
| 121 | 121 | return; |
| 122 | 122 | } |
| 123 | - foreach($this->registeredProviders as $provider) { |
|
| 123 | + foreach ($this->registeredProviders as $provider) { |
|
| 124 | 124 | $class = $provider['class']; |
| 125 | 125 | $options = $provider['options']; |
| 126 | 126 | $this->providers[] = new $class($options); |
@@ -34,86 +34,86 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | class Search implements ISearch { |
| 36 | 36 | |
| 37 | - private $providers = array(); |
|
| 38 | - private $registeredProviders = array(); |
|
| 37 | + private $providers = array(); |
|
| 38 | + private $registeredProviders = array(); |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Search all providers for $query |
|
| 42 | - * @param string $query |
|
| 43 | - * @param string[] $inApps optionally limit results to the given apps |
|
| 44 | - * @param int $page pages start at page 1 |
|
| 45 | - * @param int $size, 0 = all |
|
| 46 | - * @return array An array of OC\Search\Result's |
|
| 47 | - */ |
|
| 48 | - public function searchPaged($query, array $inApps = array(), $page = 1, $size = 30) { |
|
| 49 | - $this->initProviders(); |
|
| 50 | - $results = array(); |
|
| 51 | - foreach($this->providers as $provider) { |
|
| 52 | - /** @var $provider Provider */ |
|
| 53 | - if ( ! $provider->providesResultsFor($inApps) ) { |
|
| 54 | - continue; |
|
| 55 | - } |
|
| 56 | - if ($provider instanceof PagedProvider) { |
|
| 57 | - $results = array_merge($results, $provider->searchPaged($query, $page, $size)); |
|
| 58 | - } else if ($provider instanceof Provider) { |
|
| 59 | - $providerResults = $provider->search($query); |
|
| 60 | - if ($size > 0) { |
|
| 61 | - $slicedResults = array_slice($providerResults, ($page - 1) * $size, $size); |
|
| 62 | - $results = array_merge($results, $slicedResults); |
|
| 63 | - } else { |
|
| 64 | - $results = array_merge($results, $providerResults); |
|
| 65 | - } |
|
| 66 | - } else { |
|
| 67 | - \OC::$server->getLogger()->warning('Ignoring Unknown search provider', array('provider' => $provider)); |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - return $results; |
|
| 71 | - } |
|
| 40 | + /** |
|
| 41 | + * Search all providers for $query |
|
| 42 | + * @param string $query |
|
| 43 | + * @param string[] $inApps optionally limit results to the given apps |
|
| 44 | + * @param int $page pages start at page 1 |
|
| 45 | + * @param int $size, 0 = all |
|
| 46 | + * @return array An array of OC\Search\Result's |
|
| 47 | + */ |
|
| 48 | + public function searchPaged($query, array $inApps = array(), $page = 1, $size = 30) { |
|
| 49 | + $this->initProviders(); |
|
| 50 | + $results = array(); |
|
| 51 | + foreach($this->providers as $provider) { |
|
| 52 | + /** @var $provider Provider */ |
|
| 53 | + if ( ! $provider->providesResultsFor($inApps) ) { |
|
| 54 | + continue; |
|
| 55 | + } |
|
| 56 | + if ($provider instanceof PagedProvider) { |
|
| 57 | + $results = array_merge($results, $provider->searchPaged($query, $page, $size)); |
|
| 58 | + } else if ($provider instanceof Provider) { |
|
| 59 | + $providerResults = $provider->search($query); |
|
| 60 | + if ($size > 0) { |
|
| 61 | + $slicedResults = array_slice($providerResults, ($page - 1) * $size, $size); |
|
| 62 | + $results = array_merge($results, $slicedResults); |
|
| 63 | + } else { |
|
| 64 | + $results = array_merge($results, $providerResults); |
|
| 65 | + } |
|
| 66 | + } else { |
|
| 67 | + \OC::$server->getLogger()->warning('Ignoring Unknown search provider', array('provider' => $provider)); |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + return $results; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Remove all registered search providers |
|
| 75 | - */ |
|
| 76 | - public function clearProviders() { |
|
| 77 | - $this->providers = array(); |
|
| 78 | - $this->registeredProviders = array(); |
|
| 79 | - } |
|
| 73 | + /** |
|
| 74 | + * Remove all registered search providers |
|
| 75 | + */ |
|
| 76 | + public function clearProviders() { |
|
| 77 | + $this->providers = array(); |
|
| 78 | + $this->registeredProviders = array(); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Remove one existing search provider |
|
| 83 | - * @param string $provider class name of a OC\Search\Provider |
|
| 84 | - */ |
|
| 85 | - public function removeProvider($provider) { |
|
| 86 | - $this->registeredProviders = array_filter( |
|
| 87 | - $this->registeredProviders, |
|
| 88 | - function ($element) use ($provider) { |
|
| 89 | - return ($element['class'] != $provider); |
|
| 90 | - } |
|
| 91 | - ); |
|
| 92 | - // force regeneration of providers on next search |
|
| 93 | - $this->providers = array(); |
|
| 94 | - } |
|
| 81 | + /** |
|
| 82 | + * Remove one existing search provider |
|
| 83 | + * @param string $provider class name of a OC\Search\Provider |
|
| 84 | + */ |
|
| 85 | + public function removeProvider($provider) { |
|
| 86 | + $this->registeredProviders = array_filter( |
|
| 87 | + $this->registeredProviders, |
|
| 88 | + function ($element) use ($provider) { |
|
| 89 | + return ($element['class'] != $provider); |
|
| 90 | + } |
|
| 91 | + ); |
|
| 92 | + // force regeneration of providers on next search |
|
| 93 | + $this->providers = array(); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Register a new search provider to search with |
|
| 98 | - * @param string $class class name of a OC\Search\Provider |
|
| 99 | - * @param array $options optional |
|
| 100 | - */ |
|
| 101 | - public function registerProvider($class, array $options = array()) { |
|
| 102 | - $this->registeredProviders[] = array('class' => $class, 'options' => $options); |
|
| 103 | - } |
|
| 96 | + /** |
|
| 97 | + * Register a new search provider to search with |
|
| 98 | + * @param string $class class name of a OC\Search\Provider |
|
| 99 | + * @param array $options optional |
|
| 100 | + */ |
|
| 101 | + public function registerProvider($class, array $options = array()) { |
|
| 102 | + $this->registeredProviders[] = array('class' => $class, 'options' => $options); |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Create instances of all the registered search providers |
|
| 107 | - */ |
|
| 108 | - private function initProviders() { |
|
| 109 | - if( ! empty($this->providers) ) { |
|
| 110 | - return; |
|
| 111 | - } |
|
| 112 | - foreach($this->registeredProviders as $provider) { |
|
| 113 | - $class = $provider['class']; |
|
| 114 | - $options = $provider['options']; |
|
| 115 | - $this->providers[] = new $class($options); |
|
| 116 | - } |
|
| 117 | - } |
|
| 105 | + /** |
|
| 106 | + * Create instances of all the registered search providers |
|
| 107 | + */ |
|
| 108 | + private function initProviders() { |
|
| 109 | + if( ! empty($this->providers) ) { |
|
| 110 | + return; |
|
| 111 | + } |
|
| 112 | + foreach($this->registeredProviders as $provider) { |
|
| 113 | + $class = $provider['class']; |
|
| 114 | + $options = $provider['options']; |
|
| 115 | + $this->providers[] = new $class($options); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | 119 | } |
@@ -81,7 +81,7 @@ |
||
| 81 | 81 | // FIXME: Required for CI |
| 82 | 82 | if (!defined('PHPUNIT_RUN')) { |
| 83 | 83 | $webRoot = \OC::$WEBROOT; |
| 84 | - if($webRoot === '') { |
|
| 84 | + if ($webRoot === '') { |
|
| 85 | 85 | $webRoot = '/'; |
| 86 | 86 | } |
| 87 | 87 | setcookie(self::COOKIE_NAME, $this->passphrase, 0, $webRoot, '', $secureCookie, true); |
@@ -48,58 +48,58 @@ |
||
| 48 | 48 | * @package OC\Session |
| 49 | 49 | */ |
| 50 | 50 | class CryptoWrapper { |
| 51 | - const COOKIE_NAME = 'oc_sessionPassphrase'; |
|
| 51 | + const COOKIE_NAME = 'oc_sessionPassphrase'; |
|
| 52 | 52 | |
| 53 | - /** @var IConfig */ |
|
| 54 | - protected $config; |
|
| 55 | - /** @var ISession */ |
|
| 56 | - protected $session; |
|
| 57 | - /** @var ICrypto */ |
|
| 58 | - protected $crypto; |
|
| 59 | - /** @var ISecureRandom */ |
|
| 60 | - protected $random; |
|
| 61 | - /** @var string */ |
|
| 62 | - protected $passphrase; |
|
| 53 | + /** @var IConfig */ |
|
| 54 | + protected $config; |
|
| 55 | + /** @var ISession */ |
|
| 56 | + protected $session; |
|
| 57 | + /** @var ICrypto */ |
|
| 58 | + protected $crypto; |
|
| 59 | + /** @var ISecureRandom */ |
|
| 60 | + protected $random; |
|
| 61 | + /** @var string */ |
|
| 62 | + protected $passphrase; |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @param IConfig $config |
|
| 66 | - * @param ICrypto $crypto |
|
| 67 | - * @param ISecureRandom $random |
|
| 68 | - * @param IRequest $request |
|
| 69 | - */ |
|
| 70 | - public function __construct(IConfig $config, |
|
| 71 | - ICrypto $crypto, |
|
| 72 | - ISecureRandom $random, |
|
| 73 | - IRequest $request) { |
|
| 74 | - $this->crypto = $crypto; |
|
| 75 | - $this->config = $config; |
|
| 76 | - $this->random = $random; |
|
| 64 | + /** |
|
| 65 | + * @param IConfig $config |
|
| 66 | + * @param ICrypto $crypto |
|
| 67 | + * @param ISecureRandom $random |
|
| 68 | + * @param IRequest $request |
|
| 69 | + */ |
|
| 70 | + public function __construct(IConfig $config, |
|
| 71 | + ICrypto $crypto, |
|
| 72 | + ISecureRandom $random, |
|
| 73 | + IRequest $request) { |
|
| 74 | + $this->crypto = $crypto; |
|
| 75 | + $this->config = $config; |
|
| 76 | + $this->random = $random; |
|
| 77 | 77 | |
| 78 | - if (!is_null($request->getCookie(self::COOKIE_NAME))) { |
|
| 79 | - $this->passphrase = $request->getCookie(self::COOKIE_NAME); |
|
| 80 | - } else { |
|
| 81 | - $this->passphrase = $this->random->generate(128); |
|
| 82 | - $secureCookie = $request->getServerProtocol() === 'https'; |
|
| 83 | - // FIXME: Required for CI |
|
| 84 | - if (!defined('PHPUNIT_RUN')) { |
|
| 85 | - $webRoot = \OC::$WEBROOT; |
|
| 86 | - if($webRoot === '') { |
|
| 87 | - $webRoot = '/'; |
|
| 88 | - } |
|
| 89 | - setcookie(self::COOKIE_NAME, $this->passphrase, 0, $webRoot, '', $secureCookie, true); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - } |
|
| 78 | + if (!is_null($request->getCookie(self::COOKIE_NAME))) { |
|
| 79 | + $this->passphrase = $request->getCookie(self::COOKIE_NAME); |
|
| 80 | + } else { |
|
| 81 | + $this->passphrase = $this->random->generate(128); |
|
| 82 | + $secureCookie = $request->getServerProtocol() === 'https'; |
|
| 83 | + // FIXME: Required for CI |
|
| 84 | + if (!defined('PHPUNIT_RUN')) { |
|
| 85 | + $webRoot = \OC::$WEBROOT; |
|
| 86 | + if($webRoot === '') { |
|
| 87 | + $webRoot = '/'; |
|
| 88 | + } |
|
| 89 | + setcookie(self::COOKIE_NAME, $this->passphrase, 0, $webRoot, '', $secureCookie, true); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * @param ISession $session |
|
| 96 | - * @return ISession |
|
| 97 | - */ |
|
| 98 | - public function wrapSession(ISession $session) { |
|
| 99 | - if (!($session instanceof CryptoSessionData)) { |
|
| 100 | - return new CryptoSessionData($session, $this->crypto, $this->passphrase); |
|
| 101 | - } |
|
| 94 | + /** |
|
| 95 | + * @param ISession $session |
|
| 96 | + * @return ISession |
|
| 97 | + */ |
|
| 98 | + public function wrapSession(ISession $session) { |
|
| 99 | + if (!($session instanceof CryptoSessionData)) { |
|
| 100 | + return new CryptoSessionData($session, $this->crypto, $this->passphrase); |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - return $session; |
|
| 104 | - } |
|
| 103 | + return $session; |
|
| 104 | + } |
|
| 105 | 105 | } |