1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ 2 3 #ifndef CONSOLEHANDLER_H 4 #define CONSOLEHANDLER_H 5 6 #include "remote/httphandler.hpp" 7 #include "base/scriptframe.hpp" 8 9 namespace icinga 10 { 11 12 struct ApiScriptFrame 13 { 14 double Seen{0}; 15 int NextLine{1}; 16 std::map<String, String> Lines; 17 Dictionary::Ptr Locals; 18 }; 19 20 class ConsoleHandler final : public HttpHandler 21 { 22 public: 23 DECLARE_PTR_TYPEDEFS(ConsoleHandler); 24 25 bool HandleRequest( 26 AsioTlsStream& stream, 27 const ApiUser::Ptr& user, 28 boost::beast::http::request<boost::beast::http::string_body>& request, 29 const Url::Ptr& url, 30 boost::beast::http::response<boost::beast::http::string_body>& response, 31 const Dictionary::Ptr& params, 32 boost::asio::yield_context& yc, 33 HttpServerConnection& server 34 ) override; 35 36 static std::vector<String> GetAutocompletionSuggestions(const String& word, ScriptFrame& frame); 37 38 private: 39 static bool ExecuteScriptHelper(boost::beast::http::request<boost::beast::http::string_body>& request, 40 boost::beast::http::response<boost::beast::http::string_body>& response, 41 const Dictionary::Ptr& params, const String& command, const String& session, bool sandboxed); 42 static bool AutocompleteScriptHelper(boost::beast::http::request<boost::beast::http::string_body>& request, 43 boost::beast::http::response<boost::beast::http::string_body>& response, 44 const Dictionary::Ptr& params, const String& command, const String& session, bool sandboxed); 45 46 }; 47 48 } 49 50 #endif /* CONSOLEHANDLER_H */ 51