<?php
/**
 *      [XCECP] (C) COLNET Inc.
 *      This is NOT a freeware, use is subject to license terms
 */
if(!defined("IN_QKWEB")){exit("Access Denied");}
class UpdateAction extends BaseAction{
	function __construct(){
		$ip = getVariable("updateServerIp");
		$remoteIp = $_SERVER['REMOTE_ADDR'];
		if($remoteIp!=$ip){ Msg::show($remoteIp.' 不是受信任的升级服务器'); }
		global $smarty;
		$smarty->setTemplateDir(ROOT_PATH."/admin/templates/");
	}
	function index(){
		
	}
	function read(){
		$file = getgpc('file');
		$file = str_replace('../','',$file);
		if(!$file){ exit('文件名不得为空'); }
		$pfile = ROOT_PATH.$file;
		if(!file_exists($pfile)){ exit('文件不存在'); }
		$fp = @fopen($pfile,'r'); if(!$fp){exit('文件打开失败');}
		$tmp='';
		while(!feof($fp)){$tmp.=fread($fp,1024);}
		@fclose($tmp);
		assign("file",$file);
		assign("code",$tmp);
		display("update/read.html");
	}
	function write(){
		$file = getgpc('file');
		$file = str_replace('../','',$file);
		if(!$file){ exit('文件名不得为空'); }
		$pfile = ROOT_PATH.$file;
		if(!file_exists($pfile)){ exit('文件不存在'); }
		$update=getgpc('update');$code=getgpc('code');
		if($update=='1' && $code){
			if(is_writable($pfile)){
				$fp = @fopen($pfile,'w'); if(!$fp){exit('文件写打开失败');}
				fwrite($fp,stripslashes($code));
				fclose($fp);
			}
		}
		$fp = @fopen($pfile,'r'); if(!$fp){exit('文件打开失败');}
		$tmp='';
		while(!feof($fp)){$tmp.=fread($fp,1024);}
		@fclose($tmp);
		assign("file",$file);
		assign("code",$tmp);
		display("update/write.html");
	}

	function create(){
		$file = getgpc('file');
		$file = str_replace('../','',$file);
		if(!$file){ exit('文件名不得为空'); }
		$pfile = ROOT_PATH.$file;
		if(!file_exists($pfile)){ echo('文件不存在将创建新文件'); }
		$update=getgpc('update');$code=getgpc('code');
		if($update=='1' && $code){
			if(is_writable($pfile)){
				$fp = @fopen($pfile,'w'); if(!$fp){exit('文件写打开失败');}
				fwrite($fp,stripslashes($code));
				fclose($fp);
			}
		}
		$fp = @fopen($pfile,'w+'); if(!$fp){exit('文件打开失败');}
		$tmp='';
		while(!feof($fp)){$tmp.=fread($fp,1024);}
		@fclose($tmp);
		assign("file",$file);
		assign("code",$tmp);
		display("update/write.html");
	}
}
?>