Skip to content

Commit

Permalink
Changed the URL to a strict IP address, added validation logic to pre…
Browse files Browse the repository at this point in the history
…vent non valid characters from being added.
  • Loading branch information
Rockdocta committed Oct 6, 2022
1 parent cde0020 commit 6795edb
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 11 deletions.
12 changes: 7 additions & 5 deletions GatewayWatchdog/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
Expand All @@ -31,10 +32,10 @@
<TextBlock Margin="5">Current Result:</TextBlock>
<TextBlock Margin="5" Name="ResultTime">Time</TextBlock>
</StackPanel>
<TextBlock Grid.Column="1" Margin="5">Gateway URL:</TextBlock>
<TextBox Grid.Column="2" Margin="5" Name="UrlText" TextChanged="UrlText_TextChanged"
Text="http://192.168.12.1" HorizontalAlignment="Stretch"></TextBox>
<Button Grid.Column="3" Name="SetUrlBtn" Content="Set URL" Margin="5" Click="SetUrlBtn_Click" IsEnabled="False" />
<TextBlock Grid.Column="1" Margin="5">Gateway IP:</TextBlock>
<TextBox Grid.Column="2" Margin="5" Name="UrlText" TextChanged="UrlText_TextChanged" PreviewKeyDown="UrlText_PreviewKeyDown"
Text="192.168.12.1" HorizontalAlignment="Left" Width="100"></TextBox>
<Button Grid.Column="3" Name="SetUrlBtn" Content="Set URL" Width="50" HorizontalAlignment="Left" Margin="5" Click="SetUrlBtn_Click" IsEnabled="False" />
<StackPanel Orientation="Vertical" Grid.Row="1" Grid.RowSpan="4">
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Vertical">
Expand Down Expand Up @@ -83,7 +84,7 @@
<TextBlock FontWeight="Bold" Foreground="Blue" Margin="5" x:Name="PingResultText">34ms</TextBlock>
</StackPanel>
</StackPanel>
<Grid Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" Name="UserAdminGrid">
<Grid Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="4" Name="UserAdminGrid">
<Grid.DataContext>
<vm:MainViewModel />
</Grid.DataContext>
Expand All @@ -102,6 +103,7 @@
<Button Content="Show Raw Telemetry Data" Name="ShowTelemetryBtn" Margin="5" Padding="5" HorizontalAlignment="Center" VerticalAlignment="Center" Click="ShowTelemetryBtn_Click"/>
<Button Content="Show Raw Cell Data" Name="ShowCellBtn" Margin="5" Padding="5" HorizontalAlignment="Stretch" VerticalAlignment="Center" Click="ShowCellBtn_Click"/>
<Button Content="Show Raw Client Data" Name="ShowClientsBtn" Margin="5" Padding="5" HorizontalAlignment="Stretch" VerticalAlignment="Center" Click="ShowClientsBtn_Click"/>
<Button Content="Show Network Config" Name="ShowNetworkConfigBtn" Margin="5" Padding="5" HorizontalAlignment="Stretch" VerticalAlignment="Center" Click="ShowNetworkConfigBtn_Click"/>
<Button Content="Restart Gateway" Name="RestartGatewayBtn" Margin="5" Padding="5" HorizontalAlignment="Stretch" VerticalAlignment="Center" Click="RestartGatewayBtn_Click"/>
<Button Content="Enable Logging" Name="EnableLoggingBtn" Margin="5" Padding="5" HorizontalAlignment="Stretch" VerticalAlignment="Center" Click="EnableLoggingBtn_Click"/>
</StackPanel>
Expand Down
40 changes: 38 additions & 2 deletions GatewayWatchdog/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Threading;
using TMobileAPI;

Expand Down Expand Up @@ -72,7 +73,7 @@ public MainWindow()

queryWorker = new GatewayQueryWorker();
queryWorker.WorkerUpdate += QueryWorker_WorkerUpdate;
queryWorker.GatewayUrl = UrlText.Text;
queryWorker.GatewayUrl = "http://" + UrlText.Text;

pingWorker = new PingWorker();
pingWorker.PingCompleted += PingWorker_PingCompleted;
Expand Down Expand Up @@ -374,7 +375,7 @@ private void TabItem_GotFocus(object sender, RoutedEventArgs e)

private void SetUrlBtn_Click(object sender, RoutedEventArgs e)
{
queryWorker.GatewayUrl = UrlText.Text;
queryWorker.GatewayUrl = "http://" + UrlText.Text;
SetUrlBtn.IsEnabled = false;
}

Expand All @@ -383,6 +384,41 @@ private void UrlText_TextChanged(object sender, TextChangedEventArgs e)
if (SetUrlBtn != null)
SetUrlBtn.IsEnabled = true;
}

private void UrlText_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
if (!((e.Key >= Key.D0 && e.Key <= Key.D9) ||
(e.Key >= Key.NumPad0 && e.Key <= Key.NumPad9) ||
e.Key == Key.Decimal || e.Key == Key.OemPeriod || e.Key == Key.Back))
{
e.Handled = true;
}

if (UrlText.Text.Count(c => c == '.') >= 3 && (e.Key == Key.OemPeriod || e.Key == Key.Decimal))
{
e.Handled = true;
}
}

private async void ShowNetworkConfigBtn_Click(object sender, RoutedEventArgs e)
{
try
{
if (Session == null)
Authenticate();

if (Session != null)
{
var telemetryData = await _gatewayEngine.GetAccessPointData(_sessionInformation);
RawDataViewer rawDataViewer = new RawDataViewer(telemetryData);
rawDataViewer.ShowDialog();
}
}
catch (Exception exc)
{
MessageBox.Show("Error occurred: " + exc.Message);
}
}
}

}
31 changes: 27 additions & 4 deletions TMobileAPI/GatewayEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,20 @@ public async Task<Root> GetGatewayInformation(string gatewayUrl)
{
throw new Exception("Error occurred while retrieving data: " + result.StatusCode + ": " + result.Content.ReadAsStringAsync().Result);
}
return JsonConvert.DeserializeObject<Root>(await result.Content.ReadAsStringAsync());

var json = await result.Content.ReadAsStringAsync();
if (!json.Contains("\"manufacturer\": \"Arcadyan\""))
{
throw new Exception("Invalid source retrieved, check gateway IP address.");
}

return JsonConvert.DeserializeObject<Root>(await result.Content.ReadAsStringAsync());

}

private async Task<T> GetTelemetryData<T>(SessionInformation session)
{

var telemetryRequest = new HttpRequestMessage(HttpMethod.Get, $"{session.GatewayUrl}/TMI/v1/network/telemetry?get=all");
telemetryRequest.Headers.Add("Authorization", $"Bearer {session.Token}");

Expand All @@ -56,8 +63,24 @@ private async Task<T> GetTelemetryData<T>(SessionInformation session)

var telemetryResponse = await client.SendAsync(telemetryRequest);
var telemetryJson = await telemetryResponse.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<T>(telemetryJson);

return JsonConvert.DeserializeObject<T>(telemetryJson);

}
public async Task<string> GetAccessPointData(SessionInformation session)
{

var telemetryRequest = new HttpRequestMessage(HttpMethod.Get, $"{session.GatewayUrl}/TMI/v1/network/configuration?get=ap");
telemetryRequest.Headers.Add("Authorization", $"Bearer {session.Token}");

HttpClient client = new()
{
Timeout = TimeSpan.FromSeconds(5)
};

var telemetryResponse = await client.SendAsync(telemetryRequest);
var telemetryJson = await telemetryResponse.Content.ReadAsStringAsync();
return telemetryJson;

}


Expand Down

0 comments on commit 6795edb

Please sign in to comment.