mirror of
				https://github.com/arcan1s/queued.git
				synced 2025-10-30 21:53:41 +00:00 
			
		
		
		
	implement auth for get option methods to hide sensetive settings
This commit is contained in:
		| @ -55,21 +55,21 @@ void QueuedServer::init() | ||||
|     } | ||||
|  | ||||
|     m_server->init(QueuedCoreAdaptor::getOption( | ||||
|                        QueuedConfig::QueuedSettings::ServerTimeout) | ||||
|                        QueuedConfig::QueuedSettings::ServerTimeout, "") | ||||
|                        .get() | ||||
|                        .toInt()); | ||||
|     QString address = QueuedCoreAdaptor::getOption( | ||||
|                           QueuedConfig::QueuedSettings::ServerAddress) | ||||
|                           QueuedConfig::QueuedSettings::ServerAddress, "") | ||||
|                           .get() | ||||
|                           .toString(); | ||||
|     ushort port | ||||
|         = QueuedCoreAdaptor::getOption(QueuedConfig::QueuedSettings::ServerPort) | ||||
|               .get() | ||||
|               .toUInt(); | ||||
|     ushort port = QueuedCoreAdaptor::getOption( | ||||
|                       QueuedConfig::QueuedSettings::ServerPort, "") | ||||
|                       .get() | ||||
|                       .toUInt(); | ||||
|     m_server->listen(QHostAddress(address), port); | ||||
|     m_server->setMaxPendingConnections( | ||||
|         QueuedCoreAdaptor::getOption( | ||||
|             QueuedConfig::QueuedSettings::ServerMaxConnections) | ||||
|             QueuedConfig::QueuedSettings::ServerMaxConnections, "") | ||||
|             .get() | ||||
|             .toInt()); | ||||
|  | ||||
|  | ||||
| @ -50,7 +50,8 @@ QVariantHash QueuedTcpServerResponseHelperApi1::getData( | ||||
|         break; | ||||
|     case QueuedTcpServerResponseHelper::RequestPath::Option: | ||||
|         if (_type == "GET") | ||||
|             output = QueuedTcpServerResponseHelperOption::getOption(_arg); | ||||
|             output | ||||
|                 = QueuedTcpServerResponseHelperOption::getOption(_arg, _token); | ||||
|         else if (_type == "POST") | ||||
|             output = QueuedTcpServerResponseHelperOption::setOption(_arg, _data, | ||||
|                                                                     _token); | ||||
|  | ||||
| @ -20,11 +20,12 @@ | ||||
|  | ||||
|  | ||||
| QVariantHash | ||||
| QueuedTcpServerResponseHelperOption::getOption(const QString &_option) | ||||
| QueuedTcpServerResponseHelperOption::getOption(const QString &_option, | ||||
|                                                const QString &_token) | ||||
| { | ||||
|     qCDebug(LOG_SERV) << "Get option" << _option; | ||||
|  | ||||
|     auto res = QueuedCoreAdaptor::getOption(_option); | ||||
|     auto res = QueuedCoreAdaptor::getOption(_option, _token); | ||||
|  | ||||
|     QVariantHash output; | ||||
|     res.match( | ||||
|  | ||||
| @ -22,7 +22,7 @@ | ||||
|  | ||||
| namespace QueuedTcpServerResponseHelperOption | ||||
| { | ||||
| QVariantHash getOption(const QString &_option); | ||||
| QVariantHash getOption(const QString &_option, const QString &_token); | ||||
| QVariantHash setOption(const QString &_option, const QVariantHash &_value, | ||||
|                        const QString &_token); | ||||
| }; | ||||
|  | ||||
| @ -42,8 +42,8 @@ QueuedTcpServerResponseHelperPlugins::addPlugin(const QString &_name, | ||||
|  | ||||
| QVariantHash QueuedTcpServerResponseHelperPlugins::listPlugins() | ||||
| { | ||||
|     auto res | ||||
|         = QueuedCoreAdaptor::getOption(QueuedConfig::QueuedSettings::Plugins); | ||||
|     auto res = QueuedCoreAdaptor::getOption( | ||||
|         QueuedConfig::QueuedSettings::Plugins, ""); | ||||
|  | ||||
|     QVariantHash output; | ||||
|     res.match( | ||||
|  | ||||
| @ -88,6 +88,20 @@ public: | ||||
|      * @return ID in settings representation | ||||
|      */ | ||||
|     static QString internalId(const QueuedConfig::QueuedSettings _key); | ||||
|     /** | ||||
|      * @brief check whether requested option is admin only | ||||
|      * @param _key | ||||
|      * key to search in | ||||
|      * @return true if this value is hidden for non-admins | ||||
|      */ | ||||
|     bool isAdmin(const QString &_key) const; | ||||
|     /** | ||||
|      * @brief check whether requested option is admin only | ||||
|      * @param _key | ||||
|      * key to search in | ||||
|      * @return true if this value is hidden for non-admins | ||||
|      */ | ||||
|     bool isAdmin(const QueuedConfig::QueuedSettings &_key) const; | ||||
|     /** | ||||
|      * @brief set value | ||||
|      * @param _key | ||||
|  | ||||
| @ -196,9 +196,11 @@ public: | ||||
|      * @brief get value from advanced settings | ||||
|      * @param _key | ||||
|      * key string | ||||
|      * @param _token | ||||
|      * user auth token | ||||
|      * @return option value or empty QVariant | ||||
|      */ | ||||
|     QueuedResult<QVariant> option(const QString &_key); | ||||
|     QueuedResult<QVariant> option(const QString &_key, const QString &_token); | ||||
|     /** | ||||
|      * @brief usage report | ||||
|      * @param _from | ||||
|  | ||||
| @ -194,16 +194,22 @@ sendUserPermissionRemove(const long long _id, | ||||
|  * @brief get option | ||||
|  * @param _property | ||||
|  * option name | ||||
|  * @param _token | ||||
|  * user auth token | ||||
|  * @return option value | ||||
|  */ | ||||
| QueuedResult<QVariant> getOption(const QString &_property); | ||||
| QueuedResult<QVariant> getOption(const QString &_property, | ||||
|                                  const QString &_token); | ||||
| /** | ||||
|  * @brief get option | ||||
|  * @param _property | ||||
|  * option name | ||||
|  * @param _token | ||||
|  * user auth token | ||||
|  * @return option value | ||||
|  */ | ||||
| QueuedResult<QVariant> getOption(const QueuedConfig::QueuedSettings _property); | ||||
| QueuedResult<QVariant> getOption(const QueuedConfig::QueuedSettings _property, | ||||
|                                  const QString &_token); | ||||
| /** | ||||
|  * @brief performance report | ||||
|  * @param _from | ||||
|  | ||||
| @ -57,9 +57,11 @@ public slots: | ||||
|      * @brief get advanced option | ||||
|      * @param property | ||||
|      * property name | ||||
|      * @param token | ||||
|      * user auth token | ||||
|      * @return property value or empty if property not found | ||||
|      */ | ||||
|     QDBusVariant Option(const QString &property); | ||||
|     QDBusVariant Option(const QString &property, const QString &token); | ||||
|     /** | ||||
|      * @brief get task property | ||||
|      * @param id | ||||
|  | ||||
| @ -132,6 +132,7 @@ enum class QueuedSettings { | ||||
| typedef struct { | ||||
|     QueuedSettings id; | ||||
|     QVariant defaultValue; | ||||
|     bool isAdmin = true; | ||||
| } QueuedSettingsField; | ||||
| /** | ||||
|  * @typedef QueuedSettingsDefaultMap | ||||
| @ -142,20 +143,20 @@ typedef QHash<QString, QueuedSettingsField> QueuedSettingsDefaultMap; | ||||
|  * @brief default settings map | ||||
|  */ | ||||
| static const QueuedSettingsDefaultMap QueuedSettingsDefaults = { | ||||
|     {"", {QueuedSettings::Invalid, QVariant()}}, | ||||
|     {"DatabaseInterval", {QueuedSettings::DatabaseInterval, 86400000}}, | ||||
|     {"", {QueuedSettings::Invalid, QVariant(), false}}, | ||||
|     {"DatabaseInterval", {QueuedSettings::DatabaseInterval, 86400000, true}}, | ||||
|     {"DatabaseVersion", | ||||
|      {QueuedSettings::DatabaseVersion, QueuedConfig::DATABASE_VERSION}}, | ||||
|     {"DefaultLimits", {QueuedSettings::DefaultLimits, "0\n0\n0\n0\n0"}}, | ||||
|     {"KeepTasks", {QueuedSettings::KeepTasks, 0}}, | ||||
|     {"KeepUsers", {QueuedSettings::KeepUsers, 0}}, | ||||
|     {"OnExitAction", {QueuedSettings::OnExitAction, 2}}, | ||||
|     {"Plugins", {QueuedSettings::Plugins, ""}}, | ||||
|     {"ServerAddress", {QueuedSettings::ServerAddress, ""}}, | ||||
|     {"ServerMaxConnections", {QueuedSettings::ServerMaxConnections, 30}}, | ||||
|     {"ServerPort", {QueuedSettings::ServerPort, 8080}}, | ||||
|     {"ServerTimeout", {QueuedSettings::ServerTimeout, -1}}, | ||||
|     {"TokenExpiration", {QueuedSettings::TokenExpiration, 30}}, | ||||
|      {QueuedSettings::DatabaseVersion, QueuedConfig::DATABASE_VERSION, true}}, | ||||
|     {"DefaultLimits", {QueuedSettings::DefaultLimits, "0\n0\n0\n0\n0", false}}, | ||||
|     {"KeepTasks", {QueuedSettings::KeepTasks, 0, false}}, | ||||
|     {"KeepUsers", {QueuedSettings::KeepUsers, 0, false}}, | ||||
|     {"OnExitAction", {QueuedSettings::OnExitAction, 2, false}}, | ||||
|     {"Plugins", {QueuedSettings::Plugins, "", false}}, | ||||
|     {"ServerAddress", {QueuedSettings::ServerAddress, "", false}}, | ||||
|     {"ServerMaxConnections", {QueuedSettings::ServerMaxConnections, 30, false}}, | ||||
|     {"ServerPort", {QueuedSettings::ServerPort, 8080, false}}, | ||||
|     {"ServerTimeout", {QueuedSettings::ServerTimeout, -1, false}}, | ||||
|     {"TokenExpiration", {QueuedSettings::TokenExpiration, 30, false}}, | ||||
| }; | ||||
| }; | ||||
|  | ||||
|  | ||||
| @ -205,9 +205,11 @@ public: | ||||
|      * @brief get value from advanced settings | ||||
|      * @param _key | ||||
|      * key string | ||||
|      * @param _token | ||||
|      * user auth token | ||||
|      * @return option value or empty QVariant | ||||
|      */ | ||||
|     QueuedResult<QVariant> option(const QString &_key); | ||||
|     QueuedResult<QVariant> option(const QString &_key, const QString &_token); | ||||
|     /** | ||||
|      * @brief usage report | ||||
|      * @param _from | ||||
|  | ||||
| @ -22,6 +22,7 @@ | ||||
|  | ||||
|  | ||||
| #include <queued/Queued.h> | ||||
| #include <queued/QueuedStaticConfig.h> | ||||
|  | ||||
|  | ||||
| /** | ||||
| @ -139,6 +140,32 @@ QueuedAdvancedSettings::internalId(const QueuedConfig::QueuedSettings _key) | ||||
| } | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * @fn isAdmin | ||||
|  */ | ||||
| bool QueuedAdvancedSettings::isAdmin(const QString &_key) const | ||||
| { | ||||
|     qCDebug(LOG_LIB) << "Check if admin option" << _key; | ||||
|  | ||||
|     if ((_key.startsWith("Plugin.")) || (_key.startsWith("plugin."))) | ||||
|         return true; | ||||
|     else | ||||
|         return QueuedConfig::QueuedSettingsDefaults[internalId(_key)].isAdmin; | ||||
| } | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * @fn isAdmin | ||||
|  */ | ||||
| bool QueuedAdvancedSettings::isAdmin( | ||||
|     const QueuedConfig::QueuedSettings &_key) const | ||||
| { | ||||
|     qCDebug(LOG_LIB) << "Check if admin option" << static_cast<int>(_key); | ||||
|  | ||||
|     return QueuedConfig::QueuedSettingsDefaults[internalId(_key)].isAdmin; | ||||
| } | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * @fn set | ||||
|  */ | ||||
|  | ||||
| @ -186,11 +186,12 @@ QueuedResult<QString> QueuedCore::hashFromPassword(const QString &_password) | ||||
| /** | ||||
|  * @fn option | ||||
|  */ | ||||
| QueuedResult<QVariant> QueuedCore::option(const QString &_key) | ||||
| QueuedResult<QVariant> QueuedCore::option(const QString &_key, | ||||
|                                           const QString &_token) | ||||
| { | ||||
|     qCDebug(LOG_LIB) << "Look for option" << _key; | ||||
|  | ||||
|     return m_impl->option(_key); | ||||
|     return m_impl->option(_key, _token); | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
| @ -290,11 +290,12 @@ QueuedResult<bool> QueuedCoreAdaptor::sendUserPermissionRemove( | ||||
| /** | ||||
|  * @fn getOption | ||||
|  */ | ||||
| QueuedResult<QVariant> QueuedCoreAdaptor::getOption(const QString &_property) | ||||
| QueuedResult<QVariant> QueuedCoreAdaptor::getOption(const QString &_property, | ||||
|                                                     const QString &_token) | ||||
| { | ||||
|     qCDebug(LOG_DBUS) << "Get option" << _property; | ||||
|  | ||||
|     QVariantList args = {_property}; | ||||
|     QVariantList args = {_property, _token}; | ||||
|     return sendRequest<QVariant>(QueuedConfig::DBUS_SERVICE, | ||||
|                                  QueuedConfig::DBUS_PROPERTY_PATH, | ||||
|                                  QueuedConfig::DBUS_SERVICE, "Option", args); | ||||
| @ -305,11 +306,12 @@ QueuedResult<QVariant> QueuedCoreAdaptor::getOption(const QString &_property) | ||||
|  * @fn getOption | ||||
|  */ | ||||
| QueuedResult<QVariant> | ||||
| QueuedCoreAdaptor::getOption(const QueuedConfig::QueuedSettings _property) | ||||
| QueuedCoreAdaptor::getOption(const QueuedConfig::QueuedSettings _property, | ||||
|                              const QString &_token) | ||||
| { | ||||
|     qCDebug(LOG_DBUS) << "Get option" << static_cast<int>(_property); | ||||
|  | ||||
|     return getOption(QueuedAdvancedSettings::internalId(_property)); | ||||
|     return getOption(QueuedAdvancedSettings::internalId(_property), _token); | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
| @ -333,11 +333,18 @@ QueuedCorePrivate::hashFromPassword(const QString &_password) | ||||
| /** | ||||
|  * @fn option | ||||
|  */ | ||||
| QueuedResult<QVariant> QueuedCorePrivate::option(const QString &_key) | ||||
| QueuedResult<QVariant> QueuedCorePrivate::option(const QString &_key, | ||||
|                                                  const QString &_token) | ||||
| { | ||||
|     qCDebug(LOG_LIB) << "Look for option" << _key; | ||||
|  | ||||
|     return m_advancedSettings->get(_key); | ||||
|     bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin); | ||||
|  | ||||
|     if ((isAdmin) || (!m_advancedSettings->isAdmin(_key))) | ||||
|         return m_advancedSettings->get(_key); | ||||
|     else | ||||
|         return QueuedError("Not allowed", | ||||
|                            QueuedEnums::ReturnStatus::InsufficientPermissions); | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
| @ -56,11 +56,12 @@ QueuedPropertyInterface::~QueuedPropertyInterface() | ||||
| /** | ||||
|  * @fn Option | ||||
|  */ | ||||
| QDBusVariant QueuedPropertyInterface::Option(const QString &property) | ||||
| QDBusVariant QueuedPropertyInterface::Option(const QString &property, | ||||
|                                              const QString &token) | ||||
| { | ||||
|     qCDebug(LOG_DBUS) << "Get property" << property; | ||||
|  | ||||
|     return QueuedCoreAdaptor::toDBusVariant(m_core->option(property)); | ||||
|     return QueuedCoreAdaptor::toDBusVariant(m_core->option(property, token)); | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
| @ -225,7 +225,8 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache, | ||||
|         break; | ||||
|     } | ||||
|     case QueuedctlArgument::OptionGet: { | ||||
|         result = QueuedctlOption::getOption(args.at(1)); | ||||
|         QString token = QueuedctlAuth::getToken(_cache, _user); | ||||
|         result = QueuedctlOption::getOption(args.at(1), token); | ||||
|         break; | ||||
|     } | ||||
|     case QueuedctlArgument::OptionSet: { | ||||
|  | ||||
| @ -38,12 +38,12 @@ QueuedctlOption::editOption(const QString &_option, const QVariant &_value, | ||||
|  | ||||
|  | ||||
| QueuedctlCommon::QueuedctlResult | ||||
| QueuedctlOption::getOption(const QString &_option) | ||||
| QueuedctlOption::getOption(const QString &_option, const QString &_token) | ||||
| { | ||||
|     qCDebug(LOG_APP) << "Get option" << _option; | ||||
|  | ||||
|     QueuedctlCommon::QueuedctlResult output; | ||||
|     auto res = QueuedCoreAdaptor::getOption(_option); | ||||
|     auto res = QueuedCoreAdaptor::getOption(_option, _token); | ||||
|     res.match( | ||||
|         [&output](const QVariant &val) { | ||||
|             output.status = val.isValid(); | ||||
|  | ||||
| @ -27,7 +27,8 @@ namespace QueuedctlOption | ||||
| QueuedctlCommon::QueuedctlResult editOption(const QString &_option, | ||||
|                                             const QVariant &_value, | ||||
|                                             const QString &_token); | ||||
| QueuedctlCommon::QueuedctlResult getOption(const QString &_option); | ||||
| QueuedctlCommon::QueuedctlResult getOption(const QString &_option, | ||||
|                                            const QString &_token); | ||||
| void parserGet(QCommandLineParser &_parser); | ||||
| void parserSet(QCommandLineParser &_parser); | ||||
| }; | ||||
|  | ||||
| @ -39,8 +39,8 @@ QueuedctlPlugins::addPlugin(const QString &_plugin, const QString &_token) | ||||
|  | ||||
| QueuedctlCommon::QueuedctlResult QueuedctlPlugins::listPlugins() | ||||
| { | ||||
|     auto res | ||||
|         = QueuedCoreAdaptor::getOption(QueuedConfig::QueuedSettings::Plugins); | ||||
|     auto res = QueuedCoreAdaptor::getOption( | ||||
|         QueuedConfig::QueuedSettings::Plugins, ""); | ||||
|  | ||||
|     QueuedctlCommon::QueuedctlResult output; | ||||
|     res.match( | ||||
|  | ||||
		Reference in New Issue
	
	Block a user