private function setFont($font) { try { $fNode = Node::load(array('id' => $font, 'class' => 'file')); } catch (ObjectNotFoundException $e) { throw new PageNotFoundException(t('Шрифт с идентификатором %id не найден.', array('%id' => $font))); } $this->font = mcms::config('filestorage') . DIRECTORY_SEPARATOR . $fNode->filepath; }
public static function decrypt($input) { $input = base64_decode(rawurldecode($input)); if (function_exists('mcrypt_create_iv') and $key = mcms::config('guid')) { $securekey = hash('sha256', $key, true); $iv = mcrypt_create_iv(32); $input = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $securekey, $input, MCRYPT_MODE_ECB, $iv); } return $input; }
private static function checkDbAccess(Context $ctx) { if (null !== ($file = $ctx->db->getDbFile())) { if (0 === strpos(realpath($file), MCMS_ROOT . DIRECTORY_SEPARATOR)) { $url = $ctx->url()->getBase($ctx) . os::webpath($file); if (false !== ($headers = (array) @get_headers($url, 1))) { if (3 == count($parts = explode(' ', $headers[0]))) { if (200 == $parts[1]) { return t('Файл базы данных доступен веб серверу, любой желающий может <a href=\'@url\'>скачать его</a>. Пожалуйста, вынесите его в папку, недоступную веб серверу, и измените путь в конфигурационном файле (%config).', array('@url' => $url, '%config' => mcms::config('fullpath'))); } } } } } }
public function __construct(Context $ctx) { // Если кроме id аттачмента ничего не задали, ругаемся if (null == $ctx->get('fid', null) or null == $ctx->get('scale', null)) { $this->sendError(500, 'usage: ?q=imgtoolkit.rpc&fid=attachment[&operation=parameter...]'); } foreach ($this->options as $k => $v) { if ($p = $ctx->get($k)) { if (in_array($k, array('noshow', 'merge', 'fid', 'mirrorH', 'mirrorV'))) { $this->options[$k] = $p; } else { $this->options[$k] = floatval($p); } } // Формируем имя файла-ссылки для кэша $outfile .= "{$this->options[$k]},"; } $outfile = trim($outfile, ','); $node = Node::load(array('class' => 'file', 'id' => $this->options['fid'])); if (empty($node)) { self::sendError(404, 'attachment not found.'); } if (null === ($storage = mcms::config('filestorage'))) { $storage = 'storage'; } $this->node = $node; $this->filename = $node->filename; $this->folder = $storage; $this->sourceDir = $storage; $this->source = $storage . '/' . $node->filepath; $this->output = $this->folder . '/' . $outfile; if (null != $this->options['merge']) { $this->mergeNode = Node::load(array('class' => 'file', 'id' => $this->options['merge'])); if (empty($this->mergeNode)) { self::sendError(404, 'merge attachment not found.'); } } }
public static function getSignature(Context $ctx = null, $full = false) { $result = array('version' => mcms::version(), 'client' => $_SERVER['REMOTE_ADDR']); try { if (null === $ctx) { $ctx = Context::last(); } $result['at'] = $ctx->host() . $ctx->folder(); $result['version_link'] = 'http://code.google.com/p/molinos-cms/wiki/ChangeLog_' . str_replace('.', '_', mcms::version(mcms::VERSION_STABLE)); if ($full) { $options = array(); if (count($parts = explode(':', mcms::config('db')))) { if (in_array($parts[0], Database::listDrivers())) { $options[] = $parts[0]; } } $options[] = str_replace('_provider', '', get_class(cache::getInstance())); $options[] = ini_get('memory_limit'); $result['options'] = join('+', $options); } } catch (Exception $e) { } return $result; }
public static function listDrivers() { return array_diff(PDO::getAvailableDrivers(), mcms::config('runtime.db.drivers.disable', array())); }
/** * Возвращает список источников обновлений. */ public static function getSources() { if (!is_array($urls = mcms::config('sources'))) { $urls = array(); } $default = 'http://molinos-cms.googlecode.com/svn/dist/' . mcms::version(mcms::VERSION_RELEASE) . '/modules.ini'; if (!in_array($default, $urls)) { $urls[] = $default; } asort($urls); return $urls; }
public static function fetch($url, $options = null) { // FIXME: придумать нормальное решение! try { $tmpdir = Context::last()->config->getPath('main/tmpdir'); } catch (Exception $e) { $tmpdir = null; } if (!$tmpdir) { $tmpdir = 'tmp'; } $outfile = os::path(os::mkdir($tmpdir), 'mcms-fetch.' . md5($url)); $ttl = mcms::config('file.cache.ttl', 3600); if (file_exists($outfile) and ($options & self::NO_CACHE or time() - $ttl > @filectime($outfile))) { if (is_writable(dirname($outfile))) { Logger::log('removing cached copy of ' . $url, 'fetch'); unlink($outfile); } } // Скачиваем файл только если его нет на диске во временной директории if (file_exists($outfile)) { Logger::log('found in cache: ' . $url, 'fetch'); } else { if (function_exists('curl_init')) { $ch = curl_init($url); $fp = fopen($outfile, "w+"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); if (null !== ($time = ini_get('max_execution_time'))) { curl_setopt($ch, CURLOPT_TIMEOUT, $time); } curl_setopt($ch, CURLOPT_USERAGENT, 'Molinos.CMS/' . mcms::version() . '; http://' . MCMS_HOST_NAME); if (!ini_get('safe_mode')) { curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); } curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); fclose($fp); if (200 != $code) { Logger::log($url . ': error ' . $code, 'fetch'); unlink($outfile); return null; } } elseif ($f = @fopen($url, 'rb')) { if (!($out = fopen($outfile, 'w'))) { throw new RuntimeException(t('Не удалось сохранить временный файл %name', array('%name' => $outfile))); } while (!feof($f)) { fwrite($out, fread($f, 1024)); } fclose($f); fclose($out); } else { Logger::log($url . ': failed.', 'fetch'); throw new RuntimeException(t('Не удалось загрузить файл: ' . 'модуль CURL отсутствует, ' . 'открыть поток HTTP тоже не удалось.')); } if (function_exists('get_headers')) { $headers = get_headers($url, true); if (!empty($headers['Content-Length']) and ($real = $headers['Content-Length']) != ($got = filesize($outfile))) { unlink($outfile); throw new RuntimeException(t('Не удалось скачать файл: вместо %real байтов было получено %got.', array('%got' => $got, '%real' => $real))); } } } if ($options & self::CONTENT) { $content = file_get_contents($outfile); return $content; } else { return $outfile; } }