getName()); if (!is_null($existingCommand) && $command_id != $existingCommand->getId()) { self::badInput("Command name already exists"); } if (is_null($command->getName()) || strlen($command->getName()) == 0) { self::badInput("Missing command name"); } HostsBusiness::getById($command->getHostId()); CommandTypesBusiness::getById($command->getCommandTypeId()); if (is_null($command->getDescription())) { $command->setDescription(""); } if (is_null($command->getData()) || strlen($command->getData()) == 0) { $command->setData("{}"); } $json = json_decode($command->getData()); if (is_null($json)) { self::badInput("Command data could not be converted to json"); } } public static function getAllLight($_user, $page = 0, $perPage = PHP_INT_MAX, $query = "") { $values = self::getAll($page, $perPage, $query); if (LuticatePermissionsBusiness::getEffectivePermission($_user->getId(), "CAMOTION_COMMAND_EDIT")->getValue()) { return $values; } return $values->map(function($command) { $command->setData(null); return $command; }); } public static function getLight($_user, $command_id) { $command = self::getById($command_id); if (LuticatePermissionsBusiness::getEffectivePermission($_user->getId(), "CAMOTION_COMMAND_EDIT")->getValue()) { return $command; } $command->setData(null); return $command; } public static function add(CommandsDbo $command) { self::checkCommand($command); return CommandsDataAccess::addId($command); } public static function edit(CommandsDbo $command, $command_id) { self::getById($command_id); self::checkCommand($command, $command_id); $command->setId($command_id); return CommandsDataAccess::editById($command_id, $command); } public static function exec($command_id) { /** * @var $command CommandsDbo * @var $host HostsDbo * @var $type CommandTypesDbo */ $command = self::getById($command_id); $host = HostsBusiness::getById($command->getHostId()); $type = CommandTypesBusiness::getById($command->getCommandTypeId()); return LuRequest::proxy('POST', $host->getUrl() . "/commands/exec", [], ["command" => $command->__toString(), "type" => $type->__toString()], ["X-Token" => $host->getToken()]); } }