{${$parameter}["err_msg"]}"; return; } if ($version=='') { include("bssversion.inc"); } /***************************************** * Locate tar file if it is not given * *****************************************/ if (!isset($tarfile)) { echo "\n"; ?> {${$parameter}["availfile"]}:"; echo "
\n"; echo "
\n";
	if (is_dir("/usr/local/apache/htdocs/bss_db"))
	{
		//$backuplist = Array();
		exec("ls -1t /usr/local/apache/htdocs/bss_db",$backuplist,$retval);
		$backupcount = count($backuplist);
		if ($backupcount <= 0)
			echo "{${$parameter}["no_backup"]}\n";
		else
			system("ls -1lht /usr/local/apache/htdocs/bss_db");
			
	}
	else
	{
		echo "{${$parameter}["no_backup"]}\n";
	}
	echo "
\n"; echo "
\n"; echo "
\n"; echo "{${$parameter}["selectfile"]}: "; echo "\n"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if (isset($bssid)) echo ""; echo "
\n"; echo "\n"; return; } /****************************************** * Mount the BSC /hd0 to /tmp/$$ directory *******************************************/ $tmpdir = sprintf("%.3f",time()/1000); $iwbox = "bss${bssid}"; $ip = name2ip($iwbox); $path_prefix = "tmp"; //---------------FTP BSS Config,EMS -> BSS----------------------- $bscLoginName="www"; $bscLoginPassword="123456"; $remote_dir="/hd0/{$version}/compile/cfg"; flush(); echo "Please wait, the operation will take some time
"; ob_flush(); flush(); system("rm -rf /$path_prefix/$iwbox"); mkdir("/$path_prefix/$iwbox",0755); system("cp $tarfile /$path_prefix/$iwbox"); chdir("/$path_prefix/$iwbox"); system("tar zxf *.tar.gz"); system("rm -rf *.tar.gz"); $conn_id=ftp_connect($ip); if($conn_id == FALSE) { echo "FTP:connect to $ip failed.
"; back(); } if(FALSE == ftp_login($conn_id,$bscLoginName,$bscLoginPassword)) { echo "FTP:login to $ip failed.
"; back(); } clearstatcache(); ftp_put_whole_dir("/$path_prefix/$iwbox",$remote_dir,$conn_id); ftp_close($conn_id); system("rm -rf /$path_prefix/$iwbox"); function ftp_put_whole_dir($local_dir,$remote_dir,$conn_id) { if($handle = opendir($local_dir)) { while(false !== ($file = readdir($handle))) { if($file != "." && $file != "..") { if(strlen(trim($file))<=0) continue; if(is_dir($file)) { ftp_put_whole_dir($local_dir."/$file",$remote_dir."/$file",$conn_id); } else { flush(); echo ""; ob_flush(); flush(); ftp_put($conn_id,$remote_dir."/$file",$local_dir."/$file",FTP_BINARY); //echo "$local_dir $remote_dir $file
"; } } } closedir($handle); } } echo "
Download completely
"; echo "\n"; echo ""; exit(); //------------------------------------------------------- /*************************************************************************************** * PHP state machine * * Rename original build and create directory * Format: it is a 2D array * Array( * Array('function','description','next state if success','next state if fail' * ) ****************************************************************************************/ $cmdlist = Array( 's00' => Array ('system("/bin/ping -q -c 1 $ip >> /dev/null", $retval);return($retval);', "{${$parameter}["ping"]} $iwbox ($ip) ...", "kickout","s01"), 's01' => Array ('return(is_dir("$path_prefix/$iwbox"));', "{${$parameter}["checkexist"]} $path_prefix/$iwbox", "s03","s02"), 's02' => Array ('return(mkdir("$path_prefix/$iwbox",0700));', "{${$parameter}["create_dir"]} $path_prefix/$iwbox", "s03","halt"), 's03' => Array ('system("umount $path_prefix/$iwbox", $retval);return($retval);', "", //"{${$parameter}["umounting"]} $path_prefix/$iwbox", "s04","s03"), 's04' => Array ('system("mount $path_prefix/$iwbox", $retval);return($retval);', "{${$parameter}["mounting"]} $path_prefix/$iwbox", "halt","s40"), 's40' => Array ('return(is_dir(sprintf("$path_prefix/$iwbox/%s/compile/cfg",strtoupper($version))));', "{${$parameter}["checkexist"]} $path_prefix/$iwbox/$version/compile/cfg", "s41","halt"), 's41' => Array ('return(chdir (sprintf("$path_prefix/$iwbox/%s/compile/cfg",strtoupper($version))));', "{${$parameter}["chdir"]} $path_prefix/$iwbox/$version/compile/cfg", "s60","halt"), 's60' => Array ('return(is_file("$tarfile"));', "{${$parameter}["checkexist"]} $tarfile", "s61","halt"), 's61' => Array ('system("tar zxf $tarfile", $retval);return($retval);', "{${$parameter}["untar"]} $tarfile ...", "halt","cleanup"), "cleanup" => Array('return(is_dir("$path_prefix/$iwbox"));', "{${$parameter}["checkexist"]} $path_prefix/$iwbox", "chroot","getout"), 'chroot' => Array ('return(chdir("/"));', "{${$parameter}["chdir"]} $path_prefix/$iwbox/$version/compile/cfg", "umount","getout"), "umount" => Array('system("umount $path_prefix/$iwbox", $retval);return($retval);', "{${$parameter}["umounting"]} $path_prefix/$iwbox", "umount","rmdir"), "rmdir" => Array('return(rmdir("$path_prefix/$iwbox"));', "{${$parameter}["rmdir"]} $path_prefix/$iwbox", "getout","getout") ); if (isset($debug)) { foreach ($cmdlist as $key => $value) { echo "$key,$value[0],$value[1],$value[2],$value[3]
"; } } /********************************************* * Execute the state machine here *********************************************/ echo "{${$parameter}["heading"]}
"; echo "
";
for ($state="s00" ; ; )
{
	if (isset($debug))
		echo "{$cmdlist[$state][0]}\n$state: ";

	echo "{${cmdlist}[$state][1]}";
	flush();
	if (@eval(${cmdlist}["$state"][0]))
		$state = $cmdlist[$state][2];
	else
		$state = $cmdlist[$state][3];


	if ($state == "getout")
	{
		echo " ... {${$parameter}["ok"]}\n";
		break;
	}
	else if ($state == "kickout")
	{
		echo " ... {${$parameter}["not_ok"]}\n";
		echo "
... {${$parameter}["failed"]}
"; echo "
";
		break;
	}
	else if ($state == "halt")
	{
		echo " ... {${$parameter}["not_ok"]}\n";
		echo "
... {${$parameter}["failed"]}
"; echo "
";
		$state = "cleanup";
	}
	else
	{
		if (${cmdlist}[$state][1] != "")
			echo " ... {${$parameter}["ok"]}\n";
	}
}

echo "
\n"; echo "... {${$parameter}["done"]}
"; echo ""; ?>