2014-03-12 14:52:47 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Jappix - An open social platform
|
|
|
|
This is the Jappix Jingle services API script
|
|
|
|
|
|
|
|
-------------------------------------------------
|
|
|
|
|
|
|
|
License: AGPL
|
|
|
|
Author: Valérian Saliou
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
// PHP base
|
|
|
|
define('JAPPIX_BASE', '..');
|
|
|
|
|
|
|
|
// Get the needed files
|
|
|
|
require_once('./functions.php');
|
|
|
|
require_once('./read-main.php');
|
|
|
|
require_once('./read-hosts.php');
|
|
|
|
|
|
|
|
// Prepare application
|
|
|
|
enableErrorSink();
|
|
|
|
hideErrors();
|
|
|
|
compressThis();
|
|
|
|
|
|
|
|
// Not allowed for a special node
|
|
|
|
if(isStatic() || isUpload()) {
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set a JSON header
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
|
|
|
|
// If valid data was sent
|
|
|
|
if(isset($_GET['username']) && !empty($_GET['username'])) {
|
|
|
|
// Read remote IP (secures passwords that are passed there)
|
|
|
|
$remote_ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
|
|
|
|
|
|
|
|
// Generate cache values
|
|
|
|
$cache_hash = md5($_GET['username'].'@'.$remote_ip);
|
|
|
|
$cache_path = JAPPIX_BASE.'/tmp/jingle/'.$cache_hash.'.cache';
|
|
|
|
$cache_life = $remote_ip ? 3600 : 0;
|
|
|
|
|
|
|
|
// Cache missing or obsolete?
|
|
|
|
$filemtime = @filemtime($cache_path);
|
|
|
|
|
|
|
|
if(!$filemtime or (time() - $filemtime >= $cache_life)) {
|
|
|
|
// Note: we use a Google API there, so fallback TURNs will be using Google's TURN server through an encrypted channel
|
|
|
|
// we know this won't satisfy everyone, but this is the best compromise we could find for the end-user
|
|
|
|
// if you are concerned about privacy, rather setup your TURN and add it to Jappix hosts configuration
|
|
|
|
|
|
|
|
// Get the JSON content
|
2014-11-25 20:12:58 +01:00
|
|
|
$json = readUrl('https://computeengineondemand.appspot.com/turn?username='.urlencode($_GET['username']));
|
2014-03-12 14:52:47 +01:00
|
|
|
|
|
|
|
if($json && strpos($json, 'uris') !== false) {
|
|
|
|
file_put_contents($cache_path, $json);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$json = file_get_contents($cache_path);
|
|
|
|
}
|
2014-11-25 23:42:38 +01:00
|
|
|
|
2014-03-12 14:52:47 +01:00
|
|
|
exit($json);
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|