@@ -25,12 +25,12 @@ |
||
25 | 25 | use OCP\IUser; |
26 | 26 | |
27 | 27 | trait FileAccess { |
28 | - protected function setupFS(IUser $user) { |
|
29 | - \OC_Util::setupFS($user->getUID()); |
|
30 | - } |
|
28 | + protected function setupFS(IUser $user) { |
|
29 | + \OC_Util::setupFS($user->getUID()); |
|
30 | + } |
|
31 | 31 | |
32 | - protected function getUserFolder(IUser $user) { |
|
33 | - $this->setupFS($user); |
|
34 | - return \OC::$server->getUserFolder($user->getUID()); |
|
35 | - } |
|
32 | + protected function getUserFolder(IUser $user) { |
|
33 | + $this->setupFS($user); |
|
34 | + return \OC::$server->getUserFolder($user->getUID()); |
|
35 | + } |
|
36 | 36 | } |
@@ -29,140 +29,140 @@ |
||
29 | 29 | |
30 | 30 | class Entry implements IEntry { |
31 | 31 | |
32 | - /** @var string|int|null */ |
|
33 | - private $id = null; |
|
34 | - |
|
35 | - /** @var string */ |
|
36 | - private $fullName = ''; |
|
37 | - |
|
38 | - /** @var string[] */ |
|
39 | - private $emailAddresses = []; |
|
40 | - |
|
41 | - /** @var string|null */ |
|
42 | - private $avatar; |
|
43 | - |
|
44 | - /** @var IAction[] */ |
|
45 | - private $actions = []; |
|
46 | - |
|
47 | - /** @var array */ |
|
48 | - private $properties = []; |
|
49 | - |
|
50 | - /** |
|
51 | - * @param string $id |
|
52 | - */ |
|
53 | - public function setId($id) { |
|
54 | - $this->id = $id; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param string $displayName |
|
59 | - */ |
|
60 | - public function setFullName($displayName) { |
|
61 | - $this->fullName = $displayName; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function getFullName() { |
|
68 | - return $this->fullName; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @param string $address |
|
73 | - */ |
|
74 | - public function addEMailAddress($address) { |
|
75 | - $this->emailAddresses[] = $address; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - public function getEMailAddresses() { |
|
82 | - return $this->emailAddresses; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * @param string $avatar |
|
87 | - */ |
|
88 | - public function setAvatar($avatar) { |
|
89 | - $this->avatar = $avatar; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - public function getAvatar() { |
|
96 | - return $this->avatar; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * @param IAction $action |
|
101 | - */ |
|
102 | - public function addAction(IAction $action) { |
|
103 | - $this->actions[] = $action; |
|
104 | - $this->sortActions(); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @return IAction[] |
|
109 | - */ |
|
110 | - public function getActions() { |
|
111 | - return $this->actions; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * sort the actions by priority and name |
|
116 | - */ |
|
117 | - private function sortActions() { |
|
118 | - usort($this->actions, function (IAction $action1, IAction $action2) { |
|
119 | - $prio1 = $action1->getPriority(); |
|
120 | - $prio2 = $action2->getPriority(); |
|
121 | - |
|
122 | - if ($prio1 === $prio2) { |
|
123 | - // Ascending order for same priority |
|
124 | - return strcasecmp($action1->getName(), $action2->getName()); |
|
125 | - } |
|
126 | - |
|
127 | - // Descending order when priority differs |
|
128 | - return $prio2 - $prio1; |
|
129 | - }); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * @param array $contact key-value array containing additional properties |
|
134 | - */ |
|
135 | - public function setProperties(array $contact) { |
|
136 | - $this->properties = $contact; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @param string $key |
|
141 | - * @return mixed |
|
142 | - */ |
|
143 | - public function getProperty($key) { |
|
144 | - if (!isset($this->properties[$key])) { |
|
145 | - return null; |
|
146 | - } |
|
147 | - return $this->properties[$key]; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @return array |
|
152 | - */ |
|
153 | - public function jsonSerialize() { |
|
154 | - $topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null; |
|
155 | - $otherActions = array_map(function (IAction $action) { |
|
156 | - return $action->jsonSerialize(); |
|
157 | - }, array_slice($this->actions, 1)); |
|
158 | - |
|
159 | - return [ |
|
160 | - 'id' => $this->id, |
|
161 | - 'fullName' => $this->fullName, |
|
162 | - 'avatar' => $this->getAvatar(), |
|
163 | - 'topAction' => $topAction, |
|
164 | - 'actions' => $otherActions, |
|
165 | - 'lastMessage' => '', |
|
166 | - ]; |
|
167 | - } |
|
32 | + /** @var string|int|null */ |
|
33 | + private $id = null; |
|
34 | + |
|
35 | + /** @var string */ |
|
36 | + private $fullName = ''; |
|
37 | + |
|
38 | + /** @var string[] */ |
|
39 | + private $emailAddresses = []; |
|
40 | + |
|
41 | + /** @var string|null */ |
|
42 | + private $avatar; |
|
43 | + |
|
44 | + /** @var IAction[] */ |
|
45 | + private $actions = []; |
|
46 | + |
|
47 | + /** @var array */ |
|
48 | + private $properties = []; |
|
49 | + |
|
50 | + /** |
|
51 | + * @param string $id |
|
52 | + */ |
|
53 | + public function setId($id) { |
|
54 | + $this->id = $id; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param string $displayName |
|
59 | + */ |
|
60 | + public function setFullName($displayName) { |
|
61 | + $this->fullName = $displayName; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function getFullName() { |
|
68 | + return $this->fullName; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @param string $address |
|
73 | + */ |
|
74 | + public function addEMailAddress($address) { |
|
75 | + $this->emailAddresses[] = $address; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * @return string |
|
80 | + */ |
|
81 | + public function getEMailAddresses() { |
|
82 | + return $this->emailAddresses; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * @param string $avatar |
|
87 | + */ |
|
88 | + public function setAvatar($avatar) { |
|
89 | + $this->avatar = $avatar; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * @return string |
|
94 | + */ |
|
95 | + public function getAvatar() { |
|
96 | + return $this->avatar; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * @param IAction $action |
|
101 | + */ |
|
102 | + public function addAction(IAction $action) { |
|
103 | + $this->actions[] = $action; |
|
104 | + $this->sortActions(); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @return IAction[] |
|
109 | + */ |
|
110 | + public function getActions() { |
|
111 | + return $this->actions; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * sort the actions by priority and name |
|
116 | + */ |
|
117 | + private function sortActions() { |
|
118 | + usort($this->actions, function (IAction $action1, IAction $action2) { |
|
119 | + $prio1 = $action1->getPriority(); |
|
120 | + $prio2 = $action2->getPriority(); |
|
121 | + |
|
122 | + if ($prio1 === $prio2) { |
|
123 | + // Ascending order for same priority |
|
124 | + return strcasecmp($action1->getName(), $action2->getName()); |
|
125 | + } |
|
126 | + |
|
127 | + // Descending order when priority differs |
|
128 | + return $prio2 - $prio1; |
|
129 | + }); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * @param array $contact key-value array containing additional properties |
|
134 | + */ |
|
135 | + public function setProperties(array $contact) { |
|
136 | + $this->properties = $contact; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @param string $key |
|
141 | + * @return mixed |
|
142 | + */ |
|
143 | + public function getProperty($key) { |
|
144 | + if (!isset($this->properties[$key])) { |
|
145 | + return null; |
|
146 | + } |
|
147 | + return $this->properties[$key]; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @return array |
|
152 | + */ |
|
153 | + public function jsonSerialize() { |
|
154 | + $topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null; |
|
155 | + $otherActions = array_map(function (IAction $action) { |
|
156 | + return $action->jsonSerialize(); |
|
157 | + }, array_slice($this->actions, 1)); |
|
158 | + |
|
159 | + return [ |
|
160 | + 'id' => $this->id, |
|
161 | + 'fullName' => $this->fullName, |
|
162 | + 'avatar' => $this->getAvatar(), |
|
163 | + 'topAction' => $topAction, |
|
164 | + 'actions' => $otherActions, |
|
165 | + 'lastMessage' => '', |
|
166 | + ]; |
|
167 | + } |
|
168 | 168 | } |
@@ -35,79 +35,79 @@ |
||
35 | 35 | |
36 | 36 | class ActionProviderStore { |
37 | 37 | |
38 | - /** @var IServerContainer */ |
|
39 | - private $serverContainer; |
|
40 | - |
|
41 | - /** @var AppManager */ |
|
42 | - private $appManager; |
|
43 | - |
|
44 | - /** @var ILogger */ |
|
45 | - private $logger; |
|
46 | - |
|
47 | - /** |
|
48 | - * @param IServerContainer $serverContainer |
|
49 | - * @param AppManager $appManager |
|
50 | - * @param ILogger $logger |
|
51 | - */ |
|
52 | - public function __construct(IServerContainer $serverContainer, AppManager $appManager, ILogger $logger) { |
|
53 | - $this->serverContainer = $serverContainer; |
|
54 | - $this->appManager = $appManager; |
|
55 | - $this->logger = $logger; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @param IUser $user |
|
60 | - * @return IProvider[] |
|
61 | - * @throws Exception |
|
62 | - */ |
|
63 | - public function getProviders(IUser $user) { |
|
64 | - $appClasses = $this->getAppProviderClasses($user); |
|
65 | - $providerClasses = $this->getServerProviderClasses(); |
|
66 | - $allClasses = array_merge($providerClasses, $appClasses); |
|
67 | - $providers = []; |
|
68 | - |
|
69 | - foreach ($allClasses as $class) { |
|
70 | - try { |
|
71 | - $providers[] = $this->serverContainer->query($class); |
|
72 | - } catch (QueryException $ex) { |
|
73 | - $this->logger->logException($ex, [ |
|
74 | - 'message' => "Could not load contacts menu action provider $class", |
|
75 | - 'app' => 'core', |
|
76 | - ]); |
|
77 | - throw new Exception("Could not load contacts menu action provider"); |
|
78 | - } |
|
79 | - } |
|
80 | - |
|
81 | - return $providers; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * @return string[] |
|
86 | - */ |
|
87 | - private function getServerProviderClasses() { |
|
88 | - return [ |
|
89 | - EMailProvider::class, |
|
90 | - ]; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @param IUser $user |
|
95 | - * @return string[] |
|
96 | - */ |
|
97 | - private function getAppProviderClasses(IUser $user) { |
|
98 | - return array_reduce($this->appManager->getEnabledAppsForUser($user), function ($all, $appId) { |
|
99 | - $info = $this->appManager->getAppInfo($appId); |
|
100 | - |
|
101 | - if (!isset($info['contactsmenu']) || !isset($info['contactsmenu'])) { |
|
102 | - // Nothing to add |
|
103 | - return $all; |
|
104 | - } |
|
105 | - |
|
106 | - $providers = array_reduce($info['contactsmenu'], function ($all, $provider) { |
|
107 | - return array_merge($all, [$provider]); |
|
108 | - }, []); |
|
109 | - |
|
110 | - return array_merge($all, $providers); |
|
111 | - }, []); |
|
112 | - } |
|
38 | + /** @var IServerContainer */ |
|
39 | + private $serverContainer; |
|
40 | + |
|
41 | + /** @var AppManager */ |
|
42 | + private $appManager; |
|
43 | + |
|
44 | + /** @var ILogger */ |
|
45 | + private $logger; |
|
46 | + |
|
47 | + /** |
|
48 | + * @param IServerContainer $serverContainer |
|
49 | + * @param AppManager $appManager |
|
50 | + * @param ILogger $logger |
|
51 | + */ |
|
52 | + public function __construct(IServerContainer $serverContainer, AppManager $appManager, ILogger $logger) { |
|
53 | + $this->serverContainer = $serverContainer; |
|
54 | + $this->appManager = $appManager; |
|
55 | + $this->logger = $logger; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @param IUser $user |
|
60 | + * @return IProvider[] |
|
61 | + * @throws Exception |
|
62 | + */ |
|
63 | + public function getProviders(IUser $user) { |
|
64 | + $appClasses = $this->getAppProviderClasses($user); |
|
65 | + $providerClasses = $this->getServerProviderClasses(); |
|
66 | + $allClasses = array_merge($providerClasses, $appClasses); |
|
67 | + $providers = []; |
|
68 | + |
|
69 | + foreach ($allClasses as $class) { |
|
70 | + try { |
|
71 | + $providers[] = $this->serverContainer->query($class); |
|
72 | + } catch (QueryException $ex) { |
|
73 | + $this->logger->logException($ex, [ |
|
74 | + 'message' => "Could not load contacts menu action provider $class", |
|
75 | + 'app' => 'core', |
|
76 | + ]); |
|
77 | + throw new Exception("Could not load contacts menu action provider"); |
|
78 | + } |
|
79 | + } |
|
80 | + |
|
81 | + return $providers; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * @return string[] |
|
86 | + */ |
|
87 | + private function getServerProviderClasses() { |
|
88 | + return [ |
|
89 | + EMailProvider::class, |
|
90 | + ]; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @param IUser $user |
|
95 | + * @return string[] |
|
96 | + */ |
|
97 | + private function getAppProviderClasses(IUser $user) { |
|
98 | + return array_reduce($this->appManager->getEnabledAppsForUser($user), function ($all, $appId) { |
|
99 | + $info = $this->appManager->getAppInfo($appId); |
|
100 | + |
|
101 | + if (!isset($info['contactsmenu']) || !isset($info['contactsmenu'])) { |
|
102 | + // Nothing to add |
|
103 | + return $all; |
|
104 | + } |
|
105 | + |
|
106 | + $providers = array_reduce($info['contactsmenu'], function ($all, $provider) { |
|
107 | + return array_merge($all, [$provider]); |
|
108 | + }, []); |
|
109 | + |
|
110 | + return array_merge($all, $providers); |
|
111 | + }, []); |
|
112 | + } |
|
113 | 113 | } |
@@ -31,35 +31,35 @@ |
||
31 | 31 | */ |
32 | 32 | class DeleteOrphanedSharesJob extends TimedJob { |
33 | 33 | |
34 | - /** |
|
35 | - * Default interval in minutes |
|
36 | - * |
|
37 | - * @var int $defaultIntervalMin |
|
38 | - **/ |
|
39 | - protected $defaultIntervalMin = 15; |
|
34 | + /** |
|
35 | + * Default interval in minutes |
|
36 | + * |
|
37 | + * @var int $defaultIntervalMin |
|
38 | + **/ |
|
39 | + protected $defaultIntervalMin = 15; |
|
40 | 40 | |
41 | - /** |
|
42 | - * sets the correct interval for this timed job |
|
43 | - */ |
|
44 | - public function __construct() { |
|
45 | - $this->interval = $this->defaultIntervalMin * 60; |
|
46 | - } |
|
41 | + /** |
|
42 | + * sets the correct interval for this timed job |
|
43 | + */ |
|
44 | + public function __construct() { |
|
45 | + $this->interval = $this->defaultIntervalMin * 60; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * Makes the background job do its work |
|
50 | - * |
|
51 | - * @param array $argument unused argument |
|
52 | - */ |
|
53 | - public function run($argument) { |
|
54 | - $connection = \OC::$server->getDatabaseConnection(); |
|
55 | - $logger = \OC::$server->getLogger(); |
|
48 | + /** |
|
49 | + * Makes the background job do its work |
|
50 | + * |
|
51 | + * @param array $argument unused argument |
|
52 | + */ |
|
53 | + public function run($argument) { |
|
54 | + $connection = \OC::$server->getDatabaseConnection(); |
|
55 | + $logger = \OC::$server->getLogger(); |
|
56 | 56 | |
57 | - $sql = |
|
58 | - 'DELETE FROM `*PREFIX*share` ' . |
|
59 | - 'WHERE `item_type` in (\'file\', \'folder\') ' . |
|
60 | - 'AND NOT EXISTS (SELECT `fileid` FROM `*PREFIX*filecache` WHERE `file_source` = `fileid`)'; |
|
57 | + $sql = |
|
58 | + 'DELETE FROM `*PREFIX*share` ' . |
|
59 | + 'WHERE `item_type` in (\'file\', \'folder\') ' . |
|
60 | + 'AND NOT EXISTS (SELECT `fileid` FROM `*PREFIX*filecache` WHERE `file_source` = `fileid`)'; |
|
61 | 61 | |
62 | - $deletedEntries = $connection->executeUpdate($sql); |
|
63 | - $logger->debug("$deletedEntries orphaned share(s) deleted", ['app' => 'DeleteOrphanedSharesJob']); |
|
64 | - } |
|
62 | + $deletedEntries = $connection->executeUpdate($sql); |
|
63 | + $logger->debug("$deletedEntries orphaned share(s) deleted", ['app' => 'DeleteOrphanedSharesJob']); |
|
64 | + } |
|
65 | 65 | } |
@@ -26,66 +26,66 @@ |
||
26 | 26 | |
27 | 27 | class RequestURL extends AbstractStringCheck { |
28 | 28 | |
29 | - /** @var string */ |
|
30 | - protected $url; |
|
29 | + /** @var string */ |
|
30 | + protected $url; |
|
31 | 31 | |
32 | - /** @var IRequest */ |
|
33 | - protected $request; |
|
32 | + /** @var IRequest */ |
|
33 | + protected $request; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param IL10N $l |
|
37 | - * @param IRequest $request |
|
38 | - */ |
|
39 | - public function __construct(IL10N $l, IRequest $request) { |
|
40 | - parent::__construct($l); |
|
41 | - $this->request = $request; |
|
42 | - } |
|
35 | + /** |
|
36 | + * @param IL10N $l |
|
37 | + * @param IRequest $request |
|
38 | + */ |
|
39 | + public function __construct(IL10N $l, IRequest $request) { |
|
40 | + parent::__construct($l); |
|
41 | + $this->request = $request; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param string $operator |
|
46 | - * @param string $value |
|
47 | - * @return bool |
|
48 | - */ |
|
49 | - public function executeCheck($operator, $value) { |
|
50 | - $actualValue = $this->getActualValue(); |
|
51 | - if (in_array($operator, ['is', '!is'])) { |
|
52 | - switch ($value) { |
|
53 | - case 'webdav': |
|
54 | - if ($operator === 'is') { |
|
55 | - return $this->isWebDAVRequest(); |
|
56 | - } else { |
|
57 | - return !$this->isWebDAVRequest(); |
|
58 | - } |
|
59 | - } |
|
60 | - } |
|
61 | - return $this->executeStringCheck($operator, $value, $actualValue); |
|
62 | - } |
|
44 | + /** |
|
45 | + * @param string $operator |
|
46 | + * @param string $value |
|
47 | + * @return bool |
|
48 | + */ |
|
49 | + public function executeCheck($operator, $value) { |
|
50 | + $actualValue = $this->getActualValue(); |
|
51 | + if (in_array($operator, ['is', '!is'])) { |
|
52 | + switch ($value) { |
|
53 | + case 'webdav': |
|
54 | + if ($operator === 'is') { |
|
55 | + return $this->isWebDAVRequest(); |
|
56 | + } else { |
|
57 | + return !$this->isWebDAVRequest(); |
|
58 | + } |
|
59 | + } |
|
60 | + } |
|
61 | + return $this->executeStringCheck($operator, $value, $actualValue); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - protected function getActualValue() { |
|
68 | - if ($this->url !== null) { |
|
69 | - return $this->url; |
|
70 | - } |
|
64 | + /** |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + protected function getActualValue() { |
|
68 | + if ($this->url !== null) { |
|
69 | + return $this->url; |
|
70 | + } |
|
71 | 71 | |
72 | - $this->url = $this->request->getServerProtocol() . '://';// E.g. http(s) + :// |
|
73 | - $this->url .= $this->request->getServerHost();// E.g. localhost |
|
74 | - $this->url .= $this->request->getScriptName();// E.g. /nextcloud/index.php |
|
75 | - $this->url .= $this->request->getPathInfo();// E.g. /apps/files_texteditor/ajax/loadfile |
|
72 | + $this->url = $this->request->getServerProtocol() . '://';// E.g. http(s) + :// |
|
73 | + $this->url .= $this->request->getServerHost();// E.g. localhost |
|
74 | + $this->url .= $this->request->getScriptName();// E.g. /nextcloud/index.php |
|
75 | + $this->url .= $this->request->getPathInfo();// E.g. /apps/files_texteditor/ajax/loadfile |
|
76 | 76 | |
77 | - return $this->url; // E.g. https://localhost/nextcloud/index.php/apps/files_texteditor/ajax/loadfile |
|
78 | - } |
|
77 | + return $this->url; // E.g. https://localhost/nextcloud/index.php/apps/files_texteditor/ajax/loadfile |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @return bool |
|
82 | - */ |
|
83 | - protected function isWebDAVRequest() { |
|
84 | - return substr($this->request->getScriptName(), 0 - strlen('/remote.php')) === '/remote.php' && ( |
|
85 | - $this->request->getPathInfo() === '/webdav' || |
|
86 | - strpos($this->request->getPathInfo(), '/webdav/') === 0 || |
|
87 | - $this->request->getPathInfo() === '/dav/files' || |
|
88 | - strpos($this->request->getPathInfo(), '/dav/files/') === 0 |
|
89 | - ); |
|
90 | - } |
|
80 | + /** |
|
81 | + * @return bool |
|
82 | + */ |
|
83 | + protected function isWebDAVRequest() { |
|
84 | + return substr($this->request->getScriptName(), 0 - strlen('/remote.php')) === '/remote.php' && ( |
|
85 | + $this->request->getPathInfo() === '/webdav' || |
|
86 | + strpos($this->request->getPathInfo(), '/webdav/') === 0 || |
|
87 | + $this->request->getPathInfo() === '/dav/files' || |
|
88 | + strpos($this->request->getPathInfo(), '/dav/files/') === 0 |
|
89 | + ); |
|
90 | + } |
|
91 | 91 | } |
@@ -28,35 +28,35 @@ |
||
28 | 28 | use Symfony\Component\Console\Output\OutputInterface; |
29 | 29 | |
30 | 30 | class Check extends Base { |
31 | - /** |
|
32 | - * @var SystemConfig |
|
33 | - */ |
|
34 | - private $config; |
|
31 | + /** |
|
32 | + * @var SystemConfig |
|
33 | + */ |
|
34 | + private $config; |
|
35 | 35 | |
36 | - public function __construct(SystemConfig $config) { |
|
37 | - parent::__construct(); |
|
38 | - $this->config = $config; |
|
39 | - } |
|
36 | + public function __construct(SystemConfig $config) { |
|
37 | + parent::__construct(); |
|
38 | + $this->config = $config; |
|
39 | + } |
|
40 | 40 | |
41 | - protected function configure() { |
|
42 | - parent::configure(); |
|
41 | + protected function configure() { |
|
42 | + parent::configure(); |
|
43 | 43 | |
44 | - $this |
|
45 | - ->setName('check') |
|
46 | - ->setDescription('check dependencies of the server environment') |
|
47 | - ; |
|
48 | - } |
|
44 | + $this |
|
45 | + ->setName('check') |
|
46 | + ->setDescription('check dependencies of the server environment') |
|
47 | + ; |
|
48 | + } |
|
49 | 49 | |
50 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
51 | - $errors = \OC_Util::checkServer($this->config); |
|
52 | - if (!empty($errors)) { |
|
53 | - $errors = array_map(function ($item) { |
|
54 | - return (string) $item['error']; |
|
55 | - }, $errors); |
|
50 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
51 | + $errors = \OC_Util::checkServer($this->config); |
|
52 | + if (!empty($errors)) { |
|
53 | + $errors = array_map(function ($item) { |
|
54 | + return (string) $item['error']; |
|
55 | + }, $errors); |
|
56 | 56 | |
57 | - $this->writeArrayInOutputFormat($input, $output, $errors); |
|
58 | - return 1; |
|
59 | - } |
|
60 | - return 0; |
|
61 | - } |
|
57 | + $this->writeArrayInOutputFormat($input, $output, $errors); |
|
58 | + return 1; |
|
59 | + } |
|
60 | + return 0; |
|
61 | + } |
|
62 | 62 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | use Symfony\Component\EventDispatcher\GenericEvent; |
36 | 36 | |
37 | 37 | if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
38 | - @set_time_limit(0); |
|
38 | + @set_time_limit(0); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | require_once '../../lib/base.php'; |
@@ -49,190 +49,190 @@ discard block |
||
49 | 49 | $eventSource->send('success', (string)$l->t('Preparing update')); |
50 | 50 | |
51 | 51 | class FeedBackHandler { |
52 | - /** @var integer */ |
|
53 | - private $progressStateMax = 100; |
|
54 | - /** @var integer */ |
|
55 | - private $progressStateStep = 0; |
|
56 | - /** @var string */ |
|
57 | - private $currentStep; |
|
58 | - /** @var \OCP\IEventSource */ |
|
59 | - private $eventSource; |
|
60 | - /** @var \OCP\IL10N */ |
|
61 | - private $l10n; |
|
62 | - |
|
63 | - public function __construct(\OCP\IEventSource $eventSource, \OCP\IL10N $l10n) { |
|
64 | - $this->eventSource = $eventSource; |
|
65 | - $this->l10n = $l10n; |
|
66 | - } |
|
67 | - |
|
68 | - public function handleRepairFeedback($event) { |
|
69 | - if (!$event instanceof GenericEvent) { |
|
70 | - return; |
|
71 | - } |
|
72 | - |
|
73 | - switch ($event->getSubject()) { |
|
74 | - case '\OC\Repair::startProgress': |
|
75 | - $this->progressStateMax = $event->getArgument(0); |
|
76 | - $this->progressStateStep = 0; |
|
77 | - $this->currentStep = $event->getArgument(1); |
|
78 | - break; |
|
79 | - case '\OC\Repair::advance': |
|
80 | - $this->progressStateStep += $event->getArgument(0); |
|
81 | - $desc = $event->getArgument(1); |
|
82 | - if (empty($desc)) { |
|
83 | - $desc = $this->currentStep; |
|
84 | - } |
|
85 | - $this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $desc])); |
|
86 | - break; |
|
87 | - case '\OC\Repair::finishProgress': |
|
88 | - $this->progressStateMax = $this->progressStateStep; |
|
89 | - $this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $this->currentStep])); |
|
90 | - break; |
|
91 | - case '\OC\Repair::step': |
|
92 | - $this->eventSource->send('success', (string)$this->l10n->t('Repair step:') . ' ' . $event->getArgument(0)); |
|
93 | - break; |
|
94 | - case '\OC\Repair::info': |
|
95 | - $this->eventSource->send('success', (string)$this->l10n->t('Repair info:') . ' ' . $event->getArgument(0)); |
|
96 | - break; |
|
97 | - case '\OC\Repair::warning': |
|
98 | - $this->eventSource->send('notice', (string)$this->l10n->t('Repair warning:') . ' ' . $event->getArgument(0)); |
|
99 | - break; |
|
100 | - case '\OC\Repair::error': |
|
101 | - $this->eventSource->send('notice', (string)$this->l10n->t('Repair error:') . ' ' . $event->getArgument(0)); |
|
102 | - break; |
|
103 | - } |
|
104 | - } |
|
52 | + /** @var integer */ |
|
53 | + private $progressStateMax = 100; |
|
54 | + /** @var integer */ |
|
55 | + private $progressStateStep = 0; |
|
56 | + /** @var string */ |
|
57 | + private $currentStep; |
|
58 | + /** @var \OCP\IEventSource */ |
|
59 | + private $eventSource; |
|
60 | + /** @var \OCP\IL10N */ |
|
61 | + private $l10n; |
|
62 | + |
|
63 | + public function __construct(\OCP\IEventSource $eventSource, \OCP\IL10N $l10n) { |
|
64 | + $this->eventSource = $eventSource; |
|
65 | + $this->l10n = $l10n; |
|
66 | + } |
|
67 | + |
|
68 | + public function handleRepairFeedback($event) { |
|
69 | + if (!$event instanceof GenericEvent) { |
|
70 | + return; |
|
71 | + } |
|
72 | + |
|
73 | + switch ($event->getSubject()) { |
|
74 | + case '\OC\Repair::startProgress': |
|
75 | + $this->progressStateMax = $event->getArgument(0); |
|
76 | + $this->progressStateStep = 0; |
|
77 | + $this->currentStep = $event->getArgument(1); |
|
78 | + break; |
|
79 | + case '\OC\Repair::advance': |
|
80 | + $this->progressStateStep += $event->getArgument(0); |
|
81 | + $desc = $event->getArgument(1); |
|
82 | + if (empty($desc)) { |
|
83 | + $desc = $this->currentStep; |
|
84 | + } |
|
85 | + $this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $desc])); |
|
86 | + break; |
|
87 | + case '\OC\Repair::finishProgress': |
|
88 | + $this->progressStateMax = $this->progressStateStep; |
|
89 | + $this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $this->currentStep])); |
|
90 | + break; |
|
91 | + case '\OC\Repair::step': |
|
92 | + $this->eventSource->send('success', (string)$this->l10n->t('Repair step:') . ' ' . $event->getArgument(0)); |
|
93 | + break; |
|
94 | + case '\OC\Repair::info': |
|
95 | + $this->eventSource->send('success', (string)$this->l10n->t('Repair info:') . ' ' . $event->getArgument(0)); |
|
96 | + break; |
|
97 | + case '\OC\Repair::warning': |
|
98 | + $this->eventSource->send('notice', (string)$this->l10n->t('Repair warning:') . ' ' . $event->getArgument(0)); |
|
99 | + break; |
|
100 | + case '\OC\Repair::error': |
|
101 | + $this->eventSource->send('notice', (string)$this->l10n->t('Repair error:') . ' ' . $event->getArgument(0)); |
|
102 | + break; |
|
103 | + } |
|
104 | + } |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | if (\OCP\Util::needUpgrade()) { |
108 | 108 | |
109 | - $config = \OC::$server->getSystemConfig(); |
|
110 | - if ($config->getValue('upgrade.disable-web', false)) { |
|
111 | - $eventSource->send('failure', (string)$l->t('Please use the command line updater because automatic updating is disabled in the config.php.')); |
|
112 | - $eventSource->close(); |
|
113 | - exit(); |
|
114 | - } |
|
115 | - |
|
116 | - // if a user is currently logged in, their session must be ignored to |
|
117 | - // avoid side effects |
|
118 | - \OC_User::setIncognitoMode(true); |
|
119 | - |
|
120 | - $logger = \OC::$server->getLogger(); |
|
121 | - $config = \OC::$server->getConfig(); |
|
122 | - $updater = new \OC\Updater( |
|
123 | - $config, |
|
124 | - \OC::$server->getIntegrityCodeChecker(), |
|
125 | - $logger, |
|
126 | - \OC::$server->query(\OC\Installer::class) |
|
127 | - ); |
|
128 | - $incompatibleApps = []; |
|
129 | - |
|
130 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
131 | - $dispatcher->addListener('\OC\DB\Migrator::executeSql', function ($event) use ($eventSource, $l) { |
|
132 | - if ($event instanceof GenericEvent) { |
|
133 | - $eventSource->send('success', (string)$l->t('[%d / %d]: %s', [$event[0], $event[1], $event->getSubject()])); |
|
134 | - } |
|
135 | - }); |
|
136 | - $dispatcher->addListener('\OC\DB\Migrator::checkTable', function ($event) use ($eventSource, $l) { |
|
137 | - if ($event instanceof GenericEvent) { |
|
138 | - $eventSource->send('success', (string)$l->t('[%d / %d]: Checking table %s', [$event[0], $event[1], $event->getSubject()])); |
|
139 | - } |
|
140 | - }); |
|
141 | - $feedBack = new FeedBackHandler($eventSource, $l); |
|
142 | - $dispatcher->addListener('\OC\Repair::startProgress', [$feedBack, 'handleRepairFeedback']); |
|
143 | - $dispatcher->addListener('\OC\Repair::advance', [$feedBack, 'handleRepairFeedback']); |
|
144 | - $dispatcher->addListener('\OC\Repair::finishProgress', [$feedBack, 'handleRepairFeedback']); |
|
145 | - $dispatcher->addListener('\OC\Repair::step', [$feedBack, 'handleRepairFeedback']); |
|
146 | - $dispatcher->addListener('\OC\Repair::info', [$feedBack, 'handleRepairFeedback']); |
|
147 | - $dispatcher->addListener('\OC\Repair::warning', [$feedBack, 'handleRepairFeedback']); |
|
148 | - $dispatcher->addListener('\OC\Repair::error', [$feedBack, 'handleRepairFeedback']); |
|
149 | - |
|
150 | - $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l) { |
|
151 | - $eventSource->send('success', (string)$l->t('Turned on maintenance mode')); |
|
152 | - }); |
|
153 | - $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($eventSource, $l) { |
|
154 | - $eventSource->send('success', (string)$l->t('Turned off maintenance mode')); |
|
155 | - }); |
|
156 | - $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($eventSource, $l) { |
|
157 | - $eventSource->send('success', (string)$l->t('Maintenance mode is kept active')); |
|
158 | - }); |
|
159 | - $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($eventSource, $l) { |
|
160 | - $eventSource->send('success', (string)$l->t('Updating database schema')); |
|
161 | - }); |
|
162 | - $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l) { |
|
163 | - $eventSource->send('success', (string)$l->t('Updated database')); |
|
164 | - }); |
|
165 | - $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use ($eventSource, $l) { |
|
166 | - $eventSource->send('success', (string)$l->t('Checking whether the database schema can be updated (this can take a long time depending on the database size)')); |
|
167 | - }); |
|
168 | - $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use ($eventSource, $l) { |
|
169 | - $eventSource->send('success', (string)$l->t('Checked database schema update')); |
|
170 | - }); |
|
171 | - $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($eventSource, $l) { |
|
172 | - $eventSource->send('success', (string)$l->t('Checking updates of apps')); |
|
173 | - }); |
|
174 | - $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($eventSource, $l) { |
|
175 | - $eventSource->send('success', (string)$l->t('Checking for update of app "%s" in appstore', [$app])); |
|
176 | - }); |
|
177 | - $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($eventSource, $l) { |
|
178 | - $eventSource->send('success', (string)$l->t('Update app "%s" from appstore', [$app])); |
|
179 | - }); |
|
180 | - $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($eventSource, $l) { |
|
181 | - $eventSource->send('success', (string)$l->t('Checked for update of app "%s" in appstore', [$app])); |
|
182 | - }); |
|
183 | - $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($eventSource, $l) { |
|
184 | - $eventSource->send('success', (string)$l->t('Checking whether the database schema for %s can be updated (this can take a long time depending on the database size)', [$app])); |
|
185 | - }); |
|
186 | - $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($eventSource, $l) { |
|
187 | - $eventSource->send('success', (string)$l->t('Checked database schema update for apps')); |
|
188 | - }); |
|
189 | - $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($eventSource, $l) { |
|
190 | - $eventSource->send('success', (string)$l->t('Updated "%1$s" to %2$s', [$app, $version])); |
|
191 | - }); |
|
192 | - $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use (&$incompatibleApps) { |
|
193 | - $incompatibleApps[]= $app; |
|
194 | - }); |
|
195 | - $updater->listen('\OC\Updater', 'failure', function ($message) use ($eventSource, $config) { |
|
196 | - $eventSource->send('failure', $message); |
|
197 | - $eventSource->close(); |
|
198 | - $config->setSystemValue('maintenance', false); |
|
199 | - }); |
|
200 | - $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l) { |
|
201 | - $eventSource->send('success', (string)$l->t('Set log level to debug')); |
|
202 | - }); |
|
203 | - $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l) { |
|
204 | - $eventSource->send('success', (string)$l->t('Reset log level')); |
|
205 | - }); |
|
206 | - $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($eventSource, $l) { |
|
207 | - $eventSource->send('success', (string)$l->t('Starting code integrity check')); |
|
208 | - }); |
|
209 | - $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($eventSource, $l) { |
|
210 | - $eventSource->send('success', (string)$l->t('Finished code integrity check')); |
|
211 | - }); |
|
212 | - |
|
213 | - try { |
|
214 | - $updater->upgrade(); |
|
215 | - } catch (\Exception $e) { |
|
216 | - \OC::$server->getLogger()->logException($e, [ |
|
217 | - 'level' => ILogger::ERROR, |
|
218 | - 'app' => 'update', |
|
219 | - ]); |
|
220 | - $eventSource->send('failure', get_class($e) . ': ' . $e->getMessage()); |
|
221 | - $eventSource->close(); |
|
222 | - exit(); |
|
223 | - } |
|
224 | - |
|
225 | - $disabledApps = []; |
|
226 | - foreach ($incompatibleApps as $app) { |
|
227 | - $disabledApps[$app] = (string) $l->t('%s (incompatible)', [$app]); |
|
228 | - } |
|
229 | - |
|
230 | - if (!empty($disabledApps)) { |
|
231 | - $eventSource->send('notice', |
|
232 | - (string)$l->t('Following apps have been disabled: %s', [implode(', ', $disabledApps)])); |
|
233 | - } |
|
109 | + $config = \OC::$server->getSystemConfig(); |
|
110 | + if ($config->getValue('upgrade.disable-web', false)) { |
|
111 | + $eventSource->send('failure', (string)$l->t('Please use the command line updater because automatic updating is disabled in the config.php.')); |
|
112 | + $eventSource->close(); |
|
113 | + exit(); |
|
114 | + } |
|
115 | + |
|
116 | + // if a user is currently logged in, their session must be ignored to |
|
117 | + // avoid side effects |
|
118 | + \OC_User::setIncognitoMode(true); |
|
119 | + |
|
120 | + $logger = \OC::$server->getLogger(); |
|
121 | + $config = \OC::$server->getConfig(); |
|
122 | + $updater = new \OC\Updater( |
|
123 | + $config, |
|
124 | + \OC::$server->getIntegrityCodeChecker(), |
|
125 | + $logger, |
|
126 | + \OC::$server->query(\OC\Installer::class) |
|
127 | + ); |
|
128 | + $incompatibleApps = []; |
|
129 | + |
|
130 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
131 | + $dispatcher->addListener('\OC\DB\Migrator::executeSql', function ($event) use ($eventSource, $l) { |
|
132 | + if ($event instanceof GenericEvent) { |
|
133 | + $eventSource->send('success', (string)$l->t('[%d / %d]: %s', [$event[0], $event[1], $event->getSubject()])); |
|
134 | + } |
|
135 | + }); |
|
136 | + $dispatcher->addListener('\OC\DB\Migrator::checkTable', function ($event) use ($eventSource, $l) { |
|
137 | + if ($event instanceof GenericEvent) { |
|
138 | + $eventSource->send('success', (string)$l->t('[%d / %d]: Checking table %s', [$event[0], $event[1], $event->getSubject()])); |
|
139 | + } |
|
140 | + }); |
|
141 | + $feedBack = new FeedBackHandler($eventSource, $l); |
|
142 | + $dispatcher->addListener('\OC\Repair::startProgress', [$feedBack, 'handleRepairFeedback']); |
|
143 | + $dispatcher->addListener('\OC\Repair::advance', [$feedBack, 'handleRepairFeedback']); |
|
144 | + $dispatcher->addListener('\OC\Repair::finishProgress', [$feedBack, 'handleRepairFeedback']); |
|
145 | + $dispatcher->addListener('\OC\Repair::step', [$feedBack, 'handleRepairFeedback']); |
|
146 | + $dispatcher->addListener('\OC\Repair::info', [$feedBack, 'handleRepairFeedback']); |
|
147 | + $dispatcher->addListener('\OC\Repair::warning', [$feedBack, 'handleRepairFeedback']); |
|
148 | + $dispatcher->addListener('\OC\Repair::error', [$feedBack, 'handleRepairFeedback']); |
|
149 | + |
|
150 | + $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l) { |
|
151 | + $eventSource->send('success', (string)$l->t('Turned on maintenance mode')); |
|
152 | + }); |
|
153 | + $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($eventSource, $l) { |
|
154 | + $eventSource->send('success', (string)$l->t('Turned off maintenance mode')); |
|
155 | + }); |
|
156 | + $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($eventSource, $l) { |
|
157 | + $eventSource->send('success', (string)$l->t('Maintenance mode is kept active')); |
|
158 | + }); |
|
159 | + $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($eventSource, $l) { |
|
160 | + $eventSource->send('success', (string)$l->t('Updating database schema')); |
|
161 | + }); |
|
162 | + $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l) { |
|
163 | + $eventSource->send('success', (string)$l->t('Updated database')); |
|
164 | + }); |
|
165 | + $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use ($eventSource, $l) { |
|
166 | + $eventSource->send('success', (string)$l->t('Checking whether the database schema can be updated (this can take a long time depending on the database size)')); |
|
167 | + }); |
|
168 | + $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use ($eventSource, $l) { |
|
169 | + $eventSource->send('success', (string)$l->t('Checked database schema update')); |
|
170 | + }); |
|
171 | + $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($eventSource, $l) { |
|
172 | + $eventSource->send('success', (string)$l->t('Checking updates of apps')); |
|
173 | + }); |
|
174 | + $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($eventSource, $l) { |
|
175 | + $eventSource->send('success', (string)$l->t('Checking for update of app "%s" in appstore', [$app])); |
|
176 | + }); |
|
177 | + $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($eventSource, $l) { |
|
178 | + $eventSource->send('success', (string)$l->t('Update app "%s" from appstore', [$app])); |
|
179 | + }); |
|
180 | + $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($eventSource, $l) { |
|
181 | + $eventSource->send('success', (string)$l->t('Checked for update of app "%s" in appstore', [$app])); |
|
182 | + }); |
|
183 | + $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($eventSource, $l) { |
|
184 | + $eventSource->send('success', (string)$l->t('Checking whether the database schema for %s can be updated (this can take a long time depending on the database size)', [$app])); |
|
185 | + }); |
|
186 | + $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($eventSource, $l) { |
|
187 | + $eventSource->send('success', (string)$l->t('Checked database schema update for apps')); |
|
188 | + }); |
|
189 | + $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($eventSource, $l) { |
|
190 | + $eventSource->send('success', (string)$l->t('Updated "%1$s" to %2$s', [$app, $version])); |
|
191 | + }); |
|
192 | + $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use (&$incompatibleApps) { |
|
193 | + $incompatibleApps[]= $app; |
|
194 | + }); |
|
195 | + $updater->listen('\OC\Updater', 'failure', function ($message) use ($eventSource, $config) { |
|
196 | + $eventSource->send('failure', $message); |
|
197 | + $eventSource->close(); |
|
198 | + $config->setSystemValue('maintenance', false); |
|
199 | + }); |
|
200 | + $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l) { |
|
201 | + $eventSource->send('success', (string)$l->t('Set log level to debug')); |
|
202 | + }); |
|
203 | + $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l) { |
|
204 | + $eventSource->send('success', (string)$l->t('Reset log level')); |
|
205 | + }); |
|
206 | + $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($eventSource, $l) { |
|
207 | + $eventSource->send('success', (string)$l->t('Starting code integrity check')); |
|
208 | + }); |
|
209 | + $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($eventSource, $l) { |
|
210 | + $eventSource->send('success', (string)$l->t('Finished code integrity check')); |
|
211 | + }); |
|
212 | + |
|
213 | + try { |
|
214 | + $updater->upgrade(); |
|
215 | + } catch (\Exception $e) { |
|
216 | + \OC::$server->getLogger()->logException($e, [ |
|
217 | + 'level' => ILogger::ERROR, |
|
218 | + 'app' => 'update', |
|
219 | + ]); |
|
220 | + $eventSource->send('failure', get_class($e) . ': ' . $e->getMessage()); |
|
221 | + $eventSource->close(); |
|
222 | + exit(); |
|
223 | + } |
|
224 | + |
|
225 | + $disabledApps = []; |
|
226 | + foreach ($incompatibleApps as $app) { |
|
227 | + $disabledApps[$app] = (string) $l->t('%s (incompatible)', [$app]); |
|
228 | + } |
|
229 | + |
|
230 | + if (!empty($disabledApps)) { |
|
231 | + $eventSource->send('notice', |
|
232 | + (string)$l->t('Following apps have been disabled: %s', [implode(', ', $disabledApps)])); |
|
233 | + } |
|
234 | 234 | } else { |
235 | - $eventSource->send('notice', (string)$l->t('Already up to date')); |
|
235 | + $eventSource->send('notice', (string)$l->t('Already up to date')); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | $eventSource->send('done', ''); |
@@ -69,348 +69,348 @@ |
||
69 | 69 | * @package OC\Core\Controller |
70 | 70 | */ |
71 | 71 | class LostController extends Controller { |
72 | - /** @var IURLGenerator */ |
|
73 | - protected $urlGenerator; |
|
74 | - /** @var IUserManager */ |
|
75 | - protected $userManager; |
|
76 | - /** @var Defaults */ |
|
77 | - protected $defaults; |
|
78 | - /** @var IL10N */ |
|
79 | - protected $l10n; |
|
80 | - /** @var string */ |
|
81 | - protected $from; |
|
82 | - /** @var IManager */ |
|
83 | - protected $encryptionManager; |
|
84 | - /** @var IConfig */ |
|
85 | - protected $config; |
|
86 | - /** @var ISecureRandom */ |
|
87 | - protected $secureRandom; |
|
88 | - /** @var IMailer */ |
|
89 | - protected $mailer; |
|
90 | - /** @var ITimeFactory */ |
|
91 | - protected $timeFactory; |
|
92 | - /** @var ICrypto */ |
|
93 | - protected $crypto; |
|
94 | - /** @var ILogger */ |
|
95 | - private $logger; |
|
96 | - /** @var Manager */ |
|
97 | - private $twoFactorManager; |
|
98 | - /** @var IInitialStateService */ |
|
99 | - private $initialStateService; |
|
100 | - |
|
101 | - /** |
|
102 | - * @param string $appName |
|
103 | - * @param IRequest $request |
|
104 | - * @param IURLGenerator $urlGenerator |
|
105 | - * @param IUserManager $userManager |
|
106 | - * @param Defaults $defaults |
|
107 | - * @param IL10N $l10n |
|
108 | - * @param IConfig $config |
|
109 | - * @param ISecureRandom $secureRandom |
|
110 | - * @param string $defaultMailAddress |
|
111 | - * @param IManager $encryptionManager |
|
112 | - * @param IMailer $mailer |
|
113 | - * @param ITimeFactory $timeFactory |
|
114 | - * @param ICrypto $crypto |
|
115 | - */ |
|
116 | - public function __construct($appName, |
|
117 | - IRequest $request, |
|
118 | - IURLGenerator $urlGenerator, |
|
119 | - IUserManager $userManager, |
|
120 | - Defaults $defaults, |
|
121 | - IL10N $l10n, |
|
122 | - IConfig $config, |
|
123 | - ISecureRandom $secureRandom, |
|
124 | - $defaultMailAddress, |
|
125 | - IManager $encryptionManager, |
|
126 | - IMailer $mailer, |
|
127 | - ITimeFactory $timeFactory, |
|
128 | - ICrypto $crypto, |
|
129 | - ILogger $logger, |
|
130 | - Manager $twoFactorManager, |
|
131 | - IInitialStateService $initialStateService) { |
|
132 | - parent::__construct($appName, $request); |
|
133 | - $this->urlGenerator = $urlGenerator; |
|
134 | - $this->userManager = $userManager; |
|
135 | - $this->defaults = $defaults; |
|
136 | - $this->l10n = $l10n; |
|
137 | - $this->secureRandom = $secureRandom; |
|
138 | - $this->from = $defaultMailAddress; |
|
139 | - $this->encryptionManager = $encryptionManager; |
|
140 | - $this->config = $config; |
|
141 | - $this->mailer = $mailer; |
|
142 | - $this->timeFactory = $timeFactory; |
|
143 | - $this->crypto = $crypto; |
|
144 | - $this->logger = $logger; |
|
145 | - $this->twoFactorManager = $twoFactorManager; |
|
146 | - $this->initialStateService = $initialStateService; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Someone wants to reset their password: |
|
151 | - * |
|
152 | - * @PublicPage |
|
153 | - * @NoCSRFRequired |
|
154 | - * |
|
155 | - * @param string $token |
|
156 | - * @param string $userId |
|
157 | - * @return TemplateResponse |
|
158 | - */ |
|
159 | - public function resetform($token, $userId) { |
|
160 | - if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
161 | - return new TemplateResponse('core', 'error', [ |
|
162 | - 'errors' => [['error' => $this->l10n->t('Password reset is disabled')]] |
|
163 | - ], |
|
164 | - 'guest' |
|
165 | - ); |
|
166 | - } |
|
167 | - |
|
168 | - try { |
|
169 | - $this->checkPasswordResetToken($token, $userId); |
|
170 | - } catch (\Exception $e) { |
|
171 | - return new TemplateResponse( |
|
172 | - 'core', 'error', [ |
|
173 | - "errors" => [["error" => $e->getMessage()]] |
|
174 | - ], |
|
175 | - 'guest' |
|
176 | - ); |
|
177 | - } |
|
178 | - $this->initialStateService->provideInitialState('core', 'resetPasswordUser', $userId); |
|
179 | - $this->initialStateService->provideInitialState('core', 'resetPasswordTarget', |
|
180 | - $this->urlGenerator->linkToRouteAbsolute('core.lost.setPassword', ['userId' => $userId, 'token' => $token]) |
|
181 | - ); |
|
182 | - |
|
183 | - return new TemplateResponse( |
|
184 | - 'core', |
|
185 | - 'login', |
|
186 | - [], |
|
187 | - 'guest' |
|
188 | - ); |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * @param string $token |
|
193 | - * @param string $userId |
|
194 | - * @throws \Exception |
|
195 | - */ |
|
196 | - protected function checkPasswordResetToken($token, $userId) { |
|
197 | - $user = $this->userManager->get($userId); |
|
198 | - if($user === null || !$user->isEnabled()) { |
|
199 | - throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
200 | - } |
|
201 | - |
|
202 | - $encryptedToken = $this->config->getUserValue($userId, 'core', 'lostpassword', null); |
|
203 | - if ($encryptedToken === null) { |
|
204 | - throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
205 | - } |
|
206 | - |
|
207 | - try { |
|
208 | - $mailAddress = !is_null($user->getEMailAddress()) ? $user->getEMailAddress() : ''; |
|
209 | - $decryptedToken = $this->crypto->decrypt($encryptedToken, $mailAddress.$this->config->getSystemValue('secret')); |
|
210 | - } catch (\Exception $e) { |
|
211 | - throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
212 | - } |
|
213 | - |
|
214 | - $splittedToken = explode(':', $decryptedToken); |
|
215 | - if(count($splittedToken) !== 2) { |
|
216 | - throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
217 | - } |
|
218 | - |
|
219 | - if ($splittedToken[0] < ($this->timeFactory->getTime() - 60*60*24*7) || |
|
220 | - $user->getLastLogin() > $splittedToken[0]) { |
|
221 | - throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is expired')); |
|
222 | - } |
|
223 | - |
|
224 | - if (!hash_equals($splittedToken[1], $token)) { |
|
225 | - throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
226 | - } |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * @param $message |
|
231 | - * @param array $additional |
|
232 | - * @return array |
|
233 | - */ |
|
234 | - private function error($message, array $additional=[]) { |
|
235 | - return array_merge(['status' => 'error', 'msg' => $message], $additional); |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * @param array $data |
|
240 | - * @return array |
|
241 | - */ |
|
242 | - private function success($data = []) { |
|
243 | - return array_merge($data, ['status'=>'success']); |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * @PublicPage |
|
248 | - * @BruteForceProtection(action=passwordResetEmail) |
|
249 | - * @AnonRateThrottle(limit=10, period=300) |
|
250 | - * |
|
251 | - * @param string $user |
|
252 | - * @return JSONResponse |
|
253 | - */ |
|
254 | - public function email($user) { |
|
255 | - if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
256 | - return new JSONResponse($this->error($this->l10n->t('Password reset is disabled'))); |
|
257 | - } |
|
258 | - |
|
259 | - \OCP\Util::emitHook( |
|
260 | - '\OCA\Files_Sharing\API\Server2Server', |
|
261 | - 'preLoginNameUsedAsUserName', |
|
262 | - ['uid' => &$user] |
|
263 | - ); |
|
264 | - |
|
265 | - // FIXME: use HTTP error codes |
|
266 | - try { |
|
267 | - $this->sendEmail($user); |
|
268 | - } catch (ResetPasswordException $e) { |
|
269 | - // Ignore the error since we do not want to leak this info |
|
270 | - $this->logger->warning('Could not send password reset email: ' . $e->getMessage()); |
|
271 | - } catch (\Exception $e) { |
|
272 | - $this->logger->logException($e); |
|
273 | - } |
|
274 | - |
|
275 | - $response = new JSONResponse($this->success()); |
|
276 | - $response->throttle(); |
|
277 | - return $response; |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * @PublicPage |
|
282 | - * @param string $token |
|
283 | - * @param string $userId |
|
284 | - * @param string $password |
|
285 | - * @param boolean $proceed |
|
286 | - * @return array |
|
287 | - */ |
|
288 | - public function setPassword($token, $userId, $password, $proceed) { |
|
289 | - if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
290 | - return $this->error($this->l10n->t('Password reset is disabled')); |
|
291 | - } |
|
292 | - |
|
293 | - if ($this->encryptionManager->isEnabled() && !$proceed) { |
|
294 | - $encryptionModules = $this->encryptionManager->getEncryptionModules(); |
|
295 | - foreach ($encryptionModules as $module) { |
|
296 | - /** @var IEncryptionModule $instance */ |
|
297 | - $instance = call_user_func($module['callback']); |
|
298 | - // this way we can find out whether per-user keys are used or a system wide encryption key |
|
299 | - if ($instance->needDetailedAccessList()) { |
|
300 | - return $this->error('', ['encryption' => true]); |
|
301 | - } |
|
302 | - } |
|
303 | - } |
|
304 | - |
|
305 | - try { |
|
306 | - $this->checkPasswordResetToken($token, $userId); |
|
307 | - $user = $this->userManager->get($userId); |
|
308 | - |
|
309 | - \OC_Hook::emit('\OC\Core\LostPassword\Controller\LostController', 'pre_passwordReset', ['uid' => $userId, 'password' => $password]); |
|
310 | - |
|
311 | - if (!$user->setPassword($password)) { |
|
312 | - throw new \Exception(); |
|
313 | - } |
|
314 | - |
|
315 | - \OC_Hook::emit('\OC\Core\LostPassword\Controller\LostController', 'post_passwordReset', ['uid' => $userId, 'password' => $password]); |
|
316 | - |
|
317 | - $this->twoFactorManager->clearTwoFactorPending($userId); |
|
318 | - |
|
319 | - $this->config->deleteUserValue($userId, 'core', 'lostpassword'); |
|
320 | - @\OC::$server->getUserSession()->unsetMagicInCookie(); |
|
321 | - } catch (HintException $e){ |
|
322 | - return $this->error($e->getHint()); |
|
323 | - } catch (\Exception $e){ |
|
324 | - return $this->error($e->getMessage()); |
|
325 | - } |
|
326 | - |
|
327 | - return $this->success(['user' => $userId]); |
|
328 | - } |
|
329 | - |
|
330 | - /** |
|
331 | - * @param string $input |
|
332 | - * @throws ResetPasswordException |
|
333 | - * @throws \OCP\PreConditionNotMetException |
|
334 | - */ |
|
335 | - protected function sendEmail($input) { |
|
336 | - $user = $this->findUserByIdOrMail($input); |
|
337 | - $email = $user->getEMailAddress(); |
|
338 | - |
|
339 | - if (empty($email)) { |
|
340 | - throw new ResetPasswordException('Could not send reset e-mail since there is no email for username ' . $input); |
|
341 | - } |
|
342 | - |
|
343 | - // Generate the token. It is stored encrypted in the database with the |
|
344 | - // secret being the users' email address appended with the system secret. |
|
345 | - // This makes the token automatically invalidate once the user changes |
|
346 | - // their email address. |
|
347 | - $token = $this->secureRandom->generate( |
|
348 | - 21, |
|
349 | - ISecureRandom::CHAR_DIGITS. |
|
350 | - ISecureRandom::CHAR_LOWER. |
|
351 | - ISecureRandom::CHAR_UPPER |
|
352 | - ); |
|
353 | - $tokenValue = $this->timeFactory->getTime() .':'. $token; |
|
354 | - $encryptedValue = $this->crypto->encrypt($tokenValue, $email . $this->config->getSystemValue('secret')); |
|
355 | - $this->config->setUserValue($user->getUID(), 'core', 'lostpassword', $encryptedValue); |
|
356 | - |
|
357 | - $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', ['userId' => $user->getUID(), 'token' => $token]); |
|
358 | - |
|
359 | - $emailTemplate = $this->mailer->createEMailTemplate('core.ResetPassword', [ |
|
360 | - 'link' => $link, |
|
361 | - ]); |
|
362 | - |
|
363 | - $emailTemplate->setSubject($this->l10n->t('%s password reset', [$this->defaults->getName()])); |
|
364 | - $emailTemplate->addHeader(); |
|
365 | - $emailTemplate->addHeading($this->l10n->t('Password reset')); |
|
366 | - |
|
367 | - $emailTemplate->addBodyText( |
|
368 | - htmlspecialchars($this->l10n->t('Click the following button to reset your password. If you have not requested the password reset, then ignore this email.')), |
|
369 | - $this->l10n->t('Click the following link to reset your password. If you have not requested the password reset, then ignore this email.') |
|
370 | - ); |
|
371 | - |
|
372 | - $emailTemplate->addBodyButton( |
|
373 | - htmlspecialchars($this->l10n->t('Reset your password')), |
|
374 | - $link, |
|
375 | - false |
|
376 | - ); |
|
377 | - $emailTemplate->addFooter(); |
|
378 | - |
|
379 | - try { |
|
380 | - $message = $this->mailer->createMessage(); |
|
381 | - $message->setTo([$email => $user->getUID()]); |
|
382 | - $message->setFrom([$this->from => $this->defaults->getName()]); |
|
383 | - $message->useTemplate($emailTemplate); |
|
384 | - $this->mailer->send($message); |
|
385 | - } catch (\Exception $e) { |
|
386 | - // Log the exception and continue |
|
387 | - $this->logger->logException($e); |
|
388 | - } |
|
389 | - } |
|
390 | - |
|
391 | - /** |
|
392 | - * @param string $input |
|
393 | - * @return IUser |
|
394 | - * @throws ResetPasswordException |
|
395 | - */ |
|
396 | - protected function findUserByIdOrMail($input) { |
|
397 | - $user = $this->userManager->get($input); |
|
398 | - if ($user instanceof IUser) { |
|
399 | - if (!$user->isEnabled()) { |
|
400 | - throw new ResetPasswordException('User is disabled'); |
|
401 | - } |
|
402 | - |
|
403 | - return $user; |
|
404 | - } |
|
405 | - |
|
406 | - $users = array_filter($this->userManager->getByEmail($input), function (IUser $user) { |
|
407 | - return $user->isEnabled(); |
|
408 | - }); |
|
409 | - |
|
410 | - if (count($users) === 1) { |
|
411 | - return reset($users); |
|
412 | - } |
|
413 | - |
|
414 | - throw new ResetPasswordException('Could not find user'); |
|
415 | - } |
|
72 | + /** @var IURLGenerator */ |
|
73 | + protected $urlGenerator; |
|
74 | + /** @var IUserManager */ |
|
75 | + protected $userManager; |
|
76 | + /** @var Defaults */ |
|
77 | + protected $defaults; |
|
78 | + /** @var IL10N */ |
|
79 | + protected $l10n; |
|
80 | + /** @var string */ |
|
81 | + protected $from; |
|
82 | + /** @var IManager */ |
|
83 | + protected $encryptionManager; |
|
84 | + /** @var IConfig */ |
|
85 | + protected $config; |
|
86 | + /** @var ISecureRandom */ |
|
87 | + protected $secureRandom; |
|
88 | + /** @var IMailer */ |
|
89 | + protected $mailer; |
|
90 | + /** @var ITimeFactory */ |
|
91 | + protected $timeFactory; |
|
92 | + /** @var ICrypto */ |
|
93 | + protected $crypto; |
|
94 | + /** @var ILogger */ |
|
95 | + private $logger; |
|
96 | + /** @var Manager */ |
|
97 | + private $twoFactorManager; |
|
98 | + /** @var IInitialStateService */ |
|
99 | + private $initialStateService; |
|
100 | + |
|
101 | + /** |
|
102 | + * @param string $appName |
|
103 | + * @param IRequest $request |
|
104 | + * @param IURLGenerator $urlGenerator |
|
105 | + * @param IUserManager $userManager |
|
106 | + * @param Defaults $defaults |
|
107 | + * @param IL10N $l10n |
|
108 | + * @param IConfig $config |
|
109 | + * @param ISecureRandom $secureRandom |
|
110 | + * @param string $defaultMailAddress |
|
111 | + * @param IManager $encryptionManager |
|
112 | + * @param IMailer $mailer |
|
113 | + * @param ITimeFactory $timeFactory |
|
114 | + * @param ICrypto $crypto |
|
115 | + */ |
|
116 | + public function __construct($appName, |
|
117 | + IRequest $request, |
|
118 | + IURLGenerator $urlGenerator, |
|
119 | + IUserManager $userManager, |
|
120 | + Defaults $defaults, |
|
121 | + IL10N $l10n, |
|
122 | + IConfig $config, |
|
123 | + ISecureRandom $secureRandom, |
|
124 | + $defaultMailAddress, |
|
125 | + IManager $encryptionManager, |
|
126 | + IMailer $mailer, |
|
127 | + ITimeFactory $timeFactory, |
|
128 | + ICrypto $crypto, |
|
129 | + ILogger $logger, |
|
130 | + Manager $twoFactorManager, |
|
131 | + IInitialStateService $initialStateService) { |
|
132 | + parent::__construct($appName, $request); |
|
133 | + $this->urlGenerator = $urlGenerator; |
|
134 | + $this->userManager = $userManager; |
|
135 | + $this->defaults = $defaults; |
|
136 | + $this->l10n = $l10n; |
|
137 | + $this->secureRandom = $secureRandom; |
|
138 | + $this->from = $defaultMailAddress; |
|
139 | + $this->encryptionManager = $encryptionManager; |
|
140 | + $this->config = $config; |
|
141 | + $this->mailer = $mailer; |
|
142 | + $this->timeFactory = $timeFactory; |
|
143 | + $this->crypto = $crypto; |
|
144 | + $this->logger = $logger; |
|
145 | + $this->twoFactorManager = $twoFactorManager; |
|
146 | + $this->initialStateService = $initialStateService; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Someone wants to reset their password: |
|
151 | + * |
|
152 | + * @PublicPage |
|
153 | + * @NoCSRFRequired |
|
154 | + * |
|
155 | + * @param string $token |
|
156 | + * @param string $userId |
|
157 | + * @return TemplateResponse |
|
158 | + */ |
|
159 | + public function resetform($token, $userId) { |
|
160 | + if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
161 | + return new TemplateResponse('core', 'error', [ |
|
162 | + 'errors' => [['error' => $this->l10n->t('Password reset is disabled')]] |
|
163 | + ], |
|
164 | + 'guest' |
|
165 | + ); |
|
166 | + } |
|
167 | + |
|
168 | + try { |
|
169 | + $this->checkPasswordResetToken($token, $userId); |
|
170 | + } catch (\Exception $e) { |
|
171 | + return new TemplateResponse( |
|
172 | + 'core', 'error', [ |
|
173 | + "errors" => [["error" => $e->getMessage()]] |
|
174 | + ], |
|
175 | + 'guest' |
|
176 | + ); |
|
177 | + } |
|
178 | + $this->initialStateService->provideInitialState('core', 'resetPasswordUser', $userId); |
|
179 | + $this->initialStateService->provideInitialState('core', 'resetPasswordTarget', |
|
180 | + $this->urlGenerator->linkToRouteAbsolute('core.lost.setPassword', ['userId' => $userId, 'token' => $token]) |
|
181 | + ); |
|
182 | + |
|
183 | + return new TemplateResponse( |
|
184 | + 'core', |
|
185 | + 'login', |
|
186 | + [], |
|
187 | + 'guest' |
|
188 | + ); |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * @param string $token |
|
193 | + * @param string $userId |
|
194 | + * @throws \Exception |
|
195 | + */ |
|
196 | + protected function checkPasswordResetToken($token, $userId) { |
|
197 | + $user = $this->userManager->get($userId); |
|
198 | + if($user === null || !$user->isEnabled()) { |
|
199 | + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
200 | + } |
|
201 | + |
|
202 | + $encryptedToken = $this->config->getUserValue($userId, 'core', 'lostpassword', null); |
|
203 | + if ($encryptedToken === null) { |
|
204 | + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
205 | + } |
|
206 | + |
|
207 | + try { |
|
208 | + $mailAddress = !is_null($user->getEMailAddress()) ? $user->getEMailAddress() : ''; |
|
209 | + $decryptedToken = $this->crypto->decrypt($encryptedToken, $mailAddress.$this->config->getSystemValue('secret')); |
|
210 | + } catch (\Exception $e) { |
|
211 | + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
212 | + } |
|
213 | + |
|
214 | + $splittedToken = explode(':', $decryptedToken); |
|
215 | + if(count($splittedToken) !== 2) { |
|
216 | + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
217 | + } |
|
218 | + |
|
219 | + if ($splittedToken[0] < ($this->timeFactory->getTime() - 60*60*24*7) || |
|
220 | + $user->getLastLogin() > $splittedToken[0]) { |
|
221 | + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is expired')); |
|
222 | + } |
|
223 | + |
|
224 | + if (!hash_equals($splittedToken[1], $token)) { |
|
225 | + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
226 | + } |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * @param $message |
|
231 | + * @param array $additional |
|
232 | + * @return array |
|
233 | + */ |
|
234 | + private function error($message, array $additional=[]) { |
|
235 | + return array_merge(['status' => 'error', 'msg' => $message], $additional); |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * @param array $data |
|
240 | + * @return array |
|
241 | + */ |
|
242 | + private function success($data = []) { |
|
243 | + return array_merge($data, ['status'=>'success']); |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * @PublicPage |
|
248 | + * @BruteForceProtection(action=passwordResetEmail) |
|
249 | + * @AnonRateThrottle(limit=10, period=300) |
|
250 | + * |
|
251 | + * @param string $user |
|
252 | + * @return JSONResponse |
|
253 | + */ |
|
254 | + public function email($user) { |
|
255 | + if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
256 | + return new JSONResponse($this->error($this->l10n->t('Password reset is disabled'))); |
|
257 | + } |
|
258 | + |
|
259 | + \OCP\Util::emitHook( |
|
260 | + '\OCA\Files_Sharing\API\Server2Server', |
|
261 | + 'preLoginNameUsedAsUserName', |
|
262 | + ['uid' => &$user] |
|
263 | + ); |
|
264 | + |
|
265 | + // FIXME: use HTTP error codes |
|
266 | + try { |
|
267 | + $this->sendEmail($user); |
|
268 | + } catch (ResetPasswordException $e) { |
|
269 | + // Ignore the error since we do not want to leak this info |
|
270 | + $this->logger->warning('Could not send password reset email: ' . $e->getMessage()); |
|
271 | + } catch (\Exception $e) { |
|
272 | + $this->logger->logException($e); |
|
273 | + } |
|
274 | + |
|
275 | + $response = new JSONResponse($this->success()); |
|
276 | + $response->throttle(); |
|
277 | + return $response; |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * @PublicPage |
|
282 | + * @param string $token |
|
283 | + * @param string $userId |
|
284 | + * @param string $password |
|
285 | + * @param boolean $proceed |
|
286 | + * @return array |
|
287 | + */ |
|
288 | + public function setPassword($token, $userId, $password, $proceed) { |
|
289 | + if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
290 | + return $this->error($this->l10n->t('Password reset is disabled')); |
|
291 | + } |
|
292 | + |
|
293 | + if ($this->encryptionManager->isEnabled() && !$proceed) { |
|
294 | + $encryptionModules = $this->encryptionManager->getEncryptionModules(); |
|
295 | + foreach ($encryptionModules as $module) { |
|
296 | + /** @var IEncryptionModule $instance */ |
|
297 | + $instance = call_user_func($module['callback']); |
|
298 | + // this way we can find out whether per-user keys are used or a system wide encryption key |
|
299 | + if ($instance->needDetailedAccessList()) { |
|
300 | + return $this->error('', ['encryption' => true]); |
|
301 | + } |
|
302 | + } |
|
303 | + } |
|
304 | + |
|
305 | + try { |
|
306 | + $this->checkPasswordResetToken($token, $userId); |
|
307 | + $user = $this->userManager->get($userId); |
|
308 | + |
|
309 | + \OC_Hook::emit('\OC\Core\LostPassword\Controller\LostController', 'pre_passwordReset', ['uid' => $userId, 'password' => $password]); |
|
310 | + |
|
311 | + if (!$user->setPassword($password)) { |
|
312 | + throw new \Exception(); |
|
313 | + } |
|
314 | + |
|
315 | + \OC_Hook::emit('\OC\Core\LostPassword\Controller\LostController', 'post_passwordReset', ['uid' => $userId, 'password' => $password]); |
|
316 | + |
|
317 | + $this->twoFactorManager->clearTwoFactorPending($userId); |
|
318 | + |
|
319 | + $this->config->deleteUserValue($userId, 'core', 'lostpassword'); |
|
320 | + @\OC::$server->getUserSession()->unsetMagicInCookie(); |
|
321 | + } catch (HintException $e){ |
|
322 | + return $this->error($e->getHint()); |
|
323 | + } catch (\Exception $e){ |
|
324 | + return $this->error($e->getMessage()); |
|
325 | + } |
|
326 | + |
|
327 | + return $this->success(['user' => $userId]); |
|
328 | + } |
|
329 | + |
|
330 | + /** |
|
331 | + * @param string $input |
|
332 | + * @throws ResetPasswordException |
|
333 | + * @throws \OCP\PreConditionNotMetException |
|
334 | + */ |
|
335 | + protected function sendEmail($input) { |
|
336 | + $user = $this->findUserByIdOrMail($input); |
|
337 | + $email = $user->getEMailAddress(); |
|
338 | + |
|
339 | + if (empty($email)) { |
|
340 | + throw new ResetPasswordException('Could not send reset e-mail since there is no email for username ' . $input); |
|
341 | + } |
|
342 | + |
|
343 | + // Generate the token. It is stored encrypted in the database with the |
|
344 | + // secret being the users' email address appended with the system secret. |
|
345 | + // This makes the token automatically invalidate once the user changes |
|
346 | + // their email address. |
|
347 | + $token = $this->secureRandom->generate( |
|
348 | + 21, |
|
349 | + ISecureRandom::CHAR_DIGITS. |
|
350 | + ISecureRandom::CHAR_LOWER. |
|
351 | + ISecureRandom::CHAR_UPPER |
|
352 | + ); |
|
353 | + $tokenValue = $this->timeFactory->getTime() .':'. $token; |
|
354 | + $encryptedValue = $this->crypto->encrypt($tokenValue, $email . $this->config->getSystemValue('secret')); |
|
355 | + $this->config->setUserValue($user->getUID(), 'core', 'lostpassword', $encryptedValue); |
|
356 | + |
|
357 | + $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', ['userId' => $user->getUID(), 'token' => $token]); |
|
358 | + |
|
359 | + $emailTemplate = $this->mailer->createEMailTemplate('core.ResetPassword', [ |
|
360 | + 'link' => $link, |
|
361 | + ]); |
|
362 | + |
|
363 | + $emailTemplate->setSubject($this->l10n->t('%s password reset', [$this->defaults->getName()])); |
|
364 | + $emailTemplate->addHeader(); |
|
365 | + $emailTemplate->addHeading($this->l10n->t('Password reset')); |
|
366 | + |
|
367 | + $emailTemplate->addBodyText( |
|
368 | + htmlspecialchars($this->l10n->t('Click the following button to reset your password. If you have not requested the password reset, then ignore this email.')), |
|
369 | + $this->l10n->t('Click the following link to reset your password. If you have not requested the password reset, then ignore this email.') |
|
370 | + ); |
|
371 | + |
|
372 | + $emailTemplate->addBodyButton( |
|
373 | + htmlspecialchars($this->l10n->t('Reset your password')), |
|
374 | + $link, |
|
375 | + false |
|
376 | + ); |
|
377 | + $emailTemplate->addFooter(); |
|
378 | + |
|
379 | + try { |
|
380 | + $message = $this->mailer->createMessage(); |
|
381 | + $message->setTo([$email => $user->getUID()]); |
|
382 | + $message->setFrom([$this->from => $this->defaults->getName()]); |
|
383 | + $message->useTemplate($emailTemplate); |
|
384 | + $this->mailer->send($message); |
|
385 | + } catch (\Exception $e) { |
|
386 | + // Log the exception and continue |
|
387 | + $this->logger->logException($e); |
|
388 | + } |
|
389 | + } |
|
390 | + |
|
391 | + /** |
|
392 | + * @param string $input |
|
393 | + * @return IUser |
|
394 | + * @throws ResetPasswordException |
|
395 | + */ |
|
396 | + protected function findUserByIdOrMail($input) { |
|
397 | + $user = $this->userManager->get($input); |
|
398 | + if ($user instanceof IUser) { |
|
399 | + if (!$user->isEnabled()) { |
|
400 | + throw new ResetPasswordException('User is disabled'); |
|
401 | + } |
|
402 | + |
|
403 | + return $user; |
|
404 | + } |
|
405 | + |
|
406 | + $users = array_filter($this->userManager->getByEmail($input), function (IUser $user) { |
|
407 | + return $user->isEnabled(); |
|
408 | + }); |
|
409 | + |
|
410 | + if (count($users) === 1) { |
|
411 | + return reset($users); |
|
412 | + } |
|
413 | + |
|
414 | + throw new ResetPasswordException('Could not find user'); |
|
415 | + } |
|
416 | 416 | } |
@@ -41,143 +41,143 @@ |
||
41 | 41 | |
42 | 42 | class PreviewController extends Controller { |
43 | 43 | |
44 | - /** @var string */ |
|
45 | - private $userId; |
|
46 | - |
|
47 | - /** @var IRootFolder */ |
|
48 | - private $root; |
|
49 | - |
|
50 | - /** @var IPreview */ |
|
51 | - private $preview; |
|
52 | - |
|
53 | - /** |
|
54 | - * PreviewController constructor. |
|
55 | - * |
|
56 | - * @param string $appName |
|
57 | - * @param IRequest $request |
|
58 | - * @param IPreview $preview |
|
59 | - * @param IRootFolder $root |
|
60 | - * @param string $userId |
|
61 | - * @param ITimeFactory $timeFactory |
|
62 | - */ |
|
63 | - public function __construct(string $appName, |
|
64 | - IRequest $request, |
|
65 | - IPreview $preview, |
|
66 | - IRootFolder $root, |
|
67 | - ?string $userId |
|
68 | - ) { |
|
69 | - parent::__construct($appName, $request); |
|
70 | - |
|
71 | - $this->preview = $preview; |
|
72 | - $this->root = $root; |
|
73 | - $this->userId = $userId; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @NoAdminRequired |
|
78 | - * @NoCSRFRequired |
|
79 | - * |
|
80 | - * @param string $file |
|
81 | - * @param int $x |
|
82 | - * @param int $y |
|
83 | - * @param bool $a |
|
84 | - * @param bool $forceIcon |
|
85 | - * @param string $mode |
|
86 | - * @return DataResponse|FileDisplayResponse |
|
87 | - */ |
|
88 | - public function getPreview( |
|
89 | - string $file = '', |
|
90 | - int $x = 32, |
|
91 | - int $y = 32, |
|
92 | - bool $a = false, |
|
93 | - bool $forceIcon = true, |
|
94 | - string $mode = 'fill'): Http\Response { |
|
95 | - |
|
96 | - if ($file === '' || $x === 0 || $y === 0) { |
|
97 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
98 | - } |
|
99 | - |
|
100 | - try { |
|
101 | - $userFolder = $this->root->getUserFolder($this->userId); |
|
102 | - $node = $userFolder->get($file); |
|
103 | - } catch (NotFoundException $e) { |
|
104 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
105 | - } |
|
106 | - |
|
107 | - return $this->fetchPreview($node, $x, $y, $a, $forceIcon, $mode); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * @NoAdminRequired |
|
112 | - * @NoCSRFRequired |
|
113 | - * |
|
114 | - * @param int $fileId |
|
115 | - * @param int $x |
|
116 | - * @param int $y |
|
117 | - * @param bool $a |
|
118 | - * @param bool $forceIcon |
|
119 | - * @param string $mode |
|
120 | - * |
|
121 | - * @return DataResponse|FileDisplayResponse |
|
122 | - */ |
|
123 | - public function getPreviewByFileId( |
|
124 | - int $fileId = -1, |
|
125 | - int $x = 32, |
|
126 | - int $y = 32, |
|
127 | - bool $a = false, |
|
128 | - bool $forceIcon = true, |
|
129 | - string $mode = 'fill') { |
|
130 | - |
|
131 | - if ($fileId === -1 || $x === 0 || $y === 0) { |
|
132 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
133 | - } |
|
134 | - |
|
135 | - $userFolder = $this->root->getUserFolder($this->userId); |
|
136 | - $nodes = $userFolder->getById($fileId); |
|
137 | - |
|
138 | - if (\count($nodes) === 0) { |
|
139 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
140 | - } |
|
141 | - |
|
142 | - $node = array_pop($nodes); |
|
143 | - |
|
144 | - return $this->fetchPreview($node, $x, $y, $a, $forceIcon, $mode); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @param Node $node |
|
149 | - * @param int $x |
|
150 | - * @param int $y |
|
151 | - * @param bool $a |
|
152 | - * @param bool $forceIcon |
|
153 | - * @param string $mode |
|
154 | - * @return DataResponse|FileDisplayResponse |
|
155 | - */ |
|
156 | - private function fetchPreview( |
|
157 | - Node $node, |
|
158 | - int $x, |
|
159 | - int $y, |
|
160 | - bool $a = false, |
|
161 | - bool $forceIcon = true, |
|
162 | - string $mode) : Http\Response { |
|
163 | - |
|
164 | - if (!($node instanceof File) || (!$forceIcon && !$this->preview->isAvailable($node))) { |
|
165 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
166 | - } |
|
167 | - if (!$node->isReadable()) { |
|
168 | - return new DataResponse([], Http::STATUS_FORBIDDEN); |
|
169 | - } |
|
170 | - |
|
171 | - try { |
|
172 | - $f = $this->preview->getPreview($node, $x, $y, !$a, $mode); |
|
173 | - $response = new FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]); |
|
174 | - $response->cacheFor(3600 * 24); |
|
175 | - return $response; |
|
176 | - } catch (NotFoundException $e) { |
|
177 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
178 | - } catch (\InvalidArgumentException $e) { |
|
179 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
180 | - } |
|
181 | - |
|
182 | - } |
|
44 | + /** @var string */ |
|
45 | + private $userId; |
|
46 | + |
|
47 | + /** @var IRootFolder */ |
|
48 | + private $root; |
|
49 | + |
|
50 | + /** @var IPreview */ |
|
51 | + private $preview; |
|
52 | + |
|
53 | + /** |
|
54 | + * PreviewController constructor. |
|
55 | + * |
|
56 | + * @param string $appName |
|
57 | + * @param IRequest $request |
|
58 | + * @param IPreview $preview |
|
59 | + * @param IRootFolder $root |
|
60 | + * @param string $userId |
|
61 | + * @param ITimeFactory $timeFactory |
|
62 | + */ |
|
63 | + public function __construct(string $appName, |
|
64 | + IRequest $request, |
|
65 | + IPreview $preview, |
|
66 | + IRootFolder $root, |
|
67 | + ?string $userId |
|
68 | + ) { |
|
69 | + parent::__construct($appName, $request); |
|
70 | + |
|
71 | + $this->preview = $preview; |
|
72 | + $this->root = $root; |
|
73 | + $this->userId = $userId; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @NoAdminRequired |
|
78 | + * @NoCSRFRequired |
|
79 | + * |
|
80 | + * @param string $file |
|
81 | + * @param int $x |
|
82 | + * @param int $y |
|
83 | + * @param bool $a |
|
84 | + * @param bool $forceIcon |
|
85 | + * @param string $mode |
|
86 | + * @return DataResponse|FileDisplayResponse |
|
87 | + */ |
|
88 | + public function getPreview( |
|
89 | + string $file = '', |
|
90 | + int $x = 32, |
|
91 | + int $y = 32, |
|
92 | + bool $a = false, |
|
93 | + bool $forceIcon = true, |
|
94 | + string $mode = 'fill'): Http\Response { |
|
95 | + |
|
96 | + if ($file === '' || $x === 0 || $y === 0) { |
|
97 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
98 | + } |
|
99 | + |
|
100 | + try { |
|
101 | + $userFolder = $this->root->getUserFolder($this->userId); |
|
102 | + $node = $userFolder->get($file); |
|
103 | + } catch (NotFoundException $e) { |
|
104 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
105 | + } |
|
106 | + |
|
107 | + return $this->fetchPreview($node, $x, $y, $a, $forceIcon, $mode); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * @NoAdminRequired |
|
112 | + * @NoCSRFRequired |
|
113 | + * |
|
114 | + * @param int $fileId |
|
115 | + * @param int $x |
|
116 | + * @param int $y |
|
117 | + * @param bool $a |
|
118 | + * @param bool $forceIcon |
|
119 | + * @param string $mode |
|
120 | + * |
|
121 | + * @return DataResponse|FileDisplayResponse |
|
122 | + */ |
|
123 | + public function getPreviewByFileId( |
|
124 | + int $fileId = -1, |
|
125 | + int $x = 32, |
|
126 | + int $y = 32, |
|
127 | + bool $a = false, |
|
128 | + bool $forceIcon = true, |
|
129 | + string $mode = 'fill') { |
|
130 | + |
|
131 | + if ($fileId === -1 || $x === 0 || $y === 0) { |
|
132 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
133 | + } |
|
134 | + |
|
135 | + $userFolder = $this->root->getUserFolder($this->userId); |
|
136 | + $nodes = $userFolder->getById($fileId); |
|
137 | + |
|
138 | + if (\count($nodes) === 0) { |
|
139 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
140 | + } |
|
141 | + |
|
142 | + $node = array_pop($nodes); |
|
143 | + |
|
144 | + return $this->fetchPreview($node, $x, $y, $a, $forceIcon, $mode); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @param Node $node |
|
149 | + * @param int $x |
|
150 | + * @param int $y |
|
151 | + * @param bool $a |
|
152 | + * @param bool $forceIcon |
|
153 | + * @param string $mode |
|
154 | + * @return DataResponse|FileDisplayResponse |
|
155 | + */ |
|
156 | + private function fetchPreview( |
|
157 | + Node $node, |
|
158 | + int $x, |
|
159 | + int $y, |
|
160 | + bool $a = false, |
|
161 | + bool $forceIcon = true, |
|
162 | + string $mode) : Http\Response { |
|
163 | + |
|
164 | + if (!($node instanceof File) || (!$forceIcon && !$this->preview->isAvailable($node))) { |
|
165 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
166 | + } |
|
167 | + if (!$node->isReadable()) { |
|
168 | + return new DataResponse([], Http::STATUS_FORBIDDEN); |
|
169 | + } |
|
170 | + |
|
171 | + try { |
|
172 | + $f = $this->preview->getPreview($node, $x, $y, !$a, $mode); |
|
173 | + $response = new FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]); |
|
174 | + $response->cacheFor(3600 * 24); |
|
175 | + return $response; |
|
176 | + } catch (NotFoundException $e) { |
|
177 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
178 | + } catch (\InvalidArgumentException $e) { |
|
179 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
180 | + } |
|
181 | + |
|
182 | + } |
|
183 | 183 | } |