Ejemplo n.º 1
0
/**
 * Make sure a link keyword (ie "1fv" as in "site.com/1fv") is valid.
 *
 */
function yourls_sanitize_string($string)
{
    // make a regexp pattern with the shorturl charset, and remove everything but this
    $pattern = yourls_make_regexp_pattern(yourls_get_shorturl_charset());
    $valid = substr(preg_replace('![^' . $pattern . ']!', '', $string), 0, 199);
    return yourls_apply_filter('sanitize_string', $valid, $string);
}
Ejemplo n.º 2
0
function ozh_preview_loader_failed($args)
{
    $request = $args[0];
    $pattern = yourls_make_regexp_pattern(yourls_get_shorturl_charset());
    if (preg_match("@^([{$pattern}]+)" . OZH_PREVIEW_CHAR . "\$@", $request, $matches)) {
        $keyword = isset($matches[1]) ? $matches[1] : '';
        $keyword = yourls_sanitize_keyword($keyword);
        ozh_preview_show($keyword);
        die;
    }
}
Ejemplo n.º 3
0
    echo base64_decode("R0lGODlhEAAQAJECAAAAzFZWzP///wAAACH5BAEAAAIALAAAAAAQABAAAAIplI+py+0PUQAgSGoNQFt0LWTVOE6GuX1H6onTVHaW2tEHnJ1YxPc+UwAAOw==");
    exit;
}
// Handle inexistent root robots.txt requests and exit
if ('/robots.txt' == $_SERVER['REQUEST_URI']) {
    header('Content-Type: text/plain; charset=utf-8');
    echo "User-agent: *\n";
    echo "Disallow:\n";
    exit;
}
// Start YOURLS
require_once dirname(__FILE__) . '/includes/load-yourls.php';
// Get request in YOURLS base (eg in 'http://site.com/yourls/abcd' get 'abdc')
$request = yourls_get_request();
// Make valid regexp pattern from authorized charset in keywords
$pattern = yourls_make_regexp_pattern(yourls_get_shorturl_charset());
// Now load required template and exit
yourls_do_action('pre_load_template', $request);
// At this point, $request is not sanitized. Sanitize in loaded template.
// Redirection:
if (preg_match("@^([{$pattern}]+)/?\$@", $request, $matches)) {
    $keyword = isset($matches[1]) ? $matches[1] : '';
    $keyword = yourls_sanitize_keyword($keyword);
    yourls_do_action('load_template_go', $keyword);
    require_once YOURLS_ABSPATH . '/yourls-go.php';
    exit;
}
// Stats:
if (preg_match("@^([{$pattern}]+)\\+(all)?/?\$@", $request, $matches)) {
    $keyword = isset($matches[1]) ? $matches[1] : '';
    $keyword = yourls_sanitize_keyword($keyword);
Ejemplo n.º 4
0
/**
 * Generate random string of (int)$length length and type $type (see function for details)
 *
 */
function yourls_rnd_string($length = 5, $type = 0, $charlist = '')
{
    $str = '';
    $length = intval($length);
    // define possible characters
    switch ($type) {
        // custom char list, or comply to charset as defined in config
        case '0':
            $possible = $charlist ? $charlist : yourls_get_shorturl_charset();
            break;
            // no vowels to make no offending word, no 0/1/o/l to avoid confusion between letters & digits. Perfect for passwords.
        // no vowels to make no offending word, no 0/1/o/l to avoid confusion between letters & digits. Perfect for passwords.
        case '1':
            $possible = "23456789bcdfghjkmnpqrstvwxyz";
            break;
            // Same, with lower + upper
        // Same, with lower + upper
        case '2':
            $possible = "23456789bcdfghjkmnpqrstvwxyzBCDFGHJKMNPQRSTVWXYZ";
            break;
            // all letters, lowercase
        // all letters, lowercase
        case '3':
            $possible = "abcdefghijklmnopqrstuvwxyz";
            break;
            // all letters, lowercase + uppercase
        // all letters, lowercase + uppercase
        case '4':
            $possible = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
            break;
            // all digits & letters lowercase
        // all digits & letters lowercase
        case '5':
            $possible = "0123456789abcdefghijklmnopqrstuvwxyz";
            break;
            // all digits & letters lowercase + uppercase
        // all digits & letters lowercase + uppercase
        case '6':
            $possible = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
            break;
    }
    $str = substr(str_shuffle($possible), 0, $length);
    return yourls_apply_filter('rnd_string', $str, $length, $type, $charlist);
}