public function __construct()
 {
     $this->setIp(requestUtils::getRemoteAddress());
     $this->setReferrer(isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : null);
     $this->setUserAgent(isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null);
     $this->setKs(kCurrentContext::$ks_object ? kCurrentContext::$ks_object : null);
 }
Exemplo n.º 2
0
 /**
  * Set default values and save the new upload token
  */
 public function saveAsNewUploadToken()
 {
     $this->_uploadToken->setStatus(UploadToken::UPLOAD_TOKEN_PENDING);
     $this->_uploadToken->setUploadedFileSize(null);
     $this->_uploadToken->setUploadTempPath(null);
     $this->_uploadToken->setUserIp(requestUtils::getRemoteAddress());
     $this->_uploadToken->setDc(kDataCenterMgr::getCurrentDcId());
     $this->_uploadToken->save();
 }
 private static function notifyProxy($msg)
 {
     $server = kConf::get("image_proxy_url");
     if ($server && requestUtils::getRemoteAddress() != $server) {
         $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
         if ($sock) {
             $secret = kConf::get("image_proxy_secret");
             $port = kConf::get("image_proxy_port");
             $data = md5($secret . $msg) . $msg;
             socket_sendto($sock, $data, strlen($data), 0, $server, $port);
             socket_close($sock);
         }
     }
 }
Exemplo n.º 4
0
 function collectAction(KalturaStatsEvent $event)
 {
     $evenLogFullPath = kConf::get("event_log_file_path");
     // if no file path - do nothing
     if (!$evenLogFullPath) {
         return;
     }
     $http_referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "";
     $users_timestamp = $event->eventTimestamp;
     $eventLine = $event->clientVer . self::SEPARATOR . $event->eventType . self::SEPARATOR . date("Y-m-d H:i:s", time()) . self::SEPARATOR . $event->sessionId . self::SEPARATOR . $event->partnerId . self::SEPARATOR . $event->entryId . self::SEPARATOR . $event->uniqueViewer . self::SEPARATOR . $event->widgetId . self::SEPARATOR . $event->uiconfId . self::SEPARATOR . $event->userId . self::SEPARATOR . $event->currentPoint . self::SEPARATOR . $event->duration . self::SEPARATOR . requestUtils::getRemoteAddress() . self::SEPARATOR . $event->processDuration . self::SEPARATOR . $event->controlId . self::SEPARATOR . $event->seek . self::SEPARATOR . $event->newPoint . self::SEPARATOR . ($event->referrer ? $event->referrer : "") . self::SEPARATOR . $users_timestamp . self::SEPARATOR . PHP_EOL;
     try {
         $res = $this->writeToFile($evenLogFullPath, $eventLine);
         if (!$res) {
             KalturaLog::err("Error while trying to write event to log. Event:\n" . $eventLine);
         }
     } catch (Exception $ex) {
         KalturaLog::err("Error while trying to write event to log. Event:\n" . $eventLine);
     }
     return true;
 }
Exemplo n.º 5
0
 public function dispatch($service, $action, $params = array())
 {
     KalturaLog::debug("Dispatching service [" . $service . "], action [" . $action . "] with params " . print_r($params, true));
     $start = microtime(true);
     // prevent impersonate to partner zero
     $p = isset($params["p"]) && $params["p"] ? $params["p"] : null;
     if (!$p) {
         $p = isset($params["partnerId"]) && $params["partnerId"] ? $params["partnerId"] : null;
     }
     $GLOBALS["partnerId"] = $p;
     // set for logger
     $userId = "";
     $ksStr = isset($params["ks"]) ? $params["ks"] : null;
     if (!$service) {
         throw new KalturaAPIException(KalturaErrors::SERVICE_NOT_SPECIFIED);
     }
     try {
         // load the service reflector
         $reflector = new KalturaServiceReflector($service);
     } catch (Exception $ex) {
         throw new KalturaAPIException(KalturaErrors::SERVICE_DOES_NOT_EXISTS, $service);
     }
     // check if action exists
     if (!$action) {
         throw new KalturaAPIException(KalturaErrors::ACTION_NOT_SPECIFIED, $service);
     }
     if (!$reflector->isActionExists($action)) {
         throw new KalturaAPIException(KalturaErrors::ACTION_DOES_NOT_EXISTS, $action, $service);
     }
     $actionParams = $reflector->getActionParams($action);
     // services.ct - check if partner is allowed to access service ...
     // validate it's ok to access this service
     $deserializer = new KalturaRequestDeserializer($params);
     $arguments = $deserializer->buildActionArguments($actionParams);
     $serviceInstance = $reflector->getServiceInstance();
     kCurrentContext::$host = isset($_SERVER["HOSTNAME"]) ? $_SERVER["HOSTNAME"] : null;
     kCurrentContext::$user_ip = requestUtils::getRemoteAddress();
     kCurrentContext::$ps_vesion = "ps3";
     kCurrentContext::$service = $reflector->getServiceName();
     kCurrentContext::$action = $action;
     kCurrentContext::$client_lang = isset($params['clientTag']) ? $params['clientTag'] : null;
     kCurrentContext::initKsPartnerUser($ksStr, $p, $userId);
     kPermissionManager::init(kConf::get('enable_cache'));
     // initialize the service before invoking the action on it
     $serviceInstance->initService($reflector->getServiceId(), $reflector->getServiceName(), $action);
     $invokeStart = microtime(true);
     KalturaLog::debug("Invoke start");
     $res = $reflector->invoke($action, $arguments);
     KalturaLog::debug("Invoke took - " . (microtime(true) - $invokeStart) . " seconds");
     KalturaLog::debug("Disptach took - " . (microtime(true) - $start) . " seconds");
     $this->clearMemory();
     return $res;
 }
Exemplo n.º 6
0
 public function dispatch($service, $action, $params = array())
 {
     $start = microtime(true);
     // prevent impersonate to partner zero
     $p = isset($params["p"]) && $params["p"] ? $params["p"] : null;
     if (!$p) {
         $p = isset($params["partnerId"]) && $params["partnerId"] ? $params["partnerId"] : null;
     }
     $GLOBALS["partnerId"] = $p;
     // set for logger
     $userId = "";
     $ksStr = isset($params["ks"]) ? $params["ks"] : null;
     if (!$service) {
         throw new KalturaAPIException(KalturaErrors::SERVICE_NOT_SPECIFIED);
     }
     //strtolower on service - map is indexed according to lower-case service IDs
     $service = strtolower($service);
     $serviceActionItem = KalturaServicesMap::retrieveServiceActionItem($service, $action);
     $action = strtolower($action);
     if (!isset($serviceActionItem->actionMap[$action])) {
         KalturaLog::crit("Action does not exist!");
         throw new KalturaAPIException(KalturaErrors::ACTION_DOES_NOT_EXISTS, $action, $service);
     }
     try {
         $actionReflector = new KalturaActionReflector($service, $action, $serviceActionItem->actionMap[$action]);
     } catch (Exception $e) {
         throw new Exception("Could not create action reflector for service [{$service}], action [{$action}]. Received error: " . $e->getMessage());
     }
     $actionParams = $actionReflector->getActionParams();
     $actionInfo = $actionReflector->getActionInfo();
     // services.ct - check if partner is allowed to access service ...
     kCurrentContext::$host = isset($_SERVER["HOSTNAME"]) ? $_SERVER["HOSTNAME"] : gethostname();
     kCurrentContext::$user_ip = requestUtils::getRemoteAddress();
     kCurrentContext::$ps_vesion = "ps3";
     kCurrentContext::$service = $serviceActionItem->serviceInfo->serviceName;
     kCurrentContext::$action = $action;
     kCurrentContext::$client_lang = isset($params['clientTag']) ? $params['clientTag'] : null;
     kCurrentContext::initKsPartnerUser($ksStr, $p, $userId);
     // validate it's ok to access this service
     $deserializer = new KalturaRequestDeserializer($params);
     $this->arguments = $deserializer->buildActionArguments($actionParams);
     KalturaLog::debug("Dispatching service [" . $service . "], action [" . $action . "], reqIndex [" . kCurrentContext::$multiRequest_index . "] with params " . print_r($this->arguments, true));
     $responseProfile = $deserializer->getResponseProfile();
     if ($responseProfile) {
         KalturaLog::debug("Response profile: " . print_r($responseProfile, true));
     }
     kPermissionManager::init(kConf::get('enable_cache'));
     kEntitlementUtils::initEntitlementEnforcement();
     $disableTags = $actionInfo->disableTags;
     if ($disableTags && is_array($disableTags) && count($disableTags)) {
         foreach ($disableTags as $disableTag) {
             KalturaCriterion::disableTag($disableTag);
         }
     }
     if ($actionInfo->validateUserObjectClass && $actionInfo->validateUserIdParamName && isset($actionParams[$actionInfo->validateUserIdParamName])) {
         //			// TODO maybe if missing should throw something, maybe a bone?
         //			if(!isset($actionParams[$actionInfo->validateUserIdParamName]))
         //				throw new KalturaAPIException(KalturaErrors::MISSING_MANDATORY_PARAMETER, $actionInfo->validateUserIdParamName);
         KalturaLog::debug("validateUserIdParamName: " . $actionInfo->validateUserIdParamName);
         $objectId = $params[$actionInfo->validateUserIdParamName];
         $this->validateUser($actionInfo->validateUserObjectClass, $objectId, $actionInfo->validateUserPrivilege, $actionInfo->validateOptions);
     }
     // initialize the service before invoking the action on it
     // action reflector will init the service to maintain the pluginable action transparency
     $actionReflector->initService($responseProfile);
     $invokeStart = microtime(true);
     KalturaLog::debug("Invoke start");
     try {
         $res = $actionReflector->invoke($this->arguments);
     } catch (KalturaAPIException $e) {
         if ($actionInfo->returnType != 'file') {
             throw $e;
         }
         KalturaResponseCacher::adjustApiCacheForException($e);
         $res = new kRendererDieError($e->getCode(), $e->getMessage());
     }
     kEventsManager::flushEvents();
     KalturaLog::debug("Invoke took - " . (microtime(true) - $invokeStart) . " seconds");
     KalturaLog::debug("Dispatch took - " . (microtime(true) - $start) . " seconds, memory: " . memory_get_peak_usage(true));
     return $res;
 }
 private function setServiceConfigFromPartner($partner)
 {
     $service_name = str_replace("Action", "", get_class($this));
     // service name is the class name without the word Action
     if ($partner && $partner->getStatus() == Partner::PARTNER_STATUS_CONTENT_BLOCK) {
         $partner_services_config = $partner->getServiceConfigId();
         $partner->setServiceConfigId(Partner::CONTENT_BLOCK_SERVICE_CONFIG_ID);
         $this->service_config = myPartnerUtils::getServiceConfig($partner);
         $partner->setServiceConfigId($partner_services_config);
     } elseif ($partner && $partner->getStatus() == Partner::PARTNER_STATUS_FULL_BLOCK) {
         $partner_services_config = $partner->getServiceConfigId();
         $partner->setServiceConfigId(Partner::FULL_BLOCK_SERVICE_CONFIG_ID);
         $this->service_config = myPartnerUtils::getServiceConfig($partner);
         $partner->setServiceConfigId($partner_services_config);
     } else {
         $this->service_config = myPartnerUtils::getServiceConfig($partner);
     }
     kCurrentContext::$host = isset($_SERVER["HOSTNAME"]) ? $_SERVER["HOSTNAME"] : gethostname();
     kCurrentContext::$user_ip = requestUtils::getRemoteAddress();
     kCurrentContext::$ps_vesion = "ps2";
     kCurrentContext::$service = "partnerservices2";
     kCurrentContext::$action = $service_name;
     $this->service_config->setServiceName($service_name);
 }
Exemplo n.º 8
0
 public function execute()
 {
     $this->forceSystemAuthentication();
     $secret = "";
     $str = $this->getP("str");
     $algo = $this->getP("algo", "wiki_decode");
     $res = "";
     $key = null;
     if ($algo == "wiki_encode") {
         $res = str_replace(array("|", "/"), array("|01", "|02"), base64_encode(serialize($str)));
     } elseif ($algo == "wiki_decode") {
         $res = @unserialize(base64_decode(str_replace(array("|02", "|01"), array("/", "|"), $str)));
     } elseif ($algo == "wiki_decode_no_serialize") {
         $res = base64_decode(str_replace(array("|02", "|01"), array("/", "|"), $str));
     } elseif ($algo == "base64_encode") {
         $res = base64_encode($str);
     } elseif ($algo == "base64_decode") {
         $res = base64_decode($str);
     } elseif ($algo == "base64_3des_encode") {
         $key = $this->getP("des_key");
         echo "[{$key}]";
         $input = $str;
         $td = mcrypt_module_open('tripledes', '', 'ecb', '');
         $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
         $key = substr($key, 0, mcrypt_enc_get_key_size($td));
         mcrypt_generic_init($td, $key, $iv);
         $encrypted_data = mcrypt_generic($td, $input);
         mcrypt_generic_deinit($td);
         mcrypt_module_close($td);
         $res = base64_encode($encrypted_data);
         $this->des_key = $key;
     } elseif ($algo == "base64_3des_decode") {
         $key = $this->getP("des_key");
         echo "[{$key}]";
         $input = base64_decode($str);
         $td = mcrypt_module_open('tripledes', '', 'ecb', '');
         $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
         $key = substr($key, 0, mcrypt_enc_get_key_size($td));
         mcrypt_generic_init($td, $key, $iv);
         $encrypted_data = mdecrypt_generic($td, $input);
         mcrypt_generic_deinit($td);
         mcrypt_module_close($td);
         $res = $encrypted_data;
         $this->des_key = $key;
     } elseif ($algo == "ks") {
         $ks = ks::fromSecureString($str);
         $res = print_r($ks, true);
         if ($ks != null) {
             $expired = $ks->valid_until;
             $expired_str = self::formatThisData($expired);
             $now = time();
             $now_str = self::formatThisData($now);
             $res .= "<br>" . "valid until: " . $expired_str . "<br>now: {$now} ({$now_str})";
         }
     } elseif ($algo == "kwid") {
         $kwid_str = @base64_decode($str);
         if (!$kwid_str) {
             // invalid string
             return "";
         }
         /*			$kwid = new kwid();
         			list ( $kwid->kshow_id , $kwid->partner_id , $kwid->subp_id ,$kwid->article_name  ,$kwid->widget_id , $kwid->hash  ) =
         				 @explode ( self::KWID_SEPARATOR , $str );
         */
         $cracked = @explode("|", $kwid_str);
         $names = array("kshow_id", "partner_id", "subp_id", "article_name", "widget_id", "hash");
         $combined = array_combine($names, $cracked);
         $secret = $this->getP("secret");
         $md5 = md5($combined["kshow_id"] . $combined["partner_id"] . $combined["subp_id"] . $combined["article_name"] . $combined["widget_id"] . $secret);
         $combined["secret"] = $secret;
         $combined["calculated hash"] = substr($md5, 1, 10);
         $res = print_r($combined, true);
     } elseif ($algo == "ip") {
         $ip_geo = new myIPGeocoder();
         if ($str) {
             $remote_addr = $str;
         } else {
             $remote_addr = requestUtils::getRemoteAddress();
         }
         $res = $ip_geo->iptocountry($remote_addr);
     }
     $this->key = $key;
     $this->secret = $secret;
     $this->str = $str;
     $this->res = $res;
     $this->algo = $algo;
 }
Exemplo n.º 9
0
 /**
  * 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();
 }
Exemplo n.º 10
0
 protected function authKey()
 {
     $ip = requestUtils::getRemoteAddress();
     $hash = kConf::get("system_pages_login_password");
     return sha1($hash . $ip);
 }
Exemplo n.º 11
0
 /**
  * Will forward to the regular swf player according to the widget_id 
  */
 public function execute()
 {
     $uv_cookie = @$_COOKIE['uv'];
     if (strlen($uv_cookie) != 35) {
         $uv_cookie = "uv_" . md5(uniqid(rand(), true));
     }
     setrawcookie('uv', $uv_cookie, time() + 3600 * 24 * 365, '/');
     // 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 = new myCache("kwidget", 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}" . $noncached_params);
         die;
     }
     // 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);
         echo $cachedResponse;
         die;
     }
     $widget_id = $this->getRequestParameter("wid");
     $show_version = $this->getRequestParameter("v");
     $debug_kdp = $this->getRequestParameter("debug_kdp", false);
     $widget = widgetPeer::retrieveByPK($widget_id);
     if (!$widget) {
         die;
     }
     // 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}";
     } else {
         $widget_type = $widget->getUiConfId();
         $uiconf_id_str = "";
     }
     if (empty($widget_type)) {
         $widget_type = 3;
     }
     $kdata = $widget->getCustomData();
     $partner_host = myPartnerUtils::getHost($widget->getPartnerId());
     $partner_cdnHost = myPartnerUtils::getCdnHost($widget->getPartnerId());
     $host = $partner_host;
     if ($widget_type == 10) {
         $swf_url = $host . "/swf/weplay.swf";
     } else {
         $swf_url = $host . "/swf/kplayer.swf";
     }
     $partner_id = $widget->getPartnerId();
     $subp_id = $widget->getSubpId();
     if (!$subp_id) {
         $subp_id = 0;
     }
     $uiConf = uiConfPeer::retrieveByPK($widget_type);
     // new ui_confs which are deleted should stop the script
     // the check for >100000 is for supporting very old mediawiki and such players
     if (!$uiConf && $widget_type > 100000) {
         die;
     }
     if ($uiConf) {
         $ui_conf_swf_url = $uiConf->getSwfUrl();
         if (kString::beginsWith($ui_conf_swf_url, "http")) {
             $swf_url = $ui_conf_swf_url;
             // absolute URL
         } else {
             $use_cdn = $uiConf->getUseCdn();
             $host = $use_cdn ? $partner_cdnHost : $partner_host;
             $swf_url = $host . myPartnerUtils::getUrlForPartner($partner_id, $subp_id) . $ui_conf_swf_url;
         }
         if ($debug_kdp) {
             $swf_url = str_replace("/kdp/", "/kdp_debug/", $swf_url);
         }
     }
     if ($show_version < 0) {
         $show_version = null;
     }
     $ip = requestUtils::getRemoteAddress();
     // to convert back, use long2ip
     // the widget log should change to reflect the new data, but for now - i used $widget_id instead of the widgget_type
     //		WidgetLog::createWidgetLog( $referer , $ip , $kshow_id , $entry_id , $kmedia_type , $widget_id );
     if ($entry_id == -1) {
         $entry_id = null;
     }
     $kdp3 = false;
     $base_wrapper_swf = myContentStorage::getFSFlashRootPath() . "/kdpwrapper/" . kConf::get('kdp_wrapper_version') . "/kdpwrapper.swf";
     $widgetIdStr = "widget_id={$widget_id}";
     $partnerIdStr = "partner_id={$partner_id}&subp_id={$subp_id}";
     if ($uiConf) {
         $ks_flashvars = "";
         $conf_vars = $uiConf->getConfVars();
         if ($conf_vars) {
             $conf_vars = "&" . $conf_vars;
         }
         $wrapper_swf = $base_wrapper_swf;
         $partner = PartnerPeer::retrieveByPK($partner_id);
         if ($partner) {
             $partner_type = $partner->getType();
         }
         if (version_compare($uiConf->getSwfUrlVersion(), "3.0", ">=")) {
             $kdp3 = true;
             // further in the code, $wrapper_swf is being used and not $base_wrapper_swf
             $wrapper_swf = $base_wrapper_swf = myContentStorage::getFSFlashRootPath() . '/kdp3wrapper/' . kConf::get('kdp3_wrapper_version') . '/kdp3wrapper.swf';
             $widgetIdStr = "widgetId={$widget_id}";
             $uiconf_id_str = "&uiConfId={$uiconf_id}";
             $partnerIdStr = "partnerId={$partner_id}&subpId={$subp_id}";
         }
         // if we are loaded without a wrapper (directly in flex)
         // 1. dont create the ks - keep url the same for caching
         // 2. dont patch the uiconf - patching is done only to wrapper anyway
         if ($nowrapper) {
             $dynamic_date = $widgetIdStr . "&host=" . str_replace("http://", "", str_replace("https://", "", $partner_host)) . "&cdnHost=" . str_replace("http://", "", str_replace("https://", "", $partner_cdnHost)) . $uiconf_id_str . $conf_vars;
             $url = "{$swf_url}?{$dynamic_date}";
         } else {
             // if kdp version >= 2.5
             if (version_compare($uiConf->getSwfUrlVersion(), "2.5", ">=")) {
                 // create an anonymous session
                 $ks = "";
                 $result = kSessionUtils::createKSessionNoValidations($partner_id, 0, $ks, 86400, false, "", "view:*");
                 $ks_flashvars = "&{$partnerIdStr}&uid=0&ts=" . microtime(true);
                 if ($widget->getSecurityType() != widget::WIDGET_SECURITY_TYPE_FORCE_KS) {
                     $ks_flashvars = "&ks={$ks}" . $ks_flashvars;
                 }
                 // patch kdpwrapper with getwidget and getuiconf
                 $root = myContentStorage::getFSContentRootPath();
                 $confFile_mtime = $uiConf->getUpdatedAt(null);
                 $new_swf_path = "widget_{$widget_id}_{$widget_type}_{$confFile_mtime}_" . md5($base_wrapper_swf . $swf_url) . ".swf";
                 $md5 = md5($new_swf_path);
                 $new_swf_path = "content/cacheswf/" . substr($md5, 0, 2) . "/" . substr($md5, 2, 2) . "/" . $new_swf_path;
                 $cached_swf = "{$root}/{$new_swf_path}";
                 if (!file_exists($cached_swf) || filemtime($cached_swf) < $confFile_mtime) {
                     kFile::fullMkdir($cached_swf);
                     require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "api_v3" . DIRECTORY_SEPARATOR . "bootstrap.php";
                     $dispatcher = KalturaDispatcher::getInstance();
                     try {
                         $widget_result = $dispatcher->dispatch("widget", "get", array("ks" => $ks, "id" => $widget_id));
                         $ui_conf_result = $dispatcher->dispatch("uiConf", "get", array("ks" => $ks, "id" => $widget_type));
                     } catch (Exception $ex) {
                         die;
                     }
                     $serializer = new KalturaXmlSerializer(false);
                     $serializer->serialize($widget_result);
                     $widget_xml = $serializer->getSerializedData();
                     $serializer = new KalturaXmlSerializer(false);
                     $serializer->serialize($ui_conf_result);
                     $ui_conf_xml = $serializer->getSerializedData();
                     $patcher = new kPatchSwf($root . $base_wrapper_swf);
                     $result = "<xml><result>{$widget_xml}</result><result>{$ui_conf_xml}</result></xml>";
                     $patcher->patch($result, $cached_swf);
                 }
                 if (file_exists($cached_swf)) {
                     $wrapper_swf = $new_swf_path;
                 }
             }
             $kdp_version_2 = strpos($swf_url, "kdp/v2.") > 0;
             if ($partner_host == "http://www.kaltura.com" && !$kdp_version_2 && !$kdp3) {
                 $partner_host = 1;
                 // otherwise the kdp will try going to cdnwww.kaltura.com
             }
             $track_wrapper = '';
             if (kConf::get('track_kdpwrapper') && kConf::get('kdpwrapper_track_url')) {
                 $track_wrapper = "&wrapper_tracker_url=" . urlencode(kConf::get('kdpwrapper_track_url') . "?activation_key=" . kConf::get('kaltura_activation_key') . "&package_version=" . kConf::get('kaltura_version'));
             }
             $dynamic_date = $widgetIdStr . $track_wrapper . "&kdpUrl=" . urlencode($swf_url) . "&host=" . str_replace("http://", "", str_replace("https://", "", $partner_host)) . "&cdnHost=" . str_replace("http://", "", str_replace("https://", "", $partner_cdnHost)) . ($show_version ? "&entryVersion={$show_version}" : "") . ($kshow_id ? "&kshowId={$kshow_id}" : "") . ($entry_id ? "&entryId={$entry_id}" : "") . $uiconf_id_str . $ks_flashvars . ($cache_st ? "&clientTag=cache_st:{$cache_st}" : "") . $conf_vars;
             // for now changed back to $host since kdp version prior to 1.0.15 didnt support loading by external domain kdpwrapper
             $url = $host . myPartnerUtils::getUrlForPartner($partner_id, $subp_id) . "/{$wrapper_swf}?{$dynamic_date}";
             // patch wrapper with flashvars and dump to browser
             if (version_compare($uiConf->getSwfUrlVersion(), "2.6.6", ">=")) {
                 $patcher = new kPatchSwf($root . $wrapper_swf, "KALTURA_FLASHVARS_DATA");
                 ob_start();
                 $patcher->patch($dynamic_date . "&referer=" . urlencode($referer));
                 $wrapper_data = ob_get_contents();
                 ob_end_clean();
                 requestUtils::sendCdnHeaders("swf", strlen($wrapper_data), $allowCache ? 60 * 10 : 0);
                 echo $wrapper_data;
                 if ($allowCache) {
                     $cache_swfdata->put($requestKey, $wrapper_data);
                 }
                 die;
             }
         }
     } else {
         $dynamic_date = "kshowId={$kshow_id}" . "&host=" . requestUtils::getRequestHostId() . ($show_version ? "&entryVersion={$show_version}" : "") . ($entry_id ? "&entryId={$entry_id}" : "") . ($entry_id ? "&KmediaType={$kmedia_type}" : "");
         $dynamic_date .= "&isWidget={$widget_type}&referer=" . urlencode($referer);
         $dynamic_date .= "&kdata={$kdata}";
         $url = "{$swf_url}?{$dynamic_date}";
     }
     // if referer has a query string an IE bug will prevent out flashvars to propagate
     // when nowrapper is true we cant use /swfparams either as there isnt a kdpwrapper
     if (!$nowrapper && $uiConf && version_compare($uiConf->getSwfUrlVersion(), "2.6.6", ">=")) {
         // apart from the /swfparam/ format, add .swf suffix to the end of the stream in case
         // a corporate firewall looks at the file suffix
         $pos = strpos($url, "?");
         $url = substr($url, 0, $pos) . "/swfparams/" . urlencode(substr($url, $pos + 1)) . ".swf";
     }
     if ($allowCache) {
         $cache->put($requestKey, $url);
     }
     if (strpos($url, "/swfparams/") > 0) {
         $url = substr($url, 0, -4) . urlencode($noncached_params) . ".swf";
     } else {
         $url .= $noncached_params;
     }
     $this->redirect($url);
 }
 /**
  * @action getRemoteAddress
  * @return string
  * 
  */
 public function getRemoteAddressAction()
 {
     $remote_addr = requestUtils::getRemoteAddress();
     return $remote_addr;
 }
Exemplo n.º 13
0
$start = microtime(true);
set_time_limit(0);
// check cache before loading anything
require_once __DIR__ . "/../lib/KalturaResponseCacher.php";
$expiry = kConf::hasParam("v3cache_getfeed_default_expiry") ? kConf::get("v3cache_getfeed_default_expiry") : 86400;
$cache = new KalturaResponseCacher(null, kCacheManager::CACHE_TYPE_API_V3_FEED, $expiry);
$cache->checkOrStart();
ob_start();
// Database
DbManager::setConfig(kConf::getDB());
DbManager::initialize();
KalturaLog::debug(">------------------------------------- syndicationFeedRenderer -------------------------------------");
KalturaLog::info("syndicationFeedRenderer-start ");
KalturaLog::debug("getFeed Params [" . print_r(requestUtils::getRequestParams(), true) . "]");
kCurrentContext::$host = isset($_SERVER["HOSTNAME"]) ? $_SERVER["HOSTNAME"] : null;
kCurrentContext::$user_ip = requestUtils::getRemoteAddress();
kCurrentContext::$ps_vesion = "ps3";
$feedId = getRequestParameter('feedId');
$entryId = getRequestParameter('entryId');
$limit = getRequestParameter('limit');
$ks = getRequestParameter('ks');
$feedProcessingKey = "feedProcessing_{$feedId}_{$entryId}_{$limit}";
if (function_exists('apc_fetch')) {
    if (apc_fetch($feedProcessingKey)) {
        KExternalErrors::dieError(KExternalErrors::PROCESSING_FEED_REQUEST);
    }
}
try {
    $syndicationFeedRenderer = new KalturaSyndicationFeedRenderer($feedId, $feedProcessingKey, $ks);
    $syndicationFeedRenderer->addFlavorParamsAttachedFilter();
    kCurrentContext::$partner_id = $syndicationFeedRenderer->syndicationFeed->partnerId;
Exemplo n.º 14
0
 /**
  * @return accessControlScope
  */
 public static function partialInit()
 {
     $scope = new accessControlScope();
     $scope->setIp(requestUtils::getRemoteAddress());
     $scope->setReferrer(isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : null);
     return $scope;
 }