+31
-7
@@ -23,7 +23,7 @@ exports = module.exports = {
|
||||
setMemoryLimit: setMemoryLimit,
|
||||
setAutomaticBackup: setAutomaticBackup,
|
||||
setAutomaticUpdate: setAutomaticUpdate,
|
||||
setRobotsTxt: setRobotsTxt,
|
||||
setReverseProxyConfig: setReverseProxyConfig,
|
||||
setCertificate: setCertificate,
|
||||
setDebugMode: setDebugMode,
|
||||
setEnvironment: setEnvironment,
|
||||
@@ -305,6 +305,22 @@ function validateRobotsTxt(robotsTxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function validateFrameAncestors(frameAncestors) {
|
||||
if (frameAncestors.length > 10) return new AppsError(AppsError.BAD_FIELD, 'frameAncestors can have only 10 items', { field: 'frameAncestors' });
|
||||
|
||||
if (frameAncestors.some(fa => !/^[a-zA-Z_\-*.]*$/.test(fa))) return new AppsError(AppsError.BAD_FIELD, 'frameAncestors is invalid', { field: 'frameAncestors' });
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function validateNginxHeaders(headers) {
|
||||
if (headers.length > 10) return new AppsError(AppsError.BAD_FIELD, 'hideHeaders can have only 10 items', { field: 'hideHeaders' });
|
||||
|
||||
if (headers.some(h => !/^[a-zA-Z-]*$/.test(h))) return new AppsError(AppsError.BAD_FIELD, 'hideHeaders is invalid', { field: 'hideHeaders' });
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function validateBackupFormat(format) {
|
||||
assert.strictEqual(typeof format, 'string');
|
||||
|
||||
@@ -1106,26 +1122,34 @@ function setAutomaticUpdate(appId, enable, auditSource, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function setRobotsTxt(appId, robotsTxt, auditSource, callback) {
|
||||
function setReverseProxyConfig(appId, reverseProxyConfig, auditSource, callback) {
|
||||
assert.strictEqual(typeof appId, 'string');
|
||||
assert(robotsTxt === null || typeof robotsTxt === 'string');
|
||||
assert.strictEqual(typeof reverseProxyConfig, 'object');
|
||||
assert.strictEqual(typeof auditSource, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
reverseProxyConfig = _.extend({ robotsTxt: null, frameAncestors: null, hideHeaders: null }, reverseProxyConfig);
|
||||
|
||||
get(appId, function (error, app) {
|
||||
if (error) return callback(error);
|
||||
|
||||
error = validateRobotsTxt(robotsTxt);
|
||||
error = validateFrameAncestors(reverseProxyConfig.frameAncestors);
|
||||
if (error) return callback(error);
|
||||
|
||||
reverseProxy.writeAppConfig(_.extend({}, app, { robotsTxt }), function (error) {
|
||||
error = validateRobotsTxt(reverseProxyConfig.robotsTxt);
|
||||
if (error) return callback(error);
|
||||
|
||||
error = validateNginxHeaders(reverseProxyConfig.hideHeaders);
|
||||
if (error) return callback(error);
|
||||
|
||||
reverseProxy.writeAppConfig(_.extend({}, app, { reverseProxyConfig }), function (error) {
|
||||
if (error) return callback(new AppsError(AppsError.EXTERNAL_ERROR, 'Error writing nginx config'));
|
||||
|
||||
appdb.update(appId, { robotsTxt: robotsTxt }, function (error) {
|
||||
appdb.update(appId, { reverseProxyConfig }, function (error) {
|
||||
if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new AppsError(AppsError.NOT_FOUND, 'No such app'));
|
||||
if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, error));
|
||||
|
||||
eventlog.add(eventlog.ACTION_APP_CONFIGURE, auditSource, { appId: appId, app: app, robotsTxt: robotsTxt });
|
||||
eventlog.add(eventlog.ACTION_APP_CONFIGURE, auditSource, { appId, app, reverseProxyConfig });
|
||||
|
||||
callback();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user