Skip to content

Commit

Permalink
Added websock upgrade option for base proxy host locations
Browse files Browse the repository at this point in the history
  • Loading branch information
jc21 committed Sep 29, 2018
1 parent efa1424 commit 83686c4
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 20 deletions.
26 changes: 26 additions & 0 deletions bin/migrate_create
@@ -0,0 +1,26 @@
#!/bin/bash

if [ "$1" == "" ]; then
echo "Error: migrate name must be specified as first arg"
exit 1
else
# Code path
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if hash realpath 2>/dev/null; then
export CODEBASE=$(realpath $SCRIPT_DIR/..)
elif hash grealpath 2>/dev/null; then
export CODEBASE=$(grealpath $SCRIPT_DIR/..)
else
export CODEBASE=$(readlink -e $SCRIPT_DIR/..)
fi

if [ -z "$CODEBASE" ]; then
echo "Unable to determine absolute codebase directory"
exit 1
fi

cd "$CODEBASE"

sudo /usr/local/bin/docker-compose run --rm --no-deps app node node_modules/knex/bin/cli.js migrate:make "$1"
exit $?
fi
37 changes: 37 additions & 0 deletions src/backend/migrations/20180929054513_websockets.js
@@ -0,0 +1,37 @@
'use strict';

const migrate_name = 'websockets';
const logger = require('../logger').migrate;

/**
* Migrate
*
* @see http://knexjs.org/#Schema
*
* @param {Object} knex
* @param {Promise} Promise
* @returns {Promise}
*/
exports.up = function (knex/*, Promise*/) {
logger.info('[' + migrate_name + '] Migrating Up...');

return knex.schema.table('proxy_host', function (proxy_host) {
proxy_host.integer('allow_websocket_upgrade').notNull().unsigned().defaultTo(0);
})
.then(() => {
logger.info('[' + migrate_name + '] proxy_host Table altered');
});

};

/**
* Undo Migrate
*
* @param {Object} knex
* @param {Promise} Promise
* @returns {Promise}
*/
exports.down = function (knex, Promise) {
logger.warn('[' + migrate_name + '] You can\'t migrate down this one.');
return Promise.resolve(true);
};
14 changes: 14 additions & 0 deletions src/backend/schema/endpoints/proxy-hosts.json
Expand Up @@ -39,6 +39,11 @@
"caching_enabled": {
"$ref": "../definitions.json#/definitions/caching_enabled"
},
"allow_websocket_upgrade": {
"description": "Allow Websocket Upgrade for all paths",
"example": true,
"type": "boolean"
},
"access_list_id": {
"$ref": "../definitions.json#/definitions/access_list_id"
},
Expand Down Expand Up @@ -80,6 +85,9 @@
"caching_enabled": {
"$ref": "#/definitions/caching_enabled"
},
"allow_websocket_upgrade": {
"$ref": "#/definitions/allow_websocket_upgrade"
},
"access_list_id": {
"$ref": "#/definitions/access_list_id"
},
Expand Down Expand Up @@ -148,6 +156,9 @@
"caching_enabled": {
"$ref": "#/definitions/caching_enabled"
},
"allow_websocket_upgrade": {
"$ref": "#/definitions/allow_websocket_upgrade"
},
"access_list_id": {
"$ref": "#/definitions/access_list_id"
},
Expand Down Expand Up @@ -200,6 +211,9 @@
"caching_enabled": {
"$ref": "#/definitions/caching_enabled"
},
"allow_websocket_upgrade": {
"$ref": "#/definitions/allow_websocket_upgrade"
},
"access_list_id": {
"$ref": "#/definitions/access_list_id"
},
Expand Down
6 changes: 6 additions & 0 deletions src/backend/templates/proxy_host.conf
Expand Up @@ -22,6 +22,12 @@ server {

{% include "_forced_ssl.conf" %}

{% if allow_websocket_upgrade == 1 or allow_websocket_upgrade == true %}
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
{% endif %}

# Proxy!
include conf.d/include/proxy.conf;
}
Expand Down
9 changes: 9 additions & 0 deletions src/frontend/js/app/nginx/proxy/form.ejs
Expand Up @@ -50,6 +50,15 @@
</label>
</div>
</div>
<div class="col-sm-12 col-md-12">
<div class="form-group">
<label class="custom-switch">
<input type="checkbox" class="custom-switch-input" name="allow_websocket_upgrade" value="1"<%- allow_websocket_upgrade ? ' checked' : '' %>>
<span class="custom-switch-indicator"></span>
<span class="custom-switch-description"><%- i18n('proxy-hosts', 'allow-websocket-upgrade') %></span>
</label>
</div>
</div>
<div class="col-sm-12 col-md-12">
<div class="form-group">
<label class="form-label"><%- i18n('proxy-hosts', 'access-list') %></label>
Expand Down
7 changes: 4 additions & 3 deletions src/frontend/js/app/nginx/proxy/form.js
Expand Up @@ -54,9 +54,10 @@ module.exports = Mn.View.extend({
let data = this.ui.form.serializeJSON();

// Manipulate
data.forward_port = parseInt(data.forward_port, 10);
data.block_exploits = !!data.block_exploits;
data.caching_enabled = !!data.caching_enabled;
data.forward_port = parseInt(data.forward_port, 10);
data.block_exploits = !!data.block_exploits;
data.caching_enabled = !!data.caching_enabled;
data.allow_websocket_upgrade = !!data.allow_websocket_upgrade;

if (typeof data.ssl_forced !== 'undefined' && data.ssl_forced === '1') {
data.ssl_forced = true;
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/js/i18n/messages.json
Expand Up @@ -98,7 +98,8 @@
"delete-confirm": "Are you sure you want to delete the Proxy host for: <strong>{domains}</strong>?",
"help-title": "What is a Proxy Host?",
"help-content": "A Proxy Host is the incoming endpoint for a web service that you want to forward.\nIt provides optional SSL termination for your service that might not have SSL support built in.\nProxy Hosts are the most common use for the Nginx Proxy Manager.",
"access-list": "Access List"
"access-list": "Access List",
"allow-websocket-upgrade": "Allow Websocket HTTP Upgrades"
},
"redirection-hosts": {
"title": "Redirection Hosts",
Expand Down
33 changes: 17 additions & 16 deletions src/frontend/js/models/proxy-host.js
Expand Up @@ -7,23 +7,24 @@ const model = Backbone.Model.extend({

defaults: function () {
return {
id: undefined,
created_on: null,
modified_on: null,
domain_names: [],
forward_ip: '',
forward_port: null,
access_list_id: 0,
certificate_id: 0,
ssl_forced: false,
caching_enabled: false,
block_exploits: false,
advanced_config: '',
meta: {},
id: undefined,
created_on: null,
modified_on: null,
domain_names: [],
forward_ip: '',
forward_port: null,
access_list_id: 0,
certificate_id: 0,
ssl_forced: false,
caching_enabled: false,
allow_websocket_upgrade: false,
block_exploits: false,
advanced_config: '',
meta: {},
// The following are expansions:
owner: null,
access_list: null,
certificate: null
owner: null,
access_list: null,
certificate: null
};
}
});
Expand Down

0 comments on commit 83686c4

Please sign in to comment.