本文整理汇总了PHP中KExternalErrors::dieGracefully方法的典型用法代码示例。如果您正苦于以下问题:PHP KExternalErrors::dieGracefully方法的具体用法?PHP KExternalErrors::dieGracefully怎么用?PHP KExternalErrors::dieGracefully使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KExternalErrors
的用法示例。
在下文中一共展示了KExternalErrors::dieGracefully方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Serves multiple files for synchronization between datacenters
*/
public function execute()
{
$fileSyncIds = $this->getRequestParameter("ids");
$hash = $this->getRequestParameter("hash");
// validate hash
$currentDc = kDataCenterMgr::getCurrentDc();
$currentDcId = $currentDc["id"];
$expectedHash = md5($currentDc["secret"] . $fileSyncIds);
if ($hash !== $expectedHash) {
$error = "Invalid hash - ids [{$fileSyncIds}] got [{$hash}] expected [{$expectedHash}]";
KalturaLog::err($error);
KExternalErrors::dieError(KExternalErrors::INVALID_TOKEN);
}
// load file syncs
$fileSyncs = FileSyncPeer::retrieveByPks(explode(',', $fileSyncIds));
if ($fileSyncs) {
KalturaMonitorClient::initApiMonitor(false, 'extwidget.serveMultiFile', $fileSyncs[0]->getPartnerId());
}
// resolve file syncs
$filePaths = array();
foreach ($fileSyncs as $fileSync) {
if ($fileSync->getDc() != $currentDcId) {
$error = "FileSync id [" . $fileSync->getId() . "] does not belong to this DC";
KalturaLog::err($error);
KExternalErrors::dieError(KExternalErrors::BAD_QUERY);
}
// resolve if file_sync is link
$fileSyncResolved = kFileSyncUtils::resolve($fileSync);
// check if file sync path leads to a file or a directory
$resolvedPath = $fileSyncResolved->getFullPath();
if (is_dir($resolvedPath)) {
$error = "FileSync id [" . $fileSync->getId() . "] is a directory";
KalturaLog::err($error);
KExternalErrors::dieError(KExternalErrors::BAD_QUERY);
}
if (!file_exists($resolvedPath)) {
$error = "Path [{$resolvedPath}] for fileSync id [" . $fileSync->getId() . "] does not exist";
KalturaLog::err($error);
continue;
}
$filePaths[$fileSync->getId()] = $resolvedPath;
}
$boundary = md5(uniqid('', true));
header('Content-Type: multipart/form-data; boundary=' . $boundary);
foreach ($filePaths as $id => $filePath) {
echo "--{$boundary}\n";
echo "Content-Type: application/octet-stream\n";
echo "Content-Disposition: form-data; name=\"{$id}\"\n\n";
readfile($filePath);
echo "\n";
}
echo "--{$boundary}--\n";
KExternalErrors::dieGracefully();
}
示例2: execute
/**
* Will forward to the regular swf player according to the widget_id
*/
public function execute()
{
// where file is {entryId/flavorId}.{ism,ismc,ismv}
$objectId = $type = null;
$objectIdStr = $this->getRequestParameter("objectId");
if ($objectIdStr) {
list($objectId, $type) = @explode(".", $objectIdStr);
}
if (!$type || !$objectId) {
KExternalErrors::dieError(KExternalErrors::MISSING_PARAMETER);
}
$ks = $this->getRequestParameter("ks");
$referrer = base64_decode($this->getRequestParameter("referrer"));
if (!is_string($referrer)) {
// base64_decode can return binary data
$referrer = '';
}
$syncKey = $this->getFileSyncKey($objectId, $type);
KalturaMonitorClient::initApiMonitor(false, 'extwidget.serveIsm', $this->entry->getPartnerId());
myPartnerUtils::enforceDelivery($this->entry, $this->flavorAsset);
if (!kFileSyncUtils::file_exists($syncKey, false)) {
list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false);
if (is_null($fileSync)) {
KalturaLog::log("Error - no FileSync for type [{$type}] objectId [{$objectId}]");
KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND);
}
$remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync);
kFileUtils::dumpUrl($remoteUrl);
}
$path = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey);
if ($type == 'ism') {
$fileData = $this->fixIsmManifestForReplacedEntry($path);
$renderer = new kRendererString($fileData, 'image/ism');
$renderer->output();
KExternalErrors::dieGracefully();
} else {
kFileUtils::dumpFile($path);
}
}
示例3: dumpUrl
public static function dumpUrl($url, $allowRange = true, $passHeaders = false, $additionalHeaders = null)
{
KalturaLog::debug("URL [{$url}], {$allowRange} [{$allowRange}], {$passHeaders} [{$passHeaders}]");
self::closeDbConnections();
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "curl/7.11.1");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// in case of private ips (internal to the datacenters) no need to check the certificate validity.
// otherwise curling for https://127.0.0.1/ will fail as the certificate is for *.domain.com
$urlHost = parse_url($url, PHP_URL_HOST);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, infraRequestUtils::isIpPrivate($urlHost) ? 0 : 2);
// prevent loop back of the proxied request by detecting the "X-Kaltura-Proxy header
if (isset($_SERVER["HTTP_X_KALTURA_PROXY"])) {
KExternalErrors::dieError(KExternalErrors::PROXY_LOOPBACK);
}
$sendHeaders = array("X-Kaltura-Proxy: dumpUrl");
if ($passHeaders) {
$sentHeaders = self::getRequestHeaders();
foreach ($sentHeaders as $header => $value) {
$sendHeaders[] = "{$header}: {$value}";
}
} elseif ($allowRange && isset($_SERVER['HTTP_RANGE']) && $_SERVER['HTTP_RANGE']) {
// get range parameters from HTTP range requst headers
list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
curl_setopt($ch, CURLOPT_RANGE, $range);
}
if ($additionalHeaders) {
foreach ($additionalHeaders as $header => $value) {
$sendHeaders[] = "{$header}: {$value}";
}
}
// when proxying request to other datacenter we may be already in a proxied request (from one of the internal proxy servers)
// we need to ensure the original HOST is sent in order to allow restirctions checks
$host = isset($_SERVER["HTTP_X_FORWARDED_HOST"]) ? $_SERVER["HTTP_X_FORWARDED_HOST"] : $_SERVER["HTTP_HOST"];
for ($i = 0; $i < count($sendHeaders); $i++) {
if (stripos($sendHeaders[$i], "host:") === 0) {
array_splice($sendHeaders, $i, 1);
break;
}
}
$sendHeaders[] = "Host:{$host}";
curl_setopt($ch, CURLOPT_HTTPHEADER, $sendHeaders);
if ($_SERVER['REQUEST_METHOD'] == 'HEAD') {
// request was HEAD, proxy only HEAD response
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
} else {
// Set callback function for body
curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'kFileUtils::read_body');
}
// Set callback function for headers
curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'kFileUtils::read_header');
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
header("Access-Control-Allow-Origin:*");
// avoid html5 xss issues
header("X-Kaltura:dumpUrl");
// grab URL and pass it to the browser
$content = curl_exec($ch);
KalturaLog::debug("CURL executed [{$content}]");
// close curl resource, and free up system resources
curl_close($ch);
KExternalErrors::dieGracefully();
}
示例4: execute
public function execute()
{
//entitlement should be disabled to serveFlavor action as we do not get ks on this action.
KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
requestUtils::handleConditionalGet();
$flavorId = $this->getRequestParameter("flavorId");
$shouldProxy = $this->getRequestParameter("forceproxy", false);
$fileName = $this->getRequestParameter("fileName");
$fileParam = $this->getRequestParameter("file");
$fileParam = basename($fileParam);
$pathOnly = $this->getRequestParameter("pathOnly", false);
$referrer = base64_decode($this->getRequestParameter("referrer"));
if (!is_string($referrer)) {
// base64_decode can return binary data
$referrer = '';
}
$flavorAsset = assetPeer::retrieveById($flavorId);
if (is_null($flavorAsset)) {
KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
}
$entryId = $this->getRequestParameter("entryId");
if (!is_null($entryId) && $flavorAsset->getEntryId() != $entryId) {
KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
}
if ($fileName) {
header("Content-Disposition: attachment; filename=\"{$fileName}\"");
header("Content-Type: application/force-download");
header("Content-Description: File Transfer");
}
$clipTo = null;
$entry = $flavorAsset->getentry();
if (!$entry) {
KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
}
KalturaMonitorClient::initApiMonitor(false, 'extwidget.serveFlavor', $flavorAsset->getPartnerId());
myPartnerUtils::enforceDelivery($entry, $flavorAsset);
$version = $this->getRequestParameter("v");
if (!$version) {
$version = $flavorAsset->getVersion();
}
$syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET, $version);
if ($pathOnly && kIpAddressUtils::isInternalIp($_SERVER['REMOTE_ADDR'])) {
$path = null;
list($file_sync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, false, false);
if ($file_sync) {
$parent_file_sync = kFileSyncUtils::resolve($file_sync);
$path = $parent_file_sync->getFullPath();
if ($fileParam && is_dir($path)) {
$path .= "/{$fileParam}";
}
}
$renderer = new kRendererString('{"sequences":[{"clips":[{"type":"source","path":"' . $path . '"}]}]}', 'application/json');
if ($path) {
$this->storeCache($renderer, $flavorAsset->getPartnerId());
}
$renderer->output();
KExternalErrors::dieGracefully();
}
if (kConf::hasParam('serve_flavor_allowed_partners') && !in_array($flavorAsset->getPartnerId(), kConf::get('serve_flavor_allowed_partners'))) {
KExternalErrors::dieError(KExternalErrors::ACTION_BLOCKED);
}
if (!kFileSyncUtils::file_exists($syncKey, false)) {
list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false);
if (is_null($fileSync)) {
KalturaLog::log("Error - no FileSync for flavor [" . $flavorAsset->getId() . "]");
KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND);
}
// always dump remote urls so they will be cached by the cdn transparently
$remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync);
kFileUtils::dumpUrl($remoteUrl);
}
$path = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey);
$isFlv = false;
if (!$shouldProxy) {
$flvWrapper = new myFlvHandler($path);
$isFlv = $flvWrapper->isFlv();
}
$clipFrom = $this->getRequestParameter("clipFrom", 0);
// milliseconds
if (is_null($clipTo)) {
$clipTo = $this->getRequestParameter("clipTo", self::NO_CLIP_TO);
}
// milliseconds
if ($clipTo == 0) {
$clipTo = self::NO_CLIP_TO;
}
if (!is_numeric($clipTo) || $clipTo < 0) {
KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'clipTo must be a positive number');
}
$seekFrom = $this->getRequestParameter("seekFrom", -1);
if ($seekFrom <= 0) {
$seekFrom = -1;
}
$seekFromBytes = $this->getRequestParameter("seekFromBytes", -1);
if ($seekFromBytes <= 0) {
$seekFromBytes = -1;
}
if ($fileParam && is_dir($path)) {
$path .= "/{$fileParam}";
kFileUtils::dumpFile($path, null, null);
//.........这里部分代码省略.........
示例5: initStorageProfile
public function initStorageProfile()
{
if (!$this->deliveryAttributes->getStorageId()) {
return;
}
$storageProfile = StorageProfilePeer::retrieveByPK($this->deliveryAttributes->getStorageId());
if (!$storageProfile) {
KExternalErrors::dieGracefully();
}
// TODO use a dieError
// storage doesn't belong to the partner
if ($storageProfile->getPartnerId() != $this->entry->getPartnerId()) {
KExternalErrors::dieGracefully();
}
// TODO use a dieError
}
示例6: execute
/**
* Will forward to the regular swf player according to the widget_id
*/
public function execute()
{
$entry_id = $this->getRequestParameter("entry_id");
$entry = null;
$widget_id = null;
$partner_id = null;
if ($entry_id) {
$entry = entryPeer::retrieveByPK($entry_id);
if (!$entry) {
KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
}
$partner_id = $entry->getPartnerId();
$widget_id = '_' . $partner_id;
}
$widget_id = $this->getRequestParameter("widget_id", $widget_id);
$widget = widgetPeer::retrieveByPK($widget_id);
if (!$widget) {
KExternalErrors::dieError(KExternalErrors::WIDGET_NOT_FOUND);
}
$subp_id = $widget->getSubpId();
if (!$subp_id) {
$subp_id = 0;
}
if (!$entry_id) {
$entry_id = $widget->getEntryId();
if ($entry_id) {
$entry = entryPeer::retrieveByPK($entry_id);
if (!$entry) {
KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
}
}
}
$allowCache = true;
$securityType = $widget->getSecurityType();
switch ($securityType) {
case widget::WIDGET_SECURITY_TYPE_TIMEHASH:
// TODO - I don't know what should be validated here
break;
case widget::WIDGET_SECURITY_TYPE_MATCH_IP:
$allowCache = false;
// here we'll attemp to match the ip of the request with that from the customData of the widget
$custom_data = $widget->getCustomData();
$valid_country = false;
if ($custom_data) {
// in this case the custom_data should be of format:
// valid_county_1,valid_country_2,...,valid_country_n;falback_entry_id
$arr = explode(";", $custom_data);
$countries_str = $arr[0];
$fallback_entry_id = isset($arr[1]) ? $arr[1] : null;
$fallback_kshow_id = isset($arr[2]) ? $arr[2] : null;
$current_country = "";
$valid_country = requestUtils::matchIpCountry($countries_str, $current_country);
if (!$valid_country) {
KalturaLog::log("Attempting to access widget [{$widget_id}] and entry [{$entry_id}] from country [{$current_country}]. Retrning entry_id: [{$fallback_entry_id}] kshow_id [{$fallback_kshow_id}]");
$entry_id = $fallback_entry_id;
}
}
break;
case widget::WIDGET_SECURITY_TYPE_FORCE_KS:
$ks_str = $this->getRequestParameter('ks');
try {
$ks = kSessionUtils::crackKs($ks_str);
} catch (Exception $e) {
KExternalErrors::dieError(KExternalErrors::INVALID_KS);
}
$res = kSessionUtils::validateKSession2(1, $partner_id, 0, $ks_str, $ks);
if ($res <= 0) {
KExternalErrors::dieError(KExternalErrors::INVALID_KS);
}
break;
default:
break;
}
$requestKey = $_SERVER["REQUEST_URI"];
// check if we cached the redirect url
$cache = new myCache("embedIframe", 10 * 60);
// 10 minutes
$cachedResponse = $cache->get($requestKey);
if ($allowCache && $cachedResponse) {
header("X-Kaltura: cached-action");
header("Expires: Sun, 19 Nov 2000 08:52:00 GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
header("Location:{$cachedResponse}");
KExternalErrors::dieGracefully();
}
$uiconf_id = $this->getRequestParameter('uiconf_id');
if (!$uiconf_id) {
$uiconf_id = $widget->getUiConfId();
}
if (!$uiconf_id) {
KExternalErrors::dieError(KExternalErrors::MISSING_PARAMETER, 'uiconf_id');
}
$partner_host = myPartnerUtils::getHost($partner_id);
$partner_cdnHost = myPartnerUtils::getCdnHost($partner_id);
$uiConf = uiConfPeer::retrieveByPK($uiconf_id);
if (!$uiConf) {
//.........这里部分代码省略.........
示例7: execute
/**
* Will forward to the regular swf player according to the widget_id
*/
public function execute()
{
$uiconf_id = $this->getRequestParameter('uiconf_id');
if (!$uiconf_id) {
KExternalErrors::dieError(KExternalErrors::MISSING_PARAMETER, 'uiconf_id');
}
$uiConf = uiConfPeer::retrieveByPK($uiconf_id);
if (!$uiConf) {
KExternalErrors::dieError(KExternalErrors::UI_CONF_NOT_FOUND);
}
$partner_id = $this->getRequestParameter('partner_id', $uiConf->getPartnerId());
if (!$partner_id) {
KExternalErrors::dieError(KExternalErrors::MISSING_PARAMETER, 'partner_id');
}
$widget_id = $this->getRequestParameter("widget_id", '_' . $partner_id);
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? "https" : "http";
$host = myPartnerUtils::getCdnHost($partner_id, $protocol, 'api');
$ui_conf_html5_url = $uiConf->getHtml5Url();
if (kConf::hasMap("optimized_playback")) {
$optimizedPlayback = kConf::getMap("optimized_playback");
if (array_key_exists($partner_id, $optimizedPlayback)) {
// force a specific kdp for the partner
$params = $optimizedPlayback[$partner_id];
if (array_key_exists('html5_url', $params)) {
$ui_conf_html5_url = $params['html5_url'];
}
}
}
$autoEmbed = $this->getRequestParameter('autoembed');
$iframeEmbed = $this->getRequestParameter('iframeembed');
$scriptName = $iframeEmbed ? 'mwEmbedFrame.php' : 'mwEmbedLoader.php';
if ($ui_conf_html5_url && $iframeEmbed) {
$ui_conf_html5_url = str_replace('mwEmbedLoader.php', 'mwEmbedFrame.php', $ui_conf_html5_url);
}
$relativeUrl = true;
// true if ui_conf html5_url is relative (doesnt start with an http prefix)
if (kString::beginsWith($ui_conf_html5_url, "http")) {
$relativeUrl = false;
$url = $ui_conf_html5_url;
// absolute URL
} else {
if (!$iframeEmbed) {
$host = "{$protocol}://" . kConf::get('html5lib_host') . "/";
}
if ($ui_conf_html5_url) {
$url = $host . $ui_conf_html5_url;
} else {
$html5_version = kConf::get('html5_version');
$url = "{$host}/html5/html5lib/{$html5_version}/" . $scriptName;
}
}
// append uiconf_id and partner id for optimizing loading of html5 library. append them only for "standard" urls by looking for the mwEmbedLoader.php/mwEmbedFrame.php suffix
if (kString::endsWith($url, $scriptName)) {
$url .= "/p/{$partner_id}/uiconf_id/{$uiconf_id}";
if (!$autoEmbed) {
$entry_id = $this->getRequestParameter('entry_id');
if ($entry_id) {
$url .= "/entry_id/{$entry_id}";
}
}
}
header("pragma:");
if ($iframeEmbed) {
$url .= (strpos($url, "?") === false ? "?" : "&") . 'wid=' . $widget_id . '&' . $_SERVER["QUERY_STRING"];
} else {
$params = "protocol={$protocol}&" . $_SERVER["QUERY_STRING"];
$url .= (strpos($url, "?") === false ? "?" : "&") . $params;
if ($relativeUrl) {
header('Content-Type: application/javascript');
kFileUtils::dumpUrl($url, true, false, array("X-Forwarded-For" => requestUtils::getRemoteAddress()));
}
}
requestUtils::sendCachingHeaders(60, true, time());
kFile::cacheRedirect($url);
header("Location:{$url}");
KExternalErrors::dieGracefully();
}
示例8: execute
//.........这里部分代码省略.........
if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE) {
$subType = entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA;
}
KalturaLog::debug("get thumbnail filesyncs");
$dataKey = $entry->getSyncKey($subType);
list($file_sync, $local) = kFileSyncUtils::getReadyFileSyncForKey($dataKey, true, false);
$tempThumbPath = null;
$entry_status = $entry->getStatus();
// both 640x480 and 0x0 requests are probably coming from the kdp
// 640x480 - old kdp version requesting thumbnail
// 0x0 - new kdp version requesting the thumbnail of an unready entry
// we need to distinguish between calls from the kdp and calls from a browser: <img src=...>
// that can't handle swf input
if (($width == 640 && $height == 480 || $width == 0 && $height == 0) && ($entry_status == entryStatus::PRECONVERT || $entry_status == entryStatus::IMPORT || $entry_status == entryStatus::ERROR_CONVERTING || $entry_status == entryStatus::DELETED)) {
$contentPath = myContentStorage::getFSContentRootPath();
$msgPath = $contentPath . "content/templates/entry/bigthumbnail/";
if ($entry_status == entryStatus::DELETED) {
$msgPath .= $entry->getModerationStatus() == moderation::MODERATION_STATUS_BLOCK ? "entry_blocked.swf" : "entry_deleted.swf";
} else {
$msgPath .= $entry_status == entryStatus::ERROR_CONVERTING ? "entry_error.swf" : "entry_converting.swf";
}
kFileUtils::dumpFile($msgPath, null, 0);
}
if (!$file_sync) {
$tempThumbPath = $entry->getLocalThumbFilePath($version, $width, $height, $type, $bgcolor, $crop_provider, $quality, $src_x, $src_y, $src_w, $src_h, $vid_sec, $vid_slice, $vid_slices, $density, $stripProfiles, $flavor_id, $file_name);
if (!$tempThumbPath) {
KExternalErrors::dieError(KExternalErrors::MISSING_THUMBNAIL_FILESYNC);
}
}
if (!$local && !$tempThumbPath && $file_sync) {
if (!in_array($file_sync->getDc(), kDataCenterMgr::getDcIds())) {
$remoteUrl = $file_sync->getExternalUrl($entry->getId());
header("Location: {$remoteUrl}");
KExternalErrors::dieGracefully();
}
$remoteUrl = kDataCenterMgr::getRedirectExternalUrl($file_sync, $_SERVER['REQUEST_URI']);
kFileUtils::dumpUrl($remoteUrl);
}
// if we didnt return a template for the player die and dont return the original deleted thumb
if ($entry_status == entryStatus::DELETED) {
KExternalErrors::dieError(KExternalErrors::ENTRY_DELETED_MODERATED);
}
if (!$tempThumbPath) {
try {
$tempThumbPath = myEntryUtils::resizeEntryImage($entry, $version, $width, $height, $type, $bgcolor, $crop_provider, $quality, $src_x, $src_y, $src_w, $src_h, $vid_sec, $vid_slice, $vid_slices, $imageFilePath, $density, $stripProfiles, $thumbParams, $format);
} catch (Exception $ex) {
if ($ex->getCode() != kFileSyncException::FILE_DOES_NOT_EXIST_ON_CURRENT_DC) {
KalturaLog::log("Error - resize image failed");
KExternalErrors::dieError(KExternalErrors::MISSING_THUMBNAIL_FILESYNC);
}
// get original flavor asset
$origFlavorAsset = assetPeer::retrieveOriginalByEntryId($entry_id);
if (!$origFlavorAsset) {
KalturaLog::log("Error - no original flavor for entry [{$entry_id}]");
KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
}
$syncKey = $origFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
$remoteFileSync = kFileSyncUtils::getOriginFileSyncForKey($syncKey, false);
if (!$remoteFileSync) {
// file does not exist on any DC - die
KalturaLog::log("Error - no FileSync for entry [{$entry_id}]");
KExternalErrors::dieError(KExternalErrors::MISSING_THUMBNAIL_FILESYNC);
}
if ($remoteFileSync->getDc() == kDataCenterMgr::getCurrentDcId()) {
KalturaLog::log("ERROR - Trying to redirect to myself - stop here.");
KExternalErrors::dieError(KExternalErrors::MISSING_THUMBNAIL_FILESYNC);
示例9: serveFileToRemoteDataCenter
public static function serveFileToRemoteDataCenter($file_sync, $file_hash, $file_name)
{
$file_sync_id = $file_sync->getId();
KalturaLog::log("File sync id [{$file_sync_id}], file_hash [{$file_hash}], file_name [{$file_name}]");
// TODO - verify security
$current_dc = self::getCurrentDc();
$current_dc_id = $current_dc["id"];
if ($file_sync->getDc() != $current_dc_id) {
$error = "DC[{$current_dc_id}]: FileSync with id [{$file_sync_id}] does not belong to this DC";
KalturaLog::err($error);
KExternalErrors::dieError(KExternalErrors::BAD_QUERY);
}
// resolve if file_sync is link
$file_sync_resolved = $file_sync;
$file_sync_resolved = kFileSyncUtils::resolve($file_sync);
// check if file sync path leads to a file or a directory
$resolvedPath = $file_sync_resolved->getFullPath();
$fileSyncIsDir = is_dir($resolvedPath);
if ($fileSyncIsDir && $file_name) {
$resolvedPath .= '/' . $file_name;
}
if (!file_exists($resolvedPath)) {
$file_name_msg = $file_name ? "file name [{$file_name}] " : '';
$error = "DC[{$current_dc_id}]: Path for fileSync id [{$file_sync_id}] " . $file_name_msg . "does not exist, resolved path [{$resolvedPath}]";
KalturaLog::err($error);
KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND);
}
// validate the hash
$expected_file_hash = md5($current_dc["secret"] . $file_sync_id);
// will be verified on the other side to make sure not some attack or external invalid request
if ($file_hash != $expected_file_hash) {
$error = "DC[{$current_dc_id}]: FileSync with id [{$file_sync_id}] - invalid hash";
KalturaLog::err($error);
KExternalErrors::dieError(KExternalErrors::INVALID_TOKEN);
}
if ($fileSyncIsDir && is_dir($resolvedPath)) {
KalturaLog::log("Serving directory content from [" . $resolvedPath . "]");
$contents = kFile::listDir($resolvedPath);
sort($contents, SORT_STRING);
$contents = serialize($contents);
header("file-sync-type: dir");
echo $contents;
KExternalErrors::dieGracefully();
} else {
KalturaLog::log("Serving file from [" . $resolvedPath . "]");
kFileUtils::dumpFile($resolvedPath);
}
}
示例10: checkForPreview
function checkForPreview(KSecureEntryHelper $securyEntryHelper, $clip_to)
{
$request = $_SERVER["REQUEST_URI"];
$preview_length_msec = $securyEntryHelper->getPreviewLength() * 1000;
if ((int) $clip_to !== (int) $preview_length_msec) {
if (strpos($request, '/clip_to/') !== false) {
if ($preview_length_msec === 0) {
header("Content-Type: video/x-flv");
KExternalErrors::dieGracefully();
}
$request = str_replace('/clip_to/' . $clip_to, '/clip_to/' . $preview_length_msec, $request);
header("Location: {$request}");
} else {
if (strpos($request, "?") !== false) {
$last_slash = strrpos($request, "/");
$request = substr_replace($request, "/clip_to/{$preview_length_msec}", $last_slash, 0);
header("Location: {$request}");
} else {
header("Location: {$request}/clip_to/{$preview_length_msec}");
}
}
KExternalErrors::dieGracefully();
}
}
示例11: execute
/**
* Will forward to the regular swf player according to the widget_id
*/
public function execute()
{
// check if this is a request for the kdp without a wrapper
// in case of an application loading the kdp (e.g. kmc)
$nowrapper = $this->getRequestParameter("nowrapper", false);
// allow caching if either the cache start time (cache_st) parameter
// wasn't specified or if it is past the specified time
$cache_st = $this->getRequestParameter("cache_st");
$allowCache = !$cache_st || $cache_st < time();
$referer = @$_SERVER['HTTP_REFERER'];
$externalInterfaceDisabled = strstr($referer, "bebo.com") === false && strstr($referer, "myspace.com") === false && strstr($referer, "current.com") === false && strstr($referer, "myyearbook.com") === false && strstr($referer, "facebook.com") === false && strstr($referer, "friendster.com") === false ? "" : "&externalInterfaceDisabled=1";
// if there is no wrapper the loader is responsible for setting extra params to the kdp
$noncached_params = "";
if (!$nowrapper) {
$noncached_params = $externalInterfaceDisabled . "&referer=" . urlencode($referer);
}
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? "https" : "http";
$requestKey = $protocol . $_SERVER["REQUEST_URI"];
// check if we cached the redirect url
$cache_redirect = new myCache("kwidget", 10 * 60);
// 10 minutes
$cachedResponse = $cache_redirect->get($requestKey);
if ($allowCache && $cachedResponse) {
header("X-Kaltura:cached-action");
header("Expires: Sun, 19 Nov 2000 08:52:00 GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
header("Location:{$cachedResponse}" . $noncached_params);
KExternalErrors::dieGracefully();
}
// check if we cached the patched swf with flashvars
$cache_swfdata = new myCache("kwidgetswf", 10 * 60);
// 10 minutes
$cachedResponse = $cache_swfdata->get($requestKey);
if ($allowCache && $cachedResponse) {
header("X-Kaltura:cached-action");
requestUtils::sendCdnHeaders("swf", strlen($cachedResponse), 60 * 10, null, true, time());
echo $cachedResponse;
KExternalErrors::dieGracefully();
}
$widget_id = $this->getRequestParameter("wid");
$show_version = $this->getRequestParameter("v");
$debug_kdp = $this->getRequestParameter("debug_kdp", false);
$widget = widgetPeer::retrieveByPK($widget_id);
if (!$widget) {
KExternalErrors::dieGracefully();
}
myPartnerUtils::blockInactivePartner($widget->getPartnerId());
// because of the routing rule - the entry_id & kmedia_type WILL exist. be sure to ignore them if smaller than 0
$kshow_id = $widget->getKshowId();
$entry_id = $widget->getEntryId();
$gallery_widget = !$kshow_id && !$entry_id;
if (!$entry_id) {
$entry_id = -1;
}
if ($widget->getSecurityType() != widget::WIDGET_SECURITY_TYPE_TIMEHASH) {
// try eid - if failed entry_id
$eid = $this->getRequestParameter("eid", $this->getRequestParameter("entry_id"));
// try kid - if failed kshow_id
$kid = $this->getRequestParameter("kid", $this->getRequestParameter("kshow_id"));
if ($eid != null) {
$entry_id = $eid;
} elseif ($kid != null) {
$kshow_id = $kid;
}
}
if ($widget->getSecurityType() == widget::WIDGET_SECURITY_TYPE_MATCH_IP) {
$allowCache = false;
// here we'll attemp to match the ip of the request with that from the customData of the widget
$custom_data = $widget->getCustomData();
$valid_country = false;
if ($custom_data) {
// in this case the custom_data should be of format:
// valid_county_1,valid_country_2,...,valid_country_n;falback_entry_id
$arr = explode(";", $custom_data);
$countries_str = $arr[0];
$fallback_entry_id = isset($arr[1]) ? $arr[1] : null;
$fallback_kshow_id = isset($arr[2]) ? $arr[2] : null;
$current_country = "";
$valid_country = requestUtils::matchIpCountry($countries_str, $current_country);
if (!$valid_country) {
KalturaLog::log("kwidgetAction: Attempting to access widget [{$widget_id}] and entry [{$entry_id}] from country [{$current_country}]. Retrning entry_id: [{$fallback_entry_id}] kshow_id [{$fallback_kshow_id}]");
$entry_id = $fallback_entry_id;
$kshow_id = $fallback_kshow_id;
}
}
} elseif ($widget->getSecurityType() == widget::WIDGET_SECURITY_TYPE_FORCE_KS) {
}
$kmedia_type = -1;
// support either uiconf_id or ui_conf_id
$uiconf_id = $this->getRequestParameter("uiconf_id");
if (!$uiconf_id) {
$uiconf_id = $this->getRequestParameter("ui_conf_id");
}
if ($uiconf_id) {
$widget_type = $uiconf_id;
$uiconf_id_str = "&uiconf_id={$uiconf_id}";
//.........这里部分代码省略.........
示例12: redirectIfRemote
/**
*
* @param $entry
* @param $sub_type
* @param $version
* @return FileSync
*/
private function redirectIfRemote($obj, $sub_type, $version, $strict = true)
{
$dataKey = $obj->getSyncKey($sub_type, $version);
list($file_sync, $local) = kFileSyncUtils::getReadyFileSyncForKey($dataKey, true, false);
if (!$file_sync) {
if ($strict) {
// file does not exist on any DC - die
KalturaLog::log("Error - no FileSync for object [{$obj->getId()}]");
header("HTTP/1.0 404 Not Found");
KExternalErrors::dieGracefully();
} else {
return null;
}
}
return $this->redirectFileSyncIfRemote($file_sync, $local);
}
示例13: dumpFile
private function dumpFile($file_path, $file_name, $limit_file_size = 0)
{
$file_name = str_replace("\n", ' ', $file_name);
$relocate = $this->getRequestParameter("relocate");
$directServe = $this->getRequestParameter("direct_serve");
if (!$relocate) {
$url = $_SERVER["REQUEST_URI"];
if (strpos($url, "?") !== false) {
$url .= "&relocate=";
} else {
$url .= "/relocate/";
}
$url .= kString::stripInvalidUrlChars($file_name);
kFile::cacheRedirect($url);
header("Location: {$url}");
KExternalErrors::dieGracefully();
} else {
if (!$directServe) {
header("Content-Disposition: attachment; filename=\"{$file_name}\"");
}
$mime_type = kFile::mimeType($file_path);
kFileUtils::dumpFile($file_path, $mime_type, null, $limit_file_size);
}
}