// Raydium Server Side repository script
// name this file "index.php", and place data in $data_dir directory.
require("config.inc.php");
if(file_exists(".lock") && $upload_accept)
$upload_accept=false;
function GorP($var)
{
global $_GET,$_POST;
if(isset($_POST[$var]))
return $_POST[$var];
if(isset($_GET[$var]))
return $_GET[$var];
return "";
}
function _opendir($directory)
{
$list=array();
$dir=@opendir($directory);
$i=0;
while($entry=@readdir($dir))
{
$key=filemtime($directory.'/'.$entry);
$key.="-$i";
$list[$key]=$entry;
$i++;
}
@closedir($dir);
krsort($list);
return $list;
}
function _readdir(&$list)
{
$ret=current($list);
next($list);
return $ret;
}
function decompress_file($gz,$final)
{
$fp=gzopen($gz,"r");
if(!$fp) die("FAILED: Cannot open gz file");
while(!gzeof($fp))
{
$data.=gzread($fp,128);
}
gzclose($fp);
$fp=fopen($final,"wb");
if(!$fp)
{
echo "FAILED: Cannot create file '$final' on this server";
return false;
}
fwrite($fp,$data);
fclose($fp);
unlink($gz);
return true;
}
function head()
{
if(file_exists(".welcome"))
{
$str=file(".welcome");
$str=$str[0];
}
else
$str="R3S Raydium data repository";
?>
Raydium 3D Game Engine
- Raydium Server Side Scripts (R3S) - Data Repository for Raydium 3D Game Engine - http://raydium.org
R3S message > home
=$str;?>
}
function tail()
{
echo "
";
}
function home()
{
global $data_dir,$upload_accept;
head();
echo "Available files:
\n";
echo "";
if ($dh = _opendir($data_dir))
{
while (($file = _readdir($dh)) !== false)
{
if($file[0]==".") continue;
$size=filesize($data_dir.$file);
$total_size+=$size;
echo "$file | $size byte(s) | | ".date("Y-m-d H:i:s",filemtime($data_dir.$file))." |
";
}
}
echo " |
";
echo "Total size | ".sprintf("%.2f",$total_size/1024/1024)." MB |
";
echo "You can add this URL in your rayphp/repositories.* files.
";
if($upload_accept) $up="supports"; else $up="does not supports";
echo "This server $up data uploading.
";
tail();
}
function main($file,$type,$username,$password,$data)
{
global $data_dir,$upload,$upload_accept,$brute_force_delay;
global $HTTP_POST_FILES;
if($type=="")
{
home();
return;
}
$file=rawurldecode($file);
$file=str_replace("/","",$file);
$file=$data_dir.$file;
if($type=="listRepos")
{
if($file==$data_dir)
$file="$data_dir/*";
foreach((array)glob($file) as $file)
{
if($file[0]!='.')
echo trim(str_replace("/","",substr($file,strlen($data_dir))))."\n";
}
return;
}
// For all next operations, consider $file as mandatory ...
if($file=="") return;
if($type=="putGzip")
{
if(!$upload_accept)
{
echo "FAILED: Upload is not activated on this server !";
return;
}
sleep($brute_force_delay);
$username=rawurldecode($username);
$password=rawurldecode($password);
if($username!=$upload["user"] || $password!=$upload["pass"])
{
echo "FAILED: invalid user/pass ($username/$password)";
return;
}
$filegz=$file.".tmp.gz";
if(file_exists($HTTP_POST_FILES["data"]["tmp_name"]))
{
move_uploaded_file($HTTP_POST_FILES["data"]["tmp_name"], $filegz);
}
else die("FAILED: Cannot find data in this request");
if(!decompress_file($filegz,$file)) return;
chmod($file,0664);
echo "+ SUCCESS: file uploaded";
return;
}
if(!file_exists($file)) die("FAILED: file not found");
if($type=="getGzip")
{
$fp=fopen($file,"rb");
if(!$fp) die("FAILED: file not found");
$data=fread($fp,filesize($file));
fclose($fp);
$tmp=tempnam("./","delme");
$fp=gzopen($tmp,"wb");
if(!$fp) return;
gzwrite($fp,$data);
gzclose($fp);
//$dat=gzencode($data);
//echo $dat;
//echo date("s");
readfile($tmp);
unlink($tmp);
//echo $tmp;
}
if($type=="getDate")
{
echo filemtime($file);
}
if($type=="getBin")
{
header('Content-type: application/octet-stream');
header('Content-Transfer-Encoding: Binary');
header('Content-length: '.filesize($file));
header('Content-Disposition: attachment; filename="'.basename($file).'"');
readfile($file);
}
} // end main()
main(GorP("file"),GorP("type"),GorP("username"),GorP("password"),GorP("data"));
?>