@@ -46,7 +46,7 @@ |
||
46 | 46 | /** |
47 | 47 | * @since 9.2.0 |
48 | 48 | */ |
49 | - const EVENT = self::class . ':' . 'PreviewRequested'; |
|
49 | + const EVENT = self::class.':'.'PreviewRequested'; |
|
50 | 50 | |
51 | 51 | const MODE_FILL = 'fill'; |
52 | 52 | const MODE_COVER = 'cover'; |
@@ -44,74 +44,74 @@ |
||
44 | 44 | */ |
45 | 45 | interface IPreview { |
46 | 46 | |
47 | - /** |
|
48 | - * @since 9.2.0 |
|
49 | - */ |
|
50 | - const EVENT = self::class . ':' . 'PreviewRequested'; |
|
47 | + /** |
|
48 | + * @since 9.2.0 |
|
49 | + */ |
|
50 | + const EVENT = self::class . ':' . 'PreviewRequested'; |
|
51 | 51 | |
52 | - const MODE_FILL = 'fill'; |
|
53 | - const MODE_COVER = 'cover'; |
|
52 | + const MODE_FILL = 'fill'; |
|
53 | + const MODE_COVER = 'cover'; |
|
54 | 54 | |
55 | - /** |
|
56 | - * In order to improve lazy loading a closure can be registered which will be |
|
57 | - * called in case preview providers are actually requested |
|
58 | - * |
|
59 | - * $callable has to return an instance of \OCP\Preview\IProvider |
|
60 | - * |
|
61 | - * @param string $mimeTypeRegex Regex with the mime types that are supported by this provider |
|
62 | - * @param \Closure $callable |
|
63 | - * @return void |
|
64 | - * @since 8.1.0 |
|
65 | - */ |
|
66 | - public function registerProvider($mimeTypeRegex, \Closure $callable); |
|
55 | + /** |
|
56 | + * In order to improve lazy loading a closure can be registered which will be |
|
57 | + * called in case preview providers are actually requested |
|
58 | + * |
|
59 | + * $callable has to return an instance of \OCP\Preview\IProvider |
|
60 | + * |
|
61 | + * @param string $mimeTypeRegex Regex with the mime types that are supported by this provider |
|
62 | + * @param \Closure $callable |
|
63 | + * @return void |
|
64 | + * @since 8.1.0 |
|
65 | + */ |
|
66 | + public function registerProvider($mimeTypeRegex, \Closure $callable); |
|
67 | 67 | |
68 | - /** |
|
69 | - * Get all providers |
|
70 | - * @return array |
|
71 | - * @since 8.1.0 |
|
72 | - */ |
|
73 | - public function getProviders(); |
|
68 | + /** |
|
69 | + * Get all providers |
|
70 | + * @return array |
|
71 | + * @since 8.1.0 |
|
72 | + */ |
|
73 | + public function getProviders(); |
|
74 | 74 | |
75 | - /** |
|
76 | - * Does the manager have any providers |
|
77 | - * @return bool |
|
78 | - * @since 8.1.0 |
|
79 | - */ |
|
80 | - public function hasProviders(); |
|
75 | + /** |
|
76 | + * Does the manager have any providers |
|
77 | + * @return bool |
|
78 | + * @since 8.1.0 |
|
79 | + */ |
|
80 | + public function hasProviders(); |
|
81 | 81 | |
82 | - /** |
|
83 | - * Returns a preview of a file |
|
84 | - * |
|
85 | - * The cache is searched first and if nothing usable was found then a preview is |
|
86 | - * generated by one of the providers |
|
87 | - * |
|
88 | - * @param File $file |
|
89 | - * @param int $width |
|
90 | - * @param int $height |
|
91 | - * @param bool $crop |
|
92 | - * @param string $mode |
|
93 | - * @param string $mimeType To force a given mimetype for the file (files_versions needs this) |
|
94 | - * @return ISimpleFile |
|
95 | - * @throws NotFoundException |
|
96 | - * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid) |
|
97 | - * @since 11.0.0 - \InvalidArgumentException was added in 12.0.0 |
|
98 | - */ |
|
99 | - public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null); |
|
82 | + /** |
|
83 | + * Returns a preview of a file |
|
84 | + * |
|
85 | + * The cache is searched first and if nothing usable was found then a preview is |
|
86 | + * generated by one of the providers |
|
87 | + * |
|
88 | + * @param File $file |
|
89 | + * @param int $width |
|
90 | + * @param int $height |
|
91 | + * @param bool $crop |
|
92 | + * @param string $mode |
|
93 | + * @param string $mimeType To force a given mimetype for the file (files_versions needs this) |
|
94 | + * @return ISimpleFile |
|
95 | + * @throws NotFoundException |
|
96 | + * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid) |
|
97 | + * @since 11.0.0 - \InvalidArgumentException was added in 12.0.0 |
|
98 | + */ |
|
99 | + public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null); |
|
100 | 100 | |
101 | - /** |
|
102 | - * Returns true if the passed mime type is supported |
|
103 | - * @param string $mimeType |
|
104 | - * @return boolean |
|
105 | - * @since 6.0.0 |
|
106 | - */ |
|
107 | - public function isMimeSupported($mimeType = '*'); |
|
101 | + /** |
|
102 | + * Returns true if the passed mime type is supported |
|
103 | + * @param string $mimeType |
|
104 | + * @return boolean |
|
105 | + * @since 6.0.0 |
|
106 | + */ |
|
107 | + public function isMimeSupported($mimeType = '*'); |
|
108 | 108 | |
109 | - /** |
|
110 | - * Check if a preview can be generated for a file |
|
111 | - * |
|
112 | - * @param \OCP\Files\FileInfo $file |
|
113 | - * @return bool |
|
114 | - * @since 8.0.0 |
|
115 | - */ |
|
116 | - public function isAvailable(\OCP\Files\FileInfo $file); |
|
109 | + /** |
|
110 | + * Check if a preview can be generated for a file |
|
111 | + * |
|
112 | + * @param \OCP\Files\FileInfo $file |
|
113 | + * @return bool |
|
114 | + * @since 8.0.0 |
|
115 | + */ |
|
116 | + public function isAvailable(\OCP\Files\FileInfo $file); |
|
117 | 117 | } |
@@ -28,45 +28,45 @@ |
||
28 | 28 | |
29 | 29 | class Credentials implements ICredentials { |
30 | 30 | |
31 | - /** @var string */ |
|
32 | - private $uid; |
|
31 | + /** @var string */ |
|
32 | + private $uid; |
|
33 | 33 | |
34 | - /** @var string */ |
|
35 | - private $loginName; |
|
34 | + /** @var string */ |
|
35 | + private $loginName; |
|
36 | 36 | |
37 | - /** @var string */ |
|
38 | - private $password; |
|
37 | + /** @var string */ |
|
38 | + private $password; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param string $uid |
|
42 | - * @param string $loginName |
|
43 | - * @param string $password |
|
44 | - */ |
|
45 | - public function __construct($uid, $loginName, $password) { |
|
46 | - $this->uid = $uid; |
|
47 | - $this->loginName = $loginName; |
|
48 | - $this->password = $password; |
|
49 | - } |
|
40 | + /** |
|
41 | + * @param string $uid |
|
42 | + * @param string $loginName |
|
43 | + * @param string $password |
|
44 | + */ |
|
45 | + public function __construct($uid, $loginName, $password) { |
|
46 | + $this->uid = $uid; |
|
47 | + $this->loginName = $loginName; |
|
48 | + $this->password = $password; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return string |
|
53 | - */ |
|
54 | - public function getUID() { |
|
55 | - return $this->uid; |
|
56 | - } |
|
51 | + /** |
|
52 | + * @return string |
|
53 | + */ |
|
54 | + public function getUID() { |
|
55 | + return $this->uid; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - public function getLoginName() { |
|
62 | - return $this->loginName; |
|
63 | - } |
|
58 | + /** |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + public function getLoginName() { |
|
62 | + return $this->loginName; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public function getPassword() { |
|
69 | - return $this->password; |
|
70 | - } |
|
65 | + /** |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public function getPassword() { |
|
69 | + return $this->password; |
|
70 | + } |
|
71 | 71 | |
72 | 72 | } |
@@ -37,84 +37,84 @@ |
||
37 | 37 | |
38 | 38 | class Store implements IStore { |
39 | 39 | |
40 | - /** @var ISession */ |
|
41 | - private $session; |
|
42 | - |
|
43 | - /** @var ILogger */ |
|
44 | - private $logger; |
|
45 | - |
|
46 | - /** @var IProvider|null */ |
|
47 | - private $tokenProvider; |
|
48 | - |
|
49 | - /** |
|
50 | - * @param ISession $session |
|
51 | - * @param ILogger $logger |
|
52 | - * @param IProvider $tokenProvider |
|
53 | - */ |
|
54 | - public function __construct(ISession $session, ILogger $logger, IProvider $tokenProvider = null) { |
|
55 | - $this->session = $session; |
|
56 | - $this->logger = $logger; |
|
57 | - $this->tokenProvider = $tokenProvider; |
|
58 | - |
|
59 | - Util::connectHook('OC_User', 'post_login', $this, 'authenticate'); |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Hook listener on post login |
|
64 | - * |
|
65 | - * @param array $params |
|
66 | - */ |
|
67 | - public function authenticate(array $params) { |
|
68 | - $this->session->set('login_credentials', json_encode($params)); |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Replace the session implementation |
|
73 | - * |
|
74 | - * @param ISession $session |
|
75 | - */ |
|
76 | - public function setSession(ISession $session) { |
|
77 | - $this->session = $session; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * @since 12 |
|
82 | - * |
|
83 | - * @return ICredentials the login credentials of the current user |
|
84 | - * @throws CredentialsUnavailableException |
|
85 | - */ |
|
86 | - public function getLoginCredentials() { |
|
87 | - if (is_null($this->tokenProvider)) { |
|
88 | - throw new CredentialsUnavailableException(); |
|
89 | - } |
|
90 | - |
|
91 | - $trySession = false; |
|
92 | - try { |
|
93 | - $sessionId = $this->session->getId(); |
|
94 | - $token = $this->tokenProvider->getToken($sessionId); |
|
95 | - |
|
96 | - $uid = $token->getUID(); |
|
97 | - $user = $token->getLoginName(); |
|
98 | - $password = $this->tokenProvider->getPassword($token, $sessionId); |
|
99 | - |
|
100 | - return new Credentials($uid, $user, $password); |
|
101 | - } catch (SessionNotAvailableException $ex) { |
|
102 | - $this->logger->debug('could not get login credentials because session is unavailable', ['app' => 'core']); |
|
103 | - } catch (InvalidTokenException $ex) { |
|
104 | - $this->logger->debug('could not get login credentials because the token is invalid', ['app' => 'core']); |
|
105 | - $trySession = true; |
|
106 | - } catch (PasswordlessTokenException $ex) { |
|
107 | - $this->logger->debug('could not get login credentials because the token has no password', ['app' => 'core']); |
|
108 | - $trySession = true; |
|
109 | - } |
|
110 | - |
|
111 | - if ($trySession && $this->session->exists('login_credentials')) { |
|
112 | - $creds = json_decode($this->session->get('login_credentials')); |
|
113 | - return new Credentials($creds->uid, $creds->uid, $creds->password); |
|
114 | - } |
|
115 | - |
|
116 | - // If we reach this line, an exception was thrown. |
|
117 | - throw new CredentialsUnavailableException(); |
|
118 | - } |
|
40 | + /** @var ISession */ |
|
41 | + private $session; |
|
42 | + |
|
43 | + /** @var ILogger */ |
|
44 | + private $logger; |
|
45 | + |
|
46 | + /** @var IProvider|null */ |
|
47 | + private $tokenProvider; |
|
48 | + |
|
49 | + /** |
|
50 | + * @param ISession $session |
|
51 | + * @param ILogger $logger |
|
52 | + * @param IProvider $tokenProvider |
|
53 | + */ |
|
54 | + public function __construct(ISession $session, ILogger $logger, IProvider $tokenProvider = null) { |
|
55 | + $this->session = $session; |
|
56 | + $this->logger = $logger; |
|
57 | + $this->tokenProvider = $tokenProvider; |
|
58 | + |
|
59 | + Util::connectHook('OC_User', 'post_login', $this, 'authenticate'); |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Hook listener on post login |
|
64 | + * |
|
65 | + * @param array $params |
|
66 | + */ |
|
67 | + public function authenticate(array $params) { |
|
68 | + $this->session->set('login_credentials', json_encode($params)); |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Replace the session implementation |
|
73 | + * |
|
74 | + * @param ISession $session |
|
75 | + */ |
|
76 | + public function setSession(ISession $session) { |
|
77 | + $this->session = $session; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * @since 12 |
|
82 | + * |
|
83 | + * @return ICredentials the login credentials of the current user |
|
84 | + * @throws CredentialsUnavailableException |
|
85 | + */ |
|
86 | + public function getLoginCredentials() { |
|
87 | + if (is_null($this->tokenProvider)) { |
|
88 | + throw new CredentialsUnavailableException(); |
|
89 | + } |
|
90 | + |
|
91 | + $trySession = false; |
|
92 | + try { |
|
93 | + $sessionId = $this->session->getId(); |
|
94 | + $token = $this->tokenProvider->getToken($sessionId); |
|
95 | + |
|
96 | + $uid = $token->getUID(); |
|
97 | + $user = $token->getLoginName(); |
|
98 | + $password = $this->tokenProvider->getPassword($token, $sessionId); |
|
99 | + |
|
100 | + return new Credentials($uid, $user, $password); |
|
101 | + } catch (SessionNotAvailableException $ex) { |
|
102 | + $this->logger->debug('could not get login credentials because session is unavailable', ['app' => 'core']); |
|
103 | + } catch (InvalidTokenException $ex) { |
|
104 | + $this->logger->debug('could not get login credentials because the token is invalid', ['app' => 'core']); |
|
105 | + $trySession = true; |
|
106 | + } catch (PasswordlessTokenException $ex) { |
|
107 | + $this->logger->debug('could not get login credentials because the token has no password', ['app' => 'core']); |
|
108 | + $trySession = true; |
|
109 | + } |
|
110 | + |
|
111 | + if ($trySession && $this->session->exists('login_credentials')) { |
|
112 | + $creds = json_decode($this->session->get('login_credentials')); |
|
113 | + return new Credentials($creds->uid, $creds->uid, $creds->password); |
|
114 | + } |
|
115 | + |
|
116 | + // If we reach this line, an exception was thrown. |
|
117 | + throw new CredentialsUnavailableException(); |
|
118 | + } |
|
119 | 119 | |
120 | 120 | } |
@@ -129,7 +129,7 @@ |
||
129 | 129 | $data = $result->fetchAll(); |
130 | 130 | $result->closeCursor(); |
131 | 131 | |
132 | - $entities = array_map(function ($row) { |
|
132 | + $entities = array_map(function($row) { |
|
133 | 133 | return DefaultToken::fromRow($row); |
134 | 134 | }, $data); |
135 | 135 |
@@ -36,136 +36,136 @@ |
||
36 | 36 | |
37 | 37 | class DefaultTokenMapper extends QBMapper { |
38 | 38 | |
39 | - public function __construct(IDBConnection $db) { |
|
40 | - parent::__construct($db, 'authtoken'); |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Invalidate (delete) a given token |
|
45 | - * |
|
46 | - * @param string $token |
|
47 | - */ |
|
48 | - public function invalidate(string $token) { |
|
49 | - /* @var $qb IQueryBuilder */ |
|
50 | - $qb = $this->db->getQueryBuilder(); |
|
51 | - $qb->delete('authtoken') |
|
52 | - ->where($qb->expr()->eq('token', $qb->createNamedParameter($token, IQueryBuilder::PARAM_STR))) |
|
53 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(DefaultToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
54 | - ->execute(); |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param int $olderThan |
|
59 | - * @param int $remember |
|
60 | - */ |
|
61 | - public function invalidateOld(int $olderThan, int $remember = IToken::DO_NOT_REMEMBER) { |
|
62 | - /* @var $qb IQueryBuilder */ |
|
63 | - $qb = $this->db->getQueryBuilder(); |
|
64 | - $qb->delete('authtoken') |
|
65 | - ->where($qb->expr()->lt('last_activity', $qb->createNamedParameter($olderThan, IQueryBuilder::PARAM_INT))) |
|
66 | - ->andWhere($qb->expr()->eq('type', $qb->createNamedParameter(IToken::TEMPORARY_TOKEN, IQueryBuilder::PARAM_INT))) |
|
67 | - ->andWhere($qb->expr()->eq('remember', $qb->createNamedParameter($remember, IQueryBuilder::PARAM_INT))) |
|
68 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(DefaultToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
69 | - ->execute(); |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Get the user UID for the given token |
|
74 | - * |
|
75 | - * @param string $token |
|
76 | - * @throws DoesNotExistException |
|
77 | - * @return DefaultToken |
|
78 | - */ |
|
79 | - public function getToken(string $token): DefaultToken { |
|
80 | - /* @var $qb IQueryBuilder */ |
|
81 | - $qb = $this->db->getQueryBuilder(); |
|
82 | - $result = $qb->select('id', 'uid', 'login_name', 'password', 'name', 'token', 'type', 'remember', 'last_activity', 'last_check', 'scope', 'expires', 'version') |
|
83 | - ->from('authtoken') |
|
84 | - ->where($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
85 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(DefaultToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
86 | - ->execute(); |
|
87 | - |
|
88 | - $data = $result->fetch(); |
|
89 | - $result->closeCursor(); |
|
90 | - if ($data === false) { |
|
91 | - throw new DoesNotExistException('token does not exist'); |
|
92 | - } |
|
93 | - return DefaultToken::fromRow($data); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Get the token for $id |
|
98 | - * |
|
99 | - * @param int $id |
|
100 | - * @throws DoesNotExistException |
|
101 | - * @return DefaultToken |
|
102 | - */ |
|
103 | - public function getTokenById(int $id): DefaultToken { |
|
104 | - /* @var $qb IQueryBuilder */ |
|
105 | - $qb = $this->db->getQueryBuilder(); |
|
106 | - $result = $qb->select('id', 'uid', 'login_name', 'password', 'name', 'token', 'type', 'remember', 'last_activity', 'last_check', 'scope', 'expires', 'version') |
|
107 | - ->from('authtoken') |
|
108 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
109 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(DefaultToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
110 | - ->execute(); |
|
111 | - |
|
112 | - $data = $result->fetch(); |
|
113 | - $result->closeCursor(); |
|
114 | - if ($data === false) { |
|
115 | - throw new DoesNotExistException('token does not exist'); |
|
116 | - } |
|
117 | - return DefaultToken::fromRow($data); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Get all tokens of a user |
|
122 | - * |
|
123 | - * The provider may limit the number of result rows in case of an abuse |
|
124 | - * where a high number of (session) tokens is generated |
|
125 | - * |
|
126 | - * @param string $uid |
|
127 | - * @return DefaultToken[] |
|
128 | - */ |
|
129 | - public function getTokenByUser(string $uid): array { |
|
130 | - /* @var $qb IQueryBuilder */ |
|
131 | - $qb = $this->db->getQueryBuilder(); |
|
132 | - $qb->select('id', 'uid', 'login_name', 'password', 'name', 'token', 'type', 'remember', 'last_activity', 'last_check', 'scope', 'expires', 'version') |
|
133 | - ->from('authtoken') |
|
134 | - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
135 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(DefaultToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
136 | - ->setMaxResults(1000); |
|
137 | - $result = $qb->execute(); |
|
138 | - $data = $result->fetchAll(); |
|
139 | - $result->closeCursor(); |
|
140 | - |
|
141 | - $entities = array_map(function ($row) { |
|
142 | - return DefaultToken::fromRow($row); |
|
143 | - }, $data); |
|
144 | - |
|
145 | - return $entities; |
|
146 | - } |
|
147 | - |
|
148 | - public function deleteById(string $uid, int $id) { |
|
149 | - /* @var $qb IQueryBuilder */ |
|
150 | - $qb = $this->db->getQueryBuilder(); |
|
151 | - $qb->delete('authtoken') |
|
152 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
153 | - ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
154 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(DefaultToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
155 | - $qb->execute(); |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * delete all auth token which belong to a specific client if the client was deleted |
|
160 | - * |
|
161 | - * @param string $name |
|
162 | - */ |
|
163 | - public function deleteByName(string $name) { |
|
164 | - $qb = $this->db->getQueryBuilder(); |
|
165 | - $qb->delete('authtoken') |
|
166 | - ->where($qb->expr()->eq('name', $qb->createNamedParameter($name), IQueryBuilder::PARAM_STR)) |
|
167 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(DefaultToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
168 | - $qb->execute(); |
|
169 | - } |
|
39 | + public function __construct(IDBConnection $db) { |
|
40 | + parent::__construct($db, 'authtoken'); |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Invalidate (delete) a given token |
|
45 | + * |
|
46 | + * @param string $token |
|
47 | + */ |
|
48 | + public function invalidate(string $token) { |
|
49 | + /* @var $qb IQueryBuilder */ |
|
50 | + $qb = $this->db->getQueryBuilder(); |
|
51 | + $qb->delete('authtoken') |
|
52 | + ->where($qb->expr()->eq('token', $qb->createNamedParameter($token, IQueryBuilder::PARAM_STR))) |
|
53 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(DefaultToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
54 | + ->execute(); |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param int $olderThan |
|
59 | + * @param int $remember |
|
60 | + */ |
|
61 | + public function invalidateOld(int $olderThan, int $remember = IToken::DO_NOT_REMEMBER) { |
|
62 | + /* @var $qb IQueryBuilder */ |
|
63 | + $qb = $this->db->getQueryBuilder(); |
|
64 | + $qb->delete('authtoken') |
|
65 | + ->where($qb->expr()->lt('last_activity', $qb->createNamedParameter($olderThan, IQueryBuilder::PARAM_INT))) |
|
66 | + ->andWhere($qb->expr()->eq('type', $qb->createNamedParameter(IToken::TEMPORARY_TOKEN, IQueryBuilder::PARAM_INT))) |
|
67 | + ->andWhere($qb->expr()->eq('remember', $qb->createNamedParameter($remember, IQueryBuilder::PARAM_INT))) |
|
68 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(DefaultToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
69 | + ->execute(); |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Get the user UID for the given token |
|
74 | + * |
|
75 | + * @param string $token |
|
76 | + * @throws DoesNotExistException |
|
77 | + * @return DefaultToken |
|
78 | + */ |
|
79 | + public function getToken(string $token): DefaultToken { |
|
80 | + /* @var $qb IQueryBuilder */ |
|
81 | + $qb = $this->db->getQueryBuilder(); |
|
82 | + $result = $qb->select('id', 'uid', 'login_name', 'password', 'name', 'token', 'type', 'remember', 'last_activity', 'last_check', 'scope', 'expires', 'version') |
|
83 | + ->from('authtoken') |
|
84 | + ->where($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
85 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(DefaultToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
86 | + ->execute(); |
|
87 | + |
|
88 | + $data = $result->fetch(); |
|
89 | + $result->closeCursor(); |
|
90 | + if ($data === false) { |
|
91 | + throw new DoesNotExistException('token does not exist'); |
|
92 | + } |
|
93 | + return DefaultToken::fromRow($data); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Get the token for $id |
|
98 | + * |
|
99 | + * @param int $id |
|
100 | + * @throws DoesNotExistException |
|
101 | + * @return DefaultToken |
|
102 | + */ |
|
103 | + public function getTokenById(int $id): DefaultToken { |
|
104 | + /* @var $qb IQueryBuilder */ |
|
105 | + $qb = $this->db->getQueryBuilder(); |
|
106 | + $result = $qb->select('id', 'uid', 'login_name', 'password', 'name', 'token', 'type', 'remember', 'last_activity', 'last_check', 'scope', 'expires', 'version') |
|
107 | + ->from('authtoken') |
|
108 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
109 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(DefaultToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
110 | + ->execute(); |
|
111 | + |
|
112 | + $data = $result->fetch(); |
|
113 | + $result->closeCursor(); |
|
114 | + if ($data === false) { |
|
115 | + throw new DoesNotExistException('token does not exist'); |
|
116 | + } |
|
117 | + return DefaultToken::fromRow($data); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Get all tokens of a user |
|
122 | + * |
|
123 | + * The provider may limit the number of result rows in case of an abuse |
|
124 | + * where a high number of (session) tokens is generated |
|
125 | + * |
|
126 | + * @param string $uid |
|
127 | + * @return DefaultToken[] |
|
128 | + */ |
|
129 | + public function getTokenByUser(string $uid): array { |
|
130 | + /* @var $qb IQueryBuilder */ |
|
131 | + $qb = $this->db->getQueryBuilder(); |
|
132 | + $qb->select('id', 'uid', 'login_name', 'password', 'name', 'token', 'type', 'remember', 'last_activity', 'last_check', 'scope', 'expires', 'version') |
|
133 | + ->from('authtoken') |
|
134 | + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
135 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(DefaultToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
136 | + ->setMaxResults(1000); |
|
137 | + $result = $qb->execute(); |
|
138 | + $data = $result->fetchAll(); |
|
139 | + $result->closeCursor(); |
|
140 | + |
|
141 | + $entities = array_map(function ($row) { |
|
142 | + return DefaultToken::fromRow($row); |
|
143 | + }, $data); |
|
144 | + |
|
145 | + return $entities; |
|
146 | + } |
|
147 | + |
|
148 | + public function deleteById(string $uid, int $id) { |
|
149 | + /* @var $qb IQueryBuilder */ |
|
150 | + $qb = $this->db->getQueryBuilder(); |
|
151 | + $qb->delete('authtoken') |
|
152 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
153 | + ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
154 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(DefaultToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
155 | + $qb->execute(); |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * delete all auth token which belong to a specific client if the client was deleted |
|
160 | + * |
|
161 | + * @param string $name |
|
162 | + */ |
|
163 | + public function deleteByName(string $name) { |
|
164 | + $qb = $this->db->getQueryBuilder(); |
|
165 | + $qb->delete('authtoken') |
|
166 | + ->where($qb->expr()->eq('name', $qb->createNamedParameter($name), IQueryBuilder::PARAM_STR)) |
|
167 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(DefaultToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
168 | + $qb->execute(); |
|
169 | + } |
|
170 | 170 | |
171 | 171 | } |
@@ -103,6 +103,6 @@ |
||
103 | 103 | $time = new \DateTime('now', $timeZone); |
104 | 104 | $timestampInfo = $time->format($this->config->getSystemValue('logdateformat', \DateTime::ATOM)); |
105 | 105 | |
106 | - return $timestampInfo . ' ' . $this->formatter->format($message); |
|
106 | + return $timestampInfo.' '.$this->formatter->format($message); |
|
107 | 107 | } |
108 | 108 | } |
@@ -28,85 +28,85 @@ |
||
28 | 28 | use Symfony\Component\Console\Formatter\OutputFormatterStyleInterface; |
29 | 29 | |
30 | 30 | class TimestampFormatter implements OutputFormatterInterface { |
31 | - /** @var IConfig */ |
|
32 | - protected $config; |
|
31 | + /** @var IConfig */ |
|
32 | + protected $config; |
|
33 | 33 | |
34 | - /** @var OutputFormatterInterface */ |
|
35 | - protected $formatter; |
|
34 | + /** @var OutputFormatterInterface */ |
|
35 | + protected $formatter; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param IConfig $config |
|
39 | - * @param OutputFormatterInterface $formatter |
|
40 | - */ |
|
41 | - public function __construct(IConfig $config, OutputFormatterInterface $formatter) { |
|
42 | - $this->config = $config; |
|
43 | - $this->formatter = $formatter; |
|
44 | - } |
|
37 | + /** |
|
38 | + * @param IConfig $config |
|
39 | + * @param OutputFormatterInterface $formatter |
|
40 | + */ |
|
41 | + public function __construct(IConfig $config, OutputFormatterInterface $formatter) { |
|
42 | + $this->config = $config; |
|
43 | + $this->formatter = $formatter; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Sets the decorated flag. |
|
48 | - * |
|
49 | - * @param bool $decorated Whether to decorate the messages or not |
|
50 | - */ |
|
51 | - public function setDecorated($decorated) { |
|
52 | - $this->formatter->setDecorated($decorated); |
|
53 | - } |
|
46 | + /** |
|
47 | + * Sets the decorated flag. |
|
48 | + * |
|
49 | + * @param bool $decorated Whether to decorate the messages or not |
|
50 | + */ |
|
51 | + public function setDecorated($decorated) { |
|
52 | + $this->formatter->setDecorated($decorated); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Gets the decorated flag. |
|
57 | - * |
|
58 | - * @return bool true if the output will decorate messages, false otherwise |
|
59 | - */ |
|
60 | - public function isDecorated() { |
|
61 | - return $this->formatter->isDecorated(); |
|
62 | - } |
|
55 | + /** |
|
56 | + * Gets the decorated flag. |
|
57 | + * |
|
58 | + * @return bool true if the output will decorate messages, false otherwise |
|
59 | + */ |
|
60 | + public function isDecorated() { |
|
61 | + return $this->formatter->isDecorated(); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Sets a new style. |
|
66 | - * |
|
67 | - * @param string $name The style name |
|
68 | - * @param OutputFormatterStyleInterface $style The style instance |
|
69 | - */ |
|
70 | - public function setStyle($name, OutputFormatterStyleInterface $style) { |
|
71 | - $this->formatter->setStyle($name, $style); |
|
72 | - } |
|
64 | + /** |
|
65 | + * Sets a new style. |
|
66 | + * |
|
67 | + * @param string $name The style name |
|
68 | + * @param OutputFormatterStyleInterface $style The style instance |
|
69 | + */ |
|
70 | + public function setStyle($name, OutputFormatterStyleInterface $style) { |
|
71 | + $this->formatter->setStyle($name, $style); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Checks if output formatter has style with specified name. |
|
76 | - * |
|
77 | - * @param string $name |
|
78 | - * @return bool |
|
79 | - */ |
|
80 | - public function hasStyle($name) { |
|
81 | - return $this->formatter->hasStyle($name); |
|
82 | - } |
|
74 | + /** |
|
75 | + * Checks if output formatter has style with specified name. |
|
76 | + * |
|
77 | + * @param string $name |
|
78 | + * @return bool |
|
79 | + */ |
|
80 | + public function hasStyle($name) { |
|
81 | + return $this->formatter->hasStyle($name); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * Gets style options from style with specified name. |
|
86 | - * |
|
87 | - * @param string $name |
|
88 | - * @return OutputFormatterStyleInterface |
|
89 | - * @throws \InvalidArgumentException When style isn't defined |
|
90 | - */ |
|
91 | - public function getStyle($name) { |
|
92 | - return $this->formatter->getStyle($name); |
|
93 | - } |
|
84 | + /** |
|
85 | + * Gets style options from style with specified name. |
|
86 | + * |
|
87 | + * @param string $name |
|
88 | + * @return OutputFormatterStyleInterface |
|
89 | + * @throws \InvalidArgumentException When style isn't defined |
|
90 | + */ |
|
91 | + public function getStyle($name) { |
|
92 | + return $this->formatter->getStyle($name); |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Formats a message according to the given styles. |
|
97 | - * |
|
98 | - * @param string $message The message to style |
|
99 | - * @return string The styled message, prepended with a timestamp using the |
|
100 | - * log timezone and dateformat, e.g. "2015-06-23T17:24:37+02:00" |
|
101 | - */ |
|
102 | - public function format($message) { |
|
95 | + /** |
|
96 | + * Formats a message according to the given styles. |
|
97 | + * |
|
98 | + * @param string $message The message to style |
|
99 | + * @return string The styled message, prepended with a timestamp using the |
|
100 | + * log timezone and dateformat, e.g. "2015-06-23T17:24:37+02:00" |
|
101 | + */ |
|
102 | + public function format($message) { |
|
103 | 103 | |
104 | - $timeZone = $this->config->getSystemValue('logtimezone', 'UTC'); |
|
105 | - $timeZone = $timeZone !== null ? new \DateTimeZone($timeZone) : null; |
|
104 | + $timeZone = $this->config->getSystemValue('logtimezone', 'UTC'); |
|
105 | + $timeZone = $timeZone !== null ? new \DateTimeZone($timeZone) : null; |
|
106 | 106 | |
107 | - $time = new \DateTime('now', $timeZone); |
|
108 | - $timestampInfo = $time->format($this->config->getSystemValue('logdateformat', \DateTime::ATOM)); |
|
107 | + $time = new \DateTime('now', $timeZone); |
|
108 | + $timestampInfo = $time->format($this->config->getSystemValue('logdateformat', \DateTime::ATOM)); |
|
109 | 109 | |
110 | - return $timestampInfo . ' ' . $this->formatter->format($message); |
|
111 | - } |
|
110 | + return $timestampInfo . ' ' . $this->formatter->format($message); |
|
111 | + } |
|
112 | 112 | } |
@@ -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,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 | } |