mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-08-08 02:13:34 +00:00
Supporting open-appsec
This commit is contained in:
52
backend/internal/setting-openappsec.js
Executable file
52
backend/internal/setting-openappsec.js
Executable file
@@ -0,0 +1,52 @@
|
||||
const fs = require('fs');
|
||||
const error = require('../lib/error');
|
||||
const path = require('path');
|
||||
|
||||
const constants = require('../lib/constants');
|
||||
|
||||
const internalOpenappsecSetting = {
|
||||
configFilePath: path.join(constants.APPSEC_EXT_DIR, constants.APPSEC_CONFIG_FILE_NAME),
|
||||
|
||||
/**
|
||||
* @param {Access} access
|
||||
* @return {Promise}
|
||||
*/
|
||||
getLocalPolicy: (access) => {
|
||||
return access.can('settings:list')
|
||||
.then(() => {
|
||||
try {
|
||||
const filePath = internalOpenappsecSetting.configFilePath
|
||||
if (!fs.existsSync(filePath)) {
|
||||
return;
|
||||
}
|
||||
const fileContent = fs.readFileSync(filePath, 'utf8');
|
||||
const jsonStr = JSON.stringify(fileContent);
|
||||
return jsonStr;
|
||||
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Access} access
|
||||
* @param {Object} data
|
||||
* @return {Promise}
|
||||
*/
|
||||
updateLocalPolicy: (access, data) => {
|
||||
return access.can('settings:list')
|
||||
.then(() => {
|
||||
const filePath = internalOpenappsecSetting.configFilePath
|
||||
const yamlStr = data.local_policy;
|
||||
fs.writeFileSync(filePath, yamlStr, {encoding: 'utf8'});
|
||||
return true;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
throw new error.ConfigurationError(err.message);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = internalOpenappsecSetting;
|
Reference in New Issue
Block a user