🎉 Added files

This commit is contained in:
2025-01-26 18:33:45 +01:00
commit 40149d87b3
301 changed files with 81911 additions and 0 deletions

5
rayphp/README Normal file
View File

@@ -0,0 +1,5 @@
This directory contains client PHP scripts for Raydium and other
rayphp files.
Some of the most interesting files of this directory are "repositories.*" ones,
describing wich data servers are available for your applications data.

32
rayphp/getfile.php Normal file
View File

@@ -0,0 +1,32 @@
<?
// gets file from repositories listed in repositories.list
// params: $filename (string, input), $force (integer, input),
// $status (integer, output)
// This script must be placed in "rayphp" sub-directory.
require("libfile.php");
$status=0;
filename_cut($filename,$file,$path);
echo "Using repositories to get '$file' file";
$repos=read_repositories_file("repositories.list");
// foreach repository
for($i=0;$i<count($repos);$i++)
{
$r = $repos[$i];
if(valid_entry($r))
{
if(update_file($file,$r,$path.$file,$force))
{
$status=1;
return;
}
}
}
// If we get here, something went wrong
die("No valid repository found for this file, aborting.");
?>

11
rayphp/httptest.php Normal file
View File

@@ -0,0 +1,11 @@
<?
// Test if Internet connection is available using Raydium website
// params: $status (integer, output)
// (0 means 'not available', 1 means 'OK')
// This script must be placed in "rayphp" sub-directory.
require("libfile.php");
$status = (http_test()?1:0);
?>

362
rayphp/libfile.php Normal file
View File

@@ -0,0 +1,362 @@
<?
// set the proxy according to the configuration database
$proxy = str_pad('', 128);
raydium_parser_db_get("Generic-Proxy", $proxy, "");
$GLOBALS['raydium_proxy'] = $proxy;
// returns a newer content for a file (using HTTP repository)
function update_file($file,$repos,$local,$force)
{
$file=rawurlencode($file);
$req="$repos?file=$file&type=getDate";
$d=http_download($req);
if($d == false)
{
echo "FAILED: Cannot get date on $file ($repos)";
return false;
}
$ld=@filemtime($local);
if($ld>=$d && !$force && $d!=false && $ld!=false)
{
echo "Local file is the same or newer, aborting. ($repos)";
return false;
}
$req="$repos?file=$file&type=getGzip";
$data=http_download($req);
// we got nothing
if($data===false)
{
echo "FAILED: Cannot retrieve $file ($repos)";
return false;
}
// if we got an error message
if(substr($data,0,6)=="FAILED")
{
// not very safe on a rogue server
echo $data." ($repos)";
return false;
}
echo "OK ($repos)";
// let's update the file with data
$data=gzdecode($data);
$fp=@fopen($local,"wb");
if(!$fp) die("FAILED: Cannot create output file '$path$file', aborting.");
fwrite($fp,$data);
fclose($fp);
return true;
}
// Retrieves a file from the internet using HTTP. Return the file as a string
function http_download($url)
{
$ch = curl_init();
if (defined($GLOBALS['raydium_proxy']))
curl_setopt ($ch, CURLOPT_PROXY, $GLOBALS['raydium_proxy']);
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
$result = curl_exec ($ch);
if (curl_errno($ch))
{
print "ERROR downloading file: " . curl_error($ch);
return false;
}
else
{
curl_close($ch);
return $result;
}
}
function read_repositories_file_internal($repos,&$repos_list)
{
$list=@file($repos);
if(count($list)==0)
die("Cannot open $repos");
// let's clean up the list
for($i=0;$i<count($list);$i++)
{
$list[$i]=trim($list[$i]);
}
$repos_list = array_unique (array_merge($repos_list,$list));
return $repos_list;
}
// Get repositories from a given (local) file
function read_repositories_file($repos)
{
global $raydium_php_rayphp_path;
$repos_list=array();
$tmp=str_pad("",256);
raydium_file_home_path_cpy($repos,$tmp);
if(file_exists($tmp))
read_repositories_file_internal($tmp,$repos_list);
read_repositories_file_internal($raydium_php_rayphp_path."/".$repos,$repos_list);
return $repos_list;
}
// Get the file list from a given repository
function list_repos($filter,$size,$repos)
{
$filter=rawurlencode($filter);
$req="$repos?file=$filter&type=listRepos";
$d=http_download($req);
if($d===false)
return false;
echo "Listing from '$repos'";
return implode("",$d);
}
// Sets file and path from a full filename
function filename_cut($filename,&$file,&$path)
{
$t=explode("/",$filename);
$file=$t[count($t)-1];
$t[count($t)-1]="";
$path=implode("/",$t);
}
// Is it a non-empty and non-comment line ?
function valid_entry($r)
{
if($r[0]!='#' && strlen(trim($r))>0)
return true;
else
return false;
}
// unzip a given input
function gzdecode($in)
{
$tmp=str_pad("",256);
raydium_file_home_path_cpy("tmp.tmp.gz",$tmp);
$fp=fopen($tmp,"wb");
if(!$fp) return false;
fwrite($fp,$in);
fclose($fp);
$fp=gzopen($tmp,"rb");
if(!$fp) return false;
while(!gzeof($fp))
{
$data.=gzread($fp,128);
}
gzclose($fp);
unlink($tmp);
return $data;
}
function ftp_upload($repos,$local,$distant)
{
$url=parse_url($repos);
$conn_id = ftp_connect($url["host"],$url["port"]);
$login_result = ftp_login($conn_id, $url["user"], $url["pass"]);
ftp_pasv($conn_id, true);
if (ftp_put($conn_id,$url["path"].$distant, $local, FTP_ASCII))
{
echo "$repos: SUCCESS";
ftp_close($conn_id);
return true;
}
else
{
echo "Failed contacting $repos";
ftp_close($conn_id);
return false;
}
}
function http_upload($repos,$local,$distant)
{
// creating temporary files is a little crappy, but it works
$data=@file_get_contents($local);
$data=gzencode($data);
$zfilename = $local . ".gz";
$fp=fopen($zfilename,"wb");
if(!$fp)
{
print "FAILED: Cannot create zipped file $zfilename";
return false;
}
fwrite($fp,$data);
fclose($fp);
$url=parse_url($repos);
$user=rawurlencode($url["user"]);
$pass=rawurlencode($url["pass"]);
$path=$url["path"];
$host=$url["host"];
$post = Array();
$post[ 'file' ] = $distant;
$post[ 'type' ] = "putGzip";
$post[ 'username' ] = $user;
$post[ 'password' ] = $pass;
$post[ 'data' ] = "@".$zfilename;
$ch = curl_init();
if (defined($GLOBALS['raydium_proxy']))
curl_setopt ($ch, CURLOPT_PROXY, $GLOBALS['raydium_proxy']);
curl_setopt($ch, CURLOPT_URL, "http://".$host.$path );
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1 );
// seems no need to tell it enctype='multipart/data' it already knows
curl_setopt($ch, CURLOPT_POSTFIELDS, $post );
$response = curl_exec( $ch );
unlink($zfilename);
if($response[0]=='+')
{
return true;
}
else
{
echo "HTTP reply: $response";
return false;
}
}
// supported files : (depends_xxx style)
function depends_tri($filename)
{
$fp=fopen($filename,"rt");
if($fp==false)
{
echo "Cannot open $filename";
}
fgets($fp, 4096); // skip first line (version number)
while (!feof($fp))
{
$line = trim(fgets($fp, 4096));
$line=explode(" ",$line);
$tex=trim($line[count($line)-1]);
if(substr($tex,0,4)!="rgb(")
{
$tex=trim($tex);
$ok=false;
if(strpos($tex,';') && !$ok) // is multitextured with ";" ?
{
$ok=true;
$texs=explode(";",$tex);
if(strlen($texs[0])) $ret[]=$texs[0]; // yes, and it's a "detail texture"
if(strlen($texs[1])) // yes and it's a lightmap
{
if(strpos($texs[1],"|")!==false)
{
$lm=explode("|",$texs[1]);
$ret[]=$lm[2];
}
else
$ret[]=$texs[1];
}
}
if(strpos($tex,'#') && !$ok) // is an environment map ?
{
$ok=true;
$texs=explode("#",$tex);
$ret[]=$texs[0];
$ret[]=$texs[1];
}
if(!$ok && strlen($tex))
$ret[]=$tex;
$ret=@array_values(array_unique($ret));
}
}
fclose($fp);
$ret[]=$filename;
return $ret;
}
function depends_prt($filename)
{
$f=@file($filename);
for($i=0;$i<count($f);$i++)
{
$line=trim($f[$i]);
if($line[0]=='/' && $line[1]=='/') continue;
if(strpos($line,"texture") === false) continue;
echo $line;
$t=explode('=',$line);
$t=trim($t[1]);
$t=str_replace('"',"",$t);
$t=str_replace(';',"",$t);
$ret[]=$t;
}
$ret[]=$filename;
return $ret;
}
function depends_find($filename)
{
$tbl=explode(".",$filename);
$ext=trim($tbl[count($tbl)-1]);
if($ext=="tri") return depends_tri($filename);
if($ext=="prt") return depends_prt($filename);
// else ..
$ret[]=$filename;
return $ret;
}
/////////////////// Network section
// tests if the website is reacheable.
function http_test()
{
$url="http://raydium.org/ping.php";
$ch = curl_init();
if (defined($GLOBALS['raydium_proxy']))
curl_setopt ($ch, CURLOPT_PROXY, $GLOBALS['raydium_proxy']);
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 3);
$result = curl_exec ($ch);
if (curl_errno($ch))
{
print "HTTP connection test failed: " . curl_error($ch);
return false;
}
else
{
curl_close($ch);
return true;
}
}
?>

37
rayphp/listrepos.php Normal file
View File

@@ -0,0 +1,37 @@
<?
// lists files from the first valid repository
// params: $filter (string, input), $size (integer, input)
// $list (string, output), $status (integer, output)
// This script must be placed in "rayphp" sub-directory.
require("libfile.php");
$status=0; // sets status to "error", by default
$repos=read_repositories_file("repositories.list");
$list="";
for($i=0;$i<count($repos);$i++)
{
$r = $repos[$i];
if(valid_entry($r))
{
if( ($data=list_repos($filter,$size,$r)) )
{
if(strlen($data)+1>=$size)
{
echo "$r : Not enough memory";
}
else
{
$list="$data";
$status=1;
exit(0);
}
}
}
}
// Something is wrong
die("No valid repository found for listing, abording.");
?>

84
rayphp/putfile.php Normal file
View File

@@ -0,0 +1,84 @@
<?
// gets file from repositories listed in repositories.list
// params: $filename (string, input), $depends (integer, input)
// $status (integer, output)
// This script must be placed in "rayphp" sub-directory.
require("libfile.php");
$status=0; // sets status to "error", by default
//$filename="buggy.tri"; // used when debugging outside of Raydium
$repos=read_repositories_file("repositories.upload");
if($depends)
{
$deps = depends_find($filename);
}
else
{
$deps[] = $filename;
}
// for each file to upload
for($j=0;$j<count($deps);$j++)
{
filename_cut($deps[$j],$file,$path);
if(!file_exists($path.$file) || !is_readable($path.$file))
{
echo "Cannot upload '$path$file': file do not exist or invalid rights";
continue;
}
echo "Using repositories to upload '$file' file...";
// for each repository
for($i=0;$i<count($repos);$i++)
{
$r = $repos[$i];
if(valid_entry($r))
{
// http or ftp ?
$type=parse_url($r);
$type=$type["scheme"];
if(($type=="ftp" ||
$type=="ftps" )
&& ftp_upload($r,$path.$file,$file))
{
touch($path.$file);
$status++;
break;
}
if(($type=="http" ||
$type=="https" )
&& http_upload($r,$path.$file,$file))
{
touch($path.$file);
$status++;
break;
}
}
}
}
if($status==count($deps))
{
echo "All files uploaded ($status)";
return;
}
if($status==0)
{
echo "No file uploaded";
return;
}
echo "Only $status/".count($deps)." file(s) uploaded";
?>

33
rayphp/r3s/README Normal file
View File

@@ -0,0 +1,33 @@
R3S: Raydium Server Side Scripts
--------------------------------
With this files and a HTTP/PHP server, you can build very
quickly a data repository server, allowing clients to get new files
(and refresh old ones) from this server.
Files are all stored in the same directory, since
the client will rebuilt directory structure by itself.
R3S support uploading, but you can also use a FTP server since Raydium
client applications allows this.
With R3S, FTP is slower than HTTP since no compression is used (R3S protocol
is using gzip with HTTP) but is the only correct solution with big files, since
most HTTP servers and proxies limits requests size.
See configuration file, and place data in $data_dir directory.
Please, note that Apache (or any other HTTP server) must have write rights
in $data_dir directory:
# chgrp apache files/
# chown g+w files/
(You may have to change "apache" to "httpd", "www-data" or something else).
For security reasons (uploaded PHP scripts), you should deny direct access
to the "file/" directory with Apache:
<Directory /home/raydium/repository/files>
Deny from all
</Directory>
You can create a .welcome message (one line only) in this directory.
A .lock file in this directory will lock all upload support for this repository.

16
rayphp/r3s/config.inc.php Normal file
View File

@@ -0,0 +1,16 @@
<?
// Raydium Server Side repository Scripts (R3S) configuration file.
// files directory:
$data_dir="files/";
# Upload params:
# Note: You can also use an FTP server.
$upload_accept=true;
$upload["user"]="anonymous";
$upload["pass"]="nopass";
// Minimum delay (in seconds) for each upload request:
$brute_force_delay=1;
?>

270
rayphp/r3s/index.php Normal file
View File

@@ -0,0 +1,270 @@
<?
// 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 <a href=\"http://raydium.org/\">Raydium</a> data repository";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Raydium 3D Game Engine</title>
<style type="text/css">
<!--BODY {color: #424242; font-family: Verdana,Arial,Helvetica,sans-serif,monospace; margin: 0; padding: 0; }
A.blk {color: black;}
A {color: #F19137;}
A:HOVER {color: #227CBF;}
.topbanner {background-color: #FFCC00; border: 0; border-bottom: 1px dashed #5E5E5E; text-align: right;margin: 0; height: 15px; font-size: x-small; padding: 0;}
.topbanner A {color: Black;}.topbanner A:HOVER {color: #F19137; text-decoration: none;}
.topbanner UL {list-style: none; border: 0; margin: 0;}
.topbanner LI {display: inline; margin: 3px;}
#contenu {margin: 0 10% 0 170px; position: absolute; left:5px; top: 45px; width: 800px;}
.publi_bloc { border-bottom: 2px dotted #FFCC00; margin-bottom: 20px;}
.publi_head {border-bottom: 1px dashed #A9A9A9; border-left: 10px solid #FFCC00;}
.publi_head h2 { margin: 0px; padding-left: 10px;}
.publi_head h2 a { color: #424242; text-decoration: none; }
.publi_head h2 a:hover { color: #727272; text-decoration: none; }
.publi_info {text-align: right; color: #A9A9A9;}
.publi_info a {color: #A9A9A9; text-decoration: none;}
.publi_info a:hover {color: #696969; text-decoration: none;}
.publi_corps{ padding: 10px;}
IMG {border: 1px solid; margin: 5px;}
.tables {background: #f3f3f3;border-collapse:collapse;margin-left: auto; margin-right: auto;}
.tables TD {border-style: solid; border-color:black; border-width:1px; text-align: center; padding-left: 5px; padding-right: 5px;}
.redfont { color: #dd0000;}
.greenfont { color: #00dd00;}
.noborder { border : 0;}
.border_one { border: 1px dashed #ACACAC; background-color: #EEEEEE; }-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15">
</head>
<body>
<div class="topbanner">
<ul>
<li>Raydium Server Side Scripts (R3S) - Data Repository for Raydium 3D Game Engine - <a href="http://raydium.org/">http://raydium.org</a></li>
</ul>
</div>
<div id="contenu">
<div class="contenu">
<div class="publi_bloc">
<div class="publi_head">
<strong>&nbsp;R3S message</strong> &gt; home<h2><?=$str;?></h2>
</div>
<div class="publi_corps">
<?
}
function tail()
{
echo "</div></div></div></div></body></html>";
}
function home()
{
global $data_dir,$upload_accept;
head();
echo "<h3>Available files:</h3>\n";
echo "<table border=0 cellpadding=2>";
if ($dh = _opendir($data_dir))
{
while (($file = _readdir($dh)) !== false)
{
if($file[0]==".") continue;
$size=filesize($data_dir.$file);
$total_size+=$size;
echo "<tr><td><b><a href=\"?type=getBin&file=$file\">$file</a></b></td><td align=right>$size byte(s)</td><td>&nbsp;</td><td>".date("Y-m-d H:i:s",filemtime($data_dir.$file))."</td></tr>";
}
}
echo "<tr><td>&nbsp;</td></tr>";
echo "<tr><td><b>Total size</b></td><td align=right>".sprintf("%.2f",$total_size/1024/1024)." MB</td></tr";
echo "</table><br>";
echo "You can add this URL in your <i>rayphp/repositories.*</i> files.<br>";
if($upload_accept) $up="supports"; else $up="does not supports";
echo "This server $up data uploading.<br><br>";
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"));
?>

11
rayphp/repositories.list Normal file
View File

@@ -0,0 +1,11 @@
# This file lists data (tri, tga, wav, ogg, ...) repositories.
# Listed servers must run R3S (Raydium Server Side Scripts) files.
# you can only use http and https protocols:
# http://host.tld/path
# main:
http://fastrepo.raydium.org/
http://repository.raydium.org/
# we needs "contrib" servers

View File

@@ -0,0 +1,12 @@
# This file lists all repositories used for uploading:
# You can use http/https URL (R3S servers) or ftp/ftps servers (classic FTP).
# Only first valid server will be used in this list.
# No test is done to see if your file is newer than server side one.
# Warning ! Be carefull with "/" at the end of urls since Raydium client
# do not supports redirections !
http://anonymous:nopass@repository.raydium.org/
ftp://anonymous:nopass@ftp.raydium.org:29/
#http://anonymous:nopass@localhost/raydium/repository/
#http://anonymous:nopass@localhost/