/**
 * Returns the Javascript code and creates the key for hardened trackbacks.
 */
function getTracbackKeyJS($uri, $date)
{
    global $PIVOTX;
    // Abort immediately if hardened trackbacks isn't enabled.
    if ($PIVOTX['config']->get('hardened_trackback') != 1) {
        exit;
    }
    // Get the entry from the DB..
    $entry = $PIVOTX['db']->read_entry($uri, $date);
    // Exit if non-existing ID supplied
    if (empty($entry['code'])) {
        debug('Entry not found');
    } else {
        $id = intval($entry['code']);
    }
    $keydir = $PIVOTX['paths']["db_path"] . "tbkeys/";
    $tburl = $PIVOTX['paths']['host'] . makeFileLink($entry['code'], '', '');
    $trackback = getDefault($PIVOTX['config']->get('localised_trackback_name'), "trackback");
    if ($PIVOTX['config']->get('mod_rewrite') == 0) {
        $tburl .= "&{$trackback}&key=";
    } else {
        $tburl .= "/{$trackback}/?key=";
    }
    if (!strstr($_SERVER["HTTP_REFERER"], $_SERVER["SERVER_NAME"])) {
        // Creating a bogus key
        $tbkey = md5(microtime());
        debug("hardened trackbacks: illegal request - creating bogus key");
    } else {
        makeDir($keydir);
        $tbkey = md5($PIVOTX['config']->get('server_spam_key') . $_SERVER["REMOTE_ADDR"] . $id . time());
        if (!touch($keydir . $tbkey)) {
            debug("hardened trackbacks: directory {$keydir} isn't writable - can't create key");
        } else {
            chmodFile($keydir . $tbkey);
        }
    }
    // Getting the time offset between the web and file server (if there is any)
    $offset = timeDiffWebFile($tbkey_debug);
    // delete keys older than 15 minutes
    $nNow = time();
    $handle = opendir($keydir);
    while (false !== ($file = readdir($handle))) {
        $filepath = $keydir . $file;
        if (!is_dir($filepath) && $file != "index.html") {
            $Diff = $nNow - filectime($filepath);
            if ($Diff > 60 * 15 + $offset) {
                unlink($filepath);
            }
        }
    }
    closedir($handle);
    header('Content-Type: text/javascript');
    echo <<<EOM

function showTBURL_{$entry['code']}(element_id)  {
    var element = document.getElementById(element_id);
    element.innerHTML = '<br />{$tburl}' + '{$tbkey}';
}

function showTBURLgen_{$entry['code']}(element_id, tburl_gen)  {
    var element = document.getElementById(element_id);
    element.innerHTML = tburl_gen;
}

EOM;
    exit;
}
示例#2
0
            fclose($out);
            unlink($_FILES['file']['tmp_name']);
        } else {
            die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
        }
    } else {
        die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}');
    }
} else {
    // Open temp file
    $out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab");
    if ($out) {
        // Read binary input stream and append it to temp file
        $in = fopen("php://input", "rb");
        if ($in) {
            while ($buff = fread($in, 4096)) {
                fwrite($out, $buff);
            }
        } else {
            die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
        }
        fclose($out);
    } else {
        die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
    }
}
// Ensure the uploaded file has the correct file permission.
chmodFile($targetDir . DIRECTORY_SEPARATOR . $fileName);
// FIXME: Add auto_thumbnail
// Return JSON-RPC response
die('{"jsonrpc" : "2.0", "result" : null, "id" : "id"}');
示例#3
0
function processFile($file, $ftp)
{
    global $ftpConfig, $runFiles;
    switch ($file['action']) {
        case 'update':
        case 'run':
            if ($file['type'] == 'directory' && $file['name'] != '') {
                $dirs = explode("/", $file['path'] . '/' . $file['name']);
            } else {
                $dirs = explode("/", $file['path']);
                $dirs = array_slice($dirs, 0, count($dirs) - 1);
            }
            if (count($dirs) > 0) {
                createDirs($dirs, $ftp);
            }
            if ($file['type'] == 'file') {
                putContents($ftpConfig->base . $file['path'] . ($file['path'] != '/' ? '/' : '') . $file['name'], $ftpConfig->source . $file['path'] . ($file['path'] != '/' ? '/' : '') . $file['name'], $ftp);
            }
            chmodFile($ftpConfig->base . $file['path'] . ($file['path'] != '/' ? '/' : '') . $file['name'], $file['mode'], $ftp);
            // Almacenamos el archivo si se debe ejecutar
            if ($file['action'] == 'run' && $file['type'] == 'file') {
                $runFiles[] = $ftpConfig->target . $file['path'] . ($file['path'] != '/' ? '/' : '') . $file['name'];
            }
            break;
        case 'delete':
            if ($file['type'] == 'directory') {
                deleteFTPDir($ftpConfig->base . $file['path'] . ($file['path'] != '/' ? '/' : '') . $file['name'], $ftp);
            } else {
                $ftp->delete($ftpConfig->base . $file['path'] . ($file['path'] != '/' ? '/' : '') . $file['name']);
            }
            break;
    }
}
/**
 * Creates a thumbnail using the GD library.
 *
 * Currently only JPEG and PNG is supported (in the GD library).
 *
 * @param string $imagename
 * @return boolean
 */
function auto_thumbnail($imagename, $folder = '', $action = 'upload', $maxsize = '0')
{
    global $PIVOTX;
    // If we can't create thumbnails locally or we haven't enabled "Automatic Thumbnails",
    // we don't automatically make a thumbnail..
    // Action not Upload --> other function trying to create a thumb so disregard upload_autothumb
    if (!$PIVOTX['image']['local'] || $action == 'upload' && !$PIVOTX['config']->get('upload_autothumb')) {
        return FALSE;
    }
    $ext = strtolower(getExtension($imagename));
    if ($ext == "jpeg") {
        $ext = "jpg";
    }
    $thumbname = makeThumbname(basename($imagename));
    if ($folder == '') {
        $folder = $PIVOTX['paths']['upload_path'];
    }
    $filename = $folder . $imagename;
    $thumbfilename = $folder . $thumbname;
    $width = $PIVOTX['image']['mw'];
    $height = $PIVOTX['image']['mh'];
    // We are current only handling JPEG and PNG.
    if ($ext == "jpg") {
        $src = ImageCreateFromJPEG($filename);
    } elseif ($ext == "png") {
        $src = ImageCreateFromPNG($filename);
    } else {
        debug("Can not auto create thumb for " . basename($filename) . " - unsupported extension.");
        return FALSE;
    }
    list($curwidth, $curheight) = getimagesize($filename);
    // When Fancybox calls and maxsize is specified then maxthumb was specified in FB
    if ($action == 'Fancybox' && $maxsize != '0') {
        if ($curwidth > $curheight) {
            $height = round($curheight * ($maxsize / $curwidth));
            $width = $maxsize;
        } else {
            $width = round($curwidth * ($maxsize / $curheight));
            $height = $maxsize;
        }
    }
    $scale = min($curheight / $height, $curwidth / $width);
    if (function_exists('ImageCreateTrueColor')) {
        $dst = ImageCreateTrueColor($width, $height);
    } else {
        $dst = ImageCreate($width, $height);
    }
    $startx = $width / 2 - $curwidth / 2 / $scale;
    $endx = $width / 2 + $curwidth / 2 / $scale - $startx;
    $starty = $height / 2 - $curheight / 2 / $scale;
    $endy = $height / 2 + $curheight / 2 / $scale - $starty;
    ImageCopyResampled($dst, $src, $startx, $starty, 0, 0, $endx, $endy, $curwidth, $curheight);
    if ($ext == "jpg") {
        ImageJPEG($dst, $thumbfilename, $PIVOTX['image']['qual']);
    } elseif ($ext == "png") {
        ImagePNG($dst, $thumbfilename, $PIVOTX['image']['qual']);
    }
    chmodFile($thumbfilename);
    ImageDestroy($src);
    ImageDestroy($dst);
    return TRUE;
}