Пример #1
0
 /**
  * Constructor. Init all variables.
  *
  * @param array $options
  *
  * @access public
  */
 function System_SharedMemory_Shmop($options)
 {
     $this->_options = $this->_default($options, array('size' => 1048576, 'tmp' => get_tmp_dir(), 'project' => 's'));
     $this->_h = $this->_ftok($this->_options['project']);
 }
Пример #2
0
 /**
  * Constructor. Init all variables.
  *
  * @param array $options
  *
  * @access public
  */
 function __construct($options)
 {
     $this->_options = $this->_default($options, array('tmp' => get_tmp_dir()));
     $this->_connected = is_writeable($this->_options['tmp']) && is_dir($this->_options['tmp']);
 }
Пример #3
0
$f=clean($_GET['file']);

//ob_start();

if(@$_GET['size']=='small' || !empty($_GET['info'])) list($w,$h)=array(160,120);
else if(@$_GET['size']=='normal') list($w,$h)=array(220,220);
else if(@$_GET['size']=='big') list($w,$h)=array(620,460);
else die();

$ret = -1;

setreadable($f, true);

if(preg_match('/Darwin/is', PHP_OS))
{
	$cmd = ROOT.'/full/thumbnailer '.escapeshellarg(abs_path($f)).' '.escapeshellarg($pr = get_tmp_dir().'/'.uniqid(rand()).'.jpg').' '.$w.' '.$h;
	
	//echo $cmd."<bR>";
	
	/* Code specially for MAMP, which spoils some environment variables... */
	
	putenv("DYLD_LIBRARY_PATH=");
	
	exec($cmd, $out, $ret);
	
	if($ret == 0)
	{
		header('content-type: image/jpeg');
		
		readfile($pr);
		
Пример #4
0
function d_filelist_cached($dir, $start, $length, $filter = '')
{
    //sleep(1);
    $tmpdir = is_callable('get_tmp_dir') ? get_tmp_dir() : '/tmp';
    $cache_prefix = $tmpdir . '/dolphin' . md5(__FILE__);
    $cache_dat = $cache_prefix . '.dat';
    $cache_idx = $cache_prefix . '.idx';
    $new = false;
    if (!file_exists($cache_dat) || filemtime($dir) > filemtime($cache_dat)) {
        $new = true;
        $fp = fopen($cache_dat, 'w+b');
        $ifp = fopen($cache_idx, 'w+b');
    } else {
        $fp = fopen($cache_dat, 'r+b');
        $ifp = fopen($cache_idx, 'r+b');
        list(, $l) = unpack('n', fread($fp, 2));
        $cached_dir = fread($fp, $l);
        list(, $l) = unpack('n', fread($fp, 2));
        $cached_filter = fread($fp, $l);
        if ($cached_dir != $dir || $cached_filter != $filter) {
            ftruncate($fp, 0);
            ftruncate($ifp, 0);
            fseek($fp, 0, SEEK_SET);
            fseek($ifp, 0, SEEK_SET);
            $new = true;
        }
    }
    $items = array();
    $cnt = 0;
    $old_cwd = getcwd();
    try {
        if (!@chdir($dir)) {
            throw new Exception('Could not chdir to the folder');
        }
        if ($new) {
            fwrite($fp, pack('n', strlen($dir)) . $dir);
            fwrite($fp, pack('n', strlen($filter)) . $filter);
            $pos = ftell($fp);
            $dh = opendir('.');
            if (!$dh) {
                throw new Exception('Could not open directory for reading');
            }
            $filter = strtolower($filter);
            while (false !== ($f = readdir($dh))) {
                if ($f == '.' || $f == '..') {
                    continue;
                }
                if (strlen($filter) && !substr_count(strtolower($f), $filter)) {
                    continue;
                }
                fwrite($ifp, pack('NN', $pos, strlen($f)));
                fwrite($fp, $f);
                $pos += strlen($f);
                // ftell is not as fast as it should be, sadly
            }
            fflush($ifp);
            fflush($fp);
        }
        fseek($ifp, $start * 8);
        $first = true;
        $curr_idx = $start;
        while ($curr_idx < $start + $length) {
            list(, $pos, $l) = unpack('N2', fread($ifp, 8));
            if ($first) {
                fseek($fp, $pos);
                $first = false;
            }
            $f = fread($fp, $l);
            if (!strlen($f)) {
                break;
            }
            if (strlen($f) != $l) {
                throw new Exception('Consistency error');
            }
            $items[$curr_idx++] = array('name' => $f, 'size' => filesize($f), 'is_dir' => is_dir($f));
        }
        $cnt = filesize($cache_idx) / 8;
    } catch (Exception $e) {
        fclose($fp);
        fclose($ifp);
        unlink($cache_dat);
        unlink($cache_idx);
        @chdir($old_cwd);
        return is_callable('d_error') ? d_error($e->getMessage()) : false;
    }
    if ($cnt < 500 && $length >= 500) {
        usort($items, 'd_filelist_cached_usort_cmp');
    }
    @chdir($old_cwd);
    return array('items' => $items, 'cnt' => $cnt);
}
Пример #5
0
$MAX_RECURSION = 6;
$dir_list = array($R['WEB_ROOT']);
$R['WRITEABLE_WEBDIR'] = '';
for ($recursion = 1; $recursion <= $MAX_RECURSION; $recursion++) {
    foreach ($dir_list as $dir) {
        if (dirAccess($dir, 'w')) {
            $R['WRITEABLE_WEBDIR'] = @realpath($dir);
            break 2;
        }
    }
    if ($recursion == $MAX_RECURSION) {
        break;
    }
    $parent_dir_list = $dir_list;
    $dir_list = array();
    foreach ($parent_dir_list as $dir) {
        if ($h = @opendir($dir)) {
            while (($elem = readdir($h)) !== FALSE) {
                if ($elem != '.' && $elem != '..') {
                    if ((@fileperms($dir . '/' . $elem) & 0x4000) == 0x4000) {
                        $dir_list[] = $dir . '/' . $elem;
                    }
                }
            }
            closedir($h);
        }
    }
}
$tmp = get_tmp_dir();
$R['WRITEABLE_TMPDIR'] = dirAccess($tmp, 'w') ? $tmp : $R['WRITEABLE_WEBDIR'];
return $R;
Пример #6
0
function saveOds($obj, $file)
{
    $charset = ini_get('default_charset');
    ini_set('default_charset', 'UTF-8');
    $tmp = get_tmp_dir();
    $uid = uniqid();
    mkdir($tmp . '/' . $uid);
    file_put_contents($tmp . '/' . $uid . '/content.xml', $obj->array2ods());
    file_put_contents($tmp . '/' . $uid . '/mimetype', 'application/vnd.oasis.opendocument.spreadsheet');
    file_put_contents($tmp . '/' . $uid . '/meta.xml', $obj->getMeta('es-ES'));
    file_put_contents($tmp . '/' . $uid . '/styles.xml', $obj->getStyle());
    file_put_contents($tmp . '/' . $uid . '/settings.xml', $obj->getSettings());
    mkdir($tmp . '/' . $uid . '/META-INF/');
    mkdir($tmp . '/' . $uid . '/Configurations2/');
    mkdir($tmp . '/' . $uid . '/Configurations2/acceleator/');
    mkdir($tmp . '/' . $uid . '/Configurations2/images/');
    mkdir($tmp . '/' . $uid . '/Configurations2/popupmenu/');
    mkdir($tmp . '/' . $uid . '/Configurations2/statusbar/');
    mkdir($tmp . '/' . $uid . '/Configurations2/floater/');
    mkdir($tmp . '/' . $uid . '/Configurations2/menubar/');
    mkdir($tmp . '/' . $uid . '/Configurations2/progressbar/');
    mkdir($tmp . '/' . $uid . '/Configurations2/toolbar/');
    file_put_contents($tmp . '/' . $uid . '/META-INF/manifest.xml', $obj->getManifest());
    shell_exec('cd ' . $tmp . '/' . $uid . ';zip -r ' . escapeshellarg($file) . ' ./');
    ini_set('default_charset', $charset);
}
Пример #7
0
         if ($style->short_name === "default") {
             $default_style = $style;
             break;
         }
     }
     // Convert the document using the default styling.
     $converted_bytes = $bookflow->convert($format, $default_style, "test");
     // Save the converted document.
     $tmpfname = $bookflow->id . "." . $format;
     if (file_put_contents($tmpdname . DIRECTORY_SEPARATOR . $tmpfname, $converted_bytes) === FALSE) {
         // throw new BookalopeException("Failed to write converted document.");
         error_log("Error writing generated " . $format . " file, skipping.");
     }
 }
 // Zip all generated files into an archive for download.
 $zipfname = get_tmp_dir() . DIRECTORY_SEPARATOR . $bookflow->id . ".zip";
 $zip = new ZipArchive();
 $zip->open($zipfname, ZipArchive::CREATE);
 foreach (glob($tmpdname . DIRECTORY_SEPARATOR . $bookflow->id . ".*") as $fname) {
     $zip->addFile($fname, basename($fname));
 }
 // $zip->addGlob($tmpdname . DIRECTORY_SEPARATOR . $bookflow->id . ".*", 0, array("remove_all_path" => TRUE));
 $zip->close();
 // Remove the temporary folder. (Assumes the 'rm' command.)
 system("rm -rf " . escapeshellarg($tmpdname));
 // Delete the book and all of its bookflows.
 error_log("Deleting book and all bookflows...");
 $book->delete();
 // Return the archive as a response.
 // http_response_code(200);
 header("HTTP/1.1 200 OK");
Пример #8
0
 /**
  * Constructor. Init all variables.
  *
  * @param array $options
  *
  * @access public
  */
 function System_SharedMemory_File($options)
 {
     $this->_options = $this->_default($options, array('tmp' => get_tmp_dir()));
     $this->_connected = is_writeable($this->_options['tmp']) && is_dir($this->_options['tmp']);
 }
Пример #9
0
function _tmpname()
{
	if(!$tdir = get_tmp_dir()) return false;
	$fname = $tdir.'/ftp_'.uniqid(rand()).'.dolphin'; // temporal file name
	register_shutdown_function(create_function('','unlink(base64_decode("'.base64_encode($fname).'"));'));
	
	return $fname;
}
Пример #10
0
/**
 * update_dolphin is a system function for Dolphin.php . You need to specify the function to print errors, if they happen. update_dolphin requires $_REQUEST['act'] to be set to 'upload-new' or 'download-new', and returns NEED_UPLOAD if it needs to show the upload form (it happens if it cannot download the archive from site). The upload form must contain an input field with name "files[]". If all is ok, returns TRUE, otherwise returns string, containing error description or special NEED_UPLOAD. You need to check for TRUE using === operator.
 *
 * @param string $print_err_func
 * @return mixed
 */
function update_dolphin($print_err_func)
{
	if(IS_DEVELOPER) return 'This operation is not permitted for you';
	
	ini_set('display_errors', 'On');
		
	/* disable attempts to download the archive with Dolphin.php by itself */
	if(!CAN_SELFUPDATE) $_REQUEST['act'] = 'upload-new';

	$tmp  =get_tmp_dir();
	if(!$tmp) return 'No suitable temp directory found';
	$tmp = abs_path($tmp);
	$root = abs_path(ROOT);
			
	if(!$tmp || $tmp == $root || substr($tmp, 0, strlen($root)) == $root)
	{
		/* TODO: write normal answer if $tmp is ROOT or subdirectory of ROOT */
		return 'Update is impossible. '.reason();
	}
	
	chdir($tmp);
	
	if(empty($_FILES['files']) && $_REQUEST['act']!='download-new')
	{
		return NEED_UPLOAD;
	}
	
	if($_REQUEST['act']!='download-new') upload_files($tmp);
	else
	{
		$build = file_get_contents(MASTER_SITE.'files/dolphin-build.txt');
		
		$errtext = 'It seems that your server does not allow outgoing connections for PHP scripts, or '.MASTER_SITE.' is down. Try to upload archive with '.SNAME.' manually.';
		
		if(!$build) return NEED_UPLOAD;
		
		if(BUILD >= $build) return 'Your build is up-to-date';
		
		$dolphin = file_get_contents(MASTER_SITE.'files/dolphin-current.zip');
		
		if(!$dolphin) return NEED_UPLOAD;
		
		if(!d_file_put_contents($tmp.'/dolphin-current.zip', $dolphin)) return 'Cannot write '.show_file($tmp.'/dolphin-current.zip','file').' ('.$tmp.'/dolphin-current.zip).'.reason();
	}
	
	$f = $tmp.'/dolphin-current.zip';
	if(!file_exists($f)) return '<b>dolphin-current.zip</b> was not found';
	d_copy(ROOT.'/config.php',$cfg_old=$tmp.'/dolphin_config.php');
	
	require_once(ROOT.'/system/libs/pclzip.php');

	umask(0);
	/* note, that we check if extracting is possible _before_ deleting ROOT */
	$e=new PclZip($f);
	
	//echo '<!--';
	//echo 'file: '.$f.'<br>';
	
	// some hosters require PHP files and folders with PHP scripts to have special rights, so we need to
	// save rights for some essensial files
	
	$tochmod = array('','system','index.php','system/download.php','system/preview.php');
	$rights = array();
	foreach($tochmod as $v) $rights[ROOT.'/'.$v] = get_rights(ROOT.'/'.$v);
	
	d_remove(ROOT);
	//echo 'Removed ROOT.<br>';
	d_mkdir(ROOT,777);
	setwritable(ROOT);
	//echo 'Created ROOT.<br>';
	//echo 'ROOT is writable: '.(is_writable(ROOT) ? 'true' : 'false').'<br>';
	chdir(ROOT);
	//echo 'Changed directory to ROOT.<br>';
	//echo '-->';
	
	if(!$e->extract('.')) return '<b>dolphin-current.zip</b> could not be extracted. Upload the new version <b>via FTP</b>. Here are the contents of your <b>config.php</b>:<pre>'.htmlspecialchars(d_file_get_contents($cfg_old)).'</pre>';
	
	foreach($rights as $k=>$v) d_chmod($k,$v);
	
	if(!empty($_POST['save-login']) || $_REQUEST['act']=='download-new')
	{	
		/* delete BUILD, VERSION and NAME from config.php, they are now in core.php for compatibilty */
		$conf = d_file_get_contents($cfg_old);
		$conf = preg_replace('/define\\(\'(BUILD|VERSION|NAME)\'.*\\)\\;/sU','',$conf);
		d_file_put_contents(ROOT.'/config.php', $conf);
		
		$core = d_file_get_contents(ROOT.'/system/core.php');
		if(!$core)
		{
			$build = "undefined";
		}else
		{
			preg_match("/define\\('BUILD'\\,([0-9]+)\\)/is", $core, $m);
			$build = $m[1];
		}
		
		//echo '<!--Writing new information about build: '.$build.' and '.$version.'<br>-->';
	}
	
	d_unlink($f);
	//echo '<!-- Deleting archive<br> -->';
	
	if($build!='undefined' && $build > BUILD)
	{
		d_unlink($cfg_old);
		return true;
	}
	
	return 'Update did not complete successfully. Please upload the new version <b>via FTP</b>. Here are the contents of your previous <b>config.php</b>:<pre>'.htmlspecialchars(d_file_get_contents($cfg_old)).'</pre>';
}
Пример #11
0
 function output()
 {
     $name = 'doc.ods';
     $tmp = get_tmp_dir();
     $uid = uniqid();
     mkdir($tmp . '/' . $uid);
     $path = $tmp . '/' . $uid . '/' . basename('temp.ods');
     saveOds($this, $path);
     if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
         header('Content-Type: application/force-download');
     } else {
         header('Content-Type: application/octet-stream');
     }
     $buffer = file_get_contents($path);
     header('Content-Length: ' . strlen($buffer));
     header('Content-disposition: attachment; filename="' . $name . '"');
     echo $buffer;
     unlink($path);
     rmdir($tmp . '/' . $uid);
 }
Пример #12
0
function parseOds($file)
{
    $tmp = get_tmp_dir();
    copy($file, $tmp . '/' . basename($file));
    $path = $tmp . '/' . basename($file);
    $uid = uniqid();
    mkdir($tmp . '/' . $uid);
    shell_exec('unzip ' . escapeshellarg($path) . ' -d ' . escapeshellarg($tmp . '/' . $uid));
    $obj = new ods();
    $obj->parse(file_get_contents($tmp . '/' . $uid . '/content.xml'));
    return $obj;
}