예제 #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.
        """
예제 #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.
        """
예제 #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):
        """
예제 #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
예제 #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 == '>':
예제 #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]:
예제 #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)
예제 #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.
        """
예제 #11
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)
# 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:
예제 #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:
    """