Completed
Push — master ( 20365b...f0c4e3 )
by Tim
10s
created

ServerXmlConfiguration::getCiphers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * \AppserverIo\Server\Configuration\ServerXmlConfiguration
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Johann Zelger <[email protected]>
15
 * @copyright 2015 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/appserver-io/server
18
 * @link      http://www.appserver.io
19
 */
20
21
namespace AppserverIo\Server\Configuration;
22
23
use AppserverIo\Server\Utils\ServerUtil;
24
use AppserverIo\Server\Interfaces\ServerConfigurationInterface;
25
26
/**
27
 * Server configuration that handles XML files.
28
 *
29
 * @author    Johann Zelger <[email protected]>
30
 * @copyright 2015 TechDivision GmbH <[email protected]>
31
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
32
 * @link      https://github.com/appserver-io/server
33
 * @link      http://www.appserver.io
34
 */
35
class ServerXmlConfiguration implements ServerConfigurationInterface
36
{
37
38
    /**
39
     * The configured rewrite rules
40
     *
41
     * @var array
42
     */
43
    protected $rewrites = array();
44
45
    /**
46
     * The configured locations.
47
     *
48
     * @var array
49
     */
50
    protected $locations = array();
51
52
    /**
53
     * The configured headers
54
     *
55
     * @var array
56
     */
57
    protected $headers = array();
58
59
    /**
60
     * Holds the environmentVariables array
61
     *
62
     * @var array
63
     */
64
    protected $environmentVariables = array();
65
66
    /**
67
     * The server name for internal purposes.
68
     *
69
     * @var string
70
     */
71
    protected $name = 'httpsServer';
72
73
    /**
74
     * The server class name.
75
     *
76
     * @var string
77
     */
78
    protected $type = '\\AppserverIo\\Server\\Servers\\MultiThreadedServer';
79
80
    /**
81
     * The worker class name.
82
     *
83
     * @var string
84
     */
85
    protected $workerType = '\\AppserverIo\\Server\\Workers\\ThreadWorker';
86
87
    /**
88
     * The socket class name.
89
     *
90
     * @var string
91
     */
92
    protected $socketType = '\\AppserverIo\\Server\\Sockets\\StreamSocket';
93
94
    /**
95
     * The stream context class name.
96
     *
97
     * @var string
98
     */
99
    protected $streamContextType = '\\AppserverIo\\Server\\Contexts\\StreamContext';
100
101
    /**
102
     * The server context class name.
103
     *
104
     * @var string
105
     */
106
    protected $serverContextType = '\\AppserverIo\\Server\\Contexts\\ServerContext';
107
108
    /**
109
     * The request context class name.
110
     *
111
     * @var string
112
     */
113
    protected $requestContextType = '\\AppserverIo\\Server\\Contexts\\RequestContext';
114
115
    /**
116
     * The logger name for internal purposes.
117
     *
118
     * @var string
119
     */
120
    protected $loggerName = 'System';
121
122
    /**
123
     * The server admin's email addres.
124
     *
125
     * @var string
126
     */
127
    protected $admin = '[email protected]';
128
129
    /**
130
     * The server software name.
131
     *
132
     * @var string
133
     */
134
    protected $software = 'phpWebServer/7.0.0';
135
136
    /**
137
     * The number of workers to start.
138
     *
139
     * @var integer
140
     */
141
    protected $workerNumber = 64;
142
143
    /**
144
     * The minimum number of requests a worker handles.
145
     *
146
     * @var integer
147
     */
148
    protected $workerAcceptMin = 16;
149
150
    /**
151
     * The maximum number of requests a worker handles.
152
     *
153
     * @var integer
154
     */
155
    protected $workerAcceptMax = 64;
156
157
    /**
158
     * The transport protocol to use.
159
     *
160
     * @var string
161
     */
162
    protected $transport = 'tcp';
163
164
    /**
165
     * The IP address to use.
166
     *
167
     * @var string
168
     */
169
    protected $address = '0.0.0.0';
170
171
    /**
172
     * The port to use.
173
     *
174
     * @var string
175
     */
176
    protected $port = 9080;
177
178
    /**
179
     * Socket flags used for socket initialization.
180
     *
181
     * @var string
182
     */
183
    protected $flags = null;
184
185
    /**
186
     * The server's document root.
187
     *
188
     * @var string
189
     */
190
    protected $documentRoot = 'var/www';
191
192
    /**
193
     * Directory index files to be used.
194
     *
195
     * @var string
196
     */
197
    protected $directoryIndex = 'index.php index.html index.htm';
198
199
    /**
200
     * The maximum requests to be handled for a keep alive connection.
201
     *
202
     * @var integer
203
     */
204
    protected $keepAliveMax = 64;
205
206
    /**
207
     * The timeout for the keep alive connection.
208
     *
209
     * @var integer
210
     */
211
    protected $keepAliveTimeout = 5;
212
213
    /**
214
     * Flag to enable/disable auto index functionality.
215
     *
216
     * @var boolean
217
     */
218
    protected $autoIndex = false;
219
220
    /**
221
     * The path to the error page template.
222
     *
223
     * @var string
224
     */
225
    protected $errorsPageTemplatePath = 'resources/templates/www/error.phtml';
226
227
    /**
228
     * The path to the welcome page template.
229
     *
230
     * @var string
231
     */
232
    protected $welcomePageTemplatePath = 'resources/templates/www/welcome.phtml';
233
234
    /**
235
     * The path to the auto index template.
236
     *
237
     * @var string
238
     */
239
    protected $autoIndexTemplatePath = 'resources/templates/www/auto_index.phtml';
240
241
    /**
242
     * The path to the SSL certificate.
243
     *
244
     * @var string
245
     */
246
    protected $certPath = 'etc/webserver.pem';
247
248
    /**
249
     * The path to the SSL certificate's private key file.
250
     *
251
     * @var string
252
     */
253
    protected $privateKeyPath = null;
254
255
    /**
256
     * The path to the Diffie Hellmann param file.
257
     *
258
     * @var string
259
     */
260
    protected $dhParamPath = null;
261
262
    /**
263
     * The SSL certificate's passphrase.
264
     *
265
     * @var string
266
     */
267
    protected $passphrase = null;
268
269
    /**
270
     * The crypto method(s) to use.
271
     *
272
     * @var string
273
     */
274
    protected $cryptoMethod = 'STREAM_CRYPTO_METHOD_TLS_SERVER';
275
276
    /**
277
     * The peer name.
278
     *
279
     * @var string
280
     */
281
    protected $peerName = null;
282
283
    /**
284
     * Flag to enable/disable peer verification.
285
     *
286
     * @var boolean
287
     */
288
    protected $verifyPeer = false;
289
290
    /**
291
     * The flag to enable/disable peer name verification.
292
     *
293
     * @var boolean
294
     */
295
    protected $verifyPeerName = false;
296
297
    /**
298
     * Flag to allow/disallow self signed SSL certificates.
299
     *
300
     * @var boolean
301
     */
302
    protected $allowSelfSigned = true;
303
304
    /**
305
     * The flag to disable TLS compression. This can help mitigate the CRIME attack vector.
306
     *
307
     * @var boolean
308
     */
309
    protected $disableCompression = true;
310
311
    /**
312
     * The flag to control cipher ordering preferences during negotiation has to be allowed.
313
     *
314
     * @var boolean
315
     */
316
    protected $honorCipherOrder = true;
317
318
    /**
319
     * The curve to use with ECDH ciphers, if not specified prime256v1 will be used.
320
     *
321
     * @var string
322
     */
323
    protected $ecdhCurve = 'prime256v1';
324
325
    /**
326
     * The flag to enable/disable new key pair has to be created in scenarios where ECDH cipher suites are negotiated (instead of the preferred ECDHE ciphers).
327
     * @var boolean
328
     */
329
    protected $singleEcdhUse = true;
330
331
    /**
332
     * The flag to enable/disable new key pair creation when using DH parameters (improves forward secrecy).
333
     *
334
     * @var boolean
335
     */
336
    protected $singleDhUse = true;
337
338
    /**
339
     * The list of available ciphers.
340
     *
341
     * @var string
342
     * @link http://php.net/manual/en/context.ssl.php#context.ssl.ciphers
343
     * @link https://www.openssl.org/docs/manmaster/apps/ciphers.html#CIPHER_LIST_FORMAT
344
     */
345
    protected $ciphers = 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:ECDHE-RSA-RC4-SHA:ECDHE-ECDSA-RC4-SHA:AES128:AES256:RC4-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!PSK';
346
347
    /**
348
     * Constructs config
349
     *
350
     * @param \SimpleXMLElement $node The simple xml element used to build config
351
     */
352
    public function __construct($node)
353
    {
354
355
        // load the object properties
356
        $properties = get_object_vars($this);
357
358
        // prepare properties
359
        $this->name = (string) $node->attributes()->name;
360
        $this->type = (string) $node->attributes()->type;
361
        $this->workerType = (string) $node->attributes()->worker;
362
        $this->socketType = (string) $node->attributes()->socket;
363
        $this->streamContextType = (string) $node->attributes()->streamContext;
364
        $this->serverContextType = (string) $node->attributes()->serverContext;
365
        $this->requestContextType = (string) $node->attributes()->requestContext;
366
        $this->loggerName = (string) $node->attributes()->loggerName;
367
368
        // extract the properties from the params
369
        foreach ($node->xpath('./params/param') as $param) {
370
            if (array_key_exists($propertyName = (string) $param->attributes()->name, $properties)) {
371
                $this->{$propertyName} = ServerUtil::singleton()->castToType($param->attributes()->type, (string) $param);
372
            }
373
        }
374
375
        // prepare analytics
376
        $this->analytics = $this->prepareAnalytics($node);
0 ignored issues
show
Bug introduced by
The property analytics does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
377
        // prepare modules
378
        $this->headers = $this->prepareHeaders($node);
379
        // prepare modules
380
        $this->modules = $this->prepareModules($node);
0 ignored issues
show
Bug introduced by
The property modules does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
381
        // prepare connection handlers
382
        $this->connectionHandlers = $this->prepareConnectionHandlers($node);
0 ignored issues
show
Bug introduced by
The property connectionHandlers does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
383
        // prepare handlers
384
        $this->handlers = $this->prepareHandlers($node);
0 ignored issues
show
Bug introduced by
The property handlers does not seem to exist. Did you mean connectionHandlers?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
385
        // prepare virutalHosts
386
        $this->virtualHosts = $this->prepareVirtualHosts($node);
0 ignored issues
show
Bug introduced by
The property virtualHosts does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
387
        // prepare rewrites
388
        $this->rewrites = $this->prepareRewrites($node);
389
        // prepare environmentVariables
390
        $this->environmentVariables = $this->prepareEnvironmentVariables($node);
391
        // prepare authentications
392
        $this->authentications = $this->prepareAuthentications($node);
0 ignored issues
show
Bug introduced by
The property authentications does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
393
        // prepare accesses
394
        $this->accesses = $this->prepareAccesses($node);
0 ignored issues
show
Bug introduced by
The property accesses does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
395
        // prepare locations
396
        $this->locations = $this->prepareLocations($node);
397
        // prepare rewrite maps
398
        $this->rewriteMaps = $this->prepareRewriteMaps($node);
0 ignored issues
show
Bug introduced by
The property rewriteMaps does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
399
        // prepare certificates
400
        $this->certificates = $this->prepareCertificates($node);
0 ignored issues
show
Bug introduced by
The property certificates does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
401
    }
402
403
    /**
404
     * Prepares the headers array based on a simple xml element node
405
     *
406
     * @param \SimpleXMLElement $node The xml node
407
     *
408
     * @return array
409
     */
410
    public function prepareHeaders(\SimpleXMLElement $node)
411
    {
412
        $headers = array();
413
        if ($node->headers) {
414
            foreach ($node->headers->header as $headerNode) {
415
                // Cut of the SimpleXML attributes wrapper and attach it to our headers
416
                $override = false;
417
                $overrideAttribute = strtolower((string)$headerNode->attributes()->override);
418
                if ($overrideAttribute && $overrideAttribute === 'true') {
419
                    $override = true;
420
                }
421
                $append = false;
422
                $appendAttribute = strtolower((string)$headerNode->attributes()->append);
423
                if ($appendAttribute && $appendAttribute === 'true') {
424
                    $append = true;
425
                }
426
                $header = array(
427
                    'type' => (string) $headerNode->attributes()->type,
428
                    'name' => (string) $headerNode->attributes()->name,
429
                    'value' => (string) $headerNode->attributes()->value,
430
                    'uri' => (string) $headerNode->attributes()->uri,
431
                    'override' => $override,
432
                    'append' => $append
433
                );
434
                $headers[(string) $headerNode->attributes()->type][] = $header;
435
            }
436
        }
437
        return $headers;
438
    }
439
440
    /**
441
     * Prepares the modules array based on a simple xml element node
442
     *
443
     * @param \SimpleXMLElement $node The xml node
444
     *
445
     * @return array
446
     */
447
    public function prepareModules(\SimpleXMLElement $node)
448
    {
449
        $modules = array();
450
        if ($node->modules) {
451
            foreach ($node->modules->module as $moduleNode) {
452
                $modules[] = new ModuleXmlConfiguration($moduleNode);
453
            }
454
        }
455
        return $modules;
456
    }
457
458
    /**
459
     * Prepares the connectionHandlers array based on a simple xml element node
460
     *
461
     * @param \SimpleXMLElement $node The xml node
462
     *
463
     * @return array
464
     */
465
    public function prepareConnectionHandlers(\SimpleXMLElement $node)
466
    {
467
        $connectionHandlers = array();
468
        if ($node->connectionHandlers) {
469
            foreach ($node->connectionHandlers->connectionHandler as $connectionHandlerNode) {
470
                $connectionHandlerType = (string)$connectionHandlerNode->attributes()->type;
471
                $connectionHandlers[] = $connectionHandlerType;
472
            }
473
        }
474
        return $connectionHandlers;
475
    }
476
477
    /**
478
     * Prepares the handlers array based on a simple xml element node
479
     *
480
     * @param \SimpleXMLElement $node The xml node
481
     *
482
     * @return array
483
     */
484
    public function prepareHandlers(\SimpleXMLElement $node)
485
    {
486
        $handlers = array();
487
        if ($node->handlers) {
488 View Code Duplication
            foreach ($node->handlers->handler as $handlerNode) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
489
                $params = array();
490
                if ($handlerNode->params->param) {
491
                    foreach ($handlerNode->params->param as $paramNode) {
492
                        $paramName = (string)$paramNode->attributes()->name;
493
                        $params[$paramName] = (string)array_shift($handlerNode->xpath(".//param[@name='$paramName']"));
0 ignored issues
show
Bug introduced by
$handlerNode->xpath(".//...@name='{$paramName}']") cannot be passed to array_shift() as the parameter $array expects a reference.
Loading history...
494
                    }
495
                }
496
                $handlers[(string)$handlerNode->attributes()->extension] = array(
497
                    'name' => (string)$handlerNode->attributes()->name,
498
                    'params' => $params
499
                );
500
            }
501
        }
502
        return $handlers;
503
    }
504
505
    /**
506
     * Prepares the virtual hosts array based on a simple xml element node
507
     *
508
     * @param \SimpleXMLElement $node The xml node
509
     *
510
     * @return array
511
     */
512
    public function prepareVirtualHosts(\SimpleXMLElement $node)
513
    {
514
        $virutalHosts = array();
515
        if ($node->virtualHosts) {
516
            foreach ($node->virtualHosts->virtualHost as $virtualHostNode) {
517
                $virtualHostNames = explode(' ', (string)$virtualHostNode->attributes()->name);
518
                $params = array();
519
                foreach ($virtualHostNode->params->param as $paramNode) {
520
                    $paramName = (string)$paramNode->attributes()->name;
521
                    $params[$paramName] = (string)array_shift($virtualHostNode->xpath(".//param[@name='$paramName']"));
0 ignored issues
show
Bug introduced by
$virtualHostNode->xpath(...@name='{$paramName}']") cannot be passed to array_shift() as the parameter $array expects a reference.
Loading history...
522
                }
523 View Code Duplication
                foreach ($virtualHostNames as $virtualHostName) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
524
                    // set all virtual hosts params per key for faster matching later on
525
                    $virutalHosts[trim($virtualHostName)] = array(
526
                        'params' => $params,
527
                        'headers' => $this->prepareHeaders($virtualHostNode),
528
                        'rewriteMaps' => $this->prepareRewriteMaps($virtualHostNode),
529
                        'rewrites' => $this->prepareRewrites($virtualHostNode),
530
                        'locations' => $this->prepareLocations($virtualHostNode),
531
                        'environmentVariables' => $this->prepareEnvironmentVariables($virtualHostNode),
532
                        'authentications' => $this->prepareAuthentications($virtualHostNode),
533
                        'accesses' => $this->prepareAccesses($virtualHostNode),
534
                        'analytics' => $this->prepareAnalytics($virtualHostNode)
535
                    );
536
                }
537
            }
538
        }
539
        return $virutalHosts;
540
    }
541
542
    /**
543
     * Prepares the rewrite maps based on a simple xml element node
544
     *
545
     * @param \SimpleXMLElement $node The xml node
546
     *
547
     * @return array
548
     */
549 View Code Duplication
    public function prepareRewriteMaps(\SimpleXMLElement $node)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
550
    {
551
        $rewriteMaps = array();
552
        if ($node->rewriteMaps) {
553
            foreach ($node->rewriteMaps->rewriteMap as $rewriteMapNode) {
554
                $rewriteMapType = (string)$rewriteMapNode->attributes()->type;
555
                $params = array();
556
                foreach ($rewriteMapNode->params->param as $paramNode) {
557
                    $paramName = (string)$paramNode->attributes()->name;
558
                    $params[$paramName] = (string)array_shift($rewriteMapNode->xpath(".//param[@name='$paramName']"));
0 ignored issues
show
Bug introduced by
$rewriteMapNode->xpath("...@name='{$paramName}']") cannot be passed to array_shift() as the parameter $array expects a reference.
Loading history...
559
                }
560
                $rewriteMaps[$rewriteMapType] = $params;
561
            }
562
        }
563
        return $rewriteMaps;
564
    }
565
566
    /**
567
     * Prepares the rewrites array based on a simple xml element node
568
     *
569
     * @param \SimpleXMLElement $node The xml node
570
     *
571
     * @return array
572
     */
573
    public function prepareRewrites(\SimpleXMLElement $node)
574
    {
575
        $rewrites = array();
576
        if ($node->rewrites) {
577
            foreach ($node->rewrites->rewrite as $rewriteNode) {
578
                // Cut of the SimpleXML attributes wrapper and attach it to our rewrites
579
                $rewrite = (array)$rewriteNode;
580
                $rewrites[] = array_shift($rewrite);
581
            }
582
        }
583
        return $rewrites;
584
    }
585
586
    /**
587
     * Prepares the certificates array based on a simple xml element node
588
     *
589
     * @param \SimpleXMLElement $node The xml node
590
     *
591
     * @return array
592
     */
593
    public function prepareCertificates(\SimpleXMLElement $node)
594
    {
595
        $certificates = array();
596
        if ($node->certificates) {
597
            foreach ($node->certificates->certificate as $certificateNode) {
598
                // Cut of the SimpleXML attributes wrapper and attach it to our locations
599
                $certificate = array(
600
                    'domain' => (string) $certificateNode->attributes()->domain,
601
                    'certPath' => (string) $certificateNode->attributes()->certPath
602
                );
603
                $certificates[] = $certificate;
604
            }
605
        }
606
        return $certificates;
607
    }
608
609
    /**
610
     * Prepares the locations array based on a simple xml element node
611
     *
612
     * @param \SimpleXMLElement $node The xml node
613
     *
614
     * @return array
615
     */
616
    public function prepareLocations(\SimpleXMLElement $node)
617
    {
618
        $locations = array();
619
        if ($node->locations) {
620
            foreach ($node->locations->location as $locationNode) {
621
                // Cut of the SimpleXML attributes wrapper and attach it to our locations
622
                $location = array(
623
                    'condition' => (string) $locationNode->attributes()->condition,
624
                    'handlers' => $this->prepareHandlers($locationNode),
625
                    'headers' => $this->prepareHeaders($locationNode),
626
                );
627
                $locations[] = $location;
628
            }
629
        }
630
        return $locations;
631
    }
632
633
    /**
634
     * Prepares the environmentVariables array based on a simple xml element node
635
     *
636
     * @param \SimpleXMLElement $node The xml node
637
     *
638
     * @return array
639
     */
640
    public function prepareEnvironmentVariables(\SimpleXMLElement $node)
641
    {
642
        $environmentVariables = array();
643
        if ($node->environmentVariables) {
644
            foreach ($node->environmentVariables->environmentVariable as $environmentVariableNode) {
645
                // Cut of the SimpleXML attributes wrapper and attach it to our environment variable
646
                $environmentVariable = (array)$environmentVariableNode;
647
                $environmentVariables[] = array_shift($environmentVariable);
648
            }
649
        }
650
        return $environmentVariables;
651
    }
652
653
    /**
654
     * Prepares the authentications array based on a simple xml element node
655
     *
656
     * @param \SimpleXMLElement $node The xml node
657
     *
658
     * @return array
659
     */
660 View Code Duplication
    public function prepareAuthentications(\SimpleXMLElement $node)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
661
    {
662
        $authentications = array();
663
        if ($node->authentications) {
664
            foreach ($node->authentications->authentication as $authenticationNode) {
665
                $params = array();
666
                foreach ($authenticationNode->params->param as $paramNode) {
667
                    $paramName = (string)$paramNode->attributes()->name;
668
                    $params[$paramName] = (string)array_shift($authenticationNode->xpath(".//param[@name='$paramName']"));
0 ignored issues
show
Bug introduced by
$authenticationNode->xpa...@name='{$paramName}']") cannot be passed to array_shift() as the parameter $array expects a reference.
Loading history...
669
                }
670
                $authentications[(string)$authenticationNode->attributes()->uri] = $params;
671
            }
672
        }
673
        return $authentications;
674
    }
675
676
    /**
677
     * Prepares the access array based on a simple xml element node
678
     *
679
     * @param \SimpleXMLElement $node The xml node
680
     *
681
     * @return array
682
     */
683 View Code Duplication
    public function prepareAccesses(\SimpleXMLElement $node)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
684
    {
685
        // init accesses
686
        $accesses = array();
687
        if ($node->accesses) {
688
            foreach ($node->accesses->access as $accessNode) {
689
                $params = array();
690
                foreach ($accessNode->params->param as $paramNode) {
691
                    $paramName = (string)$paramNode->attributes()->name;
692
                    $params[$paramName] = (string)array_shift($accessNode->xpath(".//param[@name='$paramName']"));
0 ignored issues
show
Bug introduced by
$accessNode->xpath(".//p...@name='{$paramName}']") cannot be passed to array_shift() as the parameter $array expects a reference.
Loading history...
693
                }
694
                $accesses[(string)$accessNode->attributes()->type][] = $params;
695
            }
696
        }
697
        return $accesses;
698
    }
699
700
    /**
701
     * Prepares the analytics array based on a simple XML element node
702
     *
703
     * @param \SimpleXMLElement $node The XML node
704
     *
705
     * @return array
706
     */
707
    public function prepareAnalytics(\SimpleXMLElement $node)
708
    {
709
        $analytics = array();
710
        if ($node->analytics) {
711
            foreach ($node->analytics->analytic as $analyticNode) {
712
                $connectors = array();
713 View Code Duplication
                foreach ($analyticNode->connectors->connector as $connectorNode) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
714
                    // connectors might have params
715
                    $params = array();
716
                    if ($connectorNode->params) {
717
                        foreach ($connectorNode->params->param as $paramNode) {
718
                            $paramName = (string)$paramNode->attributes()->name;
719
                            $params[$paramName] = (string)array_shift($connectorNode->xpath(".//param[@name='$paramName']"));
0 ignored issues
show
Bug introduced by
$connectorNode->xpath("....@name='{$paramName}']") cannot be passed to array_shift() as the parameter $array expects a reference.
Loading history...
720
                        }
721
                    }
722
723
                    // build up the connectors entry
724
                    $connectors[] = array(
725
                        'name' => (string)$connectorNode->attributes()->name,
726
                        'type' => (string)$connectorNode->attributes()->type,
727
                        'params' => $params
728
                    );
729
                }
730
731
                // build up the analytics entry
732
                $analytics[] = array(
733
                    'uri' => (string)$analyticNode->attributes()->uri,
734
                    'connectors' => $connectors
735
                );
736
            }
737
        }
738
        return $analytics;
739
    }
740
741
    /**
742
     * Return's name
743
     *
744
     * @return string
745
     */
746
    public function getName()
747
    {
748
        return $this->name;
749
    }
750
751
    /**
752
     * Return's type
753
     *
754
     * @return string
755
     */
756
    public function getType()
757
    {
758
        return $this->type;
759
    }
760
761
    /**
762
     * Return's logger name
763
     *
764
     * @return string
765
     */
766
    public function getLoggerName()
767
    {
768
        return $this->loggerName;
769
    }
770
771
    /**
772
     * Return's transport
773
     *
774
     * @return string
775
     */
776
    public function getTransport()
777
    {
778
        return $this->transport;
779
    }
780
781
    /**
782
     * Returns rewrites
783
     *
784
     * @return array
785
     */
786
    public function getRewrites()
787
    {
788
        return $this->rewrites;
789
    }
790
791
    /**
792
     * Return's address
793
     *
794
     * @return string
795
     */
796
    public function getAddress()
797
    {
798
        return $this->address;
799
    }
800
801
    /**
802
     * Return's port
803
     *
804
     * @return int
805
     */
806
    public function getPort()
807
    {
808
        return (int)$this->port;
809
    }
810
811
    /**
812
     * Return's flags
813
     *
814
     * @return string
815
     */
816
    public function getFlags()
817
    {
818
        return $this->flags;
819
    }
820
821
    /**
822
     * Return's software
823
     *
824
     * @return string
825
     */
826
    public function getSoftware()
827
    {
828
        return $this->software;
829
    }
830
831
    /**
832
     * Return's admin
833
     *
834
     * @return string
835
     */
836
    public function getAdmin()
837
    {
838
        return $this->admin;
839
    }
840
841
    /**
842
     * Return's analytics
843
     *
844
     * @return string
845
     */
846
    public function getAnalytics()
847
    {
848
        return $this->analytics;
849
    }
850
851
    /**
852
     * Return's keep-alive max connection
853
     *
854
     * @return int
855
     */
856
    public function getKeepAliveMax()
857
    {
858
        return (int)$this->keepAliveMax;
859
    }
860
861
    /**
862
     * Return's keep-alive timeout
863
     *
864
     * @return int
865
     */
866
    public function getKeepAliveTimeout()
867
    {
868
        return (int)$this->keepAliveTimeout;
869
    }
870
871
    /**
872
     * Return's template path for errors page
873
     *
874
     * @return string
875
     */
876
    public function getErrorsPageTemplatePath()
877
    {
878
        return $this->errorsPageTemplatePath;
879
    }
880
881
    /**
882
     * Returns template path for possible configured welcome page
883
     *
884
     * @return string
885
     */
886
    public function getWelcomePageTemplatePath()
887
    {
888
        return $this->welcomePageTemplatePath;
889
    }
890
891
    /**
892
     * Returns template path for possible configured auto index page
893
     *
894
     * @return string
895
     */
896
    public function getAutoIndexTemplatePath()
897
    {
898
        return $this->autoIndexTemplatePath;
899
    }
900
901
    /**
902
     * Return's worker number
903
     *
904
     * @return int
905
     */
906
    public function getWorkerNumber()
907
    {
908
        return (int)$this->workerNumber;
909
    }
910
911
    /**
912
     * Return's worker's accept min count
913
     *
914
     * @return int
915
     */
916
    public function getWorkerAcceptMin()
917
    {
918
        return (int)$this->workerAcceptMin;
919
    }
920
921
    /**
922
     * Return's worker's accept max count
923
     *
924
     * @return int
925
     */
926
    public function getWorkerAcceptMax()
927
    {
928
        return (int)$this->workerAcceptMax;
929
    }
930
931
    /**
932
     * Return's the auto index configuration
933
     *
934
     * @return boolean
935
     */
936
    public function getAutoIndex()
937
    {
938
        return (boolean)$this->autoIndex;
939
    }
940
941
    /**
942
     * Return's server context type
943
     *
944
     * @return string
945
     */
946
    public function getServerContextType()
947
    {
948
        return $this->serverContextType;
949
    }
950
951
    /**
952
     * Returns stream context type
953
     *
954
     * @return string
955
     */
956
    public function getStreamContextType()
957
    {
958
        return $this->streamContextType;
959
    }
960
961
    /**
962
     * Return's server context type
963
     *
964
     * @return string
965
     */
966
    public function getRequestContextType()
967
    {
968
        return $this->requestContextType;
969
    }
970
971
    /**
972
     * Return's socket type
973
     *
974
     * @return string
975
     */
976
    public function getSocketType()
977
    {
978
        return $this->socketType;
979
    }
980
981
    /**
982
     * Return's worker type
983
     *
984
     * @return string
985
     */
986
    public function getWorkerType()
987
    {
988
        return $this->workerType;
989
    }
990
991
    /**
992
     * Return's document root
993
     *
994
     * @return string
995
     */
996
    public function getDocumentRoot()
997
    {
998
        return $this->documentRoot;
999
    }
1000
1001
    /**
1002
     * Return's directory index definition
1003
     *
1004
     * @return string
1005
     */
1006
    public function getDirectoryIndex()
1007
    {
1008
        return $this->directoryIndex;
1009
    }
1010
1011
    /**
1012
     * Return's the connection handlers
1013
     *
1014
     * @return array
1015
     */
1016
    public function getConnectionHandlers()
1017
    {
1018
        return $this->connectionHandlers;
1019
    }
1020
1021
    /**
1022
     * Returns the headers used by the server
1023
     *
1024
     * @return array
1025
     */
1026
    public function getHeaders()
1027
    {
1028
        return $this->headers;
1029
    }
1030
1031
    /**
1032
     * Returns the certificates used by the server
1033
     *
1034
     * @return array
1035
     */
1036
    public function getCertificates()
1037
    {
1038
        return $this->certificates;
1039
    }
1040
1041
    /**
1042
     * Return's the virtual hosts
1043
     *
1044
     * @return array
1045
     */
1046
    public function getVirtualHosts()
1047
    {
1048
        return $this->virtualHosts;
1049
    }
1050
1051
    /**
1052
     * Return's the authentication information's
1053
     *
1054
     * @return array
1055
     */
1056
    public function getAuthentications()
1057
    {
1058
        return $this->authentications;
1059
    }
1060
1061
    /**
1062
     * Return's modules
1063
     *
1064
     * @return array
1065
     */
1066
    public function getModules()
1067
    {
1068
        return $this->modules;
1069
    }
1070
1071
    /**
1072
     * Return's array
1073
     *
1074
     * @return array
1075
     */
1076
    public function getHandlers()
1077
    {
1078
        return $this->handlers;
0 ignored issues
show
Bug introduced by
The property handlers does not seem to exist. Did you mean connectionHandlers?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1079
    }
1080
1081
    /**
1082
     * Return's cert path
1083
     *
1084
     * @return string
1085
     */
1086
    public function getCertPath()
1087
    {
1088
        return $this->certPath;
1089
    }
1090
1091
    /**
1092
     * Return's passphrase
1093
     *
1094
     * @return string
1095
     */
1096
    public function getPassphrase()
1097
    {
1098
        return $this->passphrase;
1099
    }
1100
1101
    /**
1102
     * Returns the environment variable configuration
1103
     *
1104
     * @return array
1105
     */
1106
    public function getEnvironmentVariables()
1107
    {
1108
        return $this->environmentVariables;
1109
    }
1110
1111
    /**
1112
     * Returns the access configuration.
1113
     *
1114
     * @return array
1115
     */
1116
    public function getAccesses()
1117
    {
1118
        return $this->accesses;
1119
    }
1120
1121
    /**
1122
     * Returns the locations.
1123
     *
1124
     * @return array
1125
     */
1126
    public function getLocations()
1127
    {
1128
        return $this->locations;
1129
    }
1130
1131
    /**
1132
     * Returns the rewrite maps.
1133
     *
1134
     * @return array
1135
     */
1136
    public function getRewriteMaps()
1137
    {
1138
        return $this->rewriteMaps;
1139
    }
1140
1141
    /**
1142
     * Return's DH param path
1143
     *
1144
     * @return string
1145
     */
1146
    public function getDhParamPath()
1147
    {
1148
        return $this->dhParamPath;
1149
    }
1150
1151
    /**
1152
     * Return's private key path
1153
     *
1154
     * @return string
1155
     */
1156
    public function getPrivateKeyPath()
1157
    {
1158
        return $this->privateKeyPath;
1159
    }
1160
1161
    /**
1162
     * Return's the crypto method to use
1163
     *
1164
     * @return string
1165
     */
1166
    public function getCryptoMethod()
1167
    {
1168
        return $this->cryptoMethod;
1169
    }
1170
1171
    /**
1172
     * Return's the peer name to be used, if this value is not set, then the name is guessed based on the hostname used when opening the stream
1173
     *
1174
     * @return string
1175
     */
1176
    public function getPeerName()
1177
    {
1178
        return $this->peerName;
1179
    }
1180
1181
    /**
1182
     * Return's TRUE it the verification of use SSL certificate has to be required
1183
     *
1184
     * @return boolean
1185
     */
1186
    public function getVerifyPeer()
1187
    {
1188
        return $this->verifyPeer;
1189
    }
1190
1191
    /**
1192
     * Return's TRUE it the peer name has to be verified
1193
     *
1194
     * @return boolean
1195
     */
1196
    public function getVerifyPeerName()
1197
    {
1198
        return $this->verifyPeerName;
1199
    }
1200
1201
    /**
1202
     * Return's TRUE to disable TLS compression. This can help mitigate the CRIME attack vector
1203
     *
1204
     * @return boolean
1205
     */
1206
    public function getDisableCompression()
1207
    {
1208
        return $this->disableCompression;
1209
    }
1210
1211
    /**
1212
     * Return's TRUE if self-signed certificates has to be allowed, but requires verify_peer to be FALSE
1213
     *
1214
     * @return boolean
1215
     */
1216
    public function getAllowSelfSigned()
1217
    {
1218
        return $this->allowSelfSigned;
1219
    }
1220
1221
    /**
1222
     * Return's TRUE if control cipher ordering preferences during negotiation has to be allowed
1223
     *
1224
     * @return boolean
1225
     */
1226
    public function getHonorCipherOrder()
1227
    {
1228
        return $this->honorCipherOrder;
1229
    }
1230
1231
    /**
1232
     * Return's the curve to use with ECDH ciphers, if not specified prime256v1 will be used
1233
     *
1234
     * @return string
1235
     */
1236
    public function getEcdhCurve()
1237
    {
1238
        return $this->ecdhCurve;
1239
    }
1240
1241
    /**
1242
     * Return's TRUE if a new key pair has to be created in scenarios where ECDH cipher suites are negotiated (instead of the preferred ECDHE ciphers)
1243
     *
1244
     * @return boolean
1245
     */
1246
    public function getSingleEcdhUse()
1247
    {
1248
        return $this->singleEcdhUse;
1249
    }
1250
1251
    /**
1252
     * Return's TRUE if new key pair has to be created when using DH parameters (improves forward secrecy)
1253
     *
1254
     * @return boolean
1255
     */
1256
    public function getSingleDhUse()
1257
    {
1258
        return $this->singleDhUse;
1259
    }
1260
1261
    /**
1262
     * Return's the list of available ciphers.
1263
     *
1264
     * @return string
1265
     * @link http://php.net/manual/en/context.ssl.php#context.ssl.ciphers
1266
     * @link https://www.openssl.org/docs/manmaster/apps/ciphers.html#CIPHER_LIST_FORMAT
1267
     */
1268
    public function getCiphers()
1269
    {
1270
        return $this->ciphers;
1271
    }
1272
}
1273