add internal/external server option to admin settings
This commit is contained in:
Родитель
fc78604fca
Коммит
169a3e0994
|
@ -20,6 +20,17 @@ if (!$auth) {
|
|||
}
|
||||
|
||||
$data = array ();
|
||||
$data ['serverType'] = OCP\Config::getAppValue ( 'ojsxc', 'serverType' );
|
||||
|
||||
if ($data ['serverType'] === 'internal') {
|
||||
OCP\JSON::encodedPrint ( array (
|
||||
'result' => 'success',
|
||||
'data' => $data
|
||||
) );
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$data ['xmpp'] = array ();
|
||||
$data ['xmpp'] ['url'] = OCP\Config::getAppValue ( 'ojsxc', 'boshUrl' );
|
||||
$data ['xmpp'] ['domain'] = OCP\Config::getAppValue ( 'ojsxc', 'xmppDomain' );
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
OCP\User::checkAdminUser ();
|
||||
OCP\JSON::callCheck ();
|
||||
|
||||
OCP\Config::setAppValue ( 'ojsxc', 'serverType', $_POST ['serverType'] );
|
||||
OCP\Config::setAppValue ( 'ojsxc', 'boshUrl', $_POST ['boshUrl'] );
|
||||
OCP\Config::setAppValue ( 'ojsxc', 'xmppDomain', $_POST ['xmppDomain'] );
|
||||
OCP\Config::setAppValue ( 'ojsxc', 'xmppResource', $_POST ['xmppResource'] );
|
||||
|
|
|
@ -11,14 +11,12 @@ OCP\App::registerAdmin ( 'ojsxc', 'settings' );
|
|||
|
||||
$jsxc_root = (defined('JSXC_ENV') && JSXC_ENV === 'dev')? 'jsxc/dev/' : 'jsxc/';
|
||||
|
||||
if(\OCP\User::isLoggedIn()) {
|
||||
OCP\Util::addScript ( 'ojsxc', $jsxc_root.'lib/jquery.slimscroll' );
|
||||
OCP\Util::addScript ( 'ojsxc', $jsxc_root.'lib/jquery.fullscreen' );
|
||||
OCP\Util::addScript ( 'ojsxc', $jsxc_root.'lib/jsxc.dep' );
|
||||
OCP\Util::addScript ( 'ojsxc', $jsxc_root.'jsxc' );
|
||||
OCP\Util::addScript('ojsxc', 'ojsxc');
|
||||
OCP\Util::addScript('ojsxc', 'oc-backend');
|
||||
}
|
||||
OCP\Util::addScript ( 'ojsxc', $jsxc_root.'lib/jquery.slimscroll' );
|
||||
OCP\Util::addScript ( 'ojsxc', $jsxc_root.'lib/jquery.fullscreen' );
|
||||
OCP\Util::addScript ( 'ojsxc', $jsxc_root.'lib/jsxc.dep' );
|
||||
OCP\Util::addScript ( 'ojsxc', $jsxc_root.'jsxc' );
|
||||
OCP\Util::addScript('ojsxc', 'ojsxc');
|
||||
|
||||
// ############# CSS #############
|
||||
OCP\Util::addStyle ( 'ojsxc', 'jquery.mCustomScrollbar' );
|
||||
OCP\Util::addStyle ( 'ojsxc', 'jquery.colorbox' );
|
||||
|
|
165
js/admin.js
165
js/admin.js
|
@ -1,52 +1,151 @@
|
|||
/* global $, OC */
|
||||
|
||||
$(document).ready(function() {
|
||||
$('#ojsxc').submit(function(event) {
|
||||
event.preventDefault();
|
||||
|
||||
// clear area
|
||||
$('#ojsxc .msg').html(' ');
|
||||
|
||||
var post = $(this).serialize();
|
||||
var status = $('<div/>').html('<img src="' + jsxc.options.root + '/img/loading.gif" alt="wait" width="16px" height="16px" />');
|
||||
|
||||
var statusBosh = status.clone().html(status.html() + " Testing BOSH Server...");
|
||||
$('#ojsxc .msg').append(statusBosh);
|
||||
|
||||
/**
|
||||
* Test if bosh server is up and running.
|
||||
*
|
||||
* @param {string} url BOSH url
|
||||
* @param {string} domain host domain for BOSH server
|
||||
* @param {Function} cb called if test is done
|
||||
*/
|
||||
function testBoshServer(url, domain, cb) {
|
||||
var rid = jsxc.storage.getItem('rid') || '123456';
|
||||
var xmppDomain = $('#xmppDomain').val();
|
||||
var fail = function() {
|
||||
statusBosh.addClass('jsxc_fail').text('BOSH server NOT reachable. Please beware of the same-origin-policy (SOP). If your XMPP server doesn\'t reside on the same host as your OwnCloud (same port/protocol), use the Apache ProxyRequest or modify the content-security-policy (CSP) by defining "custom_csp_policy" in OwnCloud\'s config.php.');
|
||||
};
|
||||
|
||||
function fail(m) {
|
||||
var msg = 'BOSH server NOT reachable or misconfigured.';
|
||||
|
||||
if (typeof m === 'string') {
|
||||
msg += '<br /><br />' + m;
|
||||
}
|
||||
|
||||
cb({
|
||||
status: 'fail',
|
||||
msg: msg
|
||||
});
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: $('#boshUrl').val(),
|
||||
data: "<body rid='" + rid + "' xmlns='http://jabber.org/protocol/httpbind' to='" + xmppDomain + "' xml:lang='en' wait='60' hold='1' content='text/xml; charset=utf-8' ver='1.6' xmpp:version='1.0' xmlns:xmpp='urn:xmpp:xbosh'/>",
|
||||
global: false
|
||||
url: url,
|
||||
data: "<body rid='" + rid + "' xmlns='http://jabber.org/protocol/httpbind' to='" + domain + "' xml:lang='en' wait='60' hold='1' content='text/xml; charset=utf-8' ver='1.6' xmpp:version='1.0' xmlns:xmpp='urn:xmpp:xbosh'/>",
|
||||
global: false,
|
||||
dataType: 'xml'
|
||||
}).done(function(stanza) {
|
||||
if (typeof stanza === 'string') {
|
||||
// shouldn't be needed anymore, because of dataType
|
||||
stanza = $.parseXML(stanza);
|
||||
}
|
||||
|
||||
var body = $(stanza).find('body[xmlns="http://jabber.org/protocol/httpbind"]');
|
||||
var condition = (body) ? body.attr('condition') : null;
|
||||
var type = (body) ? body.attr('type') : null;
|
||||
|
||||
if (body.length > 0 && condition != 'internal-server-error') {
|
||||
statusBosh.addClass('jsxc_success').text('BOSH Server reachable.');
|
||||
// we got a valid xml response, but we have test for errors
|
||||
|
||||
if (body.length > 0 && type !== 'terminate') {
|
||||
cb({
|
||||
status: 'success',
|
||||
msg: 'BOSH Server reachable.'
|
||||
});
|
||||
} else {
|
||||
fail();
|
||||
if (condition == 'internal-server-error') {
|
||||
statusBosh.html(statusBosh.text() + ' <br /><br /><b>Error: </b>' + body.text());
|
||||
if (condition === 'internal-server-error') {
|
||||
fail('Internal server error: ' + body.text());
|
||||
} else if (condition === 'host-unknown') {
|
||||
if (url) {
|
||||
fail('Host unknown: ' + domain + ' is unknown to your XMPP server.');
|
||||
} else {
|
||||
fail('Host unknown: Please provide a XMPP domain.');
|
||||
}
|
||||
} else {
|
||||
fail(condition);
|
||||
}
|
||||
}
|
||||
}).fail(function(xhr, textStatus) {
|
||||
// no valid xml, not found or csp issue
|
||||
|
||||
var fullurl;
|
||||
if (url.match(/^https?:\/\//)) {
|
||||
fullurl = url;
|
||||
} else {
|
||||
fullurl = window.location.protocol + '//' + window.location.host;
|
||||
if (url.match(/^\//)) {
|
||||
fullurl += url;
|
||||
} else {
|
||||
fullurl += window.location.pathname.replace(/[^/]+$/, "") + url;
|
||||
}
|
||||
}
|
||||
|
||||
}).fail(fail);
|
||||
if(xhr.status === 0) {
|
||||
// cross-side
|
||||
fail('Cross domain requests are not possible with the current same-origin-policy (SOP). ' +
|
||||
'You have to use Apache ProxyRequest or Nginx proxy_pass.');
|
||||
} else if (xhr.status === 404) {
|
||||
// not found
|
||||
fail('Your server responded with "404 Not Found". Please check if your BOSH server is running and reachable via ' + fullurl + '.');
|
||||
} else if (textStatus === 'parsererror') {
|
||||
fail('Invalid XML received. Maybe ' + fullurl + ' was redirected. You should use an absolute url.');
|
||||
} else {
|
||||
fail(xhr.status + ' ' + xhr.statusText);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var statusSet = status.clone().html(status.html() + " Saving...");
|
||||
$('#ojsxc .msg').append(statusSet);
|
||||
$('#ojsxc [name=serverType]').change(function(){
|
||||
$('#ojsxc .ojsxc-external, #ojsxc .ojsxc-internal').hide();
|
||||
$('#ojsxc .ojsxc-' + $(this).val()).show();
|
||||
});
|
||||
$('#ojsxc [name=serverType]:checked').change();
|
||||
|
||||
$('#boshUrl, #xmppDomain').on('input', function(){
|
||||
var self = $(this);
|
||||
var timeout = self.data('timeout');
|
||||
|
||||
if (timeout) {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
|
||||
var url = $('#boshUrl').val();
|
||||
var domain = $('#xmppDomain').val();
|
||||
|
||||
if (!url || !domain) {
|
||||
// we need url and domain to test BOSH server
|
||||
return;
|
||||
}
|
||||
|
||||
$('#ojsxc .boshUrl-msg').html('<div></div>');
|
||||
var status = $('#ojsxc .boshUrl-msg div');
|
||||
status.html('<img src="' + jsxc.options.root + '/img/loading.gif" alt="wait" width="16px" height="16px" /> Testing BOSH Server...');
|
||||
|
||||
// test only every 2 seconds
|
||||
timeout = setTimeout(function() {
|
||||
testBoshServer(url, domain, function(res) {
|
||||
status.addClass('jsxc_' + res.status);
|
||||
status.html(res.msg);
|
||||
});
|
||||
}, 2000);
|
||||
|
||||
self.data('timeout', timeout);
|
||||
});
|
||||
|
||||
$('#ojsxc').submit(function(event) {
|
||||
event.preventDefault();
|
||||
|
||||
var post = $(this).serialize();
|
||||
|
||||
$('#ojsxc .msg').html('<div>');
|
||||
var status = $('#ojsxc .msg div');
|
||||
status.html('<img src="' + jsxc.options.root + '/img/loading.gif" alt="wait" width="16px" height="16px" /> Saving...');
|
||||
|
||||
$.post(OC.filePath('ojsxc', 'ajax', 'setsettings.php'), post, function(data) {
|
||||
if (data)
|
||||
statusSet.addClass('jsxc_success').text('Settings saved.');
|
||||
else
|
||||
statusSet.addClass('jsxc_fail').text('Error!');
|
||||
});
|
||||
if (data) {
|
||||
status.addClass('jsxc_success').text('Settings saved.');
|
||||
} else {
|
||||
status.addClass('jsxc_fail').text('Error!');
|
||||
}
|
||||
|
||||
setTimeout(function(){
|
||||
status.hide('slow');
|
||||
}, 3000);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
2
js/jsxc
2
js/jsxc
|
@ -1 +1 @@
|
|||
Subproject commit a14cfde5db73135d5ff2a11bcc69fe7b3d1a46b8
|
||||
Subproject commit 3669cfca6557129cf0dcb361135e7adac0480a9c
|
|
@ -1,7 +0,0 @@
|
|||
/* global OC */
|
||||
$(document).ready(function () {
|
||||
jsxc.options.xmpp.url = OC.generateUrl('apps/ojsxc/http-bind');
|
||||
jsxc.start(OC.currentUser + '@' + OC.getHost(), Math.floor(Math.random() * (1000 - 1)) + 1, Math.floor(Math.random() * (1000 - 1)) + 1);
|
||||
jsxc.xmpp.conn.resume();
|
||||
jsxc.onMaster();
|
||||
});
|
15
js/ojsxc.js
15
js/ojsxc.js
|
@ -236,9 +236,20 @@ $(function() {
|
|||
username: username,
|
||||
password: password
|
||||
},
|
||||
success: function(d) {
|
||||
if (d.result === 'success' && d.data.xmpp.url !== '' && d.data.xmpp.url !== null) {
|
||||
success: function(d) { console.log('success', d);
|
||||
if (d.result === 'success' && d.data.serverType !== 'internal' && d.data.xmpp.url !== '' && d.data.xmpp.url !== null) {
|
||||
cb(d.data);
|
||||
} else if (d.data.serverType === 'internal') {
|
||||
// fake successful connection
|
||||
jsxc.storage.setItem('jid', username + '@' + window.location.host + '/internal');
|
||||
jsxc.storage.setItem('sid', 'internal');
|
||||
jsxc.storage.setItem('rid', '123456');
|
||||
jsxc.bid = username + '@' + window.location.host;
|
||||
jsxc.options.set('xmpp', {
|
||||
url: OC.generateUrl('apps/ojsxc/http-bind')
|
||||
});
|
||||
|
||||
cb(false);
|
||||
} else {
|
||||
cb(false);
|
||||
}
|
||||
|
|
|
@ -34,6 +34,50 @@
|
|||
}
|
||||
}
|
||||
|
||||
#ojsxc {
|
||||
.form-group {
|
||||
margin-bottom: 0.8em;
|
||||
}
|
||||
.form-offset-label {
|
||||
@media (min-width: 768px) {
|
||||
padding-left: 280px;
|
||||
}
|
||||
}
|
||||
label {
|
||||
box-sizing: border-box;
|
||||
padding-right: 15px;
|
||||
display: inline-block;
|
||||
@media (min-width: 768px) {
|
||||
width: 280px;
|
||||
text-align: right;
|
||||
}
|
||||
}
|
||||
input {
|
||||
box-sizing: border-box;
|
||||
padding-right: 15px;
|
||||
display: inline-block;
|
||||
width: 100%;
|
||||
&[type='checkbox'] {
|
||||
width: auto;
|
||||
}
|
||||
@media (min-width: 768px) {
|
||||
width: auto;
|
||||
}
|
||||
}
|
||||
input+label {
|
||||
width: auto;
|
||||
}
|
||||
input+label+em {
|
||||
padding-left: 20px;
|
||||
}
|
||||
em, .boshUrl-msg {
|
||||
display: block;
|
||||
@media (min-width: 768px) {
|
||||
padding-left: 280px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
%msg {
|
||||
border: 1px solid #fff;
|
||||
border-radius: 3px;
|
||||
|
|
|
@ -5,7 +5,8 @@ OCP\Util::addScript ( "ojsxc", "admin" );
|
|||
|
||||
$tmpl = new OCP\Template ( 'ojsxc', 'settings' );
|
||||
|
||||
$tmpl->assign ( 'boshUrl', OCP\Config::getAppValue ( 'ojsxc', 'boshUrl' ) );
|
||||
$tmpl->assign ( 'serverType', OCP\Config::getAppValue ( 'ojsxc', 'serverType' ));
|
||||
$tmpl->assign ( 'boshUrl', OCP\Config::getAppValue ( 'ojsxc', 'boshUrl' ));
|
||||
$tmpl->assign ( 'xmppDomain', OCP\Config::getAppValue ( 'ojsxc', 'xmppDomain' ) );
|
||||
$tmpl->assign ( 'xmppResource', OCP\Config::getAppValue ( 'ojsxc', 'xmppResource' ) );
|
||||
$tmpl->assign ( 'xmppOverwrite', OCP\Config::getAppValue ( 'ojsxc', 'xmppOverwrite' ) );
|
||||
|
|
|
@ -1,62 +1,77 @@
|
|||
<div class="section">
|
||||
<h2>Owncloud JavaScript Xmpp Client</h2>
|
||||
<h2>JavaScript Xmpp Client</h2>
|
||||
<form id="ojsxc">
|
||||
<table style="width: auto">
|
||||
<tr>
|
||||
<td><label for="boshUrl">* BOSH url</label></td>
|
||||
<td><input type="text" name="boshUrl" id="boshUrl" value="<?php p($_['boshUrl']); ?>" /></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="xmppDomain">* XMPP domain</label></td>
|
||||
<td><input type="text" name="xmppDomain" id="xmppDomain" value="<?php p($_['xmppDomain']); ?>" /></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="xmppResource">XMPP resource</label></td>
|
||||
<td><input type="text" name="xmppResource" id="xmppResource" value="<?php p($_['xmppResource']); ?>" /></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="xmppOverwrite">Allow user to overwrite XMPP settings</label></td>
|
||||
<td><input type="checkbox" name="xmppOverwrite" id="xmppOverwrite" value="true" <?php if($_['xmppOverwrite'] === 'true' || $_['xmppOverwrite'] === true) echo "checked"; ?> /></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="xmppStartMinimized">Hide roster after first login</label></td>
|
||||
<td><input type="checkbox" name="xmppStartMinimized" id="xmppStartMinimized" value="true" <?php if($_['xmppStartMinimized'] === 'true' || $_['xmppStartMinimized'] === true) echo "checked"; ?> /></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="iceUrl">TURN Url</label></td>
|
||||
<td><input type="text" name="iceUrl" id="iceUrl" value="<?php p($_['iceUrl']); ?>" /></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="iceUsername">TURN Username</label></td>
|
||||
<td><input type="text" name="iceUsername" id="iceUrl" value="<?php p($_['iceUsername']); ?>" /></td>
|
||||
<td><em>If no username is set, TURN-REST-API credentials are used.</em></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="iceCredential">TURN Credential</label></td>
|
||||
<td><input type="text" name="iceCredential" id="iceCredential" value="<?php p($_['iceCredential']); ?>" /></td>
|
||||
<td><em>If no password is set, TURN-REST-API credentials are used.</em></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="iceSecret">TURN Secret</label></td>
|
||||
<td><input type="text" name="iceSecret" id="iceSecret" value="<?php p($_['iceSecret']); ?>" /></td>
|
||||
<td><em>Secret for TURN-REST-API credentials as described <a href="http://tools.ietf.org/html/draft-uberti-behave-turn-rest-00" target="_blank">here</a>.
|
||||
</em></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="iceTtl">TURN TTL</label></td>
|
||||
<td><input type="text" name="iceTtl" id="iceTtl" value="<?php p($_['iceTtl']); ?>" /></td>
|
||||
<td><em>Lifetime for TURN-REST-API credentials in seconds.</em></td>
|
||||
</tr>
|
||||
</table>
|
||||
<div class="form-group">
|
||||
<input type="radio" name="serverType" id="serverTypeInternal" value="internal" <?php if($_['serverType'] === 'internal')echo 'checked'; ?> />
|
||||
<label for="serverTypeInternal">Internal (Experimental)</label>
|
||||
<em>Internal server is not ready for production and contains not all features of an external server. To be precise only one-to-one messages are possible.</em>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="radio" name="serverType" id="serverTypeExternal" value="external" <?php if($_['serverType'] === 'external')echo 'checked'; ?> />
|
||||
<label for="serverTypeExternal">External</label>
|
||||
<em>Choose this option to use your own XMPP server.</em>
|
||||
</div>
|
||||
|
||||
<div class="ojsxc-internal hidden">
|
||||
<div>
|
||||
<div class="msg"></div>
|
||||
|
||||
<input type="submit" value="Save settings" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ojsxc-external hidden">
|
||||
<div class="form-group">
|
||||
<label for="xmppDomain">* XMPP domain</label>
|
||||
<input type="text" name="xmppDomain" id="xmppDomain" required="required" value="<?php p($_['xmppDomain']); ?>" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="boshUrl">* BOSH url</label>
|
||||
<input type="text" name="boshUrl" id="boshUrl" required="required" value="<?php p($_['boshUrl']); ?>" />
|
||||
<div class="boshUrl-msg"></div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="xmppResource">XMPP resource</label>
|
||||
<input type="text" name="xmppResource" id="xmppResource" value="<?php p($_['xmppResource']); ?>" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="xmppOverwrite">Allow user to overwrite XMPP settings</label>
|
||||
<input type="checkbox" name="xmppOverwrite" id="xmppOverwrite" value="true" <?php if($_['xmppOverwrite'] === 'true' || $_['xmppOverwrite'] === true) echo "checked"; ?> />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="xmppStartMinimized">Hide roster after first login</label>
|
||||
<input type="checkbox" name="xmppStartMinimized" id="xmppStartMinimized" value="true" <?php if($_['xmppStartMinimized'] === 'true' || $_['xmppStartMinimized'] === true) echo "checked"; ?> />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="iceUrl">TURN Url</label>
|
||||
<input type="text" name="iceUrl" id="iceUrl" value="<?php p($_['iceUrl']); ?>" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="iceUsername">TURN Username</label>
|
||||
<input type="text" name="iceUsername" id="iceUrl" value="<?php p($_['iceUsername']); ?>" />
|
||||
<em>If no username is set, TURN-REST-API credentials are used.</em>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="iceCredential">TURN Credential</label>
|
||||
<input type="text" name="iceCredential" id="iceCredential" value="<?php p($_['iceCredential']); ?>" />
|
||||
<em>If no password is set, TURN-REST-API credentials are used.</em>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="iceSecret">TURN Secret</label>
|
||||
<input type="text" name="iceSecret" id="iceSecret" value="<?php p($_['iceSecret']); ?>" />
|
||||
<em>Secret for TURN-REST-API credentials as described <a href="http://tools.ietf.org/html/draft-uberti-behave-turn-rest-00" target="_blank">here</a>.</em>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="iceTtl">TURN TTL</label>
|
||||
<input type="text" name="iceTtl" id="iceTtl" value="<?php p($_['iceTtl']); ?>" />
|
||||
<em>Lifetime for TURN-REST-API credentials in seconds.</em>
|
||||
</div>
|
||||
|
||||
<div class="msg"></div>
|
||||
|
||||
<input type="submit" value="Save settings" />
|
||||
<div class="form-offset-label">
|
||||
<div class="msg"></div>
|
||||
|
||||
<input type="submit" value="Save settings" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
|
Загрузка…
Ссылка в новой задаче