/** * To prevent users from using something insecure like "Password" we make sure that the * secret they've provided is at least 30 characters in length. */ private function ensureSecretSecure() { if (empty($this->options['secret'])) { throw new ArgumentException(Ak::t('A secret is required to generate an integrity hash for cookie session data. Use ' . 'AkConfig::setOption(\'action_controller.session\', ' . 'array("key" => "_myapp_session", "secret" => "some secret ' . 'phrase of at least %length characters")); in config/environment.php', array('%length' => self::SECRET_MIN_LENGTH))); } if (strlen($this->options['secret']) < self::SECRET_MIN_LENGTH) { throw new ArgumentException(Ak::t('Secret should be something secure, ' . 'like "%rand". The value you provided "%secret", ' . 'is shorter than the minimum length of %length characters', array('%length' => self::SECRET_MIN_LENGTH, '%rand' => Ak::uuid(), '%secret' => $this->options['secret']))); } }
function extractImagesIntoInlineParts(&$Mail, $options = array()) { $html =& $Mail->body; require_once(AK_LIB_DIR.DS.'AkActionView'.DS.'helpers'.DS.'text_helper.php'); $images = TextHelper::get_image_urls_from_html($html); $html_images = array(); if(!empty($images)){ require_once(AK_LIB_DIR.DS.'AkImage.php'); require_once(AK_LIB_DIR.DS.'AkActionView'.DS.'helpers'.DS.'asset_tag_helper.php'); $images = array_diff(array_unique($images), array('')); foreach ($images as $image){ $original_image_name = $image; $image = $this->_getImagePath($image); if(!empty($image)){ $extenssion = substr($image, strrpos('.'.$image,'.')); $image_name = Ak::uuid().'.'.$extenssion; $html_images[$original_image_name] = 'cid:'.$image_name; $Mail->setAttachment('image/'.$extenssion, array( 'body' => Ak::file_get_contents($image), 'filename' => $image_name, 'content_disposition' => 'inline', 'content_id' => '<'.$image_name.'>', )); } } $modified_html = str_replace(array_keys($html_images),array_values($html_images), $html); if($modified_html != $html){ $html = $modified_html; $Mail->_moveBodyToInlinePart(); } } }
public function extractImagesIntoInlineParts(&$Mail, $options = array()) { $html =& $Mail->body; $images = AkTextHelper::get_image_urls_from_html($html); $html_images = array(); if (!empty($images)) { $tmp_dir = AkConfig::getDir('tmp'); $app_dir = AkConfig::getDir('app'); $images = array_diff(array_unique($images), array('')); foreach ($images as $image) { $original_image_name = $image; if (substr($image, 0, 4) == 'cid:') { continue; } $image = $this->_getImagePath($image); if (!empty($image)) { $extenssion = substr($image, strrpos('.' . $image, '.')); $image_name = Ak::uuid() . '.' . $extenssion; $html_images[$original_image_name] = 'cid:' . $image_name; $Mail->setAttachment('image/' . $extenssion, array('body' => AkFileSystem::file_get_contents($image, array('base_path' => strstr($image, $app_dir) ? null : $tmp_dir)), 'filename' => $image_name, 'content_disposition' => 'inline', 'content_id' => '<' . $image_name . '>')); } } $modified_html = str_replace(array_keys($html_images), array_values($html_images), $html); if ($modified_html != $html) { $html = $modified_html; $Mail->moveBodyToInlinePart(); } } }
static function setTokenKey($key = null) { $key = empty($key) ? Ak::uuid() : $key; $yml_path = realpath(AkConfig::getDir('app') . DS . '../config') . DS . 'admin.yml'; $admin_yml = file_get_contents($yml_path); $admin_yml = preg_replace('/token_key: SECRET/', 'token_key: ' . $key, $admin_yml); file_put_contents($yml_path, $admin_yml); }
function cachePage($content, $path = null, $language = null, $gzipped=false, $sendETag = false, $orgStrlen = null) { global $_ENV; static $ETag; $cacheIds = array(); if (!($this->_cachingAllowed() && $this->_perform_caching)) return; $cacheId = $this->_buildCacheId($path, $language); $skipEtagSending = false; if ($orgStrlen != strlen($content)) $skipEtagSending = true; $notNormalizedCacheId = $this->_buildCacheId($path, $language,false); $removeHeaders = array(); $addHeaders = array(); if ($gzipped) { $cacheId = $this->_scopeWithGzip($cacheId); $notNormalizedCacheId = $this->_scopeWithGzip($notNormalizedCacheId); $addHeaders = array('Content-Encoding'=>'gzip','Content-Length'=>strlen($content)); $removeHeaders = array('content-length'); } else { $removeHeaders = array('content-encoding'); } $addHeaders = array_merge($addHeaders,$this->_additional_headers); $cacheGroup = $this->_buildCacheGroup(); if ($sendETag && !headers_sent()) { $ETag = Ak::uuid(); $etagHeader = 'ETag: '.$ETag; $this->_controller->Response->addSentHeader($etagHeader); if(!$skipEtagSending) { header($etagHeader); } else { header('Expires: '.gmdate('D, d M Y H:i:s',0)); } } //$addHeaders['ETag'] = $ETag; $cacheIds[] = $cacheId; $cacheIds[] = $notNormalizedCacheId; $cacheTimestamp = time(); $content = $this->_modifyCacheContent($content,$addHeaders, $removeHeaders,$cacheIds,$cacheGroup); //Ak::getLogger('caching')->message('Got timestamp from ENV:'.$_ENV['_page_cache_timestamp']); $cached_params = $this->_storePageCache($content,$cacheId,$cacheGroup,!empty($_ENV['_page_cache_timestamp'])?$_ENV['_page_cache_timestamp']:null); $res = $this->_cache_store->save($cached_params,$cacheId,$cacheGroup); if ($notNormalizedCacheId != $cacheId) { // Store the not normalized cacheid $cached_params = $this->_storePageCache($content,$cacheId,$cacheGroup,!empty($_ENV['_page_cache_timestamp'])?$_ENV['_page_cache_timestamp']:null); $this->_cache_store->save($cached_params,$notNormalizedCacheId,$cacheGroup); } return $res; }
function cachePage($content, $path = null, $language = null, $gzipped=false, $sendETag = false, $orgStrlen = null) { static $ETag; if (!($this->_cachingAllowed() && $this->_perform_caching)) return; $cacheId = $this->_buildCacheId($path, $language); $skipEtagSending = false; if ($orgStrlen != strlen($content)) $skipEtagSending = true; $notNormalizedCacheId = $this->_buildCacheId($path, $language,false); $removeHeaders = array(); $addHeaders = array(); if ($gzipped) { $cacheId = $this->_scopeWithGzip($cacheId); $notNormalizedCacheId = $this->_scopeWithGzip($notNormalizedCacheId); $addHeaders = array('Content-Encoding'=>'gzip'); } else { $removeHeaders = array('content-encoding'); } $cacheGroup = $this->_buildCacheGroup(); if ($sendETag && !headers_sent()) { $ETag = Ak::uuid(); $etagHeader = 'ETag: '.$ETag; $this->_controller->Response->addSentHeader($etagHeader); if(!$skipEtagSending) { header($etagHeader); } else { header('Expires: '.gmdate('D, d M Y H:i:s',0)); } } //$addHeaders['ETag'] = $ETag; $cacheTimestamp = time(); $content = $this->_modifyCacheContent($content,$addHeaders, $removeHeaders); $filename = $this->_storePageCache($content,$cacheId,$cacheGroup); $res = $this->_cache_store->save($filename,$cacheId,$cacheGroup); if ($notNormalizedCacheId != $cacheId) { // Store the not normalized cacheid $filename = $this->_storePageCache($content,$cacheId,$cacheGroup); $this->_cache_store->save($filename,$notNormalizedCacheId,$cacheGroup); } return $res; }
function _handle_partial_files($params) { $result = array(); foreach ($params as $name=>$details){ if(is_array($details) && !empty($details['name']) && !empty($details['tmp_name']) && !empty($details['size'])){ $details['persistence_key'] = md5($details['tmp_name'].Ak::uuid()); $details['human_size'] = $this->_controller->number_helper->human_size($details['size']); $file = $this->Cache->get($details['persistence_key'], 'persistent_files'); if (empty($file)) { $this->Cache->save(serialize(array_merge($details,array('contents'=>base64_encode(file_get_contents($details['tmp_name']))))), $details['persistence_key'], 'persistent_files'); } $result[$name] = $details; }elseif(is_array($details)){ $_nested = $this->_handle_partial_files($details); if(!empty($_nested)){ $result = array_merge(array($name=>$_nested), $result); } } } return $result; }
private function _setExternals($items, $extras = '') { $externals = array(); foreach ($items as $name => $uri) { $externals[] = "{$name} " . rtrim($uri, '/'); } $tmp_file = AK_TMP_DIR . DS . Ak::uuid(); $plugins_dir = AK_PLUGINS_DIR; AkFileSystem::file_put_contents($tmp_file, join("\n", $externals)); `svn propset {$extras} -q svn:externals -F "{$tmp_file}" "{$plugins_dir}"`; AkFileSystem::file_delete($tmp_file); }
public function _identifyRequest() { $this->_request_id = Ak::uuid(); }
public static function form_authenticity_token() { if (!isset($_SESSION['_csrf_token'])) { $_SESSION['_csrf_token'] = sha1(Ak::uuid() . Ak::randomString()); } return $_SESSION['_csrf_token']; }
static function checkIfTestingWebserverIsAccesible($options = array()) { if (AkConfig::getOption('webserver_enabled', false)) { return; } if (!AK_WEB_REQUEST && file_exists($options['base_path'] . DS . 'ping.php')) { $uuid = Ak::uuid(); file_put_contents($options['base_path'] . DS . 'akelos_test_ping_uuid.txt', $uuid); AkConfig::setOption('webserver_enabled', @file_get_contents(AkConfig::getOption('testing_url') . '/' . basename($options['base_path']) . '/ping.php') == $uuid); unlink($options['base_path'] . DS . 'akelos_test_ping_uuid.txt'); } else { AkConfig::setOption('webserver_enabled', false); } }
function _getHeaders($to = null) { return array('From' => trim($this->email_account->sender_name . ' <' . $this->email_account->reply_to . '>'), 'Return-path' => trim($this->email_account->sender_name . ' <' . $this->email_account->reply_to . '>'), 'Subject' => $this->subject, 'To' => $to, 'Message-Id' => '<' . $this->id . '.' . Ak::uuid() . substr('*****@*****.**', strpos('*****@*****.**', '@')) . '>', 'Date' => strftime("%a, %d %b %Y %H:%M:%S %z", Ak::getTimestamp())); }
protected function _cleanUpAndCreateEmptyFolders() { # empty log files if (!AK_WIN) { $writable_files = array('log', 'log/development.log', 'log/production.log', 'log/testing.log', 'config/locales', 'app/locales'); foreach ($writable_files as $file) { $file = $this->options['directory'] . DS . $file; if (!is_file($file)) { touch($file); } `chmod -R 777 {$file}`; } } $dirs_to_remove = array('releases', 'reports'); foreach ($dirs_to_remove as $dir) { self::removeDir($this->options['directory'] . DS . $dir); } $files_and_replacements = array('config/environment.php' => array('[SECRET]' => Ak::uuid())); foreach ($files_and_replacements as $file => $replacements) { $file = $this->options['directory'] . DS . $file; file_put_contents($file, str_replace(array_keys($replacements), array_values($replacements), file_get_contents($file))); } // Copy docs self::copyRecursivelly($this->options['directory'] . DS . 'vendor' . DS . 'akelos' . DS . 'docs', $this->options['directory'] . DS . 'docs'); }