Exemple #1
0
 public static function modifyDbconn($DBHost, $DBName, $DBLogin, $DBPassword)
 {
     if (strlen($DBHost) <= 0) {
         throw new \Bitrix\Main\ArgumentNullException("DBHost");
     }
     if (strlen($DBName) <= 0) {
         throw new \Bitrix\Main\ArgumentNullException("DBName");
     }
     if (strlen($DBLogin) <= 0) {
         throw new \Bitrix\Main\ArgumentNullException("DBLogin");
     }
     $filename = \Bitrix\Main\Application::getDocumentRoot() . "/bitrix/php_interface/dbconn.php";
     $file = new \Bitrix\Main\IO\File($filename);
     if (!$file->isExists()) {
         return false;
     }
     $content = file_get_contents($filename);
     if (strlen($content) <= 0) {
         return false;
     }
     file_put_contents(\Bitrix\Main\Application::getDocumentRoot() . "/bitrix/php_interface/dbconn.php.bak", $content);
     $content = preg_replace('/(\\$DBHost\\s*=\\s*(\\"|\')+)(.*)((\\"|\')+;)/', '${1}' . $DBHost . '${4}', $content);
     $content = preg_replace('/(\\$DBName\\s*=\\s*(\\"|\')+)(.*)((\\"|\')+;)/', '${1}' . $DBName . '${4}', $content);
     $content = preg_replace('/(\\$DBLogin\\s*=\\s*(\\"|\')+)(.*)((\\"|\')+;)/', '${1}' . $DBLogin . '${4}', $content);
     $content = preg_replace('/(\\$DBPassword\\s*=\\s*(\\"|\')+)(.*)((\\"|\')+;)/', '${1}' . $DBPassword . '${4}', $content);
     return file_put_contents($filename, $content);
 }
Exemple #2
0
 /**
  * Returns urlrewrite array
  *
  * @param string $site Site ID.
  * @return array
  */
 private static function getRewriteRules($site)
 {
     $docRoot = rtrim(\Bitrix\Main\SiteTable::getDocumentRoot($site), '/');
     $rewriteRules = array();
     $arUrlRewrite =& $rewriteRules;
     $rewriteFile = new \Bitrix\Main\IO\File($docRoot . '/urlrewrite.php');
     if ($rewriteFile->isExists()) {
         include $rewriteFile->getPath();
     }
     return $rewriteRules;
 }
Exemple #3
0
 /**
  * @return array All roles defenitions
  * @throws \Bitrix\Main\IO\FileNotFoundException
  */
 public static function getList()
 {
     static $def = null;
     if ($def == null) {
         $filename = \Bitrix\Main\Application::getDocumentRoot() . "/bitrix/modules/scale/include/rolesdefinitions.php";
         $file = new \Bitrix\Main\IO\File($filename);
         if ($file->isExists()) {
             require_once $filename;
         } else {
             throw new \Bitrix\Main\IO\FileNotFoundException($filename);
         }
         if (isset($rolesDefinitions)) {
             $def = $rolesDefinitions;
         } else {
             $def = array();
         }
     }
     return $def;
 }
Exemple #4
0
 /**
  * Returns actions list
  * @param bool $checkConditions - if we need to check conditions
  * @return array of all actions defenitions
  * @throws \Bitrix\Main\IO\FileNotFoundException
  */
 public static function getList($checkConditions = false)
 {
     static $def = null;
     if ($def == null) {
         $filename = \Bitrix\Main\Application::getDocumentRoot() . "/bitrix/modules/scale/include/actionsdefinitions.php";
         $file = new \Bitrix\Main\IO\File($filename);
         if ($file->isExists()) {
             require_once $filename;
         } else {
             throw new \Bitrix\Main\IO\FileNotFoundException($filename);
         }
         if (isset($actionsDefinitions)) {
             $def = $actionsDefinitions;
             if (is_array($def) && $checkConditions) {
                 foreach ($def as $actionId => $action) {
                     if (isset($action["CONDITION"]) && !self::isConditionSatisfied($action["CONDITION"])) {
                         unset($def[$actionId]);
                     }
                 }
             }
         } else {
             $def = array();
         }
     }
     return $def;
 }
Exemple #5
0
 /**
  * Parses the passed content to find css, js and images. Returns the array of files.
  *
  * @param $content
  *
  * @return array
  */
 public function getFilesFromContent($content)
 {
     $files = array();
     $arFilesByType = array();
     $arExtensions = array("js", "css");
     $extension_regex = "(?:" . implode("|", $arExtensions) . ")";
     $regex = "/\n\t\t\t\t((?i:\n\t\t\t\t\thref=\n\t\t\t\t\t|src=\n\t\t\t\t\t|BX\\.loadCSS\\(\n\t\t\t\t\t|BX\\.loadScript\\(\n\t\t\t\t\t|jsUtils\\.loadJSFile\\(\n\t\t\t\t\t|background\\s*:\\s*url\\(\n\t\t\t\t))                                                   #attribute\n\t\t\t\t(\"|')                                               #open_quote\n\t\t\t\t([^?'\"]+\\.)                                        #href body\n\t\t\t\t(" . $extension_regex . ")                           #extentions\n\t\t\t\t(|\\?\\d+|\\?v=\\d+)                                 #params\n\t\t\t\t(\\2)                                                #close_quote\n\t\t\t/x";
     $match = array();
     preg_match_all($regex, $content, $match);
     $link = $match[3];
     $extension = $match[4];
     $params = $match[5];
     $linkCount = count($link);
     $fileData = array("FULL_FILE_LIST" => array(), "FILE_TIMESTAMPS" => array(), "CSS_FILE_IMAGES" => array());
     for ($i = 0; $i < $linkCount; $i++) {
         $fileData["FULL_FILE_LIST"][] = $files[] = $link[$i] . $extension[$i] . $params[$i];
         $fileData["FILE_TIMESTAMPS"][$link[$i] . $extension[$i]] = $params[$i];
         $arFilesByType[$extension[$i]][] = $link[$i] . $extension[$i];
     }
     $manifestCache = $this->readManifestCache($this->getCurrentManifestID());
     if (array_key_exists("css", $arFilesByType)) {
         $cssCount = count($arFilesByType["css"]);
         for ($j = 0; $j < $cssCount; $j++) {
             $cssFilePath = $arFilesByType["css"][$j];
             if ($manifestCache["FILE_DATA"]["FILE_TIMESTAMPS"][$cssFilePath] != $fileData["FILE_TIMESTAMPS"][$cssFilePath]) {
                 $fileContent = false;
                 $fileUrl = parse_url($cssFilePath);
                 $file = new \Bitrix\Main\IO\File(Application::getDocumentRoot() . $fileUrl['path']);
                 if ($file->isExists() && $file->isReadable()) {
                     $fileContent = $file->getContents();
                 } elseif ($fileUrl["scheme"]) {
                     $req = new \CHTTP();
                     $req->http_timeout = 20;
                     $fileContent = $req->Get($cssFilePath);
                 }
                 if ($fileContent != false) {
                     $regex = '#([;\\s:]*(?:url|@import)\\s*\\(\\s*)(\'|"|)(.+?)(\\2)\\s*\\)#si';
                     $cssFileRelative = new \Bitrix\Main\IO\File($cssFilePath);
                     $cssPath = $cssFileRelative->getDirectoryName();
                     preg_match_all($regex, $fileContent, $match);
                     $matchCount = count($match[3]);
                     for ($k = 0; $k < $matchCount; $k++) {
                         $file = self::replaceUrlCSS($match[3][$k], addslashes($cssPath));
                         if (!in_array($file, $files) && !strpos($file, ";base64")) {
                             $fileData["FULL_FILE_LIST"][] = $files[] = $file;
                             $fileData["CSS_FILE_IMAGES"][$cssFilePath][] = $file;
                         }
                     }
                 }
             } else {
                 $fileData["CSS_FILE_IMAGES"][$cssFilePath] = $manifestCache["FILE_DATA"]["CSS_FILE_IMAGES"][$cssFilePath];
                 if (is_array($manifestCache["FILE_DATA"]["CSS_FILE_IMAGES"][$cssFilePath])) {
                     $fileData["FULL_FILE_LIST"] = array_merge($fileData["FULL_FILE_LIST"], $manifestCache["FILE_DATA"]["CSS_FILE_IMAGES"][$cssFilePath]);
                 }
             }
         }
     }
     return $fileData;
 }
Exemple #6
0
             $res = $engine->setSiteInfo($arDomain['DOMAIN'], $arDomain['SITE_DIR'], array($fieldName => $fieldValue));
             break;
     }
     break;
 case 'site_verify':
     $res = array('error' => 'Unknown domain');
     if (is_array($arDomain)) {
         $siteInfo = $engine->getSiteInfo($arDomain['DOMAIN'], $arDomain['SITE_DIR']);
         if ($siteInfo[$arDomain['DOMAIN']]['verified'] == 'false') {
             $filename = $siteInfo[$arDomain['DOMAIN']]['verification-method']['file-name'];
             // paranoia?
             $filename = preg_replace("/^(.*?)\\..*\$/", "\\1.html", $filename);
             if (strlen($filename) > 0) {
                 $path = Path::combine(strlen($arDomain['SITE_DOC_ROOT']) > 0 ? $arDomain['SITE_DOC_ROOT'] : $_SERVER['DOCUMENT_ROOT'], $arDomain['SITE_DIR'], $filename);
                 $obFile = new \Bitrix\Main\IO\File($path);
                 if ($obFile->isExists()) {
                     $obFile->delete();
                 }
                 $obFile->putContents($siteInfo[$arDomain['DOMAIN']]['verification-method']['file-content']);
                 $res = $engine->verifySite($arDomain['DOMAIN'], $arDomain['SITE_DIR']);
             }
             $res = $engine->getFeeds();
             $res['_domain'] = $arDomain['DOMAIN'];
         } elseif ($siteInfo[$arDomain['DOMAIN']]['verified'] == 'true') {
             $res = $siteInfo;
             $res['_domain'] = $arDomain['DOMAIN'];
         }
     } else {
         $res = array('error' => 'No domain');
     }
     break;
Exemple #7
0
     }
     if ($error === false) {
         $source = Bitrix\Main\Text\Encoding::convertEncodingToCurrent($source);
         $source = Bitrix\ABTest\AdminHelper::getRealPath($site, $source);
         if (empty($source)) {
             $error = getMessage('ABTEST_UNKNOWN_PAGE');
         }
         if ($error === false) {
             $docRoot = rtrim(\Bitrix\Main\SiteTable::getDocumentRoot($site), '/');
             $source = new Bitrix\Main\IO\File($docRoot . $source);
             $k = 0;
             do {
                 $targetPath = BX_ROOT . '/abtest/' . date('Ymd') . '/' . sprintf('%u', crc32(rand() . time())) . $source->getName();
                 $target = new Bitrix\Main\IO\File($docRoot . $targetPath);
             } while ($target->isExists() && $k++ < 10);
             if ($target->isExists()) {
                 $error = getMessage('ABTEST_AJAX_ERROR');
             } else {
                 $success = copyDirFiles($source->getPath(), $target->getPath(), false, false, false);
                 if ($success) {
                     $result = $targetPath;
                 } else {
                     $error = getMessage('ABTEST_AJAX_ERROR');
                 }
             }
         }
     }
     break;
 case 'check':
     $site = isset($_REQUEST['site']) ? $_REQUEST['site'] : null;
     $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
Exemple #8
0
                         $errors[] = str_replace(array('#ID#', '#VALUE#'), array(intval($k) + 1, htmlspecialcharsbx($TEST_DATA['old_value'][$k])), getMessage('ABTEST_UNKNOWN_TEST_TEMPLATE'));
                     }
                     if (!empty($TEST_DATA['new_value'][$k]) && !is_set($arTemplates, $TEST_DATA['new_value'][$k])) {
                         $errors[] = str_replace(array('#ID#', '#VALUE#'), array(intval($k) + 1, htmlspecialcharsbx($TEST_DATA['new_value'][$k])), getMessage('ABTEST_UNKNOWN_TEST_TEMPLATE'));
                     }
                     break;
                 case 'page':
                     if (!empty($TEST_DATA['old_value'][$k])) {
                         $file = new Bitrix\Main\IO\File($docRoot . $TEST_DATA['old_value'][$k]);
                         if (!$file->isExists()) {
                             $errors[] = str_replace(array('#ID#', '#VALUE#'), array(intval($k) + 1, htmlspecialcharsbx($TEST_DATA['old_value'][$k])), getMessage('ABTEST_UNKNOWN_TEST_PAGE'));
                         }
                     }
                     if (!empty($TEST_DATA['new_value'][$k])) {
                         $file = new Bitrix\Main\IO\File($docRoot . $TEST_DATA['new_value'][$k]);
                         if (!$file->isExists()) {
                             $errors[] = str_replace(array('#ID#', '#VALUE#'), array(intval($k) + 1, htmlspecialcharsbx($TEST_DATA['new_value'][$k])), getMessage('ABTEST_UNKNOWN_TEST_PAGE'));
                         }
                     }
                     break;
             }
         }
         $arFields['TEST_DATA']['list'][] = array('type' => $type, 'old_value' => $TEST_DATA['old_value'][$k], 'new_value' => $TEST_DATA['new_value'][$k]);
     }
 } else {
     $errors[] = getMessage('ABTEST_EMPTY_TEST_DATA');
 }
 if (!empty($errors)) {
     $message = new CAdminMessage(array('MESSAGE' => getMessage('ABTEST_TEST_DATA_ERROR'), 'DETAILS' => join('<br>', $errors)));
 }
 if (empty($message)) {
Exemple #9
0
 protected static function getItemValue($hostname, $categoryId, $item, $param)
 {
     if (isset($item["VALUE"])) {
         return $item["VALUE"];
     }
     if (isset($item["VALUE_FUNC"])) {
         return call_user_func_array($item["VALUE_FUNC"], isset($item["FUNC_PARAMS"]) ? $item["FUNC_PARAMS"] : array());
     }
     if ((!$item["RRD"] || !$item["CF"]) && !$item["OPTIONS"]) {
         throw new \Exception("Monitoring param item in category " . $categoryId . " has no RRD or CF fields.");
     }
     if (isset($item["RRD"])) {
         $rrdFile = str_replace('##HOSTNAME##', $hostname, $item["RRD"]);
         $rrdPath = static::$rrdPath . "/" . $hostname . "/" . $rrdFile;
         $file = new \Bitrix\Main\IO\File($rrdPath);
         if (!$file->isExists()) {
             throw new \Bitrix\Main\IO\FileNotFoundException($rrdPath);
         }
         $first = \rrd_first($rrdPath);
         $last = \rrd_last($rrdPath);
     }
     if (isset($item["OPTIONS"])) {
         $arOpts = $item["OPTIONS"];
         $arOpts = str_replace('##HOSTNAME##', $hostname, $arOpts);
     } else {
         if ($item["CF"] == "MIN") {
             $agr = "MINIMUM";
         } elseif ($item["CF"] == "MAX") {
             $agr = "MAXIMUM";
         } else {
             $agr = $item["CF"];
         }
         if ($item["CF"] == "LAST") {
             $item["CF"] = "AVERAGE";
         }
         $format = isset($item["FORMAT"]) ? $item["FORMAT"] : "%6.2lf";
         $arOpts = array("DEF:val=" . $rrdPath . ":42:" . $item["CF"], "VDEF:vval=val," . $agr, "PRINT:vval:" . $format);
     }
     if (isset($item["RRD"])) {
         $arOpts[] = "--start";
         $arOpts[] = $first;
         $arOpts[] = "--end";
         $arOpts[] = $last;
     }
     $data = \rrd_graph("/dev/null", $arOpts);
     if (isset($item["DATA_FUNC"])) {
         $func = create_function('$data', $item["DATA_FUNC"]);
         if (is_callable($func)) {
             $result = $func($data);
         }
     } else {
         if (isset($data["calcpr"])) {
             $data["data"] = $data["calcpr"];
         }
         $result = static::extractRrdValue($data);
     }
     return $result;
 }