mirror of
https://github.com/valitydev/wazuh-kibana-app.git
synced 2024-11-06 18:05:20 +00:00
Prettier
This commit is contained in:
parent
3b931fec15
commit
183c0ec36b
@ -84,7 +84,8 @@ export class AgentsPreviewController {
|
||||
});
|
||||
|
||||
this.$scope.$on('wazuhFetched', (ev, parameters) => {
|
||||
this.$scope.showNoAgents = !parameters.items.length > 0 && !parameters.filters.length;
|
||||
this.$scope.showNoAgents =
|
||||
!parameters.items.length > 0 && !parameters.filters.length;
|
||||
});
|
||||
|
||||
this.init = false;
|
||||
|
@ -83,7 +83,7 @@ export class DevToolsController {
|
||||
}
|
||||
);
|
||||
// Register plugin for code mirror
|
||||
CodeMirror.commands.autocomplete = function (cm) {
|
||||
CodeMirror.commands.autocomplete = function(cm) {
|
||||
CodeMirror.showHint(cm, CodeMirror.hint.dictionaryHint, {
|
||||
completeSingle: false
|
||||
});
|
||||
@ -244,7 +244,10 @@ export class DevToolsController {
|
||||
}
|
||||
this.linesWithClass = [];
|
||||
if (group) {
|
||||
if (!group.requestTextJson || (group.requestText.includes('{') && group.requestText.includes('}'))) {
|
||||
if (
|
||||
!group.requestTextJson ||
|
||||
(group.requestText.includes('{') && group.requestText.includes('}'))
|
||||
) {
|
||||
this.linesWithClass.push(
|
||||
this.apiInputBox.addLineClass(
|
||||
group.start,
|
||||
@ -332,7 +335,7 @@ export class DevToolsController {
|
||||
this.apiInputBox.setSize('auto', '100%');
|
||||
this.apiInputBox.model = [];
|
||||
this.getAvailableMethods();
|
||||
this.apiInputBox.on('keyup', function (cm, e) {
|
||||
this.apiInputBox.on('keyup', function(cm, e) {
|
||||
if (!ExcludedIntelliSenseTriggerKeys[(e.keyCode || e.which).toString()]) {
|
||||
cm.execCommand('autocomplete', null, {
|
||||
completeSingle: false
|
||||
@ -356,22 +359,22 @@ export class DevToolsController {
|
||||
this.highlightGroup(currentGroup);
|
||||
|
||||
// Register our custom Codemirror hint plugin.
|
||||
CodeMirror.registerHelper('hint', 'dictionaryHint', function (editor) {
|
||||
CodeMirror.registerHelper('hint', 'dictionaryHint', function(editor) {
|
||||
const model = editor.model;
|
||||
function getDictionary(line, word) {
|
||||
let hints = [];
|
||||
const exp = line.split(/\s+/g);
|
||||
if (exp[0] && exp[0].match(/^(?:GET|PUT|POST|DELETE).*$/)) {
|
||||
let method = model.find(function (item) {
|
||||
let method = model.find(function(item) {
|
||||
return item.method === exp[0];
|
||||
});
|
||||
const forbidChars = /^[^?{]+$/;
|
||||
if (method && !exp[2] && forbidChars.test(word)) {
|
||||
method.endpoints.forEach(function (endpoint) {
|
||||
method.endpoints.forEach(function(endpoint) {
|
||||
endpoint.path = endpoint.name;
|
||||
if (endpoint.args && endpoint.args.length > 0) {
|
||||
let argSubs = [];
|
||||
endpoint.args.forEach(function (arg) {
|
||||
endpoint.args.forEach(function(arg) {
|
||||
const pathSplitted = endpoint.name.split('/');
|
||||
const arrayIdx = pathSplitted.indexOf(arg.name);
|
||||
const wordSplitted = word.split('/');
|
||||
@ -383,7 +386,7 @@ export class DevToolsController {
|
||||
}
|
||||
});
|
||||
let auxPath = endpoint.name;
|
||||
argSubs.forEach(function (arg) {
|
||||
argSubs.forEach(function(arg) {
|
||||
auxPath = auxPath.replace(arg.id, arg.value);
|
||||
});
|
||||
endpoint.path = auxPath;
|
||||
@ -404,26 +407,26 @@ export class DevToolsController {
|
||||
const whiteSpace = /\s/;
|
||||
while (end < curLine.length && !whiteSpace.test(curLine.charAt(end)))
|
||||
++end;
|
||||
while (start && !whiteSpace.test(curLine.charAt(start - 1)))--start;
|
||||
while (start && !whiteSpace.test(curLine.charAt(start - 1))) --start;
|
||||
const curWord = start !== end && curLine.slice(start, end);
|
||||
return {
|
||||
list: (!curWord
|
||||
? []
|
||||
: getDictionary(curLine, curWord).filter(function (item) {
|
||||
return item.toUpperCase().includes(curWord.toUpperCase());
|
||||
})
|
||||
: getDictionary(curLine, curWord).filter(function(item) {
|
||||
return item.toUpperCase().includes(curWord.toUpperCase());
|
||||
})
|
||||
).sort(),
|
||||
from: CodeMirror.Pos(cur.line, start),
|
||||
to: CodeMirror.Pos(cur.line, end)
|
||||
};
|
||||
});
|
||||
const evtDocument = this.$document[0];
|
||||
$('.wz-dev-column-separator').mousedown(function (e) {
|
||||
$('.wz-dev-column-separator').mousedown(function(e) {
|
||||
e.preventDefault();
|
||||
$('.wz-dev-column-separator').addClass('active');
|
||||
const leftOrigWidth = $('#wz-dev-left-column').width();
|
||||
const rightOrigWidth = $('#wz-dev-right-column').width();
|
||||
$(evtDocument).mousemove(function (e) {
|
||||
$(evtDocument).mousemove(function(e) {
|
||||
const leftWidth = e.pageX - 215 + 14;
|
||||
let rightWidth = leftOrigWidth - leftWidth;
|
||||
$('#wz-dev-left-column').css('width', leftWidth);
|
||||
@ -431,7 +434,7 @@ export class DevToolsController {
|
||||
});
|
||||
});
|
||||
|
||||
$(evtDocument).mouseup(function () {
|
||||
$(evtDocument).mouseup(function() {
|
||||
$('.wz-dev-column-separator').removeClass('active');
|
||||
$(evtDocument).unbind('mousemove');
|
||||
});
|
||||
@ -458,10 +461,10 @@ export class DevToolsController {
|
||||
const desiredGroup = firstTime
|
||||
? this.groups.filter(item => item.requestText)
|
||||
: this.groups.filter(
|
||||
item =>
|
||||
item.requestText &&
|
||||
(item.end >= selection.line && item.start <= selection.line)
|
||||
);
|
||||
item =>
|
||||
item.requestText &&
|
||||
(item.end >= selection.line && item.start <= selection.line)
|
||||
);
|
||||
|
||||
// Place play button at first line from the selected group
|
||||
const cords = this.apiInputBox.cursorCoords({
|
||||
@ -517,12 +520,12 @@ export class DevToolsController {
|
||||
const method = desiredGroup.requestText.startsWith('GET')
|
||||
? 'GET'
|
||||
: desiredGroup.requestText.startsWith('POST')
|
||||
? 'POST'
|
||||
: desiredGroup.requestText.startsWith('PUT')
|
||||
? 'PUT'
|
||||
: desiredGroup.requestText.startsWith('DELETE')
|
||||
? 'DELETE'
|
||||
: 'GET';
|
||||
? 'POST'
|
||||
: desiredGroup.requestText.startsWith('PUT')
|
||||
? 'PUT'
|
||||
: desiredGroup.requestText.startsWith('DELETE')
|
||||
? 'DELETE'
|
||||
: 'GET';
|
||||
|
||||
let requestCopy = desiredGroup.requestText.includes(method)
|
||||
? desiredGroup.requestText.split(method)[1].trim()
|
||||
|
@ -26,12 +26,7 @@ class WzRegisterAgents {
|
||||
reload: '&'
|
||||
};
|
||||
}
|
||||
controller(
|
||||
$scope,
|
||||
wazuhConfig,
|
||||
errorHandler,
|
||||
apiReq
|
||||
) {
|
||||
controller($scope, wazuhConfig, errorHandler, apiReq) {
|
||||
const configuration = wazuhConfig.getConfig();
|
||||
$scope.adminMode = !!(configuration || {}).admin;
|
||||
const load = async () => {
|
||||
@ -44,14 +39,15 @@ class WzRegisterAgents {
|
||||
/* linux */
|
||||
steps: [
|
||||
{
|
||||
title: 'Add the agent to the manager',
|
||||
title: 'Add the agent to the manager'
|
||||
},
|
||||
{
|
||||
title: 'Import the key to the agent',
|
||||
code: '# /var/ossec/bin/manage_agents -i '
|
||||
},
|
||||
{
|
||||
title: 'Edit the Wazuh agent configuration to add the Wazuh manager IP',
|
||||
title:
|
||||
'Edit the Wazuh agent configuration to add the Wazuh manager IP'
|
||||
},
|
||||
{
|
||||
title: 'Restart the agent'
|
||||
@ -62,7 +58,7 @@ class WzRegisterAgents {
|
||||
/* windows */
|
||||
steps: [
|
||||
{
|
||||
title: 'Register the agent',
|
||||
title: 'Register the agent'
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -73,26 +69,40 @@ class WzRegisterAgents {
|
||||
|
||||
$scope.nextStep = () => {
|
||||
$scope.registerObj.currentStep++;
|
||||
if ($scope.registerObj.currentStep >= $scope.registerObj.systems[$scope.registerObj.selectedSystem].steps.length) {
|
||||
if (
|
||||
$scope.registerObj.currentStep >=
|
||||
$scope.registerObj.systems[$scope.registerObj.selectedSystem].steps
|
||||
.length
|
||||
) {
|
||||
$scope.restartingAgent = false;
|
||||
$scope.reload();
|
||||
load();
|
||||
}
|
||||
$scope.$applyAsync();
|
||||
}
|
||||
};
|
||||
$scope.addAgent = async () => {
|
||||
try {
|
||||
$scope.addingAgent = true;
|
||||
const data = await apiReq.request('POST', '/agents', {
|
||||
name: $scope.registerObj.systems[$scope.registerObj.selectedSystem].steps[0].agentName,
|
||||
ip: $scope.registerObj.systems[$scope.registerObj.selectedSystem].steps[0].agentIP
|
||||
name:
|
||||
$scope.registerObj.systems[$scope.registerObj.selectedSystem]
|
||||
.steps[0].agentName,
|
||||
ip:
|
||||
$scope.registerObj.systems[$scope.registerObj.selectedSystem]
|
||||
.steps[0].agentIP
|
||||
});
|
||||
if (!(((data || {}).data || {}).data || {}).key) {
|
||||
throw new Error("No agent key received");
|
||||
throw new Error('No agent key received');
|
||||
} else {
|
||||
$scope.registerObj.systems[$scope.registerObj.selectedSystem].steps[1].key = data.data.data.key;
|
||||
$scope.registerObj.systems[$scope.registerObj.selectedSystem].steps[1].code += data.data.data.key;
|
||||
$scope.registerObj.systems[$scope.registerObj.selectedSystem].steps[3].id = data.data.data.id;
|
||||
$scope.registerObj.systems[
|
||||
$scope.registerObj.selectedSystem
|
||||
].steps[1].key = data.data.data.key;
|
||||
$scope.registerObj.systems[
|
||||
$scope.registerObj.selectedSystem
|
||||
].steps[1].code += data.data.data.key;
|
||||
$scope.registerObj.systems[
|
||||
$scope.registerObj.selectedSystem
|
||||
].steps[3].id = data.data.data.id;
|
||||
}
|
||||
$scope.addingAgent = false;
|
||||
$scope.nextStep();
|
||||
@ -101,21 +111,29 @@ class WzRegisterAgents {
|
||||
errorHandler.handle(error, 'Adding agent error');
|
||||
}
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
$scope.restartAgent = async () => {
|
||||
$scope.restartingAgent = true;
|
||||
try {
|
||||
const data = await apiReq.request(
|
||||
'PUT',
|
||||
`/agents/${$scope.registerObj.systems[$scope.registerObj.selectedSystem].steps[3].id}/restart`,
|
||||
`/agents/${
|
||||
$scope.registerObj.systems[$scope.registerObj.selectedSystem]
|
||||
.steps[3].id
|
||||
}/restart`,
|
||||
{}
|
||||
);
|
||||
const result = ((data || {}).data || {}).data || false;
|
||||
if (!result) {
|
||||
throw new Error('Unexpected error restarting agent');
|
||||
}
|
||||
errorHandler.info(`Success. Agent ${$scope.registerObj.systems[$scope.registerObj.selectedSystem].steps[0].agentName} has been registered.`);
|
||||
errorHandler.info(
|
||||
`Success. Agent ${
|
||||
$scope.registerObj.systems[$scope.registerObj.selectedSystem]
|
||||
.steps[0].agentName
|
||||
} has been registered.`
|
||||
);
|
||||
$scope.nextStep();
|
||||
} catch (error) {
|
||||
errorHandler.handle(error, '');
|
||||
@ -124,7 +142,7 @@ class WzRegisterAgents {
|
||||
$scope.$applyAsync();
|
||||
};
|
||||
|
||||
$scope.setSystem = (system) => {
|
||||
$scope.setSystem = system => {
|
||||
$scope.registerObj.currentStep = 0;
|
||||
load();
|
||||
$scope.registerObj.selectedSystemTab = system;
|
||||
@ -139,8 +157,8 @@ class WzRegisterAgents {
|
||||
$scope.registerObj.selectedSystem = 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
app.directive('wzRegisterAgents', () => new WzRegisterAgents());
|
||||
app.directive('wzRegisterAgents', () => new WzRegisterAgents());
|
||||
|
@ -162,7 +162,10 @@ app.directive('wzTable', function() {
|
||||
// Resize
|
||||
checkGap($scope, $scope.items);
|
||||
$scope.searchTable();
|
||||
$scope.$emit('wazuhFetched', { items: $scope.items, filters: instance.filters });
|
||||
$scope.$emit('wazuhFetched', {
|
||||
items: $scope.items,
|
||||
filters: instance.filters
|
||||
});
|
||||
}
|
||||
if ($scope.customColumns) {
|
||||
setTimeout(() => {
|
||||
|
Loading…
Reference in New Issue
Block a user