From 479d8ad96fc3f9398f80a6b2418a400afce5d767 Mon Sep 17 00:00:00 2001 From: Leberwurscht Date: Mon, 16 Apr 2012 21:40:23 +0200 Subject: [PATCH] jappixmini: move modified BOSH proxy out of Jappix source tree to be able to use vanilla Jappix. This is possible because bosh.php is under MIT license. --- jappixmini/README | 11 +-- jappixmini/jappixmini.php | 19 +++- jappixmini/proxy.php | 178 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 201 insertions(+), 7 deletions(-) create mode 100644 jappixmini/proxy.php diff --git a/jappixmini/README b/jappixmini/README index 222b85a5..b833dae4 100644 --- a/jappixmini/README +++ b/jappixmini/README @@ -27,8 +27,9 @@ Installation Jappix Mini (AGPL license) is not distributed with this addon. You need to install it manually: -* Download latest zip file named friendica-addon-* from - https://github.com/Leberwurscht/jappix/tags and place the zip file in the - addon folder. Make sure to name it 'jappix.zip' - the download link required - by the AGPL points there. -* Unpack the zip file, rename the folder to 'jappix'. Do not delete jappix.zip. +* Download latest jappix version from https://github.com/jappix/jappix/tags to + addon/jappixmini/jappix.zip. Really make sure you name it 'jappix.zip' - the + download link required by the AGPL points there. +* Unpack the zip file to addon/jappixmini/jappix/. Do not delete jappix.zip. +* Delete the file addon/jappixmini/jappix/index.php. This is important, because + otherwise the installer of Jappix would be publicly accessible. diff --git a/jappixmini/jappixmini.php b/jappixmini/jappixmini.php index b177507a..93689a1e 100644 --- a/jappixmini/jappixmini.php +++ b/jappixmini/jappixmini.php @@ -100,7 +100,22 @@ function jappixmini_plugin_admin(&$a, &$o) { // display instructions and warnings on addon settings page for admin if (!file_exists("addon/jappixmini/jappix")) { - $o .= '

You need to install the Jappix application, adapted for Friendica (see README).

'; + $o .= '

You need to install the Jappix application (see README).

'; + } + else if (file_exists("addon/jappixmini/jappix/index.php")) { + // try to delete automatically + try { + unlink("addon/jappixmini/jappix/index.php"); + } + catch (Exception $e) {} + + // warn admin if this is not possible + if (file_exists("addon/jappixmini/jappix/index.php")) + $o .= '

You must delete addon/jappixmini/jappix/index.php (see README).

'; + else { + info("Deleted addon/jappixmini/jappix/index.php automatically."); + $o .= '

Jappix is installed.

'; + } } else if (!file_exists("addon/jappixmini/jappix.zip")) { $o .= '

The source archive jappix.zip does not exist. This is probably a violation of the Jappix License (see README).

'; @@ -422,7 +437,7 @@ function jappixmini_script(&$a,&$s) { // set proxy if necessary $use_proxy = get_config('jappixmini','bosh_proxy'); if ($use_proxy) { - $proxy = $a->get_baseurl().'/addon/jappixmini/jappix/php/bosh.php'; + $proxy = $a->get_baseurl().'/addon/jappixmini/proxy.php'; } else { $proxy = ""; diff --git a/jappixmini/proxy.php b/jappixmini/proxy.php new file mode 100644 index 00000000..72de341c --- /dev/null +++ b/jappixmini/proxy.php @@ -0,0 +1,178 @@ + array( + 'method' => 'POST', + 'content' => $data + ) + ); + + $parameters['http']['header'] = $headers; + + // Change default timeout + ini_set('default_socket_timeout', 30); + + // Create the connection + $stream = @stream_context_create($parameters); + $connection = @fopen($HOST_BOSH, 'rb', false, $stream); + + // Failed to connect! + if($connection == false) { + header('Status: 502 Proxy Error', true, 502); + exit('HTTP/1.1 502 Proxy Error'); + } + + // Allow stream blocking to handle incoming BOSH data + @stream_set_blocking($connection, true); + + // Get the output content + $output = @stream_get_contents($connection); +} + +// Cache headers +header('Cache-Control: no-cache, must-revalidate'); +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); + +// POST output +if($method == 'POST') { + // XML header + header('Content-Type: text/xml; charset=utf-8'); + + if(!$output) + echo(''); + else + echo($output); +} + +// GET output +if($method == 'GET') { + // JSON header + header('Content-type: application/json'); + + // Encode output to JSON + $json_output = json_encode($output); + + if(($output == false) || ($output == '') || ($json_output == 'null')) + echo($callback.'({"reply":""});'); + else + echo($callback.'({"reply":'.$json_output.'});'); +} + +// Close the connection +if($use_curl) + curl_close($connection); +else + @fclose($connection); + +?>