public bool Verify(ISSHHostKeyInformationProvider info) { if (!_loaded) { try { Load(); } catch (Exception ex) { //ロード中のエラーのときは鍵は拒否。安全側に! RuntimeUtil.ReportException(ex); return(false); } } string keystr = info.KnownHostsString; string local = (info.Protocol == SSHProtocol.SSH1) ? _dataForSSH1[ToKeyString(info)] : _dataForSSH2[ToKeyString(info)]; if (local == null) { return(AskUserReliability(info, keystr, "Message.HostKeyChecker.AskHostKeyRegister")); } else if (keystr != local) { return(AskUserReliability(info, keystr, "Message.HostKeyChecker.AskHostKeyRenew")); } else { return(true); } }
/// <summary> /// Sends bytes. /// </summary> /// <param name="data">Byte array that contains data to send.</param> /// <param name="offset">Offset in data</param> /// <param name="length">Length of bytes to transmit</param> /// <param name="localEcho">Whether bytes can be repeated as local echo</param> private void TransmitInternal(byte[] data, int offset, int length, bool localEcho) { // Note: // This method may be called from multiple threads. // One is UI thread which is processing key events, and another is communication thread // which is going to send back something. // // Some IPoderosaSocket implementations have thread-safe Transmit() method, but not all. // So we transmit data exclusively. lock (_transmitSync) { try { if (localEcho && _settings.LocalEcho) { _dataForLocalEcho.Set(data, 0, data.Length); _host.OnReception(_dataForLocalEcho); } _connection.Socket.Transmit(data, offset, length); } catch (Exception) { try { _connection.Close(); } catch (Exception ex) { RuntimeUtil.ReportException(ex); } _host.TerminalHost.OwnerWindow.Warning(GEnv.Strings.GetString("Message.TerminalControl.FailedToSend")); } } }
private static CommandResult SaveShortcutFile(ICommandTarget target) { ITerminalControlHost t = TerminalCommandTarget.AsTerminal(target); if (t == null) { return(CommandResult.Failed); } SaveFileDialog dlg = new SaveFileDialog(); dlg.Title = TEnv.Strings.GetString("Caption.SaveShortcutFile"); dlg.DefaultExt = "gts"; dlg.AddExtension = true; dlg.Filter = "Terminal Shortcut(*.gts)|*.gts"; if (dlg.ShowDialog() == DialogResult.OK) { try { new ShortcutFileContent(t.TerminalSettings, t.TerminalConnection.Destination).SaveToXML(dlg.FileName); return(CommandResult.Succeeded); } catch (Exception ex) { RuntimeUtil.ReportException(ex); return(CommandResult.Failed); } } else { return(CommandResult.Cancelled); } }
private static CommandResult CmdPasteFromFile(ICommandTarget target) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = GEnv.Strings.GetString("Caption.SelectPasteFile"); dlg.Filter = "All Files(*.*)|*.*"; if (dlg.ShowDialog() == DialogResult.OK) { StreamReader r = null; try { ITerminalControlHost host = TerminalCommandTarget.AsOpenTerminal(target); if (host == null) { return(CommandResult.Failed); } r = new StreamReader(dlg.FileName, Encoding.Default); host.TerminalTransmission.SendTextStream(r, true); return(CommandResult.Succeeded); } catch (Exception ex) { RuntimeUtil.ReportException(ex); return(CommandResult.Failed); } finally { if (r != null) { r.Close(); } } } return(CommandResult.Cancelled); }
internal MacroExecutor RunMacroModule(MacroModule module, ISession sessionToBind, IMacroEventListener listener) { try { Assembly asm = MacroUtil.LoadMacroAssembly(module); MacroExecutor macroExec = new MacroExecutor(module, asm); if (sessionToBind != null) { bool bound = _sessionBinder.Bind(macroExec, sessionToBind); if (!bound) { GUtil.Warning(null, Strings.GetString("Message.MacroPlugin.AnotherMacroIsRunningInThisSession")); return(null); } } if (listener != null) { listener.IndicateMacroStarted(); } macroExec.AsyncExec(listener); return(macroExec); } catch (Exception ex) { RuntimeUtil.ReportException(ex); return(null); } }
public void AsyncConnect() { bool success = false; _asyncThread = Thread.CurrentThread; try { ITerminalConnection result = Connect(); if (!_interrupted) { success = true; Debug.Assert(result != null); ProtocolUtil.FireConnectionSucceeded(_param); _client.SuccessfullyExit(result); } } catch (Exception ex) { if (!(ex is LocalShellUtilException)) { RuntimeUtil.ReportException(ex); } if (!_interrupted) { _client.ConnectionFailed(ex.Message); ProtocolUtil.FireConnectionFailure(_param, ex.Message); } } finally { if (!success && _process != null && !_process.HasExited) { _process.Kill(); } } }
//コンテキストメニュー表示 public void ShowContextMenu(IPoderosaMenuGroup[] menus, ICommandTarget target, Point point_screen, ContextMenuFlags flags) { //まずソート ICollection sorted = PositionDesignationSorter.SortItems(menus); ContextMenuStrip cm = new ContextMenuStrip(); MenuUtil.BuildContextMenu(cm, new ConvertingEnumerable <IPoderosaMenuGroup>(sorted), target); if (cm.Items.Count == 0) { cm.Dispose(); return; } //キーボード操作をトリガにメニューを出すときは、選択があったほうが何かと操作しやすい。 if ((flags & ContextMenuFlags.SelectFirstItem) != ContextMenuFlags.None) { cm.Items[0].Select(); } // ContextMenuStrip is not disposed automatically and // its instance sits in memory till application end. // To release a document object related with some menu items, // we need to dispose ContextMenuStrip explicitly soon after it disappeared. cm.VisibleChanged += new EventHandler(ContextMenuStripVisibleChanged); try { cm.Show(this, this.PointToClient(point_screen)); } catch (Exception ex) { RuntimeUtil.ReportException(ex); } }
private void OnOK(object sender, EventArgs args) { try { TypedHashtable <IShellScheme, IShellScheme> table = new TypedHashtable <IShellScheme, IShellScheme>(); List <IShellScheme> newscheme = new List <IShellScheme>(); IShellScheme newdefault = null; foreach (ItemTag tag in _tags) { if (tag.Original != null) { table.Add(tag.Original, tag.ShellScheme); } newscheme.Add(tag.ShellScheme); if (tag.ShellScheme.IsGeneric) { newdefault = tag.ShellScheme; } } foreach (ItemTag tag in _removing) { table.Add(tag.Original, newdefault); } _schemeCollection.UpdateAll(newscheme.ToArray(), table); } catch (Exception ex) { RuntimeUtil.ReportException(ex); } }
public override void TerminatePlugin() { base.TerminatePlugin(); IStartupContextSupplier s = (IStartupContextSupplier)_poderosaWorld.GetAdapter(typeof(IStartupContextSupplier)); Flush(); //ファイルの有無に関わらず内部のStorageNodeは更新しとく if (s.PreferenceFileName != null) { string preferenceFileName = s.PreferenceFileName; string tempPreferenceFileName = preferenceFileName + ".tmp"; string prevPreferenceFileName = preferenceFileName + ".prev"; try { using (TextWriter writer = new StreamWriter(tempPreferenceFileName, false, System.Text.Encoding.Default)) { WritePreference(writer); } if (File.Exists(preferenceFileName)) { File.Delete(prevPreferenceFileName); File.Move(preferenceFileName, prevPreferenceFileName); } File.Move(tempPreferenceFileName, preferenceFileName); } catch (Exception ex) { RuntimeUtil.ReportException(ex); } } }
protected override void OnClosing(System.ComponentModel.CancelEventArgs e) { base.OnClosing(e); try { if (SessionManagerPlugin.Instance == null) { return; //単体テストではSessionなしで起動することもありだ } IPoderosaDocument doc = _view.Document; if (doc == null) { return; } PrepareCloseResult r = SessionManagerPlugin.Instance.CloseDocument(doc); if (r == PrepareCloseResult.Cancel) { _closeCancelled = true; e.Cancel = true; } else { e.Cancel = false; } } catch (Exception ex) { RuntimeUtil.ReportException(ex); e.Cancel = false; //バグのためにウィンドウを閉じることもできない、というのはまずい } }
public bool Verify(ISSHLoginParameter param, SSHConnectionInfo info) { if (!_loaded) { try { Load(); } catch (Exception ex) { //ロード中のエラーのときは鍵は拒否。安全側に! RuntimeUtil.ReportException(ex); return(false); } } string keystr = info.DumpHostKeyInKnownHostsStyle(); string local = param.Method == SSHProtocol.SSH1 ? _dataForSSH1[ToKeyString(param)] : _dataForSSH2[ToKeyString(param)]; if (local == null) { return(AskUserReliability(param, info, keystr, "Message.HostKeyChecker.AskHostKeyRegister")); } else if (keystr != local) { return(AskUserReliability(param, info, keystr, "Message.HostKeyChecker.AskHostKeyRenew")); } else { return(true); } }
private void OnOK(object sender, EventArgs args) { this.DialogResult = DialogResult.None; StringResource sr = SSHUtilPlugin.Instance.Strings; try { SSH2UserAuthKey key = SSH2UserAuthKey.FromSECSHStyleFile(_tKeyFile.Text, _tCurrentPassphrase.Text); if (_tNewPassphrase.Text != _tNewPassphraseAgain.Text) { GUtil.Warning(this, sr.GetString("Message.ChangePassphrase.PassphraseMismatch")); } else { if (_tNewPassphrase.Text.Length > 0 || GUtil.AskUserYesNo(this, sr.GetString("Message.ChangePassphrase.AskEmptyPassphrase")) == DialogResult.Yes) { FileStream s = new FileStream(_tKeyFile.Text, FileMode.Create); key.WritePrivatePartInSECSHStyleFile(s, "", _tNewPassphrase.Text); s.Close(); GUtil.Warning(this, sr.GetString("Message.ChangePassphrase.NotifyChanged"), MessageBoxIcon.Information); this.DialogResult = DialogResult.OK; this.Close(); } } } catch (Exception ex) { RuntimeUtil.ReportException(ex); GUtil.Warning(this, ex.Message); } }
/// <summary> /// /// </summary> /// <returns></returns> /// <exclude/> public Image GetImage() { try { if (!_imageLoadIsAttempted) { _imageLoadIsAttempted = true; _backgroundImage = null; if (_backgroundImageFileName != null && _backgroundImageFileName.Length > 0) { try { _backgroundImage = Image.FromFile(_backgroundImageFileName); } catch (Exception) { MessageBox.Show("Can't find the background image!", "Poderosa error", MessageBoxButtons.OK, MessageBoxIcon.Hand); } } } return(_backgroundImage); } catch (Exception ex) { RuntimeUtil.ReportException(ex); return(null); } }
public void ApplySplitInfo(string format) { try { //現状を獲得 IPoderosaView[] previous_views = GetAllViews(); IPoderosaDocument[] documents = new IPoderosaDocument[previous_views.Length]; //分割適用後アクティブになるやつ for (int i = 0; i < previous_views.Length; i++) { documents[i] = previous_views[i].Document; } IPoderosaView[] new_views; SessionManagerPlugin sm = SessionManagerPlugin.Instance; if (format.Length > 0) { Form container = _parent.AsForm(); container.SuspendLayout(); Control old_root = this.RootControl; _paneDivision.ApplySplitInfo(old_root.Parent, old_root, format, delegate(string label) { return(CreateNewPane(_defaultViewFactory, DockStyle.Fill)); }); //とりあえずデフォルトファクトリで作成 container.ResumeLayout(true); _singlePane = null; //成功裏に終わったときのみ new_views = GetAllViews(); //新しいのを取得 } else { IContentReplaceableView view; UnifyAll(out view); new_views = new IPoderosaView[] { view }; } //既存ドキュメントに再適用 foreach (DocumentHost dh in sm.GetAllDocumentHosts()) { int index = CollectionUtil.ArrayIndexOf(previous_views, dh.LastAttachedView); if (index != -1) { IPoderosaView new_view = index < new_views.Length ? new_views[index] : new_views[0]; //個数が減ったら先頭に dh.AlternateView(new_view); } } //もともとActiveだったやつを再適用 for (int i = 0; i < documents.Length; i++) { if (documents[i] != null) { sm.AttachDocumentAndView(documents[i], sm.FindDocumentHost(documents[i]).LastAttachedView); //LastAttachedViewはこの上のループで適用済み } } } catch (Exception ex) { RuntimeUtil.ReportException(ex); } }
public static void Main(string[] args) { try { Run(args); } catch (Exception ex) { RuntimeUtil.ReportException(ex); } }
private static void CopyToClipboard(string data) { try { Clipboard.SetDataObject(data, false); } catch (Exception ex) { RuntimeUtil.ReportException(ex); } }
public void BypassDragDrop(DragEventArgs args) { try { WindowManagerPlugin.Instance.BypassDragDrop(_tabBarTable.ParentForm, args); } catch (Exception ex) { RuntimeUtil.ReportException(ex); } }
protected override void OnDragDrop(DragEventArgs args) { base.OnDragDrop(args); try { WindowManagerPlugin.Instance.BypassDragDrop(this, args); } catch (Exception ex) { RuntimeUtil.ReportException(ex); } }
//Termination処理の失敗時の処理 private void CloseError(Exception ex) { try { RuntimeUtil.ReportException(ex); CleanupErrorStatus(); } catch (Exception ex2) { RuntimeUtil.ReportException(ex2); } }
protected override void OnDragDrop(DragEventArgs drgevent) { base.OnDragDrop(drgevent); try { WindowManagerPlugin.Instance.BypassDragDrop(this.ParentForm, drgevent); } catch (Exception ex) { RuntimeUtil.ReportException(ex); } }
public static CommandResult OpenShortcutFile(ICommandTarget target, string filename) { IPoderosaMainWindow window = CommandTargetUtil.AsWindow(target); if (window == null) { window = (IPoderosaMainWindow)CommandTargetUtil.AsViewOrLastActivatedView(target).ParentForm.GetAdapter(typeof(IPoderosaMainWindow)); } if (window == null) { return(CommandResult.Ignored); } if (!File.Exists(filename)) { window.Warning(String.Format("{0} is not a file", filename)); return(CommandResult.Failed); } ShortcutFileContent f = null; try { f = ShortcutFileContent.LoadFromXML(filename); } catch (Exception ex) { //変なファイルをドロップしたなどで例外は簡単に起こりうる window.Warning(String.Format("Failed to read {0}\n{1}", filename, ex.Message)); return(CommandResult.Failed); } try { //独立ウィンドウにポップアップさせるようなことは考えていない IContentReplaceableView rv = (IContentReplaceableView)target.GetAdapter(typeof(IContentReplaceableView)); if (rv == null) { rv = (IContentReplaceableView)window.ViewManager.GetCandidateViewForNewDocument().GetAdapter(typeof(IContentReplaceableView)); } TerminalControl tc = (TerminalControl)rv.GetCurrentContent().GetAdapter(typeof(TerminalControl)); if (tc != null) //ターミナルコントロールがないときは無理に設定しにいかない { RenderProfile rp = f.TerminalSettings.UsingDefaultRenderProfile ? TerminalSessionsPlugin.Instance.TerminalEmulatorService.TerminalEmulatorOptions.CreateRenderProfile() : f.TerminalSettings.RenderProfile; Size sz = tc.CalcTerminalSize(rp); f.TerminalParameter.SetTerminalSize(sz.Width, sz.Height); } ITerminalSession s = TerminalSessionsPlugin.Instance.TerminalSessionStartCommand.StartTerminalSession(target, f.TerminalParameter, f.TerminalSettings); return(s != null ? CommandResult.Succeeded : CommandResult.Failed); } catch (Exception ex) { RuntimeUtil.ReportException(ex); return(CommandResult.Failed); } }
//IByteAsyncInputStream‚̃nƒ“ƒhƒ‰‚Å—áŠO‚ª—ˆ‚é‚Æ‚¯‚Á‚±‚¤ŽSŽ–‚È‚Ì‚Å‚±‚Ì’†‚Å‚µ‚Á‚©‚èƒK[ƒh private GenericResult OnReceptionCore(ByteDataFragment data) { try { _callback.OnReception(_dataFragment); return(GenericResult.Succeeded); } catch (Exception ex) { RuntimeUtil.ReportException(ex); Close(); return(GenericResult.Failed); } }
public void SaveTo(StructuredText node) { foreach (MRUItem tp in _data) { try { node.AddChild(_serializer.Serialize(tp)); } catch (Exception ex) { RuntimeUtil.ReportException(ex); } } }
protected override void OnDragEnter(DragEventArgs args) { #if DISABLEDRAGDROP base.OnDragEnter(args); try { WindowManagerPlugin.Instance.BypassDragEnter(this, args); } catch (Exception ex) { RuntimeUtil.ReportException(ex); } #endif }
public void Transmit(byte[] data, int offset, int length) { try { _outputStream.Write(data, offset, length); _outputStream.Flush(); } catch (IOException e) { RuntimeUtil.ReportException(e); } catch (ObjectDisposedException e) { RuntimeUtil.ReportException(e); } }
private GenericResult OnAbnormalTerminationCore(string msg) { try { _ownerConnection.CloseBySocket(); _callback.OnAbnormalTermination(msg); return(GenericResult.Succeeded); } catch (Exception ex) { RuntimeUtil.ReportException(ex); _socket.Disconnect(false); return(GenericResult.Failed); } }
private void DoCommand(IPoderosaCommand command) { try { ICommandTarget target = GetCommandTarget(); Debug.Assert(target != null); if (command.CanExecute(target)) { CommandManagerPlugin.Instance.Execute(command, target); } } catch (Exception ex) { RuntimeUtil.ReportException(ex); } }
public TimerSite(int interval, TimerDelegate callback) { _callback = callback; _timer = new Timer(); _timer.Interval = interval; _timer.Tick += delegate(object sender, EventArgs ars) { try { _callback(); } catch (Exception ex) { RuntimeUtil.ReportException(ex); } }; _timer.Enabled = true; }
public void Connect() { try { switch (_protocol) { case ProtocolType.Cywin: _synchronizedConnector = _basePoderosaInstance.ProtocolService.CreateFormBasedSynchronozedConnector(_window); _asyncConnection = _basePoderosaInstance.ProtocolService.AsyncCygwinConnect(_synchronizedConnector.InterruptableConnectorClient, (ICygwinParameter)_terminalParameter); _terminalConnection = _synchronizedConnector.WaitConnection(_asyncConnection, _basePoderosaInstance.TerminalSessionsPlugin.TerminalSessionOptions.TerminalEstablishTimeout); break; case ProtocolType.Raw: break; case ProtocolType.RLogin: break; case ProtocolType.Serial: _terminalConnection = (ITerminalConnection)SerialPortUtil.CreateNewSerialConnection(_window, (SerialTerminalParam)_terminalParameter, (SerialTerminalSettings)_terminalSettings); break; case ProtocolType.SSH1: case ProtocolType.SSH2: _synchronizedConnector = _basePoderosaInstance.ProtocolService.CreateFormBasedSynchronozedConnector(_window); _asyncConnection = _basePoderosaInstance.ProtocolService.AsyncSSHConnect(_synchronizedConnector.InterruptableConnectorClient, (ISSHLoginParameter)_terminalParameter); _terminalConnection = _synchronizedConnector.WaitConnection(_asyncConnection, _basePoderosaInstance.TerminalSessionsPlugin.TerminalSessionOptions.TerminalEstablishTimeout); break; case ProtocolType.Telnet: _synchronizedConnector = _basePoderosaInstance.ProtocolService.CreateFormBasedSynchronozedConnector(_window); _asyncConnection = _basePoderosaInstance.ProtocolService.AsyncTelnetConnect(_synchronizedConnector.InterruptableConnectorClient, (ITCPParameter)_terminalParameter); _terminalConnection = _synchronizedConnector.WaitConnection(_asyncConnection, _basePoderosaInstance.TerminalSessionsPlugin.TerminalSessionOptions.TerminalEstablishTimeout); break; default: _terminalConnection = null; break; } _terminalSession = new TerminalSession(_terminalConnection, _terminalSettings); _basePoderosaInstance.SessionManagerPlugin.StartNewSession(_terminalSession, _terminalView); _basePoderosaInstance.SessionManagerPlugin.ActivateDocument(_terminalSession.Terminal.IDocument, ActivateReason.InternalAction); } catch (Exception ex) { RuntimeUtil.ReportException(ex); //return CommandResult.Failed; } }
public CommandResult InternalExecute(ICommandTarget target, params IAdaptable[] args) { ISSHConnection sshConnection = GetSSHConnection(target) as ISSHConnection; if (sshConnection == null || sshConnection.SSHProtocol != SSHProtocol.SSH2) { return(CommandResult.Ignored); } string connectionName = GetTerminalName(target); if (connectionName == null) { connectionName = SFTPPlugin.Instance.StringResource.GetString("Common.UnknownPeer"); } Form ownerForm = GetForm(target); if (!ConfirmToUse(ownerForm, "SFTP")) { return(CommandResult.Cancelled); } SFTPClient sftp = null; try { sftp = SFTPClient.OpenSFTPChannel(sshConnection); SFTPForm form = new SFTPForm(ownerForm, sftp, connectionName); form.Show(); // Note: don't specify owner to avoid fixed z-order. return(CommandResult.Succeeded); } catch (Exception e) { if (sftp != null) { try { sftp.Close(); } catch (Exception) { } sftp = null; } RuntimeUtil.ReportException(e); return(CommandResult.Failed); } }