コード例 #1
0
function absPath($inputPath, $baseDir = '.')
{
    // add basedir to inputPath if it's not absolute
    if (!isAbsPath($inputPath)) {
        if (!isAbsPath($baseDir)) {
            // make basedir absolute if it's not already
            $cwd = getcwd();
            if (!isAbsPath($cwd)) {
                die("getcwd() didn't return an absulte path '" . htmlencode($cwd) . "'!");
            }
            $baseDir = absPath($baseDir, $cwd);
        }
        $inputPath = "{$baseDir}/{$inputPath}";
    }
    // remove path prefixes: \\UNC-SERVER or C:
    $uncServerPrefix = '';
    $driveLetterPrefix = '';
    $uncServerRegexp = "|^\\\\\\\\[^\\\\/]+|";
    // matches \\SERVER-NAME UNC style prefixs
    $driveLetterRegexp = "|^[a-z]:(?=[\\\\/])|i";
    // matches W: windows drive letter prefixs
    if (preg_match($uncServerRegexp, $inputPath, $matches)) {
        // match prefix
        $uncServerPrefix = $matches[0];
        $inputPath = preg_replace($uncServerRegexp, '', $inputPath, 1);
        // remove prefix
    } elseif (preg_match($driveLetterRegexp, $inputPath, $matches)) {
        // match prefix
        $driveLetterPrefix = $matches[0];
        $inputPath = preg_replace($driveLetterRegexp, '', $inputPath, 1);
        // remove prefix
    }
    // normalize path components (replace backslashes, remove double-slashes, resolve . and ..)
    $inputPathComponents = preg_split("|[\\\\/]|", $inputPath, null, PREG_SPLIT_NO_EMPTY);
    $outputPathComponents = array();
    foreach ($inputPathComponents as $component) {
        if ($component == '.') {
            /* do nothing */
        } elseif ($component == '..') {
            array_pop($outputPathComponents);
        } else {
            array_push($outputPathComponents, $component);
        }
    }
    $outputPath = implode('/', $outputPathComponents);
    // re-add path prefixes and root slash
    $absPath = $uncServerPrefix . $driveLetterPrefix . '/' . $outputPath;
    //
    return $absPath;
}
コード例 #2
0
function getValidationErrors($label, $value, $rulesString)
{
    $errors = array();
    // parse rules string
    $regexp = "(?<=^|\\s)";
    // zero-width lookbehind for start of string or whitespace
    $regexp .= "(\\!)?";
    // may or may-not countain NOT char
    $regexp .= "(\\w+)";
    // match rule word (eg: notBlank, minLength)
    $regexp .= "(?:\\((.*?)\\))?";
    // match argument in braces (if braces specified)
    $regexp .= "(?=\\s|\$)";
    // zero-width lookahead for whitespace or end of string
    preg_match_all("/{$regexp}/", $rulesString, $rules, PREG_SET_ORDER);
    // process rules
    foreach ($rules as $rule) {
        $matchedString = $rule[0];
        $booleanNot = (bool) $rule[1];
        $ruleName = strtolower($rule[2]);
        $ruleArgs = isset($rule[3]) ? $rule[3] : '';
        //showme(array("Matched String" => $matchedString, "Boolean Not" => $booleanNot, "Rule Name" => $ruleName, "Rule Args" => $ruleArgs)); // debug
        //
        $mb_length = mb_strlen($value);
        ### Modifier Rules Rules
        //*** NOTE: Check lowercase versions of all rule names
        if ($ruleName == 'allowblank') {
            if ($value == '') {
                break;
            }
            // this rule is used in addition to other rules (which may not allow blank be default)
        } elseif ($ruleName == 'notblank') {
            $fail = $value == '';
            if ($fail && !$booleanNot) {
                $errors[] = sprintf(t('\'%1$s\' cannot be blank'), $label);
            }
            _dieAsCaller_onUnsupportedBooleanNot($ruleName, $booleanNot, $rulesString);
        } elseif ($ruleName == 'minlength') {
            $fail = $mb_length < $ruleArgs;
            if ($fail && !$booleanNot) {
                $errors[] = sprintf(t('\'%1$s\' must be at least %2$s characters! (currently %3$s characters)'), $label, $ruleArgs, $mb_length);
            }
            _dieAsCaller_onUnsupportedBooleanNot($ruleName, $booleanNot, $rulesString);
        } elseif ($ruleName == 'maxlength') {
            $fail = $mb_length > $ruleArgs;
            if ($fail && !$booleanNot) {
                $errors[] = sprintf(t('\'%1$s\' cannot be longer than %2$s characters! (currently %3$s characters)'), $label, $ruleArgs, $mb_length);
            }
            _dieAsCaller_onUnsupportedBooleanNot($ruleName, $booleanNot, $rulesString);
        } elseif ($ruleName == 'startsWith') {
            $fail = !startsWith($ruleArgs, $value);
            if ($fail && !$booleanNot) {
                $errors[] = sprintf(t('\'%1$s\' must start with \'%2$s\''), $label, $ruleArgs);
            } elseif (!$fail && $booleanNot) {
                $errors[] = sprintf(t('\'%1$s\' cannot start with \'%2$s\''), $label, $ruleArgs);
            }
        } elseif ($ruleName == 'endsWith') {
            $fail = !endsWith($ruleArgs, $value);
            if ($fail && !$booleanNot) {
                $errors[] = sprintf(t('\'%1$s\' must end with \'%2$s\''), $label, $ruleArgs);
            } elseif (!$fail && $booleanNot) {
                $errors[] = sprintf(t('\'%1$s\' cannot end with \'%2$s\''), $label, $ruleArgs);
            }
        } elseif ($ruleName == 'contains') {
            $fail = !contains($ruleArgs, $value);
            if ($fail && !$booleanNot) {
                $errors[] = sprintf(t('\'%1$s\' must contain \'%2$s\''), $label, $ruleArgs);
            } elseif (!$fail && $booleanNot) {
                $errors[] = sprintf(t('\'%1$s\' cannot contain \'%2$s\''), $label, $ruleArgs);
            }
        } elseif ($ruleName == 'oneof') {
            $allowedValues = preg_split("/\\s*,\\s*/", $ruleArgs);
            $fail = !in_array($value, $allowedValues);
            if ($fail && !$booleanNot) {
                $errors[] = sprintf(t('\'%1$s\' must be one of the following (%2$s)!'), $label, $ruleArgs);
            } elseif (!$fail && $booleanNot) {
                $errors[] = sprintf(t('\'%1$s\' cannot be one of the following (%2$s)!'), $label, $ruleArgs);
            }
        } elseif ($ruleName == 'validemail') {
            $fail = !isValidEmail($value, false);
            if ($fail && !$booleanNot) {
                $errors[] = sprintf(t('\'%1$s\' isn\'t a valid email address (example user@example.com)!'), $label);
            }
            _dieAsCaller_onUnsupportedBooleanNot($ruleName, $booleanNot, $rulesString);
        } elseif ($ruleName == 'validemails') {
            $fail = !isValidEmail($value, true);
            if ($fail && !$booleanNot) {
                $errors[] = sprintf(t('\'%1$s\' isn\'t a valid email address (example user@example.com)!'), $label);
            }
            _dieAsCaller_onUnsupportedBooleanNot($ruleName, $booleanNot, $rulesString);
        } elseif ($ruleName == 'minnumber') {
            $fail = $value < $ruleArgs;
            if ($fail && !$booleanNot) {
                $errors[] = sprintf(t('\'%1$s\' must be equal or greater than %2$s!'), $label, $ruleArgs);
            }
            _dieAsCaller_onUnsupportedBooleanNot($ruleName, $booleanNot, $rulesString);
        } elseif ($ruleName == 'maxnumber') {
            $fail = $value > $ruleArgs;
            if ($fail && !$booleanNot) {
                $errors[] = sprintf(t('\'%1$s\' must be equal or less than %2$s!'), $label, $ruleArgs);
            }
            _dieAsCaller_onUnsupportedBooleanNot($ruleName, $booleanNot, $rulesString);
        } elseif ($ruleName == 'int') {
            $fail = !preg_match("/^-?[0-9]+\$/", $value);
            if ($fail && !$booleanNot) {
                $errors[] = sprintf(t('\'%1$s\' must be a number (only 0-9 and negative numbers are allowed)!'), $label);
            }
            _dieAsCaller_onUnsupportedBooleanNot($ruleName, $booleanNot, $rulesString);
        } elseif ($ruleName == 'positiveint') {
            $fail = !preg_match("/^[0-9]+\$/", $value);
            if ($fail && !$booleanNot) {
                $errors[] = sprintf(t('\'%1$s\' must be a number (only 0-9 are allowed)!'), $label);
            }
            _dieAsCaller_onUnsupportedBooleanNot($ruleName, $booleanNot, $rulesString);
        } elseif ($ruleName == 'pathexists') {
            $fail = !file_exists($value);
            if ($fail && !$booleanNot) {
                $errors[] = sprintf(t('\'%1$s\' doesn\'t exist!'), $label);
            } elseif (!$fail && $booleanNot) {
                $errors[] = sprintf(t('\'%1$s\' already exists!'), $label);
            }
        } elseif ($ruleName == 'relativepath') {
            $fail = isAbsPath($value);
            if ($fail && !$booleanNot) {
                $errors[] = sprintf(t('\'%1$s\' must be an absolute path (starting with / or C:\\)!'), $label);
            } elseif (!$fail && $booleanNot) {
                $errors[] = sprintf(t('\'%1$s\' must be a relative path (cannot start with / or C:\\)!'), $label);
            }
        } elseif ($ruleName == 'absolutepath') {
            $fail = !isAbsPath($value);
            if ($fail && !$booleanNot) {
                $errors[] = sprintf(t('\'%1$s\' must be an absolute path (starting with / or C:\\)!'), $label);
            } elseif (!$fail && $booleanNot) {
                $errors[] = sprintf(t('\'%1$s\' must be a relative path (cannot start with / or C:\\)!'), $label);
            }
        } else {
            dieAsCaller(sprintf(t("Unknown rule '%s' specified!"), $ruleName));
        }
    }
    //
    $errorString = implode("\n", $errors);
    if ($errorString) {
        $errorString .= "\n";
    }
    return $errorString;
}
コード例 #3
0
<?php

/**
 * Retrieve path (taken from cli_dispatch.phpsh)
 */
// Get path to this script
$tempPathThisScript = isset($_SERVER['argv'][0]) ? $_SERVER['argv'][0] : (isset($_ENV['_']) ? $_ENV['_'] : $_SERVER['_']);
// Resolve path
if (!isAbsPath($tempPathThisScript)) {
    $workingDirectory = $_SERVER['PWD'] ? $_SERVER['PWD'] : getcwd();
    if ($workingDirectory) {
        $tempPathThisScript = $workingDirectory . '/' . preg_replace('/\\.\\//', '', $tempPathThisScript);
        if (!@is_file($tempPathThisScript)) {
            die('Relative path found, but an error occured during resolving of the absolute path: ' . $tempPathThisScript . PHP_EOL);
        }
    } else {
        die('Relative path found, but resolving absolute path is not supported on this platform.' . PHP_EOL);
    }
}
$typo3Root = preg_replace('#typo3conf/ext/crawler/cli/bootstrap.php$#', '', $tempPathThisScript);
/**
 * Second parameter is a base64 encoded serialized array of header data
 */
$additionalHeaders = unserialize(base64_decode($_SERVER['argv'][3]));
if (is_array($additionalHeaders)) {
    foreach ($additionalHeaders as $additionalHeader) {
        if (strpos($additionalHeader, ':') !== FALSE) {
            list($key, $value) = explode(':', $additionalHeader, 2);
            $key = str_replace('-', '_', strtoupper(trim($key)));
            if ($key != 'HOST') {
                $_SERVER['HTTP_' . $key] = $value;
コード例 #4
0
saveFile($config, $config_data);
//////////////////////////////////////////////////////////////////////
// Verify no overwrites
//////////////////////////////////////////////////////////////////////
if (!file_exists($users) && !file_exists($projects) && !file_exists($active)) {
    //////////////////////////////////////////////////////////////////
    // Get POST responses
    //////////////////////////////////////////////////////////////////
    $username = cleanUsername("default");
    $password = encryptPassword("default");
    //////////////////////////////////////////////////////////////////
    // Create Projects files
    //////////////////////////////////////////////////////////////////
    $project_path = 'cloud-project';
    $project_name = 'Cloud Project';
    if (!isAbsPath($project_path)) {
        $project_path = str_replace(" ", "_", preg_replace('/[^\\w-\\.]/', '', $project_path));
        mkdir($workspace . "/" . $project_path);
    } else {
        $project_path = cleanPath($project_path);
        if (substr($project_path, -1) == '/') {
            $project_path = substr($project_path, 0, strlen($project_path) - 1);
        }
        if (!file_exists($project_path)) {
            if (!mkdir($project_path . '/', 0755, true)) {
                die("Unable to create Absolute Path");
            }
        } else {
            if (!is_writable($project_path) || !is_readable($project_path)) {
                die("No Read/Write Permission");
            }
コード例 #5
0
function isAbsolutePath($path)
{
    return isAbsPath($path);
}
コード例 #6
0
function backupDatabase($filenameOrPath = '', $selectedTable = '')
{
    global $TABLE_PREFIX;
    $prefixPlaceholder = '#TABLE_PREFIX#_';
    set_time_limit(60 * 5);
    // v2.51 - allow up to 5 minutes to backup/restore database
    session_write_close();
    // v2.51 - End the current session and store session data so locked session data doesn't prevent concurrent access to CMS by user while backup in progress
    // error checking
    if ($selectedTable != '') {
        $schemaTables = getSchemaTables();
        if (preg_match("/[^\\w\\d\\-\\.]/", $selectedTable)) {
            die(__FUNCTION__ . " : \$selectedTable contains invalid chars! " . htmlencode($selectedTable));
        }
        if (!in_array($selectedTable, $schemaTables)) {
            die("Unknown table selected '" . htmlencode($selectedTable) . "'!");
        }
    }
    // open backup file
    $hostname = preg_replace('/[^\\w\\d\\-\\.]/', '', @$_SERVER['HTTP_HOST']);
    if (!$filenameOrPath) {
        $filenameOrPath = "{$hostname}-v{$GLOBALS['APP']['version']}-" . date('Ymd-His');
        if ($selectedTable) {
            $filenameOrPath .= "-{$selectedTable}";
        }
        $filenameOrPath .= ".sql.php";
    }
    $outputFilepath = isAbsPath($filenameOrPath) ? $filenameOrPath : DATA_DIR . "/backups/{$filenameOrPath}";
    // v2.60 if only filename provided, use /data/backup/ as the basedir
    $fp = @fopen($outputFilepath, 'x');
    if (!$fp) {
        // file already exists - avoid race condition
        session_start();
        return false;
    }
    // create no execute php header
    fwrite($fp, "-- <?php die('This is not a program file.'); exit; ?>\n\n");
    # prevent file from being executed
    // get tablenames to backup
    if ($selectedTable) {
        $tablenames = array(getTableNameWithPrefix($selectedTable));
    } else {
        $skippedTables = array('_cron_log', '_error_log', '_outgoing_mail', '_nlb_log');
        // don't backup these table names
        $skippedTables = applyFilters('backupDatabase_skippedTables', $skippedTables);
        // let users skip tables via plugins
        $skippedTables = array_map('getTableNameWithPrefix', $skippedTables);
        // add table_prefix to all table names (if needed)
        $allTables = getMysqlTablesWithPrefix();
        $tablenames = array_diff($allTables, $skippedTables);
        // remove skipped tables from list
    }
    // backup database
    foreach ($tablenames as $unescapedTablename) {
        $escapedTablename = mysql_escape($unescapedTablename);
        $tablenameWithFakePrefix = $prefixPlaceholder . getTableNameWithoutPrefix($escapedTablename);
        // create table
        fwrite($fp, "\n--\n");
        fwrite($fp, "-- Table structure for table `{$tablenameWithFakePrefix}`\n");
        fwrite($fp, "--\n\n");
        fwrite($fp, "DROP TABLE IF EXISTS `{$tablenameWithFakePrefix}`;\n\n");
        $result = mysql_query("SHOW CREATE TABLE `{$escapedTablename}`");
        list(, $createStatement) = mysql_fetch_row($result) or die("MySQL Error: " . htmlencode(mysql_error()));
        $createStatement = str_replace("TABLE `{$TABLE_PREFIX}", "TABLE `{$prefixPlaceholder}", $createStatement);
        fwrite($fp, "{$createStatement};\n\n");
        if (is_resource($result)) {
            mysql_free_result($result);
        }
        // create rows
        fwrite($fp, "\n--\n");
        fwrite($fp, "-- Dumping data for table `{$tablenameWithFakePrefix}`\n");
        fwrite($fp, "--\n\n");
        $result = mysql_query("SELECT * FROM `{$escapedTablename}`") or die("MySQL Error: " . htmlencode(mysql_error()));
        while ($row = mysql_fetch_row($result)) {
            $values = '';
            foreach ($row as $value) {
                if (is_null($value)) {
                    $values .= 'NULL,';
                } else {
                    $values .= '"' . mysql_real_escape_string($value) . '",';
                }
            }
            $values = chop($values, ',');
            // remove trailing comma
            fwrite($fp, "INSERT INTO `{$tablenameWithFakePrefix}` VALUES({$values});\n");
        }
        if (is_resource($result)) {
            mysql_free_result($result);
        }
    }
    //
    fwrite($fp, "\n");
    $result = fwrite($fp, "-- Dump completed on " . date('Y-m-d H:i:s O') . "\n\n");
    if ($result === false) {
        die(__FUNCTION__ . ": Error writing backup file! {$php_errormsg}");
    }
    fclose($fp) || die(__FUNCTION__ . ": Error closing backup file! {$php_errormsg}");
    //
    @session_start();
    // hide error: E_WARNING: session_start(): Cannot send session cache limiter - headers already sent
    return $outputFilepath;
}