add new syslog parser
authorStricted <info@stricted.net>
Thu, 1 Sep 2016 17:40:04 +0000 (19:40 +0200)
committerStricted <info@stricted.net>
Thu, 1 Sep 2016 17:40:04 +0000 (19:40 +0200)
add numeric textbox

SpeedportHybridControl.Implementations/NumberTextBox.cs [new file with mode: 0644]
SpeedportHybridControl.Implementations/SpeedportHybridControl.Implementations.csproj
SpeedportHybridControl/Data/SpeedportHybrid.cs
SpeedportHybridControl/Data/SpeedportHybridAPI.cs
SpeedportHybridControl/page/TR181Page.xaml

diff --git a/SpeedportHybridControl.Implementations/NumberTextBox.cs b/SpeedportHybridControl.Implementations/NumberTextBox.cs
new file mode 100644 (file)
index 0000000..013750e
--- /dev/null
@@ -0,0 +1,81 @@
+using System;
+using System.Windows;
+using System.Windows.Input;
+using System.Windows.Controls;
+
+namespace SpeedportHybridControl.Implementations
+{
+    // https://social.msdn.microsoft.com/Forums/vstudio/en-US/fb0745f0-6c26-4a9e-b792-3f7e8484b243/allow-only-number-in-textbox?forum=wpf#8acf76ea-7667-4763-a837-473ea2b03fa5
+    public class NumberTextBox : TextBox
+    {
+        static NumberTextBox()
+        {
+            EventManager.RegisterClassHandler(
+                typeof(NumberTextBox),
+                DataObject.PastingEvent,
+                (DataObjectPastingEventHandler)((sender, e) =>
+                {
+                    if (!IsDataValid(e.DataObject))
+                    {
+                        DataObject data = new DataObject();
+                        data.SetText(String.Empty);
+                        e.DataObject = data;
+                        e.Handled = false;
+                    }
+                }));
+        }
+
+        protected override void OnDrop(DragEventArgs e)
+        {
+            e.Handled = !IsDataValid(e.Data);
+            base.OnDrop(e);
+        }
+
+        protected override void OnDragOver(DragEventArgs e)
+        {
+            if (!IsDataValid(e.Data))
+            {
+                e.Handled = true;
+                e.Effects = DragDropEffects.None;
+            }
+
+            base.OnDragEnter(e);
+        }
+
+        private static Boolean IsDataValid(IDataObject data)
+        {
+            Boolean isValid = false;
+            if (data != null)
+            {
+                String text = data.GetData(DataFormats.Text) as String;
+                if (!String.IsNullOrEmpty(text == null ? null : text.Trim()))
+                {
+                    Int32 result = -1;
+                    if (Int32.TryParse(text, out result))
+                    {
+                        if (result > 0)
+                        {
+                            isValid = true;
+                        }
+                    }
+                }
+            }
+
+            return isValid;
+        }
+
+        protected override void OnKeyDown(KeyEventArgs e)
+        {
+            if (e.Key < Key.D0 || e.Key > Key.D9)
+            {
+                if (e.Key < Key.NumPad0 || e.Key > Key.NumPad9)
+                {
+                    if (e.Key != Key.Back)
+                    {
+                        e.Handled = true;
+                    }
+                }
+            }
+        }
+    }
+}
index ea9fc19a31cf4c52fe76cd82fecd8b1a0a35b888..263347a009a271af2dfda65eccdcba1accb5ff7c 100644 (file)
@@ -54,6 +54,7 @@
     <Compile Include="Cryptography.cs" />
     <Compile Include="DelegateCommand.cs" />
     <Compile Include="LogManager.cs" />
+    <Compile Include="NumberTextBox.cs" />
     <Compile Include="PasswordHelper.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Settings.cs" />
index 44da76f03e2bce0351faafbd022b83bdeaa9e661..540b47943ff485ad77fd097939da74cd5ac0a8b9 100644 (file)
@@ -448,7 +448,7 @@ namespace SpeedportHybridControl.Data
                 return;
 
             DslPageModel dsl = Application.Current.FindResource("DslPageModel") as DslPageModel;
-
+            
             string response = SpeedportHybridAPI.getInstance().sendEnryptedRequest("data/dsl.json");
             if (response.IsNullOrEmpty())
                 return;
@@ -671,90 +671,76 @@ namespace SpeedportHybridControl.Data
                     return;
 
                 SyslogPageModel syslog = Application.Current.FindResource("SyslogPageModel") as SyslogPageModel;
-
-                string response = SpeedportHybridAPI.getInstance().sendEnryptedRequest("data/SystemMessages.json");
+                string response = SpeedportHybridAPI.getInstance().sendEnryptedRequest("data/Syslog.json", string.Concat("csrf_token=",SpeedportHybridAPI.getInstance().getToken(), "&exporttype=0"));
                 if (response.IsNullOrEmpty())
                     return;
 
-                JToken jArray = JToken.Parse(response);
-                response = null;
-
+                string[] lines = response.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
                 List<SyslogList> syslogList = new List<SyslogList>();
-                foreach (JToken jToken in jArray)
+                foreach (string line in lines)
                 {
-                    JToken varid = jToken["varid"];
-                    if (varid.ToString().Equals("addmessage"))
-                    {
-                        var a = jToken["varvalue"];
-                        var stamp = a[1]["varvalue"];
-                        var msg = a[2]["varvalue"];
-
-                        // login
-                        if (msg.ToString().Contains("(G101)").Equals(true))
-                            continue;
+                    // first line / last line
+                    if ((line.Contains("Datum/Uhrzeit") && line.Contains("Meldung")) || line.IsNullOrEmpty())
+                        continue;
 
-                        // logout
-                        if (msg.ToString().Contains("(G102)").Equals(true))
-                            continue;
+                    // login
+                    if (line.Contains("(G101)").Equals(true))
+                        continue;
 
-                        // session timeout
-                        if (msg.ToString().Contains("(G103)").Equals(true))
-                            continue;
+                    // logout
+                    if (line.Contains("(G102)").Equals(true))
+                        continue;
 
-                        // dnsv6 error
-                        if (msg.ToString().Contains("(P008)").Equals(true))
-                            continue;
+                    // session timeout
+                    if (line.Contains("(G103)").Equals(true))
+                        continue;
 
-                        // Funkzellen Info
-                        if (msg.ToString().Contains("(LT004)") && isLTE.Equals(true))
-                        {
-                            LteInfoModel lte = Application.Current.FindResource("LteInfoModel") as LteInfoModel;
+                    // dnsv6 error
+                    if (line.Contains("(P008)").Equals(true))
+                        continue;
 
-                            string[] parts = msg.ToString().Split(',');
-                            string frequenz = parts[2];
+                    string[] parts;
 
-                            if (frequenz.Equals("20"))
-                            {
-                                frequenz = "800 MHz";
-                            }
-                            else if (frequenz.Equals("3"))
-                            {
-                                frequenz = "1800 MHz";
-                            }
-                            else if (frequenz.Equals("7"))
-                            {
-                                frequenz = "2600 MHz";
-                            }
+                    // Funkzellen Info
+                    if (line.Contains("(LT004)") && isLTE.Equals(true))
+                    {
+                        LteInfoModel lte = Application.Current.FindResource("LteInfoModel") as LteInfoModel;
 
-                            lte.frequenz = frequenz;
+                        parts = line.Split(',');
+                        string frequenz = parts[2];
 
-                            varid = null;
-                            jArray = null;
-                            a = null;
-                            stamp = null;
-                            msg = null;
-                            syslogList = null;
-                            return;
+                        if (frequenz.Equals("20"))
+                        {
+                            frequenz = "800 MHz";
+                        }
+                        else if (frequenz.Equals("3"))
+                        {
+                            frequenz = "1800 MHz";
+                        }
+                        else if (frequenz.Equals("7"))
+                        {
+                            frequenz = "2600 MHz";
                         }
 
-                        syslogList.Add(new SyslogList() { timestamp = stamp.ToString(), message = msg.ToString() });
+                        lte.frequenz = frequenz;
 
-                        a = null;
-                        stamp = null;
-                        msg = null;
+                        syslogList = null;
+                        return;
                     }
-                    varid = null;
+
+                    parts = line.Split(new string[] { " " }, 3, StringSplitOptions.None);
+                    syslogList.Add(new SyslogList() { timestamp = string.Concat(parts[0], " ", parts[1]), message = parts[2] });
                 }
 
                 syslog.syslogList = syslogList;
                 syslogList = null;
-                jArray = null;
 
                 DateTime time = DateTime.Now;
                 string format = "dd.MM.yyyy HH:mm:ss";
                 syslog.datetime = time.ToString(format);
 
                 syslog = null;
+                
             }
             catch (Exception ex)
             {
index 2dcfe37a549327c1adb036769abdd926988f3b6c..afeed3a0c5ffbe20d3a444226ac1b6308fe82671 100644 (file)
@@ -141,19 +141,13 @@ namespace SpeedportHybridControl.Data
                 JToken jArray = JToken.Parse(response);
                 if (jArray.getVar("status").Equals("ok"))
                 {
-                    if (isLoggedin().Equals(true))
-                    {
-                        logout = false;
-                    }
-                    else {
-                        logout = true;
-                        _password = "";
-                        _challenge = "";
-                        _cookie = new CookieContainer();
-                        _lastReboot = DateTime.MinValue;
-                        _hash = "";
-                        _derivedk = "";
-                    }
+                    logout = true;
+                    _password = "";
+                    _challenge = "";
+                    _cookie = new CookieContainer();
+                    _lastReboot = DateTime.MinValue;
+                    _hash = "";
+                    _derivedk = "";
                 }
 
                 jArray = null;
@@ -223,7 +217,7 @@ namespace SpeedportHybridControl.Data
                 */
         public bool isLoggedin()
         {
-            string response = sendRequest("data/SecureStatus.json");
+            string response = sendRequest("data/heartbeat.json");
             if (response.IsNullOrEmpty())
                 return false;
 
@@ -232,7 +226,7 @@ namespace SpeedportHybridControl.Data
             {
                 JToken jArray = JToken.Parse(response);
 
-                if (jArray.getVar("loginstate").Equals("1")/* && jArray.getVar("login").Equals("true")*/)
+                if (jArray.getVar("loginstate").Equals("1"))
                 {
                     login = true;
                 }
index 9aa2e7eb231764a10e76a689074076fcf9088add..7377bbbdbcc82ff4df26abb55ec73dbfdf57c06f 100644 (file)
@@ -4,6 +4,7 @@
       xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
       xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
       xmlns:local="clr-namespace:SpeedportHybridControl"
+      xmlns:Implementations="clr-namespace:SpeedportHybridControl.Implementations;assembly=SpeedportHybridControl.Implementations"
       mc:Ignorable="d"
       Width="Auto" Height="Auto"
       Title="TR181Page">
@@ -52,7 +53,7 @@
         <GroupBox Header="Einstellungen" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="335,0,0,0" Height="76">
             <Grid>
                 <TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="QueueSkbTimeOut:" VerticalAlignment="Top" Margin="0,3,0,0"/>
-                <TextBox x:Name="tbQueue" HorizontalAlignment="Left" Margin="115,2,0,0" TextWrapping="Wrap" Text="{Binding QueueSkbTimeOut}" VerticalAlignment="Top" Width="42" />
+                <Implementations:NumberTextBox x:Name="tbQueue" HorizontalAlignment="Left" Margin="115,2,0,0" TextWrapping="Wrap" Text="{Binding QueueSkbTimeOut}" VerticalAlignment="Top" Width="42" />
                 <Button Command="{Binding Path=SaveCommand}" x:Name="btnSave" Content="Speichern" HorizontalAlignment="Left" Margin="44,34,0,0" VerticalAlignment="Top" Width="75" />
             </Grid>
         </GroupBox>