예제 #1
0
 def wmGetKeyPairs(self):
     try:
         sID = uiCommon.getAjaxArg("sID")
         sHTML = ""
 
         sSQL = "select keypair_id, keypair_name, private_key, passphrase" \
             " from cloud_account_keypair" \
             " where account_id = '" + sID + "'"
 
         dt = self.db.select_all_dict(sSQL)
         if self.db.error:
             uiCommon.log_nouser(self.db.error, 0)
 
         if dt:
             sHTML += "<ul>"
             for dr in dt:
                 sName = dr["keypair_name"]
 
                 # DO NOT send these back to the client.
                 sPK = ("false" if not dr["private_key"] else "true")
                 sPP = ("false" if not dr["passphrase"] else "true")
                 # sLoginPassword = "******"
 
                 sHTML += "<li class=\"ui-widget-content ui-corner-all keypair\" id=\"kp_" + dr["keypair_id"] + "\" has_pk=\"" + sPK + "\" has_pp=\"" + sPP + "\">"
                 sHTML += "<span class=\"keypair_label pointer\">" + sName + "</span>"
                 sHTML += "<span class=\"keypair_icons pointer\"><img src=\"static/images/icons/fileclose.png\" class=\"keypair_delete_btn\" /></span>"
                 sHTML += "</li>"
             sHTML += "</ul>"
         else:
             sHTML += ""
 
         return sHTML
     except Exception:
         uiCommon.log_nouser(traceback.format_exc(), 0)
         return traceback.format_exc()
예제 #2
0
 def wmGetCloudsTable(self):
     try:
         sHTML = ""
         sFilter = uiCommon.getAjaxArg("sSearch")
         sHTML = ""
         
         ca = cloud.Clouds(sFilter)
         if ca.rows:
             for row in ca.rows:
                 sHTML += "<tr cloud_id=\"" + row["cloud_id"] + "\">"
                 sHTML += "<td class=\"chkboxcolumn\">"
                 sHTML += "<input type=\"checkbox\" class=\"chkbox\"" \
                 " id=\"chk_" + row["cloud_id"] + "\"" \
                 " tag=\"chk\" />"
                 sHTML += "</td>"
                 
                 sHTML += "<td class=\"selectable\">" + row["cloud_name"] +  "</td>"
                 sHTML += "<td class=\"selectable\">" + row["provider"] +  "</td>"
                 sHTML += "<td class=\"selectable\">" + row["api_url"] +  "</td>"
                 sHTML += "<td class=\"selectable\">" + row["api_protocol"] +  "</td>"
                 
                 sHTML += "</tr>"
 
         return sHTML    
     except Exception:
         uiCommon.log_nouser(traceback.format_exc(), 0)
         return traceback.format_exc()
예제 #3
0
    def wmDeleteClouds(self):
        try:
            sDeleteArray = uiCommon.getAjaxArg("sDeleteArray")
            if len(sDeleteArray) < 36:
                return "{\"info\" : \"Unable to delete - no selection.\"}"

            sDeleteArray = uiCommon.QuoteUp(sDeleteArray)

            #get important data that will be deleted for the log
            sSQL = "select cloud_id, cloud_name, provider from clouds where cloud_id in (" + sDeleteArray + ")"
            rows = self.db.select_all_dict(sSQL)

            sSQL = "delete from clouds where cloud_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
            for dr in rows:
                uiCommon.WriteObjectDeleteLog(
                    uiGlobals.CatoObjectTypes.Cloud, dr["cloud_id"],
                    dr["cloud_name"], dr["provider"] + " Cloud Deleted.")

            return "{\"result\" : \"success\"}"

        except Exception:
            uiCommon.log_nouser(traceback.format_exc(), 0)
            return traceback.format_exc()
예제 #4
0
    def wmGetCloudsTable(self):
        try:
            sHTML = ""
            sFilter = uiCommon.getAjaxArg("sSearch")
            sHTML = ""

            ca = cloud.Clouds(sFilter)
            if ca.rows:
                for row in ca.rows:
                    sHTML += "<tr cloud_id=\"" + row["cloud_id"] + "\">"
                    sHTML += "<td class=\"chkboxcolumn\">"
                    sHTML += "<input type=\"checkbox\" class=\"chkbox\"" \
                    " id=\"chk_" + row["cloud_id"] + "\"" \
                    " tag=\"chk\" />"
                    sHTML += "</td>"

                    sHTML += "<td class=\"selectable\">" + row[
                        "cloud_name"] + "</td>"
                    sHTML += "<td class=\"selectable\">" + row[
                        "provider"] + "</td>"
                    sHTML += "<td class=\"selectable\">" + row[
                        "api_url"] + "</td>"
                    sHTML += "<td class=\"selectable\">" + row[
                        "api_protocol"] + "</td>"

                    sHTML += "</tr>"

            return sHTML
        except Exception:
            uiCommon.log_nouser(traceback.format_exc(), 0)
            return traceback.format_exc()
예제 #5
0
    def wmDeleteClouds(self):
        try:
            sDeleteArray = uiCommon.getAjaxArg("sDeleteArray")
            if len(sDeleteArray) < 36:
                return "{\"info\" : \"Unable to delete - no selection.\"}"
    
            sDeleteArray = uiCommon.QuoteUp(sDeleteArray)
            
            #get important data that will be deleted for the log
            sSQL = "select cloud_id, cloud_name, provider from clouds where cloud_id in (" + sDeleteArray + ")"
            rows = self.db.select_all_dict(sSQL)

            sSQL = "delete from clouds where cloud_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
            for dr in rows:
                uiCommon.WriteObjectDeleteLog(uiGlobals.CatoObjectTypes.Cloud, dr["cloud_id"], dr["cloud_name"], dr["provider"] + " Cloud Deleted.")
    
            return "{\"result\" : \"success\"}"
            
        except Exception:
            uiCommon.log_nouser(traceback.format_exc(), 0)
            return traceback.format_exc()
예제 #6
0
    def wmGetCloudObjectList(self):
        try:
            sAccountID = uiCommon.getAjaxArg("sAccountID")
            sCloudID = uiCommon.getAjaxArg("sCloudID")
            sObjectType = uiCommon.getAjaxArg("sObjectType")
            sHTML = ""

            dt, err = uiCommon.GetCloudObjectsAsList(sAccountID, sCloudID,
                                                     sObjectType)
            if not err:
                if dt:
                    sHTML = self.DrawTableForType(sAccountID, sObjectType, dt)
                else:
                    sHTML = "No data returned from the Cloud Provider."
            else:
                sHTML += "<div class=\"ui-widget\" style=\"margin-top: 10px;\">"
                sHTML += "<div style=\"padding: 10px;\" class=\"ui-state-highlight ui-corner-all\">"
                sHTML += "<span style=\"float: left; margin-right: .3em;\" class=\"ui-icon ui-icon-info\"></span>"
                sHTML += "<p>" + err + "</p>"
                sHTML += "</div>"
                sHTML += "</div>"

            return sHTML
        except Exception:
            uiCommon.log_nouser(traceback.format_exc(), 0)
            return traceback.format_exc()
예제 #7
0
    def wmGetCloudObjectList(self):
        try:
            sAccountID = uiCommon.getAjaxArg("sAccountID")
            sCloudID = uiCommon.getAjaxArg("sCloudID")
            sObjectType = uiCommon.getAjaxArg("sObjectType")
            sHTML = ""

            dt, err = uiCommon.GetCloudObjectsAsList(sAccountID, sCloudID, sObjectType)
            if not err:
                if dt:
                    sHTML = self.DrawTableForType(sAccountID, sObjectType, dt)
                else:
                    sHTML = "No data returned from the Cloud Provider."
            else:
                sHTML += "<div class=\"ui-widget\" style=\"margin-top: 10px;\">"
                sHTML += "<div style=\"padding: 10px;\" class=\"ui-state-highlight ui-corner-all\">"
                sHTML += "<span style=\"float: left; margin-right: .3em;\" class=\"ui-icon ui-icon-info\"></span>"
                sHTML += "<p>" + err + "</p>"
                sHTML += "</div>"
                sHTML += "</div>"

            return sHTML
        except Exception:
            uiCommon.log_nouser(traceback.format_exc(), 0)
            return traceback.format_exc()
예제 #8
0
 def wmGetCloudAccountsJSON(self):
     try:
         provider = uiCommon.getAjaxArg("sProvider")
         ca = cloud.CloudAccounts(sFilter="", sProvider=provider)
         if ca:
             return ca.AsJSON()
         
         #should not get here if all is well
         return "{\"result\":\"fail\",\"error\":\"Failed to get Cloud Accounts using filter [" + provider + "].\"}"
     except Exception:
         uiCommon.log_nouser(traceback.format_exc(), 0)
         return traceback.format_exc()
예제 #9
0
    def wmGetCloudAccountsJSON(self):
        try:
            provider = uiCommon.getAjaxArg("sProvider")
            ca = cloud.CloudAccounts(sFilter="", sProvider=provider)
            if ca:
                return ca.AsJSON()

            #should not get here if all is well
            return "{\"result\":\"fail\",\"error\":\"Failed to get Cloud Accounts using filter [" + provider + "].\"}"
        except Exception:
            uiCommon.log_nouser(traceback.format_exc(), 0)
            return traceback.format_exc()
예제 #10
0
def CacheTaskCommands():
    #creates the html cache file
    try:
        sCatHTML = ""
        sFunHTML = ""

        # so, we will use the FunctionCategories class in the session that was loaded at login, and build the list items for the commands tab.
        cats = uiCommon.GetTaskFunctionCategories()
        if not cats:
            print "Error: Task Function Categories class is not in the datacache."
        else:
            for cat in cats:
                sCatHTML += "<li class=\"ui-widget-content ui-corner-all command_item category\""
                sCatHTML += " id=\"cat_" + cat.Name + "\""
                sCatHTML += " name=\"" + cat.Name + "\">"
                sCatHTML += "<div>"
                sCatHTML += "<img class=\"category_icon\" src=\"" + cat.Icon + "\" alt=\"\" />"
                sCatHTML += "<span>" + cat.Label + "</span>"
                sCatHTML += "</div>"
                sCatHTML += "<div id=\"help_text_" + cat.Name + "\" class=\"hidden\">"
                sCatHTML += cat.Description
                sCatHTML += "</div>"
                sCatHTML += "</li>"
                
                sFunHTML += "<div class=\"functions hidden\" id=\"cat_" + cat.Name + "_functions\">"
                # now, let's work out the functions.
                # we can just draw them all... they are hidden and will display on the client as clicked
                for fn in cat.Functions:
                    sFunHTML += "<div class=\"ui-widget-content ui-corner-all command_item function\""
                    sFunHTML += " id=\"fn_" + fn.Name + "\""
                    sFunHTML += " name=\"" + fn.Name + "\">"
                    sFunHTML += "<img class=\"function_icon\" src=\"" + fn.Icon + "\" alt=\"\" />"
                    sFunHTML += "<span>" + fn.Label + "</span>"
                    sFunHTML += "<div id=\"help_text_" + fn.Name + "\" class=\"hidden\">"
                    sFunHTML += fn.Description
                    sFunHTML += "</div>"
                    sFunHTML += "</div>"

                sFunHTML += "</div>"

        with open("%s/static/_categories.html" % web_root, 'w') as f_out:
            if not f_out:
                print "ERROR: unable to create static/_categories.html."
            f_out.write(sCatHTML)

        with open("%s/static/_functions.html" % web_root, 'w') as f_out:
            if not f_out:
                print "ERROR: unable to create static/_functions.html."
            f_out.write(sFunHTML)

    except Exception, ex:
        uiCommon.log_nouser(ex.__str__(), 0)
예제 #11
0
 def wmGetCloudAccount(self):
     try:
         sID = uiCommon.getAjaxArg("sID")
         a = cloud.CloudAccount()
         if a:
             a.FromID(sID)
             if a.ID:
                 return a.AsJSON()
         
         #should not get here if all is well
         return "{\"result\":\"fail\",\"error\":\"Failed to get details for Cloud Account [" + sID + "].\"}"
     except Exception:
         uiCommon.log_nouser(traceback.format_exc(), 0)
         return traceback.format_exc()
예제 #12
0
    def wmGetCloudAccount(self):
        try:
            sID = uiCommon.getAjaxArg("sID")
            a = cloud.CloudAccount()
            if a:
                a.FromID(sID)
                if a.ID:
                    return a.AsJSON()

            #should not get here if all is well
            return "{\"result\":\"fail\",\"error\":\"Failed to get details for Cloud Account [" + sID + "].\"}"
        except Exception:
            uiCommon.log_nouser(traceback.format_exc(), 0)
            return traceback.format_exc()
예제 #13
0
    def wmGetProviderObjectTypes(self):
        try:
            sProvider = uiCommon.getAjaxArg("sProvider")
            sHTML = ""
            cp = providers.CloudProviders()
            if cp:
                p = cp[sProvider]
                for i in p.GetAllObjectTypes.items():
                    print i

            return sHTML
        except Exception:
            uiCommon.log_nouser(traceback.format_exc(), 0)
            return traceback.format_exc()
예제 #14
0
 def wmGetProviderObjectTypes(self):
     try:
         sProvider = uiCommon.getAjaxArg("sProvider")
         sHTML = ""
         cp = providers.CloudProviders()
         if cp:
             p = cp[sProvider]
             for i in p.GetAllObjectTypes.items():
                 print i
                 
         return sHTML
     except Exception:
         uiCommon.log_nouser(traceback.format_exc(), 0)
         return traceback.format_exc()
예제 #15
0
    def wmTestCloudConnection(self):
        try:
            sAccountID = uiCommon.getAjaxArg("sAccountID")
            sCloudID = uiCommon.getAjaxArg("sCloudID")

            c = cloud.Cloud()
            c.FromID(sCloudID)
            if c.ID is None:
                return "{\"result\":\"fail\",\"error\":\"Failed to get Cloud details for Cloud ID [" + sCloudID + "].\"}"

            ca = cloud.CloudAccount()
            ca.FromID(sAccountID)
            if ca.ID is None:
                return "{\"result\":\"fail\",\"error\":\"Failed to get Cloud Account details for Cloud Account ID [" + sAccountID + "].\"}"

            # get the test cloud object type for this provider
            cot = c.Provider.GetObjectTypeByName(c.Provider.TestObject)
            if cot is not None:
                if not cot.ID:
                    return "{\"result\":\"fail\",\"error\":\"Cannot find definition for requested object type [" + c.Provider.TestObject + "].\"}"
            else:
                return "{\"result\":\"fail\",\"error\":\"GetCloudObjectType failed for [" + c.Provider.TestObject + "].\"}"

            # different providers libs have different methods for building a url
            url = ""
            if c.Provider.Name.lower() == "openstack":
                """not yet implemented"""
                #ACWebMethods.openstackMethods acOS = new ACWebMethods.openstackMethods()
                #sXML = acOS.GetCloudObjectsAsXML(c.ID, cot, 0000BYREF_ARG0000sErr, null)
            else:  #Amazon aws, Eucalyptus, and OpenStackAws
                import aws
                awsi = aws.awsInterface()
                url, err = awsi.BuildURL(ca, c, cot)
                if err:
                    return "{\"result\":\"fail\",\"error\":\"" + uiCommon.packJSON(
                        err) + "\"}"

            if not url:
                return "{\"result\":\"fail\",\"error\":\"Unable to build API URL.\"}"
            result, err = uiCommon.HTTPGet(url, 30)
            if err:
                return "{\"result\":\"fail\",\"error\":\"" + uiCommon.packJSON(
                    err) + "\"}"

            return "{\"result\":\"success\",\"response\":\"" + uiCommon.packJSON(
                result) + "\"}"
        except Exception:
            uiCommon.log_nouser(traceback.format_exc(), 0)
            return traceback.format_exc()
예제 #16
0
    def wmGetProvider(self):
        try:
            sProvider = uiCommon.getAjaxArg("sProvider")

            cp = providers.CloudProviders()
            if cp is None:
                return "{\"result\":\"fail\",\"error\":\"Failed to get Providers.\"}"
            else:
                p = cp[sProvider]
                if p is not None:
                    return p.AsJSON()
                else:
                    return "{\"result\":\"fail\",\"error\":\"Failed to get Provider details for [" + sProvider + "].\"}"
        except Exception:
            uiCommon.log_nouser(traceback.format_exc(), 0)
            return traceback.format_exc()
예제 #17
0
 def wmGetProvider(self):
     try:
         sProvider = uiCommon.getAjaxArg("sProvider")
         
         cp = providers.CloudProviders()
         if cp is None:
             return "{\"result\":\"fail\",\"error\":\"Failed to get Providers.\"}"
         else:
             p = cp[sProvider]
             if p is not None:
                 return p.AsJSON()
             else:
                 return "{\"result\":\"fail\",\"error\":\"Failed to get Provider details for [" + sProvider + "].\"}"
     except Exception:
         uiCommon.log_nouser(traceback.format_exc(), 0)
         return traceback.format_exc()
예제 #18
0
    def wmSaveCloud(self):
        sMode = uiCommon.getAjaxArg("sMode")
        sCloudID = uiCommon.getAjaxArg("sCloudID")
        sCloudName = uiCommon.getAjaxArg("sCloudName")
        sProvider = uiCommon.getAjaxArg("sProvider")
        sAPIUrl = uiCommon.getAjaxArg("sAPIUrl")
        sAPIProtocol = uiCommon.getAjaxArg("sAPIProtocol")

        c = None
        try:
            if sMode == "add":
                c, sErr = cloud.Cloud.DBCreateNew(sCloudName, sProvider,
                                                  sAPIUrl, sAPIProtocol)
                if sErr:
                    return "{\"error\" : \"" + sErr + "\"}"
                if c == None:
                    return "{\"error\" : \"Unable to create Cloud.\"}"

                uiCommon.WriteObjectAddLog(uiGlobals.CatoObjectTypes.Cloud,
                                           c.ID, c.Name, "Cloud Created")
            elif sMode == "edit":
                c = cloud.Cloud()
                c.FromID(sCloudID)
                if c == None:
                    return "{\"error\" : \"Unable to get Cloud using ID [" + sCloudID + "].\"}"
                c.Name = sCloudName
                c.APIProtocol = sAPIProtocol
                c.APIUrl = sAPIUrl

                #get a new provider by name
                c.Provider = providers.Provider.FromName(sProvider)
                result, msg = c.DBUpdate()
                if not result:
                    uiCommon.log(msg, 2)
                    return "{\"info\" : \"%s\"}" % msg

                uiCommon.WriteObjectPropertyChangeLog(
                    uiGlobals.CatoObjectTypes.Cloud, c.ID, c.Name, sCloudName,
                    c.Name)

            if c:
                return c.AsJSON()
            else:
                return "{\"error\" : \"Unable to save Cloud using mode [" + sMode + "].\"}"
        except Exception:
            uiCommon.log_nouser(traceback.format_exc(), 0)
            return traceback.format_exc()
예제 #19
0
    def wmTestCloudConnection(self):
        try:
            sAccountID = uiCommon.getAjaxArg("sAccountID")
            sCloudID = uiCommon.getAjaxArg("sCloudID")
            
            c = cloud.Cloud()
            c.FromID(sCloudID)
            if c.ID is None:
                return "{\"result\":\"fail\",\"error\":\"Failed to get Cloud details for Cloud ID [" + sCloudID + "].\"}"
            
            ca = cloud.CloudAccount()
            ca.FromID(sAccountID)
            if ca.ID is None:
                return "{\"result\":\"fail\",\"error\":\"Failed to get Cloud Account details for Cloud Account ID [" + sAccountID + "].\"}"

            # get the test cloud object type for this provider
            cot = c.Provider.GetObjectTypeByName(c.Provider.TestObject)
            if cot is not None:
                if not cot.ID:
                    return "{\"result\":\"fail\",\"error\":\"Cannot find definition for requested object type [" + c.Provider.TestObject + "].\"}"
            else:
                return "{\"result\":\"fail\",\"error\":\"GetCloudObjectType failed for [" + c.Provider.TestObject + "].\"}"
            
            # different providers libs have different methods for building a url
            url = ""
            if c.Provider.Name.lower() =="openstack":
                """not yet implemented"""
                #ACWebMethods.openstackMethods acOS = new ACWebMethods.openstackMethods()
                #sXML = acOS.GetCloudObjectsAsXML(c.ID, cot, 0000BYREF_ARG0000sErr, null)
            else: #Amazon aws, Eucalyptus, and OpenStackAws
                import aws
                awsi = aws.awsInterface()
                url, err = awsi.BuildURL(ca, c, cot);            
                if err:
                    return "{\"result\":\"fail\",\"error\":\"" + uiCommon.packJSON(err) +"\"}"

            if not url:
                return "{\"result\":\"fail\",\"error\":\"Unable to build API URL.\"}"
            result, err = uiCommon.HTTPGet(url, 30)
            if err:
                return "{\"result\":\"fail\",\"error\":\"" + uiCommon.packJSON(err) + "\"}"
            
            return "{\"result\":\"success\",\"response\":\"" + uiCommon.packJSON(result) + "\"}"
        except Exception:
            uiCommon.log_nouser(traceback.format_exc(), 0)
            return traceback.format_exc()
예제 #20
0
    def wmGetProvidersList(self):
        try:
            sUserDefinedOnly = uiCommon.getAjaxArg("sUserDefinedOnly")
            sHTML = ""
            cp = providers.CloudProviders()
            if cp:
                for name, p in cp.iteritems():
                    if catocommon.is_true(sUserDefinedOnly):
                        if p.UserDefinedClouds:
                            sHTML += "<option value=\"" + name + "\">" + name + "</option>"
                    else:
                        sHTML += "<option value=\"" + name + "\">" + name + "</option>"

            return sHTML
        except Exception:
            uiCommon.log_nouser(traceback.format_exc(), 0)
            return traceback.format_exc()
예제 #21
0
 def wmGetProvidersList(self):
     try:
         sUserDefinedOnly = uiCommon.getAjaxArg("sUserDefinedOnly")
         sHTML = ""
         cp = providers.CloudProviders()
         if cp:
             for name, p in cp.iteritems():
                 if catocommon.is_true(sUserDefinedOnly):
                     if p.UserDefinedClouds:
                         sHTML += "<option value=\"" + name + "\">" + name + "</option>"
                 else:
                     sHTML += "<option value=\"" + name + "\">" + name + "</option>"
 
                 
         return sHTML
     except Exception:
         uiCommon.log_nouser(traceback.format_exc(), 0)
         return traceback.format_exc()
예제 #22
0
    def wmSaveCloud(self):
        sMode = uiCommon.getAjaxArg("sMode")
        sCloudID = uiCommon.getAjaxArg("sCloudID")
        sCloudName = uiCommon.getAjaxArg("sCloudName")
        sProvider = uiCommon.getAjaxArg("sProvider")
        sAPIUrl = uiCommon.getAjaxArg("sAPIUrl")
        sAPIProtocol = uiCommon.getAjaxArg("sAPIProtocol")

        c = None
        try:
            if sMode == "add":
                c, sErr = cloud.Cloud.DBCreateNew(sCloudName, sProvider, sAPIUrl, sAPIProtocol)
                if sErr:
                    return "{\"error\" : \"" + sErr + "\"}"
                if c == None:
                    return "{\"error\" : \"Unable to create Cloud.\"}"

                uiCommon.WriteObjectAddLog(uiGlobals.CatoObjectTypes.Cloud, c.ID, c.Name, "Cloud Created")
            elif sMode == "edit":
                c = cloud.Cloud()
                c.FromID(sCloudID)
                if c == None:
                    return "{\"error\" : \"Unable to get Cloud using ID [" + sCloudID + "].\"}"
                c.Name = sCloudName
                c.APIProtocol = sAPIProtocol
                c.APIUrl = sAPIUrl

                #get a new provider by name
                c.Provider = providers.Provider.FromName(sProvider)
                result, msg = c.DBUpdate()
                if not result:
                    uiCommon.log(msg, 2)
                    return "{\"info\" : \"%s\"}" % msg
                
                uiCommon.WriteObjectPropertyChangeLog(uiGlobals.CatoObjectTypes.Cloud, c.ID, c.Name, sCloudName, c.Name)

            if c:
                return c.AsJSON()
            else:
                return "{\"error\" : \"Unable to save Cloud using mode [" + sMode + "].\"}"
        except Exception:
            uiCommon.log_nouser(traceback.format_exc(), 0)
            return traceback.format_exc()
예제 #23
0
    def wmGetCloudAccountsTable(self):
        try:
            sFilter = uiCommon.getAjaxArg("sSearch")
            sHTML = ""

            ca = cloud.CloudAccounts(sFilter)
            if ca.rows:
                for row in ca.rows:
                    sHTML += "<tr account_id=\"" + row["account_id"] + "\">"

                    if not row["has_ecosystems"]:
                        sHTML += "<td class=\"chkboxcolumn\">"
                        sHTML += "<input type=\"checkbox\" class=\"chkbox\"" \
                        " id=\"chk_" + row["account_id"] + "\"" \
                        " tag=\"chk\" />"
                        sHTML += "</td>"
                    else:
                        sHTML += "<td>"
                        sHTML += "<span class=\"ui-icon ui-icon-info forceinline account_help_btn\"" \
                            " title=\"This account has associated Ecosystems and cannot be deleted.\"></span>"
                        sHTML += "</td>"

                    sHTML += "<td class=\"selectable\">" + row[
                        "account_name"] + "</td>"
                    sHTML += "<td class=\"selectable\">" + row[
                        "account_number"] + "</td>"
                    sHTML += "<td class=\"selectable\">" + row[
                        "provider"] + "</td>"
                    sHTML += "<td class=\"selectable\">" + row[
                        "login_id"] + "</td>"
                    sHTML += "<td class=\"selectable\">" + row[
                        "is_default"] + "</td>"

                    sHTML += "</tr>"

            return sHTML

            #should not get here if all is well
            return "{\"result\":\"fail\",\"error\":\"Failed to get Cloud Accounts using filter [" + sFilter + "].\"}"
        except Exception:
            uiCommon.log_nouser(traceback.format_exc(), 0)
            return traceback.format_exc()
예제 #24
0
def auth_app_processor(handle):
    path = web.ctx.path
    
    # this is very handy in verbose debugging mode for identifying errors
    uiCommon.log_nouser("Serving %s" % path, 4)
    
    # requests that are allowed, no matter what
    if path in [
        "/uiMethods/wmAttemptLogin", 
        "/uiMethods/wmGetQuestion", 
        "/logout", 
        "/notAllowed", 
        "/notfound", 
        "/announcement", 
        "/getlicense", 
        "/uiMethods/wmLicenseAgree", 
        "/uiMethods/wmUpdateHeartbeat"
        ]:
        return handle()

    # any other request requires an active session ... kick it out if there's not one.
    if not session.get('user', False):
        raise web.seeother('/static/login.html?msg=' + urllib.quote_plus("Session expired."))
    
    # check the role/method mappings to see if the requested page is allowed
    # HERE's the rub! ... some of our requests are for "pages" and others (most) are ajax calls.
    # for the pages, we can redirect to the "notAllowed" page, 
    # but for the ajax calls we can't - we need to return an acceptable ajax response.
    
    # the only way to tell if the request is for a page or an ajax
    # is to look at the name.
    # all of our ajax aware methods are called "wmXXX"
    
    if uiCommon.check_roles(path):
        return handle()
    else:
        print path
        if "Methods\/wm" in path:
            raise web.seeother('notAllowed')
        else:
            return "Some content on this page isn't available to your user."
예제 #25
0
def SetTaskCommands():
    try:
        from taskCommands import FunctionCategories
        #we load two classes here...
        #first, the category/function hierarchy
        cats = FunctionCategories()
        bCoreSuccess = cats.Load("%s/task_commands.xml" % web_root)
        if not bCoreSuccess:
            raise Exception("Critical: Unable to read/parse task_commands.xml.")

        #try to append any extension files
        #this will read all the xml files in /extensions
        #and append to sErr if it failed, but not crash or die.
        for root, subdirs, files in os.walk("%s/extensions" % web_root):
            for f in files:
                ext = os.path.splitext(f)[-1]
                if ext == ".xml":
                    fullpath = os.path.join(root, f)
                    if not cats.Append(fullpath):
                        uiCommon.log_nouser("WARNING: Unable to load extension command xml file [" + fullpath + "].", 0)

        #put the categories list in the session...
        #uiGlobals.session.function_categories = cats.Categories
        #then the dict of all functions for fastest lookups
        #uiGlobals.session.functions = cats.Functions

        # was told not to put big objects in the session, so since this can actually be shared by all users,
        # lets try saving a pickle
        # it will get created every time a user logs in, but can be read by all.
        with open("%s/datacache/_categories.pickle" % web_root, 'w') as f_out:
            if not f_out:
                print "ERROR: unable to create datacache/_categories.pickle."
            pickle.dump(cats, f_out, pickle.HIGHEST_PROTOCOL)
        
        #rebuild the cache html files
        CacheTaskCommands()

        return True
    except Exception, ex:
        uiCommon.log_nouser("Unable to load Task Commands XML." + ex.__str__(), 0)
예제 #26
0
    def wmDeleteAccounts(self):
        try:
            sDeleteArray = uiCommon.getAjaxArg("sDeleteArray")
            if len(sDeleteArray) < 36:
                return "{\"info\" : \"Unable to delete - no selection.\"}"
    
            sDeleteArray = uiCommon.QuoteUp(sDeleteArray)

            #  get data that will be deleted for the log
            sSQL = "select account_id, account_name, provider, login_id from cloud_account where account_id in (" + sDeleteArray + ")"
            rows = self.db.select_all_dict(sSQL)


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

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

            self.db.tran_commit()

            #  if we made it here, so save the logs
            for dr in rows:
                uiCommon.WriteObjectDeleteLog(uiGlobals.CatoObjectTypes.CloudAccount, dr["account_id"], dr["account_name"], dr["provider"] + " Account for LoginID [" + dr["login_id"] + "] Deleted")

            return "{\"result\" : \"success\"}"
        except Exception:
            uiCommon.log_nouser(traceback.format_exc(), 0)
예제 #27
0
    def wmDeleteAccounts(self):
        try:
            sDeleteArray = uiCommon.getAjaxArg("sDeleteArray")
            if len(sDeleteArray) < 36:
                return "{\"info\" : \"Unable to delete - no selection.\"}"

            sDeleteArray = uiCommon.QuoteUp(sDeleteArray)

            #  get data that will be deleted for the log
            sSQL = "select account_id, account_name, provider, login_id from cloud_account where account_id in (" + sDeleteArray + ")"
            rows = self.db.select_all_dict(sSQL)

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

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

            self.db.tran_commit()

            #  if we made it here, so save the logs
            for dr in rows:
                uiCommon.WriteObjectDeleteLog(
                    uiGlobals.CatoObjectTypes.CloudAccount, dr["account_id"],
                    dr["account_name"], dr["provider"] +
                    " Account for LoginID [" + dr["login_id"] + "] Deleted")

            return "{\"result\" : \"success\"}"
        except Exception:
            uiCommon.log_nouser(traceback.format_exc(), 0)
예제 #28
0
    def wmGetCloudAccountsTable(self):
        try:
            sFilter = uiCommon.getAjaxArg("sSearch")
            sHTML = ""
            
            ca = cloud.CloudAccounts(sFilter)
            if ca.rows:
                for row in ca.rows:
                    sHTML += "<tr account_id=\"" + row["account_id"] + "\">"
                    
                    if not row["has_ecosystems"]:
                        sHTML += "<td class=\"chkboxcolumn\">"
                        sHTML += "<input type=\"checkbox\" class=\"chkbox\"" \
                        " id=\"chk_" + row["account_id"] + "\"" \
                        " tag=\"chk\" />"
                        sHTML += "</td>"
                    else:
                        sHTML += "<td>"
                        sHTML += "<span class=\"ui-icon ui-icon-info forceinline account_help_btn\"" \
                            " title=\"This account has associated Ecosystems and cannot be deleted.\"></span>"
                        sHTML += "</td>"
                    
                    sHTML += "<td class=\"selectable\">" + row["account_name"] +  "</td>"
                    sHTML += "<td class=\"selectable\">" + row["account_number"] +  "</td>"
                    sHTML += "<td class=\"selectable\">" + row["provider"] +  "</td>"
                    sHTML += "<td class=\"selectable\">" + row["login_id"] +  "</td>"
                    sHTML += "<td class=\"selectable\">" + row["is_default"] +  "</td>"
                    
                    sHTML += "</tr>"

            return sHTML    
            
            #should not get here if all is well
            return "{\"result\":\"fail\",\"error\":\"Failed to get Cloud Accounts using filter [" + sFilter + "].\"}"
        except Exception:
            uiCommon.log_nouser(traceback.format_exc(), 0)
            return traceback.format_exc()
예제 #29
0
    def wmGetKeyPairs(self):
        try:
            sID = uiCommon.getAjaxArg("sID")
            sHTML = ""

            sSQL = "select keypair_id, keypair_name, private_key, passphrase" \
                " from cloud_account_keypair" \
                " where account_id = '" + sID + "'"

            dt = self.db.select_all_dict(sSQL)
            if self.db.error:
                uiCommon.log_nouser(self.db.error, 0)

            if dt:
                sHTML += "<ul>"
                for dr in dt:
                    sName = dr["keypair_name"]

                    # DO NOT send these back to the client.
                    sPK = ("false" if not dr["private_key"] else "true")
                    sPP = ("false" if not dr["passphrase"] else "true")
                    # sLoginPassword = "******"

                    sHTML += "<li class=\"ui-widget-content ui-corner-all keypair\" id=\"kp_" + dr[
                        "keypair_id"] + "\" has_pk=\"" + sPK + "\" has_pp=\"" + sPP + "\">"
                    sHTML += "<span class=\"keypair_label pointer\">" + sName + "</span>"
                    sHTML += "<span class=\"keypair_icons pointer\"><img src=\"static/images/icons/fileclose.png\" class=\"keypair_delete_btn\" /></span>"
                    sHTML += "</li>"
                sHTML += "</ul>"
            else:
                sHTML += ""

            return sHTML
        except Exception:
            uiCommon.log_nouser(traceback.format_exc(), 0)
            return traceback.format_exc()
예제 #30
0
 def Append(self, sFileName):
     try:
         log_nouser("Parsing extension file " + sFileName, 4)
         xRoot = ET.parse(sFileName)
         if xRoot == None:
             #crash... we can't do anything if the XML is busted
             return False
         else:
             xCategories = xRoot.findall(".//category")
             for xCategory in xCategories:
                 cat = self.BuildCategory(xCategory)
                 if cat != None:
                     log_nouser("Parsing extension category = " + cat.Name, 4)
                     self.Categories.append(cat)
                     
             return True
     except Exception, ex:
         # appending does not throw an exception, just a warning in the log
         log_nouser("WARNING: Error parsing extension command file [" + sFileName + "]. " + ex.__str__(), 0)
예제 #31
0
    def wmSaveKeyPair(self):
        try:
            sKeypairID = uiCommon.getAjaxArg("sKeypairID")
            sAccountID = uiCommon.getAjaxArg("sAccountID")
            sName = uiCommon.getAjaxArg("sName")
            sPK = uiCommon.getAjaxArg("sPK")
            sPP = uiCommon.getAjaxArg("sPP")

            if not sName:
                return "KeyPair Name is Required."

            sPK = uiCommon.unpackJSON(sPK)

            bUpdatePK = False
            if sPK:
                bUpdatePK = True

            bUpdatePP = False
            if sPP and sPP != "!2E4S6789O":
                bUpdatePP = True

            if not sKeypairID:
                # empty id, it's a new one.
                sPKClause = ""
                if bUpdatePK:
                    sPKClause = "'" + catocommon.cato_encrypt(sPK) + "'"

                sPPClause = "null"
                if bUpdatePP:
                    sPPClause = "'" + catocommon.cato_encrypt(sPP) + "'"

                sSQL = "insert into cloud_account_keypair (keypair_id, account_id, keypair_name, private_key, passphrase)" \
                    " values ('" + catocommon.new_guid() + "'," \
                    "'" + sAccountID + "'," \
                    "'" + sName.replace("'", "''") + "'," \
                    + sPKClause + "," \
                    + sPPClause + \
                    ")"
            else:
                sPKClause = ""
                if bUpdatePK:
                    sPKClause = ", private_key = '" + catocommon.cato_encrypt(
                        sPK) + "'"

                sPPClause = ""
                if bUpdatePP:
                    sPPClause = ", passphrase = '" + catocommon.cato_encrypt(
                        sPP) + "'"

                sSQL = "update cloud_account_keypair set" \
                    " keypair_name = '" + sName.replace("'", "''") + "'" \
                    + sPKClause + sPPClause + \
                    " where keypair_id = '" + sKeypairID + "'"

            if not self.db.exec_db_noexcep(sSQL):
                uiCommon.log(self.db.error)
                return self.db.error

            return ""

        except Exception:
            uiCommon.log_nouser(traceback.format_exc(), 0)
            return traceback.format_exc()
예제 #32
0
    def DrawTableForType(self, sAccountID, sObjectType, dt):
        try:
            # we will need this at the bottom
            sSQL = "select eo.ecosystem_object_id, e.ecosystem_id, e.ecosystem_name" \
                " from ecosystem_object eo" \
                " join ecosystem e on eo.ecosystem_id = e.ecosystem_id" \
                " where e.account_id = '" + sAccountID + "'" \
                " and eo.ecosystem_object_type = '" + sObjectType + "'"

            ecosystems = self.db.select_all_dict(sSQL)
            if self.db.error:
                return self.db.error

            sHTML = ""

            # buld the table
            sHTML += "<table class=\"jtable\" cellspacing=\"1\" cellpadding=\"1\" width=\"99%\">"
            sHTML += "<tr>"
            sHTML += "<th class=\"chkboxcolumn\">"
            sHTML += "<input type=\"checkbox\" class=\"chkbox\" id=\"chkAll\" />"
            sHTML += "</th>"

            # loop column headers (by getting just one item in the dict)
            for prop in dt.itervalues().next():
                sHTML += "<th>"
                sHTML += prop.Label
                sHTML += "</th>"

            # the last column is hardcoded for ecosystems.
            sHTML += "<th>Ecosystems</th>"

            sHTML += "</tr>"

            # loop rows

            # remember, the properties themselves have the value
            for sObjectID, props in dt.iteritems():
                # crush the spaces... a javascript ID can't have spaces
                sJSID = sObjectID.strip().replace(" ", "")

                sHTML += "<tr>"
                sHTML += "<td class=\"chkboxcolumn\">"

                # not drawing the checkbox if there's no ID defined, we can't add it to an ecosystem without an id
                if sObjectID:
                    sHTML += "<input type=\"checkbox\" class=\"chkbox\"" \
                        " id=\"chk_" + sJSID + "\"" \
                        " object_id=\"" + sObjectID + "\"" \
                        " tag=\"chk\" />"

                    sHTML += "</td>"

                # loop data columns
                for prop in props:
                    print "%s - %s" % (prop.Name, prop.Value)
                    sValue = (prop.Value if prop.Value else "")
                    sHTML += "<td>"

                    # should we try to show an icon?
                    if prop.HasIcon and sValue:
                        sHTML += "<img class=\"custom_icon\" src=\"static/images/custom/" + prop.Name.replace(
                            " ", "").lower() + "_" + sValue.replace(
                                " ", "").lower() + ".png\" alt=\"\" />"

                    # if this is the "Tags" column, it might contain some xml... break 'em down
                    if prop.Name == "Tags" and sValue:
                        try:
                            xDoc = ET.fromstring(sValue)
                            if xDoc is not None:
                                sTags = ""
                                for xeTag in xDoc.findall("item"):
                                    sTags += "<b>%s</b> : %s<br />" % (
                                        xeTag.findtext("key", ""),
                                        xeTag.findtext("value", ""))
                                sHTML += sTags
                        except:  # couldn't parse it.  hmmm....
                            print traceback.format_exc()
                            # I guess just stick the value in there, but make it safe
                            sHTML += uiCommon.SafeHTML(sValue)
                    else:
                        sHTML += (
                            sValue if sValue else "&nbsp;"
                        )  # we're building a table, empty cells should still have &nbsp;

                    sHTML += "</td>"

                # spin the ecosystems query here, building a list of ecosystems associated with this object
                sHTML += "<td>"
                if ecosystems:
                    for ecosystem in ecosystems:
                        if ecosystem["ecosystem_object_id"] == sObjectID:
                            sHTML += "<span class=\"ecosystem_link pointer\" ecosystem_id=\"%s\">%s</span><br />" % (
                                ecosystem["ecosystem_id"],
                                ecosystem["ecosystem_name"])
                sHTML += "</td>"

                sHTML += "</tr>"

            sHTML += "</table>"

            return sHTML
        except Exception:
            uiCommon.log_nouser(traceback.format_exc(), 0)
            return traceback.format_exc()
예제 #33
0
    def DrawTableForType(self, sAccountID, sObjectType, dt):
        try:
            # we will need this at the bottom
            sSQL = "select eo.ecosystem_object_id, e.ecosystem_id, e.ecosystem_name" \
                " from ecosystem_object eo" \
                " join ecosystem e on eo.ecosystem_id = e.ecosystem_id" \
                " where e.account_id = '" + sAccountID + "'" \
                " and eo.ecosystem_object_type = '" + sObjectType + "'"

            ecosystems = self.db.select_all_dict(sSQL)
            if self.db.error:
                return self.db.error

            sHTML = ""

            # buld the table
            sHTML += "<table class=\"jtable\" cellspacing=\"1\" cellpadding=\"1\" width=\"99%\">"
            sHTML += "<tr>"
            sHTML += "<th class=\"chkboxcolumn\">"
            sHTML += "<input type=\"checkbox\" class=\"chkbox\" id=\"chkAll\" />"
            sHTML += "</th>"

            # loop column headers (by getting just one item in the dict)
            for prop in dt.itervalues().next():
                sHTML += "<th>"
                sHTML += prop.Label
                sHTML += "</th>"

            # the last column is hardcoded for ecosystems.
            sHTML += "<th>Ecosystems</th>"

            sHTML += "</tr>"

            # loop rows

            # remember, the properties themselves have the value
            for sObjectID, props in dt.iteritems():
                # crush the spaces... a javascript ID can't have spaces
                sJSID = sObjectID.strip().replace(" ","")

                sHTML += "<tr>"
                sHTML += "<td class=\"chkboxcolumn\">"
                
                # not drawing the checkbox if there's no ID defined, we can't add it to an ecosystem without an id
                if sObjectID:
                    sHTML += "<input type=\"checkbox\" class=\"chkbox\"" \
                        " id=\"chk_" + sJSID + "\"" \
                        " object_id=\"" + sObjectID + "\"" \
                        " tag=\"chk\" />"
                
                    sHTML += "</td>"

                # loop data columns
                for prop in props:
                    print "%s - %s" % (prop.Name, prop.Value)
                    sValue = (prop.Value if prop.Value else "")
                    sHTML += "<td>"

                    # should we try to show an icon?
                    if prop.HasIcon and sValue:
                        sHTML += "<img class=\"custom_icon\" src=\"static/images/custom/" + prop.Name.replace(" ", "").lower() + "_" + sValue.replace(" ", "").lower() + ".png\" alt=\"\" />"
                
                    # if this is the "Tags" column, it might contain some xml... break 'em down
                    if prop.Name == "Tags" and sValue:
                        try:
                            xDoc = ET.fromstring(sValue)
                            if xDoc is not None:
                                sTags = ""
                                for xeTag in xDoc.findall("item"):
                                    sTags += "<b>%s</b> : %s<br />" % (xeTag.findtext("key", ""), xeTag.findtext("value", ""))
                                sHTML += sTags
                        except: # couldn't parse it.  hmmm....
                            print traceback.format_exc()
                            # I guess just stick the value in there, but make it safe
                            sHTML += uiCommon.SafeHTML(sValue)
                    else:                         
                        sHTML += (sValue if sValue else "&nbsp;") # we're building a table, empty cells should still have &nbsp;

                    sHTML += "</td>"

                # spin the ecosystems query here, building a list of ecosystems associated with this object
                sHTML += "<td>"
                if ecosystems:
                    for ecosystem in ecosystems:
                        if ecosystem["ecosystem_object_id"] == sObjectID:
                            sHTML += "<span class=\"ecosystem_link pointer\" ecosystem_id=\"%s\">%s</span><br />" % (ecosystem["ecosystem_id"], ecosystem["ecosystem_name"])
                sHTML += "</td>"
                
                sHTML += "</tr>"

            sHTML += "</table>"

            return sHTML
        except Exception:
            uiCommon.log_nouser(traceback.format_exc(), 0)
            return traceback.format_exc()
예제 #34
0
    def wmSaveKeyPair(self):
        try:
            sKeypairID = uiCommon.getAjaxArg("sKeypairID")
            sAccountID = uiCommon.getAjaxArg("sAccountID")
            sName = uiCommon.getAjaxArg("sName")
            sPK = uiCommon.getAjaxArg("sPK")
            sPP = uiCommon.getAjaxArg("sPP")

            if not sName:
                return "KeyPair Name is Required."
    
            sPK = uiCommon.unpackJSON(sPK)
    
            bUpdatePK = False
            if sPK:
                bUpdatePK = True
    
            bUpdatePP = False
            if sPP and sPP != "!2E4S6789O":
                bUpdatePP = True
    
    
            if not sKeypairID:
                # empty id, it's a new one.
                sPKClause = ""
                if bUpdatePK:
                    sPKClause = "'" + catocommon.cato_encrypt(sPK) + "'"

                sPPClause = "null"
                if bUpdatePP:
                    sPPClause = "'" + catocommon.cato_encrypt(sPP) + "'"

                sSQL = "insert into cloud_account_keypair (keypair_id, account_id, keypair_name, private_key, passphrase)" \
                    " values ('" + catocommon.new_guid() + "'," \
                    "'" + sAccountID + "'," \
                    "'" + sName.replace("'", "''") + "'," \
                    + sPKClause + "," \
                    + sPPClause + \
                    ")"
            else:
                sPKClause = ""
                if bUpdatePK:
                    sPKClause = ", private_key = '" + catocommon.cato_encrypt(sPK) + "'"

                sPPClause = ""
                if bUpdatePP:
                    sPPClause = ", passphrase = '" + catocommon.cato_encrypt(sPP) + "'"

                sSQL = "update cloud_account_keypair set" \
                    " keypair_name = '" + sName.replace("'", "''") + "'" \
                    + sPKClause + sPPClause + \
                    " where keypair_id = '" + sKeypairID + "'"

            if not self.db.exec_db_noexcep(sSQL):
                uiCommon.log(self.db.error)
                return self.db.error

            return ""
        
        except Exception:
            uiCommon.log_nouser(traceback.format_exc(), 0)
            return traceback.format_exc()
예제 #35
0
    uiGlobals.session = session
    uiGlobals.server = server
    uiGlobals.config = config
    uiGlobals.web_root = web_root
    
    # setting this to True seems to show a lot more detail in UI exceptions
    web.config.debug = False

    # we need to build some static html here...
    # caching in the session is a bad idea, and this stuff very very rarely changes.
    # so, when the service is started it will update the files, and the ui 
    # will simply pull in the files when requested.
    
    # put the task commands in a pickle for our lookups
    # and cache the html in a flat file
    uiCommon.log_nouser("Generating static html...", 3)
    SetTaskCommands()
    CacheMenu()

    
    
    # Uncomment the following - it will print out all the core methods in the app
    # this will be handy during the conversion, as we add functions to uiGlobals.RoleMethods.
#    for s in dir():
#        print "\"/%s\" : [\"Administrator\", \"Developer\"]," % s
#    for s in dir(uiMethods):
#        print "\"%s\" : [\"Administrator\", \"Developer\"]," % s
#    for s in dir(taskMethods):
#        print "\"/%s\" : [\"Administrator\", \"Developer\"]," % s
#    for s in dir(ecoMethods):
#        print "\"%s\" : [\"Administrator\", \"Developer\"]," % s