Skip to content

Commit

Permalink
Merge pull request #93 from JokerQyou/external-ssl-termination
Browse files Browse the repository at this point in the history
External ssl termination
  • Loading branch information
windkh authored Dec 21, 2019
2 parents 735a39d + afc8836 commit 31d5116
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
22 changes: 20 additions & 2 deletions telegrambot/99-telegrambot.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
privatekey: { value: "", required: false },
certificate: { value: "", required: false },
useselfsignedcertificate: { value: false, required: false },

sslterminated: { value: false, required: false },
verboselogging: { value: false, required: false }
},
credentials: {
Expand All @@ -59,6 +59,20 @@
updateOptions();
$("#node-config-input-updatemode").change(updateOptions);

// sslTerminated on / off
var sslTerminated = function() {
var mode = $('#node-config-input-sslterminated').prop('checked');
if (mode === false) {
$('#node-config-input-privatekey').parent().show();
$('#node-config-input-certificate').parent().show();
} else {
$('#node-config-input-privatekey').parent().hide();
$('#node-config-input-certificate').parent().hide();
}
};
sslTerminated();
$('#node-config-input-sslterminated').change(sslTerminated);

// socks5 on / off
var useSocks5 = function() {
var mode = $("#node-config-input-usesocks").prop('checked');
Expand Down Expand Up @@ -152,8 +166,12 @@
<label for="node-config-input-useselfsignedcertificate"><i class="fa fa-pencil"></i> Certificate is self-signed</label>
<input type="checkbox" id="node-config-input-useselfsignedcertificate" style="display: inline-block; width: auto; vertical-align: top;">
</div>
<div class="form-row">
<label for="node-config-input-sslterminated"><i class="fa fa-pencil"></i> SSL terminated by reverse proxy</label>
<input type="checkbox" id="node-config-input-sslterminated" style="display: inline-block; width: auto; vertical-align: top;">
</div>

<div class="form-tips" style="width: auto"><b>Tip:</b> Webhook mode requires a HTTPS certificate. The certificate can also be a self-signed (=custom) one. If any of the host, key, certificate properties is left blank the bot will default to polling mode.</div>
<div class="form-tips" style="width: auto"><b>Tip:</b> Webhook mode requires a HTTPS certificate. The certificate can also be a self-signed (=custom) one. If any of the host, key, certificate properties is left blank the bot will default to polling mode. If SSL termination is alredy handled by reverse proxy, key and certificate is not required.</div>
</div>
</div>

Expand Down
13 changes: 8 additions & 5 deletions telegrambot/99-telegrambot.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ module.exports = function (RED) {
this.privateKey = n.privatekey;
this.certificate = n.certificate;
this.useSelfSignedCertificate = n.useselfsignedcertificate;

this.sslTerminated = n.sslterminated;

// 4. optional when request via SOCKS5 is used.
this.useSocks = n.usesocks;
if(this.useSocks){
Expand All @@ -88,7 +89,7 @@ module.exports = function (RED) {

this.useWebhook = false;
if (this.updateMode == "webhook") {
if (this.botHost && this.privateKey && this.certificate) {
if (this.botHost && (this.sslTerminated || (this.privateKey && this.certificate))) {
this.useWebhook = true;
} else{
self.error("Configuration data for webhook is not complete. Defaulting to polling mode.");
Expand All @@ -109,8 +110,10 @@ module.exports = function (RED) {
{
autoOpen: true,
port : this.localBotPort,
key: this.privateKey,
cert: this.certificate,
};
if (!this.sslTerminated) {
webHook.key = this.privateKey;
webHook.cert = this.certificate;
}
var options =
{
Expand All @@ -136,7 +139,7 @@ module.exports = function (RED) {

var botUrl = "https://" + this.botHost + ":" + this.publicBotPort + "/" + this.token;
var setWebHookOptions;
if (this.useSelfSignedCertificate){
if (!this.sslTerminated && this.useSelfSignedCertificate){
setWebHookOptions = {
certificate: options.webHook.cert,
};
Expand Down

0 comments on commit 31d5116

Please sign in to comment.