function _read_cert_from_file()
 {
     $file = new CFile($this->license_cert_file);
     $_rows = $file->getLines();
     $this->cipher->setKey($this->license_key->license_key);
     $certificate = $this->cipher->decrypt(end($_rows));
     // the last row in the cert file is the certifcate data.
     return is_string($certificate) ? trim($certificate) : '';
 }
 /**
  * Use avactis-system/admin/index.php?asc_action=combine_php
  */
 function combinePreloadedPHP()
 {
     global $application;
     $mm = $application->getInstance('Modules_Manager');
     $sys_dir = CConf::get('system_dir');
     $modules_dir = CConf::get('modules_dir');
     $add_modules_dir = CConf::get('add_modules_dir');
     $conf_core = CConf::get('preload_core_php');
     $core_files = array();
     foreach ($conf_core['files'] as $file) {
         $core_files[] = realpath($sys_dir . $file);
     }
     if ($php = fopen($conf_core['combined_file'], 'w')) {
         $this->addPhpFiles($php, array_filter($core_files));
         $file = new CFile($application->appIni['PATH_TAGS_FILE']);
         $tags = $file->getLines();
         if (is_array($tags)) {
             foreach ($tags as $tag) {
                 fwrite($php, "if (! function_exists('{$tag}')) {\n" . $application->getTagFunction($tag) . "\n} else { \nCTrace::inf('Registering tag: function \\'{$tag}\\' is already defined.'); }\n");
                 fwrite($php, "if (! function_exists('get{$tag}')) {\n" . $application->getTagGetFunction($tag) . "\n} else { \nCTrace::inf('Registering tag: function \\'get{$tag}\\' is already defined.'); }\n");
                 fwrite($php, "if (! function_exists('getVal{$tag}')) {\n" . $application->getTagGetValFunction($tag) . "\n} else { \nCTrace::inf('Registering tag: function \\'getVal{$tag}\\' is already defined.'); }\n");
             }
             fwrite($php, "\ndefine('GLOBAL_TAGS_REGISTERED', 'yes');\n");
         }
         fclose($php);
     }
     $modules_core = CConf::get('preload_modules_php');
     $modules_files = array();
     foreach ($modules_core['files'] as $file) {
         if (is_file(realpath($add_modules_dir . $file))) {
             $modules_files[] = realpath($add_modules_dir . $file);
         } else {
             $modules_files[] = realpath($modules_dir . $file);
         }
     }
     foreach ($mm->moduleList as $module_name => $moduleInfo) {
         // see using of COMPILED_MODULES_LOADED constant
         if (isset($moduleInfo->constantsFile)) {
             $const_file = realpath($modules_dir . $moduleInfo->directory . $moduleInfo->constantsFile);
             if (!in_array($const_file, $modules_files) && !in_array($const_file, $core_files)) {
                 $modules_files[] = $const_file;
             }
         }
         $queries_file = realpath($modules_dir . $moduleInfo->directory . 'dbqueries/common.php');
         if (!in_array($queries_file, $modules_files) && !in_array($queries_file, $core_files)) {
             $modules_files[] = $queries_file;
         }
     }
     if ($php = fopen($modules_core['combined_file'], 'w')) {
         $this->addPhpFiles($php, array_filter($modules_files));
         fwrite($php, "\ndefine('COMPILED_MODULES_LOADED', 'yes');\n");
         fclose($php);
     }
     $conf_modules_views_cz = CConf::get('preload_modules_views_cz_php');
     $modules_files = array();
     foreach ($conf_modules_views_cz['files'] as $file) {
         if (is_file(realpath($add_modules_dir . $file))) {
             $modules_files[] = realpath($add_modules_dir . $file);
         } else {
             $modules_files[] = realpath($modules_dir . $file);
         }
     }
     if ($php = fopen($conf_modules_views_cz['combined_file'], 'w')) {
         $this->addPhpFiles($php, array_filter($modules_files));
         //            var_dump($mm->czViewList, $mm->czAliasesList);
         foreach (array_keys($mm->czViewList) as $view) {
             fwrite($php, "\nif (! function_exists('{$view}')) {\n    " . $mm->getViewFunction($view) . "\n}\nelse {\n    CTrace::inf('Registering module view: function \\'{$view}\\' is already defined.');\n}\nif (! function_exists('get{$view}')) {\n    " . $mm->getViewGetFunction($view) . "\n}\nelse {\n    CTrace::inf('Registering module view: function \\'get{$view}\\' is already defined.');\n}");
         }
         foreach ($mm->czAliasesList as $alias_name => $view_name) {
             fwrite($php, "\nif (! function_exists('{$alias_name}')) {\n    " . $mm->getAliasFunction($alias_name, $view_name) . "\n}\nelse {\n    CTrace::inf('Registering module alias: function \\'{$alias_name}\\' is already defined.');\n}\nif (! function_exists('get{$alias_name}')) {\n    " . $mm->getAliasGetFunction($alias_name, $view_name) . "\n}\nelse {\n    CTrace::inf('Registering module alias: function \\'get{$alias_name}\\' is already defined.');\n}");
         }
         fwrite($php, "\ndefine('MODULES_VIEWS_REGISTERED', 'yes');\n");
         fclose($php);
     }
 }
 function saveHTAcontent($hta_content, $layout_path)
 {
     $return = array();
     global $application;
     $row_layout = _parse_cz_layout_ini_file($layout_path, true);
     if (isset($row_layout['Site']['SitePath'])) {
         $dest_file_path = $row_layout['Site']['SitePath'] . '.htaccess';
     } else {
         $dest_file_path = $application->appIni["PATH_ASC_ROOT"] . '.htaccess';
     }
     if (file_exists($dest_file_path) and !is_writable($dest_file_path)) {
         $return[] = 'ERR_CANT_WRITE_FILE';
         return $return;
     }
     if (!is_writable(dirname($dest_file_path))) {
         $return[] = 'ERR_CANT_WRITE_FILE';
         return $return;
     }
     #                     ,
     if (file_exists($dest_file_path)) {
         $file = new CFile($dest_file_path);
         $lines = array_map("rtrim", $file->getLines());
         $out_content = '';
         $i = 0;
         while ($i < count($lines) and $lines[$i] != REWRITE_BLOCK_IDENT_BEGIN) {
             $out_content .= $lines[$i] . "\n";
             $i++;
         }
         $out_content .= $hta_content;
         $i++;
         while ($i < count($lines) and $lines[$i] != REWRITE_BLOCK_IDENT_END) {
             $i++;
         }
         $i++;
         while ($i < count($lines)) {
             $out_content .= $lines[$i] . "\n";
             $i++;
         }
     } else {
         $out_content = $hta_content;
     }
     asc_file_put_contents($dest_file_path, $out_content);
     $layout_integrity = array('product_list' => $row_layout['ProductList'], 'product_info' => $row_layout['ProductInfo'], 'cms_page' => $row_layout['CMSPage']);
     $htaccess_md5 = md5($hta_content);
     $sefu_integrity = array('cats_template' => $application->getAppIni('SEFU_CATEGORY_QUERY_STRING_SUFFIX'), 'prods_template' => $application->getAppIni('SEFU_PRODUCT_QUERY_STRING_SUFFIX'), 'cms_template' => $application->getAppIni('SEFU_CMSPAGE_QUERY_STRING_SUFFIX'));
     $sets_integrity = array('cats_prefix' => $this->settings['CATS_PREFIX'], 'prods_prefix' => $this->settings['PRODS_PREFIX'], 'cms_prefix' => $this->settings['CMS_PREFIX'], 'rewrite_scheme' => $this->settings['REWRITE_SCHEME']);
     $tables = $this->getTables();
     $integrity_table = $tables['mr_integrity']['columns'];
     $query = new DB_Replace('mr_integrity');
     $query->addReplaceValue($layout_path, $integrity_table['layout_path']);
     $query->addReplaceValue(md5(serialize($layout_integrity)), $integrity_table['layout_md5']);
     $query->addReplaceValue($dest_file_path, $integrity_table['htaccess_path']);
     $query->addReplaceValue($htaccess_md5, $integrity_table['htaccess_md5']);
     $query->addReplaceValue(md5(serialize($sefu_integrity)), $integrity_table['sefu_md5']);
     $query->addReplaceValue(md5(serialize($sets_integrity)), $integrity_table['sets_md5']);
     $application->db->PrepareSQL($query);
     $application->db->DB_Exec();
     //                    .      ,        ,                     .
     $this->enableMRforLayout($layout_path);
     return $return;
 }
Example #4
0
 /**
  * Load YAML into a PHP array from an instantiated object
  *
  * The load method, when supplied with a YAML stream (string or file path),
  * will do its best to convert the YAML into a PHP array.  Pretty simple.
  *  Usage:
  *  <code>
  *   $parser = new Spyc;
  *   $array  = $parser->load('lucky.yml');
  *   print_r($array);
  *  </code>
  * @access public
  * @return array
  * @param string $input Path of YAML file or string containing YAML
  */
 function load($input)
 {
     // See what type of input we're talking about
     // If it's not a file, assume it's a string
     if (!empty($input) && strpos($input, "\n") === false && file_exists($input)) {
         $file = new CFile($input);
         $yaml = $file->getLines();
     } else {
         $yaml = explode("\n", $input);
     }
     // Initiate some objects and values
     $base = new YAMLNode(1);
     $base->indent = 0;
     $this->_lastIndent = 0;
     $this->_lastNode = $base->id;
     $this->_inBlock = false;
     $this->_isInline = false;
     $this->_nodeId = 2;
     foreach ($yaml as $linenum => $line) {
         $ifchk = trim($line);
         // If the line starts with a tab (instead of a space), throw a fit.
         if (preg_match('/^(\\t)+(\\w+)/', $line)) {
             $err = 'ERROR: Line ' . ($linenum + 1) . ' in your input YAML begins' . ' with a tab.  YAML only recognizes spaces.  Please reformat.';
             die($err);
         }
         if ($this->_inBlock === false && empty($ifchk)) {
             continue;
         } elseif ($this->_inBlock == true && empty($ifchk)) {
             $last =& $this->_allNodes[$this->_lastNode];
             $last->data[key($last->data)] .= "\n";
         } elseif ($ifchk[0] != '#' && substr($ifchk, 0, 3) != '---') {
             // Create a new node and get its indent
             $node = new YAMLNode($this->_nodeId);
             $this->_nodeId++;
             $node->indent = $this->_getIndent($line);
             // Check where the node lies in the hierarchy
             if ($this->_lastIndent == $node->indent) {
                 // If we're in a block, add the text to the parent's data
                 if ($this->_inBlock === true) {
                     $parent =& $this->_allNodes[$this->_lastNode];
                     $parent->data[key($parent->data)] .= trim($line) . $this->_blockEnd;
                 } else {
                     // The current node's parent is the same as the previous node's
                     if (isset($this->_allNodes[$this->_lastNode])) {
                         $node->parent = $this->_allNodes[$this->_lastNode]->parent;
                     }
                 }
             } elseif ($this->_lastIndent < $node->indent) {
                 if ($this->_inBlock === true) {
                     $parent =& $this->_allNodes[$this->_lastNode];
                     $parent->data[key($parent->data)] .= trim($line) . $this->_blockEnd;
                 } elseif ($this->_inBlock === false) {
                     // The current node's parent is the previous node
                     $node->parent = $this->_lastNode;
                     // If the value of the last node's data was > or | we need to
                     // start blocking i.e. taking in all lines as a text value until
                     // we drop our indent.
                     $parent =& $this->_allNodes[$node->parent];
                     $this->_allNodes[$node->parent]->children = true;
                     if (is_array($parent->data)) {
                         $chk = '';
                         if (isset($parent->data[key($parent->data)])) {
                             $chk = $parent->data[key($parent->data)];
                         }
                         if ($chk === '>') {
                             $this->_inBlock = true;
                             $this->_blockEnd = ' ';
                             $parent->data[key($parent->data)] = str_replace('>', '', $parent->data[key($parent->data)]);
                             $parent->data[key($parent->data)] .= trim($line) . ' ';
                             $this->_allNodes[$node->parent]->children = false;
                             $this->_lastIndent = $node->indent;
                         } elseif ($chk === '|') {
                             $this->_inBlock = true;
                             $this->_blockEnd = "\n";
                             $parent->data[key($parent->data)] = str_replace('|', '', $parent->data[key($parent->data)]);
                             $parent->data[key($parent->data)] .= trim($line) . "\n";
                             $this->_allNodes[$node->parent]->children = false;
                             $this->_lastIndent = $node->indent;
                         }
                     }
                 }
             } elseif ($this->_lastIndent > $node->indent) {
                 // Any block we had going is dead now
                 if ($this->_inBlock === true) {
                     $this->_inBlock = false;
                     if ($this->_blockEnd = "\n") {
                         $last =& $this->_allNodes[$this->_lastNode];
                         $last->data[key($last->data)] = trim($last->data[key($last->data)]);
                     }
                 }
                 // We don't know the parent of the node so we have to find it
                 // foreach ($this->_allNodes as $n) {
                 foreach ($this->_indentSort[$node->indent] as $n) {
                     if ($n->indent == $node->indent) {
                         $node->parent = $n->parent;
                     }
                 }
             }
             if ($this->_inBlock === false) {
                 // Set these properties with information from our current node
                 $this->_lastIndent = $node->indent;
                 // Set the last node
                 $this->_lastNode = $node->id;
                 // Parse the YAML line and return its data
                 $node->data = $this->_parseLine($line);
                 // Add the node to the master list
                 $this->_allNodes[$node->id] = $node;
                 // Add a reference to the parent list
                 $this->_allParent[intval($node->parent)][] = $node->id;
                 // Add a reference to the node in an indent array
                 $this->_indentSort[$node->indent][] =& $this->_allNodes[$node->id];
                 // Add a reference to the node in a References array if this node
                 // has a YAML reference in it.
                 if (is_array($node->data) && isset($node->data[key($node->data)]) && !is_array($node->data[key($node->data)]) && (preg_match('/^&([^ ]+)/', $node->data[key($node->data)]) || preg_match('/^\\*([^ ]+)/', $node->data[key($node->data)]))) {
                     $this->_haveRefs[] =& $this->_allNodes[$node->id];
                 } elseif (is_array($node->data) && isset($node->data[key($node->data)]) && is_array($node->data[key($node->data)])) {
                     // Incomplete reference making code.  Ugly, needs cleaned up.
                     foreach ($node->data[key($node->data)] as $d) {
                         if (!is_array($d) && (preg_match('/^&([^ ]+)/', $d) || preg_match('/^\\*([^ ]+)/', $d))) {
                             $this->_haveRefs[] =& $this->_allNodes[$node->id];
                         }
                     }
                 }
             }
         }
     }
     unset($node);
     // Here we travel through node-space and pick out references (& and *)
     $this->_linkReferences();
     // Build the PHP array out of node-space
     $trunk = $this->_buildArray();
     return $trunk;
 }
 function _httpsrequest($url, $URI, $http_method, $content_type = "", $body = "")
 {
     if ($this->passcookies && $this->_redirectaddr) {
         $this->setcookies();
     }
     $headers = array();
     $URI_PARTS = parse_url($URI);
     if (empty($url)) {
         $url = "/";
     }
     // GET ... header not needed for curl
     //$headers[] = $http_method." ".$url." ".$this->_httpversion;
     if (!empty($this->agent)) {
         $headers[] = "User-Agent: " . $this->agent;
     }
     if (!empty($this->host)) {
         $headers[] = "Host: " . $this->host;
     }
     if (!empty($this->accept)) {
         $headers[] = "Accept: " . $this->accept;
     }
     if (!empty($this->referer)) {
         $headers[] = "Referer: " . $this->referer;
     }
     if (!empty($this->cookies)) {
         if (!is_array($this->cookies)) {
             $this->cookies = (array) $this->cookies;
         }
         reset($this->cookies);
         if (count($this->cookies) > 0) {
             $cookie_str = 'Cookie: ';
             foreach ($this->cookies as $cookieKey => $cookieVal) {
                 $cookie_str .= $cookieKey . "=" . urlencode($cookieVal) . "; ";
             }
             $headers[] = _byte_substr($cookie_str, 0, -2);
         }
     }
     if (!empty($this->rawheaders)) {
         if (!is_array($this->rawheaders)) {
             $this->rawheaders = (array) $this->rawheaders;
         }
         while (list($headerKey, $headerVal) = each($this->rawheaders)) {
             $headers[] = $headerKey . ": " . $headerVal;
         }
     }
     if (!empty($content_type)) {
         if ($content_type == "multipart/form-data") {
             $headers[] = "Content-type: {$content_type}; boundary=" . $this->_mime_boundary;
         } else {
             $headers[] = "Content-type: {$content_type}";
         }
     }
     if (!empty($body)) {
         $headers[] = "Content-length: " . _byte_strlen($body);
     }
     if (!empty($this->user) || !empty($this->pass)) {
         $headers[] = "Authorization: BASIC " . base64_encode($this->user . ":" . $this->pass);
     }
     for ($curr_header = 0; $curr_header < count($headers); $curr_header++) {
         $cmdline_params .= " -H \"" . $headers[$curr_header] . "\"";
     }
     if (!empty($body)) {
         $cmdline_params .= " -d \"{$body}\"";
     }
     if ($this->read_timeout > 0) {
         $cmdline_params .= " -m " . $this->read_timeout;
     }
     $headerfile = tempnam($temp_dir, "sno");
     $safer_URI = strtr($URI, "\"", " ");
     // strip quotes from the URI to avoid shell access
     exec($this->curl_path . " -D \"{$headerfile}\"" . $cmdline_params . " \"" . $safer_URI . "\"", $results, $return);
     if ($return) {
         $this->error = "Error: cURL could not retrieve the document, error {$return}.";
         return false;
     }
     $results = implode("\r\n", $results);
     $file = new CFile($headerfile);
     $result_headers = $file->getLines();
     $this->_redirectaddr = false;
     unset($this->headers);
     for ($currentHeader = 0; $currentHeader < count($result_headers); $currentHeader++) {
         // if a header begins with Location: or URI:, set the redirect
         if (preg_match("/^(Location: |URI: )/i", $result_headers[$currentHeader])) {
             // get URL portion of the redirect
             preg_match("/^(Location: |URI:)\\s+(.*)/", chop($result_headers[$currentHeader]), $matches);
             // look for :// in the Location header to see if hostname is included
             if (!preg_match("|\\:\\/\\/|", $matches[2])) {
                 // no host in the path, so prepend
                 $this->_redirectaddr = $URI_PARTS["scheme"] . "://" . $this->host . ":" . $this->port;
                 // eliminate double slash
                 if (!preg_match("|^/|", $matches[2])) {
                     $this->_redirectaddr .= "/" . $matches[2];
                 } else {
                     $this->_redirectaddr .= $matches[2];
                 }
             } else {
                 $this->_redirectaddr = $matches[2];
             }
         }
         if (preg_match("|^HTTP/|", $result_headers[$currentHeader])) {
             $this->response_code = $result_headers[$currentHeader];
         }
         $this->headers[] = $result_headers[$currentHeader];
     }
     // check if there is a a redirect meta tag
     if (preg_match("'<meta[\\s]*http-equiv[^>]*?content[\\s]*=[\\s]*[\"\\']?\\d+;[\\s]+URL[\\s]*=[\\s]*([^\"\\']*?)[\"\\']?>'i", $results, $match)) {
         $this->_redirectaddr = $this->_expandlinks($match[1], $URI);
     }
     // have we hit our frame depth and is there frame src to fetch?
     if ($this->_framedepth < $this->maxframes && preg_match_all("'<frame\\s+.*src[\\s]*=[\\'\"]?([^\\'\"\\>]+)'i", $results, $match)) {
         $this->results[] = $results;
         for ($x = 0; $x < count($match[1]); $x++) {
             $this->_frameurls[] = $this->_expandlinks($match[1][$x], $URI_PARTS["scheme"] . "://" . $this->host);
         }
     } elseif (is_array($this->results)) {
         $this->results[] = $results;
     } else {
         $this->results = $results;
     }
     unlink("{$headerfile}");
     return true;
 }