Add janus_path and janus_secret, allowing for more secure and flexible Janus installs

pull/3413/head
Jonathan Bennett 2022-01-21 22:23:41 -06:00
parent 4eb4e0eb18
commit 52e48c02b6
8 changed files with 58 additions and 8 deletions

View File

@ -370,6 +370,28 @@ our @options = (
type => $types{boolean}, type => $types{boolean},
category => 'system', category => 'system',
}, },
{
name => 'ZM_JANUS_SECRET',
default => '',
description => 'Password for Janus streaming administration.',
help => q`This value should be set to a secure password,
and match the admin_key value in janus.plugin.streaming.config.
`,
type => $types{string},
category => 'system',
},
{
name => 'ZM_JANUS_PATH',
default => '',
description => 'URL for Janus HTTP/S port',
help => q`Janus requires HTTP/S communication to administer
and initiate h.264 streams. If left blank, this will default to
the ZM hostname, port 8088/janus. This setting is particularly
useful for putting janus behind a reverse proxy.
`,
type => $types{string},
category => 'system',
},
{ {
name => 'ZM_ENABLE_CSRF_MAGIC', name => 'ZM_ENABLE_CSRF_MAGIC',
default => 'yes', default => 'yes',

View File

@ -3383,7 +3383,12 @@ size_t Monitor::WriteCallback(void *contents, size_t size, size_t nmemb, void *u
int Monitor::add_to_janus() { int Monitor::add_to_janus() {
//TODO clean this up, add error checking, etc //TODO clean this up, add error checking, etc
std::string response; std::string response;
std::string endpoint = "127.0.0.1:8088/janus/"; std::string endpoint;
if ((config.janus_path != nullptr) && (config.janus_path[0] != '\0')) {
endpoint = config.janus_path;
} else {
endpoint = "127.0.0.1:8088/janus/";
}
std::string postData = "{\"janus\" : \"create\", \"transaction\" : \"randomString\"}"; std::string postData = "{\"janus\" : \"create\", \"transaction\" : \"randomString\"}";
std::string rtsp_username; std::string rtsp_username;
std::string rtsp_password; std::string rtsp_password;
@ -3425,6 +3430,7 @@ int Monitor::add_to_janus() {
if (pos == std::string::npos) return -1; if (pos == std::string::npos) return -1;
janus_id = response.substr(pos + 6, 16); janus_id = response.substr(pos + 6, 16);
response = ""; response = "";
endpoint += "/";
endpoint += janus_id; endpoint += janus_id;
postData = "{\"janus\" : \"attach\", \"plugin\" : \"janus.plugin.streaming\", \"transaction\" : \"randomString\"}"; postData = "{\"janus\" : \"attach\", \"plugin\" : \"janus.plugin.streaming\", \"transaction\" : \"randomString\"}";
curl_easy_setopt(curl, CURLOPT_URL,endpoint.c_str()); curl_easy_setopt(curl, CURLOPT_URL,endpoint.c_str());
@ -3445,8 +3451,10 @@ int Monitor::add_to_janus() {
//Assemble our actual request //Assemble our actual request
postData = "{\"janus\" : \"message\", \"transaction\" : \"randomString\", \"body\" : {"; postData = "{\"janus\" : \"message\", \"transaction\" : \"randomString\", \"body\" : {";
postData += "\"request\" : \"create\", \"admin_key\" : \"supersecret\", \"type\" : \"rtsp\", "; postData += "\"request\" : \"create\", \"admin_key\" : \"";
postData += "\"url\" : \""; postData += config.janus_secret;
postData += "\", \"type\" : \"rtsp\", ";
postData += "\"url\" : \"";
postData += rtsp_path; postData += rtsp_path;
postData += "\", \"rtsp_user\" : \""; postData += "\", \"rtsp_user\" : \"";
postData += rtsp_username; postData += rtsp_username;
@ -3474,7 +3482,12 @@ int Monitor::add_to_janus() {
int Monitor::remove_from_janus() { int Monitor::remove_from_janus() {
//TODO clean this up, add error checking, etc //TODO clean this up, add error checking, etc
std::string response; std::string response;
std::string endpoint = "127.0.0.1:8088/janus/"; std::string endpoint;
if ((config.janus_path != nullptr) && (config.janus_path[0] != '\0')) {
endpoint = config.janus_path;
} else {
endpoint = "127.0.0.1:8088/janus/";
}
std::string postData = "{\"janus\" : \"create\", \"transaction\" : \"randomString\"}"; std::string postData = "{\"janus\" : \"create\", \"transaction\" : \"randomString\"}";
std::size_t pos; std::size_t pos;
CURLcode res; CURLcode res;
@ -3495,6 +3508,7 @@ int Monitor::remove_from_janus() {
if (pos == std::string::npos) return -1; if (pos == std::string::npos) return -1;
std::string janus_id = response.substr(pos + 6, 16); std::string janus_id = response.substr(pos + 6, 16);
response = ""; response = "";
endpoint += "/";
endpoint += janus_id; endpoint += janus_id;
postData = "{\"janus\" : \"attach\", \"plugin\" : \"janus.plugin.streaming\", \"transaction\" : \"randomString\"}"; postData = "{\"janus\" : \"attach\", \"plugin\" : \"janus.plugin.streaming\", \"transaction\" : \"randomString\"}";
curl_easy_setopt(curl, CURLOPT_URL,endpoint.c_str()); curl_easy_setopt(curl, CURLOPT_URL,endpoint.c_str());
@ -3512,7 +3526,9 @@ int Monitor::remove_from_janus() {
//Assemble our actual request //Assemble our actual request
postData = "{\"janus\" : \"message\", \"transaction\" : \"randomString\", \"body\" : {"; postData = "{\"janus\" : \"message\", \"transaction\" : \"randomString\", \"body\" : {";
postData += "\"request\" : \"destroy\", \"admin_key\" : \"supersecret\", \"id\" : "; postData += "\"request\" : \"destroy\", \"admin_key\" : \"";
postData += config.janus_secret;
postData += "\", \"id\" : ";
postData += std::to_string(id); postData += std::to_string(id);
postData += "}}"; postData += "}}";

View File

@ -2095,7 +2095,7 @@ function getStreamHTML($monitor, $options = array()) {
) ); ) );
return getVideoStreamHTML( 'liveStream'.$monitor->Id(), $streamSrc, $options['width'], $options['height'], ZM_MPEG_LIVE_FORMAT, $monitor->Name() ); return getVideoStreamHTML( 'liveStream'.$monitor->Id(), $streamSrc, $options['width'], $options['height'], ZM_MPEG_LIVE_FORMAT, $monitor->Name() );
} else if ( $monitor->JanusEnabled() ) { } else if ( $monitor->JanusEnabled() ) {
return '<video id="liveStream'.$monitor->Id().'" width="'.$options['width'].'"autoplay muted playsinline=""></video>'; return '<video id="liveStream'.$monitor->Id().'" width="'.$options['width'].'"autoplay muted controls playsinline="" ></video>';
} else if ( $options['mode'] == 'stream' and canStream() ) { } else if ( $options['mode'] == 'stream' and canStream() ) {
$options['mode'] = 'jpeg'; $options['mode'] = 'jpeg';
$streamSrc = $monitor->getStreamSrc($options); $streamSrc = $monitor->getStreamSrc($options);

View File

@ -92,7 +92,9 @@ function MonitorStream(monitorData) {
if (this.janusEnabled) { if (this.janusEnabled) {
var id = parseInt(this.id); var id = parseInt(this.id);
var server; var server;
if (window.location.protocol=='https:') { if (ZM_JANUS_PATH) {
server = ZM_JANUS_PATH;
} else if (window.location.protocol=='https:') {
// Assume reverse proxy setup for now // Assume reverse proxy setup for now
server = "https://" + window.location.hostname + "/janus"; server = "https://" + window.location.hostname + "/janus";
} else { } else {

View File

@ -192,6 +192,7 @@ xhtmlHeaders(__FILE__, translate('CycleWatch'));
</div> </div>
</div> </div>
</div> </div>
<script>var ZM_JANUS_PATH = '<?php echo ZM_JANUS_PATH ?>'</script>
<script src="<?php echo cache_bust('js/adapter.min.js') ?>"></script> <script src="<?php echo cache_bust('js/adapter.min.js') ?>"></script>
<script src="/javascript/janus/janus.js"></script> <script src="/javascript/janus/janus.js"></script>
<?php xhtmlFooter() ?> <?php xhtmlFooter() ?>

View File

@ -51,7 +51,14 @@ function initCycle() {
if ( scale == '0' || scale == 'auto' ) changeScale(); if ( scale == '0' || scale == 'auto' ) changeScale();
if (monitorData[monIdx].janusEnabled) { if (monitorData[monIdx].janusEnabled) {
server = "http://" + window.location.hostname + ":8088/janus"; if (ZM_JANUS_PATH) {
server = ZM_JANUS_PATH;
} else if (window.location.protocol=='https:') {
// Assume reverse proxy setup for now
server = "https://" + window.location.hostname + "/janus";
} else {
server = "http://" + window.location.hostname + ":8088/janus";
}
opaqueId = "streamingtest-"+Janus.randomString(12); opaqueId = "streamingtest-"+Janus.randomString(12);
Janus.init({debug: "all", callback: function() { Janus.init({debug: "all", callback: function() {
janus = new Janus({ janus = new Janus({

View File

@ -318,6 +318,7 @@ foreach (array_reverse($zones) as $zone) {
</div> </div>
</div> </div>
</div> </div>
<script>var ZM_JANUS_PATH = '<?php echo ZM_JANUS_PATH ?>'</script>
<script src="<?php echo cache_bust('js/adapter.min.js') ?>"></script> <script src="<?php echo cache_bust('js/adapter.min.js') ?>"></script>
<script src="/javascript/janus/janus.js"></script> <script src="/javascript/janus/janus.js"></script>
<script src="<?php echo cache_bust('js/MonitorStream.js') ?>"></script> <script src="<?php echo cache_bust('js/MonitorStream.js') ?>"></script>

View File

@ -396,6 +396,7 @@ if ( ZM_WEB_SOUND_ON_ALARM ) {
?> ?>
</div> </div>
</div> </div>
<script>var ZM_JANUS_PATH = '<?php echo ZM_JANUS_PATH ?>'</script>
<script src="<?php echo cache_bust('js/adapter.min.js') ?>"></script> <script src="<?php echo cache_bust('js/adapter.min.js') ?>"></script>
<script src="/javascript/janus/janus.js"></script> <script src="/javascript/janus/janus.js"></script>
<script src="<?php echo cache_bust('js/MonitorStream.js') ?>"></script> <script src="<?php echo cache_bust('js/MonitorStream.js') ?>"></script>