■主控程式 upfile.php
<?
####################################################################
#Project Name: Test
#Author : lanf
#Home Page: http://lanf.yeah.net
#E-mail:imbusy@263.net
#Time: 2001 . 9
####################################################################
##驗證身份函數
function getUserRight($username,$user){
if($username==$user' '$user=="*") return true;
echo "<html>您沒有這個操作ID的許可權。<a href=javascript:window.history.back()>點這裡返回修改</a></html>";
return false;
}
##驗證身份函數結束
##檔案類型驗證函式
function getFileType($filename,$fileType){
$fileExtent=strrchr($filename, ".");$fileExtent=substr($fileExtent,1);
$fileExtent=strtolower($fileExtent);$fileType=strtolower($fileType);
if(strstr($fileType,"jpg")|| strstr($fileType,"gif")' 'strstr($fileType,"png") ){
if(!GetImageSize($imgfile)) {
echo "<html>這個操作ID不允許上傳此種類型檔案。<a href=javascript:window.history.back()>點這裡返回修改</a></html>";
return false;};
};
if(strstr($fileType,$fileExtent )' '$fileType="*") return true;
echo "<html>這個操作ID不允許上傳此種類型檔案。<a href=javascript:window.history.back()>點這裡返回修改</a></html>";
return false;
}
##檔案類型驗證函式結束
##上傳網站驗證函式
function checkFromSiteErr($siteFrom,$limitSite){
//取得網站網域名稱的ip地址;http://202.108.240.75 www.yyy.com
//echo $siteFrom;
$step1=substr($siteFrom,7);//echo "<br>$step1";
$step2=strpos($step1, "/");//echo "<br>$step2";
$step3=substr($step1,0,$step2);//echo "<br>$step3";
//if(eregi("^[0-9]+.[0-9]+.[0-9]+.[0-9]+$",$step3)){;}else{
$referIP=gethostbyname($step3);//echo "<br>ip:$referIP<br>";
//}
//到這裡,$referIP已經是一個上一個頁面的ip地址。
//匹配相關的內容。
if(strpos($limitSite,",",1)){
//說明是一組值
$pieces = explode(",",$limitSite);
while(list($key,$value) = each($pieces)){
$limit=gethostbyname($value);
if($starPos=strpos($limit,"*")){
//帶*號的IP
$tempLimit=substr($limit,0,$starPos);
$tempFromIP=substr($referIP,0,$starPos);
if($tempLimit==$tempFromIP){
return false;
}else{
continue;
};
}else{
//不帶*號的IP
if($limit==$referIP){
return false;
}else{
continue;
};
};
}
echo "<html>錯誤的上傳網站#16。<a href=javascript:window.close()>點這裡關閉視窗</a></html>";
return true;
}else{
//說明只有一個限制
$limit=gethostbyname($limitSite);
if($starPos=strpos($limit,"*")){
//帶*號的IP
$tempLimit=substr($limit,0,$starPos);
$tempFromIP=substr($referIP,0,$starPos);
if($tempLimit==$tempFromIP){
return false;
}else{
echo "<html>錯誤的上傳網站。<a href=javascript:window.close()>點這裡關閉視窗</a></html>";
return true;
};
}else{
//不帶*號的IP
if($limit==$referIP){
return false;
}else{
echo "<html>錯誤的上傳網站。<a href=javascript:window.close()>點這裡關閉視窗</a></html>";
return true;
};
};
}
};
##上傳網站驗證函式結束
##日誌記錄函數
function putLog($actionID,$message,$flag="a"){
if(!file_exists("./log")){
echo "目前的目錄沒有建立屬性為0777的log目錄,正在嘗試建立……";
if(@mkdir("./log",0777)){echo "建立成功!!!";}else{echo "失敗!許可權不足,請手動建立 ./log 。<br> 日誌沒有被記錄……"; return false;}
}
$logfile="./log/".$actionID.$flag.".log";
$cmdstr="echo "".$message."" >> ".$logfile;
if (!file_exists($logfile)) {passthru("touch ".$logfile); chmod($logfile,0777);}
passthru($cmdstr);
return true;
};
##日誌記錄函數
##取設定檔參數函數
function get_config($conf,$actionID="",$actionType=""){
//$conf 設定檔名,$actionID 操作ID ,$actionType 操作類型
global $targetDir,$user,$maxLength,$fileType,$checkFile,$limitSite,$callback;
$actionID=trim($actionID);
if($actionID=="") return false;
$keylength=strlen($actionID);
$fileArray=file($conf);
$canshuZoneId=0;
if($actionType=="upload"){
//假如是上傳檔案的話
while (list($key,$value) = each($fileArray)) {
$value=trim($value);
//判斷參數地區,將參數提取限制在上傳檔案設定區
$Zone_temp=substr($value,0,1);
if($Zone_temp=="["){//開始一個參數地區
if(strstr($value, "up")){