diff --git a/SPHDecode/MainWindow.xaml b/SPHDecode/MainWindow.xaml
index 35f1d4a..65b6054 100644
--- a/SPHDecode/MainWindow.xaml
+++ b/SPHDecode/MainWindow.xaml
@@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SPHDecode"
mc:Ignorable="d"
- Title="SPHDecode" Height="145" Width="405">
+ Title="SPHDecode" Height="160" Width="405">
@@ -15,15 +15,25 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
diff --git a/SPHDecode/MainWindow.xaml.cs b/SPHDecode/MainWindow.xaml.cs
index 61e3a23..6882bda 100644
--- a/SPHDecode/MainWindow.xaml.cs
+++ b/SPHDecode/MainWindow.xaml.cs
@@ -14,5 +14,10 @@ public MainWindow()
{
InitializeComponent();
}
+
+ private void CheckBox_Checked(object sender, RoutedEventArgs e)
+ {
+
+ }
}
}
diff --git a/SPHDecode/Model/MainWindowModel.cs b/SPHDecode/Model/MainWindowModel.cs
index 51a5641..38cee42 100644
--- a/SPHDecode/Model/MainWindowModel.cs
+++ b/SPHDecode/Model/MainWindowModel.cs
@@ -3,6 +3,7 @@
using Microsoft.Win32;
using System.IO;
using System.Windows;
+using System.Xml;
namespace SPHDecode.Model
{
@@ -10,10 +11,15 @@ class MainWindowModel : SuperViewModel
{
private string _srcFile;
private string _dstFile;
+ private bool _telnet;
+ private string _username;
+ private string _password;
+ private string _config;
private DelegateCommand _srcFileDialog;
private DelegateCommand _dstFileDialog;
- private DelegateCommand _encrypt;
- private DelegateCommand _decrypt;
+ private DelegateCommand _loadConfig;
+ private DelegateCommand _saveConfig;
+
public string srcFile
{
@@ -27,6 +33,30 @@ public string dstFile
set { SetProperty(ref _dstFile, value); }
}
+ public bool telnet
+ {
+ get { return _telnet; }
+ set { SetProperty(ref _telnet, value); }
+ }
+
+ public string username
+ {
+ get { return _username; }
+ set { SetProperty(ref _username, value); }
+ }
+
+ public string password
+ {
+ get { return _password; }
+ set { SetProperty(ref _password, value); }
+ }
+
+ public string config
+ {
+ get { return _config; }
+ set { SetProperty(ref _config, value); }
+ }
+
public DelegateCommand srcFileDialog
{
get { return _srcFileDialog; }
@@ -39,16 +69,16 @@ public DelegateCommand dstFileDialog
set { SetProperty(ref _dstFileDialog, value); }
}
- public DelegateCommand encrypt
+ public DelegateCommand LoadConfig
{
- get { return _encrypt; }
- set { SetProperty(ref _encrypt, value); }
+ get { return _loadConfig; }
+ set { SetProperty(ref _loadConfig, value); }
}
- public DelegateCommand decrypt
+ public DelegateCommand SaveConfig
{
- get { return _decrypt; }
- set { SetProperty(ref _decrypt, value); }
+ get { return _saveConfig; }
+ set { SetProperty(ref _saveConfig, value); }
}
private void OnsrcFileDialogExecute()
@@ -69,31 +99,67 @@ private void OndstFileDialogExecute()
saveFileDialog = null;
}
- private void OnencryptExecute()
+ private void OnLoadConfigExecute()
{
- string orig = File.ReadAllText(srcFile);
- // remove BOM from utf-8 file
- orig = orig.Replace("\ufeff", "");
+ if (string.IsNullOrWhiteSpace(srcFile))
+ {
+ LogManager.WriteToLog("no input file specified");
+ MessageBox.Show("no input file specified", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error);
+ return;
+ }
+
+ byte[] orig = File.ReadAllBytes(srcFile);
+ config = Cryptography.Decrypt(orig);
- // replace windows with unix line endings
- orig = orig.Replace("\r\n", "\n").Replace("\r", "\n");
+ XmlDocument xmlDoc = new XmlDocument();
+ xmlDoc.LoadXml(config);
- byte[] encode = Cryptography.Encrypt(orig);
- if (Object.Equals(encode, null).Equals(false))
+ XmlNode node = xmlDoc.SelectSingleNode("/InternetGatewayDeviceConfig/Device/DeviceInfo/X_ServiceManage");
+ string tel = node.Attributes["TelnetEnable"]?.InnerText;
+
+ telnet = false;
+ if (tel.Equals("1"))
{
- File.WriteAllBytes(dstFile, encode);
- MessageBox.Show("config encrypted successfully", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information);
+ telnet = true;
}
+
+ node = xmlDoc.SelectSingleNode("/InternetGatewayDeviceConfig/Device/UserInterface/X_Cli/UserInfo").FirstChild;
+ username = node.Attributes["Username"]?.InnerText;
+ password = node.Attributes["Userpassword"]?.InnerText;
}
- private void OndecryptExecute()
+ private void OnSaveConfigExecute()
{
- byte[] orig = File.ReadAllBytes(srcFile);
- string decode = Cryptography.Decrypt(orig);
- if (string.IsNullOrWhiteSpace(decode).Equals(false))
+ if (string.IsNullOrWhiteSpace(dstFile))
+ {
+ LogManager.WriteToLog("no output file specified");
+ MessageBox.Show("no output file specified", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error);
+ return;
+ }
+
+ XmlDocument xmlDoc = new XmlDocument();
+ xmlDoc.LoadXml(config);
+
+ XmlNode node = xmlDoc.SelectSingleNode("/InternetGatewayDeviceConfig/Device/DeviceInfo/X_ServiceManage");
+ string tel = node.Attributes["TelnetEnable"]?.InnerText;
+
+ node = xmlDoc.SelectSingleNode("/InternetGatewayDeviceConfig/Device/UserInterface/X_Cli/UserInfo").FirstChild;
+ string user = node.Attributes["Username"]?.InnerText;
+ string pass = node.Attributes["Userpassword"]?.InnerText;
+
+ config = config.Replace(
+ string.Concat(""),
+ string.Concat(""));
+
+ config = config.Replace(
+ string.Concat(""),
+ string.Concat("") );
+
+ byte[] encode = Cryptography.Encrypt(config);
+ if (Object.Equals(encode, null).Equals(false))
{
- File.WriteAllText(dstFile, decode);
- MessageBox.Show("config decrypted successfully", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information);
+ File.WriteAllBytes(dstFile, encode);
+ MessageBox.Show("config encrypted successfully", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
@@ -101,8 +167,8 @@ public MainWindowModel()
{
srcFileDialog = new DelegateCommand(new Action(OnsrcFileDialogExecute));
dstFileDialog = new DelegateCommand(new Action(OndstFileDialogExecute));
- encrypt = new DelegateCommand(new Action(OnencryptExecute));
- decrypt = new DelegateCommand(new Action(OndecryptExecute));
+ LoadConfig = new DelegateCommand(new Action(OnLoadConfigExecute));
+ SaveConfig = new DelegateCommand(new Action(OnSaveConfigExecute));
}
}
}