예제 #1
0
파일: extscr_cli.cpp 프로젝트: mickem/nscp
void extscr_cli::list(const Plugin::ExecuteRequestMessage::Request &request, Plugin::ExecuteResponseMessage::Response *response) {
	po::variables_map vm;
	po::options_description desc;
	bool json = false, query = false, lib = false;

	desc.add_options()
		("help", "Show help.")

#ifdef HAVE_JSON_SPIRIT
		("json", po::bool_switch(&json),
			"Return the list in json format.")
#endif
		("query", po::bool_switch(&query),
			"List queries instead of scripts (for aliases).")
		("include-lib", po::bool_switch(&lib),
			"Do not ignore any lib folders.")

		;

	try {
		npo::basic_command_line_parser cmd(request);
		cmd.options(desc);

		po::parsed_options parsed = cmd.run();
		po::store(parsed, vm);
		po::notify(vm);
	} catch (const std::exception &e) {
		return npo::invalid_syntax(desc, request.command(), "Invalid command line: " + utf8::utf8_from_native(e.what()), *response);
	}

	if (vm.count("help")) {
		nscapi::protobuf::functions::set_response_good(*response, npo::help(desc));
		return;
	}
	std::string resp;
#ifdef HAVE_JSON_SPIRIT
	json_spirit::Array data;
#endif
	if (query) {
		Plugin::RegistryRequestMessage rrm;
		Plugin::RegistryResponseMessage response;
		Plugin::RegistryRequestMessage::Request *payload = rrm.add_payload();
		payload->mutable_inventory()->set_fetch_all(true);
		payload->mutable_inventory()->add_type(Plugin::Registry_ItemType_QUERY);
		std::string pb_response;
		provider_->get_core()->registry_query(rrm.SerializeAsString(), pb_response);
		response.ParseFromString(pb_response);
		BOOST_FOREACH(const ::Plugin::RegistryResponseMessage_Response &p, response.payload()) {
			BOOST_FOREACH(const ::Plugin::RegistryResponseMessage_Response_Inventory &i, p.inventory()) {
				if (json) {
#ifdef HAVE_JSON_SPIRIT
					data.push_back(i.name());
#endif
				} else {
					resp += i.name() + "\n";
				}
			}
		}
	} else {
예제 #2
0
	void registry_inventory_modules(Mongoose::Request &request, Mongoose::StreamResponse &response) {
		if (!is_loggedin(request, response, password))
			return;

		Plugin::RegistryRequestMessage rrm;
		nscapi::protobuf::functions::create_simple_header(rrm.mutable_header());
		Plugin::RegistryRequestMessage::Request *payload = rrm.add_payload();
		if (request.get("all", "true") == "true")
			payload->mutable_inventory()->set_fetch_all(true);
		std::string type = request.get("type", "query");

		payload->mutable_inventory()->add_type(Plugin::Registry_ItemType_MODULE);
		std::string pb_response, json_response;
		core->registry_query(rrm.SerializeAsString(), pb_response);
		core->protobuf_to_json("RegistryResponseMessage", pb_response, json_response);
		response << json_response;
	}
예제 #3
0
	void registry_inventory(Mongoose::Request &request, Mongoose::StreamResponse &response) {
		if (!is_loggedin(request, response, password))
			return;

		Plugin::RegistryRequestMessage rrm;
		nscapi::protobuf::functions::create_simple_header(rrm.mutable_header());
		Plugin::RegistryRequestMessage::Request *payload = rrm.add_payload();
		if (request.get("all", "true") == "true")
			payload->mutable_inventory()->set_fetch_all(true);
		std::string type = request.get("type", "query");

		if (type == "query")
			payload->mutable_inventory()->add_type(Plugin::Registry_ItemType_QUERY);
		else if (type == "command")
			payload->mutable_inventory()->add_type(Plugin::Registry_ItemType_COMMAND);
		else if (type == "module")
			payload->mutable_inventory()->add_type(Plugin::Registry_ItemType_MODULE);
		else if (type == "query-alias")
			payload->mutable_inventory()->add_type(Plugin::Registry_ItemType_QUERY_ALIAS);
		else if (type == "all")
			payload->mutable_inventory()->add_type(Plugin::Registry_ItemType_ALL);
		else {
			response.setCode(HTTP_SERVER_ERROR);
			response << "500 Invalid type. Possible types are: query, command, plugin, query-alias, all";
			return;
		}
		std::string pb_response, json_response;
		core->registry_query(rrm.SerializeAsString(), pb_response);
		core->protobuf_to_json("RegistryResponseMessage", pb_response, json_response);
		response << json_response;
	}