Exemplo n.º 1
0
        static void Main()
        {
            try
            {
                #region Programm hochfahren
                //Console.BufferHeight = 1000; //Max. Zeilen in Console begrenzen
                Console.WriteLine("Progammstart. Beenden mit >Exit> - Für Hilfe: >Help<");
                Ini.ReadIni();
                Console.WriteLine($"Tägliche Abfrage um {HourOfDailyTasks} Uhr.");

                //Modem initialisieren
                Gsm.SmsSentEvent              += Gsm_SmsSentEvent;
                Gsm.SmsRecievedEvent          += Gsm_SmsRecievedEvent;
                Gsm.GsmStatusReceived         += Gsm_GsmStatusReceived;
                Gsm.SmsSentFaildEvent         += Gsm_SmsSentFaildEvent;
                Gsm.SerialPortDisposed        += Gsm_SerialPortDisposed;
                Gsm.StatusReportRecievedEvent += Gsm_StatusReportRecievedEvent;
                Gsm.ModemSetup();

                Tab_Log.Insert(Tab_Log.Topic.Startup, 3, "Programmstart");

#if DEBUG
                Gsm.Debug = 7;
                Console.WriteLine("Debug: Es wird keine Info-Email beim Programmstart versendet.");
#else
                Email.Send(new System.Net.Mail.MailAddressCollection()
                {
                    Email.Admin
                }, DateTime.Now.ToString("G") + " MelBox2 Programmstart", "Information von " + Environment.MachineName);
#endif
                Console.WriteLine("Prüfe Datenbank: " + (Sql.CheckDb() ? "ok" : "Fehler"));

                MelBoxWeb.Server.Start();
                SetHourTimer();

                #endregion

                bool run = true;

                while (run)
                {
                    string request = Console.ReadLine() ?? string.Empty;
                    run = ParseConsoleInput(request);
                }
            }
            finally
            {
                Console.WriteLine("Das Programm wird beendet.");
                Gsm.Ask_DeactivateCallForewarding();
                MelBoxWeb.Server.Stop();
                Gsm.DisConnect();
            }
        }
Exemplo n.º 2
0
        public static async Task CompanyUpdate(IHttpContext context)
        {
            Server.ReadCookies(context).TryGetValue("MelBoxId", out string guid);

            if (!Server.LogedInHash.TryGetValue(guid, out Contact user) || user.Accesslevel < Server.Level_Reciever)
            {
                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("address", out string address);
            payload.TryGetValue("city", out string city);
            #endregion

            Company where = new Company(0);

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

            Company set = new Company
            {
                Name    = name,
                Address = address,
                City    = city
            };

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

            string alert;

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

            await Server.PageAsync(context, "Firmeninformation ändern", alert);
        }
Exemplo n.º 3
0
        public static async Task CompanyCreate(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);
            payload.TryGetValue("name", out string name);
            payload.TryGetValue("address", out string address);
            payload.TryGetValue("city", out string city);

            Company set = new Company
            {
                Name    = name,
                Address = address,
                City    = city
            };
            #endregion

            bool success = MelBoxSql.Tab_Company.Insert(set);
            string alert;

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

            await Server.PageAsync(context, "Neue Firmeninformation erstellen", alert);
        }
Exemplo n.º 4
0
        public static async Task LoggingDelete(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;
            string html  = string.Empty;

            if (isAdmin)
            {
                var logDateStr = context.Request.PathParameters["logDate"];

                if (DateTime.TryParse(logDateStr, out DateTime logDate))
                {
                    logDate = logDate.AddDays(-1); //Den Tag selbst nicht mehr löschen

                    if (MelBoxSql.Tab_Log.Delete(logDate))
                    {
                        string text = $"Log-Einträge bis zum {logDate.ToShortDateString()} gelöscht durch [{user.Id}] >{user.Name}<.";
                        html = Html.Alert(2, "Log-Einträge gelöscht.", text);
                        Tab_Log.Insert(Tab_Log.Topic.Database, 2, text);
                    }
                    else
                    {
                        html = Html.Alert(3, "Keine Log-Einträge gelöscht.", "Keine passenden Einträge zum löschen gefunden.");
                    }
                }
            }

            System.Data.DataTable log = MelBoxSql.Tab_Log.SelectLast(Sql.MaxSelectedRows);
            string table = Html.FromTable(log);

            await Server.PageAsync(context, "Log", html + table);
        }
Exemplo n.º 5
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.º 6
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.º 7
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.º 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 string LastModemError = string.Empty; //Für Modem-Fehler nur einmal im Log aufzeichnen.
        #endregion

        private static void Gsm_GsmStatusReceived(object sender, GsmStatusArgs e)
        {
            if ((Gsm.Debug & (int)Gsm.DebugCategory.GsmStatus) > 0)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(e.Property + ":\t" + e.Value);
                Console.ForegroundColor = ConsoleColor.Gray;
            }

            switch (e.Property)
            {
            case Gsm.Modem.SignalQuality:
                MelBoxWeb.GsmStatus.SignalQuality = (int)e.Value;
                break;

            case Gsm.Modem.BitErrorRate:
                MelBoxWeb.GsmStatus.SignalErrorRate = (double)e.Value;
                break;

            case Gsm.Modem.OwnPhoneNumber:
                MelBoxWeb.GsmStatus.OwnNumber = e.Value.ToString();
                break;

            case Gsm.Modem.OwnName:
                MelBoxWeb.GsmStatus.OwnName = e.Value.ToString();
                break;

            case Gsm.Modem.ServiceCenterNumber:
                MelBoxWeb.GsmStatus.ServiceCenterNumber = e.Value.ToString();
                break;

            case Gsm.Modem.NetworkRegistration:
                MelBoxWeb.GsmStatus.NetworkRegistration = e.Value.ToString();
                if (e.Value.ToString() != "registriert")
                {
                    MelBoxSql.Tab_Log.Insert(Tab_Log.Topic.Gsm, 1, "Mobilfunknetz: " + e.Value);
                }
                break;

            case Gsm.Modem.ProviderName:
                MelBoxWeb.GsmStatus.ProviderName = e.Value.ToString();
                break;

            case Gsm.Modem.IncomingCall:
                string call = "Eingehender Sprachanruf von " + e.Value;
                MelBoxSql.Tab_Log.Insert(MelBoxSql.Tab_Log.Topic.Gsm, 2, call);
                Console.WriteLine(DateTime.Now + "\t" + call);
                break;

            case Gsm.Modem.RelayCallEnabled:
                if ((bool)e.Value)
                {
                    MelBoxWeb.GsmStatus.RelayNumber = Gsm.RelayCallsToPhone;
                    Tab_Log.Insert(Tab_Log.Topic.Gsm, 3, "Sprachanrufe werden umgeleitet an +" + Gsm.RelayCallsToPhone);
                }
                else
                {
                    Tab_Log.Insert(Tab_Log.Topic.Gsm, 1, "Keine Umleitung von Sprachanrufen an +" + Gsm.RelayCallsToPhone);
                    Gsm.Ask_RelayIncomingCalls(Gsm.RelayCallsToPhone);
                }
                break;

            case Gsm.Modem.PinStatus:
                MelBoxWeb.GsmStatus.PinStatus = e.Value.ToString();
                break;

            case Gsm.Modem.ModemError:
                MelBoxWeb.GsmStatus.LastError = DateTime.Now.ToString("G") + " - " + e.Value.ToString();

                if (LastModemError.Length == 0 || LastModemError != e.Value.ToString())
                {
                    Tab_Log.Insert(Tab_Log.Topic.Gsm, 2, "Fehler an Modem: " + e.Value);
                    LastModemError = e.Value.ToString();     //Fehler nur einmal im Log aufzeichnen.
                }
                break;

            case Gsm.Modem.SimSlot:
                if ((bool)e.Value)
                {
                    Console.WriteLine("SIM-Karte erkannt.");
                    Gsm.Ask_NetworkRegistration();
                }
                break;

            default:
                break;
            }
        }