@@ -36,22 +36,22 @@ |
||
36 | 36 | */ |
37 | 37 | class Version0002Date20200902144824 extends SimpleMigrationStep { |
38 | 38 | |
39 | - /** |
|
40 | - * @param IOutput $output |
|
41 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
42 | - * @param array $options |
|
43 | - * @return null|ISchemaWrapper |
|
44 | - * @since 20.0.0 |
|
45 | - */ |
|
46 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
47 | - /** @var ISchemaWrapper $schema */ |
|
48 | - $schema = $schemaClosure(); |
|
49 | - |
|
50 | - $statusTable = $schema->getTable('user_status'); |
|
51 | - |
|
52 | - $statusTable->addIndex(['status_timestamp'], 'user_status_tstmp_ix'); |
|
53 | - $statusTable->addIndex(['is_user_defined', 'status'], 'user_status_iud_ix'); |
|
54 | - |
|
55 | - return $schema; |
|
56 | - } |
|
39 | + /** |
|
40 | + * @param IOutput $output |
|
41 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
42 | + * @param array $options |
|
43 | + * @return null|ISchemaWrapper |
|
44 | + * @since 20.0.0 |
|
45 | + */ |
|
46 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
47 | + /** @var ISchemaWrapper $schema */ |
|
48 | + $schema = $schemaClosure(); |
|
49 | + |
|
50 | + $statusTable = $schema->getTable('user_status'); |
|
51 | + |
|
52 | + $statusTable->addIndex(['status_timestamp'], 'user_status_tstmp_ix'); |
|
53 | + $statusTable->addIndex(['is_user_defined', 'status'], 'user_status_iud_ix'); |
|
54 | + |
|
55 | + return $schema; |
|
56 | + } |
|
57 | 57 | } |
@@ -25,45 +25,45 @@ |
||
25 | 25 | namespace OCA\Files\Activity\Settings; |
26 | 26 | |
27 | 27 | class FileChanged extends FileActivitySettings { |
28 | - /** |
|
29 | - * @return string Lowercase a-z and underscore only identifier |
|
30 | - * @since 11.0.0 |
|
31 | - */ |
|
32 | - public function getIdentifier() { |
|
33 | - return 'file_changed'; |
|
34 | - } |
|
28 | + /** |
|
29 | + * @return string Lowercase a-z and underscore only identifier |
|
30 | + * @since 11.0.0 |
|
31 | + */ |
|
32 | + public function getIdentifier() { |
|
33 | + return 'file_changed'; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @return string A translated string |
|
38 | - * @since 11.0.0 |
|
39 | - */ |
|
40 | - public function getName() { |
|
41 | - return $this->l->t('A file or folder has been <strong>changed</strong>'); |
|
42 | - } |
|
36 | + /** |
|
37 | + * @return string A translated string |
|
38 | + * @since 11.0.0 |
|
39 | + */ |
|
40 | + public function getName() { |
|
41 | + return $this->l->t('A file or folder has been <strong>changed</strong>'); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @return int whether the filter should be rather on the top or bottom of |
|
46 | - * the admin section. The filters are arranged in ascending order of the |
|
47 | - * priority values. It is required to return a value between 0 and 100. |
|
48 | - * @since 11.0.0 |
|
49 | - */ |
|
50 | - public function getPriority() { |
|
51 | - return 2; |
|
52 | - } |
|
44 | + /** |
|
45 | + * @return int whether the filter should be rather on the top or bottom of |
|
46 | + * the admin section. The filters are arranged in ascending order of the |
|
47 | + * priority values. It is required to return a value between 0 and 100. |
|
48 | + * @since 11.0.0 |
|
49 | + */ |
|
50 | + public function getPriority() { |
|
51 | + return 2; |
|
52 | + } |
|
53 | 53 | |
54 | - public function canChangeMail() { |
|
55 | - return true; |
|
56 | - } |
|
54 | + public function canChangeMail() { |
|
55 | + return true; |
|
56 | + } |
|
57 | 57 | |
58 | - public function isDefaultEnabledMail() { |
|
59 | - return false; |
|
60 | - } |
|
58 | + public function isDefaultEnabledMail() { |
|
59 | + return false; |
|
60 | + } |
|
61 | 61 | |
62 | - public function canChangeNotification() { |
|
63 | - return true; |
|
64 | - } |
|
62 | + public function canChangeNotification() { |
|
63 | + return true; |
|
64 | + } |
|
65 | 65 | |
66 | - public function isDefaultEnabledNotification() { |
|
67 | - return false; |
|
68 | - } |
|
66 | + public function isDefaultEnabledNotification() { |
|
67 | + return false; |
|
68 | + } |
|
69 | 69 | } |
@@ -34,15 +34,15 @@ |
||
34 | 34 | * @since 15.0.0 |
35 | 35 | */ |
36 | 36 | interface IWriteStreamStorage extends IStorage { |
37 | - /** |
|
38 | - * Write the data from a stream to a file |
|
39 | - * |
|
40 | - * @param string $path |
|
41 | - * @param resource $stream |
|
42 | - * @param int|null $size the size of the stream if known in advance |
|
43 | - * @return int the number of bytes written |
|
44 | - * @throws GenericFileException |
|
45 | - * @since 15.0.0 |
|
46 | - */ |
|
47 | - public function writeStream(string $path, $stream, int $size = null): int; |
|
37 | + /** |
|
38 | + * Write the data from a stream to a file |
|
39 | + * |
|
40 | + * @param string $path |
|
41 | + * @param resource $stream |
|
42 | + * @param int|null $size the size of the stream if known in advance |
|
43 | + * @return int the number of bytes written |
|
44 | + * @throws GenericFileException |
|
45 | + * @since 15.0.0 |
|
46 | + */ |
|
47 | + public function writeStream(string $path, $stream, int $size = null): int; |
|
48 | 48 | } |
@@ -35,143 +35,143 @@ |
||
35 | 35 | * @since 6.0.0 |
36 | 36 | */ |
37 | 37 | interface IManager { |
38 | - /** |
|
39 | - * Generates a new IEvent object |
|
40 | - * |
|
41 | - * Make sure to call at least the following methods before sending it to the |
|
42 | - * app with via the publish() method: |
|
43 | - * - setApp() |
|
44 | - * - setType() |
|
45 | - * - setAffectedUser() |
|
46 | - * - setSubject() |
|
47 | - * - setObject() |
|
48 | - * |
|
49 | - * @return IEvent |
|
50 | - * @since 8.2.0 |
|
51 | - */ |
|
52 | - public function generateEvent(): IEvent; |
|
53 | - |
|
54 | - /** |
|
55 | - * Publish an event to the activity consumers |
|
56 | - * |
|
57 | - * Make sure to call at least the following methods before sending an Event: |
|
58 | - * - setApp() |
|
59 | - * - setType() |
|
60 | - * - setAffectedUser() |
|
61 | - * - setSubject() |
|
62 | - * - setObject() |
|
63 | - * |
|
64 | - * @param IEvent $event |
|
65 | - * @throws \BadMethodCallException if required values have not been set |
|
66 | - * @since 8.2.0 |
|
67 | - */ |
|
68 | - public function publish(IEvent $event): void; |
|
69 | - |
|
70 | - /** |
|
71 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
72 | - * activity consumers are actually requested |
|
73 | - * |
|
74 | - * $callable has to return an instance of \OCP\Activity\IConsumer |
|
75 | - * |
|
76 | - * @param \Closure $callable |
|
77 | - * @since 6.0.0 |
|
78 | - */ |
|
79 | - public function registerConsumer(\Closure $callable): void; |
|
80 | - |
|
81 | - /** |
|
82 | - * @param string $filter Class must implement OCA\Activity\IFilter |
|
83 | - * @since 11.0.0 |
|
84 | - */ |
|
85 | - public function registerFilter(string $filter): void; |
|
86 | - |
|
87 | - /** |
|
88 | - * @return IFilter[] |
|
89 | - * @since 11.0.0 |
|
90 | - */ |
|
91 | - public function getFilters(): array; |
|
92 | - |
|
93 | - /** |
|
94 | - * @param string $id |
|
95 | - * @return IFilter |
|
96 | - * @throws \InvalidArgumentException when the filter was not found |
|
97 | - * @since 11.0.0 |
|
98 | - */ |
|
99 | - public function getFilterById(string $id): IFilter; |
|
100 | - |
|
101 | - /** |
|
102 | - * @param string $setting Class must implement OCA\Activity\ISetting |
|
103 | - * @since 11.0.0 |
|
104 | - */ |
|
105 | - public function registerSetting(string $setting): void; |
|
106 | - |
|
107 | - /** |
|
108 | - * @return ActivitySettings[] |
|
109 | - * @since 11.0.0 |
|
110 | - */ |
|
111 | - public function getSettings(): array; |
|
112 | - |
|
113 | - /** |
|
114 | - * @param string $provider Class must implement OCA\Activity\IProvider |
|
115 | - * @since 11.0.0 |
|
116 | - */ |
|
117 | - public function registerProvider(string $provider): void; |
|
118 | - |
|
119 | - /** |
|
120 | - * @return IProvider[] |
|
121 | - * @since 11.0.0 |
|
122 | - */ |
|
123 | - public function getProviders(): array; |
|
124 | - |
|
125 | - /** |
|
126 | - * @param string $id |
|
127 | - * @return ActivitySettings |
|
128 | - * @throws \InvalidArgumentException when the setting was not found |
|
129 | - * @since 11.0.0 |
|
130 | - */ |
|
131 | - public function getSettingById(string $id): ActivitySettings; |
|
132 | - |
|
133 | - /** |
|
134 | - * @param string $type |
|
135 | - * @param int $id |
|
136 | - * @since 8.2.0 |
|
137 | - */ |
|
138 | - public function setFormattingObject(string $type, int $id): void; |
|
139 | - |
|
140 | - /** |
|
141 | - * @return bool |
|
142 | - * @since 8.2.0 |
|
143 | - */ |
|
144 | - public function isFormattingFilteredObject(): bool; |
|
145 | - |
|
146 | - /** |
|
147 | - * @param bool $status Set to true, when parsing events should not use SVG icons |
|
148 | - * @since 12.0.1 |
|
149 | - */ |
|
150 | - public function setRequirePNG(bool $status): void; |
|
151 | - |
|
152 | - /** |
|
153 | - * @return bool |
|
154 | - * @since 12.0.1 |
|
155 | - */ |
|
156 | - public function getRequirePNG(): bool; |
|
157 | - |
|
158 | - /** |
|
159 | - * Set the user we need to use |
|
160 | - * |
|
161 | - * @param string|null $currentUserId |
|
162 | - * @throws \UnexpectedValueException If the user is invalid |
|
163 | - * @since 9.0.1 |
|
164 | - */ |
|
165 | - public function setCurrentUserId(string $currentUserId = null): void; |
|
166 | - |
|
167 | - /** |
|
168 | - * Get the user we need to use |
|
169 | - * |
|
170 | - * Either the user is logged in, or we try to get it from the token |
|
171 | - * |
|
172 | - * @return string |
|
173 | - * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
174 | - * @since 8.1.0 |
|
175 | - */ |
|
176 | - public function getCurrentUserId(): string; |
|
38 | + /** |
|
39 | + * Generates a new IEvent object |
|
40 | + * |
|
41 | + * Make sure to call at least the following methods before sending it to the |
|
42 | + * app with via the publish() method: |
|
43 | + * - setApp() |
|
44 | + * - setType() |
|
45 | + * - setAffectedUser() |
|
46 | + * - setSubject() |
|
47 | + * - setObject() |
|
48 | + * |
|
49 | + * @return IEvent |
|
50 | + * @since 8.2.0 |
|
51 | + */ |
|
52 | + public function generateEvent(): IEvent; |
|
53 | + |
|
54 | + /** |
|
55 | + * Publish an event to the activity consumers |
|
56 | + * |
|
57 | + * Make sure to call at least the following methods before sending an Event: |
|
58 | + * - setApp() |
|
59 | + * - setType() |
|
60 | + * - setAffectedUser() |
|
61 | + * - setSubject() |
|
62 | + * - setObject() |
|
63 | + * |
|
64 | + * @param IEvent $event |
|
65 | + * @throws \BadMethodCallException if required values have not been set |
|
66 | + * @since 8.2.0 |
|
67 | + */ |
|
68 | + public function publish(IEvent $event): void; |
|
69 | + |
|
70 | + /** |
|
71 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
72 | + * activity consumers are actually requested |
|
73 | + * |
|
74 | + * $callable has to return an instance of \OCP\Activity\IConsumer |
|
75 | + * |
|
76 | + * @param \Closure $callable |
|
77 | + * @since 6.0.0 |
|
78 | + */ |
|
79 | + public function registerConsumer(\Closure $callable): void; |
|
80 | + |
|
81 | + /** |
|
82 | + * @param string $filter Class must implement OCA\Activity\IFilter |
|
83 | + * @since 11.0.0 |
|
84 | + */ |
|
85 | + public function registerFilter(string $filter): void; |
|
86 | + |
|
87 | + /** |
|
88 | + * @return IFilter[] |
|
89 | + * @since 11.0.0 |
|
90 | + */ |
|
91 | + public function getFilters(): array; |
|
92 | + |
|
93 | + /** |
|
94 | + * @param string $id |
|
95 | + * @return IFilter |
|
96 | + * @throws \InvalidArgumentException when the filter was not found |
|
97 | + * @since 11.0.0 |
|
98 | + */ |
|
99 | + public function getFilterById(string $id): IFilter; |
|
100 | + |
|
101 | + /** |
|
102 | + * @param string $setting Class must implement OCA\Activity\ISetting |
|
103 | + * @since 11.0.0 |
|
104 | + */ |
|
105 | + public function registerSetting(string $setting): void; |
|
106 | + |
|
107 | + /** |
|
108 | + * @return ActivitySettings[] |
|
109 | + * @since 11.0.0 |
|
110 | + */ |
|
111 | + public function getSettings(): array; |
|
112 | + |
|
113 | + /** |
|
114 | + * @param string $provider Class must implement OCA\Activity\IProvider |
|
115 | + * @since 11.0.0 |
|
116 | + */ |
|
117 | + public function registerProvider(string $provider): void; |
|
118 | + |
|
119 | + /** |
|
120 | + * @return IProvider[] |
|
121 | + * @since 11.0.0 |
|
122 | + */ |
|
123 | + public function getProviders(): array; |
|
124 | + |
|
125 | + /** |
|
126 | + * @param string $id |
|
127 | + * @return ActivitySettings |
|
128 | + * @throws \InvalidArgumentException when the setting was not found |
|
129 | + * @since 11.0.0 |
|
130 | + */ |
|
131 | + public function getSettingById(string $id): ActivitySettings; |
|
132 | + |
|
133 | + /** |
|
134 | + * @param string $type |
|
135 | + * @param int $id |
|
136 | + * @since 8.2.0 |
|
137 | + */ |
|
138 | + public function setFormattingObject(string $type, int $id): void; |
|
139 | + |
|
140 | + /** |
|
141 | + * @return bool |
|
142 | + * @since 8.2.0 |
|
143 | + */ |
|
144 | + public function isFormattingFilteredObject(): bool; |
|
145 | + |
|
146 | + /** |
|
147 | + * @param bool $status Set to true, when parsing events should not use SVG icons |
|
148 | + * @since 12.0.1 |
|
149 | + */ |
|
150 | + public function setRequirePNG(bool $status): void; |
|
151 | + |
|
152 | + /** |
|
153 | + * @return bool |
|
154 | + * @since 12.0.1 |
|
155 | + */ |
|
156 | + public function getRequirePNG(): bool; |
|
157 | + |
|
158 | + /** |
|
159 | + * Set the user we need to use |
|
160 | + * |
|
161 | + * @param string|null $currentUserId |
|
162 | + * @throws \UnexpectedValueException If the user is invalid |
|
163 | + * @since 9.0.1 |
|
164 | + */ |
|
165 | + public function setCurrentUserId(string $currentUserId = null): void; |
|
166 | + |
|
167 | + /** |
|
168 | + * Get the user we need to use |
|
169 | + * |
|
170 | + * Either the user is logged in, or we try to get it from the token |
|
171 | + * |
|
172 | + * @return string |
|
173 | + * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
174 | + * @since 8.1.0 |
|
175 | + */ |
|
176 | + public function getCurrentUserId(): string; |
|
177 | 177 | } |
@@ -24,30 +24,30 @@ |
||
24 | 24 | namespace OC\Files\Cache; |
25 | 25 | |
26 | 26 | class NullWatcher extends Watcher { |
27 | - private $policy; |
|
27 | + private $policy; |
|
28 | 28 | |
29 | - public function __construct() { |
|
30 | - } |
|
29 | + public function __construct() { |
|
30 | + } |
|
31 | 31 | |
32 | - public function setPolicy($policy) { |
|
33 | - $this->policy = $policy; |
|
34 | - } |
|
32 | + public function setPolicy($policy) { |
|
33 | + $this->policy = $policy; |
|
34 | + } |
|
35 | 35 | |
36 | - public function getPolicy() { |
|
37 | - return $this->policy; |
|
38 | - } |
|
36 | + public function getPolicy() { |
|
37 | + return $this->policy; |
|
38 | + } |
|
39 | 39 | |
40 | - public function checkUpdate($path, $cachedEntry = null) { |
|
41 | - return false; |
|
42 | - } |
|
40 | + public function checkUpdate($path, $cachedEntry = null) { |
|
41 | + return false; |
|
42 | + } |
|
43 | 43 | |
44 | - public function update($path, $cachedData) { |
|
45 | - } |
|
44 | + public function update($path, $cachedData) { |
|
45 | + } |
|
46 | 46 | |
47 | - public function needsUpdate($path, $cachedData) { |
|
48 | - return false; |
|
49 | - } |
|
47 | + public function needsUpdate($path, $cachedData) { |
|
48 | + return false; |
|
49 | + } |
|
50 | 50 | |
51 | - public function cleanFolder($path) { |
|
52 | - } |
|
51 | + public function cleanFolder($path) { |
|
52 | + } |
|
53 | 53 | } |
@@ -27,146 +27,146 @@ |
||
27 | 27 | |
28 | 28 | class RequestRemoteAddress implements ICheck { |
29 | 29 | |
30 | - /** @var IL10N */ |
|
31 | - protected $l; |
|
32 | - |
|
33 | - /** @var IRequest */ |
|
34 | - protected $request; |
|
35 | - |
|
36 | - /** |
|
37 | - * @param IL10N $l |
|
38 | - * @param IRequest $request |
|
39 | - */ |
|
40 | - public function __construct(IL10N $l, IRequest $request) { |
|
41 | - $this->l = $l; |
|
42 | - $this->request = $request; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * @param string $operator |
|
47 | - * @param string $value |
|
48 | - * @return bool |
|
49 | - */ |
|
50 | - public function executeCheck($operator, $value) { |
|
51 | - $actualValue = $this->request->getRemoteAddress(); |
|
52 | - $decodedValue = explode('/', $value); |
|
53 | - |
|
54 | - if ($operator === 'matchesIPv4') { |
|
55 | - return $this->matchIPv4($actualValue, $decodedValue[0], $decodedValue[1]); |
|
56 | - } elseif ($operator === '!matchesIPv4') { |
|
57 | - return !$this->matchIPv4($actualValue, $decodedValue[0], $decodedValue[1]); |
|
58 | - } elseif ($operator === 'matchesIPv6') { |
|
59 | - return $this->matchIPv6($actualValue, $decodedValue[0], $decodedValue[1]); |
|
60 | - } else { |
|
61 | - return !$this->matchIPv6($actualValue, $decodedValue[0], $decodedValue[1]); |
|
62 | - } |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * @param string $operator |
|
67 | - * @param string $value |
|
68 | - * @throws \UnexpectedValueException |
|
69 | - */ |
|
70 | - public function validateCheck($operator, $value) { |
|
71 | - if (!in_array($operator, ['matchesIPv4', '!matchesIPv4', 'matchesIPv6', '!matchesIPv6'])) { |
|
72 | - throw new \UnexpectedValueException($this->l->t('The given operator is invalid'), 1); |
|
73 | - } |
|
74 | - |
|
75 | - $decodedValue = explode('/', $value); |
|
76 | - if (count($decodedValue) !== 2) { |
|
77 | - throw new \UnexpectedValueException($this->l->t('The given IP range is invalid'), 2); |
|
78 | - } |
|
79 | - |
|
80 | - if (in_array($operator, ['matchesIPv4', '!matchesIPv4'])) { |
|
81 | - if (!filter_var($decodedValue[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { |
|
82 | - throw new \UnexpectedValueException($this->l->t('The given IP range is not valid for IPv4'), 3); |
|
83 | - } |
|
84 | - if ($decodedValue[1] > 32 || $decodedValue[1] <= 0) { |
|
85 | - throw new \UnexpectedValueException($this->l->t('The given IP range is not valid for IPv4'), 4); |
|
86 | - } |
|
87 | - } else { |
|
88 | - if (!filter_var($decodedValue[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { |
|
89 | - throw new \UnexpectedValueException($this->l->t('The given IP range is not valid for IPv6'), 3); |
|
90 | - } |
|
91 | - if ($decodedValue[1] > 128 || $decodedValue[1] <= 0) { |
|
92 | - throw new \UnexpectedValueException($this->l->t('The given IP range is not valid for IPv6'), 4); |
|
93 | - } |
|
94 | - } |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Based on https://stackoverflow.com/a/594134 |
|
99 | - * @param string $ip |
|
100 | - * @param string $rangeIp |
|
101 | - * @param int $bits |
|
102 | - * @return bool |
|
103 | - */ |
|
104 | - protected function matchIPv4($ip, $rangeIp, $bits) { |
|
105 | - $rangeDecimal = ip2long($rangeIp); |
|
106 | - $ipDecimal = ip2long($ip); |
|
107 | - $mask = -1 << (32 - $bits); |
|
108 | - return ($ipDecimal & $mask) === ($rangeDecimal & $mask); |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Based on https://stackoverflow.com/a/7951507 |
|
113 | - * @param string $ip |
|
114 | - * @param string $rangeIp |
|
115 | - * @param int $bits |
|
116 | - * @return bool |
|
117 | - */ |
|
118 | - protected function matchIPv6($ip, $rangeIp, $bits) { |
|
119 | - $ipNet = inet_pton($ip); |
|
120 | - $binaryIp = $this->ipv6ToBits($ipNet); |
|
121 | - $ipNetBits = substr($binaryIp, 0, $bits); |
|
122 | - |
|
123 | - $rangeNet = inet_pton($rangeIp); |
|
124 | - $binaryRange = $this->ipv6ToBits($rangeNet); |
|
125 | - $rangeNetBits = substr($binaryRange, 0, $bits); |
|
126 | - |
|
127 | - return $ipNetBits === $rangeNetBits; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Based on https://stackoverflow.com/a/7951507 |
|
132 | - * @param string $packedIp |
|
133 | - * @return string |
|
134 | - */ |
|
135 | - protected function ipv6ToBits($packedIp) { |
|
136 | - $unpackedIp = unpack('A16', $packedIp); |
|
137 | - $unpackedIp = str_split($unpackedIp[1]); |
|
138 | - $binaryIp = ''; |
|
139 | - foreach ($unpackedIp as $char) { |
|
140 | - $binaryIp .= str_pad(decbin(ord($char)), 8, '0', STR_PAD_LEFT); |
|
141 | - } |
|
142 | - return str_pad($binaryIp, 128, '0', STR_PAD_RIGHT); |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * returns a list of Entities the checker supports. The values must match |
|
147 | - * the class name of the entity. |
|
148 | - * |
|
149 | - * An empty result means the check is universally available. |
|
150 | - * |
|
151 | - * @since 18.0.0 |
|
152 | - */ |
|
153 | - public function supportedEntities(): array { |
|
154 | - return []; |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * returns whether the operation can be used in the requested scope. |
|
159 | - * |
|
160 | - * Scope IDs are defined as constants in OCP\WorkflowEngine\IManager. At |
|
161 | - * time of writing these are SCOPE_ADMIN and SCOPE_USER. |
|
162 | - * |
|
163 | - * For possibly unknown future scopes the recommended behaviour is: if |
|
164 | - * user scope is permitted, the default behaviour should return `true`, |
|
165 | - * otherwise `false`. |
|
166 | - * |
|
167 | - * @since 18.0.0 |
|
168 | - */ |
|
169 | - public function isAvailableForScope(int $scope): bool { |
|
170 | - return true; |
|
171 | - } |
|
30 | + /** @var IL10N */ |
|
31 | + protected $l; |
|
32 | + |
|
33 | + /** @var IRequest */ |
|
34 | + protected $request; |
|
35 | + |
|
36 | + /** |
|
37 | + * @param IL10N $l |
|
38 | + * @param IRequest $request |
|
39 | + */ |
|
40 | + public function __construct(IL10N $l, IRequest $request) { |
|
41 | + $this->l = $l; |
|
42 | + $this->request = $request; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * @param string $operator |
|
47 | + * @param string $value |
|
48 | + * @return bool |
|
49 | + */ |
|
50 | + public function executeCheck($operator, $value) { |
|
51 | + $actualValue = $this->request->getRemoteAddress(); |
|
52 | + $decodedValue = explode('/', $value); |
|
53 | + |
|
54 | + if ($operator === 'matchesIPv4') { |
|
55 | + return $this->matchIPv4($actualValue, $decodedValue[0], $decodedValue[1]); |
|
56 | + } elseif ($operator === '!matchesIPv4') { |
|
57 | + return !$this->matchIPv4($actualValue, $decodedValue[0], $decodedValue[1]); |
|
58 | + } elseif ($operator === 'matchesIPv6') { |
|
59 | + return $this->matchIPv6($actualValue, $decodedValue[0], $decodedValue[1]); |
|
60 | + } else { |
|
61 | + return !$this->matchIPv6($actualValue, $decodedValue[0], $decodedValue[1]); |
|
62 | + } |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * @param string $operator |
|
67 | + * @param string $value |
|
68 | + * @throws \UnexpectedValueException |
|
69 | + */ |
|
70 | + public function validateCheck($operator, $value) { |
|
71 | + if (!in_array($operator, ['matchesIPv4', '!matchesIPv4', 'matchesIPv6', '!matchesIPv6'])) { |
|
72 | + throw new \UnexpectedValueException($this->l->t('The given operator is invalid'), 1); |
|
73 | + } |
|
74 | + |
|
75 | + $decodedValue = explode('/', $value); |
|
76 | + if (count($decodedValue) !== 2) { |
|
77 | + throw new \UnexpectedValueException($this->l->t('The given IP range is invalid'), 2); |
|
78 | + } |
|
79 | + |
|
80 | + if (in_array($operator, ['matchesIPv4', '!matchesIPv4'])) { |
|
81 | + if (!filter_var($decodedValue[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { |
|
82 | + throw new \UnexpectedValueException($this->l->t('The given IP range is not valid for IPv4'), 3); |
|
83 | + } |
|
84 | + if ($decodedValue[1] > 32 || $decodedValue[1] <= 0) { |
|
85 | + throw new \UnexpectedValueException($this->l->t('The given IP range is not valid for IPv4'), 4); |
|
86 | + } |
|
87 | + } else { |
|
88 | + if (!filter_var($decodedValue[0], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { |
|
89 | + throw new \UnexpectedValueException($this->l->t('The given IP range is not valid for IPv6'), 3); |
|
90 | + } |
|
91 | + if ($decodedValue[1] > 128 || $decodedValue[1] <= 0) { |
|
92 | + throw new \UnexpectedValueException($this->l->t('The given IP range is not valid for IPv6'), 4); |
|
93 | + } |
|
94 | + } |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Based on https://stackoverflow.com/a/594134 |
|
99 | + * @param string $ip |
|
100 | + * @param string $rangeIp |
|
101 | + * @param int $bits |
|
102 | + * @return bool |
|
103 | + */ |
|
104 | + protected function matchIPv4($ip, $rangeIp, $bits) { |
|
105 | + $rangeDecimal = ip2long($rangeIp); |
|
106 | + $ipDecimal = ip2long($ip); |
|
107 | + $mask = -1 << (32 - $bits); |
|
108 | + return ($ipDecimal & $mask) === ($rangeDecimal & $mask); |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Based on https://stackoverflow.com/a/7951507 |
|
113 | + * @param string $ip |
|
114 | + * @param string $rangeIp |
|
115 | + * @param int $bits |
|
116 | + * @return bool |
|
117 | + */ |
|
118 | + protected function matchIPv6($ip, $rangeIp, $bits) { |
|
119 | + $ipNet = inet_pton($ip); |
|
120 | + $binaryIp = $this->ipv6ToBits($ipNet); |
|
121 | + $ipNetBits = substr($binaryIp, 0, $bits); |
|
122 | + |
|
123 | + $rangeNet = inet_pton($rangeIp); |
|
124 | + $binaryRange = $this->ipv6ToBits($rangeNet); |
|
125 | + $rangeNetBits = substr($binaryRange, 0, $bits); |
|
126 | + |
|
127 | + return $ipNetBits === $rangeNetBits; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Based on https://stackoverflow.com/a/7951507 |
|
132 | + * @param string $packedIp |
|
133 | + * @return string |
|
134 | + */ |
|
135 | + protected function ipv6ToBits($packedIp) { |
|
136 | + $unpackedIp = unpack('A16', $packedIp); |
|
137 | + $unpackedIp = str_split($unpackedIp[1]); |
|
138 | + $binaryIp = ''; |
|
139 | + foreach ($unpackedIp as $char) { |
|
140 | + $binaryIp .= str_pad(decbin(ord($char)), 8, '0', STR_PAD_LEFT); |
|
141 | + } |
|
142 | + return str_pad($binaryIp, 128, '0', STR_PAD_RIGHT); |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * returns a list of Entities the checker supports. The values must match |
|
147 | + * the class name of the entity. |
|
148 | + * |
|
149 | + * An empty result means the check is universally available. |
|
150 | + * |
|
151 | + * @since 18.0.0 |
|
152 | + */ |
|
153 | + public function supportedEntities(): array { |
|
154 | + return []; |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * returns whether the operation can be used in the requested scope. |
|
159 | + * |
|
160 | + * Scope IDs are defined as constants in OCP\WorkflowEngine\IManager. At |
|
161 | + * time of writing these are SCOPE_ADMIN and SCOPE_USER. |
|
162 | + * |
|
163 | + * For possibly unknown future scopes the recommended behaviour is: if |
|
164 | + * user scope is permitted, the default behaviour should return `true`, |
|
165 | + * otherwise `false`. |
|
166 | + * |
|
167 | + * @since 18.0.0 |
|
168 | + */ |
|
169 | + public function isAvailableForScope(int $scope): bool { |
|
170 | + return true; |
|
171 | + } |
|
172 | 172 | } |
@@ -32,41 +32,41 @@ |
||
32 | 32 | * @since 20.0.0 |
33 | 33 | */ |
34 | 34 | class GetQuotaEvent extends Event { |
35 | - /** @var IUser */ |
|
36 | - private $user; |
|
37 | - /** @var string|null */ |
|
38 | - private $quota = null; |
|
35 | + /** @var IUser */ |
|
36 | + private $user; |
|
37 | + /** @var string|null */ |
|
38 | + private $quota = null; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @since 20.0.0 |
|
42 | - */ |
|
43 | - public function __construct(IUser $user) { |
|
44 | - parent::__construct(); |
|
45 | - $this->user = $user; |
|
46 | - } |
|
40 | + /** |
|
41 | + * @since 20.0.0 |
|
42 | + */ |
|
43 | + public function __construct(IUser $user) { |
|
44 | + parent::__construct(); |
|
45 | + $this->user = $user; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @since 20.0.0 |
|
50 | - */ |
|
51 | - public function getUser(): IUser { |
|
52 | - return $this->user; |
|
53 | - } |
|
48 | + /** |
|
49 | + * @since 20.0.0 |
|
50 | + */ |
|
51 | + public function getUser(): IUser { |
|
52 | + return $this->user; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Get the set quota as human readable string, or null if no overwrite is set |
|
57 | - * |
|
58 | - * @since 20.0.0 |
|
59 | - */ |
|
60 | - public function getQuota(): ?string { |
|
61 | - return $this->quota; |
|
62 | - } |
|
55 | + /** |
|
56 | + * Get the set quota as human readable string, or null if no overwrite is set |
|
57 | + * |
|
58 | + * @since 20.0.0 |
|
59 | + */ |
|
60 | + public function getQuota(): ?string { |
|
61 | + return $this->quota; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Set the quota overwrite as human readable string |
|
66 | - * |
|
67 | - * @since 20.0.0 |
|
68 | - */ |
|
69 | - public function setQuota(string $quota): void { |
|
70 | - $this->quota = $quota; |
|
71 | - } |
|
64 | + /** |
|
65 | + * Set the quota overwrite as human readable string |
|
66 | + * |
|
67 | + * @since 20.0.0 |
|
68 | + */ |
|
69 | + public function setQuota(string $quota): void { |
|
70 | + $this->quota = $quota; |
|
71 | + } |
|
72 | 72 | } |
@@ -40,40 +40,40 @@ |
||
40 | 40 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
41 | 41 | |
42 | 42 | class AdditionalScriptsMiddleware extends Middleware { |
43 | - /** @var EventDispatcherInterface */ |
|
44 | - private $legacyDispatcher; |
|
45 | - /** @var IUserSession */ |
|
46 | - private $userSession; |
|
47 | - /** @var IEventDispatcher */ |
|
48 | - private $dispatcher; |
|
43 | + /** @var EventDispatcherInterface */ |
|
44 | + private $legacyDispatcher; |
|
45 | + /** @var IUserSession */ |
|
46 | + private $userSession; |
|
47 | + /** @var IEventDispatcher */ |
|
48 | + private $dispatcher; |
|
49 | 49 | |
50 | - public function __construct(EventDispatcherInterface $legacyDispatcher, IUserSession $userSession, IEventDispatcher $dispatcher) { |
|
51 | - $this->legacyDispatcher = $legacyDispatcher; |
|
52 | - $this->userSession = $userSession; |
|
53 | - $this->dispatcher = $dispatcher; |
|
54 | - } |
|
50 | + public function __construct(EventDispatcherInterface $legacyDispatcher, IUserSession $userSession, IEventDispatcher $dispatcher) { |
|
51 | + $this->legacyDispatcher = $legacyDispatcher; |
|
52 | + $this->userSession = $userSession; |
|
53 | + $this->dispatcher = $dispatcher; |
|
54 | + } |
|
55 | 55 | |
56 | - public function afterController($controller, $methodName, Response $response): Response { |
|
57 | - if ($response instanceof TemplateResponse) { |
|
58 | - if (!$controller instanceof PublicShareController) { |
|
59 | - /* |
|
56 | + public function afterController($controller, $methodName, Response $response): Response { |
|
57 | + if ($response instanceof TemplateResponse) { |
|
58 | + if (!$controller instanceof PublicShareController) { |
|
59 | + /* |
|
60 | 60 | * The old event was not dispatched on the public share controller as there was |
61 | 61 | * OCA\Files_Sharing::loadAdditionalScripts for that. This is kept for compatibility reasons |
62 | 62 | * only for the old event as this is now also included in BeforeTemplateRenderedEvent |
63 | 63 | */ |
64 | - $this->legacyDispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS, new GenericEvent()); |
|
65 | - } |
|
64 | + $this->legacyDispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS, new GenericEvent()); |
|
65 | + } |
|
66 | 66 | |
67 | - if (!($response instanceof StandaloneTemplateResponse) && $this->userSession->isLoggedIn()) { |
|
68 | - $this->legacyDispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN, new GenericEvent()); |
|
69 | - $isLoggedIn = true; |
|
70 | - } else { |
|
71 | - $isLoggedIn = false; |
|
72 | - } |
|
67 | + if (!($response instanceof StandaloneTemplateResponse) && $this->userSession->isLoggedIn()) { |
|
68 | + $this->legacyDispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN, new GenericEvent()); |
|
69 | + $isLoggedIn = true; |
|
70 | + } else { |
|
71 | + $isLoggedIn = false; |
|
72 | + } |
|
73 | 73 | |
74 | - $this->dispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($isLoggedIn, $response)); |
|
75 | - } |
|
74 | + $this->dispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($isLoggedIn, $response)); |
|
75 | + } |
|
76 | 76 | |
77 | - return $response; |
|
78 | - } |
|
77 | + return $response; |
|
78 | + } |
|
79 | 79 | } |
@@ -37,32 +37,32 @@ |
||
37 | 37 | * @since 20.0.0 |
38 | 38 | */ |
39 | 39 | class BeforeTemplateRenderedEvent extends Event { |
40 | - /** @var bool */ |
|
41 | - private $loggedIn; |
|
42 | - /** @var TemplateResponse */ |
|
43 | - private $response; |
|
40 | + /** @var bool */ |
|
41 | + private $loggedIn; |
|
42 | + /** @var TemplateResponse */ |
|
43 | + private $response; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @since 20.0.0 |
|
47 | - */ |
|
48 | - public function __construct(bool $loggedIn, TemplateResponse $response) { |
|
49 | - parent::__construct(); |
|
45 | + /** |
|
46 | + * @since 20.0.0 |
|
47 | + */ |
|
48 | + public function __construct(bool $loggedIn, TemplateResponse $response) { |
|
49 | + parent::__construct(); |
|
50 | 50 | |
51 | - $this->loggedIn = $loggedIn; |
|
52 | - $this->response = $response; |
|
53 | - } |
|
51 | + $this->loggedIn = $loggedIn; |
|
52 | + $this->response = $response; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @since 20.0.0 |
|
57 | - */ |
|
58 | - public function isLoggedIn(): bool { |
|
59 | - return $this->loggedIn; |
|
60 | - } |
|
55 | + /** |
|
56 | + * @since 20.0.0 |
|
57 | + */ |
|
58 | + public function isLoggedIn(): bool { |
|
59 | + return $this->loggedIn; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @since 20.0.0 |
|
64 | - */ |
|
65 | - public function getResponse(): TemplateResponse { |
|
66 | - return $this->response; |
|
67 | - } |
|
62 | + /** |
|
63 | + * @since 20.0.0 |
|
64 | + */ |
|
65 | + public function getResponse(): TemplateResponse { |
|
66 | + return $this->response; |
|
67 | + } |
|
68 | 68 | } |