示例#1
0
function runCSharpTests($clientRoot)
{
    global $config;
    // upgrade the solution to a new version
    $search = array('Microsoft Visual Studio Solution File, Format Version 10.00', '# Visual C# Express 2008', ' ToolsVersion="3.5" ', '<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>');
    $replace = array('Microsoft Visual Studio Solution File, Format Version ' . $config['csharp']['solution_format_version'], '# ' . $config['csharp']['visual_studio_version'], ' ToolsVersion="' . $config['csharp']['visual_studio_tools_version'] . '" ', '<TargetFrameworkVersion>v' . $config['csharp']['dot_net_framework_version'] . '</TargetFrameworkVersion>');
    replaceInFolder($clientRoot, array('.sln', '.csproj'), null, $search, $replace);
    // clean up
    $exeFile = fixSlashes("{$clientRoot}/KalturaClientTester/bin/Debug/KalturaClientTester.exe");
    if (file_exists($exeFile)) {
        unlink($exeFile);
    }
    // compile
    executeCommandFrom($clientRoot, $config['csharp']['devenv_bin'], "/build Debug KalturaClient.sln");
    // wait for compilation to end
    $startTime = microtime(true);
    while (microtime(true) - $startTime < 30) {
        if (file_exists($exeFile)) {
            break;
        }
        sleep(1);
    }
    if (!file_exists($exeFile)) {
        echo "Error: failed to compile {$exeFile}\n";
        return;
    }
    // run the tests
    executeCommandFrom("{$clientRoot}/KalturaClientTester", $exeFile);
}
function getPluginPathAndUrl($alernateFilename = '', $callerDepth_NO_LONGER_USED_AS_OF_212 = 0)
{
    if ($callerDepth_NO_LONGER_USED_AS_OF_212) {
        dieAsCaller(__FUNCTION__ . "() no longer supports 2nd argument, please update your code!");
    }
    $pluginPath = '';
    $pluginUrl = '';
    foreach (debug_backtrace() as $caller) {
        $callerFilepath = fixSlashes(@$caller['file']);
        if (!preg_match('|/plugins/|', $callerFilepath)) {
            continue;
        }
        // get path and url
        $pluginPath = $callerFilepath;
        $pluginPath = preg_replace("|^.*plugins/(.*?)\$|", '\\1', $pluginPath);
        // eg: myPlugin/myPlugin.php
        $pluginUrl = str_replace(' ', '%20', @$_SERVER['SCRIPT_NAME']);
        // url encoded spaces
        $pluginUrl = preg_replace("|[^/]+\$|", "plugins/{$pluginPath}", $pluginUrl);
        // eg: /myCMS/plugins/myPlugin/myPlugin.php
        // use alternate filename
        if ($alernateFilename) {
            $pluginPath = preg_replace("|[^/]+\$|", $alernateFilename, $pluginPath);
            $pluginUrl = preg_replace("|[^/]+\$|", $alernateFilename, $pluginUrl);
        }
        break;
    }
    // error checking
    if (!$pluginPath) {
        $error = __FUNCTION__ . ": Couldn't find any plugins in caller stack.  This function can only be called by source files under the /plugins/ folder!<br/>\n";
        die($error);
    }
    //
    return array($pluginPath, $pluginUrl);
}
示例#3
0
function _init_fixPhpConfig()
{
    umask(0);
    // use default permission on created files
    ini_set('open_basedir', null);
    // PHP 5.3+ disable open_basedir restrictions (we also set this with php.ini for earlier php versions)
    if (!ini_get('suhosin.memory_limit')) {
        // don't increase memory if suhosin doesn't allow it (or script will die): http://www.hardened-php.net/suhosin/configuration.html#suhosin.memory_limit
        ini_set('memory_limit', '128M');
        // raise memory limit (if allowed)
    }
    ini_set('magic_quotes_runtime', 0);
    // disable magic_quotes_runtime (backslashes quotes in input)
    ini_set('mysql.connect_timeout', 6);
    // PHP default of 60 ties up browser for too long - mysql.connect_timeout may not work on windows
    ini_set('gd.jpeg_ignore_warning', 1);
    // suppress "Warning: imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file" and other GD errors.  See: http://bugs.php.net/bug.php?id=39918
    ini_set('default_charset', 'utf-8');
    //
    if (function_exists('mb_internal_encoding')) {
        // just in-case mbstring isn't loaded
        mb_internal_encoding('utf-8');
        // required for mb_encode_mimeheader() to work properly
    }
    // disable zlib.output_compression so we can output content from register_shutdown_function - http://php.net/manual/en/function.register-shutdown-function.php#72604
    @ini_set('zlib.output_compression', 0);
    // experimental - while (@ob_end_flush()); // disable any and all output buffers (so they don't interfere)
    // this code prevents sending of headers after this line on some servers (headers already sent)- figure out why this triggers internal whitespace plugin detector error
    // Set PHP arg_separator.output value to & so PHP http_build_query() function always works as expected
    ini_set('arg_separator.output', '&');
    // set_include_path - so we can load libraries without full path like this: require_once("/lib/library.php");
    // ... Note that init.php is called from files in different directories so we can't use relative paths
    // ... Note: set_include_path won't work here if host set it in httpd config - see: http://bugs.php.net/bug.php?id=45288#c140023
    // There's a bug in some PHP installs where the follow error is reported intermittently if set_include_path() is called:
    // "Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 268692400 bytes) in Unknown on line 0"
    // The memory amounts vary but they are usually very large.  A workaround is to:
    // - Copy the CMS dir path from: Admin > General Settings > Program Directory
    // - Update php.ini and add the path to the beginning of "include_path" followed by a path separator (either : or ;)
    // - Comment out the lines below:
    $newIncludePath = SCRIPT_DIR . PATH_SEPARATOR;
    // include program dir
    $newIncludePath .= CMS_ASSETS_DIR . '/3rdParty' . PATH_SEPARATOR;
    // include /3rdParty/ dir for libraries that expect themselves to be off the current directory (like Zend)
    //$newIncludePath .= CMS_ASSETS_DIR.'/3rdParty/PEAR' . PATH_SEPARATOR;   // v2.xx - not yet added
    $newIncludePath .= rtrim(get_include_path(), PATH_SEPARATOR);
    // Remove trailing PATH_SEPARATOR (":") - This is good form anyway, but note that a PHP v5.0.4 bug caused trailing PATH_SEPARATOR (":") to check for include()d files in the root ("/") and return errors that it couldn't find it.
    set_include_path($newIncludePath);
    // undo magic_quotes
    // The htscanner extension sets magic_quotes_gpc = 0 but doesn't actually disable magic-quotes so backslashes are still added.  See: http://pecl.php.net/bugs/bug.php?id=10623
    $fixHtscannerBug10623 = extension_loaded('htscanner') && ini_get('htscanner.config_file') == '.htaccess' && get_cfg_var('magic_quotes_gpc');
    // if they fix this in future add version check phpversion('htscanner') < n.nn
    $undoMagicQuotes = @get_magic_quotes_gpc() || $fixHtscannerBug10623;
    if ($undoMagicQuotes) {
        // undo deprecated php magic_quotes feature, see: http://php.net/manual/en/security.magicquotes.php
        $in = array(&$_GET, &$_POST, &$_COOKIE);
        // from: http://www.php.net/manual/en/security.magicquotes.disabling.php
        while (list($k, $v) = each($in)) {
            foreach ($v as $key => $val) {
                if (!is_array($val)) {
                    $in[$k][$key] = stripslashes($val);
                    continue;
                }
                $in[] =& $in[$k][$key];
            }
        }
        unset($in);
    }
    // Set common _SERVER values that are undefined when from from cronjobs and command-line (to prevent warnings) - v2.17
    $_SERVER['SCRIPT_NAME'] = @$_SERVER['SCRIPT_NAME'];
    $_SERVER['HTTP_HOST'] = @$_SERVER['HTTP_HOST'];
    // Fix SCRIPT_NAME and PHP_ SELF (often set incorrectly when PHP is in CGI mode)
    $isCgiMode = PHP_SAPI == 'cgi' || PHP_SAPI == 'cgi-fcgi';
    if ($isCgiMode && @$_SERVER['REQUEST_URI']) {
        list($scriptUri) = explode('?', $_SERVER['REQUEST_URI']);
        // remove query string
        if (@$_SERVER["PATH_INFO"] && @$_SERVER["PATH_INFO"] != $scriptUri) {
            // remove PATH_INFO
            $escapedPathInfo = preg_quote($_SERVER['PATH_INFO'], '/');
            $scriptUri = preg_replace("/{$escapedPathInfo}\$/", '', $scriptUri);
        }
        $_SERVER['SCRIPT_NAME_ORIGINAL'] = @$_SERVER['SCRIPT_NAME'];
        // for debugging - save original value
        $_SERVER['SCRIPT_NAME'] = $scriptUri;
    }
    $_SERVER['PHP_' . 'SELF_ORIGINAL'] = @$_SERVER['PHP_' . 'SELF'];
    // for debugging - save original value
    $_SERVER['PHP_' . 'SELF'] = @$_SERVER['SCRIPT_NAME'];
    // Fix PATH_INFO - CGI PHP sometimes sets pathinfo to PHP_ SELF when it's blank (which causes problems when reading numbers from PATH_INFO in viewer_functions.php
    if (@$_SERVER["PATH_INFO"] == @$_SERVER['PHP_' . 'SELF']) {
        $_SERVER["PATH_INFO_ORIGINAL"] = @$_SERVER["PATH_INFO"];
        $_SERVER["PATH_INFO"] = '';
    }
    // fix DOCUMENT_ROOT - Not set in MS-IIS and often incorrect in Apache virtual hosting configurations
    $validDocRoot = @$_SERVER['DOCUMENT_ROOT'] && @is_dir(@$_SERVER['DOCUMENT_ROOT'] . '/');
    // Add trailing slash so hosts who mis-configured 'open_basedir' with a trailing slash don't get an "not in basedir" error
    if (!$validDocRoot && @$_SERVER['SCRIPT_NAME']) {
        // Note: If SCRIPT_NAME isn't set (such as in PHP CLI) we don't overwrite DOCUMENT_ROOT, since we need it to calculate the path
        list($lastFrame) = array_reverse(debug_backtrace());
        // end(debug_backtrace()) caused: PHP Strict Standards:  Only variables should be passed by reference
        $pathOfCaller = @$lastFrame['file'];
        // filepath of calling script (since path to this lib file might be different)
        $fullFilepath = fixSlashes(coalesce($pathOfCaller, __FILE__));
        // eg: C:/wamp/www/application/admin.php - path of script that included us, or path of this file if no caller
        $search = fixSlashes($_SERVER['SCRIPT_NAME']);
        // eg:            /application/admin.php
        $webroot = str_replace($search, '', $fullFilepath);
        // eg: C:/wamp/www
        if (@is_dir("{$webroot}/")) {
            // add trailing slash so hosts who mis-configured 'open_basedir' with a trailing slash don't get an "not in basedir" error
            $_SERVER['DOCUMENT_ROOT_ORIGINAL'] = @$_SERVER['DOCUMENT_ROOT'];
            // for debugging - save original value
            $_SERVER['DOCUMENT_ROOT'] = $webroot;
        }
    }
    // define HTTP_REFERER
    if (!array_key_exists('HTTP_REFERER', $_SERVER)) {
        $_SERVER['HTTP_REFERER'] = '';
    }
}
示例#4
0
function realUrl($targetUrl, $baseUrl = null)
{
    if (isAbsoluteUrl($targetUrl)) {
        return $targetUrl;
    }
    ### get baseUrl
    if (!$baseUrl) {
        // default baseUrl to currently running web script
        $baseUrl = isHTTPS() ? 'https://' : 'http://';
        $baseUrl .= coalesce(@$_SERVER['HTTP_HOST'], parse_url(@$GLOBALS['SETTINGS']['adminUrl'], PHP_URL_HOST));
        $baseUrl .= inCLI() ? '/' : $_SERVER['SCRIPT_NAME'];
        // SCRIPT_NAME has filepath not web path for command line scripts so just set to /
        $baseUrl = str_replace(' ', '%20', $baseUrl);
    }
    if (!isAbsoluteUrl($baseUrl)) {
        $baseUrl = realUrl($baseUrl);
    }
    // make sure supplied $baseUrl is absolute. if it's not, make it so, relative to currently running script
    // parse baseurl into parts
    $baseUrlParts = parse_url($baseUrl);
    $baseUrlDomain = $baseUrlParts['scheme'] . '://';
    // figure out $baseUrlDomain (e.g. http://domain)
    if (@$baseUrlParts['user']) {
        $baseUrlDomain .= $baseUrlParts['user'];
        if (@$baseUrlParts['pass']) {
            $baseUrlDomain .= ':' . $baseUrlParts['pass'];
        }
        $baseUrlDomain .= '@';
    }
    $baseUrlDomain .= $baseUrlParts['host'];
    if (@$baseUrlParts['port']) {
        $baseUrlDomain .= ':' . $baseUrlParts['port'];
    }
    // if no target,  nothing specified for target, use baseUrl
    if ($targetUrl == '') {
        $absoluteUrl = $baseUrl;
    } elseif (strpos($targetUrl, '/') === 0) {
        $absoluteUrl = $baseUrlDomain . $targetUrl;
    } else {
        if (strpos($targetUrl, '?') === 0) {
            $absoluteUrl = $baseUrlDomain . $baseUrlParts['path'] . $targetUrl;
        } else {
            if (strpos($targetUrl, '#') === 0) {
                $absoluteUrl = $baseUrlDomain . $baseUrlParts['path'];
                if (@$baseUrlParts['query']) {
                    $absoluteUrl .= '?' . $baseUrlParts['query'];
                }
                $absoluteUrl = $absoluteUrl . $targetUrl;
            } else {
                $basePath = $baseUrlParts['path'];
                if (!$basePath) {
                    trigger_error("Error getting path from realUrl('{$targetUrl}', '{$baseUrl}')!\n");
                }
                // v2.62 - if basepath is webroot ("/") or webroot file ("/example.php") then remote all parent references (../) from targetUrl
                $isPathRootDir = in_array(dirname($baseUrlParts['path']), array('\\', '/'));
                if ($isPathRootDir) {
                    $targetUrl = preg_replace("|(\\.\\./)+|", '', $targetUrl);
                }
                // if the baseUrl includes a file (e.g. 'dir/admin.php'), strip it (e.g. 'dir/')
                if (!endsWith('/', $basePath)) {
                    $basePath = dirname($basePath) . '/';
                    $basePath = fixSlashes($basePath);
                    // root paths return / only, so prevent // (or \/ on windows) from the above code
                }
                $absoluteUrl = $baseUrlDomain . $basePath . $targetUrl;
            }
        }
    }
    // collapse "dir/../"s
    $madeReplacement = true;
    while ($madeReplacement) {
        // keep making replacements until we can't anymore
        $absoluteUrl = preg_replace('@[^/]+/\\.\\./@', '', $absoluteUrl, 1, $madeReplacement);
    }
    // collapse "/./"s
    $absoluteUrl = preg_replace('@/\\./@', '/', $absoluteUrl, -1);
    // url encode spaces
    $absoluteUrl = str_replace(' ', '%20', $absoluteUrl);
    // url encoded spaces
    return $absoluteUrl;
}
示例#5
0
<?php

require_once __DIR__ . '/utils.php';
if ($argc < 3) {
    die("Usage:\n\tphp " . basename(__FILE__) . " <clients name> <target dir>\n");
}
$clientsName = $argv[1];
$targetDir = fixSlashes($argv[2]);
if (!is_dir($targetDir)) {
    mkdir($targetDir, 0777, true);
}
$config = parse_ini_file(dirname(__FILE__) . '/config.ini', true);
$serverName = $config['general']['server_name'];
$summary = file_get_contents("http://{$serverName}/{$clientsName}/summary.kinf");
$summary = unserialize($summary);
$generatedDate = $summary['generatedDate'];
foreach ($summary as $name => $params) {
    if (!is_array($params)) {
        continue;
    }
    $fileName = "{$name}_{$generatedDate}.tar.gz";
    $fileUrl = "http://{$serverName}/{$clientsName}/{$fileName}";
    $localPath = "{$targetDir}/{$fileName}";
    echo "Downloading {$fileUrl} to {$localPath}\n";
    $clientTarGz = file_get_contents($fileUrl);
    file_put_contents($localPath, $clientTarGz);
}
function _languageFiles_getDirs()
{
    $source = 'auto';
    // possible future optimization to avoid checking all language files on every lookup.  Add $source parameter to function (auto, 'default', 'admin', $pluginDirPath)
    # PHP Bugfix: Disable directory detection with debug_backtrace() for buggy PHP versions until we can increase minimum PHP version required
    # debug_backtrace() causes segmentation fault and/or memory issues - https://bugs.php.net/bug.php?id=51552
    # Fixed in PHP 5.2.14 and and 5.3.3 respectively - http://php.net/ChangeLog-5.php
    static $isBuggyPHP;
    if (!isset($isBuggyPHP)) {
        // cache result so we're not checking version on every call
        $buggy52branch = version_compare(phpversion(), '5.2.14', '<');
        // any PHP less then 5.2.14
        $buggy53branch = version_compare(phpversion(), '5.3.0', '>=') && version_compare(phpversion(), '5.3.3', '<');
        // PHP 5.3.0 to PHP 5.3.2
        $isBuggyPHP = $buggy52branch || $buggy53branch;
    }
    // get calling plugin language dir (if being called by a plugin)
    $pluginLangDir = '';
    if (!$isBuggyPHP && !in_array($source, array('default', 'admin'))) {
        $callerFilepaths = array_map('fixSlashes', array_unique(array_pluck(debug_backtrace(), 'file')));
        $pluginDir = fixSlashes(SCRIPT_DIR . '/plugins/');
        $pluginDirRegexp = '/^' . preg_quote($pluginDir, '/') . '/';
        $pluginPath = array_value(array_values(preg_grep($pluginDirRegexp, $callerFilepaths)), 0);
        $pluginLangDir = $pluginPath ? fixSlashes(dirname($pluginPath) . '/languages') : '';
    }
    // get other language dirs
    static $defaultLangDir, $adminLangDir;
    if (!isset($defaultLangDir)) {
        $defaultLangDir = SCRIPT_DIR . "/lib/languages";
    }
    if (!isset($adminLangDir)) {
        $adminLangDir = SCRIPT_DIR . "/lib/languages/adminMenu";
    }
    //
    return array($defaultLangDir, $adminLangDir, $pluginLangDir);
}
<?php

require_once __DIR__ . '/utils.php';
if ($argc < 2) {
    die("Usage:\n\tphp " . basename(__FILE__) . " <root dir>\n");
}
$rootDir = fixSlashes($argv[1]);
$config = parse_ini_file(dirname(__FILE__) . '/config.ini', true);
$search = array('@YOUR_PARTNER_ID@', '@YOUR_USER_SECRET@', '@YOUR_ADMIN_SECRET@', '@SERVICE_URL@');
$replace = array($config['general']['partner_id'], $config['general']['user_secret'], $config['general']['admin_secret'], $config['general']['service_url']);
replaceInFolder($rootDir, null, array('.tar.gz', 'configureTestPartner.php'), $search, $replace, '.template', '');