<commit_before><?php

/*

Jappix - An open social platform
This is the Jappix Jingle services API script

-------------------------------------------------

License: AGPL
Author: <NAME>

*/

// 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'])) {
    $cache_hash = md5($_GET['username']);
    $cache_path = JAPPIX_BASE.'/tmp/jingle/'.$cache_hash.'cache';
    $cache_life = 3600;
    
    // 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
        $json = read_url('https://computeengineondemand.appspot.com/turn?username='.urlencode($_GET['username']));

        if($json && strpos($json, 'uris') !== false) {
            file_put_contents($cache_path, $json);
        }
    } else {
        $json = file_get_contents($cache_path);
    }
    
    exit($json);
}

?><commit_msg>Secure Jingle API credentials retrieval using IP<commit_after><?php

/*

Jappix - An open social platform
This is the Jappix Jingle services API script

-------------------------------------------------

License: AGPL
Author: <NAME>

*/

// 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
        $json = read_url('https://computeengineondemand.appspot.com/turn?username='.urlencode($_GET['username']));

        if($json && strpos($json, 'uris') !== false) {
            file_put_contents($cache_path, $json);
        }
    } else {
        $json = file_get_contents($cache_path);
    }
    
    exit($json);
}

?>
{'fraction_non_alphanumeric': 0.16839741790625878, 'fraction_numerical': 0.0030872859949480774, 'mean_word_length': 2.886586695747001, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '462522', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1059, 'n_words': 310}