UI: Add "-c block none|all|internet" command-line argument

This commit is contained in:
Nodir Temirkhodjaev 2024-11-07 12:23:33 +05:00
parent cfcf4539ab
commit 0f0a3c10e2
3 changed files with 56 additions and 0 deletions

View File

@ -10,6 +10,7 @@ static const QHash<Command, const char *> g_commandNames = {
CASE_STRING(CommandNone),
CASE_STRING(CommandHome),
CASE_STRING(CommandBlock),
CASE_STRING(CommandProg),
CASE_STRING(CommandBackup),
CASE_STRING(CommandZone),
@ -121,6 +122,7 @@ static const RpcManager g_commandManagers[] = {
Rpc_NoneManager, // CommandNone = 0,
Rpc_NoneManager, // CommandHome,
Rpc_NoneManager, // CommandBlock,
Rpc_NoneManager, // CommandProg,
Rpc_NoneManager, // CommandBackup,
Rpc_NoneManager, // CommandZone,
@ -212,6 +214,7 @@ static const qint8 g_commandValidations[] = {
0, // CommandNone = 0,
0, // CommandHome,
0, // CommandBlock,
0, // CommandProg,
0, // CommandBackup,
0, // CommandZone,

View File

@ -12,6 +12,7 @@ enum Command : qint8 {
CommandNone = 0,
CommandHome,
CommandBlock,
CommandProg,
CommandBackup,
CommandZone,

View File

@ -47,6 +47,53 @@ bool processCommandHome(const ProcessCommandArgs &p)
return false;
}
enum BlockAction : qint8 {
BlockActionInvalid = -1,
BlockActionNone = 0,
BlockActionAll,
BlockActionInet,
};
bool processCommandProgBlock(BlockAction blockAction)
{
auto confManager = IoC<ConfManager>();
auto conf = confManager->conf();
conf->setBlockTrafficIndex(blockAction);
return confManager->saveFlags();
}
BlockAction blockActionByText(const QString &commandText)
{
if (commandText == "none")
return BlockActionNone;
if (commandText == "all")
return BlockActionAll;
if (commandText == "internet")
return BlockActionInet;
return BlockActionInvalid;
}
bool processCommandBlock(const ProcessCommandArgs &p)
{
const BlockAction blockAction = blockActionByText(p.args.value(0).toString());
if (blockAction == BlockActionInvalid) {
p.errorMessage = "Usage: block none|all|internet";
return false;
}
if (!checkActionPassword(blockAction)) {
p.errorMessage = "Password required";
return false;
}
return processCommandProgBlock(blockAction);
}
enum ProgAction : quint32 {
ProgActionNone = 0,
ProgActionAdd = (1 << 0),
@ -214,6 +261,9 @@ bool processCommand(const ProcessCommandArgs &p)
case Control::CommandHome: {
ok = processCommandHome(p);
} break;
case Control::CommandBlock: {
ok = processCommandBlock(p);
} break;
case Control::CommandProg: {
ok = processCommandProg(p);
} break;
@ -314,6 +364,8 @@ bool ControlManager::processCommandClient()
Control::Command command;
if (settings->controlCommand() == "home") {
command = Control::CommandHome;
} else if (settings->controlCommand() == "block") {
command = Control::CommandBlock;
} else if (settings->controlCommand() == "prog") {
command = Control::CommandProg;
} else if (settings->controlCommand() == "backup") {