mirror of
https://github.com/tnodir/fort
synced 2024-11-15 07:45:22 +00:00
UI: Add "-c zone update" command line argument
This commit is contained in:
parent
f9ca5c7dee
commit
3bc831ce51
@ -13,6 +13,7 @@ const char *const commandString(Command cmd)
|
|||||||
|
|
||||||
CASE_STRING(CommandHome)
|
CASE_STRING(CommandHome)
|
||||||
CASE_STRING(CommandProg)
|
CASE_STRING(CommandProg)
|
||||||
|
CASE_STRING(CommandZone)
|
||||||
|
|
||||||
CASE_STRING(Rpc_Result_Ok)
|
CASE_STRING(Rpc_Result_Ok)
|
||||||
CASE_STRING(Rpc_Result_Error)
|
CASE_STRING(Rpc_Result_Error)
|
||||||
@ -120,6 +121,7 @@ RpcManager managerByCommand(Command cmd)
|
|||||||
|
|
||||||
Rpc_NoneManager, // CommandHome,
|
Rpc_NoneManager, // CommandHome,
|
||||||
Rpc_NoneManager, // CommandProg,
|
Rpc_NoneManager, // CommandProg,
|
||||||
|
Rpc_NoneManager, // CommandZone,
|
||||||
|
|
||||||
Rpc_NoneManager, // Rpc_Result_Ok,
|
Rpc_NoneManager, // Rpc_Result_Ok,
|
||||||
Rpc_NoneManager, // Rpc_Result_Error,
|
Rpc_NoneManager, // Rpc_Result_Error,
|
||||||
@ -206,6 +208,7 @@ bool commandRequiresValidation(Command cmd)
|
|||||||
|
|
||||||
0, // CommandHome,
|
0, // CommandHome,
|
||||||
0, // CommandProg,
|
0, // CommandProg,
|
||||||
|
0, // CommandZone,
|
||||||
|
|
||||||
0, // Rpc_Result_Ok,
|
0, // Rpc_Result_Ok,
|
||||||
0, // Rpc_Result_Error,
|
0, // Rpc_Result_Error,
|
||||||
|
@ -13,6 +13,7 @@ enum Command : qint8 {
|
|||||||
|
|
||||||
CommandHome,
|
CommandHome,
|
||||||
CommandProg,
|
CommandProg,
|
||||||
|
CommandZone,
|
||||||
|
|
||||||
Rpc_Result_Ok,
|
Rpc_Result_Ok,
|
||||||
Rpc_Result_Error,
|
Rpc_Result_Error,
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
#include <fortsettings.h>
|
#include <fortsettings.h>
|
||||||
#include <manager/windowmanager.h>
|
#include <manager/windowmanager.h>
|
||||||
#include <rpc/rpcmanager.h>
|
#include <rpc/rpcmanager.h>
|
||||||
|
#include <task/taskinfozonedownloader.h>
|
||||||
|
#include <task/taskmanager.h>
|
||||||
#include <util/fileutil.h>
|
#include <util/fileutil.h>
|
||||||
#include <util/ioc/ioccontainer.h>
|
#include <util/ioc/ioccontainer.h>
|
||||||
#include <util/osutil.h>
|
#include <util/osutil.h>
|
||||||
@ -25,6 +27,11 @@ constexpr int maxClientsCount = 9;
|
|||||||
|
|
||||||
const QLoggingCategory LC("control");
|
const QLoggingCategory LC("control");
|
||||||
|
|
||||||
|
bool checkActionPassword()
|
||||||
|
{
|
||||||
|
return IoC<WindowManager>()->checkPassword(/*temporary=*/true);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ControlManager::ControlManager(QObject *parent) : QObject(parent) { }
|
ControlManager::ControlManager(QObject *parent) : QObject(parent) { }
|
||||||
@ -107,6 +114,8 @@ bool ControlManager::processCommandClient()
|
|||||||
command = Control::CommandHome;
|
command = Control::CommandHome;
|
||||||
} else if (settings->controlCommand() == "prog") {
|
} else if (settings->controlCommand() == "prog") {
|
||||||
command = Control::CommandProg;
|
command = Control::CommandProg;
|
||||||
|
} else if (settings->controlCommand() == "zone") {
|
||||||
|
command = Control::CommandZone;
|
||||||
} else {
|
} else {
|
||||||
qCWarning(LC) << "Unknown control command:" << settings->controlCommand();
|
qCWarning(LC) << "Unknown control command:" << settings->controlCommand();
|
||||||
return false;
|
return false;
|
||||||
@ -220,24 +229,27 @@ bool ControlManager::processRequest(Control::Command command, const QVariantList
|
|||||||
|
|
||||||
bool ControlManager::processCommand(const ProcessCommandArgs &p)
|
bool ControlManager::processCommand(const ProcessCommandArgs &p)
|
||||||
{
|
{
|
||||||
|
bool ok;
|
||||||
|
|
||||||
switch (p.command) {
|
switch (p.command) {
|
||||||
case Control::CommandHome: {
|
case Control::CommandHome: {
|
||||||
if (processCommandHome(p))
|
ok = processCommandHome(p);
|
||||||
return true;
|
|
||||||
} break;
|
} break;
|
||||||
case Control::CommandProg: {
|
case Control::CommandProg: {
|
||||||
if (processCommandProg(p))
|
ok = processCommandProg(p);
|
||||||
return true;
|
} break;
|
||||||
|
case Control::CommandZone: {
|
||||||
|
ok = processCommandZone(p);
|
||||||
} break;
|
} break;
|
||||||
default:
|
default:
|
||||||
if (IoC<RpcManager>()->processCommandRpc(p))
|
ok = IoC<RpcManager>()->processCommandRpc(p);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p.errorMessage.isEmpty()) {
|
if (!ok && p.errorMessage.isEmpty()) {
|
||||||
p.errorMessage = "Invalid command";
|
p.errorMessage = "Invalid command";
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ControlManager::processCommandHome(const ProcessCommandArgs &p)
|
bool ControlManager::processCommandHome(const ProcessCommandArgs &p)
|
||||||
@ -297,8 +309,7 @@ bool ControlManager::checkProgActionPassword(ProgAction progAction)
|
|||||||
constexpr const quint32 passwordRequiredActions =
|
constexpr const quint32 passwordRequiredActions =
|
||||||
ProgActionDel | ProgActionAllow | ProgActionBlock | ProgActionKill;
|
ProgActionDel | ProgActionAllow | ProgActionBlock | ProgActionKill;
|
||||||
|
|
||||||
return (passwordRequiredActions & progAction) == 0
|
return (passwordRequiredActions & progAction) == 0 || checkActionPassword();
|
||||||
|| IoC<WindowManager>()->checkPassword(/*temporary=*/true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ControlManager::ProgAction ControlManager::progActionByText(const QString &commandText)
|
ControlManager::ProgAction ControlManager::progActionByText(const QString &commandText)
|
||||||
@ -321,6 +332,49 @@ ControlManager::ProgAction ControlManager::progActionByText(const QString &comma
|
|||||||
return ProgActionNone;
|
return ProgActionNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ControlManager::processCommandZone(const ProcessCommandArgs &p)
|
||||||
|
{
|
||||||
|
const ZoneAction zoneAction = zoneActionByText(p.args.value(0).toString());
|
||||||
|
if (zoneAction == ZoneActionNone) {
|
||||||
|
p.errorMessage = "Usage: zone update";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!checkZoneActionPassword(zoneAction)) {
|
||||||
|
p.errorMessage = "Password required";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return processCommandZoneAction(zoneAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ControlManager::processCommandZoneAction(ZoneAction zoneAction)
|
||||||
|
{
|
||||||
|
switch (zoneAction) {
|
||||||
|
case ZoneActionUpdate: {
|
||||||
|
IoC<TaskManager>()->runTask(TaskInfo::ZoneDownloader);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ControlManager::checkZoneActionPassword(ZoneAction zoneAction)
|
||||||
|
{
|
||||||
|
constexpr const quint32 passwordRequiredActions = ZoneActionUpdate;
|
||||||
|
|
||||||
|
return (passwordRequiredActions & zoneAction) == 0 || checkActionPassword();
|
||||||
|
}
|
||||||
|
|
||||||
|
ControlManager::ZoneAction ControlManager::zoneActionByText(const QString &commandText)
|
||||||
|
{
|
||||||
|
if (commandText == "update")
|
||||||
|
return ZoneActionUpdate;
|
||||||
|
|
||||||
|
return ZoneActionNone;
|
||||||
|
}
|
||||||
|
|
||||||
QString ControlManager::getServerName(bool isService)
|
QString ControlManager::getServerName(bool isService)
|
||||||
{
|
{
|
||||||
return QLatin1String(APP_BASE) + (isService ? "Svc" : OsUtil::userName()) + "Pipe";
|
return QLatin1String(APP_BASE) + (isService ? "Svc" : OsUtil::userName()) + "Pipe";
|
||||||
|
@ -54,15 +54,25 @@ private:
|
|||||||
ProgActionKill = (1 << 4),
|
ProgActionKill = (1 << 4),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum ZoneAction : quint32 {
|
||||||
|
ZoneActionNone = 0,
|
||||||
|
ZoneActionUpdate = (1 << 0),
|
||||||
|
};
|
||||||
|
|
||||||
bool processCommand(const ProcessCommandArgs &p);
|
bool processCommand(const ProcessCommandArgs &p);
|
||||||
|
|
||||||
bool processCommandHome(const ProcessCommandArgs &p);
|
bool processCommandHome(const ProcessCommandArgs &p);
|
||||||
|
|
||||||
bool processCommandProg(const ProcessCommandArgs &p);
|
bool processCommandProg(const ProcessCommandArgs &p);
|
||||||
bool processCommandProgAction(ProgAction progAction, const QString &appPath);
|
static bool processCommandProgAction(ProgAction progAction, const QString &appPath);
|
||||||
static bool checkProgActionPassword(ProgAction progAction);
|
static bool checkProgActionPassword(ProgAction progAction);
|
||||||
static ProgAction progActionByText(const QString &commandText);
|
static ProgAction progActionByText(const QString &commandText);
|
||||||
|
|
||||||
|
bool processCommandZone(const ProcessCommandArgs &p);
|
||||||
|
static bool processCommandZoneAction(ZoneAction zoneAction);
|
||||||
|
static bool checkZoneActionPassword(ZoneAction zoneAction);
|
||||||
|
static ZoneAction zoneActionByText(const QString &commandText);
|
||||||
|
|
||||||
static QString getServerName(bool isService = false);
|
static QString getServerName(bool isService = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user