Example #1
0
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA

from umit.db.Utils import empty
from umit.db.Utils import log_debug

debug = log_debug('umit.db.Store')

"""
Missing methods for:
    Traceroute insertion.
"""

class RawStore:
    """
    Store data into database.
    """

    def __init__(self, conn, cursor):
        """
        Expects a conn and cursor from database connection.
        """
Example #2
0
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA

from umit.db.Utils import empty
from umit.db.Utils import log_debug
from umit.db.Utils import normalize
from umit.db.Connection import ConnectDB

"""
Missing methods for:
    Traceroute retrieval.
"""

debug = log_debug('umit.db.Retrieve')

class RawRetrieve:
    """
    Retrieve raw data from database.
    """

    def __init__(self, conn, cursor):
        """
        Expects a conn and cursor from database connection.
        """
        self.conn = conn
        self.cursor = cursor


    def get_service_info_id_from_db(self, info, service_name_id):
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA

from datetime import datetime, timedelta

from umit.db.Utils import log_debug
from umit.db.Connection import ConnectDB
from umit.db.Retrieve import CompositeRetrieve

debug = log_debug('umit.db.Remove')

class ScanRemover(ConnectDB, CompositeRetrieve):
    """
    Removes scans from database.
    """

    def __init__(self, database):
        ConnectDB.__init__(self, database)
        CompositeRetrieve.__init__(self, self.conn, self.cursor)


    def remove_scan(self, fk_scan):
        """
        Removes a scan from database.
        """
Example #4
0
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA

from umit.db.Utils import empty
from umit.db.Utils import log_debug
from umit.db.Utils import normalize
from umit.db.Connection import ConnectDB
"""
Missing methods for:
    Traceroute retrieval.
"""

debug = log_debug('umit.db.Retrieve')


class RawRetrieve:
    """
    Retrieve raw data from database.
    """
    def __init__(self, conn, cursor):
        """
        Expects a conn and cursor from database connection.
        """
        self.conn = conn
        self.cursor = cursor

    def get_service_info_id_from_db(self, info, service_name_id):
        """
Example #5
0
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA

from umit.db.Utils import empty
from umit.db.Utils import log_debug

debug = log_debug('umit.db.Store')
"""
Missing methods for:
    Traceroute insertion.
"""


class RawStore:
    """
    Store data into database.
    """
    def __init__(self, conn, cursor):
        """
        Expects a conn and cursor from database connection.
        """
        self.conn = conn
Example #6
0
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA

from datetime import datetime

from umit.core.NmapParser import NmapParser

from umit.db.Connection import ConnectDB
from umit.db.Store import RawStore
from umit.db.Retrieve import InventoryRetrieve
from umit.db.InventoryChanges import UpdateChanges
from umit.db.Utils import empty, log_debug, normalize

debug = log_debug('umit.db.XMLStore')

class XMLStore(ConnectDB, InventoryRetrieve, RawStore):
    """
    Stores xml into database.
    """

    def __init__(self, database, store_original=False):
        """
        store_original  -   stores xml files in the database or not
        """

        ConnectDB.__init__(self, database)
        InventoryRetrieve.__init__(self, self.conn, self.cursor)
        RawStore.__init__(self, self.conn, self.cursor)
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA

from umit.db.Utils import log_debug
from umit.db.Connection import ConnectDB
from umit.db.Retrieve import CompositeRetrieve

from umit.core.I18N import _

debug = log_debug('umit.db.Search')

change_text = (_("change"), _("changes"))
port_text = (_("port"), _("ports"), _("service"))
comparison = ("<", ">", "==", ">=", "<=", "!=")


def perform_comparison(ports, compare, decider):
    """
    Compare ports against decider using especified comparation.
    """
    decider = int(decider)

    # ports are numbered in ascendent order.
    for port in ports:
        if compare == '>':
Example #8
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA

from umit.db.Utils import log_debug
from umit.db.Connection import ConnectDB
from umit.db.Retrieve import CompositeRetrieve

from umit.core.I18N import _

debug = log_debug('umit.db.Search')

change_text = (_("change"), _("changes"))
port_text = (_("port"), _("ports"), _("service"))
comparison = ("<", ">", "==", ">=", "<=", "!=")

def perform_comparison(ports, compare, decider):
    """
    Compare ports against decider using especified comparation.
    """
    decider = int(decider)

    # ports are numbered in ascendent order.
    for port in ports:
        if compare == '>':
            if decider <= port[0]:
Example #9
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA

from umit.core.I18N import _

from umit.db.Utils import log_debug
from umit.db.Connection import ConnectDB
from umit.db.Store import RawStore
from umit.db.Retrieve import InventoryRetrieve

debug = log_debug("umit.db.InventoryChanges")


class BadParams(Exception):
    pass


class ConnectToUpdate(ConnectDB, InventoryRetrieve, RawStore):
    """
    You should use this when doing inventory changes update exclusively
    in database.
    """
    def __init__(self, database):
        ConnectDB.__init__(self, database)
        InventoryRetrieve.__init__(self, self.conn, self.cursor)
        RawStore.__init__(self, self.conn, self.cursor)
Example #10
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA

from datetime import datetime, timedelta

from umit.db.Utils import log_debug
from umit.db.Connection import ConnectDB
from umit.db.Retrieve import CompositeRetrieve

debug = log_debug("umit.db.Remove")


class ScanRemover(ConnectDB, CompositeRetrieve):
    """
    Removes scans from database.
    """

    def __init__(self, database):
        ConnectDB.__init__(self, database)
        CompositeRetrieve.__init__(self, self.conn, self.cursor)

    def remove_scan(self, fk_scan):
        """
        Removes a scan from database.
        """
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA

from umit.core.I18N import _

from umit.db.Utils import log_debug
from umit.db.Connection import ConnectDB
from umit.db.Store import RawStore
from umit.db.Retrieve import InventoryRetrieve

debug = log_debug("umit.db.InventoryChanges")

class BadParams(Exception):
    pass

class ConnectToUpdate(ConnectDB, InventoryRetrieve, RawStore):
    """
    You should use this when doing inventory changes update exclusively
    in database.
    """

    def __init__(self, database):
        ConnectDB.__init__(self, database)
        InventoryRetrieve.__init__(self, self.conn, self.cursor)
        RawStore.__init__(self, self.conn, self.cursor)
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
"""
This handles connections to the database.
"""

from umit.db._database import sql
from umit.db._database import database
from umit.db.Utils import log_debug

debug = log_debug('umit.db.Connection')


def dict_factory(cursor, row):
    """
    Convert a standard row to a dict.
    """
    d = {}

    for idx, col in enumerate(cursor.description):
        d[col[0]] = row[idx]

    return d


class ConnectDB:
Example #13
0
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA

"""
This handles connections to the database.
"""

from umit.db._database import sql
from umit.db._database import database
from umit.db.Utils import log_debug

debug = log_debug('umit.db.Connection')

def dict_factory(cursor, row):
    """
    Convert a standard row to a dict.
    """
    d = {}

    for idx, col in enumerate(cursor.description):
        d[col[0]] = row[idx]

    return d


class ConnectDB:
    """