Example #1
0
        static void Main(string[] args)
        {
            FoeDebug.Print("Creating Foe Message content.");
            string catalog = "VOAENGLISH";

            FoeDebug.Print("Generating a random request ID.");
            string requestId = RandomString.Generate(10);

            FoeDebug.Print("Setting up SMTP configuration.");
            SmtpServer server = new SmtpServer();

            server.ServerName   = "smtp.gmail.com";
            server.Port         = 587;
            server.AuthRequired = true;
            server.SslEnabled   = true;
            server.UserName     = "******";
            server.Password     = "******";

            FoeDebug.Print("Sending content request message.");
            string subject = SubjectGenerator.RequestSubject(RequestType.Content, requestId, _userId);

            MessageManager.SendMessage(
                server,
                _userEmail,
                _processorEmail,
                subject,
                catalog);
        }
Example #2
0
        private void SendCatalogRequest()
        {
            try
            {
                // Delete all previous content requests
                FoeClientRequest.DeleteOldRequest(_requestInterval);

                // Create Foe Message
                string requestId = FoeClientRequest.GenerateId();

                FoeClientMessage.SendMessage(
                    FoeClientMessage.GetSmtpServer(),
                    FoeClientRegistry.GetEntry("useremail").Value,
                    FoeClientRegistry.GetEntry("processoremail").Value,
                    SubjectGenerator.RequestSubject(RequestType.Catalog, requestId, FoeClientRegistry.GetEntry("userid").Value),
                    "");

                // save requestid to DB
                FoeClientRequestItem reqItem = new FoeClientRequestItem();
                reqItem.Id          = requestId;
                reqItem.Type        = "catalog";
                reqItem.DtRequested = DateTime.Now;
                FoeClientRequest.Add(reqItem);

                // remember when the request was sent
                _lastRequestSent = DateTime.Now;
                // Set status
                tssStatus.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " requested catalog.";
            }
            catch (Exception)
            {
                tssStatus.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " error sending request.";
            }
        }
Example #3
0
        public static void SendRegistration()
        {
            // Check if user's email is available
            FoeClientRegistryEntry email = FoeClientRegistry.GetEntry("useremail");

            if ((email == null) || (email.Value == null) || (email.Value.Length < 3))
            {
                // Invalid user email
                return;
            }

            // Prepare message to send to server
            FoeMessage message = new FoeMessage();

            message.Add(new FoeMessageItem("UserEmail", email.Value));

            // Get SMTP server configurations
            SmtpServer server = null;

            try
            {
                server = FoeClientMessage.GetSmtpServer();
            }
            catch (Exception except)
            {
                throw new Exception("Invalid SMTP configurations.\r\n" + except.ToString());
            }

            // Send email
            try
            {
                string requestId = FoeClientRequest.GenerateId();
                FoeClientMessage.SendMessage(
                    server,
                    email.Value,
                    FoeClientRegistry.GetEntry("processoremail").Value,
                    SubjectGenerator.RequestSubject(RequestType.Registration, requestId, "Newbie"),
                    message);

                // Save request info
                FoeClientRequestItem req = new FoeClientRequestItem();
                req.Id          = requestId;
                req.Type        = "reg";
                req.DtRequested = DateTime.Now;
                FoeClientRequest.Add(req);
            }
            catch (Exception except)
            {
                throw new Exception("Error sending message.\r\n" + except.ToString());
            }
        }
Example #4
0
        public override Task GrantCustomExtension(OAuthGrantCustomExtensionContext context)
        {
            var windowsPrincipal = context.OwinContext.Authentication.User as WindowsPrincipal;

            if (windowsPrincipal == null)
            {
                context.SetError("User is not a Windows user");
                return(Task.FromResult(0));
            }

            var subject = SubjectGenerator.Create(windowsPrincipal, _options);

            context.Validated(subject);

            return(Task.FromResult(0));
        }
Example #5
0
        private void SendSubscriptionRequest()
        {
            try
            {
                // Delete all previous content requests
                FoeClientRequest.DeleteOldRequest(_requestInterval);

                // Create Foe Message
                string catalogs = "";
                List <FoeClientCatalogItem> catalog = FoeClientCatalog.GetAll();
                if (catalog.Count == 0)
                {
                    return;
                }
                foreach (FoeClientCatalogItem item in catalog)
                {
                    if (item.IsSubscribed)
                    {
                        catalogs += item.Code + ",";
                    }
                }
                string requestId = FoeClientRequest.GenerateId();

                FoeClientMessage.SendMessage(
                    FoeClientMessage.GetSmtpServer(),
                    FoeClientRegistry.GetEntry("useremail").Value,
                    FoeClientRegistry.GetEntry("processoremail").Value,
                    SubjectGenerator.RequestSubject(RequestType.Content, requestId, FoeClientRegistry.GetEntry("userid").Value),
                    catalogs);

                // save requestid to DB
                FoeClientRequestItem reqItem = new FoeClientRequestItem();
                reqItem.Id          = requestId;
                reqItem.Type        = "content";
                reqItem.DtRequested = DateTime.Now;
                FoeClientRequest.Add(reqItem);

                // remember when the request was sent
                _lastRequestSent = DateTime.Now;
                // Set status
                tssStatus.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " requested update.";
            }
            catch (Exception)
            {
                tssStatus.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " error sending request.";
            }
        }
        public override async Task GrantCustomExtension(OAuthGrantCustomExtensionContext context)
        {
            var windowsPrincipal = context.OwinContext.Authentication.User as WindowsPrincipal;

            if (windowsPrincipal == null)
            {
                context.SetError("User is not a Windows user");
                return;
            }

            var subject = SubjectGenerator.Create(windowsPrincipal, _options);
            var transformationContext = new CustomClaimsProviderContext
            {
                WindowsPrincipal = windowsPrincipal,
                OutgoingSubject  = subject
            };
            await _options.CustomClaimsProvider.TransformAsync(transformationContext);

            context.Validated(transformationContext.OutgoingSubject);
        }
        static void Main(string[] args)
        {
            FoeDebug.Print("Generating a random request ID.");
            string requestId = RandomString.Generate(10);

            FoeDebug.Print("Setting up SMTP configuration.");
            SmtpServer server = new SmtpServer();

            server.ServerName   = "doraemon";
            server.Port         = 25;
            server.AuthRequired = true;
            server.SslEnabled   = false;
            server.UserName     = "******";
            server.Password     = "******";

            FoeDebug.Print("Sending registration message.");
            MessageManager.SendMessage(
                server,
                _userEmail,
                _processorEmail,
                SubjectGenerator.RequestSubject(RequestType.Registration, requestId, "Newbie"),
                "");
        }
        public static void SendRssCache(string catalogCode, string userEmail, string requestId, bool isAutoSubscription)
        {
            // Load RSS
            string rss = FoeServerCatalog.GetRssCache(catalogCode);

            if (rss == null)
            {
                throw new Exception("RSS feed " + catalogCode + " does not exist.");
            }

            // Load User info
            FoeUser user = FoeServerUser.GetUser(userEmail);

            if (user == null)
            {
                throw new Exception("User " + userEmail + " does not exist.");
            }

            // Prepare Foe Message

            /*
             * string rssBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(feed.Rss));
             * FoeMessage foeMessage = new FoeMessage();
             * foeMessage.Add(new FoeMessageItem("CatalogCode", feed.Code));
             * foeMessage.Add(new FoeMessageItem("Rss", rssBase64));
             */

            FoeDebug.Print("Generated Foe Message.");

            // Send reply to user
            try
            {
                FoeServerMessage.SendMessage(
                    FoeServerMessage.GetDefaultSmtpServer(),
                    FoeServerRegistry.Get("ProcessorEmail"),
                    userEmail,
                    SubjectGenerator.ReplySubject(RequestType.Content, catalogCode, requestId, FoeServerUser.GetUser(userEmail).UserId),
                    rss);

                FoeDebug.Print("Sent reply to user.");

                // Add user to auto-subscription list
                if (!isAutoSubscription)
                {
                    FoeServerAutoSubscribe.Add(userEmail, catalogCode, requestId);
                }
                else
                {
                    // If the caller function is just processing AutoSubscription, then
                    // we don't want to recreate the subscription, simply update the
                    // current subscription.
                    FoeServerAutoSubscribe.Update(userEmail, catalogCode, requestId);
                }

                FoeDebug.Print("Added user to Auto Subscription.");
            }
            catch (Exception except)
            {
                FoeDebug.Print("FoeServerCatalog: Error sending email.");
                FoeDebug.Print(except.ToString());
            }
        }
        private void DoFeedAdd()
        {
            //FoeDebug.Print("Loading requests...");
            bool   hasError = false;
            string message  = "";
            // Load content requests
            FoeRequester     req            = null;
            FoeServerRequest requestManager = new FoeServerRequest(RequestType.Feed, FoeServerRegistry.Get("ProcessorEmail"));

            while ((req = requestManager.GetNextRequest()) != null)
            {
                //FoeDebug.Print("Processing request from " + req.UserEmail + " with request ID " + req.RequestId);

                // Check what contents are requested


                // Get user info
                FoeUser user = FoeServerUser.GetUser(req.UserEmail);
                if (user == null)
                {
                    //FoeDebug.Print("User not registered. Skip this request.");
                    //FoeDebug.Print("---------------------------------------");

                    // User is not registered, mark this request as "E" (Error) and skip to the next one
                    requestManager.UpdateRequestStatus(req, "E");

                    FoeServerLog.Add(_processName, FoeServerLog.LogType.Warning, "User " + user.Email + " not registered. Discard content request.");

                    continue;
                }

                //FoeDebug.Print("User verified.");

                // Process request
                List <CatalogItem> catalogs = FoeServerCatalog.GetCatalog(); // get all the catalogs on server

                if (catalogs != null)
                {
                    //FoeDebug.Print("Generated Foe Message.");

                    foreach (CatalogItem catalog in catalogs)
                    {
                        message += catalog.Code + ",";
                    }

                    // Send reply to user
                    try
                    {
                        FoeServerMessage.SendMessage(
                            FoeServerMessage.GetDefaultSmtpServer(),
                            FoeServerRegistry.Get("ProcessorEmail"),
                            req.UserEmail,
                            SubjectGenerator.ReplySubject(RequestType.Catalog, req.RequestId, FoeServerUser.GetUser(req.UserEmail).UserId),
                            message);

                        //FoeDebug.Print("Sent reply to user.");
                    }
                    catch (Exception except)
                    {
                        //FoeDebug.Print("Error sending email.");
                        //FoeDebug.Print(except.ToString());
                        hasError = true;

                        FoeServerLog.Add(_processName, FoeServerLog.LogType.Error, "Error delivering content to " + user.Email + "\r\n" + except.ToString());
                    }
                }

                // If there is no error, then we'll mark the request as 'C' (Completed).
                // Otherwise, we'll leave it as 'P' (Pending).
                if (!hasError)
                {
                    // mark request as "C" (Completed)
                    requestManager.UpdateRequestStatus(req, "C");

                    FoeServerLog.Add(_processName, FoeServerLog.LogType.Message, "Sent " + message + "to " + user.Email + " and added user to AutoSubscription.");

                    //FoeDebug.Print("Marked request as 'C' (Completed).");
                    //FoeDebug.Print("----------------------------------");
                }
                else
                {
                    //FoeDebug.Print("Leave request as 'P' (Pending).");
                    //FoeDebug.Print("-------------------------------");

                    FoeServerLog.Add(_processName, FoeServerLog.LogType.Error,
                                     "Error delivering content but error is likely caused by temporary email downtime. " +
                                     "Leave status as 'P' (Pending) so process can try again later.");
                }
            }

            // Close all requestManager connections
            requestManager.Close();
        }