1 /* 2 Drawpile - a collaborative drawing program. 3 4 Copyright (C) 2017-2018 Calle Laakkonen 5 6 Drawpile is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 Drawpile is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with Drawpile. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 #ifndef DP_SERVER_SESSIONBAN_H 20 #define DP_SERVER_SESSIONBAN_H 21 22 #include <QString> 23 #include <QHostAddress> 24 #include <QList> 25 26 class QJsonArray; 27 28 namespace server { 29 30 struct SessionBan { 31 int id; 32 QString username; 33 QString authId; 34 QHostAddress ip; 35 QString bannedBy; 36 }; 37 38 /** 39 * @brief Session internal banlist 40 * 41 * This holds the session specific bans that can be enacted (and retracted) 42 * by session operators. 43 * 44 * Unlike the serverwide banlist, this is designed to be used together with 45 * the kick function, and for privacy reasons does not normally reveal the 46 * actual IP addresses (except to moderators) 47 */ 48 class SessionBanList { 49 public: 50 SessionBanList(); 51 52 /** 53 * @brief Add a new ban 54 * 55 * If the address already exists in the ban list, this does nothing. 56 * @param username the username of the user being banned 57 * @param ip IP address to be banned 58 * @param authId authenticated user's id (if any) 59 * @param bannedBy name of the user who did the banning 60 * @param id explicitly specified ID 61 * @return id of newly added ban entry or 0 if not added 62 */ 63 int addBan(const QString &username, const QHostAddress &ip, const QString &authId, const QString &bannedBy, int id=0); 64 65 /** 66 * @brief Remove a ban entry 67 * @param id the ID number of the ban entry 68 * @return username of the removed ban entry or an empty string if not found 69 */ 70 QString removeBan(int id); 71 72 /** 73 * @brief Check if the given IP address or authenticated ID is on the ban list 74 * 75 * @param address the IP address to check (if not null) 76 * @param authId the user ID to check (if not empty) 77 */ 78 bool isBanned(const QHostAddress &address, const QString &authId) const; 79 80 /** 81 * @brief Get a JSON representation of the ban list 82 * 83 * This is used when sending the updated list to clients, as well 84 * as the JSON admin api. 85 */ 86 QJsonArray toJson(bool showIp) const; 87 88 private: 89 QList<SessionBan> m_banlist; 90 int m_idautoinc; 91 }; 92 93 } 94 95 #endif 96 97