public static function FilterCreateEx($fname, $vals, $type, &$bFullJoin, $cOperationType = false, $bSkipEmpty = true) { global $DB; if (!is_array($vals)) { $vals = array($vals); } if (count($vals) < 1) { return ""; } if (is_bool($cOperationType)) { if ($cOperationType === true) { $cOperationType = "N"; } else { $cOperationType = "E"; } } if ($cOperationType == "G") { $strOperation = ">"; } elseif ($cOperationType == "GE") { $strOperation = ">="; } elseif ($cOperationType == "LE") { $strOperation = "<="; } elseif ($cOperationType == "L") { $strOperation = "<"; } else { $strOperation = "="; } $bFullJoin = false; $bWasLeftJoin = false; $res = array(); for ($i = 0; $i < count($vals); $i++) { $val = $vals[$i]; if (!$bSkipEmpty || strlen($val) > 0 || is_bool($val) && $val === false) { switch ($type) { case "string_equal": if ($cOperationType == "?") { if (strlen($val) > 0) { $res[] = GetFilterQuery($fname, $val, "N"); } } else { if (strlen($val) <= 0) { $res[] = ($cOperationType == "N" ? "NOT" : "") . "(" . $fname . " IS NULL OR " . $DB->Length($fname) . "<=0)"; } else { $res[] = ($cOperationType == "N" ? " " . $fname . " IS NULL OR NOT " : "") . "(" . CLdapUtil::_Upper($fname) . $strOperation . CLdapUtil::_Upper("'" . $DB->ForSql($val) . "'") . ")"; } } break; case "string": if ($cOperationType == "?") { if (strlen($val) > 0) { $sr = GetFilterQuery($fname, $val, "Y", array(), "N"); if ($sr != "0") { $res[] = $sr; } } } else { if (strlen($val) <= 0) { $res[] = ($cOperationType == "N" ? "NOT" : "") . "(" . $fname . " IS NULL OR " . $DB->Length($fname) . "<=0)"; } else { if ($strOperation == "=") { $res[] = ($cOperationType == "N" ? " " . $fname . " IS NULL OR NOT " : "") . "(" . ($DB->type == "ORACLE" ? CLdapUtil::_Upper($fname) . " LIKE " . CLdapUtil::_Upper("'" . $DB->ForSqlLike($val) . "'") . " ESCAPE '\\'" : $fname . " " . ($strOperation == "=" ? "LIKE" : $strOperation) . " '" . $DB->ForSqlLike($val) . "'") . ")"; } else { $res[] = ($cOperationType == "N" ? " " . $fname . " IS NULL OR NOT " : "") . "(" . ($DB->type == "ORACLE" ? CLdapUtil::_Upper($fname) . " " . $strOperation . " " . CLdapUtil::_Upper("'" . $DB->ForSql($val) . "'") . " " : $fname . " " . $strOperation . " '" . $DB->ForSql($val) . "'") . ")"; } } } break; case "date": if (strlen($val) <= 0) { $res[] = ($cOperationType == "N" ? "NOT" : "") . "(" . $fname . " IS NULL)"; } else { $res[] = ($cOperationType == "N" ? " " . $fname . " IS NULL OR NOT " : "") . "(" . $fname . " " . $strOperation . " " . $DB->CharToDateFunction($DB->ForSql($val), "FULL") . ")"; } break; case "number": if ($cOperationType == "?") { $res[] = GetFilterQuery($fname, $val); } else { if (strlen($val) <= 0) { $res[] = ($cOperationType == "N" ? "NOT" : "") . "(" . $fname . " IS NULL)"; } else { $res[] = ($cOperationType == "N" ? " " . $fname . " IS NULL OR NOT " : "") . "(" . $fname . " " . $strOperation . " '" . DoubleVal($val) . "')"; } } break; case "number_above": if (strlen($val) <= 0) { $res[] = ($cOperationType == "N" ? "NOT" : "") . "(" . $fname . " IS NULL)"; } else { $res[] = ($cOperationType == "N" ? " " . $fname . " IS NULL OR NOT " : "") . "(" . $fname . " " . $strOperation . " '" . $DB->ForSql($val) . "')"; } break; } // we need this conditions to do INNER JOIN if (strlen($val) > 0 && $cOperationType != "N") { $bFullJoin = true; } else { $bWasLeftJoin = true; } } } $strResult = ""; for ($i = 0; $i < count($res); $i++) { if ($i > 0) { $strResult .= $cOperationType == "N" ? " AND " : " OR "; } $strResult .= "(" . $res[$i] . ")"; } if ($strResult != "") { $strResult = "(" . $strResult . ")"; } if ($bFullJoin && $bWasLeftJoin && $cOperationType != "N") { $bFullJoin = false; } return $strResult; }
function GetStsSyncURL($arSectionParams, $type = 'calendar', $employees = false) { global $USER, $APPLICATION; if (!is_array($arSectionParams)) { $arSectionParams = array('ID' => intval($arSectionParams)); } //if (!$arSectionParams['ID']) // return false; $arAllowedTypes = array('calendar', 'tasks', 'contacts'); if (!in_array($type, $arAllowedTypes)) { $type = 'calendar'; } if ($type == 'calendar') { $calendar2 = COption::GetOptionString("intranet", "calendar_2", "N") == "Y" && CModule::IncludeModule("calendar"); $fld_EXTERNAL_ID = 'XML_ID'; if ($calendar2) { // $arSectionParams = array( // 'ID' => int // 'XML_ID' => string // 'NAME' => string // 'PREFIX' => string // 'LINK_URL' => string // 'TYPE' => string // ) if (strlen($arSectionParams['XML_ID']) !== 32) { $arSectionParams[$fld_EXTERNAL_ID] = md5($arSectionParams['TYPE'] . '_' . $arSectionParams['ID'] . '_' . RandString(8)); // Set XML_ID CCalendar::SaveSection(array('arFields' => array('ID' => $arSectionParams['ID'], 'XML_ID' => $arSectionParams[$fld_EXTERNAL_ID]), 'bAffectToDav' => false, 'bCheckPermissions' => false)); } } else { if (!$arSectionParams['IBLOCK_ID'] || !$arSectionParams['NAME'] || !$arSectionParams[$fld_EXTERNAL_ID]) { $dbRes = CIBlockSection::GetByID($arSectionParams['ID']); $arSection = $dbRes->Fetch(); if ($arSection) { $arSectionParams['IBLOCK_ID'] = $arSection['IBLOCK_ID']; $arSectionParams['NAME'] = $arSection['NAME']; $arSectionParams[$fld_EXTERNAL_ID] = $arSection[$fld_EXTERNAL_ID]; } else { return false; } } if (strlen($arSectionParams[$fld_EXTERNAL_ID]) !== 32) { $arSectionParams[$fld_EXTERNAL_ID] = md5($arSectionParams['IBLOCK_ID'] . '_' . $arSectionParams['ID'] . '_' . RandString(8)); $obSect = new CIBlockSection(); if (!$obSect->Update($arSectionParams['ID'], array($fld_EXTERNAL_ID => $arSectionParams[$fld_EXTERNAL_ID]), false, false)) { return false; } } } if (!$arSectionParams['PREFIX']) { $rsSites = CSite::GetByID(SITE_ID); $arSite = $rsSites->Fetch(); if (strlen($arSite["NAME"]) > 0) { $arSectionParams['PREFIX'] = $arSite["NAME"]; } else { $arSectionParams['PREFIX'] = COption::GetOptionString('main', 'site_name', GetMessage('INTR_OUTLOOK_PREFIX_CONTACTS')); } } $GUID = CIntranetUtils::makeGUID($arSectionParams[$fld_EXTERNAL_ID]); } elseif ($type == 'contacts') { if (!$arSectionParams['LINK_URL']) { if (CModule::IncludeModule('extranet') && CExtranet::IsExtranetSite()) { $arSectionParams['LINK_URL'] = SITE_DIR . 'contacts/'; } else { $arSectionParams['LINK_URL'] = SITE_DIR . 'company/'; } } if (!$arSectionParams['NAME']) { if (CModule::IncludeModule('extranet') && CExtranet::IsExtranetSite() && !$employees) { $arSectionParams['NAME'] = GetMessage('INTR_OUTLOOK_TITLE_CONTACTS_EXTRANET'); } else { $arSectionParams['NAME'] = GetMessage('INTR_OUTLOOK_TITLE_CONTACTS'); } } if (!$arSectionParams['PREFIX']) { $rsSites = CSite::GetByID(SITE_ID); $arSite = $rsSites->Fetch(); if (strlen($arSite["NAME"]) > 0) { $arSectionParams['PREFIX'] = $arSite["NAME"]; } else { $arSectionParams['PREFIX'] = COption::GetOptionString('main', 'site_name', GetMessage('INTR_OUTLOOK_PREFIX_CONTACTS')); } } $SERVER_NAME = $_SERVER['SERVER_NAME']; $GUID_DATA = $SERVER_NAME . '|' . $type; if (CModule::IncludeModule('extranet') && CExtranet::IsExtranetSite()) { $GUID_DATA .= "|extranet"; if ($employees) { $GUID_DATA .= "|employees"; } } $GUID = CIntranetUtils::makeGUID(md5($GUID_DATA)); } elseif ($type == 'tasks') { if (!$arSectionParams['LINK_URL']) { if (CModule::IncludeModule('extranet') && CExtranet::IsExtranetSite()) { $arSectionParams['LINK_URL'] = SITE_DIR . 'contacts/personal/user/' . $USER->GetID() . '/tasks/'; } else { $arSectionParams['LINK_URL'] = SITE_DIR . 'company/personal/user/' . $USER->GetID() . '/tasks/'; } } if (!$arSectionParams['NAME']) { $arSectionParams['NAME'] = GetMessage('INTR_OUTLOOK_TITLE_TASKS'); } if (!$arSectionParams['PREFIX']) { $rsSites = CSite::GetByID(SITE_ID); $arSite = $rsSites->Fetch(); if (strlen($arSite["NAME"]) > 0) { $arSectionParams['PREFIX'] = $arSite["NAME"]; } else { $arSectionParams['PREFIX'] = COption::GetOptionString('main', 'site_name', GetMessage('INTR_OUTLOOK_PREFIX_CONTACTS')); } } $SERVER_NAME = $_SERVER['SERVER_NAME']; $GUID_DATA = $SERVER_NAME . '|' . $type; if (CModule::IncludeModule('extranet') && CExtranet::IsExtranetSite()) { $GUID_DATA .= "|extranet"; } $GUID = CIntranetUtils::makeGUID(md5($GUID_DATA)); } if (substr($arSectionParams['LINK_URL'], -9) == 'index.php') { $arSectionParams['LINK_URL'] = substr($arSectionParams['LINK_URL'], 0, -9); } if (substr($arSectionParams['LINK_URL'], -4) != '.php' && substr($arSectionParams['LINK_URL'], -1) != '/') { $arSectionParams['LINK_URL'] .= '/'; } // another dirty hack to avoid some M$ stssync protocol restrictions if (substr($arSectionParams['LINK_URL'], -1) != '/') { $arSectionParams['LINK_URL'] .= '/'; } $GLOBALS['APPLICATION']->AddHeadScript('/bitrix/js/intranet/outlook.js'); $type_script = $type; if (CModule::IncludeModule('extranet') && CExtranet::IsExtranetSite()) { $type_script .= "_extranet"; if ($employees) { $type_script .= "_emp"; } } $port = $APPLICATION->IsHTTPS() ? 443 : 80; if (\Bitrix\Main\Loader::includeModule('ldap')) { $port = CLdapUtil::getTargetPort(); } return 'jsOutlookUtils.Sync(\'' . $type . '\', \'/bitrix/tools/ws_' . $type_script . '\', \'' . $arSectionParams['LINK_URL'] . '\', \'' . CUtil::JSEscape(htmlspecialcharsbx($arSectionParams['PREFIX'])) . '\', \'' . CUtil::JSEscape($arSectionParams['NAME']) . '\', \'' . $GUID . '\', ' . intval($port) . ')'; }
public static function Fetch() { if ($res = parent::Fetch()) { $res["ADMIN_PASSWORD"] = CLdapUtil::Decrypt($res["ADMIN_PASSWORD"]); $res["FIELD_MAP"] = unserialize($res["FIELD_MAP"]); if (!is_array($res["FIELD_MAP"])) { $res["FIELD_MAP"] = array(); } } return $res; }
<td> <?php echo GetMessage("LDAP_EDIT_IMPORT_STRUCT"); ?> : </td> <td> <input onClick="__importStateSwitch(!this.checked);" type="checkbox" id="IMPORT_STRUCT" name="IMPORT_STRUCT" value="Y"<?php if ($importEnabled) { echo " checked"; } ?> ></input> </td> </tr> <?php $l = CLdapUtil::getDepartmentListFromSystem(); if ($l !== false) { ?> <tr> <td> <?php echo GetMessage("LDAP_EDIT_STRUCT_ROOT"); ?> : </td> <td> <select name="ROOT_DEPARTMENT" id="ROOT_DEPARTMENT" <?php if (!$importEnabled) { echo 'disabled="1" '; } ?> style="width: 270px">
if ($_SERVER["REQUEST_METHOD"] == "HEAD") { $res = strtolower($_SERVER["HTTP_USER_AGENT"]); if (strpos($res, "microsoft") === false && strlen($_SERVER["REAL_FILE_PATH"]) <= 0 && substr($_SERVER['REQUEST_URI'], -1, 1) == '/') { $bNeedInclude = false; $res = CUrlRewriter::GetList(array("QUERY" => $_SERVER['REQUEST_URI'])); foreach ($res as $res_detail) { if (strpos($res_detail["ID"], "webdav") !== false || strpos($res_detail["ID"], "disk") !== false || strpos($res_detail["ID"], "socialnetwork") !== false) { $bNeedInclude = true; break; } } } } if (__webdavIsDavHeaders() && $bNeedInclude) { if (CModule::includeModule('ldap') && CLdapUtil::isBitrixVMAuthSupported()) { CLdapUtil::bitrixVMAuthorize(); } if (!$_SERVER['PHP_AUTH_USER'] || !$_SERVER['PHP_AUTH_USER']) { $res = !empty($_SERVER['REDIRECT_REMOTE_USER']) ? $_SERVER['REDIRECT_REMOTE_USER'] : $_SERVER['REMOTE_USER']; if (!empty($res) && preg_match('/(?<=(basic\\s))(.*)$/is', $res, $matches)) { $res = trim($matches[0]); list($_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"]) = explode(':', base64_decode($res)); } } if (!is_array($GLOBALS["APPLICATION"]->arComponentMatch)) { $GLOBALS["APPLICATION"]->arComponentMatch = array(); } $GLOBALS["APPLICATION"]->arComponentMatch[] = 'dav'; $GLOBALS["APPLICATION"]->arComponentMatch[] = 'disk'; $GLOBALS["APPLICATION"]->arComponentMatch[] = 'socialnetwork'; define("STOP_STATISTICS", true);
function SetUser($arLdapUser, $bAddNew = true) { global $USER; $isHead = false; $bUSERGen = false; if (!is_object($USER)) { $USER = new CUser(); $bUSERGen = true; } // process previously saved department data if (IsModuleInstalled('intranet') && is_array($arLdapUser['UF_DEPARTMENT'])) { $isHead = $arLdapUser['UF_DEPARTMENT']['IS_HEAD']; // replace temporary value with a real one $arLdapUser['UF_DEPARTMENT'] = array($arLdapUser['UF_DEPARTMENT']['ID']); } if (isset($arLdapUser["ID"])) { $ID = intval($arLdapUser["ID"]); self::PrepareUserPhoto($ID, $arLdapUser); $USER->Update($ID, $arLdapUser); } else { $ldapUserID = 0; if (isset($_REQUEST["ldap_user_id"]) && strlen($_REQUEST["ldap_user_id"]) == 32) { $dbUser = CUser::GetList($O = "", $B = "", array("XML_ID" => $_REQUEST["ldap_user_id"], 'EXTERNAL_AUTH_ID' => $arLdapUser['EXTERNAL_AUTH_ID'])); if ($arUser = $dbUser->Fetch()) { if ($arUser["XML_ID"]) { $ldapUserID = $arUser["ID"]; } } } $res = CUser::GetList($O = "", $B = "", array('LOGIN_EQUAL_EXACT' => $arLdapUser['LOGIN'], 'EXTERNAL_AUTH_ID' => $arLdapUser['EXTERNAL_AUTH_ID'])); $arLdapUser['PASSWORD'] = uniqid(rand(), true); if (!($ar_res = $res->Fetch()) && $ldapUserID < 1) { if ($bAddNew) { if (strlen($arLdapUser["EMAIL"]) <= 0) { $arLdapUser["EMAIL"] = COption::GetOptionString("ldap", "default_email", 'no@email'); } $ID = $USER->Add($arLdapUser); } else { $ID = 0; } } else { $ID = $ldapUserID > 1 ? $ldapUserID : $ar_res['ID']; self::PrepareUserPhoto($ID, $arLdapUser); $USER->Update($ID, $arLdapUser); } $ID = intval($ID); } // - add this user to groups if ($ID > 0) { // - set as head of department if (IsModuleInstalled('intranet') && $isHead) { CLdapUtil::SetDepartmentHead($ID, $arLdapUser['UF_DEPARTMENT'][0]); } // For each group finding all superior ones $arUserLdapGroups = array(); $arLdapGroups = $this->GetGroupListArray(); $this->GetAllMemberOf($arLdapUser['LDAP_GROUPS'], $arUserLdapGroups, $arLdapGroups); $arGroupMaps = $this->GetGroupMaps(); $arUserBitrixGroups = $USER->GetUserGroup($ID); $arUserBitrixGroupsNew = array(); $prevGroups = $arUserBitrixGroups; sort($prevGroups); foreach ($arGroupMaps as $fromLdapGroup => $arToUserGroups) { foreach ($arToUserGroups as $toUserGroup) { if (($k = array_search($toUserGroup, $arUserBitrixGroups)) !== false) { unset($arUserBitrixGroups[$k]); } // If there is such a group among user's if (in_array($fromLdapGroup, $arUserLdapGroups)) { $arUserBitrixGroupsNew[] = $toUserGroup; } } } $arUserBitrixGroups = array_merge($arUserBitrixGroups, array_unique($arUserBitrixGroupsNew)); sort($arUserBitrixGroups); if ($arUserBitrixGroups != $prevGroups) { $USER->SetUserGroup($ID, $arUserBitrixGroups); } } if ($bUSERGen) { unset($USER); } return $ID; }
$val = "N"; } if ($option[3][0] == "multiselectbox") { $val = @implode(",", $val); } COption::SetOptionString($module_id, $name, $val, $option[1]); } if ($_POST['use_ntlm'] == 'Y') { RegisterModuleDependences('main', 'OnBeforeProlog', 'ldap', 'CLDAP', 'NTLMAuth', 40); } else { UnRegisterModuleDependences('main', 'OnBeforeProlog', 'ldap', 'CLDAP', 'NTLMAuth'); } if ($_POST['bitrixvm_auth_support'] == 'Y') { CLdapUtil::SetBitrixVMAuthSupport(); } else { CLdapUtil::UnSetBitrixVMAuthSupport(); } } } //if($MOD_RIGHT>="W"): $arAllOptions[] = array("bitrixvm_auth_hint", "", BeginNote() . GetMessage("LDAP_BITRIXVM_HINT") . EndNote(), array("statichtml", "")); $aTabs = array(array("DIV" => "edit1", "TAB" => GetMessage("MAIN_TAB_SET"), "ICON" => "ldap_settings", "TITLE" => GetMessage("MAIN_TAB_TITLE_SET")), array("DIV" => "edit2", "TAB" => GetMessage("MAIN_TAB_RIGHTS"), "ICON" => "ldap_settings", "TITLE" => GetMessage("MAIN_TAB_TITLE_RIGHTS"))); $tabControl = new CAdminTabControl("tabControl", $aTabs); $tabControl->Begin(); ?> <form method="POST" action="<?php echo $APPLICATION->GetCurPage(); ?> ?mid=<?php echo htmlspecialcharsbx($mid); ?>