E-MailRelay
gadminserver.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2021 Graeme Walker <graeme_walker@users.sourceforge.net>
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16// ===
17///
18/// \file gadminserver.h
19///
20
21#ifndef G_SMTP_ADMIN_H
22#define G_SMTP_ADMIN_H
23
24#include "gdef.h"
25#include "gmultiserver.h"
26#include "gtimer.h"
27#include "gstr.h"
28#include "glinebuffer.h"
29#include "gsmtpserverprotocol.h"
30#include "gclientptr.h"
31#include "gsmtpclient.h"
32#include <string>
33#include <list>
34#include <sstream>
35#include <utility>
36#include <memory>
37
38namespace GSmtp
39{
40 class AdminServerPeer ;
41 class AdminServer ;
42}
43
44//| \class GSmtp::AdminServerPeer
45/// A derivation of ServerPeer for the administration interface.
46///
47/// The AdminServerPeer instantiates its own Smtp::Client in order
48/// to implement the "flush" command.
49///
50/// \see GSmtp::AdminServer
51///
53{
54public:
56 const std::string & remote , const G::StringMap & info_commands ,
57 const G::StringMap & config_commands , bool with_terminate ) ;
58 ///< Constructor.
59
60 ~AdminServerPeer() override ;
61 ///< Destructor.
62
63 bool notifying() const ;
64 ///< Returns true if the remote user has asked for notifications.
65
66 void notify( const std::string & s0 , const std::string & s1 ,
67 const std::string & s2 , const std::string & s4 ) ;
68 ///< Called when something happens which the admin
69 ///< user might be interested in.
70
71private: // overrides
72 void onSendComplete() override ; // Override from GNet::BufferedServerPeer.
73 bool onReceive( const char * , std::size_t , std::size_t , std::size_t , char ) override ; // Override from GNet::BufferedServerPeer.
74 void onDelete( const std::string & ) override ; // Override from GNet::ServerPeer.
75 void onSecure( const std::string & , const std::string & , const std::string & ) override ; // Override from GNet::SocketProtocolSink.
76
77public:
78 AdminServerPeer( const AdminServerPeer & ) = delete ;
79 AdminServerPeer( AdminServerPeer && ) = delete ;
80 void operator=( const AdminServerPeer & ) = delete ;
81 void operator=( AdminServerPeer && ) = delete ;
82
83private:
84 void clientDone( const std::string & ) ;
85 static bool is( const std::string & , const std::string & ) ;
86 static std::pair<bool,std::string> find( const std::string & line , const G::StringMap & map ) ;
87 static std::string argument( const std::string & ) ;
88 void flush() ;
89 void forward() ;
90 void help() ;
91 void status() ;
92 std::shared_ptr<MessageStore::Iterator> spooled() ;
93 std::shared_ptr<MessageStore::Iterator> failures() ;
94 void sendList( std::shared_ptr<MessageStore::Iterator> ) ;
95 void sendLine( std::string , bool = true ) ;
96 void warranty() ;
97 void version() ;
98 void copyright() ;
99 std::string eol() const ;
100 void unfailAll() ;
101 void send_( const std::string & ) ;
102
103private:
105 AdminServer & m_server ;
106 std::string m_prompt ;
107 bool m_blocked ;
108 std::string m_remote_address ;
109 GNet::ClientPtr<GSmtp::Client> m_client_ptr ;
110 bool m_notifying ;
111 G::StringMap m_info_commands ;
112 G::StringMap m_config_commands ;
113 bool m_with_terminate ;
114} ;
115
116//| \class GSmtp::AdminServer
117/// A server class which implements the emailrelay administration interface.
118///
120{
121public:
123 G::Slot::Signal<const std::string&> & forward_request ,
124 const GNet::ServerPeerConfig & server_peer_config , const GNet::ServerConfig & server_config ,
125 const GSmtp::Client::Config & client_config , const GAuth::SaslClientSecrets & client_secrets ,
126 const G::StringArray & interfaces , unsigned int port , bool allow_remote ,
127 const std::string & remote_address , unsigned int connection_timeout ,
128 const G::StringMap & info_commands , const G::StringMap & config_commands ,
129 bool with_terminate ) ;
130 ///< Constructor.
131
132 ~AdminServer() override ;
133 ///< Destructor.
134
135 void report() const ;
136 ///< Generates helpful diagnostics.
137
138 MessageStore & store() ;
139 ///< Returns a reference to the message store, as
140 ///< passed in to the constructor.
141
142 FilterFactory & ff() ;
143 ///< Returns a reference to the filter factory, as
144 ///< passed in to the constructor.
145
147 ///< Returns a reference to the client secrets object, as passed
148 ///< in to the constructor. This is a client-side secrets file,
149 ///< used to authenticate ourselves with a remote server.
150
152 ///< Returns the client configuration.
153
154 unsigned int connectionTimeout() const ;
155 ///< Returns the connection timeout, as passed in to the
156 ///< constructor.
157
158 void forward() ;
159 ///< Called to trigger asynchronous forwarding.
160
161 bool notifying() const ;
162 ///< Returns true if the remote user has asked for notifications.
163
164 void notify( const std::string & s0 , const std::string & s1 ,
165 const std::string & s2 , const std::string & s3 ) ;
166 ///< Called when something happens which the admin
167 ///< users might be interested in.
168
169protected:
170 std::unique_ptr<GNet::ServerPeer> newPeer( GNet::ExceptionSinkUnbound , GNet::ServerPeerInfo , GNet::MultiServer::ServerInfo ) override ;
171 ///< Override from GNet::MultiServer.
172
173public:
174 AdminServer( const AdminServer & ) = delete ;
175 AdminServer( AdminServer && ) = delete ;
176 void operator=( const AdminServer & ) = delete ;
177 void operator=( AdminServer && ) = delete ;
178
179private:
180 void onForwardTimeout() ;
181
182private:
183 GNet::Timer<AdminServer> m_forward_timer ;
184 MessageStore & m_store ;
185 FilterFactory & m_ff ;
186 G::Slot::Signal<const std::string&> & m_forward_request ;
187 GSmtp::Client::Config m_client_config ;
188 const GAuth::SaslClientSecrets & m_client_secrets ;
189 bool m_allow_remote ;
190 std::string m_remote_address ;
191 unsigned int m_connection_timeout ;
192 G::StringMap m_info_commands ;
193 G::StringMap m_config_commands ;
194 bool m_with_terminate ;
195} ;
196
197#endif
An interface used by GAuth::SaslClient to obtain a client id and its authentication secret.
A potential ExceptionSink that is realised by bind()ing an exception source pointer.
A tuple containing an ExceptionHandler interface pointer and a bound 'exception source' pointer.
A server that listens on more than one address using a facade pattern to multiple GNet::Server instan...
Definition: gmultiserver.h:45
A structure that GNet::Server uses to configure its ServerPeer objects.
Definition: gserverpeer.h:51
A structure used in GNet::Server::newPeer().
Definition: gserver.h:142
An abstract base class for the GNet::Server's connection to a remote client.
Definition: gserverpeer.h:68
A timer class template in which the timeout is delivered to the specified method.
Definition: gtimer.h:129
A derivation of ServerPeer for the administration interface.
Definition: gadminserver.h:53
bool notifying() const
Returns true if the remote user has asked for notifications.
void notify(const std::string &s0, const std::string &s1, const std::string &s2, const std::string &s4)
Called when something happens which the admin user might be interested in.
~AdminServerPeer() override
Destructor.
AdminServerPeer(GNet::ExceptionSinkUnbound, const GNet::ServerPeerInfo &, AdminServer &, const std::string &remote, const G::StringMap &info_commands, const G::StringMap &config_commands, bool with_terminate)
Constructor.
A server class which implements the emailrelay administration interface.
Definition: gadminserver.h:120
void report() const
Generates helpful diagnostics.
MessageStore & store()
Returns a reference to the message store, as passed in to the constructor.
AdminServer(GNet::ExceptionSink, MessageStore &store, FilterFactory &ff, G::Slot::Signal< const std::string & > &forward_request, const GNet::ServerPeerConfig &server_peer_config, const GNet::ServerConfig &server_config, const GSmtp::Client::Config &client_config, const GAuth::SaslClientSecrets &client_secrets, const G::StringArray &interfaces, unsigned int port, bool allow_remote, const std::string &remote_address, unsigned int connection_timeout, const G::StringMap &info_commands, const G::StringMap &config_commands, bool with_terminate)
Constructor.
void forward()
Called to trigger asynchronous forwarding.
FilterFactory & ff()
Returns a reference to the filter factory, as passed in to the constructor.
~AdminServer() override
Destructor.
GSmtp::Client::Config clientConfig() const
Returns the client configuration.
void notify(const std::string &s0, const std::string &s1, const std::string &s2, const std::string &s3)
Called when something happens which the admin users might be interested in.
unsigned int connectionTimeout() const
Returns the connection timeout, as passed in to the constructor.
const GAuth::SaslClientSecrets & clientSecrets() const
Returns a reference to the client secrets object, as passed in to the constructor.
std::unique_ptr< GNet::ServerPeer > newPeer(GNet::ExceptionSinkUnbound, GNet::ServerPeerInfo, GNet::MultiServer::ServerInfo) override
Override from GNet::MultiServer.
bool notifying() const
Returns true if the remote user has asked for notifications.
A factory interface for GSmtp::Filter message processors.
A class which allows SMTP messages to be stored and retrieved.
Definition: gmessagestore.h:73
SMTP and message-store classes.
Definition: gadminserver.h:39
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstrings.h:31
std::map< std::string, std::string > StringMap
A std::map of std::strings.
Definition: gstrings.h:32
A structure used in GNet::MultiServer::newPeer().
Definition: gmultiserver.h:52
A configuration structure for GNet::Server.
Definition: gserver.h:50
A structure containing GSmtp::Client configuration parameters.
Definition: gsmtpclient.h:57