还是不行
CN25G(config-dnsproxy-doh)#show
DNS over HTTPS (DoH) Configuration
===========================================
Global DoH Switch : Enabled
-------------------------------------------
Configured DoH Servers:
ID Name Status URL
-----------------------------------------------------------
1 zzx on https://test2.com
2 test on test.com
===========================================
CN25G(config-dnsproxy-doh)#set 2
% Another server is being edited (ID: 1)
% Commit or abort current session first
CN25G(config-dnsproxy-doh)#set 1
CN25G(config-dnsproxy-doh-set)#
cancel - Cancel the doh set
commit - Commit the doh
dnsserver - Set doh dnsserver
name - Set doh name
status - Set doh status
end - Return to Privileged EXEC Mode
exit - Exit current mode
history - Display command history
no - Negate command
show - Display system information
CN25G(config-dnsproxy-doh-set)#
CN25G(config-dnsproxy-doh-set)#name test1
% Name updated for server 1: test1
CN25G(config-dnsproxy-doh-set)#commit
CN25G(config-dnsproxy-doh-set)#exit
CN25G(config-dnsproxy-doh)#show
DNS over HTTPS (DoH) Configuration
===========================================
Global DoH Switch : Enabled
-------------------------------------------
Configured DoH Servers:
ID Name Status URL
-----------------------------------------------------------
1 zzx on https://test2.com
2 test on test.com
===========================================
STATUS cli_dnsproxy_doh_server_set(cli_env *pCliEnv, const char *id_str) {
char buffer[128];
// 转换ID为数字
unsigned id_num = convert_id_str_to_num(id_str);
if (id_num == 0) {
snprintf(buffer, sizeof(buffer), "%% Invalid server ID: %s", id_str);
RCC_EXT_WriteStrLine(pCliEnv, buffer);
return ERROR;
}
// 检查编辑会话状态
if (s_doh_edit_ctx.in_edit) {
if (s_doh_edit_ctx.server_id == id_num) return OK;
snprintf(buffer, sizeof(buffer),
"%% Another server is being edited (ID: %u)\n"
"%% Commit or abort current session first",
s_doh_edit_ctx.server_id);
RCC_EXT_WriteStrLine(pCliEnv, buffer);
return ERROR;
}
CFG_DOH_SERVER_T **server_list = NULL;
APPL_ERRCODE ret = dmDohCfgServerGetAll(&server_list);
if (ret != ERR_NO_ERROR) {
snprintf(buffer, sizeof(buffer),
"%% Failed to get server list (error: 0x%X)", ret);
RCC_EXT_WriteStrLine(pCliEnv, buffer);
return ERROR;
}
// 查找匹配的服务器
bool found = false;
for (int i = 0; server_list[i] != NULL; i++) {
unsigned server_id = (unsigned)atoi(server_list[i]->id);
if (server_id == id_num) {
// 关键修正:直接引用原始数据结构
s_doh_edit_ctx.server_id = id_num;
s_doh_edit_ctx.server = *server_list[i]; // 结构体拷贝
found = true;
break;
}
}
// 释放服务器列表
dmDohCfgServerListFree(server_list);
if (!found) {
snprintf(buffer, sizeof(buffer),
"%% Server not found (ID: %u)", id_num);
RCC_EXT_WriteStrLine(pCliEnv, buffer);
return ERROR;
}
// 设置编辑状态
s_doh_edit_ctx.in_edit = true;
snprintf(buffer, sizeof(buffer), "%% Editing server (ID: %u)", id_num);
RCC_EXT_WriteStrLine(pCliEnv, buffer);
return OK;
}
// 提交编辑会话 - 统一处理函数
STATUS cli_dnsproxy_doh_server_set_commit(cli_env *pCliEnv) {
char buffer[256];
APPL_ERRCODE ret;
// 1. 验证编辑状态
if (!s_doh_edit_ctx.in_edit) {
RCC_EXT_WriteStrLine(pCliEnv, "%% No active edit session");
return ERROR;
}
// 2. 确保ID字段正确设置
CFG_DOH_SERVER_T *ent = &s_doh_edit_ctx.server;
snprintf(ent->id, sizeof(ent->id), "%u", s_doh_edit_ctx.server_id);
// 3. 调试日志:打印将要保存的配置
snprintf(buffer, sizeof(buffer),
"%% Saving config: ID=%s, Name=%s, URL=%s, Status=%s",
ent->id, ent->name, ent->server, ent->status);
RCC_EXT_WriteStrLine(pCliEnv, buffer);
// 4. 调用数据库API
ret = dmDohCfgServerSet(ent);
if (ret != ERR_NO_ERROR) {
snprintf(buffer, sizeof(buffer),
"%% Failed to update server (error: 0x%X)", ret);
RCC_EXT_WriteStrLine(pCliEnv, buffer);
return ERROR;
}
// 5. 清除编辑状态(关键修复)
s_doh_edit_ctx.in_edit = false;
// 6. 显示成功消息
snprintf(buffer, sizeof(buffer),
"%% Successfully committed changes for server %s", ent->id);
RCC_EXT_WriteStrLine(pCliEnv, buffer);
return OK;
}
STATUS cli_dnsproxy_doh_server_set_name(cli_env *pCliEnv, const char *new_name) {
// 1. 验证编辑状态
if (!s_doh_edit_ctx.in_edit) {
RCC_EXT_WriteStrLine(pCliEnv, "%% No active edit session");
return ERROR;
}
// 2. 设置新名称
strncpy(s_doh_edit_ctx.server.name, new_name, DNSPROXY_LEN_NAME64-1);
s_doh_edit_ctx.server.name[DNSPROXY_LEN_NAME64-1] = '\0';
// 3. 反馈
char buffer[128];
snprintf(buffer, sizeof(buffer),
"%% Name updated for server %d: %s",
s_doh_edit_ctx.server_id, new_name);
RCC_EXT_WriteStrLine(pCliEnv, buffer);
return OK;
}
STATUS cli_dnsproxy_doh_server_set_dnsserver(cli_env *pCliEnv, const char *new_url) {
if (!s_doh_edit_ctx.in_edit) {
RCC_EXT_WriteStrLine(pCliEnv, "%% No active edit session");
return ERROR;
}
// URL格式验证
if (strncmp(new_url, "https://", 8) != 0) {
RCC_EXT_WriteStrLine(pCliEnv, "%% URL must start with https://");
return ERROR;
}
strncpy(s_doh_edit_ctx.server.server, new_url, DNSPROXY_LEN_SERVER_URL-1);
s_doh_edit_ctx.server.server[DNSPROXY_LEN_SERVER_URL-1] = '\0';
char buffer[128];
snprintf(buffer, sizeof(buffer),
"%% Server URL updated for %d: %s",
s_doh_edit_ctx.server_id, new_url);
RCC_EXT_WriteStrLine(pCliEnv, buffer);
return OK;
}
STATUS cli_dnsproxy_doh_server_set_status(cli_env *pCliEnv, const char *new_status) {
if (!s_doh_edit_ctx.in_edit) {
RCC_EXT_WriteStrLine(pCliEnv, "%% No active edit session");
return ERROR;
}
// 扩展状态值验证
const char *valid_status[] = {"on", "off", "enable", "disable", NULL};
bool valid = false;
for (int i = 0; valid_status[i] != NULL; i++) {
if (strcasecmp(new_status, valid_status[i]) == 0) {
valid = true;
break;
}
}
if (!valid) {
RCC_EXT_WriteStrLine(pCliEnv, "%% Status must be 'on', 'off', 'enable' or 'disable'");
return ERROR;
}
strcpy(s_doh_edit_ctx.server.status, new_status);
char buffer[128];
snprintf(buffer, sizeof(buffer),
"%% Status updated for server %d: %s",
s_doh_edit_ctx.server_id, new_status);
RCC_EXT_WriteStrLine(pCliEnv, buffer);
return OK;
}
STATUS cli_dnsproxy_doh_server_set_cancel(cli_env *pCliEnv) {
if (!s_doh_edit_ctx.in_edit) {
RCC_EXT_WriteStrLine(pCliEnv, "%% No active edit session to abort");
return ERROR;
}
unsigned current_id = s_doh_edit_ctx.server_id;
memset(&s_doh_edit_ctx, 0, sizeof(s_doh_edit_ctx));
char buffer[128];
snprintf(buffer, sizeof(buffer), "%% Edit session aborted (ID: %u)", current_id);
RCC_EXT_WriteStrLine(pCliEnv, buffer);
return OK;
}