Пример #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>';
}
Пример #2
0
		break;
	case 'mkfile':
		@$f = clean($_SESSION['DIR'].'/'.$_REQUEST['file']);
		if(empty($_GET['apply']))
		{
			light_message('<form action="index.php?act=mkfile&apply=true" method="POST">
			Enter the name of file you want to create: 
			<br><input type="text" name="file" value="NewFile"> <input type="submit" value="go">
			</form>');
		}else
		{
			$nomain=false;
			
			if(!d_is_file($f) || !empty($_GET['confirm']))
			{
				if(d_file_put_contents($f,'')) light_message(show_file($f).' has been created successfully.');
				else light_message('File could not be created.'.reason());
			}else
			{
				light_message('File '.show_file($f).' already exists.
				<br><br><a href="index.php?act=mkfile&file='.urlencode($_REQUEST['file']).'&apply=true&confirm=true">Click here to clear the file contents</a>');
			}
		}
		break;
	case 'mkdir':
		@$f = clean($_SESSION['DIR'].'/'.$_REQUEST['file']);
		if(empty($_GET['apply']))
		{
			light_message('<form action="index.php?act=mkdir&apply=true" method="POST">
			Enter the name of directory you want to create: 
			<br><input type="text" name="file" value="NewFolder"> <input type="submit" value="go">
Пример #3
0
	'dirs'   => $_SESSION['DIRS'],
	'files'  => $_SESSION['FILES'],
	'total'  => show_size(false,true,$_SESSION['TOTAL_BYTES']),
	'uids'   => implode(', ', $_SESSION['UIDS']),
	'gids'   => implode(', ', $_SESSION['GIDS']),
	'rights' => implode(', ', $_SESSION['RIGHTS']),
	'mod'    => d_get_rights($fz[0]),
	'end'    => $end,
	'success' => $success,
	'dir'    => sizeof($fz) == 1 ? d_is_dir($fz[0]) : true,
	);
	break;
case 'save-file':
	$f = clean(urldecode($_REQUEST['filename_encoded']));
	
	if(!d_file_put_contents($f, $_REQUEST['content']))
	{
		echo 'Cannot edit file.'.reason();
		$_RESULT = false;
	}else $_RESULT = true;
	break;
case 'exec':
	session_write_close();
	$_RESULT = exec_command($_REQUEST['cmd']);
	break;
case 'get_rights':
	$_RESULT = d_get_rights($f);
	break;
case 'set_rights':
	if(!$_REQUEST['recursive'])
	{