예제 #1
0
파일: uiMethods.py 프로젝트: AsherBond/cato
    def wmSearch(self):
        """
        This function will eventually have lots of flexibility based on the 'type' and 'in' 
        parameters.  For the moment we're starting with the ability to search Task function_xml
        for the pattern.
        
        NOTE: MySql sucks at xml, so if we need to work with an xml object it's faster to retrieve every 
        row and then iterate.  So we'll have to apply a 'like' clause first to limit the set, then work with it.
        """
        _type = uiCommon.getAjaxArg("type")
        _in = uiCommon.getAjaxArg("in")
        _pattern = uiCommon.getAjaxArg("pattern")

        out = {}
        
        if _type == "task":
            # bare essentials - is the pattern in the function_xml column
            where_clause = "where (function_xml like '%%{0}%%')".format(_pattern)
            
            sql = """select t.task_id, t.task_name, t.version, s.codeblock_name, 
                s.step_id, s.step_order, s.function_name, s.function_xml
                from task_step s join task t on s.task_id = t.task_id
                %s""" % (where_clause)
            
            uiCommon.log(sql)
            
            rows = self.db.select_all_dict(sql)
            rows = list(rows) if rows else []
            out["results"] = rows
        else:
            out["error"] = "Invalid search 'type'"
            
        return catocommon.ObjectOutput.AsJSON(out)
예제 #2
0
    def wmUpdateDeploymentDetail(self):
        sDeploymentID = uiCommon.getAjaxArg("id")
        sColumn = uiCommon.getAjaxArg("column")
        sValue = uiCommon.getAjaxArg("value")

        sUserID = uiCommon.GetSessionUserID()

        if catocommon.is_guid(sDeploymentID) and catocommon.is_guid(sUserID):
            d = deployment.Deployment()
            d.FromID(sDeploymentID)

            # 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 = uiCommon.unpackJSON(sValue)

            #  check for existing name
            if sColumn == "Name":
                if d.Name == sValue:
                    return sValue + " exists, please choose another name."

            # cool, update the class attribute by name, using getattr!
            # python is so cool.. I don't even need to check if the attribute I wanna set exists.
            # just set it
            setattr(d, sColumn, sValue)

            d.DBUpdate()
            uiCommon.WriteObjectChangeLog(catocommon.CatoObjectTypes.Deployment, sDeploymentID, sColumn, sValue)

        return json.dumps({"result": "success"})
예제 #3
0
    def wmGetDeploymentsTable(self):
        """ Get a list of all Deployments"""
        sHTML = ""
        pager_html = ""
        sFilter = uiCommon.getAjaxArg("sSearch")
        sPage = uiCommon.getAjaxArg("sPage")
        maxrows = 25

        deps = deployment.Deployments(sFilter)
        if deps.rows:
            start, end, pager_html = uiCommon.GetPager(len(deps.rows), maxrows, sPage)

            for row in deps.rows[start:end]:
                sHTML += u"""
                <tr deployment_id="{0}">
                <td class="chkboxcolumn">    
                    <input type="checkbox" class="chkbox" id="chk_{0}" object_id="{0}" tag="chk" />
                </td>
                
                <td class="selectable">{1}</td>
                <td class="selectable">{2}</td>
                <td class="selectable">{3}</td>
                
                </tr>
                """.format(row["ID"], row["Name"], row["RunState"], row.get("Description", ""))

        return json.dumps({"pager": uiCommon.packJSON(pager_html), "rows": uiCommon.packJSON(sHTML)})
예제 #4
0
파일: uiMethods.py 프로젝트: AsherBond/cato
    def wmGetUsersTable(self):
        sHTML = ""
        pager_html = ""
        sFilter = uiCommon.getAjaxArg("sSearch")
        sPage = uiCommon.getAjaxArg("sPage")
        maxrows = 25

        u = catouser.Users(sFilter)
        if u.rows:
            start, end, pager_html = uiCommon.GetPager(len(u.rows), maxrows, sPage)

            for row in u.rows[start:end]:
                sHTML += "<tr user_id=\"" + row["user_id"] + "\">"
                sHTML += "<td class=\"chkboxcolumn\">"
                sHTML += "<input type=\"checkbox\" class=\"chkbox\"" \
                " id=\"chk_" + row["user_id"] + "\"" \
                " tag=\"chk\" />"
                sHTML += "</td>"

                sHTML += "<td class=\"selectable\">" + row["status"] + "</td>"
                sHTML += "<td class=\"selectable\">" + row["full_name"] + "</td>"
                sHTML += "<td class=\"selectable\">" + row["username"] + "</td>"
                sHTML += "<td class=\"selectable\">" + row["role"] + "</td>"
                sHTML += "<td class=\"selectable\">" + str(row["last_login_dt"]) + "</td>"

                if row["Tags"]:
                    tags = row["Tags"].split(",")
                    tags = "Tags:\n%s" % ("\n".join(tags))
                    sHTML += '<td class="selectable"><span class="ui-icon ui-icon-tag" title="' + tags + '"></span></td>'
                else:
                    sHTML += '<td class="selectable">&nbsp;</td>'

                sHTML += "</tr>"

        return json.dumps({"pager": uiCommon.packJSON(pager_html), "rows": uiCommon.packJSON(sHTML)})
예제 #5
0
 def wmDeleteKeyPair(self):
     sCloudID = uiCommon.getAjaxArg("sCloudID")
     sKeypairID = uiCommon.getAjaxArg("sKeypairID")
     c = cloud.Cloud()
     c.FromID(sCloudID)
     c.DeleteKeyPair(sKeypairID)
     return json.dumps({"result": "success"})
예제 #6
0
    def wmGetCloudsTable(self):
        sHTML = ""
        pager_html = ""
        sFilter = uiCommon.getAjaxArg("sSearch")
        sPage = uiCommon.getAjaxArg("sPage")
        maxrows = 25

        c = cloud.Clouds(sFilter)
        if c.rows:
            start, end, pager_html = uiCommon.GetPager(len(c.rows), maxrows, sPage)

            for row in c.rows[start:end]:
                sHTML += "<tr cloud_id=\"" + row["ID"] + "\">"
                sHTML += "<td class=\"chkboxcolumn\">"
                sHTML += "<input type=\"checkbox\" class=\"chkbox\"" \
                " id=\"chk_" + row["ID"] + "\"" \
                " tag=\"chk\" />"
                sHTML += "</td>"

                sHTML += "<td class=\"selectable\">%s</td>" % row["Name"]
                sHTML += "<td class=\"selectable\">%s</td>" % row["Provider"]
                sHTML += "<td class=\"selectable\">%s</td>" % row["APIUrl"]
                sHTML += "<td class=\"selectable\">%s</td>" % row["APIProtocol"]
                sHTML += "<td class=\"selectable\">%s</td>" % (row["DefaultAccount"] if row["DefaultAccount"] else "&nbsp;")

                sHTML += "</tr>"

        return json.dumps({"pager": uiCommon.packJSON(pager_html), "rows": uiCommon.packJSON(sHTML)})
예제 #7
0
파일: uiMethods.py 프로젝트: AsherBond/cato
    def wmSavePlan(self):
        iPlanID = uiCommon.getAjaxArg("iPlanID")
        sParameterXML = uiCommon.getAjaxArg("sParameterXML")
        iDebugLevel = uiCommon.getAjaxArg("iDebugLevel")
        """
         * JUST AS A REMINDER:
         * There is no parameter 'merging' happening here.  This is a Plan ...
         *   it has ALL the parameters it needs to pass to the CE.
         * 
         * """

        if not iPlanID:
            uiCommon.log("Missing Action Plan ID.")

        # 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.)
        sParameterXML = uiCommon.unpackJSON(sParameterXML)

        # we gotta peek into the XML and encrypt any newly keyed values
        sParameterXML = task.Task.PrepareAndEncryptParameterXML(sParameterXML)

        sSQL = """update action_plan
            set parameter_xml = %s,
            debug_level = %s
            where plan_id = %s"""

        self.db.exec_db(sSQL, (sParameterXML, iDebugLevel if iDebugLevel > -1 else None, iPlanID))

        return json.dumps({"result": "success"})
예제 #8
0
    def wmGetTemplatesTable(self):
        """ Get a list of all Deployment Templates"""
        sHTML = ""
        pager_html = ""
        sFilter = uiCommon.getAjaxArg("sSearch")
        sPage = uiCommon.getAjaxArg("sPage")
        maxrows = 25

        deps = deployment.DeploymentTemplates(sFilter, show_unavailable=True)
        if deps.rows:
            start, end, pager_html = uiCommon.GetPager(len(deps.rows), maxrows, sPage)

            for row in deps.rows[start:end]:
                available = 'Yes' if row["Available"] else 'No'

                sHTML += """
                <tr template_id="{0}">
                <td class="chkboxcolumn">    
                    <input type="checkbox" class="chkbox" id="chk_{0}" object_id="{0}" tag="chk" />
                </td>""".format(row["ID"])

                sHTML += '<td class="selectable">' + row["Name"] + '</td>'
                sHTML += '<td class="selectable">' + row["Version"] + '</td>'
                sHTML += '<td class="selectable">' + (row["Description"] if row["Description"] else "") + '</td>'
                sHTML += '<td class="selectable">' + available + '</td>'

                sHTML += "</tr>"

        return json.dumps({"pager": uiCommon.packJSON(pager_html), "rows": uiCommon.packJSON(sHTML)})
예제 #9
0
    def wmCreateTag(self):
        sTagName = uiCommon.getAjaxArg("sTagName")
        sDesc = uiCommon.getAjaxArg("sDescription")
            
        t = tag.Tag(sTagName, sDesc)
        t.DBCreateNew()
        uiCommon.WriteObjectAddLog(catocommon.CatoObjectTypes.Tag, t.Name, t.Name, "Tag Created")

        return t.AsJSON()
예제 #10
0
파일: uiMethods.py 프로젝트: AsherBond/cato
    def wmRunRepeatedly(self):
        sTaskID = uiCommon.getAjaxArg("sTaskID")
        aMonths = uiCommon.getAjaxArg("sMonths")
        aDays = uiCommon.getAjaxArg("sDays")
        aHours = uiCommon.getAjaxArg("sHours")
        aMinutes = uiCommon.getAjaxArg("sMinutes")
        sDaysOrWeeks = uiCommon.getAjaxArg("sDaysOrWeeks")
        sParameterXML = uiCommon.getAjaxArg("sParameterXML")
        iDebugLevel = uiCommon.getAjaxArg("iDebugLevel")
        sAccountID = uiCommon.getAjaxArg("sAccountID")

        # 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.)
        sParameterXML = uiCommon.unpackJSON(sParameterXML)

        sched_def = {
                     "Months": aMonths,
                     "Days": aDays,
                     "Hours": aHours,
                     "Minutes": aMinutes,
                     "DaysOrWeekdays": sDaysOrWeeks
                     }

        t = task.Task()
        t.FromID(sTaskID)
        t.RunRepeatedly(sched_def, sParameterXML, iDebugLevel, sAccountID)
예제 #11
0
    def wmCreateTemplate(self):
        name = uiCommon.getAjaxArg("name")
        version = uiCommon.getAjaxArg("version")
        desc = uiCommon.getAjaxArg("desc")
        template = uiCommon.getAjaxArg("template")

        t = deployment.DeploymentTemplate.DBCreateNew(name, version, uiCommon.unpackJSON(template), uiCommon.unpackJSON(desc))
        if t is not None:
            # create matching tags... this template gets all the tags this user has.

            uiCommon.WriteObjectAddLog(catocommon.CatoObjectTypes.Deployment, t.ID, t.Name, "Deployment Template created.")
            return json.dumps({"template_id": t.ID})
예제 #12
0
    def wmCopyTemplate(self):
        name = uiCommon.getAjaxArg("name")
        version = uiCommon.getAjaxArg("version")
        template = uiCommon.getAjaxArg("template")

        t = deployment.DeploymentTemplate()
        t.FromID(template)
        obj = t.DBCopy(name, version)

        if obj is not None:
            # TODO: create matching tags... this template gets all the tags this user has.

            uiCommon.WriteObjectAddLog(catocommon.CatoObjectTypes.Deployment, obj.ID, obj.Name, "Deployment Template created.")
            return json.dumps({"template_id": t.ID})
예제 #13
0
    def wmDeleteDeploymentGroup(self):
        sDeploymentID = uiCommon.getAjaxArg("id")
        sGroupName = uiCommon.getAjaxArg("group_name")

        sUserID = uiCommon.GetSessionUserID()

        if catocommon.is_guid(sDeploymentID) and catocommon.is_guid(sUserID):
            d = deployment.Deployment()
            d.FromID(sDeploymentID)

            d.DeleteGroup(sGroupName)
            uiCommon.WriteObjectChangeLog(catocommon.CatoObjectTypes.Deployment, sDeploymentID, d.Name, "Removed Group [%s]" % (sGroupName))

        return json.dumps({"result": "success"})
예제 #14
0
파일: uiMethods.py 프로젝트: AsherBond/cato
    def wmRunLater(self):
        sTaskID = uiCommon.getAjaxArg("sTaskID")
        sRunOn = uiCommon.getAjaxArg("sRunOn")
        sParameterXML = uiCommon.getAjaxArg("sParameterXML")
        iDebugLevel = uiCommon.getAjaxArg("iDebugLevel")
        sAccountID = uiCommon.getAjaxArg("sAccountID")

        # 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.)
        sParameterXML = uiCommon.unpackJSON(sParameterXML)

        t = task.Task()
        t.FromID(sTaskID)
        t.RunLater(sRunOn, sParameterXML, iDebugLevel, sAccountID)
예제 #15
0
    def wmSaveAccount(self):
        sMode = uiCommon.getAjaxArg("sMode")
        sAccountID = uiCommon.getAjaxArg("sAccountID")
        sAccountName = uiCommon.getAjaxArg("sAccountName")
        sAccountNumber = uiCommon.getAjaxArg("sAccountNumber")
        sProvider = uiCommon.getAjaxArg("sProvider")
        sDefaultCloudID = uiCommon.getAjaxArg("sDefaultCloudID")
        sLoginID = uiCommon.getAjaxArg("sLoginID")
        sLoginPassword = uiCommon.getAjaxArg("sLoginPassword")
        sLoginPasswordConfirm = uiCommon.getAjaxArg("sLoginPasswordConfirm")
        sIsDefault = uiCommon.getAjaxArg("sIsDefault")
        # sAutoManageSecurity = uiCommon.getAjaxArg("sAutoManageSecurity")

        if sLoginPassword != sLoginPasswordConfirm:
            return json.dumps({"info": "Passwords must match."})

        if sMode == "add":
            ca = cloud.CloudAccount.DBCreateNew(sProvider, sAccountName, sLoginID, sLoginPassword, sAccountNumber, sDefaultCloudID, sIsDefault)
            uiCommon.WriteObjectAddLog(catocommon.CatoObjectTypes.CloudAccount, ca.ID, ca.Name, "Account Created")

        elif sMode == "edit":
            ca = cloud.CloudAccount()
            ca.FromID(sAccountID)
            ca.ID = sAccountID
            ca.Name = sAccountName
            ca.AccountNumber = sAccountNumber
            ca.LoginID = sLoginID
            ca.LoginPassword = sLoginPassword
            ca.IsDefault = (True if sIsDefault == "1" else False)

            # get the cloud
            c = cloud.Cloud()
            c.FromID(sDefaultCloudID)
            if not c:
                return json.dumps({"error": "Unable to reconcile default Cloud from ID [%s]." % sDefaultCloudID})
            ca.DefaultCloud = c

            # note: we must reassign the whole provider
            # changing the name screws up the CloudProviders object in the session, which is writable! (oops)
            ca.Provider = cloud.Provider.FromName(sProvider)
            ca.DBUpdate()

            uiCommon.WriteObjectPropertyChangeLog(catocommon.CatoObjectTypes.CloudAccount, ca.ID, ca.Name, "", ca.Name)

        if ca:
            return ca.AsJSON()
        else:
            return json.dumps({"error": "Unable to save Cloud Account using mode [%s]." % sMode})
예제 #16
0
파일: uiMethods.py 프로젝트: AsherBond/cato
    def wmGetActionSchedules(self):
        sTaskID = uiCommon.getAjaxArg("sTaskID")
        sHTML = ""

        t = task.Task()
        t.FromID(sTaskID)
        schedules = t.GetSchedules()

        for dr in schedules:
            sToolTip = ""
            sToolTip += dr.get("Description", "")

            # draw it
            sHTML += " <div class=\"ui-widget-content ui-corner-all pointer clearfloat action_schedule\"" \
                " id=\"as_" + dr["ScheduleID"] + "\">"
            sHTML += " <div class=\"floatleft schedule_name\">"

            sHTML += "<span class=\"floatleft ui-icon ui-icon-calculator schedule_tip\" title=\"" + sToolTip + "\"></span>"

            sHTML += (dr["ScheduleID"] if not dr["Label"] else dr["Label"])

            sHTML += " </div>"

            sHTML += " <div class=\"floatright\">"
            sHTML += "<span class=\"ui-icon ui-icon-trash schedule_remove_btn\" title=\"Delete Schedule\"></span>"
            sHTML += " </div>"


            sHTML += " </div>"

        return sHTML
예제 #17
0
    def wmValidateTemplate(self):
        template_json = uiCommon.getAjaxArg("template")
        dt, validation_err = deployment.DeploymentTemplate.ValidateJSON(template_json)
        if dt:
            return json.dumps({"result": "success"})

        raise InfoException(validation_err.replace("\n", "<br />"))
예제 #18
0
파일: uiMethods.py 프로젝트: AsherBond/cato
    def wmGetRecurringPlan(self):
        sScheduleID = uiCommon.getAjaxArg("sScheduleID")
        # tracing this backwards, if the action_plan table has a row marked "schedule" but no schedule_id, problem.
        if not sScheduleID:
            uiCommon.log("Unable to retrieve Reccuring Plan - schedule id argument not provided.")

        sched = {}

        # now we know the details, go get the timetable for that specific schedule
        sSQL = """select schedule_id, months, days, hours, minutes, days_or_weeks, label
            from action_schedule
            where schedule_id = %s"""
        dr = self.db.select_row_dict(sSQL, (sScheduleID))
        if dr:
            sDesc = (dr["schedule_id"] if not dr["label"] else dr["label"])

            sched["sDescription"] = sDesc
            sched["sMonths"] = dr["months"]
            sched["sDays"] = dr["days"]
            sched["sHours"] = dr["hours"]
            sched["sMinutes"] = dr["minutes"]
            sched["sDaysOrWeeks"] = str(dr["days_or_weeks"])
        else:
            uiCommon.log("Unable to find details for Recurring Action Plan. " + self.db.error + " ScheduleID [" + sScheduleID + "]")

        return json.dumps(sched)
예제 #19
0
    def wmGetTemplateDeployments(self):
        template_id = uiCommon.getAjaxArg("template_id")

        sHTML = ""

        t = deployment.DeploymentTemplate()
        t.FromID(template_id)
        deps = t.GetDeployments()
        sHTML += "<ul>"
        for d in deps:
            desc = (d["Description"] if d["Description"] else "")

            sHTML += "<li class=\"ui-widget-content ui-corner-all\"" \
                " deployment_id=\"" + d["ID"] + "\"" \
                "\">"
            sHTML += "<div class=\"step_header_title deployment_name\">"
            sHTML += "<img src=\"static/images/icons/deployments_24.png\" alt=\"\" /> " + d["Name"]
            sHTML += "</div>"

            sHTML += "<div class=\"step_header_icons\">"

            # if there's a description, show a tooltip
            if desc:
                sHTML += "<span class=\"ui-icon ui-icon-info deployment_tooltip\" title=\"" + desc + "\"></span>"

            sHTML += "</div>"
            sHTML += "<div class=\"clearfloat\"></div>"
            sHTML += "</li>"

        sHTML += "</ul>"

        return sHTML
예제 #20
0
    def wmDeleteTemplates(self):
        sDeleteArray = uiCommon.getAjaxArg("sDeleteArray")
        if len(sDeleteArray) < 36:
            raise InfoException("Unable to delete - no selection.")

        sDeleteArray = uiCommon.QuoteUp(sDeleteArray)

        # can't delete it if it's referenced.
        sSQL = """select count(*) from deployment d
            join deployment_template dt on d.template_id = dt.template_id
            where dt.template_id in (%s)""" % sDeleteArray

        iResults = self.db.select_col_noexcep(sSQL)

        if not iResults:
            sSQL = "delete from deployment_template where template_id in (" + sDeleteArray + ")"
            if not self.db.tran_exec_noexcep(sSQL):
                uiCommon.log_nouser(self.db.error, 0)

            # if we made it here, save the logs
            uiCommon.WriteObjectDeleteLog(catocommon.CatoObjectTypes.DeploymentTemplate, "", "", "Templates(s) Deleted [" + sDeleteArray + "]")
        else:
            raise InfoException("Unable to delete - %d Deployments are referencing these templates." % iResults)

        return json.dumps({"result": "success"})
예제 #21
0
파일: uiMethods.py 프로젝트: AsherBond/cato
    def wmSaveMyAccount(self):
        """
            In this method, the values come from the browser in a jQuery serialized array of name/value pairs.
        """
        user_id = uiCommon.GetSessionUserID()
        args = uiCommon.getAjaxArg("values")

        u = catouser.User()
        u.FromID(user_id)

        if u.ID:
            # if a password was provided...
            # these changes are done BEFORE we manipulate the user properties for update.
            new_pw = uiCommon.unpackJSON(args.get("my_password"))
            if new_pw:
                u.ChangePassword(new_password=new_pw)
                uiCommon.WriteObjectChangeLog(catocommon.CatoObjectTypes.User, u.ID, u.FullName, "Password changed.")

            # now the other values...
            u.Email = args.get("my_email")
            u.SecurityQuestion = args.get("my_question")
            u.SecurityAnswer = uiCommon.unpackJSON(args.get("my_answer"))

            if u.DBUpdate():
                uiCommon.WriteObjectChangeLog(catocommon.CatoObjectTypes.User, u.ID, u.ID, "User updated.")

        return json.dumps({"result": "success"})
예제 #22
0
    def wmUpdateTag(self):
        sTagName = uiCommon.getAjaxArg("sTagName")
        sNewTagName = uiCommon.getAjaxArg("sNewTagName")
        sDesc = uiCommon.getAjaxArg("sDescription")
            
        t = tag.Tag(sTagName, sDesc)
        
        # update the description
        if sDesc:
            t.DBUpdate()

        # and possibly rename it
        if sNewTagName:
            t.DBRename(sNewTagName)

        return json.dumps({"result": "success"})
예제 #23
0
 def wmGetProvider(self):
     sProvider = uiCommon.getAjaxArg("sProvider")
     if sProvider:
         p = cloud.Provider.FromName(sProvider)
         return p.AsJSON()
     else:
         return json.dumps({"info": "No Cloud Accounts are defined."})
예제 #24
0
    def wmRemoveObjectTag(self):
        sObjectID = uiCommon.getAjaxArg("sObjectID")
        sObjectType = uiCommon.getAjaxArg("sObjectType")
        sTagName = uiCommon.getAjaxArg("sTagName")
        iObjectType = int(sObjectType)

        # fail on missing values
        if iObjectType < 0:
            raise Exception("Invalid Object Type.")
        if not sObjectID or not sTagName:
            raise Exception("Missing or invalid Object ID or Tag Name.")

        tag.ObjectTags.Remove(sTagName, sObjectID)
        uiCommon.WriteObjectChangeLog(iObjectType, sObjectID, "", "Tag [%s] removed." % (sTagName))

        return json.dumps({"result": "success"})
예제 #25
0
    def wmGetTagList(self):
        sObjectID = uiCommon.getAjaxArg("sObjectID")
        sHTML = ""

        # # this will be from lu_tags table
        # if the passed in objectid is empty, get them all, otherwise filter by it
        if sObjectID:
            sSQL = """select tag_name, tag_desc
                from tags
                where tag_name not in (
                select tag_name from object_tags where object_id = '%s'
                )
                order by tag_name""" % (sObjectID)
        else:
            sSQL = "select tag_name, tag_desc from tags order by tag_name"

        dt = self.db.select_all_dict(sSQL)
        if dt:                
            sHTML += "<ul>"
            for dr in dt:
                desc = (dr["tag_desc"].replace("\"", "").replace("'", "") if dr["tag_desc"] else "")
                sHTML += """<li class="tag_picker_tag ui-widget-content ui-corner-all" id="tpt_{0}" desc="{1}">{0}</li>""".format(dr["tag_name"], desc)
            sHTML += "</ul>"
        else:
            sHTML += "No Unassociated Tags exist."

        return sHTML
예제 #26
0
파일: uiMethods.py 프로젝트: AsherBond/cato
    def wmGetCredentialsJSON(self):
        sFilter = uiCommon.getAjaxArg("sFilter")

        ac = asset.Credentials(sFilter)
        if ac:
            return ac.AsJSON()
        # should not get here if all is well
        return json.dumps({"result": "fail", "error": "Failed to get Credentials using filter [%s]." % (sFilter)})
예제 #27
0
파일: uiMethods.py 프로젝트: AsherBond/cato
    def wmAssetSearch(self):
        sFilter = uiCommon.getAjaxArg("sSearch")
        sAllowMultiSelect = uiCommon.getAjaxArg("bAllowMultiSelect")
        bAllowMultiSelect = catocommon.is_true(sAllowMultiSelect)

        a = asset.Assets(sFilter)
        if a.rows:
            sHTML = "<hr />"

            iRowsToGet = len(a.rows)

            if iRowsToGet == 0:
                sHTML += "No results found"
            else:
                if iRowsToGet >= 100:
                    sHTML += "<div>Search found " + iRowsToGet + " results.  Displaying the first 100.</div>"
                    iRowsToGet = 99

                sHTML += "<ul id=\"search_asset_ul\" class=\"search_dialog_ul\">"

                i = 0
                for row in a.rows:
                    if i > iRowsToGet:
                        break

                    sHTML += "<li class=\"ui-widget-content ui-corner-all search_dialog_value\" tag=\"asset_picker_row\"" \
                        " asset_id=\"" + row["ID"] + "\"" \
                        " asset_name=\"" + row["Name"] + "\"" \
                        "\">"
                    sHTML += "<div class=\"search_dialog_value_name\">"
                    if bAllowMultiSelect:
                        sHTML += "<input type='checkbox' name='assetcheckboxes' id='assetchk_" + row["ID"] + "' value='assetchk_" + row["ID"] + "'>"
                    sHTML += "<span>" + row["Name"] + "</span>"
                    sHTML += "</div>"

                    sHTML += "<span class=\"search_dialog_value_inline_item\">Address: " + row["Address"] + "</span>"

                    sHTML += "</li>"

                    i += 1

            sHTML += "</ul>"

        return sHTML
예제 #28
0
    def wmSaveKeyPair(self):
        sKeypairID = uiCommon.getAjaxArg("sKeypairID")
        sCloudID = uiCommon.getAjaxArg("sCloudID")
        sName = uiCommon.getAjaxArg("sName")
        sPK = uiCommon.getAjaxArg("sPK")
        sPP = uiCommon.getAjaxArg("sPP")

        sPK = uiCommon.unpackJSON(sPK)

        c = cloud.Cloud()
        c.FromID(sCloudID)

        if not sKeypairID:
            # keypair_id not passed in, create a new one...
            c.AddKeyPair(sName, sPK, sPP)
        else:
            c.SaveKeyPair(sKeypairID, sName, sPK, sPP)

        return json.dumps({"result": "success"})
예제 #29
0
파일: uiMethods.py 프로젝트: AsherBond/cato
    def wmDeleteAssets(self):
        sDeleteArray = uiCommon.getAjaxArg("sDeleteArray")
        sDeleteArray = uiCommon.QuoteUp(sDeleteArray)

        if not sDeleteArray:
            raise Exception("Unable to delete - no selection.")

        asset.Assets.Delete(sDeleteArray.split(","))

        uiCommon.WriteObjectDeleteLog(catocommon.CatoObjectTypes.Asset, "Multiple", "Original Asset IDs", sDeleteArray)
        return json.dumps({"result": "success"})
예제 #30
0
파일: uiMethods.py 프로젝트: AsherBond/cato
    def wmDeleteActionPlan(self):
        iPlanID = uiCommon.getAjaxArg("iPlanID")

        if iPlanID < 1:
            uiCommon.log("Missing Action Plan ID.")
            return "Missing Action Plan ID."

        task.Task.DeletePlan(iPlanID)
        #  if we made it here, so save the logs
        uiCommon.WriteObjectDeleteLog(catocommon.CatoObjectTypes.Schedule, "", "", "Action Plan [" + iPlanID + "] deleted.")

        return json.dumps({"result": "success"})