Example #1
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>';
}
Example #2
0
				@$sz=getimagesize($f);
				light_message('<h3>Preview of '.show_file($f).'</h3>
				<a href="system/download.php?file='.rawurlencode($f).'&'.session_name().'='.session_id().'"><img src="system/preview.php?file='.rawurlencode($f).'&size=normal" border="0" alt="Download the full image" title="Download the full image ('.($sz ? $sz[0].'x'.$sz[1].', ' : '').show_size($f).')"></a>');
				break;
			default:
				if(d_filesize($f)>102400)
				{
					header('location: system/download.php?file='.rawurlencode($f).'&'.session_name().'='.session_id());
					break;
				}
				
				$wr = setwritable($f,true);
				
				light_message('<h3>Edit '.show_file($f).' <small>(<a href="?act=properties&files[]='.rawurlencode($f).'&back='.rawurlencode('?act=edit&file='.rawurlencode($f)).'">info</a>)</small></h3>
				<form action="index.php?act=edit&apply=true&file='.rawurlencode($f).'" method="POST">
				<textarea name="content" id="content" rows=10 cols=40>'.htmlspecialchars(d_file_get_contents($f)).'</textarea>
				
				<script><!--
				/* for stupid IE <= 6 */
				var checkf = function()
				{
					if(!document.getElementById) return false;
					var el = document.getElementById("content");
					if(get_width()>=800) el.style.width = "750px";
					else /*if(el.clientWidth>(get_width()-50))*/ el.style.width = (get_width()-50)+"px";
					return true;
				}
				checkf();
				setInterval(checkf,100);
				//-->
				</script>
Example #3
0
{
	$f=clean($_GET['file']);
}

// some people reported about problems with file compression, so it is turned off always

$compress=false /*d_filesize($f)<100*1024*/; //compress the stream or not?

if(!empty($_GET['text'])) $text=str_replace(array("\r\n","\r","\n","\t"),array("\n","\n","\r\n"," "),d_file_get_contents($f));

if($compress) ob_start('ob_gzhandler');

header("Content-Type: application/force-download; charset=".CHARSET); 
header("Content-Transfer-Encoding: binary");
header('Content-Description: File Transfer');
if(!$compress) header("Content-Length: ".(isset($text) ? strlen($text) : d_filesize($f)));
header("Content-Disposition: attachment; filename=\"".addslashes(basename($f))."\"");
if(empty($_GET['text']))
{
	if(file_exists($f))
	{
		readfile($f);
	}else
	{
		echo d_file_get_contents($f);
	}
}
else echo $text;

die();
?>