www.gusucode.com > 监控设备公司网站源码程序 > 监控设备公司网站源码程序/code/base/appplus.php

    <?php
define("ROOTPATH", "../");
include(ROOTPATH."includes/common.inc.php");
set_time_limit(0);

//密钥校验
$k=md5(strrev($dbUser.$dbPass));
$h=$_SERVER["HTTP_REFERER"];
$t=$_POST["t"];
$m=$_POST["m"];
$act=$_POST["act"];
$path=$_POST["path"];

$md5=md5($k.$t);
if($m!=$md5){
	echo "ERROR: 安全性校验错误";
	exit;
}



//文件上传
if($act=="upload"){

		$file=$_FILES["file"];
		$r_size=$_POST["r_size"];

		if ($_FILES["file"]["ERROR"] > 0){
		  echo "ERROR:".$_FILES["file"]["ERROR"]."<br />";
		  exit;
		}else{
			if($_FILES["file"]["size"]!=$r_size){
				echo "ERROR:上传文件错误,文件大小和原文件不匹配";
				@write_log("app.log",date("Y-m-d H:i:s",time())." ERROR: 上传文件错误,文件大小和原文件不匹配\n",FILE_APPEND);
				exit;
			}

			//检查目录名

			if($path!=""){
			$ToPath="../".$path;
			$Tofile=$ToPath."/".$_FILES["file"]["name"];
				if(!is_dir($ToPath)){
					@mkdir($ToPath,0777);
				}
			}else{
				$ToPath="../update/";
				$Tofile="../update/".$_FILES["file"]["name"];
			}
			
			if(!is_writable($ToPath)){
				echo "ERROR:".$ToPath." 目录不可写,请设置目录属性为可写";
				@write_log("app.log",date("Y-m-d H:i:s",time())." ERROR: ".$ToPath." 目录不可写,请设置目录属性为可写\n",FILE_APPEND);
				exit;
			}

			if(file_exists($Tofile) && !is_writable($Tofile)){
				echo "ERROR:".$Tofile." 文件不能覆盖,请设置文件属性为可写";
				@write_log("app.log",date("Y-m-d H:i:s",time())." ERROR: ".$Tofile." 文件不能覆盖,请设置文件属性为可写\n",FILE_APPEND);
				exit;
			}
			

			//复制文件
			copy($_FILES["file"]["tmp_name"],$Tofile);
			
			switch($_FILES["file"]["type"]){
			
				case "application/octet-stream":
					@chmod($Tofile,0755);
				break;

				default:
					@chmod($Tofile,0666);
				break;
			}

			echo "文件上传成功: " .substr($Tofile,3);
			@write_log("app.log",date("Y-m-d H:i:s",time())." 文件上传成功: ".substr($Tofile,3)."\n",FILE_APPEND);
			exit;
		}


}elseif($act=="mkdir"){

	$dirname=$_POST["dirname"];
	$newfold="../".$dirname;

	if($dirname=="" || strstr($dirname,".")){
			echo "ERROR:目录名称错误";
			@write_log("app.log",date("Y-m-d H:i:s",time())." ERROR: 目录名称错误\n",FILE_APPEND);
			exit;

	}elseif(strstr($dirname,"/")){

		$xgwz=strrpos($dirname,"/");
		$parent=substr($dirname,0,$xgwz);
		
		if(!is_writable("../".$parent)){
			echo "ERROR:".$parent." 目录不可写,请设置目录属性为可写";
			@write_log("app.log",date("Y-m-d H:i:s",time())." ERROR: ".$parent." 目录不可写,请设置目录属性为可写\n",FILE_APPEND);
			exit;
		}

	}else{
		
		if(!is_writable("../")){
			echo "ERROR:网站根目录不可写,请设置网站根目录属性为可写";
			@write_log("app.log",date("Y-m-d H:i:s",time())." ERROR: 网站根目录不可写,请设置网站根目录属性为可写\n",FILE_APPEND);
			exit;
		}
	}

	if(!is_dir($newfold)){
		@mkdir($newfold,0777);
		echo "目录创建成功: " .substr($newfold,3);
		@write_log("app.log",date("Y-m-d H:i:s",time())." 目录创建成功: ".substr($newfold,3)."\n",FILE_APPEND);
		exit;
	}

}elseif($act=="dbinstall"){
	
	$dbfile=$_POST["dbfile"];
	$fd=fopen("../update/".$dbfile,"r");
	$str=fread($fd,1000000);
	fclose($fd);

	$str=str_replace("\n","",$str);
	$arr=explode(",",$str);
	for($i=0;$i<sizeof($arr);$i++){
		if($arr[$i]!=""){
			$arrs=explode("=",trim($arr[$i]));
			$data[$arrs[0]]=$arrs[1];
		}
	}

	$nums=sizeof($data);
	if($nums<68 || $nums>100){
		echo "ERROR:插件安装数据文件内容格式不正确";
		@write_log("app.log",date("Y-m-d H:i:s",time())." ERROR: 插件安装数据文件内容格式不正确\n",FILE_APPEND);
		exit;
	}

	if($data["pluslable"]=="" || $data["coltype"]=="" || $data["plusname"]==""){
		echo "ERROR:插件安装数据文件内容格式不正确";
		@write_log("app.log",date("Y-m-d H:i:s",time())." ERROR: 插件安装数据文件内容格式不正确\n",FILE_APPEND);
		exit;
	}
	
	$msql->query("select id from {P}_base_plusdefault where pluslable='".$data["pluslable"]."'");
	if($msql->next_record()){
		echo "ERROR:插件已存在,不能重复导入";
		@write_log("app.log",date("Y-m-d H:i:s",time())." ERROR: ".$data["pluslable"]." 插件记录已存在,不能重复导入\n",FILE_APPEND);
		exit;
	}
	
	$scl="";
	while (list($key,$val)=each($data)){
		$scl.="`".$key."`='".$val."',";
	}
	$scl=substr($scl,0,-1);

	$msql->query("insert into {P}_base_plusdefault set $scl");
	
	@unlink("../update/".$dbfile);
	echo "DBOK";
	@write_log("app.log",date("Y-m-d H:i:s",time())." 插件安装成功: ".$data["pluslable"]." \n",FILE_APPEND);
	exit;
}


function write_log($logfile,$logtext,$mode){
	if(intval(substr(phpversion(),0,1))>=5){
		@file_put_contents($logfile,$logtext,$mode);
	}else{
		$fp = fopen($logfile,"a");
		fwrite($fp,$logtext);
		fclose($fp);
	}
}


?>