Add unban action
This commit is contained in:
parent
76ae0622e9
commit
1f46e83507
|
@ -19,15 +19,21 @@ class GreeterClient {
|
||||||
public:
|
public:
|
||||||
GreeterClient(std::shared_ptr<Channel> channel) : stub_(Fastnetmon::NewStub(channel)) {}
|
GreeterClient(std::shared_ptr<Channel> channel) : stub_(Fastnetmon::NewStub(channel)) {}
|
||||||
|
|
||||||
void ExecuteBan(std::string host) {
|
void ExecuteBan(std::string host, bool is_ban) {
|
||||||
ClientContext context;
|
ClientContext context;
|
||||||
fastmitigation::ExecuteBanRequest request;
|
fastmitigation::ExecuteBanRequest request;
|
||||||
fastmitigation::ExecuteBanReply reply;
|
fastmitigation::ExecuteBanReply reply;
|
||||||
|
|
||||||
request.set_ip_address(host);
|
request.set_ip_address(host);
|
||||||
|
|
||||||
Status status = stub_->ExecuteBan(&context, request, &reply);
|
Status status;
|
||||||
|
|
||||||
|
if (is_ban) {
|
||||||
|
status = stub_->ExecuteBan(&context, request, &reply);
|
||||||
|
} else {
|
||||||
|
status = stub_->ExecuteUnBan(&context, request, &reply);
|
||||||
|
}
|
||||||
|
|
||||||
if (status.ok()) {
|
if (status.ok()) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -105,14 +111,19 @@ int main(int argc, char** argv) {
|
||||||
|
|
||||||
if (request_command == "get_banlist") {
|
if (request_command == "get_banlist") {
|
||||||
greeter.GetBanList();
|
greeter.GetBanList();
|
||||||
} else if (request_command == "ban") {
|
} else if (request_command == "ban" or request_command == "unban") {
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
std::cerr << "Please provide banned IP" << std::endl;
|
std::cerr << "Please provide IP for action" << std::endl;
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ip_for_ban = argv[2];
|
std::string ip_for_ban = argv[2];
|
||||||
greeter.ExecuteBan(ip_for_ban);
|
|
||||||
|
if (request_command == "ban") {
|
||||||
|
greeter.ExecuteBan(ip_for_ban, true);
|
||||||
|
} else {
|
||||||
|
greeter.ExecuteBan(ip_for_ban, false);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "Unknown command" << std::endl;
|
std::cerr << "Unknown command" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,12 @@ class GreeterServiceImpl final : public Fastnetmon::Service {
|
||||||
|
|
||||||
return Status::OK;
|
return Status::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Status ExecuteUnBan(ServerContext* context, const fastmitigation::ExecuteBanRequest* request, fastmitigation::ExecuteBanReply* reply) override {
|
||||||
|
std::cout << "We asked for unban for IP: " << request->ip_address() << std::endl;
|
||||||
|
|
||||||
|
return Status::OK;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void RunServer() {
|
void RunServer() {
|
||||||
|
|
|
@ -5,6 +5,7 @@ package fastmitigation;
|
||||||
service Fastnetmon {
|
service Fastnetmon {
|
||||||
rpc GetBanlist(BanListRequest) returns (stream BanListReply) {}
|
rpc GetBanlist(BanListRequest) returns (stream BanListReply) {}
|
||||||
rpc ExecuteBan(ExecuteBanRequest) returns (ExecuteBanReply) {}
|
rpc ExecuteBan(ExecuteBanRequest) returns (ExecuteBanReply) {}
|
||||||
|
rpc ExecuteUnBan(ExecuteBanRequest) returns (ExecuteBanReply) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We could not create RPC method without params
|
// We could not create RPC method without params
|
||||||
|
|
Loading…
Reference in New Issue