...
 
Commits (2)
<?php
/*
* register.php
*
* This file contains the registration of a simulator to the database
* and checks if the simulator is new in the database or a reconnected one
*
* If the simulator is old, check if the nextcheck date > registration
* When the date is older, make a request to the Parser to grab new data
*
*/
require("config/config.php");
$DB_HOST=OPENSIM_DB_HOST;
$DB_NAME=OPENSIM_DB_NAME;
$DB_USER=OPENSIM_DB_USER;
$DB_PASSWORD=OPENSIM_DB_PASS;
$host = $_GET['host'];
$port = $_GET['port'];
$service = $_GET['service'];
if ($host == "" || $port == "")
{
header("HTTP/1.0 404 Bad Request");
echo "Missing host and/or port\n";
exit;
}
// Attempt to connect to the database
try {
$db = new PDO("mysql:host=$DB_HOST;dbname=$DB_NAME", $DB_USER, $DB_PASSWORD);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e)
{
echo "Error connecting to database\n";
file_put_contents('PDOErrors.txt', $e->getMessage() . "\n-----\n", FILE_APPEND);
exit;
}
if ($service == "online")
{
// Check if there is already a database row for this host
$query = $db->prepare("SELECT register FROM hostsregister WHERE host = ? AND port = ?");
$query->execute( array($host, $port) );
// Get the request time as a timestamp for later
$timestamp = $_SERVER['REQUEST_TIME'];
// If a database row was returned check the nextcheck date
if ($query->rowCount() > 0)
{
$query = $db->prepare("UPDATE hostsregister SET " .
"register = ?, " .
"nextcheck = 0, checked = 0, failcounter = 0 " .
"WHERE host = ? AND port = ?");
$query->execute( array($timestamp, $host, $port) );
}
else
{
// The SELECT did not return a result. Insert a new record.
$query = $db->prepare("INSERT INTO hostsregister VALUES (?, ?, ?, 0, 0, 0)");
$query->execute( array($host, $port, $timestamp) );
}
}
if ($service == "offline")
{
$query = $db->prepare("DELETE FROM hostsregister WHERE host = ? AND port = ?");
$query->execute( array($host, $port) );
}
$db = NULL;
if (is_array($otherRegistrars) && $hostname != "" && $port != "" && $service != "")
{
$querystring=getenv('QUERY_STRING');
foreach ($otherRegistrars as $registrar) {
$result=file_get_contents("$registrar?$querystring");
}
}
......@@ -43,11 +43,11 @@ then
echo "Downloading DTL/NSL scripts archive"
archive_url=http://www.nsl.tuis.ac.jp/DownLoad/SoftWare/OpenSim/helper_scripts-0.8.1.tar.gz
archive=tmp/$(basename "$archive_url")
[ -f $archive ] \
&& echo "archive already downloaded in $archive, remove it before launching install if you want to replace it" \
|| wget -P tmp/ $archive_url || exit 1
echo "Extracting $archive"
tar xvfz $archive --strip 1 || exit 1
fi
......@@ -78,5 +78,24 @@ grep -q "define('WEBSITE_LOGO_URL'," $config \
|| echo "define('WEBSITE_LOGO_URL', '/helper/images/login_screens/logo.png');" >> $TMP.config
grep -q "define('CURRENCY_MODULE'," $config \
|| echo "define('CURRENCY_MODULE', 'Gloebit');" >> $TMP.config
grep -q "\$otherRegistrars *=" $config \
|| echo "
//
// Forward registrations to other compatible registrars
//
// \$otherRegistrars=array(
// 'http://metaverseink.com/cgi-bin/register.py',
// );
" >> $TMP.config
if [ -f $TMP.config ]
then
egrep -B1000 "XMLGROUP_WKEY|WEBSITE_LOGO_URL|CURRENCY_MODULE" $config > $TMP.config.compiled
echo >> $TMP.config.compiled
cat $TMP.config >> $TMP.config.compiled
echo >> $TMP.config.compiled
egrep -A1000 "XMLGROUP_WKEY|WEBSITE_LOGO_URL|CURRENCY_MODULE" $config \
| egrep -v "XMLGROUP_WKEY|WEBSITE_LOGO_URL|CURRENCY_MODULE" >> $TMP.config.compiled
cat $TMP.config.compiled > config/config.php
fi
#cat $TMP.config