/Program.cs
http://quick-fwknop-ssh-launcher.googlecode.com/ · C# · 124 lines · 106 code · 15 blank · 3 comment · 0 complexity · bec3ec092b03f4b2ffc2500effbf641b MD5 · raw file
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Diagnostics;
- namespace Quick_Knock
- {
- class Program
- {
- #region FWKNOP
- private static string fwPath;
- private static string fwBin;
- private static string fwSource;
- private static string fwDest;
- private static int fwPort;
- private static string fwProtocol;
- private static string fwUser;
- #endregion
- #region PuTTY
- private static string pPath;
- private static string pBin;
- private static string pKeyPath;
- private static string pRForward;
- private static string pLForward;
- private static string pUser;
- #endregion
- #region Launchers
- private static ProcessStartInfo fwStartInfo;
- private static ProcessStartInfo pStartInfo;
- #endregion
- static void Main(string[] args)
- {
- string configFile = "config.ini";
- Console.WriteLine("Quick Knock v.01 Alpha");
- LoadConfig(configFile);
- PrepareFWKNOP();
- PrepareSSH();
- Run();
- }
- private static void Run()
- {
- try
- {
- using (Process exeProcess = Process.Start(fwStartInfo))
- {
- exeProcess.WaitForExit();
- }
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- try
- {
- using (Process exeProcess = Process.Start(pStartInfo))
- {
- exeProcess.CloseMainWindow();
- }
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- private static void PrepareFWKNOP()
- {
- fwStartInfo = new ProcessStartInfo();
- fwStartInfo.CreateNoWindow = false;
- fwStartInfo.UseShellExecute = false;
- fwStartInfo.LoadUserProfile = true;
- fwStartInfo.WorkingDirectory = fwPath;
- fwStartInfo.FileName = fwBin;
- fwStartInfo.WindowStyle = ProcessWindowStyle.Normal;
- fwStartInfo.Arguments = "-A " + fwProtocol + "/" + fwPort.ToString() + " -a " + fwSource + " -D " + fwDest + " -R -U " + fwUser;
- }
- private static void PrepareSSH()
- {
- //Console.WriteLine("Please enter your SSH passphrase:");
- //pPassphrase = Console.ReadLine();
- // Use ProcessStartInfo class
- pStartInfo = new ProcessStartInfo();
- pStartInfo.CreateNoWindow = false;
- pStartInfo.UseShellExecute = false;
- pStartInfo.WorkingDirectory = pPath;
- pStartInfo.FileName = pBin;
- pStartInfo.WindowStyle = ProcessWindowStyle.Normal;
- pStartInfo.Arguments = "-ssh -2 -4 -C -i " + pKeyPath + " -P " + fwPort + " -R " + pRForward + " -L " + pLForward + " -l " + pUser + " " + fwDest;
- }
- private static void LoadConfig(string configFile)
- {
- IniFile myConfig = new IniFile(configFile);
- string fw = "fwknop";
- string p = "putty";
- fwPath = myConfig.GetValue(fw, "path");
- fwBin = myConfig.GetValue(fw, "bin");
- fwSource = myConfig.GetValue(fw, "source");
- fwDest = myConfig.GetValue(fw, "destination");
- int.TryParse(myConfig.GetValue(fw, "port"), out fwPort);
- fwProtocol = myConfig.GetValue(fw, "protocol");
- fwUser = myConfig.GetValue(fw, "user");
- pPath = myConfig.GetValue(p, "path");
- pBin = myConfig.GetValue(p, "bin");
- pKeyPath = myConfig.GetValue(p, "keypath");
- pRForward = myConfig.GetValue(p, "rforward");
- pLForward = myConfig.GetValue(p, "lforward");
- pUser = myConfig.GetValue(p, "user");
- }
- }
- }