Esempio n. 1
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 '';
 }
Esempio n. 2
0
            }
            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;
    CUserOptions::SetOption('global', 'last_mail_check_' . $siteId, -1, false, $userId);
}
Esempio n. 3
0
         if (is_array($arMailServices[$arService['ID']]['users'])) {
             foreach ($arMailServices[$arService['ID']]['users'] as $domain => $arLogin) {
                 if (empty($arLogin)) {
                     unset($arMailServices[$arService['ID']]['users'][$domain]);
                 }
             }
         }
         if (!$bDomainUsersExist && !empty($arMailServices[$arService['ID']]['users'])) {
             $bDomainUsersExist = true;
         }
         if (!empty($arService['SERVER'])) {
             $bConnectDomainsExist = true;
         }
     }
 } elseif ($arService['SERVICE_TYPE'] == 'domain') {
     $arMailServices[$arService['ID']]['users'] = CMailDomain2::getDomainUsers($arService['TOKEN'], $arService['SERVER'], $error);
     $rsMailbox = CMailbox::getList(array('TIMESTAMP_X' => 'ASC'), array('ACTIVE' => 'Y', '!USER_ID' => 0, 'SERVER_TYPE' => 'domain', 'SERVICE_ID' => $arService['ID']));
     while ($arMailbox = $rsMailbox->fetch()) {
         list($login, $domain) = explode('@', $arMailbox['LOGIN'], 2);
         if (($key = array_search($login, $arMailServices[$arService['ID']]['users'])) !== false) {
             array_splice($arMailServices[$arService['ID']]['users'], $key, 1);
         }
     }
     if (!$bDomainUsersExist && !empty($arMailServices[$arService['ID']]['users'])) {
         $bDomainUsersExist = true;
     }
     if (!empty($arService['SERVER'])) {
         $bCreateDomainsExist = true;
         $bConnectDomainsExist = true;
     }
 }
Esempio n. 4
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');
 }
Esempio n. 5
0
 private static function executeManageDeleteMailbox(&$error)
 {
     $error = false;
     $userId = $_REQUEST['USER_ID'];
     if (!check_bitrix_sessid()) {
         $error = GetMessage('INTR_MAIL_CSRF');
     }
     if ($error === false) {
         $mailbox = CIntranetMailSetupHelper::getUserMailbox($userId);
         if (empty($mailbox) || !in_array($mailbox['SERVER_TYPE'], array('controller', 'domain', 'crdomain'))) {
             $error = GetMessage('INTR_MAIL_AJAX_ERROR');
         }
     }
     if ($error === false) {
         CMailbox::delete($mailbox['ID']);
         list($login, $domain) = explode('@', $mailbox['LOGIN'], 2);
         if ($mailbox['SERVER_TYPE'] == 'domain') {
             $domainService = CIntranetMailSetupHelper::getDomainService($mailbox['SERVICE_ID']);
             CMailDomain2::deleteUser($domainService['token'], $domain, $login);
         } else {
             if ($mailbox['SERVER_TYPE'] == 'crdomain') {
                 $crResponse = CControllerClient::ExecuteEvent('OnMailControllerDeleteMemberUser', array('DOMAIN' => $domain, 'NAME' => $login));
                 if (!isset($crResponse['result'])) {
                     $error = empty($crResponse['error']) ? GetMessage('INTR_MAIL_CONTROLLER_INVALID') : CMail::getErrorMessage($crResponse['error']);
                 }
             } else {
                 if ($mailbox['SERVER_TYPE'] == 'controller') {
                     $crResponse = CControllerClient::ExecuteEvent('OnMailControllerDeleteUser', array('DOMAIN' => $domain, 'NAME' => $login));
                     if (!isset($crResponse['result'])) {
                         $error = empty($crResponse['error']) ? GetMessage('INTR_MAIL_CONTROLLER_INVALID') : CMail::getErrorMessage($crResponse['error']);
                     }
                 }
             }
         }
         CUserCounter::Clear($userId, 'mail_unseen', $mailbox['LID']);
         CUserOptions::DeleteOption('global', 'last_mail_check_' . $mailbox['LID']);
         CUserOptions::DeleteOption('global', 'last_mail_check_success_' . $mailbox['LID']);
     }
     if ($error === false) {
         $create = '<a href="#" onclick="mb.create(' . intval($userId) . '); return false; ">' . GetMessage('INTR_MAIL_MANAGE_CREATE') . '</a>';
     }
     return array('result' => $error === false ? 'ok' : 'error', 'create' => isset($create) ? CharsetConverter::ConvertCharset($create, SITE_CHARSET, 'UTF-8') : '', 'error' => CharsetConverter::ConvertCharset($error, SITE_CHARSET, 'UTF-8'));
 }
Esempio n. 6
0
 public static function createMailbox($exists, $userId, $serviceId, $domain, $login, $password, &$error)
 {
     $error = false;
     if (intval($userId)) {
         $dbUser = CUser::getList($by = 'ID', $order = 'ASC', array('ID_EQUAL_EXACT' => intval($userId)), array('FIELDS' => 'ID'));
         if (!$dbUser->fetch()) {
             $error = GetMessage('INTR_MAIL_FORM_ERROR');
         }
     }
     if ($error === false) {
         $services = self::getMailServices();
         if (empty($services[$serviceId]) || !in_array($services[$serviceId]['type'], array('controller', 'domain', 'crdomain'))) {
             $error = GetMessage('INTR_MAIL_FORM_ERROR');
         }
     }
     if ($error === false) {
         $service = $services[$serviceId];
         if ($service['type'] == 'controller') {
             $crDomains = CControllerClient::ExecuteEvent('OnMailControllerGetDomains', array());
             $arDomains = empty($crDomains['result']) ? array() : $crDomains['result'];
             if (!is_array($arDomains) || !in_array($domain, $arDomains)) {
                 $error = CMail::getErrorMessage(CMail::ERR_API_OP_DENIED);
             }
         } else {
             if ($service['type'] == 'crdomain') {
                 $crDomains = CControllerClient::ExecuteEvent('OnMailControllerGetMemberDomains', array());
                 $arDomains = empty($crDomains['result']) ? array() : $crDomains['result'];
                 if (!is_array($arDomains) || !in_array($domain, $arDomains)) {
                     $error = CMail::getErrorMessage(CMail::ERR_API_OP_DENIED);
                 }
             } else {
                 if ($service['type'] == 'domain') {
                     if ($service['server'] != $domain) {
                         $error = GetMessage('INTR_MAIL_FORM_ERROR');
                     }
                 }
             }
         }
     }
     if ($error === false && !$exists) {
         if (!preg_match('/^[a-z0-9_]+(\\.?[a-z0-9_-]*[a-z0-9_]+)*?$/i', $login)) {
             $error = CMail::getErrorMessage(CMail::ERR_API_BAD_NAME);
         }
         if ($error === false) {
             if ($service['type'] == 'controller') {
                 $crResponse = CControllerClient::ExecuteEvent('OnMailControllerAddUser', array('DOMAIN' => $domain, 'NAME' => $login, 'PASSWORD' => $password));
                 if (!isset($crResponse['result'])) {
                     $error = empty($crResponse['error']) ? GetMessage('INTR_MAIL_CONTROLLER_INVALID') : CMail::getErrorMessage($crResponse['error']);
                 }
             } else {
                 if ($service['type'] == 'crdomain') {
                     $crResponse = CControllerClient::ExecuteEvent('OnMailControllerAddMemberUser', array('DOMAIN' => $domain, 'NAME' => $login, 'PASSWORD' => $password));
                     if (!isset($crResponse['result'])) {
                         $error = empty($crResponse['error']) ? GetMessage('INTR_MAIL_CONTROLLER_INVALID') : CMail::getErrorMessage($crResponse['error']);
                     }
                 } else {
                     if ($service['type'] == 'domain') {
                         $result = CMailDomain2::addUser($service['token'], $domain, $login, $password, $error);
                         if (is_null($result)) {
                             $error = CMail::getErrorMessage($error);
                         }
                     }
                 }
             }
         }
     }
     if ($error === false && intval($userId)) {
         if ($exists) {
             if ($service['type'] == 'controller') {
                 $crCheckMailbox = CControllerClient::ExecuteEvent('OnMailControllerCheckMailbox', array('DOMAIN' => $domain, 'NAME' => $login));
                 if (!isset($crCheckMailbox['result'])) {
                     $error = empty($crCheckMailbox['error']) ? GetMessage('INTR_MAIL_CONTROLLER_INVALID') : CMail::getErrorMessage($crCheckMailbox['error']);
                 }
             }
             if ($error === false) {
                 $dbMailbox = CMailbox::getList(array('TIMESTAMP_X' => 'ASC'), array('ACTIVE' => 'Y', '!USER_ID' => intval($userId), '=LOGIN' => $login . '@' . $domain));
                 if (($mailbox = $dbMailbox->fetch()) && $mailbox['USER_ID']) {
                     $error = GetMessage('INTR_MAIL_MAILBOX_OCCUPIED');
                 }
             }
         }
         if ($error === false) {
             $mailbox = self::getUserMailbox($userId);
             if (!empty($mailbox)) {
                 $res = CMailbox::delete($mailbox['ID']);
             }
             $arFields = array('LID' => SITE_ID, 'ACTIVE' => 'Y', 'SERVICE_ID' => $serviceId, 'NAME' => $service['name'], 'LOGIN' => $login . '@' . $domain, 'SERVER_TYPE' => $service['type'], 'USER_ID' => intval($userId));
             $res = CMailbox::add($arFields);
             if (!$res) {
                 $error = GetMessage('INTR_MAIL_SAVE_ERROR');
             }
         }
     }
     if ($error === false) {
         return $login . '@' . $domain;
     }
 }