public void Dispose() { Connection?.Dispose(); Connection = null; Tunnel?.Dispose(); Tunnel = null; }
/// <summary> /// Creates dialog for viewing existing connection /// </summary> public frmConnection(Universe universe, Server server, Database database) : this(universe) { this.server = server; this.database = database; this.sshTunnel = server.Ssh; viewMode = true; }
public MySqlContext(MySqlArguments dbInfo) { var connectionString = dbInfo.ConnectionString; if (!string.IsNullOrEmpty(dbInfo.SshHost)) { var ci = new ConnectionInfo(dbInfo.SshHost, dbInfo.SshUserName, new PasswordAuthenticationMethod(dbInfo.SshUserName, dbInfo.SshPassword)); Tunnel = new SshTunnel(ci, dbInfo.SshPort); connectionString += dbInfo.ConnectionString + ";port=" + Tunnel.LocalPort.ToString(); } Connection = new MySqlConnection(connectionString); }
private void frmConnection_Load(object sender, EventArgs e) { ResetConnectionStatuses(); if (viewMode) { if (sshTunnel == null) { sshTunnel = new SshTunnel(); } cmbHost.Enabled = nudPort.Enabled = txtUser.Enabled = txtPassword.Enabled = chkShowDBPass.Enabled = cmbDatabase.Enabled = chkUseSsh.Enabled = cmbSshHost.Enabled = nudSshPort.Enabled = txtSshUser.Enabled = txtSshPassword.Enabled = chkShowSshPass.Enabled = chkSshKey.Enabled = txtSshKey.Enabled = btnShhKey.Enabled = false; chkUseSsh.Checked = server.Ssh != null; } else { database = new Database(); server = new Server(); sshTunnel = new SshTunnel(); server.Databases.Add(database); } // autocomplite for ComboBoxes foreach (var s in universe.Servers) { cmbHost.Items.Add(s.Address); } foreach (var s in universe.Servers) { if (s.Ssh != null) { cmbSshHost.Items.Add(s.Ssh.Server); } } // bind controls to domain objects Binding b; List <Binding> bindings = new List <Binding>(); b = cmbHost.DataBindings.Add( PropertyName((ComboBox c) => c.Text), server, PropertyName((Server c) => c.Address), false, DataSourceUpdateMode.OnValidation); bindings.Add(b); b = nudPort.DataBindings.Add( PropertyName((NumericUpDown c) => c.Value), server, PropertyName((Server c) => c.Port), false, DataSourceUpdateMode.OnValidation); bindings.Add(b); b = txtUser.DataBindings.Add( PropertyName((TextBox c) => c.Text), database, PropertyName((Database c) => c.User), false, DataSourceUpdateMode.OnValidation); bindings.Add(b); b = txtPassword.DataBindings.Add( PropertyName((TextBox c) => c.Text), database, PropertyName((Database c) => c.Password), false, DataSourceUpdateMode.OnValidation); bindings.Add(b); b = cmbDatabase.DataBindings.Add( PropertyName((ComboBox c) => c.Text), database, PropertyName((Database c) => c.Name), false, DataSourceUpdateMode.OnValidation); bindings.Add(b); b = cmbSshHost.DataBindings.Add( PropertyName((ComboBox c) => c.Text), sshTunnel, PropertyName((SshTunnel c) => c.Server), false, DataSourceUpdateMode.OnValidation); bindings.Add(b); b = nudSshPort.DataBindings.Add( PropertyName((NumericUpDown c) => c.Value), sshTunnel, PropertyName((SshTunnel c) => c.Port), false, DataSourceUpdateMode.OnValidation); bindings.Add(b); b = txtSshUser.DataBindings.Add( PropertyName((TextBox c) => c.Text), sshTunnel, PropertyName((SshTunnel c) => c.User), false, DataSourceUpdateMode.OnValidation); bindings.Add(b); b = txtSshPassword.DataBindings.Add( PropertyName((TextBox c) => c.Text), sshTunnel, PropertyName((SshTunnel c) => c.Password), false, DataSourceUpdateMode.OnValidation); bindings.Add(b); b = txtSshKey.DataBindings.Add( PropertyName((TextBox c) => c.Text), sshTunnel, PropertyName((SshTunnel c) => c.KeyFilePath), false, DataSourceUpdateMode.OnValidation); bindings.Add(b); foreach (Binding binding in bindings) { binding.Format += binding_Parse; } }
private void Button1_Click(object sender, EventArgs e) { Global chilkatGlob = new Global(); var success = chilkatGlob.UnlockBundle("Anything for 30-day trial."); if (!success) { MessageBox.Show("Must active Chilkat"); } int port = 22; string hostname = txtIP.Text; string user = txtAcc.Text; string pass = txtPass.Text; SshTunnel tunel = new SshTunnel(); if (tunel.Connect(hostname, port)) { if (tunel.AuthenticatePw(user, pass)) { tunel.DynamicPortForwarding = true; if (tunel.BeginAccepting(1080)) { //Http http = new Http(); //http.SocksHostname = "localhost"; //http.SocksPort = 1080; //http.SocksVersion = 5; //http.SendCookies = true; //http.SaveCookies = true; //http.CookieDir = "memory"; //var res = http.QuickGet("https://api.myip.com/"); //MessageBox.Show(Encoding.UTF8.GetString(res)); FlurlClient client = new FlurlClient(); //client.Configure(setting => setting.HttpClientFactory = new ProxyHttpClientFactory("127.0.0.1", 1080)); var res = client.Configure(x => x.HttpClientFactory = new ProxyHttpClientFactory("127.0.0.1", 1080)) .Request("https://api.myip.com/").GetStringAsync().Result; MessageBox.Show(res); tunel.StopAccepting(true); tunel.CloseTunnel(true); } else { MessageBox.Show("Not accept port 8081"); } } else { MessageBox.Show("Wrong username or password."); } } else { MessageBox.Show("Could not connect to " + hostname); } }
static int Main(string[] args) { string cofigPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), SettingsFile.ConfigurationDirectory); DirectoryInfo configDirectory = new DirectoryInfo(cofigPath); if (!configDirectory.Exists) { configDirectory.Create(); } Log.Initialize(false); for (int i = 0; i < 2000; i++) { FileInfo fi = new FileInfo(Path.Combine(cofigPath, $"GitProxy-{i}.log")); try { Log.OpenFile(fi.FullName, "default", LogLevel.Debug, true); break; } catch (Exception) { // Ignore } } Log.Console.Enabled = true; Log.Console.AutoColorOutput = true; string settingsFilename = Path.Combine(cofigPath, SettingsFile.DefaultSettingsFilename); SettingsFile settings; if (!File.Exists(settingsFilename)) { settings = new SettingsFile(); settings.SaveToFile(settingsFilename); } else { settings = SettingsFile.LoadFromDisk(settingsFilename); } Log.Console.MinimumLevel = settings.VerboseMode ? LogLevel.Debug : LogLevel.Message; Log.Write("GitProxy> ", LogLevel.Debug); Log.Write(settings.GitExecutablePath, LogLevel.Debug); Log.Write(" ", LogLevel.Debug); List <string> gitArguments = new List <string>(args); if (settings.GitExtraArguments != null && settings.GitExtraArguments.Length > 0) { gitArguments.AddRange(settings.GitExtraArguments); } foreach (string a in gitArguments) { Log.Write(a + " ", LogLevel.Debug); } Log.WriteLine(LogLevel.Debug); SshTunnel tunnel = null; GitSession session = null; int remoteExitCode = 255; string errorOutput = null; string output = null; try { Log.WriteLine("Opening SSH tunnel to %@:%@ using username=%@. Credentials: %@ %@", LogLevel.Debug, settings.SshHostname, settings.SshPort, settings.SshUsername, !string.IsNullOrWhiteSpace(settings.SshPassword) ? "(Password)" : "", !string.IsNullOrWhiteSpace(settings.SshKeyFile) ? "(PublicKey)" : "" ); tunnel = SshTunnel.Open(settings.SshHostname, new Tunnels.Credentials.SshCredentials(settings.SshUsername, settings.SshPassword, settings.SshKeyFile), settings.SshPort); if (!tunnel.IsOpen) { Log.WriteLine("Failed to open tunnel to remote host %@ on port %@.", LogLevel.Error, settings.SshHostname, settings.SshPort); return(1); } session = tunnel.OpenGitSession(new GitSessionParameters() { Arguments = gitArguments.ToArray(), ExecutablePath = settings.GitExecutablePath, WorkingDirectory = MapDirectory(settings.DirectoryMappings, Directory.GetCurrentDirectory()) }); Log.WriteLine("Remote GIT Session opened", LogLevel.Debug); Log.WriteLine("Waiting for StdOut...", LogLevel.Debug); output = session.ReadToEnd(); errorOutput = session.StdError; remoteExitCode = session.GetExitCode(); Log.WriteLine("Remote process exited with code %@", LogLevel.Debug, session.GetExitCode().ToString("N0")); } catch (Exception ex) { Log.WriteException(ex, LogLevel.Error); Log.WriteLine(); return(255); } if (session != null && !session.IsDisposed) { Log.WriteLine("Closing remote GIT session...", LogLevel.Debug); session.Dispose(); } if (tunnel != null && tunnel.IsOpen) { Log.WriteLine("Closing SSH tunnel...", LogLevel.Debug); tunnel.Close(); } Log.WriteLine(); if (!string.IsNullOrWhiteSpace(errorOutput)) { Log.WriteLine(errorOutput, LogLevel.Error); } Log.Shutdown(); Console.Write(output); return(remoteExitCode); }