public ConfigForItemAndSwitch(ref List<DisableGetObjects.IConfigSwitchOrGroup> obj, DisableGetObjects.Setting_SwitchType[] switchTypes) { InitializeComponent(); data = obj; dataSwitchTypes = switchTypes; AddSelectionItems(); }
private void SendEnableUserNameIfNeeded(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch) { //enable登录过程 if (whatTypeOfSwitch.IsThisSwitchNeedsOfEnableUserName) { LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "等待要求enable用户名登录"); nowUsingItem.LastFlushLog += "\n" + nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "等待要求enable用户名登录\n"; try { telnetSwitch.WaitForString(whatTypeOfSwitch.PromptForEnableUserName); } catch (Exception e) { LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + e.ToString()); lock (nowUsingItem) { nowUsingItem.FlushResult = "没有提示输入enable用户名"; } throw new Exception(); } lock (nowUsingItem) { nowUsingItem.LastFlushLog += "\n" + nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "发送enable用户名\n"; } if (!telnetSwitch.SendResponse(nowUsingItem.EnableUsername, true)) { lock (nowUsingItem) { nowUsingItem.FlushResult = "发送enable用户名失败"; } throw new Exception(); } if (!telnetSwitch.WaitForChangedScreen()) { lock (nowUsingItem) { nowUsingItem.FlushResult = "发送enable用户名后没有响应"; } throw new Exception(); } } }
private void MakeSureLowPrivIsGood(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch) { //确认登录密码正确性 LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "确认登录密码正确性"); nowUsingItem.LastFlushLog += "\n" + nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "确认登录密码正确性\n"; try { telnetSwitch.WaitForString(whatTypeOfSwitch.PromptForCommandBeforeEnable); } catch (Exception e) { LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + e.ToString()); lock (nowUsingItem) { nowUsingItem.FlushResult = "登录密码错误"; } throw new Exception(); } }
private void MakeSureEnableSuccess(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch) { try { telnetSwitch.WaitForString(whatTypeOfSwitch.PromptForCommandAfterEnable); } catch (Exception e) { LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + e.ToString()); lock (nowUsingItem) { nowUsingItem.FlushResult = "没有提示enable提示符,enable 密码错误?"; } throw new Exception(); } }
private void CheckForDisableStringInData(DisableGetObjects.Setting_SwitchType whatTypeOfSwitch, string dataContains, out bool isthisswitchhasdisable, out string flushResult) { LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "取到项目:\n" + dataContains); var lines = dataContains.Split('\n'); LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "开始检查项目列表:共" + lines.Length + "项"); lock (nowUsingItem) { nowUsingItem.LastFlushLog += "\n" + nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "开始检查项目列表:共" + lines.Length.ToString() + "项\n"; } isthisswitchhasdisable = false; //保存disable flushResult = ""; foreach (var t in lines) { LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "检查项目_disable\n" + t + "查找" + whatTypeOfSwitch.ScreeningStringForDisableItem); if (t.ToLower().Contains(whatTypeOfSwitch.ScreeningStringForDisableItem.ToLower())) { LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "检查项目_port\n" + t + "查找" + whatTypeOfSwitch.ScreeningStringForPortLine); if (t.ToLower().Contains(whatTypeOfSwitch.ScreeningStringForPortLine.ToLower())) { //找到了disable的项 LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "DISABLE:" + t); flushResult += t + "\n"; isthisswitchhasdisable = true; } } } }
private void GetIntoTerminalConfigMode(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch) { nowUsingItem.LastFlushLog += "\n GetIntoTerminalConfigMode "; nowUsingItem.LastFlushLog += "\n 发送:" + whatTypeOfSwitch.SwitchCommandForConfigMode + "\r\n"; if (!telnetSwitch.SendResponse(whatTypeOfSwitch.SwitchCommandForConfigMode, true)) { lock (nowUsingItem) { nowUsingItem.LastFlushLog += "\n" + "进入终端配置模式失败\n"; } throw new Exception(); } for (int i = 0; i < 20; ++i) { telnetSwitch.SendResponse(" ", true); } }
public DEBUG_LIST(ref DisableGetObjects.Setting_Type_Switch[] swi) { InitializeComponent(); ss = swi; }
private void SendLoginUserNameIfNeeded(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch) { if (whatTypeOfSwitch.IsThisSwitchNeedsOfUserName) { LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "要求登录用户名"); lock (nowUsingItem) { nowUsingItem.LastFlushLog += "\n" + nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "要求登录用户名\n"; } try { telnetSwitch.WaitForString(whatTypeOfSwitch.PromptForUserName); } catch (Exception e) { lock (nowUsingItem) { nowUsingItem.FlushResult = "要求用户名时遇到异常-" + e.ToString(); } LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + e.ToString()); throw new Exception(); } if (!telnetSwitch.SendResponse(nowUsingItem.UserName, true)) { lock (nowUsingItem) { nowUsingItem.FlushResult = "未发送用户名"; } throw new Exception(); } if (!telnetSwitch.WaitForChangedScreen()) { lock (nowUsingItem) { nowUsingItem.FlushResult = "等待用户名结果失败"; } throw new Exception(); } } }
private void findAndReplaceInData(DisableGetObjects.IConfigSwitchOrGroup src, DisableGetObjects.IConfigSwitchOrGroup dstValue) { for(int i=0;i<data.Count;++i) { if (data[i] == src) { data[i] = dstValue; } else { var t = data[i]; findandReplaceInSub(data[i].NextItems(),ref t, src, dstValue); data[i] = t; } } }
private void deleteItemInSub(DisableGetObjects.IConfigSwitchOrGroup father, DisableGetObjects.IConfigSwitchOrGroup whattodel) { if (!father.IfHaveNextItems()) { return; } foreach (var m in father.NextItems()) { if (m == whattodel) { List<DisableGetObjects.IConfigSwitchOrGroup> w = new List<DisableGetObjects.IConfigSwitchOrGroup>(father.NextItems()); w.Remove(whattodel); father.SetItemList(w.ToArray()); return; } else { deleteItemInSub(m, whattodel); } } }
private TreeNode buildtree(DisableGetObjects.IConfigSwitchOrGroup datainput) { TreeNode result = new TreeNode(datainput.GetNowItemName()); result.Tag = datainput; if (datainput.IfHaveNextItems()) { var datanext = datainput.NextItems(); foreach (var p in datanext) { result.Nodes.Add(buildtree(p)); } } return result; }
private void SendErrdisableRecoveryCommand(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch) { nowUsingItem.LastFlushLog += "\n SendErrdisableRecoveryCommand "; nowUsingItem.LastFlushLog += "\n 发送:" + whatTypeOfSwitch.SwitchCommandForRecoving + "\r\n"; if (!telnetSwitch.SendResponse(whatTypeOfSwitch.SwitchCommandForRecoving, true)) { lock (nowUsingItem) { nowUsingItem.LastFlushLog += "\n" + "发送恢复命令失败\n"; } throw new Exception(); } for (int i = 0; i < 20; ++i) { telnetSwitch.SendResponse(" ", true); } }
private void SendEndToSuperModeCommand(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch) { lock (nowUsingItem) { nowUsingItem.LastFlushLog += "\n SendEndToSuperModeCommand \r\n"; nowUsingItem.LastFlushLog += "\n 发送:"+ whatTypeOfSwitch.SwitchCommandForEndConfig+"\r\n"; } if(!telnetSwitch.SendResponse(whatTypeOfSwitch.SwitchCommandForEndConfig, true)) { lock (nowUsingItem) { nowUsingItem.LastFlushLog += "\n" + "回到普通命令提示模式失败\n"; } throw new Exception(); } for (int i = 0; i < 20; ++i) { telnetSwitch.SendResponse(" ", true); } }
private void SendLoginPassword_HighPriv(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch) { //enable密码 LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "等待要求enable密码"); lock (nowUsingItem) { nowUsingItem.LastFlushLog += "\n" + nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "等待要求enable密码\n"; } try { telnetSwitch.WaitForString(whatTypeOfSwitch.PromptForEnablePassword); } catch (Exception e) { LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + e.ToString()); lock (nowUsingItem) { nowUsingItem.FlushResult = "没有提示输入enable密码/enable用户名错误?"; } throw new Exception(); } lock (nowUsingItem) { nowUsingItem.LastFlushLog += "\n" + nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "发送enable密码\n"; } if (!telnetSwitch.SendResponse(nowUsingItem.EnablePassword, true)) { lock (nowUsingItem) { nowUsingItem.FlushResult = "错误:发送enable密码失败"; } throw new Exception(); } if (!telnetSwitch.WaitForChangedScreen()) { lock (nowUsingItem) { nowUsingItem.FlushResult = "错误:WaitForChangedScreen返回false"; } throw new Exception(); } }
private void findandReplaceInSub(DisableGetObjects.IConfigSwitchOrGroup[] iConfigSwitchOrGroup,ref DisableGetObjects.IConfigSwitchOrGroup father, DisableGetObjects.IConfigSwitchOrGroup src, DisableGetObjects.IConfigSwitchOrGroup dstValue) { if (iConfigSwitchOrGroup == null) return; for (int i = 0; i < iConfigSwitchOrGroup.Length; ++i) { if (iConfigSwitchOrGroup[i] == src) { iConfigSwitchOrGroup[i] = dstValue; father.SetItemList(iConfigSwitchOrGroup); return; } else { findandReplaceInSub(iConfigSwitchOrGroup[i].NextItems(),ref iConfigSwitchOrGroup[i], src, dstValue); } } }
private void SendLoginPassword_LowPriv(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch) { LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "要求登录密码"); lock (nowUsingItem) { nowUsingItem.LastFlushLog += "\n" + nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "要求登录密码\n"; } try { telnetSwitch.WaitForString(whatTypeOfSwitch.PromptForPassword); } catch (Exception e) { LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + e.ToString()); lock (nowUsingItem) { nowUsingItem.FlushResult = "没有要求密码或密码请求字符串不正确"; } throw new Exception(); } LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "发送登录密码"); lock (nowUsingItem) { nowUsingItem.LastFlushLog += "\n" + nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "发送登录密码\n"; } if (!telnetSwitch.SendResponse(nowUsingItem.Password, true)) { lock (nowUsingItem) { nowUsingItem.FlushResult = "发送密码失败"; } throw new Exception(); } if (!telnetSwitch.WaitForChangedScreen()) { lock (nowUsingItem) { nowUsingItem.FlushResult = "发送密码后没有响应"; } throw new Exception(); } }
public SearchForDisableNonImmuable(DisableGetObjects.Setting_Type_Switch sts) : base(sts) { }
private void WaitForAllSwitchStatusTransmited(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch) { //大量交换机显示==more==信息,因此需要等待命令行 //added @ 2012 05 20 by sc for (int counter = 0; counter < 20; ++counter) { if (!telnetSwitch.SendResponse(" ", false)) { lock (nowUsingItem) { nowUsingItem.FlushResult = "发送等待命令行参数的请求失败"; } throw new Exception(); } } ///最大尝试次数 const int MAXIMUM_TRY_COUNT = 20; for (int currectTry = 0; currectTry <= MAXIMUM_TRY_COUNT; ++currectTry) { telnetSwitch.WaitForChangedScreen(); //若是屏幕上没有出现命令提示符 try { if (telnetSwitch.VirtualScreen.FindOnScreen(whatTypeOfSwitch.PromptForCommandAfterEnable, false) != null) { break; } } catch (NullReferenceException) { lock (nowUsingItem) { nowUsingItem.FlushResult = "发送请求命令行参数的请求中,连接断开"; } throw new Exception(); } catch (Exception) { lock (nowUsingItem) { nowUsingItem.FlushResult = "发送请求命令行参数的请求失败"; } throw new Exception(); } if (currectTry == MAXIMUM_TRY_COUNT) { //到达最大重试门限 lock (nowUsingItem) { nowUsingItem.LastFlushLog += "\n到达取得数据最大门限\n"; } } else { //发送空格以及两个回车 if (!telnetSwitch.SendResponse(" ", true)) { lock (nowUsingItem) { nowUsingItem.FlushResult = "发送等待命令行参数的请求失败-1"; } throw new Exception(); } } } }
public SearchForDisable(DisableGetObjects.Setting_Type_Switch dsni) { nowUsingItem = dsni; }
/// <summary> /// 只在初始化时调用:将交换机的配置树转换为列表 /// </summary> /// <param name="iConfigSwitchOrGroup">传入的配置树</param> /// <param name="servList">传出的列表</param> private void turnItemIntoList(DisableGetObjects.IConfigSwitchOrGroup[] iConfigSwitchOrGroup, ref List<DisableGetObjects.Setting_Type_Switch> servList) { foreach (var t in iConfigSwitchOrGroup) { if (t is DisableGetObjects.Setting_Type_Switch) { servList.Add(t as DisableGetObjects.Setting_Type_Switch); } else { if (t.IfHaveNextItems()) { turnItemIntoList(t.NextItems(), ref servList); } } } }
public RecoveryFromDisable(DisableGetObjects.Setting_Type_Switch sw) { nowUsingItem = sw; }