public static string LoadAccount(string sID) { dataAccess dc = new dataAccess(); string sSql = null; string sErr = null; string sAccountName = null; string sAccountNumber = null; string sProvider = null; string sIsDefault = null; string sAutoManage = null; string sLoginID = null; string sLoginPassword = null; sSql = "select account_id, account_name, account_number, provider, login_id, is_default, auto_manage_security" + " from cloud_account where account_id = '" + sID + "'"; StringBuilder sb = new StringBuilder(); DataRow dr = null; if (!dc.sqlGetDataRow(ref dr, sSql, ref sErr)) { throw new Exception(sErr); } else { if (dr != null) { sAccountName = (object.ReferenceEquals(dr["account_name"], DBNull.Value) ? "" : dr["account_name"].ToString()); sAccountNumber = (object.ReferenceEquals(dr["account_number"], DBNull.Value) ? "" : dr["account_number"].ToString()); sProvider = (object.ReferenceEquals(dr["provider"], DBNull.Value) ? "" : dr["provider"].ToString()); sIsDefault = (object.ReferenceEquals(dr["is_default"], DBNull.Value) ? "0" : (dc.IsTrue(dr["is_default"].ToString()) ? "1" : "0")); sAutoManage = (object.ReferenceEquals(dr["auto_manage_security"], DBNull.Value) ? "" : dr["auto_manage_security"].ToString()); sLoginID = (object.ReferenceEquals(dr["login_id"], DBNull.Value) ? "" : dr["login_id"].ToString()); sLoginPassword = "******"; // Return the object as a JSON sb.Append("{"); sb.AppendFormat("\"{0}\" : \"{1}\",", "sAccountName", sAccountName); sb.AppendFormat("\"{0}\" : \"{1}\",", "sAccountNumber", sAccountNumber); sb.AppendFormat("\"{0}\" : \"{1}\",", "sProvider", sProvider); sb.AppendFormat("\"{0}\" : \"{1}\",", "sIsDefault", sIsDefault); sb.AppendFormat("\"{0}\" : \"{1}\",", "sAutoManage", sAutoManage); sb.AppendFormat("\"{0}\" : \"{1}\",", "sLoginID", sLoginID); sb.AppendFormat("\"{0}\" : \"{1}\"", "sLoginPassword", sLoginPassword); sb.Append("}"); } else { sb.Append("{}"); } } return sb.ToString(); }
public static string SaveAccount(string sMode, string sAccountID, string sAccountName, string sAccountNumber, string sProvider, string sLoginID, string sLoginPassword, string sLoginPasswordConfirm, string sIsDefault, string sAutoManageSecurity) { // for logging string sOriginalName = ""; dataAccess dc = new dataAccess(); acUI.acUI ui = new acUI.acUI(); string sSql = ""; string sErr = ""; //if we are editing get the original values if (sMode == "edit") { } try { dataAccess.acTransaction oTrans = new dataAccess.acTransaction(ref sErr); // update the user fields. if (sMode == "edit") { sSql = "select account_name from cloud_account " + "where account_id = '" + sAccountID + "'"; if (!dc.sqlGetSingleString(ref sOriginalName, sSql, ref sErr)) throw new Exception("Error getting original account name:" + sErr); // only update the passwword if it has changed string sNewPassword = ""; if (sLoginPassword != "($%#d@x!&") { sNewPassword = "******" + dc.EnCrypt(sLoginPassword) + "'"; } sSql = "update cloud_account set" + " account_name = '" + sAccountName + "'," + " account_number = '" + sAccountNumber + "'," + " provider = '" + sProvider + "'," + " is_default = '" + sIsDefault + "'," + " auto_manage_security = '" + sAutoManageSecurity + "'," + " login_id = '" + sLoginID + "'" + sNewPassword + " where account_id = '" + sAccountID + "'"; oTrans.Command.CommandText = sSql; if (!oTrans.ExecUpdate(ref sErr)) throw new Exception("Error updating account: " + sErr); ui.WriteObjectChangeLog(Globals.acObjectTypes.CloudAccount, sAccountID, sAccountName, sOriginalName, sAccountName);} else { //now, for some reason we were having issues with the initial startup of apache //not able to perform the very first database hit. //this line serves as an inital db hit, but we aren't trapping it or showing the error dc.TestDBConnection(ref sErr); //if there are no rows yet, make this one the default even if the box isn't checked. if (sIsDefault == "0") { int iExists = -1; sSql = "select count(*) as cnt from cloud_account"; if (!dc.sqlGetSingleInteger(ref iExists, sSql, ref sErr)) { System.Threading.Thread.Sleep(300); if (!dc.sqlGetSingleInteger(ref iExists, sSql, ref sErr)) { System.Threading.Thread.Sleep(300); if (!dc.sqlGetSingleInteger(ref iExists, sSql, ref sErr)) throw new Exception("Unable to count Cloud Accounts: " + sErr); } } if (iExists == 0) sIsDefault = "1"; } sAccountID = ui.NewGUID(); sSql = "insert into cloud_account (account_id, account_name, account_number, provider, is_default, login_id, login_password, auto_manage_security)" + " values ('" + sAccountID + "'," + "'" + sAccountName + "'," + "'" + sAccountNumber + "'," + "'" + sProvider + "'," + "'" + sIsDefault + "'," + "'" + sLoginID + "'," + "'" + dc.EnCrypt(sLoginPassword) + "'," + "'" + sAutoManageSecurity + "')"; oTrans.Command.CommandText = sSql; if (!oTrans.ExecUpdate(ref sErr)) throw new Exception("Error creating account: " + sErr); ui.WriteObjectAddLog(Globals.acObjectTypes.CloudAccount, sAccountID, sAccountName, "Account Created"); } //if "default" was selected, unset all the others if (dc.IsTrue(sIsDefault)) { oTrans.Command.CommandText = "update cloud_account set is_default = 0 where account_id <> '" + sAccountID + "'"; if (!oTrans.ExecUpdate(ref sErr)) throw new Exception("Error updating defaults: " + sErr); } oTrans.Commit(); //refresh the cloud account list in the session if (!ui.PutCloudAccountsInSession(ref sErr)) throw new Exception("Error refreshing accounts in session: " + sErr); } catch (Exception ex) { throw new Exception("Error: General Exception: " + ex.Message); } // no errors to here, so return an empty string return "{'account_id':'" + sAccountID + "', 'account_name':'" + sAccountName + "', 'provider':'" + sProvider + "'}"; }
public string wmUpdateTaskDetail(string sTaskID, string sColumn, string sValue) { dataAccess dc = new dataAccess(); acUI.acUI ui = new acUI.acUI(); try { string sUserID = ui.GetSessionUserID(); if (ui.IsGUID(sTaskID) && ui.IsGUID(sUserID)) { string sErr = ""; string sSQL = ""; //we encoded this in javascript before the ajax call. //the safest way to unencode it is to use the same javascript lib. //(sometimes the javascript and .net libs don't translate exactly, google it.) sValue = ui.unpackJSON(sValue); string sOriginalTaskID = ""; sSQL = "select original_task_id from task where task_id = '" + sTaskID + "'"; if (!dc.sqlGetSingleString(ref sOriginalTaskID, sSQL, ref sErr)) throw new Exception("Unable to get original_task_id for [" + sTaskID + "]." + sErr); if (sOriginalTaskID == "") return "Unable to get original_task_id for [" + sTaskID + "]."; // bugzilla 1074, check for existing task_code and task_name if (sColumn == "task_code" || sColumn == "task_name") { sSQL = "select task_id from task where " + sColumn.Replace("'", "''") + "='" + sValue.Replace("'", "''") + "'" + " and original_task_id <> '" + sOriginalTaskID + "'"; string sValueExists = ""; if (!dc.sqlGetSingleString(ref sValueExists, sSQL, ref sErr)) throw new Exception("Unable to check for existing names [" + sTaskID + "]." + sErr); if (!string.IsNullOrEmpty(sValueExists)) return sValue + " exists, please choose another value."; } if (sColumn == "task_code" || sColumn == "task_name") { //changing the name or code updates ALL VERSIONS string sSetClause = sColumn + "='" + sValue.Replace("'", "''") + "'"; sSQL = "update task set " + sSetClause + " where original_task_id = '" + sOriginalTaskID + "'"; } else { string sSetClause = sColumn + "='" + sValue.Replace("'", "''") + "'"; //some columns on this table allow nulls... in their case an empty sValue is a null if (sColumn == "concurrent_instances" || sColumn == "queue_depth") { if (sValue.Replace(" ", "").Length == 0) sSetClause = sColumn + " = null"; else sSetClause = sColumn + "='" + sValue.Replace("'", "''") + "'"; } //some columns are checkboxes, so make sure it is a db appropriate value (1 or 0) //some columns on this table allow nulls... in their case an empty sValue is a null if (sColumn == "concurrent_by_asset") { if (dc.IsTrue(sValue)) sSetClause = sColumn + " = 1"; else sSetClause = sColumn + " = 0"; } sSQL = "update task set " + sSetClause + " where task_id = '" + sTaskID + "'"; } if (!dc.sqlExecuteUpdate(sSQL, ref sErr)) throw new Exception("Unable to update task [" + sTaskID + "]." + sErr); ui.WriteObjectChangeLog(Globals.acObjectTypes.Task, sTaskID, sColumn, sValue); } else { throw new Exception("Unable to update task. Missing or invalid task [" + sTaskID + "] id."); } } catch (Exception ex) { throw ex; } return ""; }
public string wmUpdateTaskParam(string sType, string sID, string sParamID, string sName, string sDesc, string sRequired, string sPrompt, string sEncrypt, string sPresentAs, string sValues) { dataAccess dc = new dataAccess(); acUI.acUI ui = new acUI.acUI(); FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates(); if (!ui.IsGUID(sID)) throw new Exception("Invalid or missing ID."); string sErr = ""; string sSQL = ""; //we encoded this in javascript before the ajax call. //the safest way to unencode it is to use the same javascript lib. //(sometimes the javascript and .net libs don't translate exactly, google it.) sDesc = ui.unpackJSON(sDesc).Trim(); //normalize and clean the values sRequired = (dc.IsTrue(sRequired) ? "true" : "false"); sPrompt = (dc.IsTrue(sPrompt) ? "true" : "false"); sEncrypt = (dc.IsTrue(sEncrypt) ? "true" : "false"); sName = sName.Trim().Replace("'", "''"); string sTable = ""; string sXML = ""; string sParameterXPath = "//parameter[@id = \"" + sParamID + "\"]"; //using this to keep the code below cleaner. if (sType == "ecosystem") sTable = "ecosystem"; else if (sType == "task") sTable = "task"; bool bParamAdd = false; //bool bParamUpdate = false; //if sParamID is empty, we are adding if (string.IsNullOrEmpty(sParamID)) { sParamID = "p_" + ui.NewGUID(); sParameterXPath = "//parameter[@id = \"" + sParamID + "\"]"; //reset this if we had to get a new id //does the task already have parameters? sSQL = "select parameter_xml from " + sTable + " where " + sType + "_id = '" + sID + "'"; if (!dc.sqlGetSingleString(ref sXML, sSQL, ref sErr)) throw new Exception(sErr); string sAddXML = "<parameter id=\"" + sParamID + "\" required=\"" + sRequired + "\" prompt=\"" + sPrompt + "\" encrypt=\"" + sEncrypt + "\">" + "<name>" + sName + "</name>" + "<desc>" + sDesc + "</desc>" + "</parameter>"; if (string.IsNullOrEmpty(sXML)) { //XML doesn't exist at all, add it to the record sAddXML = "<parameters>" + sAddXML + "</parameters>"; sSQL = "update " + sTable + " set " + " parameter_xml = '" + sAddXML + "'" + " where " + sType + "_id = '" + sID + "'"; if (!dc.sqlExecuteUpdate(sSQL, ref sErr)) throw new Exception(sErr); bParamAdd = true; } else { //XML exists, add the node to it ft.AddNodeToXMLColumn(sTable, "parameter_xml", sType + "_id = '" + sID + "'", "//parameters", sAddXML); bParamAdd = true; } } else { //update the node values ft.SetNodeValueinXMLColumn(sTable, "parameter_xml", sType + "_id = '" + sID + "'", sParameterXPath + "/name", sName); ft.SetNodeValueinXMLColumn(sTable, "parameter_xml", sType + "_id = '" + sID + "'", sParameterXPath + "/desc", sDesc); //and the attributes ft.SetNodeAttributeinXMLColumn(sTable, "parameter_xml", sType + "_id = '" + sID + "'", sParameterXPath, "required", sRequired); ft.SetNodeAttributeinXMLColumn(sTable, "parameter_xml", sType + "_id = '" + sID + "'", sParameterXPath, "prompt", sPrompt); ft.SetNodeAttributeinXMLColumn(sTable, "parameter_xml", sType + "_id = '" + sID + "'", sParameterXPath, "encrypt", sEncrypt); bParamAdd = false; } // not clean at all handling both tasks and ecosystems in the same method, but whatever. if (bParamAdd) { if (sType == "task") { ui.WriteObjectAddLog(Globals.acObjectTypes.Task, sID, "Parameter", "Added Parameter:" + sName ); }; if (sType == "ecosystem") { ui.WriteObjectAddLog(Globals.acObjectTypes.Ecosystem, sID, "Parameter", "Added Parameter:" + sName); }; } else { // would be a lot of trouble to add the from to, why is it needed you have each value in the log, just scroll back // so just add a changed message to the log if (sType == "task") { dc.addSecurityLog(ui.GetSessionUserID(), Globals.SecurityLogTypes.Object, Globals.SecurityLogActions.ObjectModify, Globals.acObjectTypes.Task, sID, "Parameter Changed:[" + sName + "]", ref sErr); }; if (sType == "ecosystem") { dc.addSecurityLog(ui.GetSessionUserID(), Globals.SecurityLogTypes.Object, Globals.SecurityLogActions.ObjectModify, Globals.acObjectTypes.Ecosystem, sID, "Parameter Changed:[" + sName + "]", ref sErr); }; } //update the values string[] aValues = sValues.Split('|'); string sValueXML = ""; foreach (string sVal in aValues) { string sReadyValue = ""; //if encrypt is true we MIGHT want to encrypt this value. //but it might simply be a resubmit of an existing value in which case we DON'T //if it has oev: as a prefix, it needs no additional work if (dc.IsTrue(sEncrypt)) { if (sVal.IndexOf("oev:") > -1) sReadyValue = sVal.Replace("oev:", ""); else sReadyValue = dc.EnCrypt(ui.unpackJSON(sVal)); } else { sReadyValue = ui.unpackJSON(sVal); } sValueXML += "<value id=\"pv_" + ui.NewGUID() + "\">" + sReadyValue + "</value>"; } sValueXML = "<values present_as=\"" + sPresentAs + "\">" + sValueXML + "</values>"; //whack-n-add ft.RemoveNodeFromXMLColumn(sTable, "parameter_xml", sType + "_id = '" + sID + "'", sParameterXPath + "/values"); ft.AddNodeToXMLColumn(sTable, "parameter_xml", sType + "_id = '" + sID + "'", sParameterXPath, sValueXML); return ""; }
public string wmGetTaskParam(string sType, string sID, string sParamID) { dataAccess dc = new dataAccess(); acUI.acUI ui = new acUI.acUI(); if (!ui.IsGUID(sID)) throw new Exception("Invalid or missing ID."); try { string sTable = ""; if (sType == "ecosystem") sTable = "ecosystem"; else if (sType == "task") sTable = "task"; //default values if adding - get overridden if there is a record string sName = ""; string sDesc = ""; string sRequired = "false"; string sPrompt = "true"; string sEncrypt = "false"; string sValuesHTML = ""; string sPresentAs = "value"; if (!string.IsNullOrEmpty(sParamID)) { string sErr = ""; string sXML = ""; string sSQL = "select parameter_xml" + " from " + sTable + " where " + sType + "_id = '" + sID + "'"; if (!dc.sqlGetSingleString(ref sXML, sSQL, ref sErr)) throw new Exception("Unable to get parameter_xml. " + sErr); if (sXML != "") { XDocument xd = XDocument.Parse(sXML); if (xd == null) throw new Exception("XML parameter data is invalid."); XElement xParameter = xd.XPathSelectElement("//parameter[@id = \"" + sParamID + "\"]"); if (xParameter == null) return "Error: XML does not contain parameter."; XElement xName = xParameter.XPathSelectElement("name"); if (xName == null) return "Error: XML does not contain parameter name."; XElement xDesc = xParameter.XPathSelectElement("desc"); if (xDesc == null) return "Error: XML does not contain parameter description."; sName = xName.Value; sDesc = xDesc.Value; if (xParameter.Attribute("required") != null) sRequired = xParameter.Attribute("required").Value; if (xParameter.Attribute("prompt") != null) sPrompt = xParameter.Attribute("prompt").Value; if (xParameter.Attribute("encrypt") != null) sEncrypt = xParameter.Attribute("encrypt").Value; XElement xValues = xd.XPathSelectElement("//parameter[@id = \"" + sParamID + "\"]/values"); if (xValues != null) { if (xValues.Attribute("present_as") != null) sPresentAs = xValues.Attribute("present_as").Value; int i = 0; IEnumerable<XElement> xVals = xValues.XPathSelectElements("value"); foreach (XElement xVal in xVals) { //since we can delete each item from the page it needs a unique id. string sPID = "pv" + ui.NewGUID(); string sValue = xVal.Value; string sObscuredValue = ""; if (dc.IsTrue(sEncrypt)) { // 1) obscure the ENCRYPTED value and make it safe to be an html attribute // 2) return some stars so the user will know a value is there. sObscuredValue = "oev=\"" + ui.packJSON(sValue) + "\""; sValue = ""; } sValuesHTML += "<div id=\"" + sPID + "\">" + "<textarea class=\"param_edit_value\" rows=\"1\" " + sObscuredValue + ">" + sValue + "</textarea>"; if (i > 0) { string sHideDel = (sPresentAs == "list" || sPresentAs == "dropdown" ? "" : " hidden"); sValuesHTML += " <img class=\"param_edit_value_remove_btn pointer " + sHideDel + "\" remove_id=\"" + sPID + "\"" + " src=\"../images/icons/fileclose.png\" alt=\"\" />"; } sValuesHTML += "</div>"; i++; } } else { //if, when getting the parameter, there are no values... add one. We don't want a parameter with no values //AND - no remove button on this only value sValuesHTML += "<div id=\"pv" + ui.NewGUID() + "\">" + "<textarea class=\"param_edit_value\" rows=\"1\"></textarea></div>"; } } else { throw new Exception("Unable to get parameter details. Not found."); } } else { //if, when getting the parameter, there are no values... add one. We don't want a parameter with no values //AND - no remove button on this only value sValuesHTML += "<div id=\"pv" + ui.NewGUID() + "\">" + "<textarea class=\"param_edit_value\" rows=\"1\"></textarea></div>"; } //this draws no matter what, if it's empty it's just an add dialog string sHTML = ""; sHTML += "Name: <input type=\"text\" class=\"w95pct\" id=\"param_edit_name\"" + " validate_as=\"variable\" value=\"" + sName + "\" />"; sHTML += "Options:<div class=\"param_edit_options\">"; sHTML += "<span class=\"ui-widget-content ui-corner-all param_edit_option\"><input type=\"checkbox\" id=\"param_edit_required\"" + (sRequired == "true" ? "checked=\"checked\"" : "") + " /> Required?</span>"; sHTML += "<span class=\"ui-widget-content ui-corner-all param_edit_option\"><input type=\"checkbox\" id=\"param_edit_prompt\"" + (sPrompt == "true" ? "checked=\"checked\"" : "") + " /> Prompt?</span>"; sHTML += "<span class=\"ui-widget-content ui-corner-all param_edit_option\"><input type=\"checkbox\" id=\"param_edit_encrypt\"" + (sEncrypt == "true" ? "checked=\"checked\"" : "") + " /> Encrypt?</span>"; sHTML += "</div>"; sHTML += "<br />Description: <br /><textarea id=\"param_edit_desc\" rows=\"2\">" + sDesc + "</textarea>"; sHTML += "<div id=\"param_edit_values\">Values:<br />"; sHTML += "Present As: <select id=\"param_edit_present_as\">"; sHTML += "<option value=\"value\"" + (sPresentAs == "value" ? "selected=\"selected\"" : "") + ">Value</option>"; sHTML += "<option value=\"list\"" + (sPresentAs == "list" ? "selected=\"selected\"" : "") + ">List</option>"; sHTML += "<option value=\"dropdown\"" + (sPresentAs == "dropdown" ? "selected=\"selected\"" : "") + ">Dropdown</option>"; sHTML += "</select>"; sHTML += "<hr />" + sValuesHTML + "</div>"; //if it's not available for this presentation type, it will get the "hidden" class but still be drawn string sHideAdd = (sPresentAs == "list" || sPresentAs == "dropdown" ? "" : " hidden"); sHTML += "<div id=\"param_edit_value_add_btn\" class=\"pointer " + sHideAdd + "\">" + "<img title=\"Add Another\" alt=\"\" src=\"../images/icons/edit_add.png\" style=\"width: 10px;" + " height: 10px;\" />( click to add a value )</div>"; return sHTML; } catch (Exception ex) { throw ex; } }
public string wmRerunTask(int iInstanceID, string sClearLog) { dataAccess dc = new dataAccess(); acUI.acUI ui = new acUI.acUI(); try { string sUserID = ui.GetSessionUserID(); if (iInstanceID > 0 && ui.IsGUID(sUserID)) { string sInstance = ""; string sErr = ""; string sSQL = ""; if (dc.IsTrue(sClearLog)) { sSQL = "delete from task_instance_log" + " where task_instance = '" + iInstanceID.ToString() + "'"; if (!dc.sqlExecuteUpdate(sSQL, ref sErr)) { throw new Exception("Unable to clear task instance log for [" + iInstanceID.ToString() + "]." + sErr); } } sSQL = "update task_instance set task_status = 'Submitted'," + " submitted_by = '" + sUserID + "'" + " where task_instance = '" + iInstanceID.ToString() + "'"; if (!dc.sqlGetSingleString(ref sInstance, sSQL, ref sErr)) { throw new Exception("Unable to rerun task instance [" + iInstanceID.ToString() + "]." + sErr); } return sInstance; } else { throw new Exception("Unable to run task. Missing or invalid task instance [" + iInstanceID.ToString() + "]"); } } catch (Exception ex) { throw ex; } }
public string wmGetMergedParameterXML(string sType, string sID, string sEcosystemID) { dataAccess dc = new dataAccess(); acUI.acUI ui = new acUI.acUI(); taskMethods tm = new taskMethods(); FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates(); if (string.IsNullOrEmpty(sID)) throw new Exception("ID required to look up default Parameter values."); string sErr = ""; //what is the task associated with this action? //and get the XML for it string sSQL = ""; string sDefaultsXML = ""; string sTaskID = ""; if (sType == "action") { sDefaultsXML = tm.wmGetObjectParameterXML(sType, sID, ""); sSQL = "select t.task_id" + " from ecotemplate_action ea" + " join task t on ea.original_task_id = t.original_task_id" + " and t.default_version = 1" + " where ea.action_id = '" + sID + "'"; } else if (sType == "instance") { sDefaultsXML = tm.wmGetObjectParameterXML(sType, sID, sEcosystemID); //IMPORTANT!!! if the ID is not a guid, it's a specific instance ID, and we'll need to get the task_id //but if it is a GUID, but the type is "instance", taht means the most recent INSTANCE for this TASK_ID if (ui.IsGUID(sID)) sTaskID = sID; else sSQL = "select task_id" + " from task_instance" + " where task_instance = '" + sID + "'"; } else if (sType == "plan") { sDefaultsXML = tm.wmGetObjectParameterXML(sType, sID, ""); sSQL = "select task_id" + " from action_plan" + " where plan_id = '" + sID + "'"; } else if (sType == "schedule") { sDefaultsXML = tm.wmGetObjectParameterXML(sType, sID, ""); sSQL = "select task_id" + " from action_schedule" + " where schedule_id = '" + sID + "'"; } //if we didn't get a task id directly, use the SQL to look it up if (string.IsNullOrEmpty(sTaskID)) if (!dc.sqlGetSingleString(ref sTaskID, sSQL, ref sErr)) throw new Exception(sErr); if (!ui.IsGUID(sTaskID)) throw new Exception("Unable to find Task ID for record."); XDocument xTPDoc = new XDocument(); XDocument xDefDoc = new XDocument(); //get the parameter XML from the TASK string sTaskParamXML = tm.wmGetParameterXML("task", sTaskID, ""); if (!string.IsNullOrEmpty(sTaskParamXML)) { xTPDoc = XDocument.Parse(sTaskParamXML); if (xTPDoc == null) throw new Exception("Task Parameter XML data is invalid."); XElement xTPParams = xTPDoc.XPathSelectElement("/parameters"); if (xTPParams == null) throw new Exception("Task Parameter XML data does not contain 'parameters' root node."); } //we populated this up above too if (!string.IsNullOrEmpty(sDefaultsXML)) { xDefDoc = XDocument.Parse(sDefaultsXML); if (xDefDoc == null) throw new Exception("Defaults XML data is invalid."); XElement xDefParams = xDefDoc.XPathSelectElement("/parameters"); if (xDefParams == null) throw new Exception("Defaults XML data does not contain 'parameters' root node."); } //spin the nodes in the DEFAULTS xml, then dig in to the task XML and UPDATE the value if found. //(if the node no longer exists, delete the node from the defaults xml IF IT WAS AN ACTION) //and default "values" take precedence over task values. foreach (XElement xDefault in xDefDoc.XPathSelectElements("//parameter")) { //nothing to do if it's empty if (xDefault == null) break; //look it up in the task param xml XElement xDefName = xDefault.XPathSelectElement("name"); string sDefName = (xDefName == null ? "" : xDefName.Value); XElement xDefValues = xDefault.XPathSelectElement("values"); //nothing to do if there is no values node... if (xDefValues == null) break; //or if it contains no values. if (!xDefValues.HasElements) break; //or if there is no parameter name if (string.IsNullOrEmpty(sDefName)) break; //so, we have some valid data in the defaults xml... let's merge! //we have the name of the parameter... go find it in the TASK param XML XElement xTaskParam = xTPDoc.XPathSelectElement("//parameter/name[. = '" + sDefName + "']/.."); //NOTE! the /.. gets the parent of the name node! //if it doesn't exist in the task params, remove it from this document, permanently //but only for action types... instance data is historical and can't be munged if (xTaskParam == null && sType == "action") { ft.RemoveNodeFromXMLColumn("ecotemplate_action", "parameter_defaults", "action_id = '" + sID + "'", "//parameter/name[. = '" + sDefName + "']/.."); continue; } //is this an encrypted parameter? string sEncrypt = ""; if (xTaskParam.Attribute("encrypt") != null) sEncrypt = xTaskParam.Attribute("encrypt").Value; //and the "values" collection will be the 'next' node XElement xTaskParamValues = xTaskParam.XPathSelectElement("values"); string sPresentAs = xTaskParamValues.Attribute("present_as").Value; if (sPresentAs == "dropdown") { //dropdowns get a "selected" indicator string sValueToSelect = xDefValues.XPathSelectElement("value").Value; //find the right one by value and give it the "selected" attribute. XElement xVal = xTaskParamValues.XPathSelectElement("value[. = '" + sValueToSelect + "']"); if (xVal != null) xVal.SetAttributeValue("selected", "true"); } else if (sPresentAs == "list") { //first, a list gets ALL the values replaced... xTaskParamValues.ReplaceNodes(xDefValues); } else { //IMPORTANT NOTE: //remember... both these XML documents came from wmGetObjectParameterXML... //so any encrypted data IS ALREADY OBFUSCATED and base64'd in the oev attribute. //it's a single value, so just replace it with the default. XElement xVal = xTaskParamValues.XPathSelectElement("value[1]"); if (xVal != null) { //if this is an encrypted parameter, we'll be replacing (if a default exists) the oev attribute //AND the value... don't want them to get out of sync! if (dc.IsTrue(sEncrypt)) { if (xDefValues.XPathSelectElement("value") != null) if (xDefValues.XPathSelectElement("value").Attribute("oev") != null) { xVal.SetAttributeValue("oev", xDefValues.XPathSelectElement("value").Attribute("oev").Value); xVal.Value = xDefValues.XPathSelectElement("value").Value; } } else { //not encrypted, just replace the value. if (xDefValues.XPathSelectElement("value") != null) xVal.Value = xDefValues.XPathSelectElement("value").Value; } } } } return xTPDoc.ToString(SaveOptions.DisableFormatting); ; }
public string wmGetParameters(string sType, string sID, bool bEditable, bool bSnipValues) { dataAccess dc = new dataAccess(); acUI.acUI ui = new acUI.acUI(); try { string sErr = ""; string sParameterXML = ""; string sSQL = ""; string sTable = ""; if (sType == "ecosystem") sTable = "ecosystem"; else if (sType == "task") sTable = "task"; sSQL = "select parameter_xml from " + sTable + " where " + sType + "_id = '" + sID + "'"; if (!dc.sqlGetSingleString(ref sParameterXML, sSQL, ref sErr)) { throw new Exception(sErr); } if (sParameterXML != "") { XDocument xDoc = XDocument.Parse(sParameterXML); if (xDoc == null) throw new Exception("Parameter XML data for " + sType + " [" + sID + "] is invalid."); XElement xParams = xDoc.XPathSelectElement("/parameters"); if (xParams == null) throw new Exception("Parameter XML data for " + sType + " [" + sID + "] does not contain 'parameters' root node."); string sHTML = ""; foreach (XElement xParameter in xParams.XPathSelectElements("parameter")) { string sPID = xParameter.Attribute("id").Value; string sName = xParameter.Element("name").Value; string sDesc = xParameter.Element("desc").Value; bool bEncrypt = false; if (xParameter.Attribute("encrypt") != null) bEncrypt = dc.IsTrue(xParameter.Attribute("encrypt").Value); sHTML += "<div class=\"parameter\">"; sHTML += " <div class=\"ui-state-default parameter_header\">"; sHTML += "<div class=\"step_header_title\"><span class=\"parameter_name"; sHTML += (bEditable ? " pointer" : ""); //make the name a pointer if it's editable sHTML += "\" id=\"" + sPID + "\">"; sHTML += sName; sHTML += "</span></div>"; sHTML += "<div class=\"step_header_icons\">"; sHTML += "<img class=\"parameter_help_btn pointer trans50\"" + " src=\"../images/icons/info.png\" alt=\"\" style=\"width: 12px; height: 12px;\"" + " title=\"" + sDesc.Replace("\"", "") + "\" />"; if (bEditable) { sHTML += "<img class=\"parameter_remove_btn pointer\" remove_id=\"" + sPID + "\"" + " src=\"../images/icons/fileclose.png\" alt=\"\" style=\"width: 12px; height: 12px;\" />"; } sHTML += "</div>"; sHTML += "</div>"; sHTML += "<div class=\"ui-widget-content ui-corner-bottom clearfloat parameter_detail\">"; //desc - a short snip is shown here... 75 chars. //if (!string.IsNullOrEmpty(sDesc)) // if (bSnipValues) // sDesc = ui.GetSnip(sDesc, 75); // else // sDesc = ui.FixBreaks(sDesc); //sHTML += "<div class=\"parameter_desc hidden\">" + sDesc + "</div>"; //values XElement xValues = xParameter.XPathSelectElement("values"); if (xValues != null) { foreach (XElement xValue in xValues.XPathSelectElements("value")) { string sValue = (string.IsNullOrEmpty(xValue.Value) ? "" : xValue.Value); //only show stars IF it's encrypted, but ONLY if it has a value if (bEncrypt && !string.IsNullOrEmpty(sValue)) sValue = "********"; else if (bSnipValues) sValue = ui.GetSnip(xValue.Value, 64); else sValue = ui.FixBreaks(xValue.Value); sHTML += "<div class=\"ui-widget-content ui-corner-tl ui-corner-bl parameter_value\">" + sValue + "</div>"; } } sHTML += "</div>"; sHTML += "</div>"; } return sHTML; } } catch (Exception ex) { throw new Exception(ex.Message); } //it may just be there are no parameters return ""; }
public void wmUpdateRegistryValue(string sObjectID, string sXPath, string sValue, string sEncrypt) { dataAccess dc = new dataAccess(); FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates(); //fail on missing values if (string.IsNullOrEmpty(sXPath)) throw new Exception("Missing XPath to update."); //masked means update an attribute AND encrypt the value sEncrypt = (dc.IsTrue(sEncrypt) ? "true" : "false"); sValue = (dc.IsTrue(sEncrypt) ? dc.EnCrypt(sValue) : sValue); //update if (sObjectID == "global") sObjectID = "1"; ft.SetNodeValueinXMLColumn("object_registry", "registry_xml", "object_id = '" + sObjectID + "'", sXPath, sValue); ft.SetNodeAttributeinXMLColumn("object_registry", "registry_xml", "object_id = '" + sObjectID + "'", sXPath, "encrypt", sEncrypt); return; }
public string wmSetScheduler(string sSetToStatus) { acUI.acUI ui = new acUI.acUI(); if (!ui.UserIsInRole("Administrator")) { return "Only an Administrator can perform this action."; } else { if (sSetToStatus == "") { return "Unable to set Scheduler - 'on' or 'off' status argument is required."; } dataAccess dc = new dataAccess(); string sErr = null; /* Simply flips the switch on all pollers and logservers to either on or off based on the argument. */ string sStatus = (dc.IsTrue(sSetToStatus) ? "on" : "off"); try { if (!dc.sqlExecuteUpdate("update scheduler_settings set mode_off_on = '" + sStatus + "'", ref sErr)) { throw new Exception(sErr); } } catch (Exception ex) { throw new Exception(ex.Message); } // add security log dc.addSecurityLog(ui.GetSessionUserID(), SecurityLogTypes.Security, SecurityLogActions.ConfigChange, acObjectTypes.None, "", "Scheduler set to [" + sStatus + "]", ref sErr); // no errors to here, so return an empty string return ""; } }
public void wmSaveActionParameterXML(string sActionID, string sActionDefaultsXML) { dataAccess dc = new dataAccess(); acUI.acUI ui = new acUI.acUI(); taskMethods tm = new taskMethods(); try { string sUserID = ui.GetSessionUserID(); if (ui.IsGUID(sActionID) && ui.IsGUID(sUserID)) { string sErr = ""; string sSQL = ""; //we encoded this in javascript before the ajax call. //the safest way to unencode it is to use the same javascript lib. //(sometimes the javascript and .net libs don't translate exactly, google it.) sActionDefaultsXML = ui.unpackJSON(sActionDefaultsXML); //we gotta peek into the XML and encrypt any newly keyed values PrepareAndEncryptParameterXML(ref sActionDefaultsXML); //so, like when we read it, we gotta spin and compare, and build an XML that only represents *changes* //to the defaults on the task. //what is the task associated with this action? sSQL = "select t.task_id" + " from ecotemplate_action ea" + " join task t on ea.original_task_id = t.original_task_id" + " and t.default_version = 1" + " where ea.action_id = '" + sActionID + "'"; string sTaskID = ""; if (!dc.sqlGetSingleString(ref sTaskID, sSQL, ref sErr)) throw new Exception(sErr); if (!ui.IsGUID(sTaskID)) throw new Exception("Unable to find Task ID for Action."); string sOverrideXML = ""; XDocument xTPDoc = new XDocument(); XDocument xADDoc = new XDocument(); //get the parameter XML from the TASK string sTaskParamXML = tm.wmGetParameterXML("task", sTaskID, ""); if (!string.IsNullOrEmpty(sTaskParamXML)) { xTPDoc = XDocument.Parse(sTaskParamXML); if (xTPDoc == null) throw new Exception("Task Parameter XML data is invalid."); XElement xTPParams = xTPDoc.XPathSelectElement("/parameters"); if (xTPParams == null) throw new Exception("Task Parameter XML data does not contain 'parameters' root node."); } //we had the ACTION defaults handed to us if (!string.IsNullOrEmpty(sActionDefaultsXML)) { xADDoc = XDocument.Parse(sActionDefaultsXML); if (xADDoc == null) throw new Exception("Action Defaults XML data is invalid."); XElement xADParams = xADDoc.XPathSelectElement("/parameters"); if (xADParams == null) throw new Exception("Action Defaults XML data does not contain 'parameters' root node."); } //spin the nodes in the ACTION xml, then dig in to the task XML and UPDATE the value if found. //(if the node no longer exists, delete the node from the action XML) //and action "values" take precedence over task values. //this does a regular loop because we can't remove from an IEnumerable int x = xADDoc.XPathSelectElements("//parameter").Count(); for (int i = (x-1); i>=0; i--) { XElement xDefault = xADDoc.XPathSelectElements("//parameter").ElementAt(i); //look it up in the task param xml XElement xADName = xDefault.XPathSelectElement("name"); string sADName = (xADName == null ? "" : xADName.Value); XElement xADValues = xDefault.XPathSelectElement("values"); //string sValues = (xValues == null ? "" : xValues.ToString()); //now we have the name of the parameter, go find it in the TASK param XML XElement xTaskParam = xTPDoc.XPathSelectElement("//parameter/name[. = '" + sADName + "']/.."); //NOTE! the /.. gets the parent of the name node! //if it doesn't exist in the task params, remove it from this document if (xTaskParam == null) { xDefault.Remove(); continue; } //and the "values" collection will be the 'next' node XElement xTaskParamValues = xTaskParam.XPathSelectElement("values"); //so... it might be //a) just an oev (original encrypted value) so de-base64 it //b) a value flagged for encryption //note we don't care about dirty unencrypted values... they'll compare down below just fine. //is it encrypted? bool bEncrypted = false; if (xTaskParam.Attribute("encrypt") != null) bEncrypted = dc.IsTrue(xTaskParam.Attribute("encrypt").Value); if (bEncrypted) { foreach (XElement xVal in xADValues.XPathSelectElements("value")) { if (xVal.HasAttributes) { //a) is it an oev? unpackJSON it (that's just an obfuscation wrapper) if (xVal.Attribute("oev") != null) { if (dc.IsTrue(xVal.Attribute("oev").Value)) { xVal.Value = ui.unpackJSON(xVal.Value); xVal.SetAttributeValue("oev", null); } } //b) is it do_encrypt? (remove the attribute to keep the db clutter down) if (xVal.Attribute("do_encrypt") != null) { xVal.Value = dc.EnCrypt(xVal.Value); xVal.SetAttributeValue("do_encrypt", null); } } } } //now that the encryption is sorted out, // if the combined values of the parameter happens to match what's on the task // we just remove it. //we're doing combined because of lists (the whole list must match for it to be a dupe) //it's easy to look at all the values in a node with the node.Value property. //but we'll have to manually concatenate all the oev attributes string sTaskVals = ""; string sDefVals = ""; if (bEncrypted) { // the task document already has the oev obfuscated foreach (XAttribute xa in xTaskParamValues.Elements("value").Attributes("oev")) { sTaskVals += xa.Value; } //but the XML we just got from the client doesn't... it's in the value. foreach (XElement xe in xADValues.Elements("value")) { sDefVals += ui.packJSON(xe.Value); } if (sTaskVals.Equals(sDefVals)) { xDefault.Remove(); continue; } } else { if (xTaskParamValues.Value.Equals(xADValues.Value)) { xDefault.Remove(); continue; } } } //done sOverrideXML = xADDoc.ToString(SaveOptions.DisableFormatting); //FINALLY, we have an XML that represents only the differences we wanna save. sSQL = "update ecotemplate_action set" + " parameter_defaults = '" + sOverrideXML + "'" + " where action_id = '" + sActionID + "'"; if (!dc.sqlExecuteUpdate(sSQL, ref sErr)) throw new Exception("Unable to update Eco Template Action [" + sActionID + "]." + sErr); ui.WriteObjectChangeLog(Globals.acObjectTypes.EcoTemplate, sActionID, sActionID, "Action default parameters updated: [" + sOverrideXML + "]"); } else { throw new Exception("Unable to update Eco Template Action. Missing or invalid Action ID."); } } catch (Exception ex) { throw ex; } return; }
public static string LoadAccount(string sID) { dataAccess dc = new dataAccess(); string sSql = null; string sErr = null; string sAccountName = null; string sAccountNumber = null; string sProvider = null; string sIsDefault = null; string sAutoManage = null; string sLoginID = null; string sLoginPassword = null; sSql = "select account_id, account_name, account_number, provider, login_id, is_default, auto_manage_security" + " from cloud_account where account_id = '" + sID + "'"; StringBuilder sb = new StringBuilder(); DataRow dr = null; if (!dc.sqlGetDataRow(ref dr, sSql, ref sErr)) { throw new Exception(sErr); } else { if (dr != null) { sAccountName = (object.ReferenceEquals(dr["account_name"], DBNull.Value) ? "" : dr["account_name"].ToString()); sAccountNumber = (object.ReferenceEquals(dr["account_number"], DBNull.Value) ? "" : dr["account_number"].ToString()); sProvider = (object.ReferenceEquals(dr["provider"], DBNull.Value) ? "" : dr["provider"].ToString()); sIsDefault = (object.ReferenceEquals(dr["is_default"], DBNull.Value) ? "0" : (dc.IsTrue(dr["is_default"].ToString()) ? "1" : "0")); sAutoManage = (object.ReferenceEquals(dr["auto_manage_security"], DBNull.Value) ? "" : dr["auto_manage_security"].ToString()); sLoginID = (object.ReferenceEquals(dr["login_id"], DBNull.Value) ? "" : dr["login_id"].ToString()); sLoginPassword = "******"; // Return the object as a JSON sb.Append("{"); sb.AppendFormat("\"{0}\" : \"{1}\",", "sAccountName", sAccountName); sb.AppendFormat("\"{0}\" : \"{1}\",", "sAccountNumber", sAccountNumber); sb.AppendFormat("\"{0}\" : \"{1}\",", "sProvider", sProvider); sb.AppendFormat("\"{0}\" : \"{1}\",", "sIsDefault", sIsDefault); sb.AppendFormat("\"{0}\" : \"{1}\",", "sAutoManage", sAutoManage); sb.AppendFormat("\"{0}\" : \"{1}\",", "sLoginID", sLoginID); sb.AppendFormat("\"{0}\" : \"{1}\"", "sLoginPassword", sLoginPassword); sb.Append("}"); } else { sb.Append("{}"); } } return(sb.ToString()); }
public static string SaveAccount(string sMode, string sAccountID, string sAccountName, string sAccountNumber, string sProvider, string sLoginID, string sLoginPassword, string sLoginPasswordConfirm, string sIsDefault, string sAutoManageSecurity) { // for logging string sOriginalName = ""; dataAccess dc = new dataAccess(); acUI.acUI ui = new acUI.acUI(); string sSql = ""; string sErr = ""; //if we are editing get the original values if (sMode == "edit") { } try { dataAccess.acTransaction oTrans = new dataAccess.acTransaction(ref sErr); // update the user fields. if (sMode == "edit") { sSql = "select account_name from cloud_account " + "where account_id = '" + sAccountID + "'"; if (!dc.sqlGetSingleString(ref sOriginalName, sSql, ref sErr)) { throw new Exception("Error getting original account name:" + sErr); } // only update the passwword if it has changed string sNewPassword = ""; if (sLoginPassword != "($%#d@x!&") { sNewPassword = "******" + dc.EnCrypt(sLoginPassword) + "'"; } sSql = "update cloud_account set" + " account_name = '" + sAccountName + "'," + " account_number = '" + sAccountNumber + "'," + " provider = '" + sProvider + "'," + " is_default = '" + sIsDefault + "'," + " auto_manage_security = '" + sAutoManageSecurity + "'," + " login_id = '" + sLoginID + "'" + sNewPassword + " where account_id = '" + sAccountID + "'"; oTrans.Command.CommandText = sSql; if (!oTrans.ExecUpdate(ref sErr)) { throw new Exception("Error updating account: " + sErr); } ui.WriteObjectChangeLog(Globals.acObjectTypes.CloudAccount, sAccountID, sAccountName, sOriginalName, sAccountName); } else { //now, for some reason we were having issues with the initial startup of apache //not able to perform the very first database hit. //this line serves as an inital db hit, but we aren't trapping it or showing the error dc.TestDBConnection(ref sErr); //if there are no rows yet, make this one the default even if the box isn't checked. if (sIsDefault == "0") { int iExists = -1; sSql = "select count(*) as cnt from cloud_account"; if (!dc.sqlGetSingleInteger(ref iExists, sSql, ref sErr)) { System.Threading.Thread.Sleep(300); if (!dc.sqlGetSingleInteger(ref iExists, sSql, ref sErr)) { System.Threading.Thread.Sleep(300); if (!dc.sqlGetSingleInteger(ref iExists, sSql, ref sErr)) { throw new Exception("Unable to count Cloud Accounts: " + sErr); } } } if (iExists == 0) { sIsDefault = "1"; } } sAccountID = ui.NewGUID(); sSql = "insert into cloud_account (account_id, account_name, account_number, provider, is_default, login_id, login_password, auto_manage_security)" + " values ('" + sAccountID + "'," + "'" + sAccountName + "'," + "'" + sAccountNumber + "'," + "'" + sProvider + "'," + "'" + sIsDefault + "'," + "'" + sLoginID + "'," + "'" + dc.EnCrypt(sLoginPassword) + "'," + "'" + sAutoManageSecurity + "')"; oTrans.Command.CommandText = sSql; if (!oTrans.ExecUpdate(ref sErr)) { throw new Exception("Error creating account: " + sErr); } ui.WriteObjectAddLog(Globals.acObjectTypes.CloudAccount, sAccountID, sAccountName, "Account Created"); } //if "default" was selected, unset all the others if (dc.IsTrue(sIsDefault)) { oTrans.Command.CommandText = "update cloud_account set is_default = 0 where account_id <> '" + sAccountID + "'"; if (!oTrans.ExecUpdate(ref sErr)) { throw new Exception("Error updating defaults: " + sErr); } } oTrans.Commit(); //refresh the cloud account list in the session if (!ui.PutCloudAccountsInSession(ref sErr)) { throw new Exception("Error refreshing accounts in session: " + sErr); } } catch (Exception ex) { throw new Exception("Error: General Exception: " + ex.Message); } // no errors to here, so return an empty string return("{'account_id':'" + sAccountID + "', 'account_name':'" + sAccountName + "', 'provider':'" + sProvider + "'}"); }