Exemple #1
0
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 {
void nscapi::core_helper::core_proxy::register_command(std::string command, std::string description, std::list<std::string> aliases) {

	Plugin::RegistryRequestMessage request;
	nscapi::protobuf::functions::create_simple_header(request.mutable_header());

	Plugin::RegistryRequestMessage::Request *payload = request.add_payload();
	Plugin::RegistryRequestMessage::Request::Registration *regitem = payload->mutable_registration();
	regitem->set_plugin_id(plugin_id_);
	regitem->set_type(Plugin::Registry_ItemType_QUERY);
	regitem->set_name(command);
	regitem->mutable_info()->set_title(command);
	regitem->mutable_info()->set_description(description);
	BOOST_FOREACH(const std::string &alias, aliases) {
		regitem->add_alias(alias);
	}
Exemple #3
0
	void registry_control_module_unload(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();
		std::string name = request.get("name", "");

		payload->mutable_control()->set_type(Plugin::Registry_ItemType_MODULE);
		payload->mutable_control()->set_command(Plugin::Registry_Command_UNLOAD);
		payload->mutable_control()->set_name(name);
		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;
	}
Exemple #4
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;
	}
Exemple #5
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;
	}