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 "";
        }
Example #2
0
        public string wmSetSystemCondition(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 System condition - 'up' or 'down' status argument is required.";
                }

                dataAccess dc = new dataAccess();
                string sErr = null;

                if (sSetToStatus == "down")
                {
                    wmKickAllUsers();
                    wmSetAllPollers("off");
                    wmSetScheduler("off");

                    //kill all running tasks
                    if (!dc.sqlExecuteUpdate("update task_instance set task_status = 'Aborting' where task_status = 'Processing'", ref sErr))
                    { throw new Exception(sErr); }

                    //lock out users
                    if (!dc.sqlExecuteUpdate("update login_security_settings set allow_login = 0", ref sErr))
                    { throw new Exception(sErr); }

                }
                else
                {
                    wmSetAllPollers("on");
                    wmSetScheduler("on");

                    //allow login
                    if (!dc.sqlExecuteUpdate("update login_security_settings set allow_login = 1", ref sErr))
                    { throw new Exception(sErr); }
                }

                // add security log
                dc.addSecurityLog(ui.GetSessionUserID(), SecurityLogTypes.Security, SecurityLogActions.ConfigChange, acObjectTypes.None, "", "System Condition set to [" + sSetToStatus + "]", ref sErr);

                // no errors to here, so return an empty string
                return "";
            }
        }
Example #3
0
        public bool wmLogout()
        {
            dataAccess dc = new dataAccess();
            acUI.acUI ui = new acUI.acUI();
            try
            {
                string sUserID = ui.GetSessionUserID();
                string sUserName = ui.GetSessionUsername();
                string sErr = "";
                dc.addSecurityLog(sUserID, Globals.SecurityLogTypes.Security, Globals.SecurityLogActions.UserLogout, Globals.acObjectTypes.None, sUserName, "Manual Log Out", ref sErr);
                System.Web.Security.FormsAuthentication.SignOut();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return true;
        }
Example #4
0
        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 "";
            }
        }
Example #5
0
        public string wmKickAllUsers()
        {
            acUI.acUI ui = new acUI.acUI();
            if (!ui.UserIsInRole("Administrator"))
            {
                return "Only an Administrator can perform this action.";
            }
            else
            {
                dataAccess dc = new dataAccess();
                string sErr = null;

                /*
                 Gives all users a one minute warning, then kicks them.
                 */

                try
                {
                    if (!dc.sqlExecuteUpdate("update user_session set kick=1 where user_id in " +
                        " (select user_id from users where user_role <> 'Administrator')"
                        , 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, "", "All Users were just kicked by [" + ui.GetSessionUsername() + "]", ref sErr);

                // no errors to here, so return an empty string
                return "";
            }
        }