ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ILIAS\WOPI\Discovery\Crawler Class Reference
+ Collaboration diagram for ILIAS\WOPI\Discovery\Crawler:

Public Member Functions

 __construct ()
 
 validate (URI $discovery_url)
 
 crawl (URI $discovery_url)
 
 crawlContent (string $content)
 Parses discovery XML that has already been fetched. More...
 
 getProofKeys ()
 The proof keys of the discovery read last, null if it publishes none. More...
 

Static Public Member Functions

static isWebUrl (URI $url)
 

Data Fields

const ALLOWED_SCHEMES = ['https', 'http']
 the discovery and the URLs it publishes must be web URLs, anything else (file, php, ...) would let the discovery read local resources or launch script in the ILIAS origin More...
 

Private Member Functions

 fetch (URI $discovery_url)
 
 load (?string $content)
 
 parse ()
 
 favIconUrl (\SimpleXMLElement $app)
 

Private Attributes

const XPATH = '/wopi-discovery/net-zone/app'
 
const TIMEOUT_SECONDS = 10
 
const MAX_REDIRECTS = 3
 
const MAX_SIZE_BYTES = 2 * 1024 * 1024
 
array $crawl_actions = []
 
string $content = null
 
SimpleXMLElement $discovery = null
 
array $xml_app_elements = null
 

Detailed Description

Author
Fabian Schmid fabia.nosp@m.n@sr.nosp@m..solu.nosp@m.tion.nosp@m.s

Definition at line 28 of file Crawler.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\WOPI\Discovery\Crawler::__construct ( )

Definition at line 50 of file Crawler.php.

51 {
52 $this->crawl_actions = [
53 ActionTarget::VIEW->value,
54 ActionTarget::EMBED_VIEW->value,
55 ActionTarget::EDIT->value,
56 ActionTarget::EMBED_EDIT->value,
57 ActionTarget::EDIT_NEW->value,
58 ActionTarget::CONVERT->value,
59 ];
60 }

Member Function Documentation

◆ crawl()

ILIAS\WOPI\Discovery\Crawler::crawl ( URI  $discovery_url)

Definition at line 120 of file Crawler.php.

120 : ?Apps
121 {
122 if (!$this->validate($discovery_url)) {
123 return null;
124 }
125
126 return $this->parse();
127 }
validate(URI $discovery_url)
Definition: Crawler.php:67

References ILIAS\WOPI\Discovery\Crawler\parse(), and ILIAS\WOPI\Discovery\Crawler\validate().

+ Here is the call graph for this function:

◆ crawlContent()

ILIAS\WOPI\Discovery\Crawler::crawlContent ( string  $content)

Parses discovery XML that has already been fetched.

Definition at line 132 of file Crawler.php.

132 : ?Apps
133 {
134 if (!$this->load($content)) {
135 return null;
136 }
137
138 return $this->parse();
139 }
load(?string $content)
Definition: Crawler.php:96

References ILIAS\WOPI\Discovery\Crawler\load(), and ILIAS\WOPI\Discovery\Crawler\parse().

+ Here is the call graph for this function:

◆ favIconUrl()

ILIAS\WOPI\Discovery\Crawler::favIconUrl ( \SimpleXMLElement  $app)
private

Definition at line 231 of file Crawler.php.

231 : ?URI
232 {
233 $value = $app['favIconUrl'] ?? null;
234 if ($value === null) {
235 return null;
236 }
237 try {
238 $url = new URI((string) $value);
239 } catch (\Throwable) {
240 return null;
241 }
242
243 return self::isWebUrl($url) ? $url : null;
244 }
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
static isWebUrl(URI $url)
Definition: Crawler.php:62

References ILIAS\WOPI\Discovery\Crawler\isWebUrl().

Referenced by ILIAS\WOPI\Discovery\Crawler\parse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fetch()

ILIAS\WOPI\Discovery\Crawler::fetch ( URI  $discovery_url)
private

Definition at line 79 of file Crawler.php.

79 : ?string
80 {
81 $context = stream_context_create([
82 'http' => [
83 'timeout' => self::TIMEOUT_SECONDS,
84 'max_redirects' => self::MAX_REDIRECTS,
85 ],
86 ]);
87 // one byte more than allowed tells a discovery which is too large
88 $content = @file_get_contents((string) $discovery_url, false, $context, 0, self::MAX_SIZE_BYTES + 1);
89 if ($content === false || $content === '' || strlen($content) > self::MAX_SIZE_BYTES) {
90 return null;
91 }
92
93 return $content;
94 }

References ILIAS\WOPI\Discovery\Crawler\$content.

Referenced by ILIAS\WOPI\Discovery\Crawler\validate().

+ Here is the caller graph for this function:

◆ getProofKeys()

ILIAS\WOPI\Discovery\Crawler::getProofKeys ( )

The proof keys of the discovery read last, null if it publishes none.

Definition at line 144 of file Crawler.php.

144 : ?ProofKeys
145 {
146 $element = $this->discovery?->xpath('/wopi-discovery/proof-key')[0] ?? null;
147 if (!$element instanceof \SimpleXMLElement) {
148 return null;
149 }
150 $modulus = (string) ($element['modulus'] ?? '');
151 $exponent = (string) ($element['exponent'] ?? '');
152 if ($modulus === '' || $exponent === '') {
153 return null;
154 }
155 $old_modulus = (string) ($element['oldmodulus'] ?? '');
156 $old_exponent = (string) ($element['oldexponent'] ?? '');
157
158 return new ProofKeys(
159 new ProofKey($modulus, $exponent),
160 $old_modulus === '' || $old_exponent === '' ? null : new ProofKey($old_modulus, $old_exponent)
161 );
162 }

◆ isWebUrl()

static ILIAS\WOPI\Discovery\Crawler::isWebUrl ( URI  $url)
static

Definition at line 62 of file Crawler.php.

62 : bool
63 {
64 return in_array(strtolower($url->getSchema()), self::ALLOWED_SCHEMES, true);
65 }

References ILIAS\Data\URI\getSchema().

Referenced by ILIAS\WOPI\Discovery\Crawler\favIconUrl(), and ILIAS\WOPI\Embed\EmbeddedApplication\getActionLauncherURL().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ load()

ILIAS\WOPI\Discovery\Crawler::load ( ?string  $content)
private

Definition at line 96 of file Crawler.php.

96 : bool
97 {
98 try {
99 $this->content = $content;
100 if ($this->content === null) {
101 return false;
102 }
103
104 // invalid XML is reported by returning false, not by warnings
105 $use_internal_errors = libxml_use_internal_errors(true);
106 $this->discovery = simplexml_load_string($this->content) ?: null;
107 libxml_clear_errors();
108 libxml_use_internal_errors($use_internal_errors);
109 if ($this->discovery === null) {
110 return false;
111 }
112 $this->xml_app_elements = $this->discovery->xpath(self::XPATH);
113
114 return is_array($this->xml_app_elements);
115 } catch (\Throwable) {
116 return false;
117 }
118 }

References ILIAS\WOPI\Discovery\Crawler\$content.

Referenced by ILIAS\WOPI\Discovery\Crawler\crawlContent(), and ILIAS\WOPI\Discovery\Crawler\validate().

+ Here is the caller graph for this function:

◆ parse()

ILIAS\WOPI\Discovery\Crawler::parse ( )
private

Definition at line 164 of file Crawler.php.

164 : Apps
165 {
166 // read wopi-discovery XML from $discovery_url and parse Apps with it's Actions
167 $apps = [];
168 foreach ($this->xml_app_elements as $app) {
169 $actions = [];
170 foreach ($app->action as $action) {
171 $action_name = $action['name'] ?? null;
172 $action_ext = $action['ext'] ?? null;
173 $action_urlsrc = $action['urlsrc'] ?? null;
174 // the extension of the resulting file: targetext for convert, newext for editnew
175 $target_text = isset($action['targetext'])
176 ? (string) $action['targetext']
177 : (isset($action['newext']) ? (string) $action['newext'] : null);
178 if (!$action_name instanceof \SimpleXMLElement) {
179 continue;
180 }
181 if (!$action_ext instanceof \SimpleXMLElement) {
182 continue;
183 }
184 if (!$action_urlsrc instanceof \SimpleXMLElement) {
185 continue;
186 }
187
188 if (!in_array((string) $action_name, $this->crawl_actions, true)) {
189 continue;
190 }
191
192 $uri_string = rtrim((string) $action_urlsrc, '?');
193 // remove all after ?
194 $uri = explode('?', $uri_string);
195 $uri_string = $uri[0];
196 try {
197 $launcher_url = new URI($uri_string);
198 } catch (\Throwable) {
199 continue;
200 }
201 if (!self::isWebUrl($launcher_url)) {
202 continue;
203 }
204 $actions[] = new Action(
205 0,
206 (string) $action_name,
207 (string) $action_ext,
208 $launcher_url,
209 $uri[1] ?? null,
210 $target_text
211 );
212 }
213 if ($actions === []) {
214 continue;
215 }
216
217 $app_name = $app['name'] ?? null;
218 if ($app_name === null) {
219 continue;
220 }
221 $apps[] = new App(
222 0,
223 (string) $app_name,
224 $actions,
225 $this->favIconUrl($app)
226 );
227 }
228 return new Apps($apps);
229 }
favIconUrl(\SimpleXMLElement $app)
Definition: Crawler.php:231

References ILIAS\WOPI\Discovery\Crawler\$crawl_actions, and ILIAS\WOPI\Discovery\Crawler\favIconUrl().

Referenced by ILIAS\WOPI\Discovery\Crawler\crawl(), and ILIAS\WOPI\Discovery\Crawler\crawlContent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validate()

ILIAS\WOPI\Discovery\Crawler::validate ( URI  $discovery_url)

Definition at line 67 of file Crawler.php.

67 : bool
68 {
69 if (!self::isWebUrl($discovery_url)) {
70 return false;
71 }
72 try {
73 return $this->load($this->fetch($discovery_url));
74 } catch (\Throwable) {
75 return false;
76 }
77 }
fetch(URI $discovery_url)
Definition: Crawler.php:79

References ILIAS\WOPI\Discovery\Crawler\fetch(), and ILIAS\WOPI\Discovery\Crawler\load().

Referenced by ILIAS\WOPI\Discovery\Crawler\crawl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $content

string ILIAS\WOPI\Discovery\Crawler::$content = null
private

◆ $crawl_actions

array ILIAS\WOPI\Discovery\Crawler::$crawl_actions = []
private

Definition at line 42 of file Crawler.php.

Referenced by ILIAS\WOPI\Discovery\Crawler\parse().

◆ $discovery

SimpleXMLElement ILIAS\WOPI\Discovery\Crawler::$discovery = null
private

Definition at line 44 of file Crawler.php.

◆ $xml_app_elements

array ILIAS\WOPI\Discovery\Crawler::$xml_app_elements = null
private

Definition at line 48 of file Crawler.php.

◆ ALLOWED_SCHEMES

const ILIAS\WOPI\Discovery\Crawler::ALLOWED_SCHEMES = ['https', 'http']

the discovery and the URLs it publishes must be web URLs, anything else (file, php, ...) would let the discovery read local resources or launch script in the ILIAS origin

Definition at line 38 of file Crawler.php.

◆ MAX_REDIRECTS

const ILIAS\WOPI\Discovery\Crawler::MAX_REDIRECTS = 3
private

Definition at line 40 of file Crawler.php.

◆ MAX_SIZE_BYTES

const ILIAS\WOPI\Discovery\Crawler::MAX_SIZE_BYTES = 2 * 1024 * 1024
private

Definition at line 41 of file Crawler.php.

◆ TIMEOUT_SECONDS

const ILIAS\WOPI\Discovery\Crawler::TIMEOUT_SECONDS = 10
private

Definition at line 39 of file Crawler.php.

◆ XPATH

const ILIAS\WOPI\Discovery\Crawler::XPATH = '/wopi-discovery/net-zone/app'
private

Definition at line 33 of file Crawler.php.


The documentation for this class was generated from the following file: