Skip to content

Commit

Permalink
v3.2.0-beta.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sualko committed Apr 5, 2017
1 parent 501320f commit a2c8d21
Show file tree
Hide file tree
Showing 25 changed files with 5,579 additions and 4,109 deletions.
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<name>JavaScript XMPP Chat</name>
<summary>Facebook-like chat</summary>
<description>Facebook-like chat with end-to-end encrypted conversation, video calls, multi-user rooms, XMPP and internal server backend.</description>
<version>3.1.1</version>
<version>3.2.0-beta.1</version>
<licence>agpl</licence>
<author mail="klaus@jsxc.org">Klaus Herberth</author>
<author>Tobia De Koninck</author>
Expand Down
70 changes: 70 additions & 0 deletions build/ajax/externalApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

header('Content-Type: application/json; charset=utf-8');

$config = \OC::$server->getConfig();
$apiSecret = $config->getAppValue('ojsxc', 'apiSecret');

function abort($msg) {
http_response_code(500);

\OCP\Util::writeLog('ojsxc', 'ExAPI: Abort with message: '.$msg, \OCP\Util::WARN );

die(json_encode(array(
'result' => 'error',
'data' => array(
'msg' => $msg
),
)));
}

function checkPassword() {
$currentUser = null;

\OCP\Util::writeLog('ojsxc', 'ExAPI: Check password for user: '.$_POST['username'], \OCP\Util::INFO );

if(!empty($_POST['password']) && !empty($_POST['username'])) {
$currentUser = \OC::$server->getUserManager()->checkPassword($_POST['username'], $_POST['password']);
}

if (!$currentUser) {
echo json_encode(array(
'result' => 'noauth',
));
exit();
}

$data = array();
$data ['uid'] = $currentUser->getUID();

echo json_encode(array(
'result' => 'success',
'data' => $data,
));
}

// check if we have a signature
if ( ! isset( $_SERVER[ 'HTTP_X_JSXC_SIGNATURE' ] ) )
abort( 'HTTP header "X-JSXC-Signature" is missing.' );
else if ( ! extension_loaded( 'hash' ) )
abort( 'Missing "hash" extension to check the secret code validity.' );
else if ( ! $apiSecret)
abort( 'Missing secret.' );

// check if the algo is supported
list( $algo, $hash ) = explode( '=', $_SERVER[ 'HTTP_X_JSXC_SIGNATURE' ], 2 ) + array( '', '' );
if ( ! in_array( $algo, hash_algos(), TRUE ) )
abort( "Hash algorithm '$algo' is not supported." );

// check if the key is valid
$rawPost = file_get_contents( 'php://input' );
if ( $hash !== hash_hmac( $algo, $rawPost, $apiSecret ) )
abort( 'Signature does not match.' );

switch($_POST['operation']) {
case 'auth':
checkPassword();
break;
default:
abort( "Unsupported operation." );
}
44 changes: 32 additions & 12 deletions build/ajax/getSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ function validateBoolean($val)

$currentUser = false;

if(!empty($_POST['password']) && !empty($_POST['username'])) {
$currentUser = \OC::$server->getUserManager()->checkPassword($_POST['username'], $_POST['password']);
} else if (OCP\User::isLoggedIn()) {
if (OCP\User::isLoggedIn()) {
$currentUser = \OC::$server->getUserSession()->getUser();
} else if(!empty($_POST['password']) && !empty($_POST['username'])) {
$currentUser = \OC::$server->getUserManager()->checkPassword($_POST['username'], $_POST['password']);
}

if (!$currentUser) {
Expand Down Expand Up @@ -52,15 +52,35 @@ function validateBoolean($val)
$data ['xmpp'] ['onlogin'] = null;

if (validateBoolean($config->getAppValue('ojsxc', 'xmppPreferMail'))) {
$mail = $config->getUserValue($currentUID,'settings','email');

if ($mail !== null) {
list($u, $d) = explode("@", $mail, 2);
if ($d !== null && $d !== "") {
$data ['xmpp'] ['username'] = $u;
$data ['xmpp'] ['domain'] = $d;
}
}
$mail = $config->getUserValue($currentUID,'settings','email');

if ($mail !== null) {
list($u, $d) = explode("@", $mail, 2);
if ($d !== null && $d !== "") {
$data ['xmpp'] ['username'] = $u;
$data ['xmpp'] ['domain'] = $d;
}
}
}

if (validateBoolean($config->getAppValue('ojsxc', 'timeLimitedToken'))) {
$data['xmpp']['username'] = $currentUID;
$jid = $data['xmpp']['username'] . '@' . $data['xmpp']['domain'];
$expiry = time() + 60*60;
$secret = $config->getAppValue('ojsxc', 'apiSecret');

$version = hex2bin('00');
$secretID = substr(hash('sha256', $secret, true), 0, 2);
$header = $secretID.pack('N', $expiry);
$challenge = $version.$header.$jid;
$hmac = hash_hmac('sha256', $challenge, $secret, true);
$token = $version.substr($hmac, 0, 16).$header;

// format as "user-friendly" base64
$token = str_replace('=', '', strtr(base64_encode($token),
'OIl', '-$%'));

$data['xmpp']['password'] = $token;
}

$options = $config->getUserValue($currentUID, 'ojsxc', 'options');
Expand Down
12 changes: 9 additions & 3 deletions build/ajax/setAdminSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@
$config->setAppValue('ojsxc', 'boshUrl', trim($_POST ['boshUrl']));
$config->setAppValue('ojsxc', 'xmppDomain', trim($_POST ['xmppDomain']));
$config->setAppValue('ojsxc', 'xmppResource', trim($_POST ['xmppResource']));
$config->setAppValue('ojsxc', 'xmppOverwrite', (isset($_POST ['xmppOverwrite'])) ? $_POST ['xmppOverwrite'] : 'false');
$config->setAppValue('ojsxc', 'xmppStartMinimized', (isset($_POST ['xmppStartMinimized'])) ? $_POST ['xmppStartMinimized'] : 'false');
$config->setAppValue('ojsxc', 'xmppPreferMail', (isset($_POST ['xmppPreferMail'])) ? $_POST ['xmppPreferMail'] : 'false');
$config->setAppValue('ojsxc', 'xmppOverwrite', getCheckboxValue($_POST ['xmppOverwrite']));
$config->setAppValue('ojsxc', 'xmppStartMinimized', getCheckboxValue($_POST ['xmppStartMinimized']));
$config->setAppValue('ojsxc', 'xmppPreferMail', getCheckboxValue($_POST ['xmppPreferMail']));

$config->setAppValue('ojsxc', 'iceUrl', trim($_POST ['iceUrl']));
$config->setAppValue('ojsxc', 'iceUsername', trim($_POST ['iceUsername']));
$config->setAppValue('ojsxc', 'iceCredential', $_POST ['iceCredential']);
$config->setAppValue('ojsxc', 'iceSecret', $_POST ['iceSecret']);
$config->setAppValue('ojsxc', 'iceTtl', $_POST ['iceTtl']);

$config->setAppValue('ojsxc', 'timeLimitedToken', getCheckboxValue($_POST ['timeLimitedToken']));

$config->setAppValue('ojsxc', 'firefoxExtension', $_POST ['firefoxExtension']);
$config->setAppValue('ojsxc', 'chromeExtension', $_POST ['chromeExtension']);

Expand All @@ -43,3 +45,7 @@
$config->setAppValue('ojsxc', 'externalServices', implode('|', $externalServices));

echo 'true';

function getCheckboxValue($var) {
return (isset($var)) ? $var : 'false';
}
3 changes: 2 additions & 1 deletion build/appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
* Released under the MIT license
* @author Klaus Herberth <klaus@jsxc.org>
*/
OCP\App::registerAdmin ( 'ojsxc', 'settings' );
\OCP\App::registerAdmin ( 'ojsxc', 'settings/admin' );
\OCP\App::registerPersonal('ojsxc', 'settings/personal');

$jsxc_root = (defined('JSXC_ENV') && JSXC_ENV === 'dev')? 'jsxc/dev/' : 'jsxc/';

Expand Down
2 changes: 1 addition & 1 deletion build/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<name>JavaScript XMPP Chat</name>
<summary>Facebook-like chat</summary>
<description>Facebook-like chat with end-to-end encrypted conversation, video calls, multi-user rooms, XMPP and internal server backend.</description>
<version>3.1.1</version>
<version>3.2.0-beta.1</version>
<licence>agpl</licence>
<author mail="klaus@jsxc.org">Klaus Herberth</author>
<author>Tobia De Koninck</author>
Expand Down
5 changes: 4 additions & 1 deletion build/appinfo/routes.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php
/**
* ownCloud - JavaScript XMPP Chat
*
Expand All @@ -25,6 +25,9 @@
$this->create('ojsxc_ajax_getUsers', 'ajax/getUsers.php')
->actionInclude('ojsxc/ajax/getUsers.php');

$this->create('ojsxc_ajax_externalApi', 'ajax/externalApi.php')
->actionInclude('ojsxc/ajax/externalApi.php');

$application = new Application();
$application->registerRoutes($this, array(
'routes' => array(
Expand Down
Loading

0 comments on commit a2c8d21

Please sign in to comment.