public override void RunMainWorkflow(bool isDryRun) { XmlNode overrideParameters = null; Hashtable overrideXml = new Hashtable(); // Check For Parameter Override File, Build Override Hashtable If Found if (!string.IsNullOrWhiteSpace(_wfp.ParameterOverrideFile) && File.Exists(_wfp.ParameterOverrideFile)) { try { OnStepProgress("OverrideFile", "Parameter Override File Found. [" + _wfp.ParameterOverrideFile + "]"); XmlDocument doc = new XmlDocument(); doc.Load(_wfp.ParameterOverrideFile); overrideParameters = doc.DocumentElement; OnStepProgress("OverrideFile", overrideParameters.OuterXml); foreach (XmlNode node in overrideParameters.ChildNodes) { string key = node.Attributes["name"].Value; overrideXml.Add(key, node); } } catch (Exception e) { OnStepProgress("OverrideFile", e.Message); overrideXml.Clear(); } } List <String> servers = _wfp.Servers; if (_wfp.RunUsing == RunUsingProtocolType.ProcessStart) { servers = new List <string>(); servers.Add("localhost"); } // Build Command Array For Each Server remoteCommands = new List <RemoteCommand>(); foreach (string server in servers) { String startWith = "-"; String joinWith = " "; bool useQuotes = true; bool skipBlankValues = false; if (_wfp.Powershell.ArgType != null) { if (_wfp.Powershell.ArgType.PrefixWith != null) { startWith = _wfp.Powershell.ArgType.PrefixWith; } if (_wfp.Powershell.ArgType.JoinWith != null) { joinWith = _wfp.Powershell.ArgType.JoinWith; } if (_wfp.Powershell.ArgType.UseQuotes != null) { useQuotes = Boolean.Parse(_wfp.Powershell.ArgType.UseQuotes); } if (_wfp.Powershell.ArgType.SkipBlankValues != null) { skipBlankValues = Boolean.Parse(_wfp.Powershell.ArgType.SkipBlankValues); } if (_wfp.Powershell.ArgType.value == ArgumentType.Ordered) { startWith = ""; } } // Build Argument String StringBuilder args = new StringBuilder(); args.Append("-NonInteractive "); if (!string.IsNullOrWhiteSpace(_wfp.Powershell.Script)) { if (_wfp.Powershell.ExecutionPolicy != ExecutionPolicyType.None) { args.Append(@"-ExecutionPolicy " + _wfp.Powershell.ExecutionPolicy + " "); } else if (Path.IsPathRooted(_wfp.Powershell.Script)) { // If Execution Policy isn't explicitly stated and the script is on a NAS, set the policy to "Bypass" as a default. if (_wfp.Powershell.Script.StartsWith(@"\\")) { args.Append(@"-ExecutionPolicy Bypass "); } } args.Append(@"-File """ + _wfp.Powershell.Script + @""" "); } else { args.Append(@"-Command """ + _wfp.Powershell.Command + @""" "); } //if (_wfp.Parameters != null && !string.IsNullOrWhiteSpace(_wfp.Powershell.Script)) if (_wfp.Parameters != null) { if (_wfp.Powershell.ArgType.value == ArgumentType.Named) { XmlNode node = (XmlNode)overrideXml[server]; args.Append(Utils.FormatNamedPowershellParameters(_wfp.Parameters, startWith, joinWith, useQuotes, skipBlankValues, node)); } else if (_wfp.Powershell.ArgType.value == ArgumentType.Ordered) { XmlNode node = (XmlNode)overrideXml[server]; args.Append(Utils.FormatOrderedPowershellParameters(_wfp.Parameters, startWith, useQuotes, node)); } else if (_wfp.Powershell.ArgType.value == ArgumentType.Xml) { String xml = _wfp.SerializeParameters(); args.Append(@"""" + xml.Replace(@"""", @"'") + @""""); } } RemoteCommand cmd = new RemoteCommand(); cmd.server = server; cmd.command = "powershell.exe"; cmd.args = args.ToString().Trim(); cmd.callbackLabel = server; remoteCommands.Add(cmd); } RunScript(remoteCommands, isDryRun); if (!string.IsNullOrWhiteSpace(_wfp.ParameterOverrideFile) && File.Exists(_wfp.ParameterOverrideFile)) { File.Delete(_wfp.ParameterOverrideFile); } }
public override void RunMainWorkflow(bool isDryRun) { XmlNode overrideParameters = null; Hashtable overrideXml = new Hashtable(); // Check For Parameter Override File, Build Override Hashtable If Found if (!string.IsNullOrWhiteSpace(_wfp.ParameterOverrideFile) && File.Exists(_wfp.ParameterOverrideFile)) { try { OnStepProgress("OverrideFile", "Parameter Override File Found. [" + _wfp.ParameterOverrideFile + "]"); XmlDocument doc = new XmlDocument(); doc.Load(_wfp.ParameterOverrideFile); overrideParameters = doc.DocumentElement; OnStepProgress("OverrideFile", overrideParameters.OuterXml); foreach (XmlNode node in overrideParameters.ChildNodes) { string key = node.Attributes["name"].Value; overrideXml.Add(key, node); } } catch (Exception e) { OnStepProgress("OverrideFile", e.Message); overrideXml.Clear(); } } remoteCommands = new List <RemoteCommand>(); List <string> servers = _wfp.Servers; if (_wfp.RunUsing == RunUsingProtocolType.ProcessStart) { servers = new List <string>(); servers.Add("localhost"); } foreach (string server in servers) { // Build Argument String StringBuilder args = new StringBuilder(); if (!string.IsNullOrWhiteSpace(_wfp.Ant.BuildFile)) { args.Append(@"-buildfile " + _wfp.Ant.BuildFile + " "); } if (_wfp.Parameters != null) { XmlNode node = (XmlNode)overrideXml[server]; args.Append(Utils.FormatNamedParameters(_wfp.Parameters, "-D", "=", true, false, node)); } if (!string.IsNullOrWhiteSpace(_wfp.Ant.Target)) { args.Append(_wfp.Ant.Target + " "); } string command = String.Empty; if (!string.IsNullOrWhiteSpace(_wfp.Ant.Home)) { command = _wfp.Ant.Home + @"\ant"; } else { command = "ant"; } RemoteCommand cmd = new RemoteCommand(); cmd.server = server; cmd.command = command; cmd.args = args.ToString().Trim(); cmd.callbackLabel = server; remoteCommands.Add(cmd); } RunScript(remoteCommands, isDryRun); if (!string.IsNullOrWhiteSpace(_wfp.ParameterOverrideFile) && File.Exists(_wfp.ParameterOverrideFile)) { File.Delete(_wfp.ParameterOverrideFile); } }
private void BuildPlinkCommands(XmlElement overrideParms) { OnStepProgress("OverrideFile", overrideParms.OuterXml); HashSet <string> validUsersOld = new HashSet <string>(); Dictionary <string, UserType> validUsers = new Dictionary <string, UserType>(); foreach (UserType user in _wfp.Plink.Users) { validUsers.Add(user.Name.Trim(), user); } String startWith = "-"; String joinWith = " "; bool useQuotes = true; if (_wfp.Plink.ArgType != null) { if (_wfp.Plink.ArgType.value == ArgumentType.Ordered) { startWith = ""; } if (_wfp.Plink.ArgType.PrefixWith != null) { startWith = _wfp.Plink.ArgType.PrefixWith; } if (_wfp.Plink.ArgType.JoinWith != null) { joinWith = _wfp.Plink.ArgType.JoinWith; } if (_wfp.Plink.ArgType.UseQuotes != null) { useQuotes = Boolean.Parse(_wfp.Plink.ArgType.UseQuotes); } } foreach (XmlNode userNode in overrideParms.ChildNodes) { string user = userNode.Attributes["value"].FirstChild.Value; UserType validUser = null; // if (!(validUsers.Contains(user.Trim()))) if (!(validUsers.ContainsKey(user.Trim()))) { OnStepProgress("OverrideFile", "User [" + user.Trim() + "] Is Not A Valid User For This Package."); continue; } else { validUsers.TryGetValue(user.Trim(), out validUser); } // Build Argument String String scriptArgs = null; StringBuilder args = new StringBuilder(); if (_wfp.Parameters != null) { if (_wfp.Plink.ArgType.value == ArgumentType.Ordered) { scriptArgs = Utils.FormatOrderedParameters(_wfp.Parameters, startWith, useQuotes, userNode); } else if (_wfp.Plink.ArgType.value == ArgumentType.Named) { scriptArgs = Utils.FormatNamedParameters(_wfp.Parameters, startWith, joinWith, useQuotes); } } if ((!string.IsNullOrWhiteSpace(scriptArgs)) && (!string.IsNullOrWhiteSpace(_wfp.Plink.CommandFile.Name))) { scriptArgs = scriptArgs.Replace(@"""", @"\"""); } args.Append(@"-ssh "); if (!(String.IsNullOrWhiteSpace(validUser.Password))) { String ptPassword = Utils.Decrypt(validUser.Password); if (!(ptPassword.StartsWith("UNABLE TO DECRYPT"))) { args.Append(@"-pw """ + ptPassword + @""" "); } } else if (!string.IsNullOrWhiteSpace(_wfp.Plink.PrivateKey)) { args.Append(@"-i """ + _wfp.Plink.PrivateKey + @""" "); } args.Append(@"-batch "); if (!string.IsNullOrWhiteSpace(user)) { args.Append(user + " "); } if (!string.IsNullOrWhiteSpace(_wfp.Plink.Command)) { args.Append(_wfp.Plink.Command + " "); if (scriptArgs != null) { args.Append(scriptArgs + " "); } } else if (!string.IsNullOrWhiteSpace(_wfp.Plink.CommandFile.Name)) { string codePage = "437"; if (!string.IsNullOrWhiteSpace(_wfp.Plink.CommandFile.CodePage)) { codePage = _wfp.Plink.CommandFile.CodePage; } args.Append(@"""dos2unix -" + codePage + " | sh /dev/stdin "); if (scriptArgs != null) { args.Append(scriptArgs + " "); } args.Append(@""" < """ + _wfp.Plink.CommandFile.Name + @""""); } RemoteCommand cmd = new RemoteCommand(); if (_wfp.RunUsing == RunUsingProtocolType.ProcessStart) { cmd.server = "localhost"; } else { cmd.server = _wfp.Servers[0]; } cmd.command = "plink " + args.ToString().Trim(); if (user.IndexOf("@") >= 0) { cmd.callbackLabel = user.Substring(user.IndexOf("@") + 1); } else { cmd.callbackLabel = user; } remoteCommands.Add(cmd); } }
private void BuildPlinkCommands() { String startWith = "-"; String joinWith = " "; bool useQuotes = true; bool skipBlankValues = false; if (_wfp.Plink.ArgType != null) { if (_wfp.Plink.ArgType.PrefixWith != null) { startWith = _wfp.Plink.ArgType.PrefixWith; } if (_wfp.Plink.ArgType.JoinWith != null) { joinWith = _wfp.Plink.ArgType.JoinWith; } if (_wfp.Plink.ArgType.UseQuotes != null) { useQuotes = Boolean.Parse(_wfp.Plink.ArgType.UseQuotes); } if (_wfp.Plink.ArgType.SkipBlankValues != null) { skipBlankValues = Boolean.Parse(_wfp.Plink.ArgType.SkipBlankValues); } if (_wfp.Plink.ArgType.value == ArgumentType.Ordered) { startWith = ""; } } foreach (UserType user in _wfp.Plink.Users) { // Build Argument String String scriptArgs = null; StringBuilder args = new StringBuilder(); if (_wfp.Parameters != null) { if (_wfp.Plink.ArgType.value == ArgumentType.Ordered) { scriptArgs = Utils.FormatOrderedParameters(_wfp.Parameters, startWith, useQuotes); } else if (_wfp.Plink.ArgType.value == ArgumentType.Named) { scriptArgs = Utils.FormatNamedParameters(_wfp.Parameters, startWith, joinWith, useQuotes, skipBlankValues); } } if (_wfp.Plink.CommandFile != null) { if ((!string.IsNullOrWhiteSpace(scriptArgs)) && (!string.IsNullOrWhiteSpace(_wfp.Plink.CommandFile.Name))) { scriptArgs = scriptArgs.Replace(@"""", @"\"""); } } if (config.Default.DebugMode) { args.Append(@"-v "); } args.Append(@"-ssh "); if (!(String.IsNullOrWhiteSpace(user.Password))) { String ptPassword = Utils.Decrypt(user.Password); if (!(ptPassword.StartsWith("UNABLE TO DECRYPT"))) { args.Append(@"-pw """ + ptPassword + @""" "); } } else if (!string.IsNullOrWhiteSpace(_wfp.Plink.PrivateKey)) { args.Append(@"-i """ + _wfp.Plink.PrivateKey + @""" "); } if (!_wfp.Plink.RunInteractive) { args.Append(@"-batch "); } if (!string.IsNullOrWhiteSpace(user.Name)) { args.Append(user.Name + " "); } if (!string.IsNullOrWhiteSpace(_wfp.Plink.Command)) { args.Append(_wfp.Plink.Command + " "); if (scriptArgs != null) { args.Append(scriptArgs + " "); } } else if (!string.IsNullOrWhiteSpace(_wfp.Plink.CommandFile.Name)) { string codePage = "437"; if (!string.IsNullOrWhiteSpace(_wfp.Plink.CommandFile.CodePage)) { codePage = _wfp.Plink.CommandFile.CodePage; } args.Append(@"""dos2unix -" + codePage + " | sh /dev/stdin "); if (scriptArgs != null) { args.Append(scriptArgs + " "); } args.Append(@""" < """ + _wfp.Plink.CommandFile.Name + @""""); } RemoteCommand cmd = new RemoteCommand(); if (_wfp.RunUsing == RunUsingProtocolType.ProcessStart) { cmd.server = "localhost"; } else { cmd.server = _wfp.Servers[0]; } if (String.IsNullOrWhiteSpace(_wfp.WorkingDir)) { cmd.command = "plink.exe"; } else { cmd.command = Path.Combine(_wfp.WorkingDir, "plink.exe"); } cmd.args = args.ToString().Trim(); if (user.Name.IndexOf("@") >= 0) { cmd.callbackLabel = user.Name.Substring(user.Name.IndexOf("@") + 1); } else { cmd.callbackLabel = user.Name; } remoteCommands.Add(cmd); } }
public override void RunMainWorkflow(bool isDryRun) { remoteCommands = new List <RemoteCommand>(); foreach (UserType user in _wfp.Pscp.Users) { foreach (string source in _wfp.Pscp.Sources) { // Build Argument String StringBuilder args = new StringBuilder(); if (!(String.IsNullOrWhiteSpace(user.Password))) { String ptPassword = Utils.Decrypt(user.Password); if (!(ptPassword.StartsWith("UNABLE TO DECRYPT"))) { args.Append(@"-pw """ + ptPassword + @""" "); } } else if (!string.IsNullOrWhiteSpace(_wfp.Pscp.PrivateKey)) { args.Append(@"-i """ + _wfp.Pscp.PrivateKey + @""" "); } args.Append(@"-batch "); if (!(String.IsNullOrWhiteSpace(_wfp.Pscp.KeepFileAttributes))) { try { _wfp.Pscp._keepFileAttributes = Boolean.Parse(_wfp.Pscp.KeepFileAttributes); } catch (Exception) {} } if (_wfp.Pscp._keepFileAttributes == true) { args.Append(@"-p "); } String srcStr = source; if (srcStr.EndsWith(@"\")) { srcStr += @"\"; } args.Append(@"-r """ + srcStr + @""" "); args.Append(user.Name + @":" + _wfp.Pscp.Destination); RemoteCommand cmd = new RemoteCommand(); if (_wfp.RunUsing == RunUsingProtocolType.ProcessStart) { cmd.server = "localhost"; } else { cmd.server = _wfp.Servers[0]; } if (String.IsNullOrWhiteSpace(_wfp.WorkingDir)) { cmd.command = "pscp.exe"; } else { cmd.command = System.IO.Path.Combine(_wfp.WorkingDir, "pscp.exe"); } cmd.args = args.ToString().Trim(); if (user.Name.IndexOf("@") >= 0) { cmd.callbackLabel = user.Name.Substring(user.Name.IndexOf("@") + 1); } else { cmd.callbackLabel = user.Name; } remoteCommands.Add(cmd); } } // Set Base Class Parameters RunScript(remoteCommands, isDryRun); }