static function extendKs($ks, $expiry = 86400)
 {
     $ksObj = KalturaSession::getKsObject($ks);
     if (!$ksObj) {
         return null;
     }
     $ksObj->valid_until = time() + $expiry;
     return $ksObj->generateKs();
 }
示例#2
0
if (!isset($options['raw']) && !isset($options['curl'])) {
    $params['format'] = '3';
}
# PHP
// renew all ks'es
if (!isset($options['no-renew'])) {
    $renewedSessions = array();
    foreach ($params as $key => &$value) {
        if ($key != 'ks' && !preg_match('/[\\d]+:ks/', $key)) {
            continue;
        }
        if (isset($renewedSessions[$value])) {
            $value = $renewedSessions[$value];
            continue;
        }
        $renewedKs = KalturaSession::extendKs($value);
        if (!$renewedKs) {
            continue;
        }
        $renewedSessions[$value] = $renewedKs;
        $value = $renewedKs;
    }
}
// get the service url
if (isset($options['url']) && is_string($options['url'])) {
    $serviceUrl = $options['url'];
} else {
    $serviceUrl = isset($config['apiHost']) ? $config['apiHost'] : 'www.kaltura.com';
}
if (strpos($serviceUrl, '://') === false) {
    if (isset($options['https'])) {
// parse command line
$options = KalturaCommandLineParser::parseArguments($commandLineSwitches);
$arguments = KalturaCommandLineParser::stripCommandLineSwitches($commandLineSwitches, $argv);
if (!$arguments) {
    $usage = "Usage: generateKs [switches] <partnerId>\nOptions:\n";
    $usage .= KalturaCommandLineParser::getArgumentsUsage($commandLineSwitches);
    die($usage);
}
$partnerId = $arguments[0];
KalturaSecretRepository::init();
$adminSecret = KalturaSecretRepository::getAdminSecret($partnerId);
if (!$adminSecret) {
    die("Failed to get secret for partner {$partnerId}");
}
$type = isset($options['type']) ? $options['type'] : 2;
$user = isset($options['user']) ? $options['user'] : '******';
$expiry = isset($options['expiry']) ? $options['expiry'] : 86400;
$privileges = isset($options['privileges']) ? $options['privileges'] : 'disableentitlement';
if (isset($options['widget'])) {
    $type = 0;
    $user = '******';
    $expiry = 86400;
    $privileges = 'widget:1,view:*';
}
if (!isset($options['bare'])) {
    echo "ks\t";
}
echo KalturaSession::generateKsV1($adminSecret, $user, $type, $partnerId, $expiry, $privileges, null, null);
if (!isset($options['bare'])) {
    echo "\n";
}
示例#4
0
            if ($v == 1) {
                $ret[] = $v . $k;
            }
        }
    }
    $ret = array_slice($ret, 0, 2);
    // don't care about more than 2 levels
    array_splice($ret, count($ret) - 1, 0, 'and');
    return join(' ', $ret);
}
KalturaSecretRepository::init();
if ($argc < 2) {
    die("Usage: extractKs <ks>\n");
}
$ks = $argv[1];
$ksObj = KalturaSession::getKsObject($ks);
if (!$ksObj) {
    die("Failed to parse ks {$ks}\n");
}
echo str_pad('Sig', 20) . $ksObj->hash . "\n";
echo str_pad('Fields', 20) . $ksObj->real_str . "\n";
echo "---\n";
$fieldNames = array('partner_id', 'partner_pattern', 'valid_until', 'type', 'rand', 'user', 'privileges', 'master_partner_id', 'additional_data');
foreach ($fieldNames as $fieldName) {
    echo str_pad($fieldName, 20) . $ksObj->{$fieldName};
    if ($fieldName == 'valid_until') {
        $currentTime = time();
        echo ' = ' . date('Y-m-d H:i:s', $ksObj->valid_until);
        if ($currentTime >= $ksObj->valid_until) {
            echo ' (expired ' . formatTimeInterval($currentTime - $ksObj->valid_until) . ' ago';
        } else {
示例#5
0
// ===================================================================================================
require_once dirname(__FILE__) . '/lib/KalturaCommandLineParser.php';
require_once dirname(__FILE__) . '/lib/KalturaSession.php';
$commandLineSwitches = array(array(KalturaCommandLineParser::SWITCH_NO_VALUE, 'b', 'bare', 'Print only the KS itself'), array(KalturaCommandLineParser::SWITCH_REQUIRES_VALUE, 'e', 'expiry', 'Session expiry (seconds)'));
// parse command line
$options = KalturaCommandLineParser::parseArguments($commandLineSwitches);
$arguments = KalturaCommandLineParser::stripCommandLineSwitches($commandLineSwitches, $argv);
if (!$arguments) {
    $usage = "Usage: renewKs [switches] <ks>\nOptions:\n";
    $usage .= KalturaCommandLineParser::getArgumentsUsage($commandLineSwitches);
    die($usage);
}
$input = $arguments[0];
$ks = $input;
$expiry = isset($options['expiry']) ? $options['expiry'] : 86400;
$patterns = array('/\\/ks\\/([a-zA-Z0-9+_\\-]+=*)/', '/&ks=([a-zA-Z0-9+\\/_\\-]+=*)/', '/\\?ks=([a-zA-Z0-9+\\/_\\-]+=*)/');
foreach ($patterns as $pattern) {
    preg_match_all($pattern, $input, $matches);
    if ($matches[1]) {
        $ks = reset($matches[1]);
        break;
    }
}
KalturaSecretRepository::init();
if (!isset($options['bare'])) {
    echo "ks\t";
}
echo str_replace($ks, KalturaSession::extendKs($ks, $expiry), $input);
if (!isset($options['bare'])) {
    echo "\n";
}