Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External ssl termination #93

Merged
merged 3 commits into from
Dec 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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