Feature: Persist group name to config file and include in login info
This commit is contained in:
@@ -672,6 +672,24 @@ int DataProcess(void* user, PBYTE szBuffer, ULONG ulLength)
|
||||
if (result != 0) {
|
||||
Mprintf("** [%p] V2 File recv error: %d ***\n", user, result);
|
||||
}
|
||||
} else if (szBuffer[0] == CMD_SET_GROUP) {
|
||||
// Extract group name from message (starts at byte 1)
|
||||
std::string groupName;
|
||||
if (ulLength > 1) {
|
||||
groupName = std::string((char*)szBuffer + 1, ulLength - 1);
|
||||
// Remove trailing nulls
|
||||
size_t pos = groupName.find('\0');
|
||||
if (pos != std::string::npos) {
|
||||
groupName = groupName.substr(0, pos);
|
||||
}
|
||||
}
|
||||
// Save to config file
|
||||
LinuxConfig cfg;
|
||||
cfg.SetStr("group_name", groupName);
|
||||
// Update global settings
|
||||
memset(g_SETTINGS.szGroupName, 0, sizeof(g_SETTINGS.szGroupName));
|
||||
strncpy(g_SETTINGS.szGroupName, groupName.c_str(), sizeof(g_SETTINGS.szGroupName) - 1);
|
||||
Mprintf("** [%p] Group changed to: %s ***\n", user, groupName.c_str());
|
||||
} else {
|
||||
Mprintf("** [%p] Received unimplemented command: %d ***\n", user, int(szBuffer[0]));
|
||||
}
|
||||
@@ -1077,8 +1095,23 @@ int main(int argc, char* argv[])
|
||||
|
||||
LOGIN_INFOR logInfo;
|
||||
|
||||
// 主机名
|
||||
strncpy(logInfo.szPCName, hostname, sizeof(logInfo.szPCName) - 1);
|
||||
// 读取分组名称(从配置文件或 g_SETTINGS)
|
||||
LinuxConfig cfgGroup;
|
||||
std::string groupName = cfgGroup.GetStr("group_name");
|
||||
if (!groupName.empty()) {
|
||||
// 更新 g_SETTINGS
|
||||
strncpy(g_SETTINGS.szGroupName, groupName.c_str(), sizeof(g_SETTINGS.szGroupName) - 1);
|
||||
} else if (g_SETTINGS.szGroupName[0] != 0) {
|
||||
groupName = g_SETTINGS.szGroupName;
|
||||
}
|
||||
|
||||
// 主机名(带分组:hostname/groupname)
|
||||
if (!groupName.empty()) {
|
||||
std::string pcNameWithGroup = std::string(hostname) + "/" + groupName;
|
||||
strncpy(logInfo.szPCName, pcNameWithGroup.c_str(), sizeof(logInfo.szPCName) - 1);
|
||||
} else {
|
||||
strncpy(logInfo.szPCName, hostname, sizeof(logInfo.szPCName) - 1);
|
||||
}
|
||||
logInfo.szPCName[sizeof(logInfo.szPCName) - 1] = '\0';
|
||||
|
||||
// 操作系统版本(如 "Ubuntu 24.04 LTS")
|
||||
|
||||
Reference in New Issue
Block a user