public function dispatchCommands() { $dispatcher = $this->getContext()->getModel("Commands.CommandDispatcher", "Api"); $this->context->getLoggerManager()->log(print_r($this->selection, 1)); $this->selection = AppKitArrayUtil::uniqueMultidimensional($this->selection); $this->context->getLoggerManager()->log(print_r($this->selection, 1)); AppKitLogger::debug("Trying to send commands, targets: %s , data: %s ", json_encode($this->selection), json_encode($this->data)); foreach ($this->selection as $target) { $console = $this->getConsoleInstance($target['instance']); $dispatcher->setConsoleContext($console); AppKitLogger::debug("Submitting command %s to %s", $this->command, json_encode($target)); $dispatcher->submitCommand($this->command, array_merge($target, $this->data)); AppKitLogger::debug("Finished submitting command"); } }
public function submitCommand($cmd_name, array $params, $commandClass = array("Console.ConsoleCommand", "Api")) { try { $user = $this->getContext()->getUser()->getNsmUser(); $onlySimple = $user->hasTarget('IcingaCommandRestrictions'); $command = $this->getCommand($cmd_name); $string = $this->buildCommandString($command, $params) . "\n"; if ($onlySimple && !$command["isSimple"]) { throw new Exception("Could not send command. Your user isn't allowed to send this command."); } $this->context->getLoggerManager()->log(sprintf('(%s) %s', $user->user_name, $string), AppKitLogger::COMMAND); AppKitLogger::debug("Sending icinga-command %s", $string); $cmd = $this->getContext()->getModel($commandClass[0], $commandClass[1], array("command" => "printf", "arguments" => array($string))); $cmd->stdoutFile("icinga_pipe"); $this->consoleContext->exec($cmd); if ($cmd->getReturnCode() != '0') { throw new Exception("Could not send command. Check if your webserver's user has correct permissions for writing to the command pipe."); } } catch (Exception $e) { $this->context->getLoggerManager()->log("Sending command failed " . $e->getMessage()); throw $e; } }
/** * Writes session data to database tables * @param string $id * @param mixed $data */ public function sessionWrite($id, &$data) { $max = ini_get('session.gc_maxlifetime'); $update = false; if (!$max) { $max = 1440; } $date = DateTime::createFromFormat('Y-m-d H:i:s', $this->NsmSession->session_modified); $m = md5($data); if ($date === false || time() - $date->getTimestamp() >= $max) { $update = true; } if (!$update && $this->NsmSession->session_checksum === $m) { return; } AppKitLogger::verbose("Writing new session information (checksum=%s)", $m); $this->NsmSession->session_data = $data; $this->NsmSession->session_checksum = $m; $this->NsmSession->session_modified = date('Y-m-d H:i:s'); $this->NsmSession->save(); AppKitLogger::debug("Write session update: %s", $id); AppKitLogger::verbose("Writing new session information successful"); }