SpotInstall::askNntpSettings()   F
last analyzed

Complexity

Conditions 17
Paths 1736

Size

Total Lines 136
Code Lines 86

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 306

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 86
c 2
b 1
f 0
dl 0
loc 136
ccs 0
cts 102
cp 0
rs 1.1454
cc 17
nc 1736
nop 0
crap 306

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * Created by PhpStorm.
5
 * User: root
6
 * Date: 11/6/16
7
 * Time: 3:07 PM.
8
 */
9
class SpotInstall
10
{
11
    public static function showTemplate($tplname, $vars)
12
    {
13
        /**
14
         * Make the variables availbale to the local context.
15
         */
16
        extract($vars, EXTR_REFS);
17
18
        require_once __DIR__.'/../templates/installer/includes/header.inc.php';
19
        require_once __DIR__.'/../templates/installer/'.$tplname;
20
    }
21
22
    public static function performAndPrintTests()
23
    {
24
        global $settings;
25
        global $_testInstall_Ok;
26
27
        /**
28
         * Load all the SSL signing code, we need it to create a private key.
29
         */
30
        $spotSigning = Services_Signing_Base::factory();
31
        $privKey = $spotSigning->createPrivateKey($settings['openssl_cnf_path']);
32
33
        // We need either one of those 3 extensions, so set the error flag manually.
34
        if ((!extension_loaded('openssl')) && (!extension_loaded('gmp')) && (!extension_loaded('bcmath'))) {
35
            $_testInstall_Ok = false;
36
        }
37
38
        /**
39
         * Try to create the cache directory.
40
         */
41
        if (!file_exists(__DIR__.'/../cache')) {
42
            mkdir(__DIR__.'/../cache', 0777);
43
        }
44
45
        /**
46
         * Load the template.
47
         */
48
        static::showTemplate('step-001.inc.php', ['privKey' => $privKey]);
49
    }
50
51
    public static function askDbSettings()
52
    {
53
        global $settings;
54
55
        if (!isset($settings['mydb'])) {
56
            $form = [
57
                'engine'  => 'pdo_mysql',
58
                'rootpwd' => '',
59
                'host'    => 'localhost',
60
                'port'    => '3306',
61
                'dbname'  => 'spotweb',
62
                'schema'  => 'public',
63
                'user'    => 'spotweb',
64
                'pass'    => 'spotweb',
65
                'submit'  => '',
66
            ];
67
        } else {
68
            $form = $settings['mydb'];
69
            unset($settings['mydb']);
70
        }
71
72
        if (isset($_POST['dbform'])) {
73
            $form = array_merge($form, $_POST['dbform']);
74
        }
75
76
        /**
77
         * Did the user press submit? If so, try to
78
         * connect to the database.
79
         */
80
        $databaseCreated = false;
81
        if ($form['submit'] === 'Verify database') {
82
            if (($form['engine'] == 'pdo_mysql') and (empty($form['port']))) {
83
                $form['port'] = '3306';
84
            }
85
86
            if (($form['engine'] == 'pdo_pgsql') and (empty($form['port']))) {
87
                $form['port'] = '5432';
88
            }
89
90
            try {
91
                $dbCon = dbeng_abs::getDbFactory($form['engine']);
92
93
                if (($form['engine'] == 'pdo_mysql' or $form['engine'] == 'pdo_pgsql') and (!empty($form['rootpwd']))) {
94
                    $dbCon->connectRoot($form['host'], $form['rootpwd'], $form['port']);
0 ignored issues
show
Bug introduced by
The method connectRoot() does not exist on dbeng_pdo_sqlite. Did you maybe mean connect()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

94
                    $dbCon->/** @scrutinizer ignore-call */ 
95
                            connectRoot($form['host'], $form['rootpwd'], $form['port']);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
95
                    $dbCon->createDb($form['dbname'], $form['user'], $form['pass']);
0 ignored issues
show
Bug introduced by
The method createDb() does not exist on dbeng_pdo_sqlite. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

95
                    $dbCon->/** @scrutinizer ignore-call */ 
96
                            createDb($form['dbname'], $form['user'], $form['pass']);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
96
                }
97
98
                $dbCon->connect(
99
                    $form['host'],
100
                    $form['user'],
101
                    $form['pass'],
102
                    $form['dbname'],
103
                    $form['port'],
104
                    $form['schema']
105
                );
106
107
                $databaseCreated = true;
108
109
                /**
110
                 * Store the given database settings in the
111
                 * SESSION object, we need it later to generate
112
                 * a 'dbsettings.inc.php' file.
113
                 */
114
                $_SESSION['spotsettings']['db'] = $form;
115
116
                // Call the next stage in the setup.
117
                static::gotoPage(3);
118
            } catch (Exception $x) {
119
                static::showTemplate('fatalerror.inc.php', ['x' => $x]);
120
            }
121
        }
122
123
        if (!$databaseCreated) {
124
            static::showTemplate('step-002.inc.php', ['form' => $form]);
125
        }
126
    }
127
128
    public static function askNntpSettings()
129
    {
130
        global $settings;
131
132
        // Loading the file directly seems to sometimes result in a weird error. GH issue #1861
133
        $serverList = simplexml_load_string(file_get_contents(__DIR__.'/../usenetservers.xml'));
134
        if (!isset($settings['mynntp'])) {
135
            $form = [
136
                'name'   => 'custom',
137
                'host'   => '',
138
                'user'   => '',
139
                'pass'   => '',
140
                'port'   => 119,
141
                'enc'    => false,
142
                'submit' => '', 'ssl' => '', 'namefield' => 'custom', 'verifyname'=> 'on',
143
            ];
144
        } else {
145
            $form = $settings['mynntp'];
146
            unset($settings['mynntp']);
147
        }
148
149
        if (isset($_POST['nntpform'])) {
150
            //unset($form['verifyname']);
151
            //$form = array_merge($form, $_POST['nntpform']);
152
            $form = $_POST['nntpform'];
153
        }
154
155
        /**
156
         * Did the user press submit? If so, try to
157
         * connect to the database.
158
         */
159
        $nntpVerified = false;
160
        if (($form['submit'] === 'Verify usenet server') ||
161
            ($form['submit'] === 'Skip validation')
162
        ) {
163
            try {
164
                /**
165
                 * Convert the selected NNTP name to an actual
166
                 * server record.
167
                 */
168
                if ($form['name'] == 'custom') {
169
                    $form['buggy'] = false;
170
                    $form['hdr'] = $form;
171
                    $form['nzb'] = $form;
172
                    $form['post'] = $form;
173
                    if ($form['port'] == 119) {
174
                        $form['hdr']['enc'] = false;
175
                        $form['nzb']['enc'] = false;
176
                        $form['post']['enc'] = false;
177
                    } else {
178
                        $form['hdr']['enc'] = 'ssl';
179
                        $form['nzb']['enc'] = 'ssl';
180
                        $form['post']['enc'] = 'ssl';
181
                    }
182
                    $form['hdr']['verifyname'] = isset($form['verifyname']);
183
                    $form['nzb']['verifyname'] = isset($form['verifyname']);
184
                    $form['post']['verifyname'] = isset($form['verifyname']);
185
                } else {
186
                    foreach ($serverList->usenetservers->server as $provider) {
187
                        if (extension_loaded('openssl') && isset($provider->ssl)) {
188
                            $server = $provider->ssl;
189
                        } else {
190
                            $server = $provider->plain;
191
                        }
192
193
                        if ((string) $provider['name'] == $form['name']) {
194
                            // Header usenet server
195
                            $form['hdr']['host'] = (string) $server->header;
196
                            $form['hdr']['user'] = $form['user'];
197
                            $form['hdr']['pass'] = $form['pass'];
198
                            if ((string) $server->header['ssl'] == 'yes') {
199
                                $form['hdr']['enc'] = 'ssl';
200
                            } else {
201
                                $form['hdr']['enc'] = false;
202
                            }
203
                            $form['hdr']['port'] = (int) $server->header['port'];
204
                            $form['hdr']['buggy'] = (bool) $server['buggy'];
205
                            $form['hdr']['verifyname'] = isset($form['verifyname']);
206
207
                            // NZB usenet server
208
                            $form['nzb']['host'] = (string) $server->nzb;
209
                            $form['nzb']['user'] = $form['user'];
210
                            $form['nzb']['pass'] = $form['pass'];
211
                            if ((string) $server->nzb['ssl'] == 'yes') {
212
                                $form['nzb']['enc'] = 'ssl';
213
                            } else {
214
                                $form['nzb']['enc'] = false;
215
                            }
216
                            $form['nzb']['port'] = (int) $server->nzb['port'];
217
                            $form['nzb']['buggy'] = (bool) $server['buggy'];
218
                            $form['nzb']['verifyname'] = isset($form['verifyname']);
219
220
                            // Posting usenet server
221
                            $form['post']['host'] = (string) $server->post;
222
                            $form['post']['user'] = $form['user'];
223
                            $form['post']['pass'] = $form['pass'];
224
                            if ((string) $server->post['ssl'] == 'yes') {
225
                                $form['post']['enc'] = 'ssl';
226
                            } else {
227
                                $form['post']['enc'] = false;
228
                            }
229
                            $form['post']['port'] = (int) $server->post['port'];
230
                            $form['post']['buggy'] = (bool) $server['buggy'];
231
                            $form['post']['verifyname'] = isset($form['verifyname']);
232
                        }
233
                    }
234
                }
235
236
                // Try to connect to the usenet server.
237
                if ($form['submit'] === 'Verify usenet server') {
238
                    $nntp = new Services_Nntp_Engine($form['hdr']);
239
                    $nntp->validateServer();
240
                }
241
242
                $nntpVerified = true;
243
                /**
244
                 * Store the given NNTP settings in the
245
                 * SESSION object, we need it later to update
246
                 * the settings in the database.
247
                 */
248
                $_SESSION['spotsettings']['nntp'] = $form;
249
250
                /**
251
                 * Call the next stage in the setup.
252
                 */
253
                static::gotoPage(4);
254
            } catch (Exception $x) {
255
                static::showTemplate('fatalerror.inc.php', ['x' => $x]);
256
            }
257
        }
258
259
        if (!$nntpVerified) {
260
            static::showTemplate('step-003.inc.php', [
261
                'form'       => $form,
262
                'nntpVerified' > $nntpVerified,
263
                'serverList' => $serverList,
264
            ]);
265
        }
266
    }
267
268
    public static function askSpotwebSettings()
269
    {
270
        global $settings;
271
272
        if (!isset($settings['myadminuser'])) {
273
            $form = [
274
                'systemtype'   => 'public',
275
                'username'     => '',
276
                'newpassword1' => '',
277
                'newpassword2' => '',
278
                'firstname'    => '',
279
                'lastname'     => '',
280
                'mail'         => '',
281
                'userid'       => -1,
282
            ];
283
        } else {
284
            $form = $settings['myadminuser'];
285
            unset($settings['myadminuser']);
286
        }
287
288
        if (isset($_POST['settingsform'])) {
289
            $form = array_merge($form, $_POST['settingsform']);
290
        }
291
292
        /**
293
         * Did the user press submit? If so, try to
294
         * connect to the database.
295
         */
296
        if ((isset($form['submit'])) && ($form['submit'] === 'Create system')) {
297
            try {
298
                /**
299
                 * Store the given user settings in the
300
                 * SESSION object, we need it later to update
301
                 * the settings in the database.
302
                 */
303
                $_SESSION['spotsettings']['adminuser'] = $form;
304
305
                /**
306
                 * Get the schema version and other constants.
307
                 */
308
                $bootstrap = new Bootstrap();
309
310
                /**
311
                 * And initiate the user system, this allows us to use
312
                 * validateUserRecord().
313
                 */
314
                $dbsettings = $_SESSION['spotsettings']['db'];
315
                $dbCon = dbeng_abs::getDbFactory($dbsettings['engine']);
316
                $dbCon->connect(
317
                    $dbsettings['host'],
318
                    $dbsettings['user'],
319
                    $dbsettings['pass'],
320
                    $dbsettings['dbname'],
321
                    $dbsettings['port'],
322
                    $dbsettings['schema']
323
                );
324
                $daoFactory = Dao_Factory::getDAOFactory($dbsettings['engine']);
325
                $daoFactory->setConnection($dbCon);
326
                $svcUserRecord = new ServicesValidateUserRecord(
327
                    $daoFactory,
328
                    $bootstrap->getSettings($daoFactory, false)
329
                );
330
                $errorList = $svcUserRecord->validateUserRecord($form, false)->getErrors();
331
332
                if (!empty($errorList)) {
333
                    throw new Exception($errorList[0]);
334
                }
335
336
                /**
337
                 * Call the next stage in the setup.
338
                 */
339
                static::gotoPage(99);
340
            } catch (Exception $x) {
341
                static::showTemplate('fatalerror.inc.php', ['x' => $x]);
342
            }
343
        }
344
345
        static::showTemplate('step-004.inc.php', [
346
            'form'         => $form,
347
        ]);
348
    }
349
350
    public static function createSystem()
351
    {
352
        try {
353
            /**
354
             * The settings system is used to create a lot of output,
355
             * we swallow it all.
356
             */
357
            ob_start();
358
359
            /**
360
             * Get the schema version and other constants.
361
             */
362
            $bootstrap = new Bootstrap();
363
            $schema = 'public';
0 ignored issues
show
Unused Code introduced by
The assignment to $schema is dead and can be removed.
Loading history...
364
365
            /**
366
             * Now create the database.
367
             */
368
            $dbsettings = $_SESSION['spotsettings']['db'];
369
            $dbCon = dbeng_abs::getDbFactory($dbsettings['engine']);
370
            $dbCon->connect(
371
                $dbsettings['host'],
372
                $dbsettings['user'],
373
                $dbsettings['pass'],
374
                $dbsettings['dbname'],
375
                $dbsettings['port'],
376
                $dbsettings['schema']
377
            );
378
379
            $daoFactory = Dao_Factory::getDAOFactory($dbsettings['engine']);
380
            $daoFactory->setConnection($dbCon);
381
382
            /**
383
             * The database must exist before we can get the Service_Settings_Base instance.
384
             */
385
            $dbStruct = SpotStruct_abs::factory($dbsettings['engine'], $daoFactory->getConnection());
386
            $dbStruct->updateSchema();
387
388
            $spotSettings = $bootstrap->getSettings($daoFactory, false);
389
            $svcUpgradeBase = new Services_Upgrade_Base($daoFactory, $spotSettings, $dbsettings['engine']);
390
391
            /**
392
             * Create all the different settings (only the default) ones.
393
             */
394
            $svcUpgradeBase->settings();
395
396
            /**
397
             * Create the users.
398
             */
399
            $svcUpgradeBase->users();
400
401
            /**
402
             * print all the output as HTML comment for debugging.
403
             */
404
            $dbCreateOutput = ob_get_contents();
405
            ob_end_clean();
406
407
            /**
408
             * Now it is time to do something with
409
             * the information the user has given to us.
410
             */
411
412
            /**
413
             * Update the NNTP settings in the databas.
414
             */
415
            $spotSettings->set('nntp_nzb', $_SESSION['spotsettings']['nntp']['nzb']);
416
            $spotSettings->set('nntp_hdr', $_SESSION['spotsettings']['nntp']['hdr']);
417
            $spotSettings->set('nntp_post', $_SESSION['spotsettings']['nntp']['post']);
418
419
            /**
420
             * Create the given user.
421
             */
422
            $svcUserRecord = new Services_User_Record($daoFactory, $spotSettings);
423
            $spotUser = $_SESSION['spotsettings']['adminuser'];
424
425
            /**
426
             * and actually add the user.
427
             */
428
            $spotUser['userid'] = $svcUserRecord->createUserRecord($spotUser)->getData('userid');
429
430
            /**
431
             * When the new user was created a random password was assigned,
432
             * so now have to set the supplied password.
433
             */
434
            $svcUserRecord->setUserPassword($spotUser);
435
436
            // Change the administrators' account password to that of this created user.
437
            $adminUser = $svcUserRecord->getUser(SPOTWEB_ADMIN_USERID);
438
            $adminUser['newpassword1'] = $spotUser['newpassword1'];
439
            $svcUserRecord->setUserPassword($adminUser);
440
441
            // Update the settings with our system type and our admin id.
442
            $spotSettings->set('custom_admin_userid', $spotUser['userid']);
443
            $spotSettings->set('systemtype', $spotUser['systemtype']);
444
445
            // Set the system type.
446
            $svcUpgradeBase->resetSystemType($spotUser['systemtype']);
447
448
            /**
449
             * Create the necessary database connection information (dbsettings.inc.php).
450
             */
451
            $dbConnectionString = '';
452
            switch ($_SESSION['spotsettings']['db']['engine']) {
453
                case 'pdo_mysql':
454
                    $dbConnectionString = static::createDbSettingsFile('pdo_mysql');
455
                    break;
456
                case 'pdo_pgsql':
457
                    $dbConnectionString = static::createDbSettingsFile('pdo_pgsql');
458
                    break;
459
                case 'pdo_sqlite':
460
                    $dbConnectionString = static::createDbSettingsFile('pdo_sqlite');
461
                    break;
462
            }
463
464
            static::showTemplate(
465
                'step-final.inc.php',
466
                [
467
                    'createdDbSettings'  => file_exists(__DIR__.'/../dbsettings.inc.php'),
468
                    'dbCreateOutput'     => $dbCreateOutput,
469
                    'dbConnectionString' => $dbConnectionString,
470
                ]
471
            );
472
        } catch (Exception $x) {
473
            static::showTemplate('fatalerror.inc.php', ['x' => $x]);
474
        }
475
    }
476
477
    /**
478
     * Gets the database connection string.
479
     *
480
     * @param string $engine
481
     *
482
     * @return string
483
     */
484
    public static function createDbSettingsFile($engine)
485
    {
486
        $dbSettings = $_SESSION['spotsettings']['db'];
487
        switch ($_SESSION['spotsettings']['db']['engine']) {
488
            case 'pdo_pgsql':
489
                $settings = sprintf(
490
                    '<?php%1$s%1$s'
491
                    .'$dbsettings[\'engine\'] = \'%2$s\';%1$s'
492
                    .'$dbsettings[\'host\'] = \'%3$s\';%1$s'
493
                    .'$dbsettings[\'dbname\'] = \'%4$s\';%1$s'
494
                    .'$dbsettings[\'user\'] = \'%5$s\';%1$s'
495
                    .'$dbsettings[\'pass\'] = \'%6$s\';%1$s'
496
                    .'$dbsettings[\'port\'] = \'%7$s\';%1$s'
497
                    .'$dbsettings[\'schema\'] = \'%8$s\';%1$s',
498
                    PHP_EOL,
499
                    $engine,
500
                    $dbSettings['host'],
501
                    $dbSettings['dbname'],
502
                    $dbSettings['user'],
503
                    $dbSettings['pass'],
504
                    $dbSettings['port'],
505
                    $dbSettings['schema']
506
                );
507
                break;
508
            case 'pdo_mysql':
509
            case 'pdo_sqlite':
510
                $settings = sprintf(
511
                    '<?php%1$s%1$s'
512
            .'$dbsettings[\'engine\'] = \'%2$s\';%1$s'
513
            .'$dbsettings[\'host\'] = \'%3$s\';%1$s'
514
            .'$dbsettings[\'dbname\'] = \'%4$s\';%1$s'
515
            .'$dbsettings[\'user\'] = \'%5$s\';%1$s'
516
            .'$dbsettings[\'pass\'] = \'%6$s\';%1$s'
517
            .'$dbsettings[\'port\'] = \'%7$s\';%1$s'
518
            .'$dbsettings[\'schema\'] = \'\';',
519
                    PHP_EOL,
520
                    $engine,
521
                    $dbSettings['host'],
522
                    $dbSettings['dbname'],
523
                    $dbSettings['user'],
524
                    $dbSettings['pass'],
525
                    $dbSettings['port']
526
                );
527
                break;
528
        }
529
530
        if (is_writable(__DIR__.'/../')) {
531
            file_put_contents(
532
                __DIR__.'/../dbsettings.inc.php',
533
                $settings
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $settings does not seem to be defined for all execution paths leading up to this point.
Loading history...
534
            );
535
        }
536
537
        return $settings;
538
    }
539
540
    public static function returnBytes($val)
541
    {
542
        $val = trim($val);
543
        $last = strtolower($val[strlen($val) - 1]);
544
        $val = filter_var($val, FILTER_SANITIZE_NUMBER_INT);
545
        switch ($last) {
546
            // The 'G' modifier is available since PHP 5.1.0
547
            case 'g':
548
                $val *= 1024 * 1024 * 1024;
549
                break;
550
            case 'm':
551
                $val *= 1024 * 1024;
552
                break;
553
            case 'k':
554
                $val *= 1024;
555
                break;
556
        }
557
558
        return $val;
559
    }
560
561
    public static function showResult($b, $isRequired, $okMsg = '', $nokMsg = '')
562
    {
563
        global $_testInstall_Ok;
564
565
        if ($b) {
566
            echo 'OK';
567
            if (!empty($okMsg)) {
568
                echo ' ('.$okMsg.')';
569
            }
570
        } else {
571
            echo 'NOT OK';
572
            if (!empty($nokMsg)) {
573
                echo ' ('.$nokMsg.')';
574
            }
575
576
            if ($isRequired) {
577
                $_testInstall_Ok = true;
578
            }
579
        }
580
581
        return null;
582
    }
583
584
    /**
585
     * Callback for set_error_handler.
586
     *
587
     * @param int    $number
588
     * @param string $message
589
     * @param string $file
590
     * @param string $line
591
     * @param array  $context
592
     *
593
     * @return bool False, when the default error handler should take over and true when we handled it ourself.
594
     */
595
    public static function ownWarning($number, $message, $file, $line, array $context = [])
0 ignored issues
show
Unused Code introduced by
The parameter $number is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

595
    public static function ownWarning(/** @scrutinizer ignore-unused */ $number, $message, $file, $line, array $context = [])

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $file is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

595
    public static function ownWarning($number, $message, /** @scrutinizer ignore-unused */ $file, $line, array $context = [])

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $context is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

595
    public static function ownWarning($number, $message, $file, $line, /** @scrutinizer ignore-unused */ array $context = [])

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $line is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

595
    public static function ownWarning($number, $message, $file, /** @scrutinizer ignore-unused */ $line, array $context = [])

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
596
    {
597
        // don't show errors if they are being suppressed by silent (@) operator.
598
        if (error_reporting() === 0) {
599
            return false;
600
        }
601
602
        $GLOBALS['iserror'] = true;
603
        error_log($message);
604
        echo $message;
605
606
        return true;
607
    }
608
609
    public static function testInclude($filename)
610
    {
611
        if (!file_exists($filename)) {
612
            return false;
613
        }
614
615
        require_once $filename;
616
617
        return dirname(realpath($filename));
618
    }
619
620
    /**
621
     * Goes to the one of the installation pages.
622
     *
623
     * @param int $number
624
     */
625
    public static function gotoPage($number)
626
    {
627
        header(
628
            sprintf(
629
                'Location: %s?page=%u',
630
                $_SERVER['SCRIPT_NAME'],
631
                $number
632
            )
633
        );
634
    }
635
}
636