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
38 namespace 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///
52 class GSmtp::AdminServerPeer : public GNet::ServerPeer
53{
54 public:
55 AdminServerPeer( GNet::ExceptionSinkUnbound , const GNet::ServerPeerInfo & , AdminServer & ,
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
71 private: // 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
77 public:
78 AdminServerPeer( const AdminServerPeer & ) = delete ;
79 AdminServerPeer( AdminServerPeer && ) = delete ;
80 void operator=( const AdminServerPeer & ) = delete ;
81 void operator=( AdminServerPeer && ) = delete ;
82
83 private:
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
103 private:
104 GNet::ExceptionSink m_es ;
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///
119 class GSmtp::AdminServer : public GNet::MultiServer
120{
121 public:
122 AdminServer( GNet::ExceptionSink , MessageStore & store , FilterFactory & ff ,
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
146 const GAuth::SaslClientSecrets & clientSecrets() const ;
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
151 GSmtp::Client::Config clientConfig() const ;
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
169 protected:
170 std::unique_ptr<GNet::ServerPeer> newPeer( GNet::ExceptionSinkUnbound , GNet::ServerPeerInfo , GNet::MultiServer::ServerInfo ) override ;
171 ///< Override from GNet::MultiServer.
172
173 public:
174 AdminServer( const AdminServer & ) = delete ;
175 AdminServer( AdminServer && ) = delete ;
176 void operator=( const AdminServer & ) = delete ;
177 void operator=( AdminServer && ) = delete ;
178
179 private:
180 void onForwardTimeout() ;
181
182 private:
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
GAuth::SaslClientSecrets
An interface used by GAuth::SaslClient to obtain a client id and its authentication secret.
Definition: gsaslclientsecrets.h:39
GNet::ClientPtr< GSmtp::Client >
GNet::ExceptionSinkUnbound
A potential ExceptionSink that is realised by bind()ing an exception source pointer.
Definition: gexceptionsink.h:154
GNet::ExceptionSink
A tuple containing an ExceptionHandler interface pointer and a bound 'exception source' pointer.
Definition: gexceptionsink.h:100
GNet::MultiServer
A server that listens on more than one address using a facade pattern to multiple GNet::Server instan...
Definition: gmultiserver.h:45
GNet::ServerPeerConfig
A structure that GNet::Server uses to configure its ServerPeer objects.
Definition: gserverpeer.h:51
GNet::ServerPeerInfo
A structure used in GNet::Server::newPeer().
Definition: gserver.h:142
GNet::ServerPeer
An abstract base class for the GNet::Server's connection to a remote client.
Definition: gserverpeer.h:68
GNet::Timer
A timer class template in which the timeout is delivered to the specified method.
Definition: gtimer.h:129
GSmtp::AdminServerPeer
A derivation of ServerPeer for the administration interface.
Definition: gadminserver.h:53
GSmtp::AdminServerPeer::notifying
bool notifying() const
Returns true if the remote user has asked for notifications.
Definition: gadminserver.cpp:335
GSmtp::AdminServerPeer::notify
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.
Definition: gadminserver.cpp:255
GSmtp::AdminServerPeer::~AdminServerPeer
~AdminServerPeer() override
Destructor.
Definition: gadminserver.cpp:54
GSmtp::AdminServerPeer::AdminServerPeer
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.
Definition: gadminserver.cpp:34
GSmtp::AdminServer
A server class which implements the emailrelay administration interface.
Definition: gadminserver.h:120
GSmtp::AdminServer::report
void report() const
Generates helpful diagnostics.
Definition: gadminserver.cpp:412
GSmtp::AdminServer::store
MessageStore & store()
Returns a reference to the message store, as passed in to the constructor.
Definition: gadminserver.cpp:435
GSmtp::AdminServer::AdminServer
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.
Definition: gadminserver.cpp:342
GSmtp::AdminServer::forward
void forward()
Called to trigger asynchronous forwarding.
Definition: gadminserver.cpp:394
GSmtp::AdminServer::ff
FilterFactory & ff()
Returns a reference to the filter factory, as passed in to the constructor.
Definition: gadminserver.cpp:440
GSmtp::AdminServer::~AdminServer
~AdminServer() override
Destructor.
Definition: gadminserver.cpp:366
GSmtp::AdminServer::clientConfig
GSmtp::Client::Config clientConfig() const
Returns the client configuration.
Definition: gadminserver.cpp:455
GSmtp::AdminServer::notify
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.
Definition: gadminserver.cpp:417
GSmtp::AdminServer::connectionTimeout
unsigned int connectionTimeout() const
Returns the connection timeout, as passed in to the constructor.
Definition: gadminserver.cpp:450
GSmtp::AdminServer::clientSecrets
const GAuth::SaslClientSecrets & clientSecrets() const
Returns a reference to the client secrets object, as passed in to the constructor.
Definition: gadminserver.cpp:445
GSmtp::AdminServer::newPeer
std::unique_ptr< GNet::ServerPeer > newPeer(GNet::ExceptionSinkUnbound, GNet::ServerPeerInfo, GNet::MultiServer::ServerInfo) override
Override from GNet::MultiServer.
Definition: gadminserver.cpp:371
GSmtp::AdminServer::notifying
bool notifying() const
Returns true if the remote user has asked for notifications.
Definition: gadminserver.cpp:460
GSmtp::FilterFactory
A factory interface for GSmtp::Filter message processors.
Definition: gfilterfactory.h:42
GSmtp::MessageStore
A class which allows SMTP messages to be stored and retrieved.
Definition: gmessagestore.h:73
gclientptr.h
glinebuffer.h
gmultiserver.h
gsmtpclient.h
gsmtpserverprotocol.h
gstr.h
gtimer.h
GSmtp
SMTP and message-store classes.
Definition: gadminserver.h:39
G::StringArray
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstrings.h:31
G::StringMap
std::map< std::string, std::string > StringMap
A std::map of std::strings.
Definition: gstrings.h:32
GNet::MultiServer::ServerInfo
A structure used in GNet::MultiServer::newPeer().
Definition: gmultiserver.h:52
GNet::ServerConfig
A configuration structure for GNet::Server.
Definition: gserver.h:50
GSmtp::Client::Config
A structure containing GSmtp::Client configuration parameters.
Definition: gsmtpclient.h:57
G::Slot::Signal< const std::string & >