Skip to content

Commit 4576820

Browse files
author
Leon Klingele
committed
Merge branch 'auto-generate-minimal-spreed-webrtc-config' into develop
2 parents f668070 + 361b2f1 commit 4576820

File tree

8 files changed

+94
-21
lines changed

8 files changed

+94
-21
lines changed

README.md

+6-20
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,16 @@ Your server has to be available via HTTPS. If your Nextcloud server is not using
2121
1. Place this app in the **apps/** folder of your Nextcloud installation. Make sure the directory of this app is named `spreedme`.
2222
2. Enable this Nextcloud app by browsing to **/index.php/settings/apps**
2323
3. Open the Nextcloud admin settings page (**/index.php/settings/admin#goto-spreed.me**) in your browser and configure this app:
24-
1. Click on **Generate new shared secret**. It will output a random string which you will need in one of the next steps. Copy it to your clipboard.
24+
1. Click on **Generate Spreed WebRTC config**. It will output the Spreed WebRTC configuration you will need in one of the next steps. Copy it to your clipboard.
2525
2. Click on **Save settings**.
2626
4. Set up a Spreed WebRTC server and continue with the next step.
2727
An easy-to-follow installation guideline can be found further below, see [Installation / Setup of a Spreed WebRTC server](#installation--setup-of-a-spreed-webrtc-server).
2828
5. You now should have a running Spreed WebRTC server.
29-
6. This app requires you to change some settings in the `server.conf` of the Spreed WebRTC server (`webrtc.conf` if you use the packaged version), namely:
30-
1. In the **[http]** section:
31-
- Enable (= uncomment) **basePath** and set it to **/webrtc/**
32-
(`basePath = /webrtc/`)
33-
2. In the **[app]** section:
34-
- Enable **authorizeRoomJoin** and set it to **true**
35-
(`authorizeRoomJoin = true`)
36-
- Enable **extra** and set it to the full absolute path of the **spreedme/extra** directory in your **apps** folder of your Nextcloud installation
37-
(e.g. `extra = /absolute/path/to/nextcloud/apps/spreedme/extra`)
38-
- Enable **plugin** and set it to **extra/static/owncloud.js**
39-
(`plugin = extra/static/owncloud.js`)
40-
3. In the **[users]** section:
41-
- Enable **enabled** and set it to **true**
42-
(`enabled = true`)
43-
- Enable **mode** and set it to **sharedsecret**
44-
(`mode = sharedsecret`)
45-
- Enable **sharedsecret_secret** and set it to the random string from step 1.
46-
(e.g. `sharedsecret_secret = bb04fb058e2d7fd19c5bdaa129e7883195f73a9c49414a7eXXXXXXXXXXXXXXXX`)
47-
4. Restart the Spreed WebRTC server to reload its configuration
29+
6. This app requires you to change some settings in the `server.conf` of the Spreed WebRTC server (`webrtc.conf` if you use the packaged version):
30+
1. Empty the contents of the file.
31+
2. Paste in the Spreed WebRTC config from step 1 (you should have it in your clipboard).
32+
3. Save the file.
33+
4. Restart the Spreed WebRTC server to reload its configuration.
4834
7. **That's it.** You can now start communicating securely with your friends and family by opening the **Spreed.ME app** of your Nextcloud host in your browser.
4935

5036
## Limiting access to this app

appinfo/routes.php

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
['name' => 'api#save_config', 'url' => '/api/v1/admin/config', 'verb' => 'PATCH'],
2929
['name' => 'api#regenerate_shared_secret', 'url' => '/api/v1/admin/config/regenerate/sharedsecret', 'verb' => 'POST'],
3030
['name' => 'api#regenerate_temporary_password_signing_key', 'url' => '/api/v1/admin/config/regenerate/tp-key', 'verb' => 'POST'],
31+
['name' => 'api#generate_spreed_webrtc_config', 'url' => '/api/v1/admin/config/generate/spreed-webrtc-config', 'verb' => 'POST'],
3132
['name' => 'api#download_file', 'url' => '/api/v1/file/download', 'verb' => 'GET'],
3233
],
3334
];

controller/apicontroller.php

+12
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,18 @@ public function regenerateTemporaryPasswordSigningKey() {
192192
return new DataResponse($_response);
193193
}
194194

195+
public function generateSpreedWebRTCConfig() {
196+
$_response = array('success' => false);
197+
try {
198+
$_response['config'] = Security::generateSpreedWebRTCConfig();
199+
$_response['success'] = true;
200+
} catch (\Exception $e) {
201+
$_response['error'] = $e->getCode();
202+
}
203+
204+
return new DataResponse($_response);
205+
}
206+
195207
/**
196208
* @NoAdminRequired
197209
*/

css/settings-admin.css

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
#spreedme form button[type="submit"] {
5252
margin-top: 15px;
5353
}
54+
#spreedme form textarea[name="SPREED_WEBRTC_CONFIG"] {
55+
width: 660px;
56+
height: 360px;
57+
}
5458

5559
/* TODO(leon): You know.. */
5660
#spreedme > div:not(.show-if-php-config-file):not(.show-if-php-config-database):not(:first-of-type) {

doc/spreed-webrtc-minimal-config.txt

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; Minimal Spreed WebRTC configuration for Nextcloud
2+
3+
[http]
4+
listen = 127.0.0.1:8080
5+
basePath = /webrtc/
6+
7+
[app]
8+
sessionSecret = the-default-secret-do-not-keep-me
9+
encryptionSecret = the-default-encryption-block-key
10+
authorizeRoomJoin = true
11+
serverToken = i-did-not-change-the-public-token-boo
12+
serverRealm = local
13+
extra = /absolute/path/to/nextcloud/apps/spreedme/extra
14+
plugin = extra/static/owncloud.js
15+
16+
[users]
17+
enabled = true
18+
mode = sharedsecret
19+
sharedsecret_secret = some-secret-do-not-keep

js/settings-admin.js

+26
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,22 @@ $(document).ready(function() {
8080
console.log(response, code);
8181
});
8282
};
83+
var generateSpreedWebRTCConfig = function(cb_success, cb_error) {
84+
$.ajax({
85+
url: baseUrl + '/api/v1/admin/config/generate/spreed-webrtc-config',
86+
type: 'POST',
87+
data: {},
88+
}).done(function (response) {
89+
if (response.success === true) {
90+
removeMessage();
91+
cb_success(response.config);
92+
} else {
93+
cb_error(response.error);
94+
}
95+
}).fail(function (response, code) {
96+
console.log(response, code);
97+
});
98+
};
8399

84100
$c.find('[name="OWNCLOUD_ORIGIN"]').val(OwnCloudConfig.OWNCLOUD_ORIGIN);
85101
$c.find('.needs-confirmation').click(function(e) {
@@ -115,6 +131,16 @@ $(document).ready(function() {
115131

116132
});
117133
});
134+
$c.find('[name="GENERATE_SPREED_WEBRTC_CONFIG"]').click(function(e) {
135+
generateSpreedWebRTCConfig(function(config) {
136+
$c.find('.SPREED_WEBRTC_CONFIG')
137+
.removeClass('hidden')
138+
.find('textarea')
139+
.val(config);
140+
}, function(error) {
141+
142+
});
143+
});
118144

119145
$c.find('form').submit(function(e) {
120146
e.preventDefault();

security/security.php

+16
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,22 @@ public static function regenerateTemporaryPasswordSigningKey() {
179179
Helper::setDatabaseConfigValueIfEnabled('OWNCLOUD_TEMPORARY_PASSWORD_SIGNING_KEY', $key);
180180
}
181181

182+
public static function generateSpreedWebRTCConfig() {
183+
$config = file_get_contents(Helper::getOwnAppPath() . 'doc/spreed-webrtc-minimal-config.txt');
184+
if (Helper::getDatabaseConfigValue('SPREED_WEBRTC_SHAREDSECRET') === '') {
185+
self::regenerateSharedSecret();
186+
}
187+
$replace = array(
188+
'/webrtc/' => Helper::getDatabaseConfigValueOrDefault('SPREED_WEBRTC_BASEPATH'),
189+
'the-default-secret-do-not-keep-me' => self::getRandomHexString(256 / 4), // 256 bit
190+
'the-default-encryption-block-key' => self::getRandomHexString(256 / 4), // 256 bit
191+
'i-did-not-change-the-public-token-boo' => self::getRandomHexString(256 / 4), // 256 bit
192+
'/absolute/path/to/nextcloud/apps/spreedme/extra' => Helper::getOwnAppPath() . 'extra',
193+
'some-secret-do-not-keep' => Helper::getDatabaseConfigValue('SPREED_WEBRTC_SHAREDSECRET'),
194+
);
195+
return strtr($config, $replace);
196+
}
197+
182198
public static function constantTimeEquals($a, $b) {
183199
$alen = strlen($a);
184200
$blen = strlen($b);

templates/settings-admin.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,22 @@
2828
<p><code>config/config.php</code> was not found. We will use the Nextcloud database to read/write config values.</p>
2929
<p>You can change them here:</p>
3030
<form action="#" method="POST">
31+
<p class="hidden SPREED_WEBRTC_CONFIG warning">
32+
<label for="SPREED_WEBRTC_CONFIG">A new SPREED_WEBRTC_CONFIG was generated.<br />Simply remove everything from your current <code>server.conf</code> and paste the new config in instead.<br />Restart Spreed WebRTC afterwards.</label>
33+
<textarea id="SPREED_WEBRTC_CONFIG" name="SPREED_WEBRTC_CONFIG" readonly="readonly" class="select-on-click"></textarea>
34+
</p>
35+
<p>
36+
<label for="GENERATE_SPREED_WEBRTC_CONFIG">SPREED_WEBRTC_CONFIG:</label>
37+
<input type="button" id="GENERATE_SPREED_WEBRTC_CONFIG" name="GENERATE_SPREED_WEBRTC_CONFIG"
38+
value="Generate Spreed WebRTC config" />
39+
</p>
3140
<p class="hidden SPREED_WEBRTC_SHAREDSECRET warning">
3241
<!-- label for and input id removed intentionally. This makes it possible to copy&paste 'sharedsecret_secret' -->
3342
<label>A new SPREED_WEBRTC_SHAREDSECRET was generated.<br />Use it for <code>sharedsecret_secret</code> in Spreed WebRTC's configuration.<br />Restart Spreed WebRTC afterwards.</label>
3443
<input type="text" name="SPREED_WEBRTC_SHAREDSECRET" placeholder="" readonly="readonly"
3544
class="select-on-click" value="" />
3645
</p>
37-
<p>
46+
<p class="show-if-advanced-settings">
3847
<label for="REGENERATE_SPREED_WEBRTC_SHAREDSECRET">SPREED_WEBRTC_SHAREDSECRET:</label>
3948
<input type="button" id="REGENERATE_SPREED_WEBRTC_SHAREDSECRET" name="REGENERATE_SPREED_WEBRTC_SHAREDSECRET"
4049
class="needs-confirmation" data-confirmation-message="Do you really want to generate a new shared secret?\nYou will need to change it in Spreed WebRTC's configuration, too." value="Generate new shared secret" />

0 commit comments

Comments
 (0)