Last active
August 31, 2020 18:17
-
-
Save sn0opy/fce2bd21cc55cd4e431095a3d754760f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require 'vendor/autoload.php'; | |
use GuzzleHttp\Client; | |
$f3 = Base::instance(); | |
$f3->receivers = [ | |
[ | |
"url" => "http://rdmserver123:9001/raw", | |
"secret" => "pa55word" | |
], | |
[ | |
"url" => "http://rdmserver456:9001/raw", | |
"secret" => "f00b4r!" | |
] | |
]; | |
function forward_data($content) { | |
$f3 = Base::instance(); | |
$contents = []; | |
foreach ($content as $cnt) { | |
if (!in_array($cnt->type, [2, 106, 102, 104, 101, 156])) { | |
continue; | |
} | |
array_push($contents, [ | |
"data" => $cnt->payload, | |
"method" => $cnt->type, | |
"length" => strlen($cnt->payload) | |
]); | |
} | |
$data = [ | |
"devicename" => "MADproxy", | |
"idfa" => "00000000-0000-0000-0000-00000000", | |
"trainerlvl" => 30, | |
"contents" => $contents, | |
"username" => $_SERVER['HTTP_ORIGIN'] | |
]; | |
foreach ($f3->receivers as $receiver) { | |
$options = [ | |
'headers' => [ | |
'User-Agent' => 'RDM proxy/1.0', | |
'Authorization' => 'Bearer '. $receiver["secret"] | |
] | |
]; | |
$client = new Client($options); | |
$res = $client->post($receiver["url"], ['json' => $data, 'timeout' => 3]); | |
} | |
} | |
$f3->route('POST /', function() use($f3) { | |
$content = json_decode(file_get_contents('php://input')); | |
forward_data($content); | |
}); | |
$f3->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires
composer
. Install dependencies viacomposer require bcosca/fatfree-core guzzlehttp/guzzle
Save as
index.php
in your preferred location and point PD tohttp://server.com/location/
. Do not point it directly toindex.php
nor use any other file names.