1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2025-07-07 08:14:58 +03:00

Cedar/Command: add ProtoOptionsGet and ProtoOptionsSet commands

ProtoOptionsGet command - Lists the options for the specified protocol
Help for command "ProtoOptionsGet"

Purpose:
  Lists the options for the specified protocol

Description:
  This command can be used to retrieve the options for a specific protocol.
  Detailed info (e.g. value type) will be shown.
  You can change an option's value with the ProtoOptionsSet command.

Usage:
  ProtoOptionsGet [protocol]

Parameters:
  protocol - Protocol name.

ProtoOptionsSet command - Sets an option's value for the specified protocol
Help for command "ProtoOptionsSet"

Purpose:
  Sets an option's value for the specified protocol

Description:
  This command can be used to change an option's value for a specific protocol.
  You can retrieve the options using the ProtoOptionsGet command.
  To execute this command, you must have VPN Server administrator privileges.

Usage:
  ProtoOptionsSet [protocol] [/NAME:option_name] [/VALUE:string/true/false]

Parameters:
  protocol - Protocol name.
  /NAME    - Option name.
  /VALUE   - Option value. Make sure to write a value that is accepted by the specified protocol!
This commit is contained in:
Davide Beatrici
2020-07-21 03:24:53 +02:00
parent 3a275d7257
commit 5209b310e3
9 changed files with 372 additions and 0 deletions

View File

@ -7352,6 +7352,8 @@ void PsMain(PS *ps)
{"ListenerDisable", PsListenerDisable},
{"PortsUDPGet", PsPortsUDPGet},
{"PortsUDPSet", PsPortsUDPSet},
{"ProtoOptionsGet", PsProtoOptionsGet},
{"ProtoOptionsSet", PsProtoOptionsSet},
{"ServerPasswordSet", PsServerPasswordSet},
{"ClusterSettingGet", PsClusterSettingGet},
{"ClusterSettingStandalone", PsClusterSettingStandalone},
@ -22840,6 +22842,163 @@ UINT PsPortsUDPGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
return ret;
}
// Configure an option for the specified protocol (TODO: ability to set multiple options in a single call)
UINT PsProtoOptionsSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
{
LIST *o;
PS *ps = (PS *)param;
UINT ret;
RPC_PROTO_OPTIONS t;
PARAM args[] =
{
{"[protocol]", CmdPrompt, _UU("CMD_ProtoOptionsSet_Prompt_[protocol]"), CmdEvalNotEmpty, NULL},
{"NAME", CmdPrompt, _UU("CMD_ProtoOptionsSet_Prompt_NAME"), CmdEvalNotEmpty, NULL},
{"VALUE", CmdPrompt, _UU("CMD_ProtoOptionsSet_Prompt_VALUE"), NULL, NULL}
};
o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
if (o == NULL)
{
return ERR_INVALID_PARAMETER;
}
Zero(&t, sizeof(t));
t.Protocol = CopyStr(GetParamStr(o, "[protocol]"));
ret = ScGetProtoOptions(ps->Rpc, &t);
if (ret == ERR_NO_ERROR)
{
UINT i;
bool found = false;
for (i = 0; i < t.Num; ++i)
{
PROTO_OPTION *option = &t.Options[i];
if (StrCmpi(option->Name, GetParamStr(o, "NAME")) != 0)
{
continue;
}
found = true;
switch (option->Type)
{
case PROTO_OPTION_STRING:
Free(option->String);
option->String = CopyStr(GetParamStr(o, "VALUE"));
break;
case PROTO_OPTION_BOOL:
option->Bool = GetParamYes(o, "VALUE");
break;
default:
ret = ERR_INTERNAL_ERROR;
}
if (ret == ERR_NO_ERROR)
{
ret = ScSetProtoOptions(ps->Rpc, &t);
}
break;
}
if (found == false)
{
ret = ERR_OBJECT_NOT_FOUND;
}
}
if (ret != ERR_NO_ERROR)
{
CmdPrintError(c, ret);
}
FreeRpcProtoOptions(&t);
FreeParamValueList(o);
return ret;
}
// List available options for the specified protocol
UINT PsProtoOptionsGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
{
LIST *o;
PS *ps = (PS *)param;
UINT ret;
RPC_PROTO_OPTIONS t;
PARAM args[] =
{
{"[protocol]", CmdPrompt, _UU("CMD_ProtoOptionsGet_Prompt_[protocol]"), CmdEvalNotEmpty, NULL}
};
o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
if (o == NULL)
{
return ERR_INVALID_PARAMETER;
}
Zero(&t, sizeof(t));
t.Protocol = CopyStr(GetParamStr(o, "[protocol]"));
FreeParamValueList(o);
ret = ScGetProtoOptions(ps->Rpc, &t);
if (ret == ERR_NO_ERROR)
{
UINT i;
CT *ct = CtNew();
CtInsertColumn(ct, _UU("CMD_ProtoOptionsGet_Column_Name"), false);
CtInsertColumn(ct, _UU("CMD_ProtoOptionsGet_Column_Type"), false);
CtInsertColumn(ct, _UU("CMD_ProtoOptionsGet_Column_Value"), false);
CtInsertColumn(ct, _UU("CMD_ProtoOptionsGet_Column_Description"), false);
for (i = 0; i < t.Num; ++i)
{
char description_str_key[MAX_SIZE];
const PROTO_OPTION *option = &t.Options[i];
wchar_t *value, *type, *name = CopyStrToUni(option->Name);
switch (option->Type)
{
case PROTO_OPTION_BOOL:
type = L"Boolean";
value = option->Bool ? L"True" : L"False";
break;
case PROTO_OPTION_STRING:
type = L"String";
value = CopyStrToUni(option->String);
break;
default:
Debug("StGetProtoOptions(): unhandled option type %u!\n", option->Type);
Free(name);
continue;
}
Format(description_str_key, sizeof(description_str_key), "CMD_ProtoOptions_Description_%s_%s", t.Protocol, option->Name);
CtInsert(ct, name, type, value, _UU(description_str_key));
if (option->Type == PROTO_OPTION_STRING)
{
Free(value);
}
Free(name);
}
CtFree(ct, c);
}
else
{
CmdPrintError(c, ret);
}
FreeRpcProtoOptions(&t);
return ret;
}
// Draw a row of console table
void CtPrintRow(CONSOLE *c, UINT num, UINT *widths, wchar_t **strings, bool *rights, char separate_char)
{

View File

@ -395,6 +395,8 @@ UINT PsListenerEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsListenerDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsPortsUDPSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsPortsUDPGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsProtoOptionsSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsProtoOptionsGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsServerPasswordSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsClusterSettingGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsClusterSettingStandalone(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);