MOON
Server: Apache
System: Linux kvm.asjudinet.com 5.14.0-611.54.6.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Fri May 15 04:23:18 EDT 2026 x86_64
User: asjudine (1001)
PHP: 8.0.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/share/l.v.e-manager/directadmin/lvemanager_spa/app/Base/Controller.php
<?php
/**
 * Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2019 All Rights Reserved
 *
 * Licensed under CLOUD LINUX LICENSE AGREEMENT
 * http://cloudlinux.com/docs/LICENSE.TXT
 */


namespace App\Base;

/**
 * Class Controller
 *
 * @package selector\base
 */
class Controller {
    /**
     * Default controller directory
     */
    const CONTROLLER_DIRECTORY  = 'controller';

    /**
     * @var string
     */
    public $pageTitle;

    /**
     * @var string
     */
    private $controllerDirectory;
    /**
     * View object
     *
     * @var View
     */
    private $_view;

    /**
     * Controller object
     *
     * @var Controller
     */
    protected $controller;
    /**
     * @var string
     */
    protected $controllerName;
    /**
     * @var string
     */
    protected $action;

    /**
     * @var string
     */
    public $defaultAction = 'index';

    /**
     *
     */
    public function __construct()
    {
        $this->controllerDirectory = Base::load()->getBilling();
        $this->init();
    }

    /**
     * Initialize method
     */
    public function init()
    {

    }

    /**
     * Try to resolve current controller by given params
     *
     * @param $controller
     * @param $action
     * @return mixed
     * @throws \Exception
     */
    public function getController($controller, $action)
    {
        // Allowlist BEFORE assigning $this->controllerName / touching
        // Composer's PSR-4 ClassLoader.  $controller is built from
        // $_GET['c'] (Base::getParam, no sanitization).  Composer's
        // ClassLoader translates `\\` to `/` and `file_exists` +
        // `includeFile`s the resolved path; a payload like
        // `foo/../../../target` traverses out of app/Controller/Spa/ and
        // triggers top-level side effects in any reachable .php file.
        // PSR-4 identifiers here are letters/digits optionally dash-joined
        // (e.g. `index`, `send-request`); reject anything else.
        if (!is_string($controller) || !preg_match('/^[A-Za-z][A-Za-z0-9]*(?:-[A-Za-z0-9]+)*$/', $controller)) {
            throw new Exception('Undefined page');
        }

        $this->action = empty($action) ? $this->defaultAction : $action;
        $this->controllerName = lcfirst($controller);

        try {
            $partsOfController = explode('-', $controller);
            $controllerClass = '';
            foreach ($partsOfController as $part) {
                $controllerClass .= ucfirst($part);
            }

            $controllerClass .= 'Controller';

            $this->controller = '\\App\\Controller\\'.$this->controllerDirectory.'\\'.$controllerClass;

            if (!class_exists($this->controller)) {
                throw new Exception('Undefined page');
            }

            $model = new $this->controller;
            $model->controller = $this->controller;
            $model->controllerName = $this->controllerName;
            $model->action = $this->action;
            $model->setView();

            return $model;
        } catch(\Exception $e) {
            throw new Exception($e->getMessage());
        }
    }

    /**
     * Set view object
     */
    public function setView()
    {
        $this->_view = new View($this->controllerName);
    }

    /**
     * Get View object
     *
     * @return View
     */
    public function getView()
    {
        return $this->_view;
    }

    /**
     * Run controller action
     *
     * @throws \Exception
     */
    public function runAction()
    {
        $actionMethod = lcfirst($this->action) . 'Action';

        if(!method_exists($this, $actionMethod)) {
            throw new Exception('Undefined controller action "'.$this->action.'"');
        }

        $method = new \ReflectionMethod($this->controller, $actionMethod);
        $method->invoke($this);
    }

    /**
     * Render view file with layout
     *
     * @param string $view
     * @param array $values
     * @param bool $output
     * @return string
     */
    public function render($view = 'index', $values = array(), $output = true)
    {
        return $this->_view->render($view, $values, $output);
    }

    /**
     * Render view file
     *
     * @param string $view
     * @param array $values
     * @param bool $output
     * @return string
     */
    public function renderPartial($view, $values, $output = true)
    {
        return $this->_view->renderPartial($view, $values, $output);
    }
}