示例#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'));
         }
     }
 }
示例#2
0
 public static function getMailServices()
 {
     static $services;
     if (is_null($services)) {
         $dbServices = \Bitrix\Mail\MailServicesTable::getList(array('filter' => array('ACTIVE' => 'Y', '=SITE_ID' => SITE_ID), 'order' => array('SORT' => 'ASC', 'NAME' => 'ASC')));
         $services = array();
         while (($service = $dbServices->fetch()) !== false) {
             $services[$service['ID']] = array('id' => $service['ID'], 'type' => $service['SERVICE_TYPE'], 'name' => $service['NAME'], 'link' => $service['LINK'], 'icon' => \Bitrix\Mail\MailServicesTable::getIconSrc($service['NAME'], $service['ICON']), 'server' => $service['SERVER'], 'port' => $service['PORT'], 'encryption' => $service['ENCRYPTION'], 'token' => $service['TOKEN'], 'flags' => $service['FLAGS'], 'sort' => $service['SORT']);
         }
     }
     return $services;
 }
示例#3
0
 public static function notifyMailDomain($type, $sid, $user_id, $cnt = 0)
 {
     $user_id = intval($user_id);
     $cnt = intval($cnt);
     if (!CModule::includeModule('mail')) {
         return '';
     }
     $arAdmin = CUser::getList($by, $order, array('ID' => $user_id, 'GROUPS_ID' => 1, 'ACTIVE' => 'Y'), array('FIELDS' => array('ID', 'EMAIL')))->fetch();
     if (empty($arAdmin)) {
         return '';
     }
     if ($cnt == 0) {
         return 'CIntranetUtils::notifyMailDomain("' . $type . '", "' . $sid . '", ' . $user_id . ', ' . ++$cnt . ');';
     }
     includeModuleLangFile(__FILE__);
     if (isModuleInstalled('bitrix24')) {
         $learnmoreLink = getMessage('INTR_MAIL_DOMAIN_LEARNMOREB24_LINK');
         $supportLink = getMessage('INTR_MAIL_DOMAIN_SUPPORTB24_LINK');
     } else {
         $learnmoreLink = getMessage('INTR_MAIL_DOMAIN_LEARNMORE_LINK');
         $supportLink = getMessage('INTR_MAIL_DOMAIN_SUPPORT_LINK');
     }
     if (in_array($type, array('nocomplete', 'nomailbox'))) {
         $sid = intval($sid);
         $service = \Bitrix\Mail\MailServicesTable::getList(array('filter' => array('=ID' => $sid)))->fetch();
         if (empty($service) || $service['ACTIVE'] != 'Y' || !in_array($service['SERVICE_TYPE'], array('domain', 'crdomain'))) {
             return '';
         }
         if ($service['SERVICE_TYPE'] == 'domain') {
             $result = CMailDomain2::getDomainStatus($service['TOKEN'], $service['SERVER'], $error);
             $stage = empty($result['stage']) ? null : $result['stage'];
         } else {
             $crResponse = CControllerClient::executeEvent('OnMailControllerCheckMemberDomain', array('DOMAIN' => $service['SERVER']));
             $stage = empty($crResponse['result']['stage']) ? null : $crResponse['result']['stage'];
         }
         if ($type == 'nocomplete') {
             if (in_array($stage, array('owner-check', 'mx-check'))) {
                 CEvent::send('INTRANET_MAILDOMAIN_NOCOMPLETE', array($service['SITE_ID']), array('EMAIL_TO' => $arAdmin['EMAIL'], 'LEARNMORE_LINK' => $learnmoreLink, 'SUPPORT_LINK' => $supportLink));
                 if ($cnt == 1) {
                     global $pPERIOD;
                     $pPERIOD = 3600 * 24 * 4;
                     return 'CIntranetUtils::notifyMailDomain("nocomplete", ' . $sid . ', ' . $user_id . ', ' . ++$cnt . ');';
                 }
             }
         } else {
             if ($stage == 'added') {
                 $dbMailboxes = CMailbox::getList(array(), array('ACTIVE' => 'Y', '!USER_ID' => 0, 'SERVICE_ID' => $sid));
                 $adminMailbox = false;
                 $userMailboxes = false;
                 while ($arMailbox = $dbMailboxes->fetch()) {
                     if ($arMailbox['USER_ID'] == $user_id) {
                         $adminMailbox = true;
                     } else {
                         $userMailboxes = true;
                         break;
                     }
                 }
                 if (!$userMailboxes) {
                     $eventType = $adminMailbox ? 'INTRANET_MAILDOMAIN_NOMAILBOX2' : 'INTRANET_MAILDOMAIN_NOMAILBOX';
                     CEvent::send($eventType, array($service['SITE_ID']), array('EMAIL_TO' => $arAdmin['EMAIL'], 'LEARNMORE_LINK' => $learnmoreLink, 'SUPPORT_LINK' => $supportLink));
                     if ($cnt == 1) {
                         global $pPERIOD;
                         $pPERIOD = 3600 * 24 * 21;
                         return 'CIntranetUtils::notifyMailDomain("nomailbox", ' . $sid . ', ' . $user_id . ', ' . ++$cnt . ');';
                     }
                 }
             }
         }
     } else {
         if ($type == 'noreg') {
             $dbServices = \Bitrix\Mail\MailServicesTable::getList(array('filter' => array('ACTIVE' => 'Y', 'SERVICE_TYPE' => 'crdomain')));
             while ($service = $dbServices->fetch()) {
                 if ($service['FLAGS'] & CMail::F_DOMAIN_REG) {
                     return '';
                 }
             }
             $r = CEvent::send('INTRANET_MAILDOMAIN_NOREG', array($sid), array('EMAIL_TO' => $arAdmin['EMAIL'], 'LEARNMORE_LINK' => $learnmoreLink, 'SUPPORT_LINK' => $supportLink));
         }
     }
     return '';
 }
示例#4
0
                $unseen = -1;
                $error = empty($crCheckMailbox['error']) ? GetMessage('INTR_MAIL_CONTROLLER_INVALID') : CMail::getErrorMessage($crCheckMailbox['error']);
            }
            break;
        case 'crdomain':
            list($acc['login'], $acc['domain']) = explode('@', $acc['LOGIN'], 2);
            $crCheckMailbox = CControllerClient::ExecuteEvent('OnMailControllerCheckMemberMailbox', array('DOMAIN' => $acc['domain'], 'NAME' => $acc['login']));
            if (isset($crCheckMailbox['result'])) {
                $unseen = intval($crCheckMailbox['result']);
            } else {
                $unseen = -1;
                $error = empty($crCheckMailbox['error']) ? GetMessage('INTR_MAIL_CONTROLLER_INVALID') : CMail::getErrorMessage($crCheckMailbox['error']);
            }
            break;
        case 'domain':
            $service = \Bitrix\Mail\MailServicesTable::getRowById($acc['SERVICE_ID']);
            list($acc['login'], $acc['domain']) = explode('@', $acc['LOGIN'], 2);
            $result = CMailDomain2::getUnreadMessagesCount($service['TOKEN'], $acc['domain'], $acc['login'], $error);
            if (is_null($result)) {
                $unseen = -1;
                $error = CMail::getErrorMessage($error);
            } else {
                $unseen = intval($result);
            }
            break;
    }
    CUserCounter::Set($userId, 'mail_unseen', $unseen, $siteId);
    CUserOptions::SetOption('global', 'last_mail_check_' . $siteId, time(), false, $userId);
    CUserOptions::SetOption('global', 'last_mail_check_success_' . $siteId, $unseen >= 0, false, $userId);
} else {
    $unseen = 0;
示例#5
0
} else {
    $SITE_ID = CSite::GetDefSite();
    $rsSite = CSite::GetList($by = "sort", $order = "asc", array("ID" => $SITE_ID));
    $arSite = $rsSite->GetNext();
    $SITE_DIR = $arSite["DIR"];
    $ID_INVITED = $ID_ADDED = 0;
    $arMailServices = array();
    $bDomainUsersExist = false;
    $bCreateDomainsExist = false;
    $bConnectDomainsExist = false;
    $bMailInstalled = false;
    if (CModule::IncludeModule("mail")) {
        $bMailInstalled = true;
        $dbService = \Bitrix\Mail\MailServicesTable::getList(array('filter' => array('ACTIVE' => 'Y', '=SITE_ID' => $SITE_ID), 'order' => array('SORT' => 'ASC', 'NAME' => 'ASC')));
        while ($arService = $dbService->fetch()) {
            $arMailServices[$arService['ID']] = array('id' => $arService['ID'], 'type' => $arService['SERVICE_TYPE'], 'name' => $arService['NAME'], 'link' => $arService['LINK'], 'icon' => \Bitrix\Mail\MailServicesTable::getIconSrc($arService['NAME'], $arService['ICON']), 'server' => $arService['SERVER'], 'port' => $arService['PORT'], 'encryption' => $arService['ENCRYPTION'], 'token' => $arService['TOKEN']);
            if ($arService['SERVICE_TYPE'] == 'controller') {
                $crDomains = CControllerClient::ExecuteEvent('OnMailControllerGetDomains', array());
                if (!empty($crDomains['result']) && is_array($crDomains['result'])) {
                    $arMailServices[$arService['ID']]['domains'] = $crDomains['result'];
                    $bCreateDomainsExist = true;
                }
                $arMailServices[$arService['ID']]['users'] = array();
                $crUsers = CControllerClient::ExecuteEvent('OnMailControllerGetUsers', array());
                if (!empty($crUsers['result']) && is_array($crUsers['result'])) {
                    foreach ($crUsers['result'] as $email) {
                        list($login, $domain) = explode('@', $email, 2);
                        if (empty($arMailServices[$arService['ID']]['users'][$domain])) {
                            $arMailServices[$arService['ID']]['users'][$domain] = array();
                        }
                        $arMailServices[$arService['ID']]['users'][$domain][] = $login;
示例#6
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');
 }
示例#7
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 : '');
 }