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

client_max_body_size setting via UI #4217

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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
34 changes: 34 additions & 0 deletions backend/migrations/20241209025008_client_max_body_size.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const migrate_name = 'client_max_body_size';
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('client_max_body_size').notNull().unsigned().defaultTo('1');
})
.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);
};
9 changes: 9 additions & 0 deletions backend/schema/components/proxy-host-object.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"domain_names",
"forward_host",
"forward_port",
"client_max_body_size",
"access_list_id",
"certificate_id",
"ssl_forced",
Expand Down Expand Up @@ -52,6 +53,11 @@
"minimum": 1,
"maximum": 65535
},
"client_max_body_size": {
"type": "integer",
"minimum": 1,
"maximum": 4096
},
"access_list_id": {
"$ref": "../common.json#/properties/access_list_id"
},
Expand Down Expand Up @@ -112,6 +118,9 @@
"forward_port": {
"$ref": "#/properties/forward_port"
},
"client_max_body_size": {
"$ref": "#/properties/client_max_body_size"
},
"forward_path": {
"type": "string"
},
Expand Down
1 change: 1 addition & 0 deletions backend/schema/paths/nginx/proxy-hosts/get.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"domain_names": ["test.example.com"],
"forward_host": "127.0.0.1",
"forward_port": 8989,
"client_max_body_size": 1,
"access_list_id": 0,
"certificate_id": 0,
"ssl_forced": false,
Expand Down
1 change: 1 addition & 0 deletions backend/schema/paths/nginx/proxy-hosts/hostID/get.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"domain_names": ["test.example.com"],
"forward_host": "192.168.0.10",
"forward_port": 8989,
"client_max_body_size": 1,
"access_list_id": 0,
"certificate_id": 0,
"ssl_forced": false,
Expand Down
4 changes: 4 additions & 0 deletions backend/schema/paths/nginx/proxy-hosts/hostID/put.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
"forward_port": {
"$ref": "../../../../components/proxy-host-object.json#/properties/forward_port"
},
"client_max_body_size": {
"$ref": "../../../../components/proxy-host-object.json#/properties/client_max_body_size"
},
"certificate_id": {
"$ref": "../../../../components/proxy-host-object.json#/properties/certificate_id"
},
Expand Down Expand Up @@ -100,6 +103,7 @@
"domain_names": ["test.example.com"],
"forward_host": "192.168.0.10",
"forward_port": 8989,
"client_max_body_size": 1,
"access_list_id": 0,
"certificate_id": 0,
"ssl_forced": false,
Expand Down
4 changes: 4 additions & 0 deletions backend/schema/paths/nginx/proxy-hosts/post.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
"forward_port": {
"$ref": "../../../components/proxy-host-object.json#/properties/forward_port"
},
"client_max_body_size": {
"$ref": "../../../components/proxy-host-object.json#/properties/client_max_body_size"
},
"certificate_id": {
"$ref": "../../../components/proxy-host-object.json#/properties/certificate_id"
},
Expand Down Expand Up @@ -88,6 +91,7 @@
"domain_names": ["test.example.com"],
"forward_host": "127.0.0.1",
"forward_port": 8989,
"client_max_body_size": 1,
"access_list_id": 0,
"certificate_id": 0,
"ssl_forced": false,
Expand Down
2 changes: 2 additions & 0 deletions backend/templates/proxy_host.conf
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ proxy_http_version 1.1;
}
{% endif %}

client_max_body_size {{ client_max_body_size }}m;

# Custom
include /data/nginx/custom/server_proxy[.]conf;
}
Expand Down
7 changes: 6 additions & 1 deletion frontend/js/app/nginx/proxy/form.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@
</label>
</div>
</div>

<div class="col-sm-12 col-md-12">
<div class="form-group">
<label class="form-label"><%- i18n('proxy-hosts', 'client-max-body-size' ) %></label>
<input name="client_max_body_size" type="number" class="form-control text-monospace" placeholder="1" value="<%- client_max_body_size %>" required>
</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
1 change: 1 addition & 0 deletions frontend/js/app/nginx/proxy/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ module.exports = Mn.View.extend({

// Manipulate
data.forward_port = parseInt(data.forward_port, 10);
data.client_max_body_size = parseInt(data.client_max_body_size, 10);
data.block_exploits = !!data.block_exploits;
data.caching_enabled = !!data.caching_enabled;
data.allow_websocket_upgrade = !!data.allow_websocket_upgrade;
Expand Down
1 change: 1 addition & 0 deletions frontend/js/i18n/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
"forward-scheme": "Scheme",
"forward-host": "Forward Hostname / IP",
"forward-port": "Forward Port",
"client-max-body-size": "Max proxied upload size (Mb)",
"delete": "Delete Proxy Host",
"delete-confirm": "Are you sure you want to delete the Proxy host for: <strong>{domains}</strong>?",
"help-title": "What is a Proxy Host?",
Expand Down
1 change: 1 addition & 0 deletions frontend/js/models/proxy-host.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const model = Backbone.Model.extend({
forward_scheme: 'http',
forward_host: '',
forward_port: null,
client_max_body_size: 1,
access_list_id: 0,
certificate_id: 0,
ssl_forced: false,
Expand Down
1 change: 1 addition & 0 deletions test/cypress/e2e/api/ProxyHosts.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('Proxy Hosts endpoints', () => {
forward_scheme: 'http',
forward_host: '1.1.1.1',
forward_port: 80,
client_max_body_size: 1,
access_list_id: '0',
certificate_id: 0,
meta: {
Expand Down