Issues (2963)

app/Http/Controllers/LegacyController.php (3 issues)

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Checks;
6
use Illuminate\Contracts\Session\Session;
7
use Illuminate\Http\Request;
8
use Illuminate\Support\Arr;
9
use Illuminate\Support\Str;
10
use LibreNMS\Config;
11
use LibreNMS\Util\Debug;
12
13
class LegacyController extends Controller
14
{
15
    public function index(Request $request, Session $session)
16
    {
17
        Checks::postAuth();
18
19
        // Set variables
20
        $no_refresh = false;
21
        $init_modules = ['web', 'auth'];
22
        require base_path('/includes/init.php');
23
24
        Debug::set(Str::contains($request->path(), 'debug'));
25
26
        ob_start(); // protect against bad plugins that output during start
27
        \LibreNMS\Plugins::start();
28
        ob_end_clean();
29
30
        if (Str::contains($request->path(), 'widescreen=yes')) {
31
            $session->put('widescreen', 1);
32
        }
33
        if (Str::contains($request->path(), 'widescreen=no')) {
34
            $session->forget('widescreen');
35
        }
36
37
        // Load the settings for Multi-Tenancy.
38
        if (Config::has('branding') && is_array(Config::get('branding'))) {
39
            $branding = Arr::dot(Config::get('branding.' . $request->server('SERVER_NAME'), Config::get('branding.default')));
40
            foreach ($branding as $key => $value) {
41
                Config::set($key, $value);
42
            }
43
        }
44
45
        // page_title_prefix is displayed, unless page_title is set FIXME: NEEDED?
46
        if (Config::has('page_title')) {
47
            Config::set('page_title_prefix', Config::get('page_title'));
48
        }
49
50
        // render page
51
        ob_start();
52
        $vars['page'] = basename($vars['page'] ?? '');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $vars seems to never exist and therefore isset should always be false.
Loading history...
Comprehensibility Best Practice introduced by
$vars was never initialized. Although not strictly required by PHP, it is generally a good practice to add $vars = array(); before regardless.
Loading history...
53
        if ($vars['page'] && is_file('includes/html/pages/' . $vars['page'] . '.inc.php')) {
54
            require 'includes/html/pages/' . $vars['page'] . '.inc.php';
55
        } else {
56
            abort(404);
57
        }
58
59
        $html = ob_get_clean();
60
        ob_end_clean();
61
62
        /** @phpstan-ignore-next-line */
63
        if (isset($pagetitle) && is_array($pagetitle)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $pagetitle seems to never exist and therefore isset should always be false.
Loading history...
64
            // if prefix is set, put it in front
65
            if (Config::get('page_title_prefix')) {
66
                array_unshift($pagetitle, Config::get('page_title_prefix'));
67
            }
68
69
            // if suffix is set, put it in the back
70
            if (Config::get('page_title_suffix')) {
71
                $pagetitle[] = Config::get('page_title_suffix');
72
            }
73
74
            // create and set the title
75
            $title = join(' - ', $pagetitle);
76
            $html .= "<script type=\"text/javascript\">\ndocument.title = '$title';\n</script>";
77
        }
78
79
        return response()->view('layouts.legacy_page', [
80
            'content' => $html,
81
            'refresh' => $no_refresh ? 0 : Config::get('page_refresh'),
82
        ]);
83
    }
84
85
    public function dummy()
86
    {
87
        return 'Dummy page';
88
    }
89
}
90