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

Ruleset Files moved to rules/decoders section #1304

Merged
merged 10 commits into from
Mar 12, 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
62 changes: 8 additions & 54 deletions public/controllers/management/decoders.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,6 @@ export class DecodersController {
if (!this.$scope.$$phase) this.$scope.$digest();
});

this.$scope.$on('showFileNameInput', () => {
this.newFile = true;
this.selectedItem = { file: 'new file' };
this.$scope.$applyAsync();
});

this.$scope.$on('showSaveAndOverwrite', () => {
this.overwriteError = true;
this.$scope.$applyAsync();
Expand Down Expand Up @@ -306,21 +300,6 @@ export class DecodersController {
if (!this.$scope.$$phase) this.$scope.$digest();
}

addNewFile(type) {
this.editingFile = true;
this.newFile = true;
this.newFileName = '';
this.selectedFileName = this.selectedRulesetTab;
this.selectedItem = { file: 'new file' };
this.fetchedXML = '<!-- Modify it at your will. -->';
this.type = type;
this.cancelSaveAndOverwrite();
if (!this.$scope.$$phase) this.$scope.$digest();
this.$location.search('editingFile', true);
this.appState.setNavigation({ status: true });
this.$scope.$emit('fetchedFile', { data: this.fetchedXML });
}

toggleSaveConfig = () => {
this.doingSaving = false;
this.$scope.$applyAsync();
Expand All @@ -331,42 +310,17 @@ export class DecodersController {
this.$scope.$applyAsync();
};

doSaveConfig(isNewFile, fileName) {
doSaveConfig() {
const clusterInfo = this.appState.getClusterInfo();
const showRestartManager =
clusterInfo.status === 'enabled' ? 'cluster' : 'manager';
if (isNewFile && !fileName) {
this.errorHandler.handle(
'Error creating a new file. You need to specify a file name',
''
);
return false;
} else {
if (isNewFile) {
const validFileName = /(.+).xml/;
const containsBlanks = /.*[ ].*/;
if (fileName && !validFileName.test(fileName)) {
fileName = fileName + '.xml';
}
if (containsBlanks.test(fileName)) {
this.errorHandler.handle(
'Error creating a new file. The filename can not contain white spaces.',
''
);
return false;
}
this.selectedItem = { file: fileName };
}
this.doingSaving = true;
const objParam = {
decoder: isNewFile ? this.selectedItem : this.currentDecoder,
showRestartManager,
isNewFile: !!isNewFile,
isOverwrite: !!this.overwriteError
};

this.$scope.$broadcast('saveXmlFile', objParam);
}
this.doingSaving = true;
const objParam = {
decoder: this.currentDecoder,
showRestartManager,
isOverwrite: !!this.overwriteError
};
this.$scope.$broadcast('saveXmlFile', objParam);
}

restart = () => {
Expand Down
91 changes: 80 additions & 11 deletions public/controllers/management/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,28 @@
*/

export class FilesController {
constructor($scope, wazuhConfig, rulesetHandler, errorHandler, appState) {
constructor(
$scope,
wazuhConfig,
rulesetHandler,
errorHandler,
appState,
$location
) {
this.$scope = $scope;
this.wazuhConfig = wazuhConfig;
this.rulesetHandler = rulesetHandler;
this.errorHandler = errorHandler;
this.appState = appState;
this.$location = $location;
this.appliedFilters = [];
this.searchTerm = '';
this.overwriteError = false;
}

$onInit() {
const configuration = this.wazuhConfig.getConfig();
this.adminMode = !!(configuration || {}).admin;
this.filesSubTab = 'rules';

this.$scope.$on('editFile', (ev, params) => {
this.editFile(params);
Expand All @@ -34,20 +42,53 @@ export class FilesController {
this.$scope.closeEditingFile = () => {
this.$scope.editingFile = false;
this.$scope.fetchedXML = null;
this.search();
this.$scope.$applyAsync();
};

this.$scope.doSaveConfig = () => {
this.$scope.doSaveConfig = (isNewFile, fileName) => {
const clusterInfo = this.appState.getClusterInfo();
const showRestartManager =
clusterInfo.status === 'enabled' ? 'cluster' : 'manager';
this.$scope.doingSaving = true;
const objParam = { showRestartManager };
this.$scope.currentFile.type === 'rule'
? (objParam.rule = this.$scope.currentFile)
: (objParam.decoder = this.$scope.currentFile);
this.$scope.$broadcast('saveXmlFile', objParam);
this.$scope.$applyAsync();
if (isNewFile && !fileName) {
this.errorHandler.handle(
'Error creating a new file. You need to specify a file name',
''
);
return false;
} else {
if (isNewFile) {
const validFileName = /(.+).xml/;
const containsBlanks = /.*[ ].*/;
if (fileName && !validFileName.test(fileName)) {
fileName = fileName + '.xml';
}
if (containsBlanks.test(fileName)) {
this.errorHandler.handle(
'Error creating a new file. The filename can not contain white spaces.',
''
);
return false;
}
this.selectedItem = { file: fileName };
}
this.$scope.doingSaving = true;
const objParam = {
showRestartManager,
isNewFile: !!isNewFile,
isOverwrite: !!this.overwriteError
};
(isNewFile && this.$scope.type === 'rules') ||
(!isNewFile && this.$scope.currentFile.type === 'rule')
? (objParam.rule = isNewFile
? this.selectedItem
: this.$scope.currentFile)
: (objParam.decoder = isNewFile
? this.selectedItem
: this.$scope.currentFile);
this.$scope.$broadcast('saveXmlFile', objParam);
this.$scope.$applyAsync();
}
};

this.$scope.toggleSaveConfig = () => {
Expand All @@ -60,25 +101,38 @@ export class FilesController {
this.$scope.$applyAsync();
};

this.$scope.cancelSaveAndOverwrite = () => {
this.$scope.overwriteError = false;
this.$scope.$applyAsync();
};

this.$scope.$on('showRestartMsg', () => {
this.$scope.restartMsg = true;
this.$scope.$applyAsync();
});

this.$scope.$on('showFileNameInput', () => {
this.newFile = true;
this.selectedItem = { file: 'new file' };
this.$scope.$applyAsync();
});

this.$scope.restart = () => {
this.$scope.$emit('performRestart', {});
};
}

async editFile(params) {
this.$scope.editingFile = true;
this.$scope.newFile = false;
try {
this.$scope.currentFile = params.file;
this.$scope.currentFile.type = params.path.includes('rules')
? 'rule'
: 'decoder';
this.$scope.type = `${this.$scope.currentFile.type}s`;
this.$scope.fetchedXML =
this.$scope.currentFile.type === 'rule'
this.$scope.type === 'rules'
? await this.rulesetHandler.getRuleConfiguration(
this.$scope.currentFile.file
)
Expand All @@ -93,6 +147,21 @@ export class FilesController {
}
}

addNewFile(type) {
this.$scope.editingFile = true;
this.$scope.newFile = true;
this.$scope.newFileName = '';
this.$scope.selectedFileName = this.$scope.selectedRulesetTab;
this.$scope.selectedItem = { file: 'new file' };
this.$scope.fetchedXML = '<!-- Modify it at your will. -->';
this.$scope.type = type;
this.$scope.cancelSaveAndOverwrite();
this.$scope.$applyAsync();
this.$location.search('editingFile', true);
this.appState.setNavigation({ status: true });
this.$scope.$emit('fetchedFile', { data: this.$scope.fetchedXML });
}

switchFilesSubTab(tab) {
this.filesSubTab = tab;
}
Expand Down
5 changes: 5 additions & 0 deletions public/controllers/management/management.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,14 @@ export class ManagementController {
setRulesTab(tab) {
this.rulesetTab = tab;
this.globalRulesetTab = this.rulesetTab;
this.managingFiles = false;
this.breadCrumbBack();
}

switchFilesSubTab(flag) {
this.managingFiles = flag || true;
}

breadCrumbBack(goRoot = false) {
if (this.currentRule) {
this.$scope.$broadcast('closeRuleView');
Expand Down
70 changes: 10 additions & 60 deletions public/controllers/management/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@ export function RulesController(
wazuhConfig,
rulesetHandler
) {
$scope.showingLocalRules = false;
$scope.overwriteError = false;
$scope.switchLocalRules = () =>
($scope.showingLocalRules = !$scope.showingLocalRules);

$scope.isObject = item => typeof item === 'object';

$scope.mctrl = $scope.$parent.$parent.$parent.mctrl;
$scope.mctrl.showingLocalRules = false;
$scope.appliedFilters = [];
/**
* This performs a search with a given term
Expand Down Expand Up @@ -257,7 +254,6 @@ export function RulesController(
(((ruleReloaded || {}).data || {}).data || {}).items || [];
if (!response.length) {
$scope.currentRule = null;
$scope.showingLocalRules = true;
$scope.closeDetailView(true);
} else {
$scope.currentRule = response[0];
Expand Down Expand Up @@ -318,21 +314,6 @@ export function RulesController(
);
}

$scope.addNewFile = type => {
$scope.editingFile = true;
$scope.newFile = true;
$scope.newFileName = '';
$scope.selectedFileName = $scope.selectedRulesetTab;
$scope.selectedItem = { file: 'new file' };
$scope.fetchedXML = '<!-- Modify it at your will. -->';
$scope.type = type;
$scope.cancelSaveAndOverwrite();
if (!$scope.$$phase) $scope.$digest();
$location.search('editingFile', true);
appState.setNavigation({ status: true });
$scope.$emit('fetchedFile', { data: $scope.fetchedXML });
};

$scope.toggleSaveConfig = () => {
$scope.doingSaving = false;
$scope.$applyAsync();
Expand All @@ -348,50 +329,19 @@ export function RulesController(
$scope.$applyAsync();
};

$scope.doSaveConfig = (isNewFile, fileName) => {
$scope.doSaveConfig = () => {
const clusterInfo = appState.getClusterInfo();
const showRestartManager =
clusterInfo.status === 'enabled' ? 'cluster' : 'manager';
if (isNewFile && !fileName) {
errorHandler.handle(
'Error creating a new file. You need to specify a file name',
''
);
return false;
} else {
if (isNewFile) {
const validFileName = /(.+).xml/;
const containsBlanks = /.*[ ].*/;
if (fileName && !validFileName.test(fileName)) {
fileName = fileName + '.xml';
}
if (containsBlanks.test(fileName)) {
errorHandler.handle(
'Error creating a new file. The filename can not contain white spaces.',
''
);
return false;
}
$scope.selectedItem = { file: fileName };
}
$scope.doingSaving = true;
const objParam = {
rule: isNewFile ? $scope.selectedItem : $scope.currentRule,
showRestartManager,
isNewFile: !!isNewFile,
isOverwrite: !!$scope.overwriteError
};

$scope.$broadcast('saveXmlFile', objParam);
}
$scope.doingSaving = true;
const objParam = {
rule: $scope.currentRule,
showRestartManager,
isOverwrite: !!$scope.overwriteError
};
$scope.$broadcast('saveXmlFile', objParam);
};

$scope.$on('showFileNameInput', () => {
$scope.newFile = true;
$scope.selectedItem = { file: 'new file' };
$scope.$applyAsync();
});

$scope.restart = () => {
$scope.$emit('performRestart', {});
};
Expand Down
2 changes: 1 addition & 1 deletion public/directives/wz-table/wz-table-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ app.directive('wzTable', function() {
$scope.keys.push(key.key);
}
}
init().then(() => $scope.setColResizable());
init(true).then(() => $scope.setColResizable());
};
$scope.exists = key => {
const str = key.key.value || key.key;
Expand Down
Loading