5using System.Threading.Tasks;
30 private string host =
string.Empty;
31 private string userName =
string.Empty;
32 private string password =
string.Empty;
33 private string testMailRecipient =
string.Empty;
34 private string sender =
string.Empty;
35 private string[] relayDomains =
null;
36 private int port = 587;
37 private bool useRelayServer =
false;
41 [DefaultValueStringEmpty]
45 set => this.host = value;
52 set => this.port = value;
55 [DefaultValueStringEmpty]
56 public string UserName
59 set => this.userName = value;
63 public string Password
66 set => this.password = value;
75 public bool UseRelayServer
77 get => this.useRelayServer;
78 set => this.useRelayServer = value;
81 [DefaultValueStringEmpty]
82 public string TestMailRecipient
84 get => this.testMailRecipient;
85 set => this.testMailRecipient = value;
88 [DefaultValueStringEmpty]
92 set => this.sender = value;
96 public string[] RelayDomains
98 get => this.relayDomains;
99 set => this.relayDomains = value;
102 public string RelayDomainsText
106 if (this.relayDomains is
null)
109 StringBuilder Result =
new StringBuilder();
111 foreach (
string Domain
in this.relayDomains)
112 Result.AppendLine(Domain);
114 return Result.ToString();
126 public override string Resource =>
"/Settings/Relay.md";
149 this.userName, this.password, this.relayDomains,
true);
150 return Task.CompletedTask;
168 this.testMail = WebServer.
Register(
"/Settings/TestMail",
null, this.TestMail,
true,
false,
true);
170 return base.InitSetup(WebServer);
181 return base.UnregisterSetup(WebServer);
202 !(Content.
Decoded is Dictionary<string, object> Form) ||
203 !Form.TryGetValue(
"useRelayServer", out
object Obj) || !(Obj is
bool UseRelayServer) ||
204 !Form.TryGetValue(
"testMailRecipient", out Obj) || !(Obj is
string TestMailRecipient) ||
205 !Form.TryGetValue(
"sender", out Obj) || !(Obj is
string Sender) ||
206 !Form.TryGetValue(
"relayDomains", out Obj) || !(Obj is
string RelayDomains) ||
207 !Form.TryGetValue(
"sendMail", out Obj) || !(Obj is
bool SendMail))
213 if (!Form.TryGetValue(
"hostName", out Obj) || !(Obj is
string HostName) ||
214 !Form.TryGetValue(
"portNumber", out Obj) || !(Obj is
int PortNumber) || PortNumber < 1 || PortNumber > 65535 ||
215 !Form.TryGetValue(
"userName", out Obj) || !(Obj is
string UserName) ||
216 !Form.TryGetValue(
"password", out Obj) || !(Obj is
string Password))
225 HostName =
string.Empty;
227 UserName =
string.Empty;
228 Password =
string.Empty;
232 string TabID = Request.
Header[
"X-TabID"];
233 if (
string.IsNullOrEmpty(TabID))
239 Response.StatusCode = 200;
240 Response.StatusMessage =
"OK";
242 this.useRelayServer = UseRelayServer;
243 this.host = HostName;
244 this.port = PortNumber;
245 this.userName = UserName;
246 this.password = Password;
247 this.testMailRecipient = TestMailRecipient;
248 this.sender = Sender;
249 this.relayDomains = RelayDomains.Trim().Split(
CommonTypes.
CRLF, StringSplitOptions.RemoveEmptyEntries);
253 Task
_ = Task.Run(async () =>
259 string[] TabIDs =
new string[] { TabID };
260 string Message = await this.Test(TabIDs);
262 if (
string.IsNullOrEmpty(Message))
278 private async Task<string> Test(
string[] TabIDs)
283 if (
string.IsNullOrEmpty(DefaultDomain))
284 DefaultDomain =
"localhost";
286 string Sender = this.sender;
287 if (
string.IsNullOrEmpty(Sender))
290 await this.SendMessage(TabIDs, Sender, this.testMailRecipient,
293 "------------------\r\n\r\n" +
309 throw new ArgumentException(
"Invalid mail address: " + To, nameof(To));
317 if (this.useRelayServer)
321 UserName = this.userName;
322 Password = this.password;
327 if (Exchanges is
null || Exchanges.Length == 0)
328 throw new ArgumentException(
"No mail exchange at " + Domain +
".", nameof(To));
338 if (!(TabIDs is
null))
347 await Client.Connect();
349 await Client.SendFormattedEMail(From, To, Subject, Markdown);
355 public RelayConfiguration Config;
356 public string[] TabIDs;
359 : base(
"Relay Sniffer Proxy")
420 return Task.FromResult(
true);
469 if (!
string.IsNullOrEmpty(Value))
470 this.relayDomains = Value.Split(
',');
473 if (!
string.IsNullOrEmpty(Value))
476 if (this.useRelayServer)
490 Value = await this.Test(
null);
491 if (!
string.IsNullOrEmpty(Value))
Helps with parsing of commong data types.
static readonly char[] CRLF
Contains the CR LF character sequence.
Contains information about a response to a content request.
bool HasError
If an error occurred.
object Decoded
Decoded object.
Helps with common XML-related tasks.
static string HtmlValueEncode(string s)
Differs from Encode(String), in that it does not encode the aposotrophe or the quote.
Class representing an event.
override string ToString()
Static class managing the application event log. Applications and services log events on this static ...
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
The ClientEvents class allows applications to push information asynchronously to web clients connecte...
static Task< int > PushEvent(string[] TabIDs, string Type, object Data)
Puses an event to a set of Tabs, given their Tab IDs.
Static class managing the runtime environment of the IoT Gateway.
static IUser AssertUserAuthenticated(HttpRequest Request, string Privilege)
Makes sure a request is being made from a session with a successful user login.
static int NextInteger(int Max)
Returns a non-negative random integer that is less than the specified maximum.
static DomainConfiguration Instance
Current instance of configuration.
string Domain
Principal domain name
void LogEnvironmentError(string EnvironmentVariable, object Value)
Logs an error to the event log, telling the operator an environment variable value contains an error.
bool TryGetEnvironmentVariable(string VariableName, bool Required, out string Value)
Tries to get a string-valued environment variable.
Abstract base class for multi-step system configurations.
static XmppConfiguration Instance
Current instance of configuration.
DNS resolver, as defined in:
static Task< string[]> TryLookupMailExchange(string DomainName)
Tries to look up the Mail Exchanges related to a given domain name.
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
Represents an HTTP request.
HttpRequestHeader Header
Request header.
bool HasData
If the request has data.
async Task< ContentResponse > DecodeDataAsync()
Decodes data sent in request.
Base class for all HTTP resources.
Represets a response of an HTTP client request.
async Task SendResponse()
Sends the response back to the client. If the resource is synchronous, there's no need to call this m...
Implements an HTTP server.
HttpResource Register(HttpResource Resource)
Registers a resource with the server.
bool Unregister(HttpResource Resource)
Unregisters a resource from the server.
Implements a simple SMTP Server, as defined in:
static async Task< string > GetSalutation(string DefaultDomain)
Gets the proper salutation name for the server.
void SetRelaySettings(bool UseRelayServer, string HostName, int PortNumber, string UserName, string Password, string[] RelayDomains, bool LockSettings)
Sets mail relay settings.
const int DefaultSmtpPort
Default SMTP Port (25).
Represents a sniffer error event.
Represents a sniffer exception event.
Represents a sniffer binary reception event.
Represents a sniffer text reception event.
Represents a sniffer binary transmission event.
Represents a sniffer text transmission event.
Represents a sniffer warning event.
Abstract base class for sniffers. Implements default method overloads.
A sniffer that redirects incoming events to another sniffable object.
Represents a case-insensitive string.
int IndexOf(CaseInsensitiveString value, StringComparison comparisonType)
Reports the zero-based index of the first occurrence of the specified string in the current System....
CaseInsensitiveString Trim()
Removes all leading and trailing white-space characters from the current CaseInsensitiveString object...
CaseInsensitiveString Substring(int startIndex, int length)
Retrieves a substring from this instance. The substring starts at a specified character position and ...
Static interface for database persistence. In order to work, a database provider has to be assigned t...
static async Task Update(object Object)
Updates an object in the database.
Contains information about a language.
Task< string > GetStringAsync(Type Type, int Id, string Default)
Gets the string value of a string ID. If no such string exists, a string is created with the default ...
Provides the user configuration options regarding use of SMTP Relay server to send mail.
override void SetStaticInstance(ISystemConfiguration Configuration)
Sets the static instance of the configuration.
override Task< bool > SimplifiedConfiguration()
Simplified configuration by configuring simple default values.
const string BROKER_RELAY_PORT
Port number to use when connecting relay server.
override async Task< bool > EnvironmentConfiguration()
Environment configuration by configuring values available in environment variables.
string[] EncryptedProperties
Array of properties that are encrypted.
const string BROKER_RELAY_USE
If an SMTP relay server is to be used (true or 1), or if the broker should connect to the recipient m...
static RelayConfiguration Instance
Current instance of configuration.
override Task InitSetup(HttpServer WebServer)
Initializes the setup object.
override Task ConfigureSystem()
Is called during startup to configure the system.
const string BROKER_RELAY_PASSWORD
Password of account when authenticating access to the relay server.
const string BROKER_RELAY_HOST
Host(or domain) or the SMTP Relay server.
override Task UnregisterSetup(HttpServer WebServer)
Unregisters the setup object.
const string BROKER_RELAY_DOMAINS
Optional Comma-separated list of domain names for which the broker can act as an SMTP relay.
const string BROKER_RELAY_USER
User account in the relay server.
override string ConfigPrivilege
Minimum required privilege for a user to be allowed to change the configuration defined by the class.
const string BROKER_RELAY_SENDER
Default sender of mail messages from broker.
override Task< string > Title(Language Language)
Gets a title for the system configuration.
Service Module hosting the XMPP broker and its components.
Interface for system configurations. The gateway will scan all module for system configuration classe...
Interface for objects containing encrypted properties. Mark the properties that are encrypted with th...
Priority
Priority of message
BinaryPresentationMethod
How binary data is to be presented.