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

Fix JavaScript code bugs #373

Merged
merged 3 commits into from
Apr 16, 2019
Merged

Fix JavaScript code bugs #373

merged 3 commits into from
Apr 16, 2019

Conversation

mgmacias95
Copy link
Contributor

Hello team,

This PR fixes #370, #371 and #372.

Best regards,
Marta

@mgmacias95
Copy link
Contributor Author

Make sure an error is returned if stdin parameter in execute.exec is not an object

root@master:/home/vagrant/GitHub/wazuh-api# grep -i execute.exec /var/ossec/api/helpers/request_templates.js
    execute.exec(python_bin, [wazuh_control], data_request, function (data) { res_h.send(req, res, data); });
root@master:/home/vagrant/GitHub/wazuh-api# sed -i "s:, data_request, func:, null, func:g" /var/ossec/api/helpers/request_templates.js
root@master:/home/vagrant/GitHub/wazuh-api# grep -i execute.exec /var/ossec/api/helpers/request_templates.js
    execute.exec(python_bin, [wazuh_control], null, function (data) { res_h.send(req, res, data); });
root@master:/home/vagrant/GitHub/wazuh-api# systemctl restart wazuh-api
root@master:/home/vagrant/GitHub/wazuh-api# curl -u foo:bar "localhost:55000/agents?pretty"
{
   "error": 1,
   "message": "Error executing command: stdin value must be an object: null"
}
root@master:/home/vagrant/GitHub/wazuh-api# tail -n4 /var/ossec/logs/api.log
WazuhAPI 2019-04-16 09:42:23 foo: ::ffff:127.0.0.1 GET /agents
WazuhAPI 2019-04-16 09:42:23 foo: CMD - Error executing command: stdin value must be an object: null
WazuhAPI 2019-04-16 09:42:23 foo: [::ffff:127.0.0.1] GET /agents/?pretty - 500 - error: '1'.
WazuhAPI 2019-04-16 09:42:23 foo: Response: {"error":1,"message":"Error executing command: stdin value must be an object: null"} HTTP Status: 500
root@master:/home/vagrant/GitHub/wazuh-api# sed -i "s:, null, func:, data_request, func:g" /var/ossec/api/helpers/request_templates.js
root@master:/home/vagrant/GitHub/wazuh-api# grep -i execute.exec /var/ossec/api/helpers/request_templates.js
    execute.exec(python_bin, [wazuh_control], data_request, function (data) { res_h.send(req, res, data); });
root@master:/home/vagrant/GitHub/wazuh-api# systemctl restart wazuh-api
root@master:/home/vagrant/GitHub/wazuh-api# curl -u foo:bar "localhost:55000/agents?pretty"
{
   "error": 0,
   "data": {
      "items": [
         {
            "os": {
               "arch": "x86_64",
               "codename": "Bionic Beaver",
               "major": "18",
               "minor": "04",
               "name": "Ubuntu",
               "platform": "ubuntu",
               "uname": "Linux |master |4.15.0-46-generic |#49-Ubuntu SMP Wed Feb 6 09:33:07 UTC 2019 |x86_64",
               "version": "18.04.2 LTS"
            },
            "version": "Wazuh v3.9.0",
            "name": "master",
            "manager": "master",
            "registerIP": "127.0.0.1",
            "lastKeepAlive": "9999-12-31 23:59:59",
            "ip": "127.0.0.1",
            "id": "000",
            "status": "Active",
            "dateAdd": "2019-04-16 08:51:34",
            "node_name": "master"
         }
      ],
      "totalItems": 1
   }
}
root@master:/home/vagrant/GitHub/wazuh-api# tail -n4 /var/ossec/logs/api.log

---
WazuhAPI 2019-04-16 09:44:01 foo: CMD - STDOUT: 543 bytes
WazuhAPI 2019-04-16 09:44:01 foo: [::ffff:127.0.0.1] GET /agents/?pretty - 200 - error: '0'.

Split select input argument by , without using a callback

root@master:/home/vagrant/GitHub/wazuh-api# grep -i select_param.split /var/ossec/api/helpers/filters.js
        select['fields'] = select_param.split(',');
root@master:/home/vagrant/GitHub/wazuh-api# curl -u foo:bar "localhost:55000/agents?pretty&select=id,name,os.platform"
{
   "error": 0,
   "data": {
      "items": [
         {
            "os": {
               "platform": "ubuntu"
            },
            "name": "master",
            "id": "000"
         }
      ],
      "totalItems": 1
   }
}

Set log level in configuration using uppercase characters

root@master:/home/vagrant/GitHub/wazuh-api# grep -i config.logs /var/ossec/api/configuration/config.js
config.logs = "info";
root@master:/home/vagrant/GitHub/wazuh-api# sed -i "s:config.logs = \"info\";:config.logs = \"InFo\";:g" /var/ossec/api/configuration/config.js
root@master:/home/vagrant/GitHub/wazuh-api# grep -i config.logs /var/ossec/api/configuration/config.js
config.logs = "InFo";
root@master:/home/vagrant/GitHub/wazuh-api# systemctl restart wazuh-api
root@master:/home/vagrant/GitHub/wazuh-api# tail -n1 /var/ossec/logs/api.log
WazuhAPI 2019-04-16 09:48:45 : Listening on: http://:::55000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants