Example #1
0
 def build_request(self, signal):
     """Builds the XML message from the signal."""
     doc = Document()
     e1 = doc.createElement("TOBI_communication");
     e2 = doc.createElement("signal")
     a = doc.createAttribute("Type")
     a.value = str(signal)
     e2.attributes[a.name] = a.value
     e1.appendChild(e2)
     doc.appendChild(e1)
     return doc.toxml()
Example #2
0
 def build_request(self, signal):
     """Builds the XML message from the signal."""
     doc = Document()
     e1 = doc.createElement("TOBI_communication")
     e2 = doc.createElement("signal")
     a = doc.createAttribute("Type")
     a.value = str(signal)
     e2.attributes[a.name] = a.value
     e1.appendChild(e2)
     doc.appendChild(e1)
     return doc.toxml()
Example #3
0
    def _serializeXML(self):
        '''
         Expects data to be a list of Contact Objects
        '''
        doc = Document()

        element = doc.createElement("AddressBook")
        doc.appendChild(element)

        for data in self._data:

            contact = doc.createElement("Contact")
            element.appendChild(contact)

            firstName = doc.createAttribute("firstName")
            firstName.nodeValue = data.getFirstName()

            lastName = doc.createAttribute("lastName")
            lastName.nodeValue = data.getlastName()

            address = doc.createAttribute("address")
            address.nodeValue = data.getAddress()

            phone = doc.createAttribute("phone")
            phone.nodeValue = data.getPhone()

            contact.setAttributeNode(firstName)
            contact.setAttributeNode(lastName)
            contact.setAttributeNode(address)
            contact.setAttributeNode(phone)

        data = open(self._filePath, "w")
        data.write(doc.toprettyxml())
        data.close()

        print "Contacts saved out as an XML file."
        return True
Example #4
0
class XMLDump(object):
    """
    This class purpose is to dump the data into an xml Format.
    The format of the xml file is described in the scheme file xml/sqlmap.xsd
    """

    def __init__(self):
        self._outputFile = None
        self._outputFP = None
        self.__root = None
        self.__doc = Document()

    def _addToRoot(self, element):
        """
        Adds element to the root element
        """
        self.__root.appendChild(element)

    def __write(self, data, n=True):
        """
        Writes the data into the file
        """
        if n:
            self._outputFP.write("%s\n" % data)
        else:
            self._outputFP.write("%s " % data)

        self._outputFP.flush()

        kb.dataOutputFlag = True

    def _getRootChild(self, elemName):
        """
        Returns the child of the root with the described name
        """
        elements = self.__root.getElementsByTagName(elemName)
        if elements:
            return elements[0]

        return elements

    def _createTextNode(self, data):
        """
        Creates a text node with utf8 data inside.
        The text is escaped to an fit the xml text Format.
        """
        if data is None:
            return self.__doc.createTextNode(u'')
        else:
            escaped_data = saxutils.escape(data, ENTITIES)
            return self.__doc.createTextNode(escaped_data)

    def _createAttribute(self, attrName, attrValue):
        """
        Creates an attribute node with utf8 data inside.
        The text is escaped to an fit the xml text Format.
        """
        attr = self.__doc.createAttribute(attrName)
        if attrValue is None:
            attr.nodeValue = u''
        else:
            attr.nodeValue = getUnicode(attrValue)
        return attr

    def string(self, header, data, sort=True):
        """
        Adds string element to the xml.
        """
        if isinstance(data, (list, tuple, set)):
            self.lister(header, data, sort)
            return

        messagesElem = self._getRootChild(MESSAGES_ELEM_NAME)
        if (not(messagesElem)):
            messagesElem = self.__doc.createElement(MESSAGES_ELEM_NAME)
            self._addToRoot(messagesElem)

        if data:
            data = self._formatString(data)
        else:
            data = ""

        elem = self.__doc.createElement(MESSAGE_ELEM)
        elem.setAttributeNode(self._createAttribute(TYPE_ATTR, header))
        elem.appendChild(self._createTextNode(data))
        messagesElem.appendChild(elem)

    def lister(self, header, elements, sort=True):
        """
        Adds information formatted as list element
        """
        lstElem = self.__doc.createElement(LST_ELEM_NAME)
        lstElem.setAttributeNode(self._createAttribute(TYPE_ATTR, header))
        if elements:
            if sort:
                try:
                    elements = set(elements)
                    elements = list(elements)
                    elements.sort(key=lambda x: x.lower())
                except:
                    pass

            for element in elements:
                memberElem = self.__doc.createElement(MEMBER_ELEM)
                lstElem.appendChild(memberElem)
                if isinstance(element, basestring):
                    memberElem.setAttributeNode(self._createAttribute(TYPE_ATTR, "string"))
                    memberElem.appendChild(self._createTextNode(element))
                elif isinstance(element, (list, tuple, set)):
                    memberElem.setAttributeNode(self._createAttribute(TYPE_ATTR, "list"))
                    for e in element:
                        memberElemStr = self.__doc.createElement(MEMBER_ELEM)
                        memberElemStr.setAttributeNode(self._createAttribute(TYPE_ATTR, "string"))
                        memberElemStr.appendChild(self._createTextNode(getUnicode(e)))
                        memberElem.appendChild(memberElemStr)
        listsElem = self._getRootChild(LSTS_ELEM_NAME)
        if not(listsElem):
            listsElem = self.__doc.createElement(LSTS_ELEM_NAME)
            self._addToRoot(listsElem)
        listsElem.appendChild(lstElem)

    def technic(self, technicType, data):
        """
        Adds information about the technic used to extract data from the db
        """
        technicElem = self.__doc.createElement(TECHNIC_ELEM_NAME)
        technicElem.setAttributeNode(self._createAttribute(TYPE_ATTR, technicType))
        textNode = self._createTextNode(data)
        technicElem.appendChild(textNode)
        technicsElem = self._getRootChild(TECHNICS_ELEM_NAME)
        if not(technicsElem):
            technicsElem = self.__doc.createElement(TECHNICS_ELEM_NAME)
            self._addToRoot(technicsElem)
        technicsElem.appendChild(technicElem)

    def banner(self, data):
        """
        Adds information about the database banner to the xml.
        The banner contains information about the type and the version of the database.
        """
        bannerElem = self.__doc.createElement(BANNER_ELEM_NAME)
        bannerElem.appendChild(self._createTextNode(data))
        self._addToRoot(bannerElem)

    def currentUser(self, data):
        """
        Adds information about the current database user to the xml
        """
        currentUserElem = self.__doc.createElement(CURRENT_USER_ELEM_NAME)
        textNode = self._createTextNode(data)
        currentUserElem.appendChild(textNode)
        self._addToRoot(currentUserElem)

    def currentDb(self, data):
        """
        Adds information about the current database is use to the xml
        """
        currentDBElem = self.__doc.createElement(CURRENT_DB_ELEM_NAME)
        textNode = self._createTextNode(data)
        currentDBElem.appendChild(textNode)
        self._addToRoot(currentDBElem)

    def dba(self, isDBA):
        """
        Adds information to the xml that indicates whether the user has DBA privileges
        """
        isDBAElem = self.__doc.createElement(IS_DBA_ELEM_NAME)
        isDBAElem.setAttributeNode(self._createAttribute(VALUE_ATTR, getUnicode(isDBA)))
        self._addToRoot(isDBAElem)

    def users(self, users):
        """
        Adds a list of the existing users to the xml
        """
        usersElem = self.__doc.createElement(USERS_ELEM_NAME)
        if isinstance(users, basestring):
            users = [users]
        if users:
            for user in users:
                userElem = self.__doc.createElement(DB_USER_ELEM_NAME)
                usersElem.appendChild(userElem)
                userElem.appendChild(self._createTextNode(user))
        self._addToRoot(usersElem)

    def dbs(self, dbs):
        """
        Adds a list of the existing databases to the xml
        """
        dbsElem = self.__doc.createElement(DBS_ELEM_NAME)
        if dbs:
            for db in dbs:
                dbElem = self.__doc.createElement(DB_NAME_ELEM_NAME)
                dbsElem.appendChild(dbElem)
                dbElem.appendChild(self._createTextNode(db))
        self._addToRoot(dbsElem)

    def userSettings(self, header, userSettings, subHeader):
        """
        Adds information about the user's settings to the xml.
        The information can be user's passwords, privileges and etc..
        """
        self._areAdmins = set()
        userSettingsElem = self._getRootChild(USER_SETTINGS_ELEM_NAME)
        if (not(userSettingsElem)):
            userSettingsElem = self.__doc.createElement(USER_SETTINGS_ELEM_NAME)
            self._addToRoot(userSettingsElem)

        userSettingElem = self.__doc.createElement(USER_SETTING_ELEM_NAME)
        userSettingElem.setAttributeNode(self._createAttribute(TYPE_ATTR, header))

        if isinstance(userSettings, (tuple, list, set)):
            self._areAdmins = userSettings[1]
            userSettings = userSettings[0]

        users = userSettings.keys()
        users.sort(key=lambda x: x.lower())

        for user in users:
            userElem = self.__doc.createElement(USER_ELEM_NAME)
            userSettingElem.appendChild(userElem)
            if user in self._areAdmins:
                userElem.setAttributeNode(self._createAttribute(TYPE_ATTR, ADMIN_USER))
            else:
                userElem.setAttributeNode(self._createAttribute(TYPE_ATTR, REGULAR_USER))

            settings = userSettings[user]

            settings.sort()

            for setting in settings:
                settingsElem = self.__doc.createElement(SETTINGS_ELEM_NAME)
                settingsElem.setAttributeNode(self._createAttribute(TYPE_ATTR, subHeader))
                settingTextNode = self._createTextNode(setting)
                settingsElem.appendChild(settingTextNode)
                userElem.appendChild(settingsElem)
        userSettingsElem.appendChild(userSettingElem)

    def dbTables(self, dbTables):
        """
        Adds information of the existing db tables to the xml
        """
        if not isinstance(dbTables, dict):
            self.string(TABLES_ELEM_NAME, dbTables)
            return

        dbTablesElem = self.__doc.createElement(DB_TABLES_ELEM_NAME)

        for db, tables in dbTables.items():
            tables.sort(key=lambda x: x.lower())
            dbElem = self.__doc.createElement(DATABASE_ELEM_NAME)
            dbElem.setAttributeNode(self._createAttribute(NAME_ATTR, db))
            dbTablesElem.appendChild(dbElem)
            for table in tables:
                tableElem = self.__doc.createElement(DB_TABLE_ELEM_NAME)
                tableElem.appendChild(self._createTextNode(table))
                dbElem.appendChild(tableElem)
        self._addToRoot(dbTablesElem)

    def dbTableColumns(self, tableColumns):
        """
        Adds information about the columns of the existing tables to the xml
        """

        columnsElem = self._getRootChild(COLUMNS_ELEM_NAME)
        if not(columnsElem):
            columnsElem = self.__doc.createElement(COLUMNS_ELEM_NAME)

        for db, tables in tableColumns.items():
            if not db:
                db = DEFAULT_DB
            dbElem = self.__doc.createElement(DATABASE_COLUMNS_ELEM)
            dbElem.setAttributeNode(self._createAttribute(NAME_ATTR, db))
            columnsElem.appendChild(dbElem)

            for table, columns in tables.items():
                tableElem = self.__doc.createElement(TABLE_ELEM_NAME)
                tableElem.setAttributeNode(self._createAttribute(NAME_ATTR, table))

                colList = columns.keys()
                colList.sort(key=lambda x: x.lower())

                for column in colList:
                    colType = columns[column]
                    colElem = self.__doc.createElement(COLUMN_ELEM_NAME)
                    if colType is not None:
                        colElem.setAttributeNode(self._createAttribute(TYPE_ATTR, colType))
                    else:
                        colElem.setAttributeNode(self._createAttribute(TYPE_ATTR, UNKNOWN_COLUMN_TYPE))
                    colElem.appendChild(self._createTextNode(column))
                    tableElem.appendChild(colElem)

        self._addToRoot(columnsElem)

    def dbTableValues(self, tableValues):
        """
        Adds the values of specific table to the xml.
        The values are organized according to the relevant row and column.
        """
        tableElem = self.__doc.createElement(DB_TABLE_VALUES_ELEM_NAME)
        if (tableValues is not None):
            db = tableValues["__infos__"]["db"]
            if not db:
                db = "All"
            table = tableValues["__infos__"]["table"]

            count = int(tableValues["__infos__"]["count"])
            columns = tableValues.keys()
            columns.sort(key=lambda x: x.lower())

            tableElem.setAttributeNode(self._createAttribute(DB_ATTR, db))
            tableElem.setAttributeNode(self._createAttribute(NAME_ATTR, table))

            for i in range(count):
                rowElem = self.__doc.createElement(ROW_ELEM_NAME)
                tableElem.appendChild(rowElem)
                for column in columns:
                    if column != "__infos__":
                        info = tableValues[column]
                        value = info["values"][i]

                        if re.search("^[\ *]*$", value):
                            value = "NULL"

                        cellElem = self.__doc.createElement(CELL_ELEM_NAME)
                        cellElem.setAttributeNode(self._createAttribute(COLUMN_ATTR, column))
                        cellElem.appendChild(self._createTextNode(value))
                        rowElem.appendChild(cellElem)

        dbValuesElem = self._getRootChild(DB_VALUES_ELEM)
        if (not(dbValuesElem)):
            dbValuesElem = self.__doc.createElement(DB_VALUES_ELEM)
            self._addToRoot(dbValuesElem)

        dbValuesElem.appendChild(tableElem)

        logger.info("Table '%s.%s' dumped to XML file" % (db, table))

    def dbColumns(self, dbColumns, colConsider, dbs):
        """
        Adds information about the columns
        """
        for column in dbColumns.keys():
            printDbs = {}
            for db, tblData in dbs.items():
                for tbl, colData in tblData.items():
                    for col, dataType in colData.items():
                        if column in col:
                            if db in printDbs:
                                if tbl in printDbs[db]:
                                    printDbs[db][tbl][col] = dataType
                                else:
                                    printDbs[db][tbl] = {col: dataType}
                            else:
                                printDbs[db] = {}
                                printDbs[db][tbl] = {col: dataType}

                            continue

        self.dbTableColumns(printDbs)

    def query(self, query, queryRes):
        """
        Adds details of an executed query to the xml.
        The query details are the query itself and its results.
        """
        queryElem = self.__doc.createElement(QUERY_ELEM_NAME)
        queryElem.setAttributeNode(self._createAttribute(VALUE_ATTR, query))
        queryElem.appendChild(self._createTextNode(queryRes))
        queriesElem = self._getRootChild(QUERIES_ELEM_NAME)
        if (not(queriesElem)):
            queriesElem = self.__doc.createElement(QUERIES_ELEM_NAME)
            self._addToRoot(queriesElem)
        queriesElem.appendChild(queryElem)

    def registerValue(self, registerData):
        """
        Adds information about an extracted registry key to the xml
        """
        registerElem = self.__doc.createElement(REGISTER_DATA_ELEM_NAME)
        registerElem.appendChild(self._createTextNode(registerData))
        registriesElem = self._getRootChild(REGISTERY_ENTRIES_ELEM_NAME)
        if (not(registriesElem)):
            registriesElem = self.__doc.createElement(REGISTERY_ENTRIES_ELEM_NAME)
            self._addToRoot(registriesElem)
        registriesElem.appendChild(registerElem)

    def rFile(self, filePath, data):
        """
        Adds an extracted file's content to the xml
        """
        fileContentElem = self.__doc.createElement(FILE_CONTENT_ELEM_NAME)
        fileContentElem.setAttributeNode(self._createAttribute(NAME_ATTR, filePath))
        fileContentElem.appendChild(self._createTextNode(data))
        self._addToRoot(fileContentElem)

    def setOutputFile(self):
        """
        Initiates the xml file from the configuration.
        """
        if (conf.xmlFile):
            try:
                self._outputFile = conf.xmlFile
                self.__root = None

                if os.path.exists(self._outputFile):
                    try:
                        self.__doc = xml.dom.minidom.parse(self._outputFile)
                        self.__root = self.__doc.childNodes[0]
                    except ExpatError:
                        self.__doc = Document()

                self._outputFP = codecs.open(self._outputFile, "w+", UNICODE_ENCODING)

                if self.__root is None:
                    self.__root = self.__doc.createElementNS(NAME_SPACE_ATTR, RESULTS_ELEM_NAME)
                    self.__root.setAttributeNode(self._createAttribute(XMLNS_ATTR, NAME_SPACE_ATTR))
                    self.__root.setAttributeNode(self._createAttribute(SCHEME_NAME_ATTR, SCHEME_NAME))
                    self.__doc.appendChild(self.__root)
            except IOError:
                raise SqlmapFilePathException("Wrong filename provided for saving the xml file: %s" % conf.xmlFile)

    def getOutputFile(self):
        return self._outputFile

    def finish(self, resultStatus, resultMsg=""):
        """
        Finishes the dumper operation:
        1. Adds the session status to the xml
        2. Writes the xml to the file
        3. Closes the xml file
        """
        if ((self._outputFP is not None) and not(self._outputFP.closed)):
            statusElem = self.__doc.createElement(STATUS_ELEM_NAME)
            statusElem.setAttributeNode(self._createAttribute(SUCESS_ATTR, getUnicode(resultStatus)))

            if not resultStatus:
                errorElem = self.__doc.createElement(ERROR_ELEM_NAME)

                if isinstance(resultMsg, Exception):
                    errorElem.setAttributeNode(self._createAttribute(TYPE_ATTR, type(resultMsg).__name__))
                else:
                    errorElem.setAttributeNode(self._createAttribute(TYPE_ATTR, UNHANDLED_PROBLEM_TYPE))

                errorElem.appendChild(self._createTextNode(getUnicode(resultMsg)))
                statusElem.appendChild(errorElem)

            self._addToRoot(statusElem)
            self.__write(prettyprint.formatXML(self.__doc, encoding=UNICODE_ENCODING))
            self._outputFP.close()
Example #5
0
# root node

orderlist = doc.createElement('orderlist')

doc.appendChild(orderlist)

# first layer

order = doc.createElement('order')

orderlist.appendChild(order)

# attribute

att = doc.createAttribute('test_att')

order.setAttributeNode(att)

order.setAttribute('test_att', 'test')

# new element

customer = doc.createElement('customer')

customer_text = doc.createTextNode('foo')

customer.appendChild(customer_text)

order.appendChild(customer)
Example #6
0
def create_session():
    try:
        # Write the XML request with the minidom  module
        newdoc = Document()
        request = newdoc.createElement('request')
        newdoc.appendChild(request)
        control = newdoc.createElement('control')
        request.appendChild(control)
        senderid = newdoc.createElement('senderid')
        control.appendChild(senderid).appendChild(
            newdoc.createTextNode(acc_keys.int_sender_id()))
        senderpassword = newdoc.createElement('password')
        control.appendChild(senderpassword).appendChild(
            newdoc.createTextNode(acc_keys.int_sender_pass()))
        controlid = newdoc.createElement('controlid')
        control.appendChild(controlid).appendChild(
            newdoc.createTextNode(str(int(time.time()))))
        uniqueid = newdoc.createElement('uniqueid')
        control.appendChild(uniqueid).appendChild(
            newdoc.createTextNode("false"))
        dtdversion = newdoc.createElement('dtdversion')
        control.appendChild(dtdversion).appendChild(
            newdoc.createTextNode("3.0"))
        includewhitespace = newdoc.createElement('includewhitespace')
        control.appendChild(includewhitespace).appendChild(
            newdoc.createTextNode("false"))
        print('1')
        operation = newdoc.createElement('operation')
        request.appendChild(operation)
        print('2')
        authentication = newdoc.createElement('authentication')
        operation.appendChild(operation)
        print('3')
        ses = 'test'

        sessionid = newdoc.createElement('sessionid')
        authentication.appendChild(sessionid).appendChild(
            newdoc.createTextNode(ses))
        print('4')
        content = newdoc.createElement('content')
        operation.appendChild(content)
        print('5')
        function = newdoc.createElement('function')
        content.appendChild(function).setAttributeNode(
            newdoc.createAttribute('controlid'))
        function.attributes["controlid"].value = "1"
        print('6')
        read = newdoc.createElement('readByQuery')
        function.appendChild(read)
        print('7')
        objectt = newdoc.createElement('object')
        read.appendChild(objectt).appendChild(newdoc.createTextNode('VENDOR'))
        print('8')
        fields = newdoc.createElement('fields')
        read.appendChild(objectt).appendChild(newdoc.createTextNode('*'))
        print('9')
        query = newdoc.createElement('query')
        read.appendChild(query)
        print('10')
        pagesize = newdoc.createElement('pagesize')
        read.appendChild(pagesize).appendChild(newdoc.createTextNode('3'))

        print(request.toprettyxml())

        # Print the XML response to the console
        #print(result.toprettyxml())

        find = result.getElementsByTagName('sessionid')
        sessionid = find[0].firstChild.nodeValue
        return sessionid

    except Exception as inst:
        print("Uh oh, something is wrong")
        print(type(inst))
        print(inst.args)
Example #7
0
class XMLDump:
    '''
    This class purpose is to dump the data into an xml Format.
    The format of the xml file is described in the scheme file xml/sqlmap.xsd
    '''
    def __init__(self):
        self.__outputFile = None
        self.__outputFP = None
        self.__root = None
        self.__doc = Document()

    def __addToRoot(self, element):
        '''
        Adds element to the root element
        '''
        self.__root.appendChild(element)

    def __write(self, data, n=True):
        '''
        Writes the data into the file
        '''
        if n:
            self.__outputFP.write("%s\n" % data)
        else:
            self.__outputFP.write("%s " % data)

        self.__outputFP.flush()

        kb.dataOutputFlag = True

    def __getRootChild(self, elemName):
        '''
        Returns the child of the root with the described name
        '''
        elements = self.__root.getElementsByTagName(elemName)
        if elements:
            return elements[0]

        return elements

    def __createTextNode(self, data):
        '''
        Creates a text node with utf8 data inside.
        The text is escaped to an fit the xml text Format.
        '''
        if data is None:
            return self.__doc.createTextNode(u'')
        else:
            escaped_data = saxutils.escape(data, ENTITIES)
            return self.__doc.createTextNode(escaped_data)

    def __createAttribute(self, attrName, attrValue):
        '''
        Creates an attribute node with utf8 data inside.
        The text is escaped to an fit the xml text Format.
        '''
        attr = self.__doc.createAttribute(attrName)
        if attrValue is None:
            attr.nodeValue = u''
        else:
            attr.nodeValue = getUnicode(attrValue)
        return attr

    def string(self, header, data, sort=True):
        '''
        Adds string element to the xml.
        '''
        if isinstance(data, (list, tuple, set)):
            self.lister(header, data, sort)
            return

        messagesElem = self.__getRootChild(MESSAGES_ELEM_NAME)
        if (not (messagesElem)):
            messagesElem = self.__doc.createElement(MESSAGES_ELEM_NAME)
            self.__addToRoot(messagesElem)

        if data:
            data = self.__formatString(data)
        else:
            data = ""

        elem = self.__doc.createElement(MESSAGE_ELEM)
        elem.setAttributeNode(self.__createAttribute(TYPE_ATTR, header))
        elem.appendChild(self.__createTextNode(data))
        messagesElem.appendChild(elem)

    def lister(self, header, elements, sort=True):
        '''
        Adds information formatted as list element
        '''
        lstElem = self.__doc.createElement(LST_ELEM_NAME)
        lstElem.setAttributeNode(self.__createAttribute(TYPE_ATTR, header))
        if elements:

            if sort:
                try:
                    elements = set(elements)
                    elements = list(elements)
                    elements.sort(key=lambda x: x.lower())
                except:
                    pass

            for element in elements:
                memberElem = self.__doc.createElement(MEMBER_ELEM)
                lstElem.appendChild(memberElem)
                if isinstance(element, basestring):
                    memberElem.setAttributeNode(
                        self.__createAttribute(TYPE_ATTR, "string"))
                    memberElem.appendChild(self.__createTextNode(element))
                elif isinstance(element, (list, tuple, set)):
                    memberElem.setAttributeNode(
                        self.__createAttribute(TYPE_ATTR, "list"))
                    for e in element:
                        memberElemStr = self.__doc.createElement(MEMBER_ELEM)
                        memberElemStr.setAttributeNode(
                            self.__createAttribute(TYPE_ATTR, "string"))
                        memberElemStr.appendChild(
                            self.__createTextNode(getUnicode(e)))
                        memberElem.appendChild(memberElemStr)
        listsElem = self.__getRootChild(LSTS_ELEM_NAME)
        if not (listsElem):
            listsElem = self.__doc.createElement(LSTS_ELEM_NAME)
            self.__addToRoot(listsElem)
        listsElem.appendChild(lstElem)

    def technic(self, technicType, data):
        '''
        Adds information about the technic used to extract data from the db
        '''
        technicElem = self.__doc.createElement(TECHNIC_ELEM_NAME)
        technicElem.setAttributeNode(
            self.__createAttribute(TYPE_ATTR, technicType))
        textNode = self.__createTextNode(data)
        technicElem.appendChild(textNode)
        technicsElem = self.__getRootChild(TECHNICS_ELEM_NAME)
        if not (technicsElem):
            technicsElem = self.__doc.createElement(TECHNICS_ELEM_NAME)
            self.__addToRoot(technicsElem)
        technicsElem.appendChild(technicElem)

    def banner(self, data):
        '''
        Adds information about the database banner to the xml.
        The banner contains information about the type and the version of the database.
        '''
        bannerElem = self.__doc.createElement(BANNER_ELEM_NAME)
        bannerElem.appendChild(self.__createTextNode(data))
        self.__addToRoot(bannerElem)

    def currentUser(self, data):
        '''
        Adds information about the current database user to the xml
        '''
        currentUserElem = self.__doc.createElement(CURRENT_USER_ELEM_NAME)
        textNode = self.__createTextNode(data)
        currentUserElem.appendChild(textNode)
        self.__addToRoot(currentUserElem)

    def currentDb(self, data):
        '''
        Adds information about the current database is use to the xml
        '''
        currentDBElem = self.__doc.createElement(CURRENT_DB_ELEM_NAME)
        textNode = self.__createTextNode(data)
        currentDBElem.appendChild(textNode)
        self.__addToRoot(currentDBElem)

    def dba(self, isDBA):
        '''
        Adds information to the xml that indicates whether the user has DBA privileges
        '''
        isDBAElem = self.__doc.createElement(IS_DBA_ELEM_NAME)
        isDBAElem.setAttributeNode(
            self.__createAttribute(VALUE_ATTR, getUnicode(isDBA)))
        self.__addToRoot(isDBAElem)

    def users(self, users):
        '''
        Adds a list of the existing users to the xml
        '''
        usersElem = self.__doc.createElement(USERS_ELEM_NAME)
        if isinstance(users, basestring):
            users = [users]
        if users:
            for user in users:
                userElem = self.__doc.createElement(DB_USER_ELEM_NAME)
                usersElem.appendChild(userElem)
                userElem.appendChild(self.__createTextNode(user))
        self.__addToRoot(usersElem)

    def dbs(self, dbs):
        '''
        Adds a list of the existing databases to the xml
        '''
        dbsElem = self.__doc.createElement(DBS_ELEM_NAME)
        if dbs:
            for db in dbs:
                dbElem = self.__doc.createElement(DB_NAME_ELEM_NAME)
                dbsElem.appendChild(dbElem)
                dbElem.appendChild(self.__createTextNode(db))
        self.__addToRoot(dbsElem)

    def userSettings(self, header, userSettings, subHeader):
        '''
        Adds information about the user's settings to the xml.
        The information can be user's passwords, privileges and etc..
        '''
        self.__areAdmins = set()
        userSettingsElem = self.__getRootChild(USER_SETTINGS_ELEM_NAME)
        if (not (userSettingsElem)):
            userSettingsElem = self.__doc.createElement(
                USER_SETTINGS_ELEM_NAME)
            self.__addToRoot(userSettingsElem)

        userSettingElem = self.__doc.createElement(USER_SETTING_ELEM_NAME)
        userSettingElem.setAttributeNode(
            self.__createAttribute(TYPE_ATTR, header))

        if isinstance(userSettings, (tuple, list, set)):
            self.__areAdmins = userSettings[1]
            userSettings = userSettings[0]

        users = userSettings.keys()
        users.sort(key=lambda x: x.lower())

        for user in users:
            userElem = self.__doc.createElement(USER_ELEM_NAME)
            userSettingElem.appendChild(userElem)
            if user in self.__areAdmins:
                userElem.setAttributeNode(
                    self.__createAttribute(TYPE_ATTR, ADMIN_USER))
            else:
                userElem.setAttributeNode(
                    self.__createAttribute(TYPE_ATTR, REGULAR_USER))

            settings = userSettings[user]

            settings.sort()

            for setting in settings:
                settingsElem = self.__doc.createElement(SETTINGS_ELEM_NAME)
                settingsElem.setAttributeNode(
                    self.__createAttribute(TYPE_ATTR, subHeader))
                settingTextNode = self.__createTextNode(setting)
                settingsElem.appendChild(settingTextNode)
                userElem.appendChild(settingsElem)
        userSettingsElem.appendChild(userSettingElem)

    def dbTables(self, dbTables):
        '''
        Adds information of the existing db tables to the xml
        '''
        if not isinstance(dbTables, dict):
            self.string(TABLES_ELEM_NAME, dbTables)
            return

        dbTablesElem = self.__doc.createElement(DB_TABLES_ELEM_NAME)

        for db, tables in dbTables.items():
            tables.sort(key=lambda x: x.lower())
            dbElem = self.__doc.createElement(DATABASE_ELEM_NAME)
            dbElem.setAttributeNode(self.__createAttribute(NAME_ATTR, db))
            dbTablesElem.appendChild(dbElem)
            for table in tables:
                tableElem = self.__doc.createElement(DB_TABLE_ELEM_NAME)
                tableElem.appendChild(self.__createTextNode(table))
                dbElem.appendChild(tableElem)
        self.__addToRoot(dbTablesElem)

    def dbTableColumns(self, tableColumns):
        '''
        Adds information about the columns of the existing tables to the xml
        '''

        columnsElem = self.__getRootChild(COLUMNS_ELEM_NAME)
        if not (columnsElem):
            columnsElem = self.__doc.createElement(COLUMNS_ELEM_NAME)

        for db, tables in tableColumns.items():
            if not db:
                db = DEFAULT_DB
            dbElem = self.__doc.createElement(DATABASE_COLUMNS_ELEM)
            dbElem.setAttributeNode(self.__createAttribute(NAME_ATTR, db))
            columnsElem.appendChild(dbElem)

            for table, columns in tables.items():
                tableElem = self.__doc.createElement(TABLE_ELEM_NAME)
                tableElem.setAttributeNode(
                    self.__createAttribute(NAME_ATTR, table))

                colList = columns.keys()
                colList.sort(key=lambda x: x.lower())

                for column in colList:
                    colType = columns[column]
                    colElem = self.__doc.createElement(COLUMN_ELEM_NAME)
                    if colType is not None:
                        colElem.setAttributeNode(
                            self.__createAttribute(TYPE_ATTR, colType))
                    else:
                        colElem.setAttributeNode(
                            self.__createAttribute(TYPE_ATTR,
                                                   UNKNOWN_COLUMN_TYPE))
                    colElem.appendChild(self.__createTextNode(column))
                    tableElem.appendChild(colElem)

        self.__addToRoot(columnsElem)

    def dbTableValues(self, tableValues):
        '''
        Adds the values of specific table to the xml.
        The values are organized according to the relevant row and column.
        '''
        tableElem = self.__doc.createElement(DB_TABLE_VALUES_ELEM_NAME)
        if (tableValues is not None):
            db = tableValues["__infos__"]["db"]
            if not db:
                db = "All"
            table = tableValues["__infos__"]["table"]

            count = int(tableValues["__infos__"]["count"])
            columns = tableValues.keys()
            columns.sort(key=lambda x: x.lower())

            tableElem.setAttributeNode(self.__createAttribute(DB_ATTR, db))
            tableElem.setAttributeNode(self.__createAttribute(
                NAME_ATTR, table))

            for i in range(count):
                rowElem = self.__doc.createElement(ROW_ELEM_NAME)
                tableElem.appendChild(rowElem)
                for column in columns:
                    if column != "__infos__":
                        info = tableValues[column]
                        value = info["values"][i]

                        if re.search("^[\ *]*$", value):
                            value = "NULL"

                        cellElem = self.__doc.createElement(CELL_ELEM_NAME)
                        cellElem.setAttributeNode(
                            self.__createAttribute(COLUMN_ATTR, column))
                        cellElem.appendChild(self.__createTextNode(value))
                        rowElem.appendChild(cellElem)

        dbValuesElem = self.__getRootChild(DB_VALUES_ELEM)
        if (not (dbValuesElem)):
            dbValuesElem = self.__doc.createElement(DB_VALUES_ELEM)
            self.__addToRoot(dbValuesElem)

        dbValuesElem.appendChild(tableElem)

        logger.info("Table '%s.%s' dumped to XML file" % (db, table))

    def dbColumns(self, dbColumns, colConsider, dbs):
        '''
        Adds information about the columns
        '''
        for column in dbColumns.keys():
            printDbs = {}
            for db, tblData in dbs.items():
                for tbl, colData in tblData.items():
                    for col, dataType in colData.items():
                        if column in col:
                            if db in printDbs:
                                if tbl in printDbs[db]:
                                    printDbs[db][tbl][col] = dataType
                                else:
                                    printDbs[db][tbl] = {col: dataType}
                            else:
                                printDbs[db] = {}
                                printDbs[db][tbl] = {col: dataType}

                            continue

        self.dbTableColumns(printDbs)

    def query(self, query, queryRes):
        '''
        Adds details of an executed query to the xml.
        The query details are the query itself and it's results.
        '''
        queryElem = self.__doc.createElement(QUERY_ELEM_NAME)
        queryElem.setAttributeNode(self.__createAttribute(VALUE_ATTR, query))
        queryElem.appendChild(self.__createTextNode(queryRes))
        queriesElem = self.__getRootChild(QUERIES_ELEM_NAME)
        if (not (queriesElem)):
            queriesElem = self.__doc.createElement(QUERIES_ELEM_NAME)
            self.__addToRoot(queriesElem)
        queriesElem.appendChild(queryElem)

    def registerValue(self, registerData):
        '''
        Adds information about an extracted registry key to the xml
        '''
        registerElem = self.__doc.createElement(REGISTER_DATA_ELEM_NAME)
        registerElem.appendChild(self.__createTextNode(registerData))
        registriesElem = self.__getRootChild(REGISTERY_ENTRIES_ELEM_NAME)
        if (not (registriesElem)):
            registriesElem = self.__doc.createElement(
                REGISTERY_ENTRIES_ELEM_NAME)
            self.__addToRoot(registriesElem)
        registriesElem.appendChild(registerElem)

    def rFile(self, filePath, data):
        '''
        Adds an extracted file's content to the xml
        '''
        fileContentElem = self.__doc.createElement(FILE_CONTENT_ELEM_NAME)
        fileContentElem.setAttributeNode(
            self.__createAttribute(NAME_ATTR, filePath))
        fileContentElem.appendChild(self.__createTextNode(data))
        self.__addToRoot(fileContentElem)

    def setOutputFile(self):
        '''
        Initiates the xml file from the configuration.
        '''
        if (conf.xmlFile):
            try:
                self.__outputFile = conf.xmlFile
                self.__root = None

                if os.path.exists(self.__outputFile):
                    try:
                        self.__doc = xml.dom.minidom.parse(self.__outputFile)
                        self.__root = self.__doc.childNodes[0]
                    except ExpatError:
                        self.__doc = Document()

                self.__outputFP = codecs.open(self.__outputFile, "w+",
                                              UNICODE_ENCODING)

                if self.__root is None:
                    self.__root = self.__doc.createElementNS(
                        NAME_SPACE_ATTR, RESULTS_ELEM_NAME)
                    self.__root.setAttributeNode(
                        self.__createAttribute(XMLNS_ATTR, NAME_SPACE_ATTR))
                    self.__root.setAttributeNode(
                        self.__createAttribute(SCHEME_NAME_ATTR, SCHEME_NAME))
                    self.__doc.appendChild(self.__root)
            except IOError:
                raise sqlmapFilePathException(
                    "Wrong filename provided for saving the xml file: %s" %
                    conf.xmlFile)

    def getOutputFile(self):
        return self.__outputFile

    def finish(self, resultStatus, resultMsg=""):
        '''
        Finishes the dumper operation:
        1. Adds the session status to the xml
        2. Writes the xml to the file
        3. Closes the xml file
        '''
        if ((self.__outputFP is not None) and not (self.__outputFP.closed)):
            statusElem = self.__doc.createElement(STATUS_ELEM_NAME)
            statusElem.setAttributeNode(
                self.__createAttribute(SUCESS_ATTR, getUnicode(resultStatus)))

            if not resultStatus:
                errorElem = self.__doc.createElement(ERROR_ELEM_NAME)

                if isinstance(resultMsg, Exception):
                    errorElem.setAttributeNode(
                        self.__createAttribute(TYPE_ATTR,
                                               type(resultMsg).__name__))
                else:
                    errorElem.setAttributeNode(
                        self.__createAttribute(TYPE_ATTR,
                                               UNHANDLED_PROBLEM_TYPE))

                errorElem.appendChild(
                    self.__createTextNode(getUnicode(resultMsg)))
                statusElem.appendChild(errorElem)

            self.__addToRoot(statusElem)
            self.__write(
                prettyprint.formatXML(self.__doc, encoding=UNICODE_ENCODING))
            self.__outputFP.close()
Example #8
0
def createATTRIBUTE(parent, attr):
    for attribute in attr:
        attributeNode = Document.createAttribute(None, attribute)
        attributeNode.value = attr[attribute]
        #print( attributeNode.name, "=", attributeNode.value )
        parent.setAttributeNode(attributeNode)
Example #9
0
def getTax(args):
   
    try: # get strings out of args
        DOCtype = args.get('docType')
        docType = DOCtype[0]
        
        sessionId = args['sessionId']
        SID = sessionId[0]

        DOCID = args['docId']
        docID = DOCID[0]
        OrderQUERY=("DOCID= '" + docID + "'")
        ItemQUERY=("DOCHDID= '" + docID + "'")
    except Exception as e:
        pass

    try: # Write the XML request with the minidom  module
        newdoc = Document()
        ############## CONTROL ELEMENT #######################
        request = newdoc.createElement('request')
        newdoc.appendChild(request)
        control = newdoc.createElement('control')
        request.appendChild(control)
        senderid = newdoc.createElement('senderid')
        control.appendChild(senderid).appendChild(newdoc.createTextNode(senderId))
        senderpassword = newdoc.createElement('password')
        control.appendChild(senderpassword).appendChild(newdoc.createTextNode(senderPassword))
        controlid = newdoc.createElement('controlid')
        control.appendChild(controlid).appendChild(newdoc.createTextNode("testRequestId"))
        uniqueid = newdoc.createElement('uniqueid')
        control.appendChild(uniqueid).appendChild(newdoc.createTextNode("false"))
        dtdversion = newdoc.createElement('dtdversion')
        control.appendChild(dtdversion).appendChild(newdoc.createTextNode("3.0"))
        includewhitespace = newdoc.createElement('includewhitespace')
        control.appendChild(includewhitespace).appendChild(newdoc.createTextNode("false"))

        operation = newdoc.createElement('operation')
        request.appendChild(operation)

        ############### AUTHENTICATION ELEMENT ####################
        authentication = newdoc.createElement('authentication')
        operation.appendChild(authentication)

        sessionid = newdoc.createElement('sessionid')
        authentication.appendChild(sessionid).appendChild(newdoc.createTextNode(SID))

        ################ CONTENT ELEMENT ##########################
        content = newdoc.createElement('content')
        operation.appendChild(content)
        function = newdoc.createElement('function')
        content.appendChild(function).setAttributeNode(newdoc.createAttribute('controlid'))
        function.attributes["controlid"].value = "testFunctionId"

        
        queryFields = [
        'RECORDNO',
        'DOCNO',
        'DOCID',  # order number?
        'CUSTOMER.NAME',
        'CUSTOMER.CUSTOMERID',
        'BILLTO.MAILADDRESS.CITY',
        'BILLTO.MAILADDRESS.STATE',
        'BILLTO.MAILADDRESS.ZIP',
        'BILLTO.MAILADDRESS.COUNTRY',
        'BILLTO.MAILADDRESS.COUNTRYCODE',
        'SHIPTO.MAILADDRESS.CITY',
        'SHIPTO.MAILADDRESS.STATE',
        'SHIPTO.MAILADDRESS.ZIP',
        'SHIPTO.MAILADDRESS.COUNTRY',
        'SHIPTO.MAILADDRESS.COUNTRYCODE',
        'SUBTOTAL',
        'TOTAL']
 
        Fields = "RECORDNO,DOCNO,DOCID,CUSTOMER.NAME,CUSTOMER.CUSTOMERID,BILLTO.MAILADDRESS.CITY,BILLTO.MAILADDRESS.STATE,BILLTO.MAILADDRESS.ZIP,BILLTO.MAILADDRESS.COUNTRY,BILLTO.MAILADDRESS.COUNTRYCODE,SHIPTO.MAILADDRESS.CITY,SHIPTO.MAILADDRESS.STATE,SHIPTO.MAILADDRESS.ZIP,SHIPTO.MAILADDRESS.COUNTRY,SHIPTO.MAILADDRESS.COUNTRYCODE,SUBTOTAL,TOTAL"
        
    # Sales Order Query
        if (docType == "Sales Order"):
            readByQuery = newdoc.createElement('readByQuery')
            function.appendChild(readByQuery)
            object = newdoc.createElement('object')
            readByQuery.appendChild(object).appendChild(newdoc.createTextNode("SODOCUMENT"))
            fields = newdoc.createElement('fields')
            readByQuery.appendChild(fields).appendChild(newdoc.createTextNode(Fields))
            query = newdoc.createElement('query')
            readByQuery.appendChild(query).appendChild(newdoc.createTextNode(OrderQUERY)) # All records
    # Purchase Order Query 
        if (docType == 'Purchase Order'):
            readByQuery = newdoc.createElement('readByQuery')
            function.appendChild(readByQuery)
            object = newdoc.createElement('object')
            readByQuery.appendChild(object).appendChild(newdoc.createTextNode("PODOCUMENT"))
            fields = newdoc.createElement('fields')
            readByQuery.appendChild(fields).appendChild(newdoc.createTextNode(Fields))
            query = newdoc.createElement('query')
            readByQuery.appendChild(query).appendChild(newdoc.createTextNode(OrderQUERY))

        # print(request.toprettyxml())

        # Post the request
        response = XMLRequestClient.XMLRequestClient.post(request)

    except Exception as inst:
        print("\nUh oh, something is wrong in getTax()")
        print(type(inst))
        print(inst.args)
        print("end of getTax Error\n")

# convert responce data into readable format
    # print(response.toprettyxml())
    orderxml=response.toxml()
    mytree= ET.fromstring(orderxml)
    operation=mytree[1]
    results=operation[1]
    data=results[3]
    potato=data[0]
    print(potato)
#  Put order fields into an array
    # for x in data[0]:
    #     print(x.tag, x.text)
    try:
        order={}
        x=0
        for field in queryFields:
            order[field]=potato[x].text
            x+=1

    except Exception as inst:
        print("\nUh oh, something is wrong in order details()")
        print(type(inst))
        print(inst.args)
        print("end of getTax Error\n")
    
    print(order)


# Query for order items

    # queryFields = [
    #     'RECORDNO',
    #     'ITEMID',
    #     'ITEMNAME',
    #     'QUANTITY',
    #     'PRICE',
    #     'TOTAL',
    # ]

    # Fields = "RECORDNO,ITEMID,ITEMNAME,QUANTITY,PRICE,TOTAL"

    # try: # Write the XML request with the minidom  module
    #     newdoc = Document()
    #     ############## CONTROL ELEMENT #######################
    #     request = newdoc.createElement('request')
    #     newdoc.appendChild(request)
    #     control = newdoc.createElement('control')
    #     request.appendChild(control)
    #     senderid = newdoc.createElement('senderid')
    #     control.appendChild(senderid).appendChild(newdoc.createTextNode(senderId))
    #     senderpassword = newdoc.createElement('password')
    #     control.appendChild(senderpassword).appendChild(newdoc.createTextNode(senderPassword))
    #     controlid = newdoc.createElement('controlid')
    #     control.appendChild(controlid).appendChild(newdoc.createTextNode("testRequestId"))
    #     uniqueid = newdoc.createElement('uniqueid')
    #     control.appendChild(uniqueid).appendChild(newdoc.createTextNode("false"))
    #     dtdversion = newdoc.createElement('dtdversion')
    #     control.appendChild(dtdversion).appendChild(newdoc.createTextNode("3.0"))
    #     includewhitespace = newdoc.createElement('includewhitespace')
    #     control.appendChild(includewhitespace).appendChild(newdoc.createTextNode("false"))

    #     operation = newdoc.createElement('operation')
    #     request.appendChild(operation)

    #     ############### AUTHENTICATION ELEMENT ####################
    #     authentication = newdoc.createElement('authentication')
    #     operation.appendChild(authentication)

    #     sessionid = newdoc.createElement('sessionid')
    #     authentication.appendChild(sessionid).appendChild(newdoc.createTextNode(SID))

    #     ################ CONTENT ELEMENT ##########################
    #     content = newdoc.createElement('content')
    #     operation.appendChild(content)
    #     function = newdoc.createElement('function')
    #     content.appendChild(function).setAttributeNode(newdoc.createAttribute('controlid'))
    #     function.attributes["controlid"].value = "testFunctionId"
    # # Sales Order Query
    #     if (docType == "Sales Order"):
    #         readByQuery = newdoc.createElement('readByQuery')
    #         function.appendChild(readByQuery)
    #         object = newdoc.createElement('object')
    #         readByQuery.appendChild(object).appendChild(newdoc.createTextNode("SODOCUMENTENTRY"))
    #         fields = newdoc.createElement('fields')
    #         readByQuery.appendChild(fields).appendChild(newdoc.createTextNode(queryFields))
    #         query = newdoc.createElement('query')
    #         readByQuery.appendChild(query).appendChild(newdoc.createTextNode(ItemQUERY)) # All records
    # # Purchase Order Query 
    #     if (docType == 'Purchase Order'):
    #         readByQuery = newdoc.createElement('readByQuery')
    #         function.appendChild(readByQuery)
    #         object = newdoc.createElement('object')
    #         readByQuery.appendChild(object).appendChild(newdoc.createTextNode("PODOCUMENTENTRY"))
    #         fields = newdoc.createElement('fields')
    #         readByQuery.appendChild(fields).appendChild(newdoc.createTextNode(queryFields))
    #         query = newdoc.createElement('query')
    #         readByQuery.appendChild(query).appendChild(newdoc.createTextNode(ItemQUERY))
    
    # #send Request
    #     response = XMLRequestClient.XMLRequestClient.post(request)

    # except Exception as inst:
    #     print("\nUh oh, something is wrong in orderitems()")
    #     print(type(inst))
    #     print(inst.args)
    #     print("end of getTax Error\n")

    # print(response.toprettyxml)
    


    placehorder= "No Tax to return yet"
    return(placehorder)
Example #10
0
def vendors(request):

    vens = []

    #pull vendors, filter by entity
    newdoc = Document();
    request = newdoc.createElement('request')
    newdoc.appendChild(request)
    control = newdoc.createElement('control')
    request.appendChild(control)
    senderid = newdoc.createElement('senderid')
    control.appendChild(senderid).appendChild(newdoc.createTextNode(acc_keys.int_sender_id()))
    senderpassword = newdoc.createElement('password')
    control.appendChild(senderpassword).appendChild(newdoc.createTextNode(acc_keys.int_sender_pass()))
    controlid = newdoc.createElement('controlid')
    control.appendChild(controlid).appendChild(newdoc.createTextNode(str(int(time.time()))))
    uniqueid = newdoc.createElement('uniqueid')
    control.appendChild(uniqueid).appendChild(newdoc.createTextNode("false"))
    dtdversion = newdoc.createElement('dtdversion')
    control.appendChild(dtdversion).appendChild(newdoc.createTextNode("3.0"))
    includewhitespace = newdoc.createElement('includewhitespace')
    control.appendChild(includewhitespace).appendChild(newdoc.createTextNode("false"))

    operation = newdoc.createElement('operation')
    request.appendChild(operation)

    authentication = newdoc.createElement('authentication')
    operation.appendChild(operation)

    s = Session.objects.order_by('-session_time')
    ses = s[0].sessionid

    sessionid = newdoc.createElement('sessionid')
    authentication.appendChild(sessionid).appendChild(newdoc.createTextNode(ses))

    content = newdoc.createElement('content')
    operation.appendChild(content)

    function = newdoc.createElement('function')
    content.appendChild(function).setAttributeNode(newdoc.createAttribute('controlid'))
    function.attributes["controlid"].value = "1"

    read = newdoc.createElement('readByQuery')
    function.appendChild(read)

    objectt = newdoc.createElement('object')
    read.appendChild(objectt).appendChild(newdoc.createTextNode('VENDOR'))

    fields = newdoc.createElement('fields')
    read.appendChild(objectt).appendChild(newdoc.createTextNode('*'))

    query = newdoc.createElement('query')
    read.appendChild(query)

    pagesize = newdoc.createElement('pagesize')
    read.appendChild(pagesize).appendChild(newdoc.createTextNode('3'))

    print(request.toprettyxml())
    #print(request)
    # Post the request
    #result = XMLRequestClient.post(request)
    '''
    for vendor in result.getElementsByTagName('vendor'):
        for tag in vendor.getElementsByTagName('DISPLAYCONTACT.PRINTAS'):
            ven = tag[0].firstChild.nodeValue
            vens.append(ven)
    '''

    #paginate
    #finish pagination
    #send list
    context = {vens}
    return render(request, 'intacct/vendors.html', context)
Example #11
0
def create_session():
    try:
        # Write the XML request with the minidom  module
        newdoc = Document()
        request = newdoc.createElement('request')
        newdoc.appendChild(request)
        control = newdoc.createElement('control')
        request.appendChild(control)
        senderid = newdoc.createElement('senderid')
        control.appendChild(senderid).appendChild(
            newdoc.createTextNode(acc_keys.int_sender_id()))
        senderpassword = newdoc.createElement('password')
        control.appendChild(senderpassword).appendChild(
            newdoc.createTextNode(acc_keys.int_sender_pass()))
        controlid = newdoc.createElement('controlid')
        control.appendChild(controlid).appendChild(
            newdoc.createTextNode(str(int(time.time()))))
        uniqueid = newdoc.createElement('uniqueid')
        control.appendChild(uniqueid).appendChild(
            newdoc.createTextNode("false"))
        dtdversion = newdoc.createElement('dtdversion')
        control.appendChild(dtdversion).appendChild(
            newdoc.createTextNode("3.0"))
        includewhitespace = newdoc.createElement('includewhitespace')
        control.appendChild(includewhitespace).appendChild(
            newdoc.createTextNode("false"))

        operation = newdoc.createElement('operation')
        request.appendChild(operation)

        authentication = newdoc.createElement('authentication')
        operation.appendChild(authentication)

        login = newdoc.createElement('login')
        authentication.appendChild(login)

        userid = newdoc.createElement('userid')
        login.appendChild(userid).appendChild(
            newdoc.createTextNode(acc_keys.int_user()))

        companyid = newdoc.createElement('companyid')
        login.appendChild(companyid).appendChild(
            newdoc.createTextNode(acc_keys.int_company_id()))

        password = newdoc.createElement('password')
        login.appendChild(password).appendChild(
            newdoc.createTextNode(acc_keys.int_user_pass()))

        content = newdoc.createElement('content')
        operation.appendChild(content)

        function = newdoc.createElement('function')
        content.appendChild(function).setAttributeNode(
            newdoc.createAttribute('controlid'))
        function.attributes["controlid"].value = "1"

        create = newdoc.createElement('getAPISession')
        function.appendChild(create)

        #print(request.toprettyxml())

        # Post the request
        result = XMLRequestClient.post(request)

        # Print the XML response to the console
        #print(result.toprettyxml())

        find = result.getElementsByTagName('sessionid')
        sessionid = find[0].firstChild.nodeValue
        return sessionid

    except Exception as inst:
        print("Uh oh, something is wrong")
        print(type(inst))
        print(inst.args)