2016-04-27 13:31:54 +02:00
|
|
|
<!--
|
2017-01-11 16:24:33 +01:00
|
|
|
Copyright JS Foundation and other contributors, http://js.foundation
|
2016-04-27 13:31:54 +02:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
-->
|
|
|
|
|
|
|
|
<script type="text/x-red" data-template-name="tls-config">
|
2017-02-27 22:04:19 +01:00
|
|
|
<div class="form-row" class="hide" id="node-config-row-uselocalfiles">
|
|
|
|
<input type="checkbox" id="node-config-input-uselocalfiles" style="display: inline-block; width: auto; vertical-align: top;">
|
|
|
|
<label for="node-config-input-uselocalfiles" style="width: 70%;"><span data-i18n="tls.label.use-local-files"></label>
|
|
|
|
</div>
|
2016-04-27 13:31:54 +02:00
|
|
|
<div class="form-row">
|
2017-02-27 22:04:19 +01:00
|
|
|
<label style="width: 120px;"><i class="fa fa-file-text-o"></i> <span data-i18n="tls.label.cert"></span></label>
|
|
|
|
<span class="tls-config-input-data">
|
2017-02-28 23:03:35 +01:00
|
|
|
<label class="editor-button" for="node-config-input-certfile"><i class="fa fa-upload"></i> <span data-i18n="tls.label.upload"></span></label>
|
2017-02-27 22:04:19 +01:00
|
|
|
<input class="hide" type="file" id="node-config-input-certfile">
|
2018-01-13 21:27:25 +01:00
|
|
|
<span id="tls-config-certname" style="width: calc(100% - 280px); overflow: hidden; line-height:34px; height:34px; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: middle;"> </span>
|
2017-02-28 23:03:35 +01:00
|
|
|
<button class="editor-button editor-button-small" id="tls-config-button-cert-clear" style="margin-left: 10px"><i class="fa fa-times"></i></button>
|
2017-02-27 22:04:19 +01:00
|
|
|
</span>
|
|
|
|
<input type="hidden" id="node-config-input-certname">
|
|
|
|
<input type="hidden" id="node-config-input-certdata">
|
2018-01-13 21:27:25 +01:00
|
|
|
<input class="hide tls-config-input-path" style="width: calc(100% - 170px);" type="text" id="node-config-input-cert" data-i18n="[placeholder]tls.placeholder.cert">
|
2016-04-27 13:31:54 +02:00
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
|
|
<label style="width: 120px;" for="node-config-input-key"><i class="fa fa-file-text-o"></i> <span data-i18n="tls.label.key"></span></label>
|
2017-02-27 22:04:19 +01:00
|
|
|
<span class="tls-config-input-data">
|
2017-02-28 23:03:35 +01:00
|
|
|
<label class="editor-button" for="node-config-input-keyfile"><i class="fa fa-upload"></i> <span data-i18n="tls.label.upload"></span></label>
|
2017-02-27 22:04:19 +01:00
|
|
|
<input class="hide" type="file" id="node-config-input-keyfile">
|
2018-01-13 21:27:25 +01:00
|
|
|
<span id="tls-config-keyname" style="width: calc(100% - 280px); overflow: hidden; line-height:34px; height:34px; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: middle;"> </span>
|
2017-02-28 23:03:35 +01:00
|
|
|
<button class="editor-button editor-button-small" id="tls-config-button-key-clear" style="margin-left: 10px"><i class="fa fa-times"></i></button>
|
2017-02-27 22:04:19 +01:00
|
|
|
</span>
|
|
|
|
<input type="hidden" id="node-config-input-keyname">
|
|
|
|
<input type="hidden" id="node-config-input-keydata">
|
2018-01-13 21:27:25 +01:00
|
|
|
<input class="hide tls-config-input-path" style="width: calc(100% - 170px);" type="text" id="node-config-input-key" data-i18n="[placeholder]tls.placeholder.key">
|
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
|
|
<label style="width: 100px; margin-left: 20px;" for="node-config-input-passphrase"> <span data-i18n="tls.label.passphrase"></span></label>
|
|
|
|
<input type="password" style="width: calc(100% - 170px);" id="node-config-input-passphrase" data-i18n="[placeholder]tls.placeholder.passphrase">
|
2016-04-27 13:31:54 +02:00
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
|
|
<label style="width: 120px;" for="node-config-input-ca"><i class="fa fa-file-text-o"></i> <span data-i18n="tls.label.ca"></span></label>
|
2017-02-27 22:04:19 +01:00
|
|
|
<span class="tls-config-input-data">
|
2017-02-28 23:03:35 +01:00
|
|
|
<label class="editor-button" for="node-config-input-cafile"><i class="fa fa-upload"></i> <span data-i18n="tls.label.upload"></span></label>
|
2017-02-27 22:04:19 +01:00
|
|
|
<input class="hide" type="file" title=" " id="node-config-input-cafile">
|
2018-01-13 21:27:25 +01:00
|
|
|
<span id="tls-config-caname" style="width: calc(100% - 280px); overflow: hidden; line-height:34px; height:34px; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: middle;"> </span>
|
2017-02-28 23:03:35 +01:00
|
|
|
<button class="editor-button editor-button-small" id="tls-config-button-ca-clear" style="margin-left: 10px"><i class="fa fa-times"></i></button>
|
2017-02-27 22:04:19 +01:00
|
|
|
</span>
|
|
|
|
<input type="hidden" id="node-config-input-caname">
|
|
|
|
<input type="hidden" id="node-config-input-cadata">
|
2018-01-13 21:27:25 +01:00
|
|
|
<input class="hide tls-config-input-path" style="width: calc(100% - 170px);" type="text" id="node-config-input-ca" data-i18n="[placeholder]tls.placeholder.ca">
|
2016-04-27 13:31:54 +02:00
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
|
|
<input type="checkbox" id="node-config-input-verifyservercert" style="display: inline-block; width: auto; vertical-align: top;">
|
2018-01-13 21:27:25 +01:00
|
|
|
<label for="node-config-input-verifyservercert" style="width: calc(100% - 170px);" data-i18n="tls.label.verify-server-cert"></label>
|
2016-04-27 13:31:54 +02:00
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
|
|
<label style="width: 120px;" for="node-config-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
2018-01-13 21:27:25 +01:00
|
|
|
<input style="width: calc(100% - 170px);" type="text" id="node-config-input-name" data-i18n="[placeholder]common.label.name">
|
2016-04-27 13:31:54 +02:00
|
|
|
</div>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/x-red" data-help-name="tls-config">
|
|
|
|
<p>Configuration options for TLS connections.</p>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
RED.nodes.registerType('tls-config',{
|
|
|
|
category: 'config',
|
|
|
|
defaults: {
|
|
|
|
name: {value:""},
|
|
|
|
cert: {value:"", validate: function(v) {
|
|
|
|
var currentKey = $("#node-config-input-key").val();
|
|
|
|
if (currentKey === undefined) {
|
|
|
|
currentKey = this.key;
|
|
|
|
}
|
|
|
|
return currentKey === '' || v != '';
|
|
|
|
}},
|
|
|
|
key: {value:"", validate: function(v) {
|
|
|
|
var currentCert = $("#node-config-input-cert").val();
|
|
|
|
if (currentCert === undefined) {
|
|
|
|
currentCert = this.cert;
|
|
|
|
}
|
|
|
|
return currentCert === '' || v != '';
|
|
|
|
}},
|
|
|
|
ca: {value:""},
|
2017-02-27 22:04:19 +01:00
|
|
|
certname: {value:""},
|
|
|
|
keyname: {value:""},
|
|
|
|
caname: {value:""},
|
2016-04-27 13:31:54 +02:00
|
|
|
verifyservercert: {value: true}
|
|
|
|
},
|
2017-02-27 22:04:19 +01:00
|
|
|
credentials: {
|
|
|
|
certdata: {type:"text"},
|
|
|
|
keydata: {type:"text"},
|
2018-01-13 21:27:25 +01:00
|
|
|
cadata: {type:"text"},
|
|
|
|
passphrase: {type:"password"}
|
2017-02-27 22:04:19 +01:00
|
|
|
},
|
2016-04-27 13:31:54 +02:00
|
|
|
label: function() {
|
|
|
|
return this.name || this._("tls.tls");
|
|
|
|
},
|
|
|
|
labelStyle: function() {
|
|
|
|
return this.name?"node_label_italic":"";
|
2017-02-27 22:04:19 +01:00
|
|
|
},
|
|
|
|
oneditprepare: function() {
|
|
|
|
function updateFileUpload() {
|
|
|
|
if ($("#node-config-input-uselocalfiles").is(':checked')) {
|
|
|
|
$(".tls-config-input-path").show();
|
|
|
|
$(".tls-config-input-data").hide();
|
|
|
|
} else {
|
|
|
|
$(".tls-config-input-data").show();
|
|
|
|
$(".tls-config-input-path").hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$("#node-config-input-uselocalfiles").on("click",function() {
|
|
|
|
updateFileUpload();
|
|
|
|
});
|
2017-02-28 23:03:35 +01:00
|
|
|
|
2017-02-27 22:04:19 +01:00
|
|
|
function saveFile(property, file) {
|
|
|
|
var dataInputId = "#node-config-input-"+property+"data";
|
|
|
|
var filenameInputId = "#node-config-input-"+property+"name";
|
|
|
|
var filename = file.name;
|
|
|
|
var reader = new FileReader();
|
|
|
|
reader.onload = function(event) {
|
|
|
|
$("#tls-config-"+property+"name").text(filename);
|
|
|
|
$(filenameInputId).val(filename);
|
|
|
|
$(dataInputId).val(event.target.result);
|
|
|
|
}
|
|
|
|
reader.readAsText(file,"UTF-8");
|
|
|
|
}
|
|
|
|
$("#node-config-input-certfile" ).change(function() {
|
|
|
|
saveFile("cert", this.files[0]);
|
|
|
|
});
|
|
|
|
$("#node-config-input-keyfile" ).change(function() {
|
|
|
|
saveFile("key", this.files[0]);
|
|
|
|
});
|
|
|
|
$("#node-config-input-cafile" ).change(function() {
|
|
|
|
saveFile("ca", this.files[0]);
|
|
|
|
});
|
2017-02-28 23:03:35 +01:00
|
|
|
|
|
|
|
function clearNameData(prop) {
|
|
|
|
$("#tls-config-"+prop+"name").text("");
|
|
|
|
$("#node-config-input-"+prop+"data").val("");
|
|
|
|
$("#node-config-input-"+prop+"name").val("");
|
|
|
|
}
|
|
|
|
$("#tls-config-button-cert-clear").click(function() {
|
|
|
|
clearNameData("cert");
|
|
|
|
});
|
|
|
|
$("#tls-config-button-key-clear").click(function() {
|
|
|
|
clearNameData("key");
|
|
|
|
});
|
|
|
|
$("#tls-config-button-ca-clear").click(function() {
|
|
|
|
clearNameData("ca");
|
|
|
|
});
|
|
|
|
|
2017-06-29 12:17:39 +02:00
|
|
|
if (RED.settings.tlsConfigDisableLocalFiles) {
|
2017-02-27 22:04:19 +01:00
|
|
|
$("#node-config-row-uselocalfiles").hide();
|
|
|
|
} else {
|
|
|
|
$("#node-config-row-uselocalfiles").show();
|
|
|
|
}
|
|
|
|
// in case paths were set from old TLS config
|
|
|
|
if(this.cert || this.key || this.ca) {
|
|
|
|
$("#node-config-input-uselocalfiles").prop('checked',true);
|
|
|
|
}
|
|
|
|
$("#tls-config-certname").text(this.certname);
|
|
|
|
$("#tls-config-keyname").text(this.keyname);
|
|
|
|
$("#tls-config-caname").text(this.caname);
|
|
|
|
updateFileUpload();
|
|
|
|
},
|
|
|
|
oneditsave: function() {
|
|
|
|
if ($("#node-config-input-uselocalfiles").is(':checked')) {
|
2017-02-28 23:03:35 +01:00
|
|
|
clearNameData("ca");
|
|
|
|
clearNameData("cert");
|
|
|
|
clearNameData("key");
|
2017-02-27 22:04:19 +01:00
|
|
|
} else {
|
|
|
|
$("#node-config-input-ca").val("");
|
|
|
|
$("#node-config-input-cert").val("");
|
2017-03-09 21:00:54 +01:00
|
|
|
$("#node-config-input-key").val("");
|
2017-02-27 22:04:19 +01:00
|
|
|
}
|
2016-04-27 13:31:54 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|