Beispiel #1
0
 public function toSecureString()
 {
     list($ksVersion, $secret) = $this->getKSVersionAndSecret($this->partner_id);
     return kSessionBase::generateSession($ksVersion, $secret, $this->user, $this->type, $this->partner_id, $this->valid_until - time(), $this->privileges, $this->master_partner_id, $this->additional_data);
 }
 private static function handleSessionStart(&$params)
 {
     if (!isset($params['service']) || $params['service'] != 'session' || !isset($params['action']) || $params['action'] != 'start' || isset($params['multirequest'])) {
         return;
         // not a stand-alone call to session start
     }
     if (!isset($params['secret']) || !isset($params['partnerId'])) {
         return;
         // missing mandatory params or not admin session
     }
     $format = isset($params['format']) ? $params['format'] : self::RESPONSE_TYPE_XML;
     if ($format != self::RESPONSE_TYPE_XML && $format != self::RESPONSE_TYPE_PHP) {
         return;
         // the format is unsupported at this level
     }
     $type = isset($params['type']) ? $params['type'] : 0;
     if (!in_array($type, array(0, 2))) {
         return;
         // invalid session type
     }
     $type = (int) $type;
     $partnerId = $params['partnerId'];
     $secrets = kSessionBase::getSecretsFromCache($partnerId);
     if (!$secrets) {
         return;
         // can't find the secrets of the partner in the cache
     }
     list($adminSecret, $userSecret, $ksVersion) = $secrets;
     $paramSecret = $params['secret'];
     if ($paramSecret !== $adminSecret && ($type || $paramSecret !== $userSecret)) {
         return;
         // invalid secret
     }
     $startTime = microtime(true);
     $userId = isset($params['userId']) ? $params['userId'] : '';
     $expiry = isset($params['expiry']) ? $params['expiry'] : 86400;
     $privileges = isset($params['privileges']) ? $params['privileges'] : null;
     $result = kSessionBase::generateSession($ksVersion, $adminSecret, $userId, $type, $partnerId, $expiry, $privileges);
     $processingTime = microtime(true) - $startTime;
     $cacheKey = md5("{$partnerId}_{$userId}_{$type}_{$expiry}_{$privileges}");
     header("X-Kaltura:cached-dispatcher,{$cacheKey},{$processingTime}", false);
     if ($format == self::RESPONSE_TYPE_XML) {
         header("Content-Type: text/xml");
         echo "<xml><result>{$result}</result><executionTime>{$processingTime}</executionTime></xml>";
         die;
     } else {
         if ($format == self::RESPONSE_TYPE_PHP) {
             echo serialize($result);
             die;
         }
     }
 }
Beispiel #3
0
 protected static function createLiveReportExportDownloadUrl($partner_id, $file_name, $expiry, $applicationUrlTemplate)
 {
     // Extract simple download name
     $regex = "/^{$partner_id}_Export_[a-zA-Z0-9]+_(?<fileName>[\\w\\-]+.csv)\$/";
     if (!preg_match($regex, $file_name, $matches)) {
         KalturaLog::err("File name doesn't match expected format");
         return null;
     }
     $downloadName = $matches['fileName'];
     // Add dc to enable redirection
     $dc = kDataCenterMgr::getCurrentDc();
     $file_name = $dc['id'] . "_" . $file_name;
     $ksStr = "";
     $partner = PartnerPeer::retrieveByPK($partner_id);
     $secret = $partner->getSecret();
     $privilege = ks::PRIVILEGE_DOWNLOAD . ":" . $file_name;
     $ksStr = kSessionBase::generateSession($partner->getKSVersion(), $partner->getAdminSecret(), null, ks::TYPE_KS, $partner_id, $expiry, $privilege);
     if ($applicationUrlTemplate) {
         $url = str_replace("[ks]", $ksStr, $applicationUrlTemplate);
         $url = str_replace("[id]", $file_name, $url);
     } else {
         //url is built with DC url in order to be directed to the same DC of the saved file
         $url = kDataCenterMgr::getCurrentDcUrl() . "/api_v3/index.php/service/liveReports/action/serveReport/ks/{$ksStr}/id/{$file_name}/{$downloadName}";
     }
     return $url;
 }