Mini Shell

Direktori : /usr/share/l.v.e-manager/directadmin/lvemanager_spa/app/Base/
Upload File :
Current File : //usr/share/l.v.e-manager/directadmin/lvemanager_spa/app/Base/SpaManager.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 SpaManager
 *
 * @package selector\base
 */
class SpaManager extends BillingManager {

    /**
     *
     */
    public function __construct()
    {
        $this->init();
    }

    /**
     * Initialize controller\action params
     *
     * @throws \Exception
     */
    public function init()
    {
        $this->actionName = Base::load()->getParam('a');
        $this->controllerName = Base::load()->getParam('c', 'index');
        $this->setHomeUrl();
    }

    /**
     * Run controller action by given params
     */
    public function run()
    {
        $model = new Controller();
        $this->controller = $model->getController($this->controllerName, $this->actionName);
        $this->controller->runAction();
    }

    /**
     * Get asset manager
     *
     * @return SpaAssets
     */
    public function getAssetManager()
    {
        $this->assetManager = $this->assetManager ? $this->assetManager : new SpaAssets();

        return $this->assetManager;
    }

    /**
     * Set home URL
     */
    public function setHomeUrl()
    {
        $parsedUrl = parse_url($_SERVER['REQUEST_URI']);

        $this->homeUrl = $parsedUrl['path'] .'?'. http_build_query(array(
            'page' => Base::load()->getParam('page'),
        ));
    }

    /**
     *
     * @param $controller
     * @param array $params
     * @return string
     */
    public function createUrl($controller, $params = array())
    {
        return $this->homeUrl . (strpos($this->homeUrl, '?') !== false) ? '&' : '?' . http_build_query($params);
    }

    /**
     * Check user privileges
     *
     * @return bool
     */
    public function isAdmin()
    {
        $command = '/usr/bin/sudo -n /usr/sbin/lvectl lve-version 2>&1';

        ob_start();
        passthru($command);
        $result = ob_get_contents();
        ob_end_clean();

        $regex_result = preg_match('/(?:password is required|you must have a tty)/', $result);

        if($regex_result == 1) {
            return false;
        } elseif($regex_result == 0) {
            return true;
        }

        return false;
    }

    /**
     * Get user domains\subdomains
     *
     * @param string|null $user
     * @return array
     */
    public function getDomains($user = null)
    {
        $domainsList = array();
        $user = $user ? $user : $_SERVER['USER'];
        $homeDir = $_SERVER['HOME'];

        if(!is_dir($domainDir = $homeDir . DS . 'domains')) {
            return $domainsList;
        }

        $domains = glob($domainDir . DS . '*', GLOB_ONLYDIR);
        foreach($domains as $domainPath) {
            $parts = explode(DS, $domainPath);
            $domain = array_pop($parts);
            $domainsList[] = $domain;

            $subDomains = glob($domainPath . DS . 'stats' . DS . '*', GLOB_ONLYDIR);
            foreach($subDomains as $subDomain) {
                $parts = explode(DS, $subDomain);
                $domainsList[] = array_pop($parts) . '.' . $domain;
            }
        }

        return $domainsList;
    }

    public function getLogin()
    {
        return $_SERVER['USER'];
    }

    public function getCurrentDomain()
    {
        return $_SERVER['SESSION_SELECTED_DOMAIN'];
    }

    public function getUID()
    {
        return exec('/usr/bin/getent passwd '.$_SERVER['USER'].' | cut -d: -f3');
    }

    public function getPluginVersion() {
        return file_get_contents('/usr/share/l.v.e-manager/version');
    }

} 

Zerion Mini Shell 1.0