summaryrefslogtreecommitdiffstats
path: root/common/CommandControl.cpp
blob: 7f1b1e91e2cbe802bc88e5e0ab473014120b660d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include <config.h>
#include <string>
#include <unordered_set>
#include "ConfigUtil.hpp"
#include "Util.hpp"
#include "CommandControl.hpp"

namespace CommandControl
{

bool FreemiumManager::_isFreemiumUser = false;
std::unordered_set<std::string> FreemiumManager::FreemiumDenyList;
std::string FreemiumManager::FreemiumDenyListString;

FreemiumManager::FreemiumManager() {}

void FreemiumManager::generateDenyList()
{
#ifdef ENABLE_FREEMIUM

    FreemiumDenyListString = config::getString("freemium.disabled_commands", "");
    Util::trim(FreemiumDenyListString);
    StringVector commandList = Util::tokenize(FreemiumDenyListString);

    std::string command;
    for (std::size_t i = 0; i < commandList.size(); i++)
    {
        // just an extra check to make sure any whitespace does not sniff in command
        // or else command will not be recognized
        command = Util::trim_whitespace(commandList[i]);
        if(!command.empty())
        {
            FreemiumDenyList.emplace(command);
        }
    }
#endif
}

const std::unordered_set<std::string>& FreemiumManager::getFreemiumDenyList()
{
    if (FreemiumDenyList.empty())
        generateDenyList();

    return FreemiumDenyList;
}

const std::string FreemiumManager::getFreemiumDenyListString()
{
    if (FreemiumDenyListString.empty())
        generateDenyList();

    return FreemiumDenyListString;
}


bool RestrictionManager::_isRestrictedUser = false;
std::unordered_set<std::string> RestrictionManager::RestrictedCommandList;
std::string RestrictionManager::RestrictedCommandListString;

RestrictionManager::RestrictionManager() {}

void RestrictionManager::generateRestrictedCommandList()
{
#ifdef ENABLE_FEATURE_RESTRICTION
    RestrictedCommandListString = config::getString("restricted_commands", "");
    Util::trim(RestrictedCommandListString);
    StringVector commandList = Util::tokenize(RestrictedCommandListString);

    std::string command;
    for (std::size_t i = 0; i < commandList.size(); i++)
    {
        // just an extra check to make sure any whitespace does not sniff in command
        // or else command will not be recognized
        command = Util::trim_whitespace(commandList[i]);
        if(!command.empty())
        {
            RestrictedCommandList.emplace(command);
        }
    }
#endif
}

const std::unordered_set<std::string>& RestrictionManager::getRestrictedCommandList()
{
    if (RestrictedCommandList.empty())
        generateRestrictedCommandList();

    return RestrictedCommandList;
}

const std::string RestrictionManager::getRestrictedCommandListString()
{
    if (RestrictedCommandListString.empty())
        generateRestrictedCommandList();

    return RestrictedCommandListString;
}
} // namespace CommandControl

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */