Merge branch 'master' into 1.4.0

# Conflicts:
#	server/CMakeLists.txt
#	server/src/client/voice/VoiceClientConnection.cpp
This commit is contained in:
WolverinDEV 2019-10-21 21:01:23 +02:00
commit 7f1254b05e
6 changed files with 168 additions and 71 deletions

@ -1 +1 @@
Subproject commit 965281a51a1f8fbaebbfc9cfeaa51dd25ce49385
Subproject commit 819ba6d0903e1d102fff5921669d223ed72982c4

View File

@ -267,7 +267,6 @@ target_link_libraries(TeaSpeakServer
sqlite3
${LIBRARY_PATH_BREAKPAD}
${LIBRARY_PATH_JDBC}
${LIBRARY_PATH_PROTOBUF}
#${LIBWEBRTC_LIBRARIES} #ATTENTIAN! WebRTC does not work with crypto! (Already contains a crypto version)

View File

@ -309,7 +309,7 @@ std::shared_ptr<Group> GroupManager::createGroup(GroupTarget target, GroupType t
return group;
}
bool GroupManager::copyGroup(std::shared_ptr<Group> group, GroupType type, std::string name, ServerId targetServerId) {
GroupId GroupManager::copyGroup(std::shared_ptr<Group> group, GroupType type, std::string name, ServerId targetServerId) {
auto group_server = group->handle->getServerId();
auto groupId = generateGroupId(this->sql);
@ -331,14 +331,14 @@ bool GroupManager::copyGroup(std::shared_ptr<Group> group, GroupType type, std::
this->loadGroupFormDatabase(groupId);
else if(this->root)
this->root->loadGroupFormDatabase(groupId);
return true;
return groupId;
}
bool GroupManager::copyGroupPermissions(const shared_ptr<Group> &source, const shared_ptr<Group> &target) {
auto targetServer = target->handle->getServerId();
auto sourceServer = source->handle->getServerId();
auto res = sql::command(this->sql, "DELETE FROM `permissions` WHERE `serverId` = :sid AND `type` = :type AND `id` = :id", variable{":sid", this->getServerId()}, variable{":type", SQL_PERM_GROUP}, variable{":id", target->groupId()}).execute();
auto res = sql::command(this->sql, "DELETE FROM `permissions` WHERE `serverId` = :sid AND `type` = :type AND `id` = :id", variable{":sid", targetServer}, variable{":type", SQL_PERM_GROUP}, variable{":id", target->groupId()}).execute();
LOG_SQL_CMD(res);
res = sql::command(this->sql, "INSERT INTO `permissions` (`serverId`, `type`, `id`, `channelId`, `permId`, `value`, `grant`) SELECT :tsid AS `serverId`, `type`, :target AS `id`, 0 AS `channelId`, `permId`, `value`,`grant` FROM `permissions` WHERE `serverId` = :ssid AND `type` = :type AND `id` = :source",

View File

@ -190,7 +190,7 @@ namespace ts {
void setChannelGroup(ClientDbId cldbId, std::shared_ptr<Group>, std::shared_ptr<BasicChannel> , std::chrono::time_point<std::chrono::system_clock> until = std::chrono::time_point<std::chrono::system_clock>());
std::shared_ptr<Group> createGroup(GroupTarget target, GroupType type, std::string name);
bool copyGroup(std::shared_ptr<Group> group, GroupType type, std::string name, ServerId targetServerId);
GroupId copyGroup(std::shared_ptr<Group> group, GroupType type, std::string name, ServerId targetServerId);
bool copyGroupPermissions(const std::shared_ptr<Group>& source, const std::shared_ptr<Group>& target);
bool reloadGroupPermissions(std::shared_ptr<Group>);

View File

@ -983,39 +983,91 @@ CommandResult ConnectedClient::handleCommandChannelGroupAdd(Command &cmd) {
CommandResult ConnectedClient::handleCommandChannelGroupCopy(Command &cmd) {
CMD_RESET_IDLE;
CMD_CHK_AND_INC_FLOOD_POINTS(5);
auto ref_server = this->server;
CACHED_PERM_CHECK(permission::b_virtualserver_channelgroup_create, 1, true);
auto group_manager = this->server ? this->server->getGroupManager() : serverInstance->getGroupManager().get();
auto src = group_manager->findGroup(cmd["scgid"].as<GroupId>());
if (!src || src->target() != GROUPTARGET_CHANNEL) return {findError("parameter_invalid"), "invalid channel group id"};
auto group_manager = this->server ? this->server->groups : serverInstance->getGroupManager().get();
bool global = false;
if(cmd[0].has("tcgid")&& cmd["tcgid"].as<GroupId>() != 0) {
auto target = group_manager->findGroup(cmd["tcgid"].as<GroupId>());
if (!target || target->target() != GROUPTARGET_CHANNEL) return {findError("parameter_invalid"), "invalid target channel group id"};
auto result = group_manager->copyGroupPermissions(src, target);
if(!result) return {findError("vs_critical"), "could not copy group!"};
global = !this->server || group_manager->isLocalGroup(target);
auto source_group_id = cmd["scgid"].as<GroupId>();
auto source_group = group_manager->findGroup(source_group_id);
if(!source_group || source_group->target() != GROUPTARGET_CHANNEL)
return {findError("group_invalid_id"), "invalid source group"};
const auto group_type_modificable = [&](GroupType type) {
switch(type) {
case GroupType::GROUP_TYPE_TEMPLATE:
if(!this->permission_granted(this->permissionValue(permission::b_serverinstance_modify_templates, 0), 1, true))
return permission::b_serverinstance_modify_templates;
break;
case GroupType::GROUP_TYPE_QUERY:
if(!this->permission_granted(this->permissionValue(permission::b_serverinstance_modify_querygroup, 0), 1, true))
return permission::b_serverinstance_modify_querygroup;
break;
default:
break;
}
return permission::undefined;
};
{
auto result = group_type_modificable(source_group->type());
if(result != permission::undefined)
return CommandResultPermissionError{result};
}
auto global_update = false;
if(cmd[0].has("tcgid") && cmd["tcgid"].as<GroupId>() != 0) {
//Copy an existing group
auto target_group = group_manager->findGroup(cmd["tcgid"]);
if(!target_group || target_group->target() != GROUPTARGET_CHANNEL)
return {findError("group_invalid_id"), "invalid target group"};
{
auto result = group_type_modificable(target_group->type());
if(result != permission::undefined)
return CommandResultPermissionError{result};
}
if(!target_group->permission_granted(permission::i_channel_group_needed_modify_power, this->calculate_permission_value(permission::i_channel_group_modify_power, 0), true))
return CommandResultPermissionError{permission::i_channel_group_modify_power};
if(!group_manager->copyGroupPermissions(source_group, target_group))
return {findError("vs_critical"), "failed to copy group permissions"};
global_update = !this->server || !group_manager->isLocalGroup(target_group);
} else {
auto type = cmd["type"].as<GroupType>();
if(type == GroupType::GROUP_TYPE_QUERY)
CACHED_PERM_CHECK(permission::b_serverinstance_modify_querygroup, 1, true);
if(type == GroupType::GROUP_TYPE_TEMPLATE)
CACHED_PERM_CHECK(permission::b_serverinstance_modify_templates, 1, true);
//Copy a new group
auto target_type = cmd["type"].as<GroupType>();
if(type == GroupType::GROUP_TYPE_NORMAL && !this->server) return {findError("parameter_invalid"), "You cant create normal channel groups on the template server"};
auto result = group_manager->copyGroup(src, cmd["type"], cmd["name"], type == GROUP_TYPE_NORMAL ? this->getServerId() : 0); //TODO maybe check by name? No duplicated groups?
if (!result) return {findError("vs_critical"), "could not copy group!"};
global = !this->server || type != GroupType::GROUP_TYPE_NORMAL;
{
auto result = group_type_modificable(target_type);
if(result != permission::undefined)
return CommandResultPermissionError{result};
}
if(!ref_server && target_type == GroupType::GROUP_TYPE_NORMAL)
return {findError("parameter_invalid"), "You cant create normal groups on the template server!"};
if(!group_manager->findGroup(GroupTarget::GROUPTARGET_CHANNEL, cmd["name"].string()).empty())
return {findError("group_name_used"), "You cant create normal groups on the template server!"};
auto target_group_id = group_manager->copyGroup(source_group, target_type, cmd["name"], target_type != GroupType::GROUP_TYPE_NORMAL ? 0 : this->getServerId());
if(target_group_id == 0)
return {findError("vs_critical"), "failed to copy group"};
if(this->getType() == ClientType::CLIENT_QUERY) {
Command notify("");
notify["cgid"] = group_manager->availableChannelGroups(false).back()->groupId();
notify["cgid"] = target_group_id;
this->sendCommand(notify);
}
global_update = !this->server || !group_manager->isLocalGroup(group_manager->findGroup(target_group_id));
}
for(const auto& server : (global ? serverInstance->getVoiceServerManager()->serverInstances() : deque<shared_ptr<TSServer>>{this->server}))
for(const auto& server : (global_update ? serverInstance->getVoiceServerManager()->serverInstances() : deque<shared_ptr<TSServer>>{this->server}))
if(server)
server->forEachClient([](shared_ptr<ConnectedClient> cl) {
cl->notifyChannelGroupList();
@ -2578,48 +2630,94 @@ CommandResult ConnectedClient::handleCommandServerGroupAdd(Command &cmd) {
return CommandResult::Success;
}
//name=Server\sAdmin\s(Copy) ssgid=1 tsgid=0 type=1
CommandResult ConnectedClient::handleCommandServerGroupCopy(Command &cmd) {
CMD_RESET_IDLE;
CMD_CHK_AND_INC_FLOOD_POINTS(5);
auto ref_server = this->server;
CACHED_PERM_CHECK(permission::b_virtualserver_servergroup_create, 1, true);
auto group_manager = this->server ? this->server->groups : serverInstance->getGroupManager().get();
bool global = false;
auto src = group_manager->findGroup(cmd["ssgid"].as<GroupId>());
if (!src || src->target() != GROUPTARGET_SERVER) return {findError("parameter_invalid"), "invalid server group id"};
if(cmd[0].has("tsgid") && cmd["tsgid"].as<GroupId>() != 0) {
auto target = group_manager->findGroup(cmd["tsgid"].as<GroupId>());
if (!target || target->target() != GROUPTARGET_SERVER) return {findError("parameter_invalid"), "invalid target server group id"};
auto result = group_manager->copyGroupPermissions(src, target);
if(!result) return {findError("vs_critical"), "could not copy group!"};
global = !this->server || group_manager->isLocalGroup(target);
} else {
//GroupType
auto type = cmd["type"].as<GroupType>();
if(type == GroupType::GROUP_TYPE_NORMAL && !this->server) return {findError("parameter_invalid"), "You cant create normal groups on the template server!"};
if(type == GroupType::GROUP_TYPE_QUERY) {
if(!this->permission_granted(this->cached_permission_value(permission::b_serverinstance_modify_querygroup), 1, true))
return CommandResultPermissionError{permission::b_serverinstance_modify_querygroup};
} else if(type == GroupType::GROUP_TYPE_TEMPLATE) {
if(!this->permission_granted(this->cached_permission_value(permission::b_serverinstance_modify_templates), 1, true))
return CommandResultPermissionError{permission::b_serverinstance_modify_templates};
auto source_group_id = cmd["ssgid"].as<GroupId>();
auto source_group = group_manager->findGroup(source_group_id);
if(!source_group || source_group->target() != GROUPTARGET_SERVER)
return {findError("group_invalid_id"), "invalid source group"};
const auto group_type_modificable = [&](GroupType type) {
switch(type) {
case GroupType::GROUP_TYPE_TEMPLATE:
if(!this->permission_granted(this->permissionValue(permission::b_serverinstance_modify_templates, 0), 1, true))
return permission::b_serverinstance_modify_templates;
break;
case GroupType::GROUP_TYPE_QUERY:
if(!this->permission_granted(this->permissionValue(permission::b_serverinstance_modify_querygroup, 0), 1, true))
return permission::b_serverinstance_modify_querygroup;
break;
default:
break;
}
return permission::undefined;
};
{
auto result = group_type_modificable(source_group->type());
if(result != permission::undefined)
return CommandResultPermissionError{result};
}
auto result = group_manager->copyGroup(src, type, cmd["name"], type != GroupType::GROUP_TYPE_NORMAL ? 0 : this->getServerId()); //TODO maybe check by name? No duplicated groups?
if (!result) return {findError("vs_critical"), "could not copy group!"};
global = !this->server || type != GroupType::GROUP_TYPE_NORMAL;
auto global_update = false;
if(cmd[0].has("tsgid") && cmd["tsgid"].as<GroupId>() != 0) {
//Copy an existing group
auto target_group = group_manager->findGroup(cmd["tsgid"]);
if(!target_group || target_group->target() != GROUPTARGET_SERVER)
return {findError("group_invalid_id"), "invalid target group"};
{
auto result = group_type_modificable(target_group->type());
if(result != permission::undefined)
return CommandResultPermissionError{result};
}
if(!target_group->permission_granted(permission::i_server_group_needed_modify_power, this->calculate_permission_value(permission::i_server_group_modify_power, 0), true))
return CommandResultPermissionError{permission::i_server_group_modify_power};
if(!group_manager->copyGroupPermissions(source_group, target_group))
return {findError("vs_critical"), "failed to copy group permissions"};
global_update = !this->server || !group_manager->isLocalGroup(target_group);
} else {
//Copy a new group
auto target_type = cmd["type"].as<GroupType>();
{
auto result = group_type_modificable(target_type);
if(result != permission::undefined)
return CommandResultPermissionError{result};
}
if(!ref_server && target_type == GroupType::GROUP_TYPE_NORMAL)
return {findError("parameter_invalid"), "You cant create normal groups on the template server!"};
if(!group_manager->findGroup(GroupTarget::GROUPTARGET_SERVER, cmd["name"].string()).empty())
return {findError("group_name_used"), "You cant create normal groups on the template server!"};
auto target_group_id = group_manager->copyGroup(source_group, target_type, cmd["name"], target_type != GroupType::GROUP_TYPE_NORMAL ? 0 : this->getServerId());
if(target_group_id == 0)
return {findError("vs_critical"), "failed to copy group"};
if(this->getType() == ClientType::CLIENT_QUERY) {
Command notify("");
notify["sgid"] = group_manager->availableServerGroups(false).back()->groupId();
notify["sgid"] = target_group_id;
this->sendCommand(notify);
}
global_update = !this->server || !group_manager->isLocalGroup(group_manager->findGroup(target_group_id));
}
for(const auto& server : (global ? serverInstance->getVoiceServerManager()->serverInstances() : deque<shared_ptr<TSServer>>{this->server}))
for(const auto& server : (global_update ? serverInstance->getVoiceServerManager()->serverInstances() : deque<shared_ptr<TSServer>>{this->server}))
if(server)
server->forEachClient([](shared_ptr<ConnectedClient> cl) {
cl->notifyServerGroupList();

2
shared

@ -1 +1 @@
Subproject commit a3c5bcb9f2f36598675da74dfb118b76eeff99fa
Subproject commit c532266cb8b1ba577e063c6ed14a810374c8c84f