public function processWindow($window, $id, $ctrl, $param1, $param2)
 {
     global $neardBs, $neardBins, $neardLang, $neardWinbinder;
     $name = $neardWinbinder->getText($this->wbInputName[WinBinder::CTRL_OBJ]);
     $target = $neardWinbinder->getText($this->wbInputDest[WinBinder::CTRL_OBJ]);
     switch ($id) {
         case $this->wbBtnDest[WinBinder::CTRL_ID]:
             $target = $neardWinbinder->sysDlgPath($window, $neardLang->getValue(Lang::GENSSL_PATH), $target);
             if ($target && is_dir($target)) {
                 $neardWinbinder->setText($this->wbInputDest[WinBinder::CTRL_OBJ], $target . '\\');
             }
             break;
         case $this->wbBtnSave[WinBinder::CTRL_ID]:
             $neardWinbinder->setProgressBarMax($this->wbProgressBar, self::GAUGE_SAVE + 1);
             $neardWinbinder->incrProgressBar($this->wbProgressBar);
             $target = Util::formatUnixPath($target);
             if (Batch::genSslCertificate($name, $target)) {
                 $neardWinbinder->incrProgressBar($this->wbProgressBar);
                 $neardWinbinder->messageBoxInfo(sprintf($neardLang->getValue(Lang::GENSSL_CREATED), $name), $neardLang->getValue(Lang::GENSSL_TITLE));
                 $neardWinbinder->destroyWindow($window);
             } else {
                 $neardWinbinder->messageBoxError($neardLang->getValue(Lang::GENSSL_CREATED_ERROR), $neardLang->getValue(Lang::GENSSL_TITLE));
                 $neardWinbinder->resetProgressBar($this->wbProgressBar);
             }
             break;
         case IDCLOSE:
         case $this->wbBtnCancel[WinBinder::CTRL_ID]:
             $neardWinbinder->destroyWindow($window);
             break;
     }
 }
 public function processWindow($window, $id, $ctrl, $param1, $param2)
 {
     global $neardBs, $neardBins, $neardLang, $neardWinbinder;
     $serverName = $neardWinbinder->getText($this->wbInputServerName[WinBinder::CTRL_OBJ]);
     $documentRoot = $neardWinbinder->getText($this->wbInputDocRoot[WinBinder::CTRL_OBJ]);
     switch ($id) {
         case $this->wbInputServerName[WinBinder::CTRL_ID]:
             $neardWinbinder->setText($this->wbLabelExp[WinBinder::CTRL_OBJ], sprintf($neardLang->getValue(Lang::VHOST_EXP_LABEL), $serverName, $documentRoot));
             $neardWinbinder->setEnabled($this->wbBtnSave[WinBinder::CTRL_OBJ], empty($serverName) ? false : true);
             break;
         case $this->wbBtnDocRoot[WinBinder::CTRL_ID]:
             $documentRoot = $neardWinbinder->sysDlgPath($window, $neardLang->getValue(Lang::VHOST_DOC_ROOT_PATH), $documentRoot);
             if ($documentRoot && is_dir($documentRoot)) {
                 $neardWinbinder->setText($this->wbInputDocRoot[WinBinder::CTRL_OBJ], $documentRoot . '\\');
                 $neardWinbinder->setText($this->wbLabelExp[WinBinder::CTRL_OBJ], sprintf($neardLang->getValue(Lang::VHOST_EXP_LABEL), $serverName, $documentRoot . '\\'));
             }
             break;
         case $this->wbBtnSave[WinBinder::CTRL_ID]:
             $neardWinbinder->setProgressBarMax($this->wbProgressBar, self::GAUGE_SAVE + 1);
             $neardWinbinder->incrProgressBar($this->wbProgressBar);
             if (is_file($neardBs->getVhostsPath() . '/' . $serverName . '.conf')) {
                 $neardWinbinder->messageBoxError(sprintf($neardLang->getValue(Lang::VHOST_ALREADY_EXISTS), $serverName), $neardLang->getValue(Lang::ADD_VHOST_TITLE));
                 $neardWinbinder->resetProgressBar($this->wbProgressBar);
                 break;
             }
             if (Batch::genSslCertificate($serverName) && file_put_contents($neardBs->getVhostsPath() . '/' . $serverName . '.conf', $neardBins->getApache()->getVhostContent($serverName, $documentRoot)) !== false) {
                 $neardWinbinder->incrProgressBar($this->wbProgressBar);
                 Util::addWindowsHost('127.0.0.1', $serverName);
                 $neardWinbinder->incrProgressBar($this->wbProgressBar);
                 $neardBins->getApache()->getService()->restart();
                 $neardWinbinder->incrProgressBar($this->wbProgressBar);
                 $neardWinbinder->messageBoxInfo(sprintf($neardLang->getValue(Lang::VHOST_CREATED), $serverName, $serverName, $documentRoot), $neardLang->getValue(Lang::ADD_VHOST_TITLE));
                 $neardWinbinder->destroyWindow($window);
             } else {
                 $neardWinbinder->messageBoxError($neardLang->getValue(Lang::VHOST_CREATED_ERROR), $neardLang->getValue(Lang::ADD_VHOST_TITLE));
                 $neardWinbinder->resetProgressBar($this->wbProgressBar);
             }
             break;
         case IDCLOSE:
         case $this->wbBtnCancel[WinBinder::CTRL_ID]:
             $neardWinbinder->destroyWindow($window);
             break;
     }
 }
 private function installServices()
 {
     global $neardLang, $neardBins;
     if (!$this->restart) {
         foreach ($neardBins->getServicesStartup() as $sName => $service) {
             $serviceError = '';
             $serviceRestart = false;
             $startServiceTime = Util::getMicrotime();
             $syntaxCheckCmd = null;
             if ($sName == BinApache::SERVICE_NAME) {
                 $bin = $neardBins->getApache();
                 $syntaxCheckCmd = BinApache::CMD_SYNTAX_CHECK;
             } elseif ($sName == BinMysql::SERVICE_NAME) {
                 $bin = $neardBins->getMysql();
                 $syntaxCheckCmd = BinMysql::CMD_SYNTAX_CHECK;
             } elseif ($sName == BinMariadb::SERVICE_NAME) {
                 $bin = $neardBins->getMariadb();
                 $syntaxCheckCmd = BinMariadb::CMD_SYNTAX_CHECK;
             } elseif ($sName == BinFilezilla::SERVICE_NAME) {
                 $bin = $neardBins->getFilezilla();
             }
             $name = $bin->getName() . ' ' . $bin->getVersion() . ' (' . $service->getName() . ')';
             $port = $bin->getPort();
             $this->splash->incrProgressBar();
             $this->splash->setTextLoading(sprintf($neardLang->getValue(Lang::STARTUP_INSTALL_SERVICE_TEXT), $name));
             $this->splash->incrProgressBar();
             if (!$service->delete()) {
                 $serviceRestart = true;
             }
             $this->splash->incrProgressBar();
             if ($bin->changePort($port) !== true) {
                 $serviceError .= sprintf($neardLang->getValue(Lang::STARTUP_PORT_ERROR), $port);
             }
             if (!$serviceRestart) {
                 $isPortInUse = Util::isPortInUse($port);
                 if ($isPortInUse === false) {
                     $this->splash->incrProgressBar();
                     if (!$service->create()) {
                         $serviceError .= sprintf($neardLang->getValue(Lang::STARTUP_SERVICE_CREATE_ERROR), $service->getError());
                     }
                     if ($sName == BinApache::SERVICE_NAME && !$neardBins->getApache()->existsSslCrt()) {
                         $this->splash->setTextLoading(sprintf($neardLang->getValue(Lang::STARTUP_GEN_SSL_CRT_TEXT), 'localhost'));
                         Batch::genSslCertificate('localhost');
                     } elseif ($sName == BinFilezilla::SERVICE_NAME && !$neardBins->getFilezilla()->existsSslCrt()) {
                         $this->splash->setTextLoading(sprintf($neardLang->getValue(Lang::STARTUP_GEN_SSL_CRT_TEXT), $neardLang->getValue(Lang::FILEZILLA)));
                         Batch::genSslCertificate(BinFilezilla::SERVICE_NAME);
                     }
                     $this->splash->incrProgressBar();
                     $this->splash->setTextLoading(sprintf($neardLang->getValue(Lang::STARTUP_START_SERVICE_TEXT), $name));
                     if (!$service->start()) {
                         if (!empty($serviceError)) {
                             $serviceError .= PHP_EOL;
                         }
                         $serviceError .= sprintf($neardLang->getValue(Lang::STARTUP_SERVICE_START_ERROR), $service->getError());
                         if (!empty($syntaxCheckCmd)) {
                             $cmdSyntaxCheck = $bin->getCmdLineOutput($syntaxCheckCmd);
                             if (!$cmdSyntaxCheck['syntaxOk']) {
                                 $serviceError .= PHP_EOL . sprintf($neardLang->getValue(Lang::STARTUP_SERVICE_SYNTAX_ERROR), $cmdSyntaxCheck['content']);
                             }
                         }
                     }
                     $this->splash->incrProgressBar();
                 } else {
                     if (!empty($serviceError)) {
                         $serviceError .= PHP_EOL;
                     }
                     $serviceError .= sprintf($neardLang->getValue(Lang::STARTUP_SERVICE_PORT_ERROR), $port, $isPortInUse);
                     $this->splash->incrProgressBar(3);
                 }
             } else {
                 $this->restart = true;
                 $this->splash->incrProgressBar(3);
             }
             if (!empty($serviceError)) {
                 if (!empty($this->error)) {
                     $this->error .= PHP_EOL . PHP_EOL;
                 }
                 $this->error .= sprintf($neardLang->getValue(Lang::STARTUP_SERVICE_ERROR), $name) . PHP_EOL . $serviceError;
             } else {
                 $this->writeLog($name . ' service installed in ' . round(Util::getMicrotime() - $startServiceTime, 3) . 's');
             }
         }
     } else {
         $this->splash->incrProgressBar(self::GAUGE_SERVICES * count($neardBins->getServicesStartup()));
     }
 }
 public function processWindow($window, $id, $ctrl, $param1, $param2)
 {
     global $neardBs, $neardBins, $neardLang, $neardWinbinder;
     $apachePortUri = $neardBins->getApache()->getPort() != 80 ? ':' . $neardBins->getApache()->getPort() : '';
     $serverName = $neardWinbinder->getText($this->wbInputServerName[WinBinder::CTRL_OBJ]);
     $documentRoot = $neardWinbinder->getText($this->wbInputDocRoot[WinBinder::CTRL_OBJ]);
     switch ($id) {
         case $this->wbInputServerName[WinBinder::CTRL_ID]:
             $neardWinbinder->setText($this->wbLabelExp[WinBinder::CTRL_OBJ], sprintf($neardLang->getValue(Lang::VHOST_EXP_LABEL), $serverName, $documentRoot));
             $neardWinbinder->setEnabled($this->wbBtnSave[WinBinder::CTRL_OBJ], empty($serverName) ? false : true);
             break;
         case $this->wbBtnDocRoot[WinBinder::CTRL_ID]:
             $documentRoot = $neardWinbinder->sysDlgPath($window, $neardLang->getValue(Lang::VHOST_DOC_ROOT_PATH), $documentRoot);
             if ($documentRoot && is_dir($documentRoot)) {
                 $neardWinbinder->setText($this->wbInputDocRoot[WinBinder::CTRL_OBJ], $documentRoot . '\\');
                 $neardWinbinder->setText($this->wbLabelExp[WinBinder::CTRL_OBJ], sprintf($neardLang->getValue(Lang::VHOST_EXP_LABEL), $serverName, $documentRoot . '\\'));
             }
             break;
         case $this->wbBtnSave[WinBinder::CTRL_ID]:
             $neardWinbinder->setProgressBarMax($this->wbProgressBar, self::GAUGE_SAVE + 1);
             $neardWinbinder->incrProgressBar($this->wbProgressBar);
             if ($serverName != $this->initServerName && is_file($neardBs->getVhostsPath() . '/' . $serverName . '.conf')) {
                 $neardWinbinder->messageBoxError(sprintf($neardLang->getValue(Lang::VHOST_ALREADY_EXISTS), $serverName), sprintf($neardLang->getValue(Lang::EDIT_VHOST_TITLE), $this->initServerName));
                 $neardWinbinder->resetProgressBar($this->wbProgressBar);
                 break;
             }
             if ($neardBins->getApache()->removeSslCrt($this->initServerName) && @unlink($neardBs->getVhostsPath() . '/' . $this->initServerName . '.conf')) {
                 new ActionSwitchHost(array('127.0.0.1', $this->initServerName, ActionSwitchHost::SWITCH_OFF));
             }
             if (Batch::genSslCertificate($serverName) && file_put_contents($neardBs->getVhostsPath() . '/' . $serverName . '.conf', $neardBins->getApache()->getVhostContent($serverName, $documentRoot)) !== false) {
                 $neardWinbinder->incrProgressBar($this->wbProgressBar);
                 Util::addWindowsHost('127.0.0.1', $serverName);
                 $neardWinbinder->incrProgressBar($this->wbProgressBar);
                 $neardBins->getApache()->getService()->restart();
                 $neardWinbinder->incrProgressBar($this->wbProgressBar);
                 $neardWinbinder->messageBoxInfo(sprintf($neardLang->getValue(Lang::VHOST_CREATED), $serverName, $serverName, $documentRoot), sprintf($neardLang->getValue(Lang::EDIT_VHOST_TITLE), $this->initServerName));
                 $neardWinbinder->destroyWindow($window);
             } else {
                 $neardWinbinder->messageBoxError($neardLang->getValue(Lang::VHOST_CREATED_ERROR), sprintf($neardLang->getValue(Lang::EDIT_VHOST_TITLE), $this->initServerName));
                 $neardWinbinder->resetProgressBar($this->wbProgressBar);
             }
             break;
         case $this->wbBtnDelete[WinBinder::CTRL_ID]:
             $neardWinbinder->setProgressBarMax($this->wbProgressBar, self::GAUGE_DELETE + 1);
             $boxTitle = $neardLang->getValue(Lang::DELETE_VHOST_TITLE);
             $confirm = $neardWinbinder->messageBoxYesNo(sprintf($neardLang->getValue(Lang::DELETE_VHOST), $this->initServerName), $boxTitle);
             $neardWinbinder->incrProgressBar($this->wbProgressBar);
             if ($confirm) {
                 if ($neardBins->getApache()->removeSslCrt($this->initServerName) && @unlink($neardBs->getVhostsPath() . '/' . $this->initServerName . '.conf')) {
                     $neardWinbinder->incrProgressBar($this->wbProgressBar);
                     new ActionSwitchHost(array('127.0.0.1', $this->initServerName, ActionSwitchHost::SWITCH_OFF));
                     $neardWinbinder->incrProgressBar($this->wbProgressBar);
                     $neardBins->getApache()->getService()->restart();
                     $neardWinbinder->incrProgressBar($this->wbProgressBar);
                     $neardWinbinder->messageBoxInfo(sprintf($neardLang->getValue(Lang::VHOST_REMOVED), $this->initServerName), $boxTitle);
                     $neardWinbinder->destroyWindow($window);
                 } else {
                     $neardWinbinder->messageBoxError(sprintf($neardLang->getValue(Lang::VHOST_REMOVE_ERROR), $neardBs->getVhostsPath() . '/' . $this->initServerName . '.conf'), $boxTitle);
                     $neardWinbinder->resetProgressBar($this->wbProgressBar);
                 }
             }
             break;
         case IDCLOSE:
         case $this->wbBtnCancel[WinBinder::CTRL_ID]:
             $neardWinbinder->destroyWindow($window);
             break;
     }
 }