Using new permissions system consequently

This commit is contained in:
WolverinDEV
2020-01-26 14:21:34 +01:00
parent bb2e7699dc
commit c7b6c0a3ba
37 changed files with 8982 additions and 657 deletions
+5
View File
@@ -529,6 +529,11 @@ void QueryClient::sendCommand(const ts::Command &command, bool) {
logTrace(LOG_QUERY, "Send command {}", cmd);
}
void QueryClient::sendCommand(const ts::command_builder &command, bool) {
writeMessage(command.build() + config::query::newlineCharacter);
logTrace(LOG_QUERY, "Send command {}", command.build());
}
void QueryClient::tick(const std::chrono::system_clock::time_point &time) {
ConnectedClient::tick(time);
}
+1
View File
@@ -26,6 +26,7 @@ namespace ts {
void writeMessage(const std::string&);
void sendCommand(const ts::Command &command, bool low = false) override;
void sendCommand(const ts::command_builder &command, bool low) override;
bool disconnect(const std::string &reason) override;
bool closeConnection(const std::chrono::system_clock::time_point& timeout = std::chrono::system_clock::time_point()) override;
+30 -30
View File
@@ -11,6 +11,8 @@
#include <src/ShutdownHelper.h>
#include <ThreadPool/Timer.h>
#include "src/client/command_handler/helpers.h"
using namespace std;
using namespace std::chrono;
using namespace ts;
@@ -219,7 +221,7 @@ command_result QueryClient::handleCommandLogin(Command& cmd) {
unique_lock tree_lock(this->server->channel_tree_lock);
if(joined_channel)
this->server->client_move(this->ref(), joined_channel, nullptr, "", ViewReasonId::VREASON_USER_ACTION, false, tree_lock);
} else if(!this->permissionGranted(permission::PERMTEST_ORDERED, permission::b_virtualserver_select_godmode, 1))
} else if(!permission::v2::permission_granted(1, this->calculate_permission(permission::b_virtualserver_select_godmode, 1)))
this->server->assignDefaultChannel(this->ref(), true);
else
this->update_cached_permissions();
@@ -271,7 +273,7 @@ command_result QueryClient::handleCommandLogout(Command &) {
if(joined) {
unique_lock server_channel_w_lock(this->server->channel_tree_lock, defer_lock);
this->server->client_move(this->ref(), joined, nullptr, "", ViewReasonId::VREASON_USER_ACTION, false, server_channel_w_lock);
} else if(!this->permissionGranted(permission::PERMTEST_ORDERED, permission::b_virtualserver_select_godmode, 1)) {
} else if(!permission::v2::permission_granted(1, this->calculate_permission(permission::b_virtualserver_select_godmode, 1))) {
this->server->assignDefaultChannel(this->ref(), true);
} else {
this->update_cached_permissions();
@@ -310,8 +312,8 @@ command_result QueryClient::handleCommandServerSelect(Command &cmd) {
if(target->getServerId() != this->query_account->bound_server)
return command_result{error::server_invalid_id, "You're a server bound query, and the target server isn't your origin."};
} else {
auto allowed = target->calculatePermission(permission::PERMTEST_ORDERED, this->getClientDatabaseId(), permission::b_virtualserver_select, this->getType(), nullptr);
if(allowed != -1 && allowed <= 0) return command_result{permission::b_virtualserver_select};
auto allowed = target->calculate_permission(permission::b_virtualserver_select, this->getClientDatabaseId(), this->getType(), 0);
if(!permission::v2::permission_granted(1, allowed)) return command_result{permission::b_virtualserver_select};
}
}
@@ -356,7 +358,7 @@ command_result QueryClient::handleCommandServerSelect(Command &cmd) {
this->subscribeChannel(this->server->channelTree->channels(), false, false);
}
auto negated_enforce_join = this->permissionGranted(permission::PERMTEST_ORDERED, permission::b_virtualserver_select_godmode, 1);
auto negated_enforce_join = permission::v2::permission_granted(1, this->calculate_permission(permission::b_virtualserver_select_godmode, 1));
if(!negated_enforce_join)
this->server->assignDefaultChannel(this->ref(), true);
else
@@ -387,8 +389,8 @@ command_result QueryClient::handleCommandLeft(Command&) {
CMD_REQ_SERVER;
CMD_REQ_CHANNEL;
CMD_RESET_IDLE;
ACTION_REQUIRES_GLOBAL_PERMISSION(permission::b_virtualserver_select_godmode, 1);
PERM_CHECK_CHANNELR(permission::b_virtualserver_select_godmode, 1, nullptr, 1);
unique_lock server_channel_lock(this->server->channel_tree_lock);
this->server->client_move(this->ref(), nullptr, nullptr, "leaving", ViewReasonId::VREASON_SERVER_LEFT, true, server_channel_lock);
return command_result{error::ok};
@@ -396,7 +398,7 @@ command_result QueryClient::handleCommandLeft(Command&) {
command_result QueryClient::handleCommandServerInfo(Command &) {
CMD_RESET_IDLE;
PERM_CHECKR(permission::b_virtualserver_info_view, 1, true);
ACTION_REQUIRES_GLOBAL_PERMISSION(permission::b_virtualserver_info_view, 1);
Command cmd("");
@@ -409,7 +411,7 @@ command_result QueryClient::handleCommandServerInfo(Command &) {
cmd["virtualserver_status"] = this->server ? ServerState::string(this->server->state) : "template";
if(this->server && this->permissionGranted(permission::PERMTEST_ORDERED, permission::b_virtualserver_connectioninfo_view, 1, nullptr, true)) {
if(this->server && permission::v2::permission_granted(1, this->calculate_permission(permission::b_virtualserver_connectioninfo_view, 0))) {
auto stats = this->server->getServerStatistics()->statistics();
auto report = this->server->serverStatistics->dataReport();
cmd["connection_bandwidth_sent_last_second_total"] = report.send_second;
@@ -478,8 +480,8 @@ command_result QueryClient::handleCommandServerInfo(Command &) {
}
command_result QueryClient::handleCommandChannelList(Command& cmd) {
PERM_CHECKR(permission::b_virtualserver_channel_list, 1, true);
CMD_RESET_IDLE;
ACTION_REQUIRES_GLOBAL_PERMISSION(permission::b_virtualserver_channel_list, 1);
Command result("");
@@ -497,7 +499,7 @@ command_result QueryClient::handleCommandChannelList(Command& cmd) {
bulk["channel_name"] = channel->name();
bulk["channel_order"] = channel->channelOrder();
bulk["total_clients"] = this->server ? this->server->getClientsByChannel(channel).size() : 0;
/* bulk["channel_needed_subscribe_power"] = channel->permissions()->getPermissionValue(permission::PERMTEST_ORDERED, permission::i_channel_needed_subscribe_power, channel, 0); */
/* bulk["channel_needed_subscribe_power"] = channel->permissions()->getPermissionValue(permission::i_channel_needed_subscribe_power, channel, 0); */
if(cmd.hasParm("flags")){
bulk["channel_flag_default"] = channel->properties()[property::CHANNEL_FLAG_DEFAULT].as<string>();
@@ -540,7 +542,8 @@ command_result QueryClient::handleCommandChannelList(Command& cmd) {
command_result QueryClient::handleCommandServerList(Command& cmd) {
CMD_RESET_IDLE;
PERM_CHECKR(permission::b_serverinstance_virtualserver_list, 1, true);
ACTION_REQUIRES_INSTANCE_PERMISSION(permission::b_serverinstance_virtualserver_list, 1);
Command res("");
int index = 0;
@@ -573,7 +576,7 @@ command_result QueryClient::handleCommandServerList(Command& cmd) {
command_result QueryClient::handleCommandServerCreate(Command& cmd) {
CMD_RESET_IDLE;
PERM_CHECKR(permission::b_virtualserver_create, 1, true);
ACTION_REQUIRES_INSTANCE_PERMISSION(permission::b_virtualserver_create, 1);
if(serverInstance->getVoiceServerManager()->getState() != ServerManager::STARTED) {
return command_result{error::vs_critical, "Server manager isn't started yet or not finished starting"};
@@ -650,7 +653,7 @@ command_result QueryClient::handleCommandServerCreate(Command& cmd) {
command_result QueryClient::handleCommandServerDelete(Command& cmd) {
CMD_RESET_IDLE;
PERM_CHECKR(permission::b_virtualserver_delete, 1, true);
ACTION_REQUIRES_INSTANCE_PERMISSION(permission::b_virtualserver_delete, 1);
if(serverInstance->getVoiceServerManager()->getState() != ServerManager::STARTED)
return command_result{error::vs_critical, "Server manager isn't started yet or not finished starting"};
@@ -664,7 +667,6 @@ command_result QueryClient::handleCommandServerDelete(Command& cmd) {
command_result QueryClient::handleCommandServerStart(Command& cmd) {
CMD_RESET_IDLE;
PERM_CHECKR(permission::b_virtualserver_start_any, 1, true);
if(serverInstance->getVoiceServerManager()->getState() != ServerManager::STARTED)
return command_result{error::vs_critical, "Server manager isn't started yet or not finished starting"};
@@ -672,10 +674,8 @@ command_result QueryClient::handleCommandServerStart(Command& cmd) {
if(!server) return command_result{error::server_invalid_id, "invalid bounded server"};
if(server->running()) return command_result{error::server_running, "server already running"};
if(server->calculatePermission(permission::PERMTEST_ORDERED, this->getClientDatabaseId(), permission::b_virtualserver_start, ClientType::CLIENT_QUERY, nullptr) != 1) {
if(!this->permissionGranted(permission::PERMTEST_HIGHEST, permission::b_virtualserver_start_any, 1))
return command_result{permission::b_virtualserver_start};
}
if(!permission::v2::permission_granted(1, server->calculate_permission(permission::b_virtualserver_start, this->getClientDatabaseId(), ClientType::CLIENT_QUERY, 0)))
ACTION_REQUIRES_INSTANCE_PERMISSION(permission::b_virtualserver_start_any, 1);
string err;
if(!server->start(err)) return command_result{error::vs_critical, err};
@@ -684,7 +684,7 @@ command_result QueryClient::handleCommandServerStart(Command& cmd) {
command_result QueryClient::handleCommandServerStop(Command& cmd) {
CMD_RESET_IDLE;
PERM_CHECKR(permission::b_virtualserver_stop, 1, true);
if(serverInstance->getVoiceServerManager()->getState() != ServerManager::STARTED)
return command_result{error::vs_critical, "Server manager isn't started yet or not finished starting"};
@@ -692,10 +692,8 @@ command_result QueryClient::handleCommandServerStop(Command& cmd) {
if(!server) return command_result{error::server_invalid_id, "invalid bounded server"};
if(!server->running()) return command_result{error::server_is_not_running, "server is not running"};
if(server->calculatePermission(permission::PERMTEST_ORDERED, this->getClientDatabaseId(), permission::b_virtualserver_stop, ClientType::CLIENT_QUERY, nullptr) != 1) {
if(!this->permissionGranted(permission::PERMTEST_HIGHEST, permission::b_virtualserver_stop_any, 1))
return command_result{permission::b_virtualserver_stop};
}
if(!permission::v2::permission_granted(1, server->calculate_permission(permission::b_virtualserver_stop, this->getClientDatabaseId(), ClientType::CLIENT_QUERY, 0)))
ACTION_REQUIRES_INSTANCE_PERMISSION(permission::b_virtualserver_stop_any, 1);
server->stop("server stopped");
return command_result{error::ok};
@@ -703,7 +701,7 @@ command_result QueryClient::handleCommandServerStop(Command& cmd) {
command_result QueryClient::handleCommandInstanceInfo(Command& cmd) {
PERM_CHECKR(permission::b_serverinstance_info_view, 1, true);
ACTION_REQUIRES_INSTANCE_PERMISSION(permission::b_serverinstance_info_view, 1);
Command res("");
for(const auto& e : serverInstance->properties().list_properties(property::FLAG_INSTANCE_VARIABLE, this->getType() == CLIENT_TEAMSPEAK ? property::FLAG_NEW : (uint16_t) 0))
@@ -716,7 +714,7 @@ command_result QueryClient::handleCommandInstanceInfo(Command& cmd) {
}
command_result QueryClient::handleCommandInstanceEdit(Command& cmd) {
PERM_CHECKR(permission::b_serverinstance_modify_settings, 1, true);
ACTION_REQUIRES_INSTANCE_PERMISSION(permission::b_serverinstance_modify_settings, 1);
for(const auto &key : cmd[0].keys()){
auto info = property::impl::info<property::InstanceProperties>(key);
@@ -739,7 +737,7 @@ command_result QueryClient::handleCommandInstanceEdit(Command& cmd) {
}
command_result QueryClient::handleCommandHostInfo(Command &) {
PERM_CHECKR(permission::b_serverinstance_info_view, 1, true);
ACTION_REQUIRES_INSTANCE_PERMISSION(permission::b_serverinstance_info_view, 1);
Command res("");
res["instance_uptime"] = duration_cast<seconds>(system_clock::now() - serverInstance->getStartTimestamp()).count();
@@ -774,7 +772,7 @@ command_result QueryClient::handleCommandHostInfo(Command &) {
}
command_result QueryClient::handleCommandGlobalMessage(Command& cmd) {
PERM_CHECKR(permission::b_serverinstance_textmessage_send, 1, true);
ACTION_REQUIRES_INSTANCE_PERMISSION(permission::b_serverinstance_textmessage_send, 1);
for(const auto &server : serverInstance->getVoiceServerManager()->serverInstances())
if(server->running()) server->broadcastMessage(server->getServerRoot(), cmd["msg"]);
@@ -801,7 +799,6 @@ command_result QueryClient::handleCommandBindingList(Command& cmd) {
//TODO with mapping!
command_result QueryClient::handleCommandServerSnapshotDeploy(Command& cmd) {
PERM_CHECKR(permission::b_virtualserver_snapshot_deploy, 1, true);
CMD_RESET_IDLE;
auto start = system_clock::now();
@@ -809,8 +806,11 @@ command_result QueryClient::handleCommandServerSnapshotDeploy(Command& cmd) {
string host = "0.0.0.0";
uint16_t port = 0;
if(this->server) {
ACTION_REQUIRES_GLOBAL_PERMISSION(permission::b_virtualserver_snapshot_deploy, 1);
host = this->server->properties()[property::VIRTUALSERVER_HOST].as<string>();
port = this->server->properties()[property::VIRTUALSERVER_PORT].as<uint16_t>();
} else {
ACTION_REQUIRES_INSTANCE_PERMISSION(permission::b_virtualserver_snapshot_deploy, 1);
}
auto hash = cmd["hash"].string();
@@ -862,7 +862,7 @@ command_result QueryClient::handleCommandServerSnapshotDeploy(Command& cmd) {
}
command_result QueryClient::handleCommandServerSnapshotCreate(Command& cmd) {
PERM_CHECKR(permission::b_virtualserver_snapshot_create, 1, true);
ACTION_REQUIRES_GLOBAL_PERMISSION(permission::b_virtualserver_snapshot_create, 1);
CMD_RESET_IDLE;
CMD_REQ_SERVER;
@@ -887,7 +887,7 @@ command_result QueryClient::handleCommandServerSnapshotCreate(Command& cmd) {
extern bool mainThreadActive;
command_result QueryClient::handleCommandServerProcessStop(Command& cmd) {
PERM_CHECKR(permission::b_serverinstance_stop, 1, true);
ACTION_REQUIRES_INSTANCE_PERMISSION(permission::b_serverinstance_stop, 1);
if(cmd[0].has("type")) {
if(cmd["type"] == "cancel") {