Пример #1
0
        //終了のハンドリング 非同期に別スレッドから呼ばれるので注意
        public void ConnectionClosed(ISSHConnection connection)
        {
            IDictionaryEnumerator e = _profileToConnection.GetEnumerator();

            while (e.MoveNext())
            {
                if (connection == e.Value)
                {
                    ChannelProfile prof = (ChannelProfile)e.Key;
                    _profileToConnection.Remove(e.Key);
                    bool manual = false;
                    lock (this) {
                        manual = _manualClosingConnections.Contains(connection);
                        if (manual)
                        {
                            _manualClosingConnections.Remove(connection);
                        }
                    }

                    if (!manual)
                    {
                        Util.InterThreadWarning(Env.Strings.GetString("Message.ConnectionManager.Disconnected"));
                    }

                    Env.MainForm.Invoke(new RefreshProfileStatusDelegate(Env.MainForm.RefreshProfileStatus), prof);

                    break;
                }
            }
        }
Пример #2
0
        public void RefreshProfileStatus(ChannelProfile prof)
        {
            ListViewItem li = FindItem(prof);

            Debug.Assert(li != null);
            li.SubItems[6].Text = Util.GetProfileStatusString(prof);
        }
Пример #3
0
        public void Load(ConfigNode parent)
        {
            ConfigNode n = parent.FindChildConfigNode("profiles");

            if (n != null)
            {
                foreach (ConfigNode ch in n.Children)
                {
                    ChannelProfile p = null;
                    if (ch.Name == "local-to-remote")
                    {
                        p = new LocalToRemoteChannelProfile();
                    }
                    else if (ch.Name == "remote-to-local")
                    {
                        p = new RemoteToLocalChannelProfile();
                    }
                    else
                    {
                        throw new FormatException(ch.Name + " is invalid channel profile name.");
                    }

                    p.Import(ch);
                    _data.Add(p);
                }
            }
        }
Пример #4
0
        //profに対応したSSHConnectionを返す。接続がなければparentを親に認証ダイアログを出して認証する
        public ISSHConnection GetOrCreateConnection(ChannelProfile prof, Form parent)
        {
            //ホスト名とアカウントのペアからコネクションを共有する仕組みがあるとよいかも
            ISSHConnection c = _profileToConnection[prof] as ISSHConnection;

            if (c != null)
            {
                return(c);
            }

            SSHShortcutLoginDialog dlg = new SSHShortcutLoginDialog(prof);

            if (dlg.ShowDialog(parent) == DialogResult.OK)
            {
                c = dlg.Result.Connection;
                try {
                    dlg.Result.WaitRequest();
                }
                catch (Exception ex) {
                    Debug.WriteLine(ex.StackTrace);
                    Util.Warning(parent, ex.Message);
                    c.Close();
                    return(null);
                }
                _profileToConnection[prof] = c;
                Env.MainForm.RefreshProfileStatus(prof);
            }

            return(c);
        }
Пример #5
0
        public void LogConnectionClosed(ChannelProfile prof, int id)
        {
            string t = String.Format("{0} {1} connection closed; id={2}", DateTime.Now.ToString(), prof.ProtocolType.ToString(), id);

            _strm.WriteLine(t);
            _strm.Flush();
        }
Пример #6
0
        public void LogConnectionClosed(ChannelProfile prof, int id)
        {
            string t = String.Format("{0} {1} connection closed; id={2}", DateTime.Now.ToString(), prof.ProtocolType.ToString(), id);

            _strm.WriteLine(t);
            _strm.Flush();
        }
Пример #7
0
 public void RemoveProfile(ChannelProfile prof) {
     if (Env.Connections.IsConnected(prof)) {
         Util.Warning(Env.MainForm, Env.Strings.GetString("Message.Commands.CannotDeleteConnectedProfile"));
         return;
     }
     Env.Profiles.RemoveProfile(prof);
     Env.MainForm.RefreshAllProfiles();
 }
Пример #8
0
 public void MoveProfileDown(ChannelProfile prof) {
     int index = Env.Profiles.IndexOf(prof);
     if (index < Env.Profiles.Count - 1) {
         Env.Profiles.RemoveProfile(prof);
         Env.Profiles.InsertAt(index + 1, prof);
         Env.MainForm.RefreshAllProfiles();
         Env.MainForm.SetSelectedIndex(index + 1);
     }
 }
Пример #9
0
 public void MoveProfileUp(ChannelProfile prof) {
     int index = Env.Profiles.IndexOf(prof);
     if (index > 0) {
         Env.Profiles.RemoveProfile(prof);
         Env.Profiles.InsertAt(index - 1, prof);
         Env.MainForm.RefreshAllProfiles();
         Env.MainForm.SetSelectedIndex(index - 1);
     }
 }
Пример #10
0
 public static SocketWithTimeout StartNewConnection(ISocketWithTimeoutClient client, ChannelProfile prof, string password, HostKeyCheckCallback keycheck) {
     SocketWithTimeout swt;
     swt = new SSHConnector(prof, password, keycheck);
     /*
     if (Env.Options.UseSocks)
         swt.AsyncConnect(client, CreateSocksParam(prof.SSHHost, prof.SSHPort));
     else*/
     swt.AsyncConnect(client, prof.SSHHost, prof.SSHPort);
     return swt;
 }
Пример #11
0
 public void RemoveProfile(ChannelProfile prof)
 {
     if (Env.Connections.IsConnected(prof))
     {
         Util.Warning(Env.MainForm, Env.Strings.GetString("Message.Commands.CannotDeleteConnectedProfile"));
         return;
     }
     Env.Profiles.RemoveProfile(prof);
     Env.MainForm.RefreshAllProfiles();
 }
Пример #12
0
        public void LogConnectionOpened(ChannelProfile prof, int id) {
            string t = String.Format("{0} {1} connection opened; id={2}", DateTime.Now.ToString(), prof.ProtocolType.ToString(), id);
            if (prof is LocalToRemoteChannelProfile)
                t = String.Format("{0}; from=localhost:{1}; to={2}:{3}", t, prof.ListenPort, prof.DestinationHost, prof.DestinationPort);
            else
                t = String.Format("{0}; from={1}:{2}; to={3}:{4}", t, prof.SSHHost, prof.ListenPort, prof.DestinationHost, prof.DestinationPort);

            _strm.WriteLine(t);
            _strm.Flush();
        }
Пример #13
0
 public static IPAddress ChannelProfileToListeningAddress(ChannelProfile prof)
 {
     if (prof.UseIPv6)
     {
         return(prof.AllowsForeignConnection ? IPAddress.IPv6Any : IPAddress.IPv6Loopback);
     }
     else
     {
         return(prof.AllowsForeignConnection ? IPAddress.Any : IPAddress.Loopback);
     }
 }
Пример #14
0
        private void OnListViewDoubleClicked(object sender, EventArgs args)
        {
            ChannelProfile prof = GetSelectedProfile();

            if (prof == null)
            {
                return;
            }

            Env.Commands.ConnectProfile(prof);
        }
Пример #15
0
 private ListViewItem FindItem(ChannelProfile prof)
 {
     foreach (ListViewItem li in _list.Items)
     {
         if (li.Tag == prof)
         {
             return(li);
         }
     }
     return(null);
 }
Пример #16
0
 public static string GetProfileTypeString(ChannelProfile prof)
 {
     if (prof is LocalToRemoteChannelProfile)
     {
         return(Env.Strings.GetString("Caption.Util.Local"));
     }
     else
     {
         return(Env.Strings.GetString("Caption.Util.Remote"));
     }
 }
Пример #17
0
        public void EditProfile(ChannelProfile prof) {
            if (Env.Connections.IsConnected(prof)) {
                Util.Warning(Env.MainForm, Env.Strings.GetString("Message.Commands.CannotEditConnectedProfile"));
                return;
            }

            ProfileEdit dlg = new ProfileEdit(prof);
            if (dlg.ShowDialog(Env.MainForm) == DialogResult.OK) {
                Env.Profiles.ReplaceProfile(prof, dlg.ResultProfile);
                Env.MainForm.RefreshAllProfiles();
            }
        }
Пример #18
0
        /*
        private static Socks CreateSocksParam(string dest_host, int dest_port) {
            Socks s = new Socks();
            s.DestName = dest_host;
            s.DestPort = (short)dest_port;
            s.Account = Env.Options.SocksAccount;
            s.Password = Env.Options.SocksPassword;
            s.ServerName = Env.Options.SocksServer;
            s.ServerPort = (short)Env.Options.SocksPort;
            s.ExcludingNetworks = Env.Options.SocksNANetworks;
            return s;
        }
        */
        public void ManualClose(ChannelProfile prof) {
            if (!IsConnected(prof)) {
                Debug.WriteLine("ManualClose - Not connected");
                return;
            }

            lock (this) {
                SSHConnection c = (SSHConnection)_profileToConnection[prof];
                _manualClosingConnections.Add(c);
                c.Disconnect("");
            }
        }
Пример #19
0
        private void OnListViewMouseUp(object sender, MouseEventArgs args)
        {
            ChannelProfile prof = GetSelectedProfile();

            if (args.Button != MouseButtons.Right || prof == null)
            {
                return;
            }

            AdjustMenu(_listViewContextMenu.Items, prof);
            _listViewContextMenu.Show(this, new Point(args.X, args.Y));
        }
Пример #20
0
        public ProfileEdit(ChannelProfile prof) {
            //
            // Windows フォーム デザイナ サポートに必要です。
            //
            InitializeComponent();
            InitializeText();

            //
            // TODO: InitializeComponent 呼び出しの後に、コンストラクタ コードを追加してください。
            //
            InitUI(prof);
        }
Пример #21
0
        public void MoveProfileDown(ChannelProfile prof)
        {
            int index = Env.Profiles.IndexOf(prof);

            if (index < Env.Profiles.Count - 1)
            {
                Env.Profiles.RemoveProfile(prof);
                Env.Profiles.InsertAt(index + 1, prof);
                Env.MainForm.RefreshAllProfiles();
                Env.MainForm.SetSelectedIndex(index + 1);
            }
        }
Пример #22
0
        public void MoveProfileUp(ChannelProfile prof)
        {
            int index = Env.Profiles.IndexOf(prof);

            if (index > 0)
            {
                Env.Profiles.RemoveProfile(prof);
                Env.Profiles.InsertAt(index - 1, prof);
                Env.MainForm.RefreshAllProfiles();
                Env.MainForm.SetSelectedIndex(index - 1);
            }
        }
Пример #23
0
        public ProfileEdit(ChannelProfile prof)
        {
            //
            // Windows �t�H�[�� �f�U�C�i �T�|�[�g�ɕK�v�ł��B
            //
            InitializeComponent();
            InitializeText();

            //
            // TODO: InitializeComponent �Ăяo���̌�ɁA�R���X�g���N�^ �R�[�h��lj����Ă��������B
            //
            InitUI(prof);
        }
Пример #24
0
        public ProfileEdit(ChannelProfile prof)
        {
            //
            // Windows フォーム デザイナ サポートに必要です。
            //
            InitializeComponent();
            InitializeText();

            //
            // TODO: InitializeComponent 呼び出しの後に、コンストラクタ コードを追加してください。
            //
            InitUI(prof);
        }
Пример #25
0
        public SSHShortcutLoginDialog(ChannelProfile profile) {
            //
            // Windows フォーム デザイナ サポートに必要です。
            //
            InitializeComponent();
            InitializeText();

            //
            // TODO: InitializeComponent 呼び出しの後に、コンストラクタ コードを追加してください。
            //
            _profile = profile;
            InitUI();
        }
Пример #26
0
        /*
         * private static Socks CreateSocksParam(string dest_host, int dest_port) {
         *  Socks s = new Socks();
         *  s.DestName = dest_host;
         *  s.DestPort = (short)dest_port;
         *  s.Account = Env.Options.SocksAccount;
         *  s.Password = Env.Options.SocksPassword;
         *  s.ServerName = Env.Options.SocksServer;
         *  s.ServerPort = (short)Env.Options.SocksPort;
         *  s.ExcludingNetworks = Env.Options.SocksNANetworks;
         *  return s;
         * }
         */
        public void ManualClose(ChannelProfile prof)
        {
            if (!IsConnected(prof))
            {
                Debug.WriteLine("ManualClose - Not connected");
                return;
            }

            lock (this) {
                ISSHConnection c = (ISSHConnection)_profileToConnection[prof];
                _manualClosingConnections.Add(c);
                c.Disconnect(DisconnectionReasonCode.ByApplication, "close by application");
            }
        }
Пример #27
0
        //コンテキストメニューと双方で使用する
        private void AdjustMenu(ToolStripItemCollection items, ChannelProfile prof)
        {
            bool connected = prof != null && Env.Connections.IsConnected(prof);

            ConvertMenuItem(items, _menuProfileConnect).Enabled    = prof != null && !connected;
            ConvertMenuItem(items, _menuProfileDisconnect).Enabled = prof != null && connected;
            ConvertMenuItem(items, _menuProfileRemove).Enabled     = prof != null && !connected;
            ConvertMenuItem(items, _menuProfileProperty).Enabled   = prof != null && !connected;

            int index = prof == null ? -1 : Env.Profiles.IndexOf(prof);

            ConvertMenuItem(items, _menuProfileUp).Enabled   = prof != null && index > 0;
            ConvertMenuItem(items, _menuProfileDown).Enabled = prof != null && index < Env.Profiles.Count - 1;
        }
Пример #28
0
        /*
         * private static Socks CreateSocksParam(string dest_host, int dest_port) {
         *  Socks s = new Socks();
         *  s.DestName = dest_host;
         *  s.DestPort = (short)dest_port;
         *  s.Account = Env.Options.SocksAccount;
         *  s.Password = Env.Options.SocksPassword;
         *  s.ServerName = Env.Options.SocksServer;
         *  s.ServerPort = (short)Env.Options.SocksPort;
         *  s.ExcludingNetworks = Env.Options.SocksNANetworks;
         *  return s;
         * }
         */
        public void ManualClose(ChannelProfile prof)
        {
            if (!IsConnected(prof))
            {
                Debug.WriteLine("ManualClose - Not connected");
                return;
            }

            lock (this) {
                SSHConnection c = (SSHConnection)_profileToConnection[prof];
                _manualClosingConnections.Add(c);
                c.Disconnect("");
            }
        }
Пример #29
0
        public SSHShortcutLoginDialog(ChannelProfile profile)
        {
            //
            // Windows フォーム デザイナ サポートに必要です。
            //
            InitializeComponent();
            InitializeText();

            //
            // TODO: InitializeComponent 呼び出しの後に、コンストラクタ コードを追加してください。
            //
            _profile = profile;
            InitUI();
        }
Пример #30
0
        public SSHShortcutLoginDialog(ChannelProfile profile)
        {
            //
            // Windows �t�H�[�� �f�U�C�i �T�|�[�g�ɕK�v�ł��B
            //
            InitializeComponent();
            InitializeText();

            //
            // TODO: InitializeComponent �Ăяo���̌�ɁA�R���X�g���N�^ �R�[�h��lj����Ă��������B
            //
            _profile = profile;
            InitUI();
        }
Пример #31
0
        public void LogConnectionOpened(ChannelProfile prof, int id)
        {
            string t = String.Format("{0} {1} connection opened; id={2}", DateTime.Now.ToString(), prof.ProtocolType.ToString(), id);

            if (prof is LocalToRemoteChannelProfile)
            {
                t = String.Format("{0}; from=localhost:{1}; to={2}:{3}", t, prof.ListenPort, prof.DestinationHost, prof.DestinationPort);
            }
            else
            {
                t = String.Format("{0}; from={1}:{2}; to={3}:{4}", t, prof.SSHHost, prof.ListenPort, prof.DestinationHost, prof.DestinationPort);
            }

            _strm.WriteLine(t);
            _strm.Flush();
        }
Пример #32
0
        public void EditProfile(ChannelProfile prof)
        {
            if (Env.Connections.IsConnected(prof))
            {
                Util.Warning(Env.MainForm, Env.Strings.GetString("Message.Commands.CannotEditConnectedProfile"));
                return;
            }

            ProfileEdit dlg = new ProfileEdit(prof);

            if (dlg.ShowDialog(Env.MainForm) == DialogResult.OK)
            {
                Env.Profiles.ReplaceProfile(prof, dlg.ResultProfile);
                Env.MainForm.RefreshAllProfiles();
            }
        }
Пример #33
0
 public static ChannelFactory Create(ChannelProfile prof)
 {
     /*
      * if(prof.ProtocolType==ProtocolType.Udp)
      *  return new UdpChannelFactory(prof);
      * else
      */
     if (prof is LocalToRemoteChannelProfile)
     {
         return(new LocalToRemoteChannelFactory((LocalToRemoteChannelProfile)prof));
     }
     else
     {
         return(new RemoteToLocalChannelFactory((RemoteToLocalChannelProfile)prof));
     }
 }
Пример #34
0
        //profに対応したSSHConnectionを返す。接続がなければparentを親に認証ダイアログを出して認証する
        public SSHConnection GetOrCreateConnection(ChannelProfile prof, Form parent) {
            //ホスト名とアカウントのペアからコネクションを共有する仕組みがあるとよいかも
            SSHConnection c = (SSHConnection)_profileToConnection[prof];
            if (c != null)
                return c;

            SSHShortcutLoginDialog dlg = new SSHShortcutLoginDialog(prof);
            DialogResult result = DialogResult.No;

            //認証設定がない場合はそのまま接続
            if (!prof.Auth)
            {
                // 疑似的にOKボタン押下
                dlg.OnOK(null, EventArgs.Empty);
                // 非同期で接続が行われるので1秒待つ
                System.Threading.Thread.Sleep(1000);
                result = DialogResult.OK;
            }
            // 認証が必要な場合
            else
            {
                // ダイアログによるユーザ認証
                result = dlg.ShowDialog(parent);
            }

            if (result == DialogResult.OK)
            {
                c = dlg.Result.Connection;
                try
                {
                    dlg.Result.WaitRequest();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.StackTrace);
                    Util.Warning(parent, ex.Message);
                    c.Close();
                    return null;
                }
                _profileToConnection[prof] = c;
                Env.MainForm.RefreshProfileStatus(prof);
            }

            return c;
        }
Пример #35
0
 private void OnListViewKeyPress(object sender, KeyPressEventArgs args)
 {
     if (args.KeyChar == '\r')
     {
         ChannelProfile prof = GetSelectedProfile();
         if (prof != null)
         {
             if (Control.ModifierKeys == Keys.Control)
             {
                 Env.Commands.EditProfile(prof);
             }
             else if (!Env.Connections.IsConnected(prof))
             {
                 Env.Commands.ConnectProfile(prof);
             }
         }
     }
 }
Пример #36
0
        private void InitUI(ChannelProfile prof)
        {
            if (prof == null)
            {
                _localToRemoteOption.Checked = true;
                _passwordOption.Checked      = true;
            }
            else
            {
                _sshHostBox.Text = prof.SSHHost;
                _portBox.Text    = prof.SSHPort.ToString();
                _accountBox.Text = prof.SSHAccount;
                //_udpOption.Checked = prof.ProtocolType==ProtocolType.Udp;
                if (prof.AuthType == AuthenticationType.Password)
                {
                    _passwordOption.Checked = true;
                }
                else
                {
                    _publicKeyOption.Checked = true;
                    _privateKeyBox.Text      = prof.PrivateKeyFile;
                }
                _loopbackOnly.Checked = !prof.AllowsForeignConnection;

                if (prof is LocalToRemoteChannelProfile)
                {
                    LocalToRemoteChannelProfile p = (LocalToRemoteChannelProfile)prof;
                    _localToRemoteOption.Checked = true;
                    _LRLocalPortBox.Text         = p.ListenPort.ToString();
                    _LRIPv6.Checked       = p.UseIPv6;
                    _LRRemoteHostBox.Text = p.DestinationHost;
                    _LRRemotePortBox.Text = p.DestinationPort.ToString();
                }
                else
                {
                    RemoteToLocalChannelProfile p = (RemoteToLocalChannelProfile)prof;
                    _remoteToLocalOption.Checked = true;
                    _RLLocalPortBox.Text         = p.DestinationPort.ToString();
                    _RLLocalHostBox.Text         = p.DestinationHost;
                    _RLRemotePortBox.Text        = p.ListenPort.ToString();
                }
            }
        }
Пример #37
0
        //profに対応したSSHConnectionを返す。接続がなければparentを親に認証ダイアログを出して認証する
        public SSHConnection GetOrCreateConnection(ChannelProfile prof, Form parent) {
            //ホスト名とアカウントのペアからコネクションを共有する仕組みがあるとよいかも
            SSHConnection c = (SSHConnection)_profileToConnection[prof];
            if (c != null)
                return c;

            SSHShortcutLoginDialog dlg = new SSHShortcutLoginDialog(prof);
            if (dlg.ShowDialog(parent) == DialogResult.OK) {
                c = dlg.Result.Connection;
                try {
                    dlg.Result.WaitRequest();
                }
                catch (Exception ex) {
                    Debug.WriteLine(ex.StackTrace);
                    Util.Warning(parent, ex.Message);
                    c.Close();
                    return null;
                }
                _profileToConnection[prof] = c;
                Env.MainForm.RefreshProfileStatus(prof);
            }

            return c;
        }
Пример #38
0
 public void DisconnectProfile(ChannelProfile prof)
 {
     Env.Connections.ManualClose(prof);
 }
Пример #39
0
 public void InsertAt(int index, ChannelProfile prof)
 {
     _data.Insert(index, prof);
 }
Пример #40
0
        private void InitUI(ChannelProfile prof) {
            if (prof == null) {
                _localToRemoteOption.Checked = true;
                _passwordOption.Checked = true;
            }
            else {
                _nameBox.Text = prof.Name;
                _sshHostBox.Text = prof.SSHHost;
                _portBox.Text = prof.SSHPort.ToString();
                _accountBox.Text = prof.SSHAccount;
                _noAuth.Checked = prof.Auth;

                //_udpOption.Checked = prof.ProtocolType==ProtocolType.Udp;
                if (prof.AuthType == AuthenticationType.Password)
                    _passwordOption.Checked = true;
                else {
                    _publicKeyOption.Checked = true;
                    _privateKeyBox.Text = prof.PrivateKeyFile;
                }
                _loopbackOnly.Checked = !prof.AllowsForeignConnection;

                if (prof is LocalToRemoteChannelProfile) {
                    LocalToRemoteChannelProfile p = (LocalToRemoteChannelProfile)prof;
                    _localToRemoteOption.Checked = true;
                    _LRLocalPortBox.Text = p.ListenPort.ToString();
                    _LRIPv6.Checked = p.UseIPv6;
                    _LRRemoteHostBox.Text = p.DestinationHost;
                    _LRRemotePortBox.Text = p.DestinationPort.ToString();
                }
                else {
                    RemoteToLocalChannelProfile p = (RemoteToLocalChannelProfile)prof;
                    _remoteToLocalOption.Checked = true;
                    _RLLocalPortBox.Text = p.DestinationPort.ToString();
                    _RLLocalHostBox.Text = p.DestinationHost;
                    _RLRemotePortBox.Text = p.ListenPort.ToString();
                }
            }
        }
Пример #41
0
 public void ConnectProfile(ChannelProfile prof)
 {
     Env.Connections.GetOrCreateConnection(prof, Env.MainForm);
 }
Пример #42
0
 public void ReplaceProfile(ChannelProfile p1, ChannelProfile p2)
 {
     _data[_data.IndexOf(p1)] = p2;
 }
Пример #43
0
        private void OnOK(object sender, EventArgs args) {
            this.DialogResult = DialogResult.None;
            string itemname = null;
            try {
                if (_localToRemoteOption.Checked)
                    _result = new LocalToRemoteChannelProfile();
                else
                    _result = new RemoteToLocalChannelProfile();

                if (_sshHostBox.Text.Length == 0)
                    throw new Exception(Env.Strings.GetString("Message.ProfileEdit.EmptySSHServer"));
                _result.SSHHost = _sshHostBox.Text;
                if (_accountBox.Text.Length == 0)
                    throw new Exception(Env.Strings.GetString("Message.ProfileEdit.EmptyAccount"));
                _result.SSHAccount = _accountBox.Text;
                _result.AuthType = _publicKeyOption.Checked ? AuthenticationType.PublicKey : AuthenticationType.Password;
                if (_result.AuthType == AuthenticationType.PublicKey)
                    _result.PrivateKeyFile = _privateKeyBox.Text;

                _result.Name = _nameBox.Text;

                itemname = Env.Strings.GetString("Caption.ProfileEdit.SSHPortNumber");
                _result.SSHPort = Util.ParsePort(_portBox.Text);

                _result.ProtocolType = ProtocolType.Tcp;

                _result.AllowsForeignConnection = !_loopbackOnly.Checked;
                if (_localToRemoteOption.Checked) {
                    LocalToRemoteChannelProfile p = (LocalToRemoteChannelProfile)_result;
                    itemname = Env.Strings.GetString("Caption.ProfileEdit.LocalPort");
                    p.ListenPort = Util.ParsePort(_LRLocalPortBox.Text);
                    if (_LRRemoteHostBox.Text.Length == 0)
                        throw new Exception(Env.Strings.GetString("Message.ProfileEdit.EmptyRemoveHost"));
                    p.DestinationHost = _LRRemoteHostBox.Text;
                    itemname = Env.Strings.GetString("Caption.ProfileEdit.DestinationPort");
                    p.DestinationPort = Util.ParsePort(_LRRemotePortBox.Text);
                    p.UseIPv6 = _LRIPv6.Checked;
                }
                else {
                    RemoteToLocalChannelProfile p = (RemoteToLocalChannelProfile)_result;
                    itemname = Env.Strings.GetString("Caption.ProfileEdit.RemotePort");
                    p.ListenPort = Util.ParsePort(_RLRemotePortBox.Text);
                    itemname = Env.Strings.GetString("Caption.ProfileEdit.DestinationHost");
                    p.DestinationHost = _RLLocalHostBox.Text;
                    itemname = Env.Strings.GetString("Caption.ProfileEdit.DestinationPort");
                    p.DestinationPort = Util.ParsePort(_RLLocalPortBox.Text);
                    p.AllowsForeignConnection = !_loopbackOnly.Checked;
                    /*
                    if(_udpOption.Checked && _loopbackOnly.Checked) {
                        throw new Exception("リモートからローカルへのUDPの転送をするときはLoopback以外からの接続を許可する必要があります。");
                    }
                    */
                }

                this.DialogResult = DialogResult.OK;
            }
            catch (FormatException) {
                Util.Warning(this, String.Format(Env.Strings.GetString("Message.OptionDialog.InvalidItem"), itemname));
            }
            catch (Exception ex) {
                Util.Warning(this, ex.Message);
            }

        }
Пример #44
0
 public void AddProfile(ChannelProfile p)
 {
     _data.Add(p);
 }
Пример #45
0
 public void RemoveProfile(ChannelProfile p)
 {
     _data.Remove(p);
 }
Пример #46
0
        private void OnOK(object sender, EventArgs args)
        {
            this.DialogResult = DialogResult.None;
            string itemname = null;

            try {
                if (_localToRemoteOption.Checked)
                {
                    _result = new LocalToRemoteChannelProfile();
                }
                else
                {
                    _result = new RemoteToLocalChannelProfile();
                }

                if (_sshHostBox.Text.Length == 0)
                {
                    throw new Exception(Env.Strings.GetString("Message.ProfileEdit.EmptySSHServer"));
                }
                _result.SSHHost = _sshHostBox.Text;
                if (_accountBox.Text.Length == 0)
                {
                    throw new Exception(Env.Strings.GetString("Message.ProfileEdit.EmptyAccount"));
                }
                _result.SSHAccount = _accountBox.Text;
                _result.AuthType   = _publicKeyOption.Checked ? AuthenticationType.PublicKey : AuthenticationType.Password;
                if (_result.AuthType == AuthenticationType.PublicKey)
                {
                    _result.PrivateKeyFile = _privateKeyBox.Text;
                }

                itemname        = Env.Strings.GetString("Caption.ProfileEdit.SSHPortNumber");
                _result.SSHPort = Util.ParsePort(_portBox.Text);

                _result.ProtocolType = ProtocolType.Tcp;

                _result.AllowsForeignConnection = !_loopbackOnly.Checked;
                if (_localToRemoteOption.Checked)
                {
                    LocalToRemoteChannelProfile p = (LocalToRemoteChannelProfile)_result;
                    itemname     = Env.Strings.GetString("Caption.ProfileEdit.LocalPort");
                    p.ListenPort = Util.ParsePort(_LRLocalPortBox.Text);
                    if (_LRRemoteHostBox.Text.Length == 0)
                    {
                        throw new Exception(Env.Strings.GetString("Message.ProfileEdit.EmptyRemoveHost"));
                    }
                    p.DestinationHost = _LRRemoteHostBox.Text;
                    itemname          = Env.Strings.GetString("Caption.ProfileEdit.DestinationPort");
                    p.DestinationPort = Util.ParsePort(_LRRemotePortBox.Text);
                    p.UseIPv6         = _LRIPv6.Checked;
                }
                else
                {
                    RemoteToLocalChannelProfile p = (RemoteToLocalChannelProfile)_result;
                    itemname                  = Env.Strings.GetString("Caption.ProfileEdit.RemotePort");
                    p.ListenPort              = Util.ParsePort(_RLRemotePortBox.Text);
                    itemname                  = Env.Strings.GetString("Caption.ProfileEdit.DestinationHost");
                    p.DestinationHost         = _RLLocalHostBox.Text;
                    itemname                  = Env.Strings.GetString("Caption.ProfileEdit.DestinationPort");
                    p.DestinationPort         = Util.ParsePort(_RLLocalPortBox.Text);
                    p.AllowsForeignConnection = !_loopbackOnly.Checked;

                    /*
                     * if(_udpOption.Checked && _loopbackOnly.Checked) {
                     *  throw new Exception("リモートからローカルへのUDPの転送をするときはLoopback以外からの接続を許可する必要があります。");
                     * }
                     */
                }

                this.DialogResult = DialogResult.OK;
            }
            catch (FormatException) {
                Util.Warning(this, String.Format(Env.Strings.GetString("Message.OptionDialog.InvalidItem"), itemname));
            }
            catch (Exception ex) {
                Util.Warning(this, ex.Message);
            }
        }
Пример #47
0
 public static IPAddress ChannelProfileToListeningAddress(ChannelProfile prof) {
     if (prof.UseIPv6)
         return prof.AllowsForeignConnection ? IPAddress.IPv6Any : IPAddress.IPv6Loopback;
     else
         return prof.AllowsForeignConnection ? IPAddress.Any : IPAddress.Loopback;
 }
Пример #48
0
 public static Color GetProfileStatusColor(ChannelProfile prof)
 {
     return Env.Connections.IsConnected(prof) ? Color.GreenYellow : Color.White;
 }
Пример #49
0
 public static string GetProfileStatusString(ChannelProfile prof) {
     return Env.Strings.GetString(Env.Connections.IsConnected(prof) ? "Caption.Util.Connected" : "Caption.Util.Disconnected");
 }
Пример #50
0
 public static string GetProfileTypeString(ChannelProfile prof) {
     if (prof is LocalToRemoteChannelProfile)
         return Env.Strings.GetString("Caption.Util.Local");
     else
         return Env.Strings.GetString("Caption.Util.Remote");
 }
Пример #51
0
 public void ReplaceProfile(ChannelProfile p1, ChannelProfile p2)
 {
     _data[_data.IndexOf(p1)] = p2;
 }
Пример #52
0
        /*
        private static Socks CreateSocksParam(string dest_host, int dest_port) {
            Socks s = new Socks();
            s.DestName = dest_host;
            s.DestPort = (short)dest_port;
            s.Account = Env.Options.SocksAccount;
            s.Password = Env.Options.SocksPassword;
            s.ServerName = Env.Options.SocksServer;
            s.ServerPort = (short)Env.Options.SocksPort;
            s.ExcludingNetworks = Env.Options.SocksNANetworks;
            return s;
        }
        */
        public void ManualClose(ChannelProfile prof)
        {
            if (!IsConnected(prof)) {
                Debug.WriteLine("ManualClose - Not connected");
                return;
            }

            lock (this) {
                ISSHConnection c = (ISSHConnection)_profileToConnection[prof];
                _manualClosingConnections.Add(c);
                c.Disconnect(DisconnectionReasonCode.ByApplication, "close by application");
            }
        }
Пример #53
0
 public int IndexOf(ChannelProfile p)
 {
     return _data.IndexOf(p);
 }
Пример #54
0
 public static string GetProfileStatusString(ChannelProfile prof)
 {
     return(Env.Strings.GetString(Env.Connections.IsConnected(prof) ? "Caption.Util.Connected" : "Caption.Util.Disconnected"));
 }
Пример #55
0
 public void RemoveProfile(ChannelProfile p)
 {
     _data.Remove(p);
 }
Пример #56
0
        //コンテキストメニューと双方で使用する
        private void AdjustMenu(ToolStripItemCollection items, ChannelProfile prof) {
            bool connected = prof != null && Env.Connections.IsConnected(prof);

            ConvertMenuItem(items, _menuProfileConnect).Enabled = prof != null && !connected;
            ConvertMenuItem(items, _menuProfileDisconnect).Enabled = prof != null && connected;
            ConvertMenuItem(items, _menuProfileRemove).Enabled = prof != null && !connected;
            ConvertMenuItem(items, _menuProfileProperty).Enabled = prof != null && !connected;

            int index = prof == null ? -1 : Env.Profiles.IndexOf(prof);
            ConvertMenuItem(items, _menuProfileUp).Enabled = prof != null && index > 0;
            ConvertMenuItem(items, _menuProfileDown).Enabled = prof != null && index < Env.Profiles.Count - 1;
        }
Пример #57
0
 public bool IsConnected(ChannelProfile prof)
 {
     return _profileToConnection[prof] != null;
 }
Пример #58
0
 private ListViewItem FindItem(ChannelProfile prof) {
     foreach (ListViewItem li in _list.Items) {
         if (li.Tag == prof)
             return li;
     }
     return null;
 }
Пример #59
0
 public SSHConnector(ChannelProfile prof, string password, VerifySSHHostKeyDelegate keycheck)
 {
     _profile = prof;
     _password = password;
     _keycheck = keycheck;
 }
Пример #60
0
 public int IndexOf(ChannelProfile p)
 {
     return(_data.IndexOf(p));
 }