prey/prey-node-client

View on GitHub

Showing 551 of 551 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

exports.get.geofences = (cb) => {
  var device_key = keys.get().device;
  if (!device_key)
    return cb(errors.get('NO_DEVICE_KEY'));

Severity: Major
Found in lib/agent/control-panel/api/devices.js and 1 other location - About 2 hrs to fix
lib/agent/control-panel/api/devices.js on lines 153..159

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 82.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

exports.get.triggers = (cb) => {
  var device_key = keys.get().device;
  if (!device_key)
    return cb(errors.get('NO_DEVICE_KEY'));

Severity: Major
Found in lib/agent/control-panel/api/devices.js and 1 other location - About 2 hrs to fix
lib/agent/control-panel/api/devices.js on lines 145..151

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 82.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function sync has 58 lines of code (exceeds 25 allowed). Consider refactoring.
Open

exports.sync = function(id, geofences, cb) {
  exports.watching = [];

  if(!geofences || geofences.length == 0) 
    done(id, cb);
Severity: Major
Found in lib/agent/actions/geofencing/index.js - About 2 hrs to fix

    Function createConnectionSocket has 58 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    const createConnectionSocket = (messageToSendSocket, cb) => {
      try {
        const existsFile = fs.existsSync(socketFile);
        if (!existsFile) {
          logger.error('The socket file does not exist');
    Severity: Major
    Found in lib/agent/socket/index.js - About 2 hrs to fix

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

      exports.get_python_version = (callback) => {
        // Asks first if the device has python2, if it fails asks for python3
        cp.exec("python" + python_version + " || python3" + python_version, (err, stdout) => {
          if (err) return callback(err);
      
      
      Severity: Major
      Found in lib/system/linux/index.js and 1 other location - About 2 hrs to fix
      lib/system/mac/index.js on lines 103..110

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 81.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

      exports.get_python_version = (callback) => {
        // Asks first if the device has python2, if it fails asks for python3
        cp.exec("python" + python_version + " || python3" + python_version, (err, stdout) => {
          if (err) return callback(err);
      
      
      Severity: Major
      Found in lib/system/mac/index.js and 1 other location - About 2 hrs to fix
      lib/system/linux/index.js on lines 96..103

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 81.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

          if (event == 'stopped' || event == 'failed') {
            storage.do(
              'update',
              {
                type: 'commands',
      Severity: Major
      Found in lib/agent/commands.js and 1 other location - About 2 hrs to fix
      lib/agent/commands.js on lines 338..355

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 81.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

          if (event == 'started') {
            storage.do(
              'update',
              {
                type: 'commands',
      Severity: Major
      Found in lib/agent/commands.js and 1 other location - About 2 hrs to fix
      lib/agent/commands.js on lines 319..336

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 81.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Function check has 57 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      exports.check = function (id, target, opts, cb) {
        function done(err) {
          if (cb && typeof cb === 'function') return cb && cb(err);
        }
      
      
      Severity: Major
      Found in lib/agent/updater.js - About 2 hrs to fix

        Function spawn has 57 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          const spawn = () => {
            const wipeOpts = [
              '-token', opts.token,
              cloud.toString(),
              directories.toString(),
        Severity: Major
        Found in lib/agent/actions/wipe/index.js - About 2 hrs to fix

          Function RemoteTerminal has 57 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          var RemoteTerminal = function(options) {
          
            var self = this;
            var options = options || {};
          
          
          Severity: Major
          Found in lib/agent/actions/remote-terminal/index.js - About 2 hrs to fix

            Function get_active_access_point has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
            Open

            exports.get_active_access_point = (callback) => {
              exports.isWifiPermissionActive((itWorks) => {
                if (itWorks) {
                  const processActiveAp = (stdout) => {
                    if (stdout.includes('AirPort: Off') || !stdout.includes('SSID')) {
            Severity: Minor
            Found in lib/agent/providers/network/mac.js - About 2 hrs to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function gather has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
            Open

            const gather = (reportName, list, cb) => {
              const data = {};
              let gathered = false;
              let count = list.length;
              let listReports = [...list];
            Severity: Minor
            Found in lib/agent/reports.js - About 2 hrs to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function fetchLocation has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
            Open

            const fetchLocation = (typeFetch, callback) => {
              if (callback && typeof callback === 'function') locCallbacks.push(callback);
              if (checking) return;
            
              const fireCallbacks = (err, coords) => {
            Severity: Minor
            Found in lib/agent/triggers/location/index.js - About 2 hrs to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            File index.js has 260 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            "use strict";
            //////////////////////////////////////////
            // Prey Node.js Windows Client Functions
            // (c) 2011 - Fork Ltd.
            // by Tomas Pollak - http://forkhq.com
            Severity: Minor
            Found in lib/system/windows/index.js - About 2 hrs to fix

              Function setUpHooks has 56 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              const setUpHooks = () => {
                if (Object.keys(eventTriggers).length === 0) return;
              
                Object.keys(eventTriggers).forEach((event) => {
                  hooks.on(event.split('-')[0], (info) => {
              Severity: Major
              Found in lib/agent/actions/triggers/index.js - About 2 hrs to fix

                Function activate_event has 55 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                exports.activate_event = (trigger) => {
                  let eventIndex;
                  try {
                    eventIndex = trigger.automation_events.findIndex((obj) => eventsList.indexOf(obj.type) > -1);
                  } catch (e) {
                Severity: Major
                Found in lib/agent/actions/triggers/index.js - About 2 hrs to fix

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                    if (osName !== 'windows') {
                      const error = new Error('Action only allowed on Windows 1O');
                      error.code = 3;
                      error.name = errorFullwipe.find((x) => x.code === error.code).message;
                      return cb(error);
                  Severity: Major
                  Found in lib/agent/actions/fullwipe/index.js and 1 other location - About 2 hrs to fix
                  lib/agent/actions/factoryreset/index.js on lines 34..39

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 79.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                    get_files_prey_in_temp(function (err, files) {
                      if (err) console.log(err);
                      if (err) return cb();
                      if (files && files.length == 0) return cb();
                      count = files.length;
                  Severity: Major
                  Found in lib/conf/tasks/clear_files_prey_temp.js and 1 other location - About 2 hrs to fix
                  lib/conf/tasks/clear_folders.js on lines 69..75

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 79.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                    get_folders_old_versions(function (err, folders) {
                      if (err) console.log(err);
                      if (err) return cb();
                      if (folders && folders.length == 0) return cb();
                      count = folders.length;
                  Severity: Major
                  Found in lib/conf/tasks/clear_folders.js and 1 other location - About 2 hrs to fix
                  lib/conf/tasks/clear_files_prey_temp.js on lines 69..75

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 79.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Severity
                  Category
                  Status
                  Source
                  Language