Exemplo n.º 1
0
        public static async Task ShiftFromDate(IHttpContext context)
        {
            Server.ReadCookies(context).TryGetValue("MelBoxId", out string guid);

            if (!Server.LogedInHash.TryGetValue(guid, out Contact user))
            {
                await Home(context);

                return;
            }

            bool isAdmin = user.Accesslevel >= Server.Level_Admin;

            var shiftDateStr = context.Request.PathParameters["shiftDate"];

            DateTime.TryParse(shiftDateStr, out DateTime shiftDate);

            Shift shift = new Shift(user.Id, shiftDate);

            string contactOptions = Tab_Contact.HtmlOptionContacts(Server.Level_Reciever, shift.ContactId, isAdmin);

            DateTime endDate = shiftDate.DayOfWeek == DayOfWeek.Monday ? shiftDate.Date.AddDays(7) : shiftDate.Date.AddDays(1);

            Dictionary <string, string> pairs = new Dictionary <string, string>
            {
                // { "##readonly##", "readonly" },
                { "##Id##", string.Empty },
                { "##ContactOptions##", contactOptions },
                { "##MinDate##", DateTime.UtcNow.Date.ToString("yyyy-MM-dd") },
                { "##StartDate##", shiftDate.Date.ToString("yyyy-MM-dd") },
                { "##EndDate##", endDate.ToString("yyyy-MM-dd") },
                { "##StartOptions##", Tab_Shift.HtmlOptionHour(shift.Start.ToLocalTime().Hour) },
                { "##EndOptions##", Tab_Shift.HtmlOptionHour(shift.End.ToLocalTime().Hour) },
                { "##Route##", "new" }
            };

            string form = Server.Page(Server.Html_FormShift, pairs);

            DataTable dt    = Sql.Shift_View();
            string    table = Html.FromShiftTable(dt, user);

            await Server.PageAsync(context, "Bereitschaftsdienst", table + form);
        }
Exemplo n.º 2
0
        public static async Task AccountDelete(IHttpContext context)
        {
            #region Anfragenden Benutzer identifizieren
            Server.ReadCookies(context).TryGetValue("MelBoxId", out string guid);

            if (guid == null || !Server.LogedInHash.TryGetValue(guid, out Contact user))
            {
                await Home(context);

                return;
            }
            #endregion

            bool isAdmin = user.Accesslevel >= Server.Level_Admin;
            string html  = Html.Alert(1, "Fehlerhafter Parameter", "Aufruf mit fehlerhaftem Parameter.");

            if (context.Request.PathParameters.TryGetValue("id", out string idStr))
            {
                if (!isAdmin || !int.TryParse(idStr, out int deleteId))
                {
                    html = Html.Alert(2, "Keine Berechtigung", $"Keine Berechtigung zum Löschen von Benutzern.");
                }
                else
                {
                    Contact contact = Tab_Contact.SelectContact(deleteId);

                    if (!Tab_Contact.Delete(deleteId))
                    {
                        html = Html.Alert(2, "Löschen fehlgeschlagen", $"Löschen des Benutzers [{deleteId}] >{contact.Name}< fehlgeschlagen.");
                    }
                    else
                    {
                        string text = $"Der Benutzer [{deleteId}] >{contact.Name}< wurde durch [{user.Id}] >{user.Name}< aus der Datenbank gelöscht.";
                        html = Html.Alert(1, "Benuter gelöscht", text);
                        MelBoxSql.Tab_Log.Insert(Tab_Log.Topic.Database, 2, text);
                    }
                }
            }

            await Server.PageAsync(context, "Benutzer löschen", html);
        }
Exemplo n.º 3
0
        private static int GetSmsSenderID(string phone, string message)
        {
            int fromId = MelBoxSql.Tab_Contact.SelectContactId(phone);

            if (fromId == 0) // Unbekannter Sender
            {
                Tab_Contact.InsertNewContact(phone, message);
                fromId = MelBoxSql.Tab_Contact.SelectContactId(phone);

                string log = message.Length > 32 ? message.Substring(0, 32) + "..." : message;
                log = $"Neuen Benutzer [{fromId}] angelegt mit Absender >{phone}< Nachricht: >{log}<";

                Tab_Log.Insert(Tab_Log.Topic.Database, 2, log);
                Email.Send(Email.Admin, log, "Unbekannter Absender: Benutzer angelegt.");
            }

#if DEBUG
            Console.WriteLine($"Debug: Kontakt >{phone}< hat die Id {fromId}");
#endif

            return(fromId);
        }
Exemplo n.º 4
0
        public static async Task ShiftFromId(IHttpContext context)
        {
            Server.ReadCookies(context).TryGetValue("MelBoxId", out string guid);
            bool isAdmin = false;

            if (Server.LogedInHash.TryGetValue(guid, out Contact user))
            {
                isAdmin = user.Accesslevel >= Server.Level_Admin;
            }

            var shiftIdStr = context.Request.PathParameters["shiftId"];

            int.TryParse(shiftIdStr, out int shiftId);

            Shift shift = Tab_Shift.Select(shiftId);

            string contactOptions = Tab_Contact.HtmlOptionContacts(Server.Level_Reciever, shift.ContactId, isAdmin);

            Dictionary <string, string> pairs = new Dictionary <string, string>
            {
                //{ "##readonly##", string.Empty },
                { "##Id##", shift.Id.ToString() },
                { "##ContactOptions##", contactOptions },
                { "##MinDate##", DateTime.UtcNow.Date.ToString("yyyy-MM-dd") },
                { "##StartDate##", shift.Start.ToLocalTime().ToString("yyyy-MM-dd") },
                { "##EndDate##", shift.End.ToLocalTime().ToString("yyyy-MM-dd") },
                { "##StartOptions##", Tab_Shift.HtmlOptionHour(shift.Start.ToLocalTime().Hour) },
                { "##EndOptions##", Tab_Shift.HtmlOptionHour(shift.End.ToLocalTime().Hour) },
                { "##Route##", "update" }
            };

            string form = Server.Page(Server.Html_FormShift, pairs);

            DataTable dt    = Sql.Shift_View();
            string    table = Html.FromShiftTable(dt, user);

            await Server.PageAsync(context, "Bereitschaftsdienst", table + form);
        }
Exemplo n.º 5
0
        public static async Task AccountUpdate(IHttpContext context)
        {
            Server.ReadCookies(context).TryGetValue("MelBoxId", out string guid);

            if (!Server.LogedInHash.TryGetValue(guid, out Contact user))
            {
                await Home(context);

                return;
            }

            #region Form auslesen
            Dictionary <string, string> payload = Server.Payload(context);
            payload.TryGetValue("Id", out string idStr);
            payload.TryGetValue("name", out string name);
            payload.TryGetValue("password", out string password);
            payload.TryGetValue("CompanyId", out string CompanyIdStr);
            payload.TryGetValue("viaEmail", out string viaEmail);
            payload.TryGetValue("viaAlwaysEmail", out string viaAlwaysEmail);
            payload.TryGetValue("email", out string email);
            payload.TryGetValue("viaPhone", out string viaPhone);
            payload.TryGetValue("phone", out string phoneStr);
            payload.TryGetValue("Keyword", out string keyWord);
            payload.TryGetValue("MaxInactiveHours", out string maxInactiveHoursStr);
            payload.TryGetValue("Accesslevel", out string accesslevelStr);
            #endregion

            #region Kontakt erstellen
            Contact where = new Contact();

            if (int.TryParse(idStr, out int Id))
            {
                where.Id = Id;
            }

            Contact set = new Contact
            {
                Name      = name,
                EntryTime = DateTime.UtcNow,
                KeyWord   = keyWord
            };

            if (password.Length > 0)
            {
                set.Password = Tab_Contact.Encrypt(password);
            }

            set.Email = email;


            if (int.TryParse(CompanyIdStr, out int companyId))
            {
                set.CompanyId = companyId;
            }

            if (int.TryParse(maxInactiveHoursStr, out int maxInactiveHours))
            {
                set.MaxInactiveHours = maxInactiveHours;
            }

            if (int.TryParse(accesslevelStr, out int accesslevel))
            {
                //kann maximal eigenen Access-Level vergeben.
                if (accesslevel > user.Accesslevel)
                {
                    accesslevel = user.Accesslevel;
                }

                set.Accesslevel = accesslevel;
            }

            if (ulong.TryParse(phoneStr, out ulong phone))
            {
                set.Phone = phone;
            }

            set.Via = Tab_Contact.Communication.Unknown;

            if (viaEmail != null)
            {
                set.Via |= Tab_Contact.Communication.Email;
            }
            if (viaAlwaysEmail != null)
            {
                set.Via |= Tab_Contact.Communication.AlwaysEmail;
            }
            if (viaPhone != null)
            {
                set.Via |= Tab_Contact.Communication.Sms;
            }
            #endregion

            bool success = Id > 0 && MelBoxSql.Tab_Contact.Update(set, where);

            string alert;

            if (success)
            {
                alert = Html.Alert(3, "Kontakt gespeichert", "Der Kontakt [" + Id + "] " + name + " wurde erfolgreich geändert.");
                Tab_Log.Insert(Tab_Log.Topic.Database, 2, "Der Kontakt [" + Id + "] >" + name + "< wurde geändert durch >" + user.Name + "< [" + user.Accesslevel + "]");
            }
            else
            {
                alert = Html.Alert(1, "Fehler beim speichern des Kontakts", "Der Kontakt [" + Id + "] " + name + " konnte in der Datenbank nicht geändert werden.");
            }

            await Server.PageAsync(context, "Benutzerkonto ändern", alert);
        }
Exemplo n.º 6
0
        public static async Task AccountCreate(IHttpContext context)
        {
            Server.ReadCookies(context).TryGetValue("MelBoxId", out string guid);

            if (!Server.LogedInHash.TryGetValue(guid, out Contact user) || user.Accesslevel < Server.Level_Admin)
            {
                await Home(context);

                return;
            }

            #region Form auslesen
            Dictionary <string, string> payload = Server.Payload(context);
            //payload.TryGetValue("Id",out string idStr); //Wird automatisch vergeben
            payload.TryGetValue("name", out string name);
            payload.TryGetValue("password", out string password);
            payload.TryGetValue("CompanyId", out string CompanyIdStr);
            payload.TryGetValue("viaEmail", out string viaEmail);
            payload.TryGetValue("viaAlwaysEmail", out string viaAlwaysEmail);
            payload.TryGetValue("email", out string email);
            payload.TryGetValue("viaPhone", out string viaPhone);
            payload.TryGetValue("phone", out string phoneStr);
            //KeyWord bei Neuanlage nicht vergebbar
            payload.TryGetValue("MaxInactiveHours", out string maxInactiveHoursStr);
            payload.TryGetValue("Accesslevel", out string accesslevelStr);
            #endregion

            #region Kontakt erstellen
            Contact contact = new Contact
            {
                Name      = name,
                EntryTime = DateTime.UtcNow,
                Password  = Tab_Contact.Encrypt(password),
                Email     = email,
            };

            if (int.TryParse(CompanyIdStr, out int companyId))
            {
                contact.CompanyId = companyId;
            }

            if (int.TryParse(maxInactiveHoursStr, out int maxInactiveHours))
            {
                contact.MaxInactiveHours = maxInactiveHours;
            }

            if (int.TryParse(accesslevelStr, out int accesslevel))
            {
                contact.Accesslevel = accesslevel;
            }

            if (ulong.TryParse(phoneStr, out ulong phone))
            {
                contact.Phone = phone;
            }

            contact.Via = Tab_Contact.Communication.Unknown;

            if (viaEmail != null)
            {
                contact.Via |= Tab_Contact.Communication.Email;
            }
            if (viaAlwaysEmail != null)
            {
                contact.Via |= Tab_Contact.Communication.AlwaysEmail;
            }
            if (viaPhone != null)
            {
                contact.Via |= Tab_Contact.Communication.Sms;
            }
            #endregion

            bool success = MelBoxSql.Tab_Contact.Insert(contact);
            string alert;

            if (success)
            {
                alert = Html.Alert(3, "Neuen Kontakt gespeichert", "Der Kontakt " + name + " wurde erfolgreich neu erstellt.");
                Tab_Log.Insert(Tab_Log.Topic.Database, 2, "Der Kontakt >" + name + "< wurde neu erstellt durch >" + user.Name + "< [" + user.Accesslevel + "]");
            }
            else
            {
                alert = Html.Alert(1, "Fehler beim speichern des Kontakts", "Der Kontakt " + name + " konnte nicht in der Datenbank gespeichert werden.");
            }

            await Server.PageAsync(context, "Benutzerkonto erstellen", alert);
        }
Exemplo n.º 7
0
        public static async Task AccountShow(IHttpContext context)
        {
            #region Anfragenden Benutzer identifizieren
            Server.ReadCookies(context).TryGetValue("MelBoxId", out string guid);

            if (guid == null || !Server.LogedInHash.TryGetValue(guid, out Contact user))
            {
                await Home(context);

                return;
            }

            bool isAdmin = user.Accesslevel >= Server.Level_Admin;
            DataTable dt = Tab_Contact.SelectContactList(user.Accesslevel, isAdmin ? 0 : user.Id);
            #endregion

            #region Anzuzeigenden Benutzer
            int showId = user.Id;

            if (context.Request.PathParameters.TryGetValue("id", out string idStr))
            {
                int.TryParse(idStr, out showId);
            }

            Contact account = MelBoxSql.Tab_Contact.SelectContact(showId);
            Company company = MelBoxSql.Tab_Company.SelectCompany(account.CompanyId);
            #endregion

            bool viaSms         = account.Via.HasFlag(Tab_Contact.Communication.Sms);
            bool viaEmail       = account.Via.HasFlag(Tab_Contact.Communication.Email);
            bool viaAlwaysEmail = account.Via.HasFlag(Tab_Contact.Communication.AlwaysEmail);

            string userRole = "Aspirant";
            if (account.Accesslevel >= Server.Level_Admin)
            {
                userRole = "Admin";
            }
            else if (account.Accesslevel >= Server.Level_Reciever)
            {
                userRole = "Benutzer";
            }
            else if (account.Accesslevel > 0)
            {
                userRole = "Beobachter";
            }

            Dictionary <string, string> pairs = new Dictionary <string, string>
            {
                { "##readonly##", isAdmin ? string.Empty : "readonly" },
                { "##disabled##", isAdmin ? string.Empty : "disabled" },
                { "##Id##", account.Id.ToString() },
                { "##Name##", account.Name },
                { "##Accesslevel##", account.Accesslevel.ToString() },
                { "##UserRole##", userRole },
                { "##UserAccesslevel##", user.Accesslevel.ToString() },
                { "##CompanyId##", account.CompanyId.ToString() },
                { "##CompanyName##", company.Name },
                { "##CompanyCity##", System.Text.RegularExpressions.Regex.Replace(company.City, @"\d", "") },
                { "##viaEmail##", viaEmail ? "checked" : string.Empty },
                { "##viaAlwaysEmail##", viaAlwaysEmail ? "checked" : string.Empty },
                { "##Email##", account.Email },
                { "##viaPhone##", viaSms ? "checked" : string.Empty },
                { "##Phone##", "+" + account.Phone.ToString() },
                { "##MaxInactiveHours##", account.MaxInactiveHours.ToString() },
                { "##KeyWord##", account.KeyWord },
                { "##CompanyList##", isAdmin ? Tab_Company.SelectCompanyAllToHtmlOption(account.CompanyId) : string.Empty },

                { "##NewContact##", isAdmin ? Html.ButtonNew("account") : string.Empty },
                { "##DeleteContact##", isAdmin ? Html.ButtonDelete("account", account.Id) : string.Empty }
            };

            string form  = Server.Page(Server.Html_FormAccount, pairs);
            string tabel = Html.FromTable(dt, true, "account");

            await Server.PageAsync(context, "Benutzerkonto", tabel + form);
        }
Exemplo n.º 8
0
        public static async Task RegisterProcessing(IHttpContext context)
        {
            #region Form auslesen
            Dictionary <string, string> payload = Server.Payload(context);
            //payload.TryGetValue("Id",out string idStr); //Wird automatisch vergeben
            payload.TryGetValue("name", out string name);
            payload.TryGetValue("password", out string password);
            payload.TryGetValue("CompanyId", out string CompanyIdStr);
            payload.TryGetValue("viaEmail", out string viaEmail);
            payload.TryGetValue("email", out string email);
            payload.TryGetValue("viaPhone", out string viaPhone);
            payload.TryGetValue("phone", out string phoneStr);
            //KeyWord nicht vergebbar
            //payload.TryGetValue("MaxInactiveHours", out string maxInactiveHoursStr);
            //payload.TryGetValue("Accesslevel", out string accesslevelStr);
            #endregion

            #region Kontakt erstellen
            Contact contact = new Contact
            {
                Name = name
            };

            if (MelBoxSql.Tab_Contact.Select(contact).Rows.Count > 0)
            {
                string error = Html.Alert(1, "Registrierung fehlgeschlagen", $"Der Benutzername {name} ist bereits vergeben." + @"<a href='/' class='w3-bar-item w3-button w3-teal w3-margin'>Nochmal</a>");
                await Server.PageAsync(context, "Benutzerregistrierung fehlgeschlagen", error);

                return;
            }

            contact.EntryTime = DateTime.UtcNow;
            contact.Password  = Tab_Contact.Encrypt(password);
            contact.Email     = email;

            if (int.TryParse(CompanyIdStr, out int companyId))
            {
                contact.CompanyId = companyId;
            }

            contact.MaxInactiveHours = 0;
            contact.Accesslevel      = 0;

            if (ulong.TryParse(phoneStr, out ulong phone))
            {
                contact.Phone = phone;
            }

            contact.Via = Tab_Contact.Communication.Unknown;

            if (viaEmail != null)
            {
                contact.Via |= Tab_Contact.Communication.Email;
            }
            if (viaPhone != null)
            {
                contact.Via |= Tab_Contact.Communication.Sms;
            }
            #endregion

            bool success = MelBoxSql.Tab_Contact.Insert(contact);

            string alert;

            if (success)
            {
                alert = Html.Alert(3, $"Erfolgreich registriert", $"Willkommen {name}!<br/> Die Registrierung muss noch durch einen Administrator bestätigt werden, bevor Sie sich einloggen können. Informieren Sie einen Administrator.");
                Tab_Log.Insert(Tab_Log.Topic.Database, 2, $"Neuer Benutzer >{name}< im Web-Portal registriert.");
            }
            else
            {
                alert = Html.Alert(1, "Registrierung fehlgeschlagen", "Es ist ein Fehler bei der Registrierung aufgetreten. Wenden Sie sich an den Administrator.");
            }


            await Server.PageAsync(context, "Benutzerregistrierung", alert);
        }
Exemplo n.º 9
0
        private static void Gsm_SmsRecievedEvent(object sender, ParseSms e)
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine(e.Sender + ":\r\n" + e.Message);
            Console.ForegroundColor = ConsoleColor.Gray;

            #region SMS-Empfang in Datenbank protokollieren
            int fromId    = GetSmsSenderID(e.Sender, e.Message);
            int messageId = MelBoxSql.Tab_Message.SelectOrCreateMessageId(e.Message);

            Recieved recieved1 = new Recieved()
            {
                FromId    = fromId,
                ContentId = messageId,
                RecTime   = DateTime.UtcNow
            };

            MelBoxSql.Tab_Recieved.Insert(recieved1);
            #endregion

            #region Weiterleiten per EMail oder SMS

            MailAddressCollection emailRecievers = new MailAddressCollection();
            string emailSuffix = string.Empty;

            Random ran     = new Random();
            int    emailId = ran.Next(256, 9999);                                // Pseudo-Id für Sendungsverfolgung

            if (e.Message.ToLower().Trim() == SmsWayValidationTrigger.ToLower()) // SmsAbruf?
            {
                #region Meldelinientest 'SmsAbruf'

                MelBoxGsm.Gsm.Ask_SmsSend(e.Sender, e.Message.Trim() + " um " + DateTime.Now.ToString("HH:mm:ss") + " Uhr.");

                Sent sent = new Sent(fromId, messageId, Tab_Contact.Communication.Sms)
                {
                    SentTime = DateTime.UtcNow
                };
                MelBoxSql.Tab_Sent.Insert(sent);

                #endregion
            }
            else if (Tab_Message.IsMessageBlockedNow(messageId)) // Nachricht zum jetzigen Zeitpunkt gesperrt?
            {
                emailSuffix += Environment.NewLine + "Keine Weiterleitung an Bereitschaftshandy da SMS zur Zeit gesperrt.";
            }
            else // An Bereitschaft senden
            {
                #region An Bereitschaft senden
                //Bereitschaft ermitteln
                List <MelBoxSql.Shift> currentShifts = MelBoxSql.Tab_Shift.SelectOrCreateCurrentShift();
                Console.WriteLine("Aktuelle Bereitschaft: ");

                //an Bereitschaft weiterleiten
                foreach (var shift in currentShifts)
                {
                    Contact to = MelBoxSql.Tab_Contact.SelectContact(shift.ContactId);
                    Console.WriteLine($"Id [{shift.Id}] >{to.Name}< von >{shift.Start}< bis >{shift.End}<");

                    //Email freigegeben und gültig?
                    if ((to.Via & Tab_Contact.Communication.Email) > 0 && Tab_Contact.IsEmail(to.Email))
                    {
                        emailRecievers.Add(new MailAddress(to.Email, to.Name));

                        Sent sent = new Sent(shift.ContactId, messageId, Tab_Contact.Communication.Email)
                        {
                            Confirmation = Tab_Sent.Confirmation.AwaitingRefernece,
                            Reference    = emailId,
                            SentTime     = DateTime.UtcNow
                        };

                        MelBoxSql.Tab_Sent.Insert(sent);
                    }

                    //SMS?
                    if ((to.Via & Tab_Contact.Communication.Sms) > 0)
                    {
                        Sent sent = new Sent(shift.ContactId, messageId, Tab_Contact.Communication.Sms)
                        {
                            Confirmation = Tab_Sent.Confirmation.NaN,
                            SentTime     = DateTime.UtcNow
                        };

                        MelBoxSql.Tab_Sent.Insert(sent);
                        MelBoxGsm.Gsm.Ask_SmsSend("+" + to.Phone.ToString(), e.Message);
                    }
                }

                if (currentShifts.Count == 0)
                {
                    Console.WriteLine("z.Zt. keine aktive Bereitschaft");
                    emailSuffix += Environment.NewLine + "Keine Weiterleitung an Bereitschaftshandy während der Geschäftszeit.";
                }
                else
                {
                    emailSuffix += Environment.NewLine + "Weiterleitung an Bereitschaftshandy außerhalb Geschäftszeiten ist erfolgt.";
                }
                #endregion
            }

            //Emails an Bereitschaft und ständige Empfänger senden.
            string subject = $"SMS-Eingang >{MelBoxSql.Tab_Contact.SelectName_Company_City(fromId)}<, Text >{e.Message}<";
            string body    = $"Absender >{e.Sender}<\r\nText >{e.Message}<\r\nSendezeit >{e.TimeUtc.ToLocalTime().ToLongTimeString()}<\r\n" + emailSuffix;
            Email.Send(emailRecievers, body, subject, emailId);

            #endregion
        }