Example #1
0
 public function installBitrix24MailService()
 {
     if (CModule::IncludeModule("mail")) {
         $result = \Bitrix\Main\SiteTable::getList();
         while (($site = $result->fetch()) !== false) {
             if (CModule::IncludeModule('extranet') && CExtranet::IsExtranetSite($site['LID'])) {
                 continue;
             }
             \Bitrix\Mail\MailServicesTable::add(array('SITE_ID' => $site['LID'], 'ACTIVE' => 'Y', 'NAME' => 'bitrix24', 'SERVICE_TYPE' => 'controller'));
         }
     }
 }
Example #2
0
 private function executeDomainPage()
 {
     global $USER, $APPLICATION;
     $APPLICATION->setTitle(GetMessage('INTR_MAIL_DOMAIN_PAGE_TITLE'));
     if (!$USER->isAdmin() && !$USER->canDoOperation('bitrix24_config')) {
         $APPLICATION->AuthForm(GetMessage('ACCESS_DENIED'));
         return;
     }
     $errors = array();
     $status = false;
     $serviceId = null;
     $settings = array();
     $services = CIntranetMailSetupHelper::getMailServices();
     if ($domainService = CIntranetMailSetupHelper::getDomainService()) {
         $serviceId = $domainService['id'];
         $settings = array('type' => $domainService['type'], 'domain' => $domainService['server'], 'flags' => $domainService['flags'], 'token' => $domainService['token'], 'public' => $domainService['encryption'] == 'N' ? 'Y' : 'N');
     }
     if ($serviceId) {
         $status = self::checkDomainStatus($settings, $error);
         // не нужно при посте
         if ($error) {
             $errors[] = $error;
         }
     }
     if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['act'])) {
         $errors = array();
         if (!check_bitrix_sessid()) {
             $errors[] = GetMessage('INTR_MAIL_CSRF');
         }
         if (!empty($errors)) {
         } else {
             if ($_POST['act'] == 'save') {
                 if (empty($_REQUEST['type']) || !in_array($_REQUEST['type'], array('delegate', 'connect'))) {
                     $errors[] = GetMessage('INTR_MAIL_FORM_ERROR');
                 }
                 if (empty($errors)) {
                     if (!$serviceId && empty($_REQUEST['domain'])) {
                         $errors[] = GetMessage('INTR_MAIL_INP_DOMAIN_EMPTY');
                     }
                     if ($_REQUEST['type'] == 'connect' && empty($_REQUEST['token'])) {
                         $errors[] = GetMessage('INTR_MAIL_INP_TOKEN_EMPTY');
                     }
                     if (!$serviceId) {
                         $settings['type'] = $_REQUEST['type'] == 'connect' ? 'domain' : 'crdomain';
                         $settings['domain'] = $_REQUEST['domain'];
                     }
                     if ($settings['type'] == 'domain') {
                         $settings['token'] = $_REQUEST['token'];
                     }
                     $settings['public'] = isset($_REQUEST['public']) && $_REQUEST['public'] == 'Y' ? 'Y' : 'N';
                     if (empty($errors)) {
                         $status = self::checkDomainStatus($settings, $error);
                         if ($error) {
                             $errors[] = $error;
                         }
                         if (empty($errors)) {
                             if ($serviceId) {
                                 $result = \Bitrix\Mail\MailServicesTable::update($serviceId, array('TOKEN' => $settings['token'], 'ENCRYPTION' => $settings['public'] == 'Y' ? 'N' : 'Y'));
                             } else {
                                 $result = \Bitrix\Mail\MailServicesTable::add(array('SITE_ID' => SITE_ID, 'ACTIVE' => 'Y', 'SERVICE_TYPE' => $settings['type'], 'NAME' => $settings['domain'], 'SERVER' => $settings['domain'], 'ENCRYPTION' => $settings['public'] == 'Y' ? 'N' : 'Y', 'SORT' => $serviceId ? $services[$serviceId]['sort'] + 1 : 100, 'TOKEN' => $settings['token']));
                                 if ($result->isSuccess()) {
                                     $serviceId = $result->getId();
                                     if ($settings['type'] == 'domain') {
                                         if ($status['stage'] == 'added') {
                                             CAgent::addAgent('CIntranetUtils::notifyMailDomain("nomailbox", ' . $serviceId . ', ' . $USER->getId() . ');', 'intranet', 'N', 3600 * 24 * 7);
                                         } else {
                                             CAgent::addAgent('CIntranetUtils::checkMailDomain(' . $serviceId . ', ' . $USER->getId() . ');', 'intranet', 'N', 600);
                                             CAgent::addAgent('CIntranetUtils::notifyMailDomain("nocomplete", ' . $serviceId . ', ' . $USER->getId() . ');', 'intranet', 'N', 3600 * 24 * 3);
                                         }
                                         CMailDomain2::setDomainLogo($settings['token'], $settings['domain'], $_SERVER['DOCUMENT_ROOT'] . $this->getPath() . '/images/' . GetMessage('INTR_MAIL_DOMAIN_ICON'), $replace = false, $error);
                                         CMailDomain2::selLocale($settings['token'], $settings['domain'], LANGUAGE_ID, $error);
                                     }
                                 }
                             }
                             if ($result->isSuccess()) {
                                 if ($status['stage'] == 'added') {
                                     LocalRedirect($APPLICATION->GetCurPage() . '?page=manage');
                                 }
                             } else {
                                 $errors[] = GetMessage('INTR_MAIL_SAVE_ERROR');
                             }
                         }
                     }
                 }
             } else {
                 if ($serviceId && $_POST['act'] == 'remove') {
                     $result = \Bitrix\Mail\MailServicesTable::delete($serviceId);
                     if ($result->isSuccess()) {
                         LocalRedirect($APPLICATION->GetCurPage() . '?page=home');
                     } else {
                         LocalRedirect($APPLICATION->GetCurPage() . '?page=domain');
                     }
                 }
             }
         }
     }
     $this->arParams['SERVICES'] = $services;
     $this->arResult['SERVICE'] = $serviceId;
     $this->arResult['SETTINGS'] = $settings;
     $this->arResult['ERRORS'] = $errors;
     $this->arResult['STATUS'] = $status;
     $this->includeComponentTemplate('domain');
 }
Example #3
0
 private static function executeDomainCreate(&$error)
 {
     global $USER;
     $error = false;
     if (!check_bitrix_sessid()) {
         $error = GetMessage('INTR_MAIL_CSRF');
     }
     if ($error === false) {
         if (CIntranetMailSetupHelper::getDomainService()) {
             $error = GetMessage('INTR_MAIL_AJAX_ERROR');
         }
     }
     if ($error === false) {
         $crResponse = CControllerClient::ExecuteEvent('OnMailControllerAddMemberDomain', array('DOMAIN' => $_REQUEST['domain']));
         if (!isset($crResponse['result'])) {
             $error = empty($crResponse['error']) ? GetMessage('INTR_MAIL_CONTROLLER_INVALID') : CMail::getErrorMessage($crResponse['error']);
         } else {
             $result = $crResponse['result'];
             if (!is_array($result)) {
                 $error = GetMessage('INTR_MAIL_CONTROLLER_INVALID');
             }
             if (!isset($result['stage']) || !in_array($result['stage'], array('owner-check', 'mx-check', 'added'))) {
                 $error = GetMessage('INTR_MAIL_CONTROLLER_INVALID');
             } else {
                 if ($result['stage'] == 'owner-check' && (!isset($result['secrets']['name']) || !isset($result['secrets']['content']))) {
                     $error = GetMessage('INTR_MAIL_CONTROLLER_INVALID');
                 }
             }
             if ($error === false) {
                 $domainStage = $result['stage'];
                 if ($result['stage'] == 'owner-check') {
                     $domainSecrets = array('name' => $result['secrets']['name'], 'content' => $result['secrets']['content']);
                 }
             }
         }
         if ($error === false) {
             $result = \Bitrix\Mail\MailServicesTable::add(array('SITE_ID' => SITE_ID, 'ACTIVE' => 'Y', 'SERVICE_TYPE' => 'crdomain', 'NAME' => $_REQUEST['domain'], 'SERVER' => $_REQUEST['domain'], 'ENCRYPTION' => $_REQUEST['public'] == 'Y' ? 'N' : 'Y'));
             if ($result->isSuccess()) {
                 CAgent::addAgent('CIntranetUtils::checkMailDomain(' . $result->getId() . ', ' . $USER->getId() . ');', 'intranet', 'N', 600);
                 CAgent::addAgent('CIntranetUtils::notifyMailDomain("nocomplete", ' . $result->getId() . ', ' . $USER->getId() . ');', 'intranet', 'N', 3600 * 24 * 3);
             }
             if (!$result->isSuccess()) {
                 $error = GetMessage('INTR_MAIL_SAVE_ERROR');
             }
         }
     }
     return array('stage' => isset($domainStage) ? $domainStage : '', 'secrets' => isset($domainSecrets) ? $domainSecrets : '');
 }