示例#1
0
 def __init__(self):
     QSData.__init__(self)
     Path.set_umit_conf(os.path.dirname(sys.argv[0]))
     Path.set_running_path(os.path.abspath(os.path.dirname(sys.argv[0])))
     data = QSData()
     self.recent_scans = data.get_recent_scans()
     self.profiles = data.get_profiles()
     self.target_list = data.get_target_list
     self.nmap_options = data.get_nmap_options()
     self.nmap_command_option = data.get_nmap_command_option()
     self.db_data = data.get_from_db()
示例#2
0
 def __init__(self):
     QSData.__init__(self)
     Path.set_umit_conf(os.path.dirname(sys.argv[0]))
     Path.set_running_path(os.path.abspath(os.path.dirname(sys.argv[0])))
     data = QSData()
     self.recent_scans = data.get_recent_scans()
     self.profiles = data.get_profiles()
     self.target_list = data.get_target_list
     self.nmap_options = data.get_nmap_options()
     self.nmap_command_option = data.get_nmap_command_option()
     self.db_data = data.get_from_db()
示例#3
0
def setup_homedir(usethis, force=False):
    """
    Setting umit home directory.
    """
    if force:
        Path.force_set_umit_conf(usethis)
    else:
        Path.set_umit_conf(usethis)

    global HOME_CONF, RUNNING_FILE

    HOME_CONF = os.path.split(Path.get_umit_conf())[0]
    RUNNING_FILE = os.path.join(HOME_CONF, 'schedrunning')
def setup_homedir(usethis, force=False):
    """
    Setting umit home directory.
    """
    if force:
        Path.force_set_umit_conf(usethis)
    else:
        Path.set_umit_conf(usethis)

    global HOME_CONF, RUNNING_FILE

    HOME_CONF = os.path.split(Path.get_umit_conf())[0]
    RUNNING_FILE = os.path.join(HOME_CONF, 'qsrunning')
    def __init__(self, nmap_path, command, host):
        Path.set_umit_conf(os.path.dirname(sys.argv[0]))
        Path.set_running_path(os.path.abspath(os.path.dirname(sys.argv[0])))
        self.nmap_path = nmap_path
        self.command = command
        #add option for ipv6 address by checking the host
        #
        #
        #check for ipv6 address and -6 to command option 

        
        if Ipv6.is_ipv6(host):
            	command = command +" -6"
        self.host = host
示例#6
0
def write_startup_setting(section, setting, value):
    """
    Set a new value for a startup setting.
    """
    configparser.set(section, setting, value)

    if section == TL_SECTION:
        configparser.write(open(TL_SETTINGS, 'w'))
        # update representation
        configparser.read(TL_SETTINGS)
    elif section == INV_SECTION:
        configparser.write(open(Path.get_umit_conf(), 'w'))
        # update representation
        configparser.read(Path.get_umit_conf())
示例#7
0
def write_startup_setting(section, setting, value):
    """
    Set a new value for a startup setting.
    """
    configparser.set(section, setting, value)

    if section == TL_SECTION:
        configparser.write(open(TL_SETTINGS, 'w'))
        # update representation
        configparser.read(TL_SETTINGS)
    elif section == INV_SECTION:
        configparser.write(open(Path.get_umit_conf(), 'w'))
        # update representation
        configparser.read(Path.get_umit_conf())
示例#8
0
def main(cmd, base_path, home_conf, winhndl=None):
    if base_path not in sys.path:
        sys.path.insert(0, base_path)
    Path.force_set_umit_conf(home_conf)
    log = file_log(Path.sched_log)

    globals()['log'] = log

    # Trying to adjust signals when running as a windows service won't work
    # since it needs to be adjusted while on the main thread.
    if not servicemanager.RunningAsService():
        if os.name == "posix":
            signal.signal(signal.SIGHUP, safe_shutdown)
        signal.signal(signal.SIGTERM, safe_shutdown)
        signal.signal(signal.SIGINT, safe_shutdown)

    cmds = {'start': start}
    cmds[cmd](winhndl=winhndl)
示例#9
0
def main(cmd, base_path, home_conf, winhndl=None):
    if base_path not in sys.path:
        sys.path.insert(0, base_path)
    Path.force_set_umit_conf(home_conf)
    log = file_log(Path.sched_log)

    globals()['log'] = log

    # Trying to adjust signals when running as a windows service won't work
    # since it needs to be adjusted while on the main thread.
    if not servicemanager.RunningAsService():
        if os.name == "posix":
            signal.signal(signal.SIGHUP, safe_shutdown)
        signal.signal(signal.SIGTERM, safe_shutdown)
        signal.signal(signal.SIGINT, safe_shutdown)

    cmds = {'start': start}
    cmds[cmd](winhndl=winhndl)
示例#10
0
    def __init__(self, running_file=None, home_conf=None, verbose=False,
            svc_class=None, svc_path=None):
        if running_file is None or home_conf is None:
            if home_conf is None:
                home_conf = os.path.split(Path.get_umit_conf())[0]
            running_file = os.path.join(home_conf, 'schedrunning')

        self.svc_class = svc_class
        self.svc_path = svc_path
        self.running_file = running_file
        self.home_conf = home_conf
        self.verbose = verbose
示例#11
0
    def __init__(self,
                 running_file=None,
                 home_conf=None,
                 verbose=False,
                 svc_class=None,
                 svc_path=None):
        if running_file is None or home_conf is None:
            if home_conf is None:
                home_conf = os.path.split(Path.get_umit_conf())[0]
            running_file = os.path.join(home_conf, 'schedrunning')

        self.svc_class = svc_class
        self.svc_path = svc_path
        self.running_file = running_file
        self.home_conf = home_conf
        self.verbose = verbose
示例#12
0
def get_config_file(filename, original_content):
    config_file = mktemp()

    try:
        c = Path.__getattr__(filename)
        if exists(c) and access(c, R_OK):
            config_file = c
        else:
            raise Exception()
    except:
        # Using temporary file
        cfile = open(config_file, "w")
        cfile.write(original_content)
        cfile.close()

    log.debug(">>> Get config file %s: %s" % (filename, config_file))
    return config_file
示例#13
0
def get_config_file(filename, original_content):
    config_file = mktemp()

    try:
        c = Path.__getattr__(filename)
        if exists(c) and access(c, R_OK):
            config_file = c
        else:
            raise Exception()
    except:
        # Using temporary file
        cfile = open(config_file, "w")
        cfile.write(original_content)
        cfile.close()

    log.debug(">>> Get config file %s: %s" % (filename, config_file))
    return config_file
示例#14
0
    def start(self, from_gui=False):
        """Start scheduler."""
        if NT:
            bg = BGRunner(self.svc_class, self.svc_path)
            from_gui = False
        else:
            if from_gui:
                # Take care when running from gui
                running_path = Path.get_running_path()
                if running_path not in sys.path:
                    sys.path.append(running_path)
                starter = __import__('umit_scheduler')
                subprocess.Popen([sys.executable, starter.__file__, 'start'])
            else:
                def post_init():
                    return main('start', sys.path[0], self.home_conf)
                bg = BGRunner(self.running_file, post_init)

        if not from_gui:
            err = bg.start()
            if err:
                return self._error(err)
示例#15
0
    def start(self, from_gui=False):
        """Start scheduler."""
        if NT:
            bg = BGRunner(self.svc_class, self.svc_path)
            from_gui = False
        else:
            if from_gui:
                # Take care when running from gui
                running_path = Path.get_running_path()
                if running_path not in sys.path:
                    sys.path.append(running_path)
                starter = __import__('umit_scheduler')
                subprocess.Popen([sys.executable, starter.__file__, 'start'])
            else:

                def post_init():
                    return main('start', sys.path[0], self.home_conf)

                bg = BGRunner(self.running_file, post_init)

        if not from_gui:
            err = bg.start()
            if err:
                return self._error(err)
示例#16
0

"""
import gtk
import cairo
import gobject

from higwidgets.higboxes import HIGHBox
from higwidgets.higscrollers import HIGScrolledWindow

from umit.preferences.widgets.IconToggleWidget import IconToggleWidget

import os.path
from umit.core.Paths import Path
# Develpment step
Path.set_umit_conf("umit")


class TabStruct:
    """ Struct of tab """
    def __init__(self):
        """ Constructor """
        self.__list = {}
        self.__first_k = None

    ### Interface - Public Functions ###
    def add_item(self, name, image=None, image_bw=None, widget=None):
        """
        @param name name of item
        @param image image selected
        @param image_bw imae black and white - unselected
import os
import sys
import gtk
import gobject

from umit.core.I18N import _
from umit.core.Paths import Path
from umit.core.Utils import amiroot, open_url_as
from umit.core.Scheduler import SchedulerControl

from umit.gui.GenericAlertDialogs import GenericAlert
from umit.gui.Help import show_help

if os.name == 'nt':
    run_path = Path.get_running_path()
    if run_path not in sys.path:
        sys.path.append(run_path)

    umit_scheduler = __import__("umit_scheduler")
    class SchedulerControl(object):
        def __getattr__(self, name):
            return lambda *args, **kwargs: umit_scheduler.main([name], False)

START_TEXT = _("Start Scheduler")
STOP_TEXT = _("Stop Scheduler")

class SchedControl(object):
    """
    GUI for controlling Scheduler starting/stopping.
    """
示例#18
0
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
"""
Controls read and write for startup options in Network Inventory.
"""

from ConfigParser import ConfigParser

from umit.core.Paths import Path

TL_SETTINGS = Path.tl_conf
TL_SECTION = "Startup"
INV_SECTION = "inventory"

configparser = ConfigParser()
configparser.read((TL_SETTINGS, Path.get_umit_conf()))


def startup_options():
    """
    Returns startup options dict.
    """
    startup = {}

    section = TL_SECTION

    for opt, value in configparser.items(section):
        startup[opt] = value

    section = INV_SECTION
示例#19
0
"""
Simple python script to replace update.sh
"""

import os
import sys
import glob
import os.path

cwd = os.getcwd()
root = os.path.dirname(cwd)
sys.path.insert(0, root)

from umit.core.Paths import Path
Path.set_umit_conf(os.path.split(sys.argv[0])[0])

plug_dir = os.path.join(Path.config_dir, "plugins")

sys.path.pop(0)
os.environ["PYTHONPATH"] = root

def build_in(dir_entry):
    os.chdir(os.path.join(cwd, dir_entry))

    if os.name =="nt":
        os.system("C:\\python25\\python.exe setup.py build_ext -c mingw32 install")
    else:
        os.system("python setup.py install")

    for plugin in glob.glob("*.ump"):
示例#20
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

import unittest

# Setting up Paths so UmitConf can be correctly loaded
from os.path import join
import os
import sys
from umit.core.Paths import Path
Path.set_umit_conf(os.path.dirname(sys.argv[0]))

# Loading Host Discovery
from umit.inventory.HostDiscovery import tryto_detect_networks, _darwin_get_addresses
from umit.inventory.HostDiscovery import NetIface


class TestGetIPv4(unittest.TestCase):
    
    def testGetIP(self):
        ifaces = tryto_detect_networks() # No Loopback

        # Get Real IP address
        import subprocess
        import tempfile
        
示例#21
0
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

import unittest

# Setting up Paths so UmitConf can be correctly loaded
from os.path import join
from umit.core.Paths import Path
Path.set_umit_conf([join("share", "umit", "config", "umit.conf")])

# Loading UmitConf files
from umit.core.UmitConf import *


class TestUmitConf(unittest.TestCase):
    def setUp(self):
        self.umit_conf = UmitConf()

    def tearDown(self):
        del self.umit_conf

    def testGetColoredDiff(self):
        self.umit_conf.colored_diff
        try:
            self.scan_exec.run_scan()
        except OSError, msg:
            raise(msg)
        
        try:
            while self.scan_exec.scan_state():
                print ">>>", self.scan_exec.get_normal_output()
        except Exception:
            print "Exception caught"
            
            
        from umit.core.UmitDB import Scans

        state = self.scan_exec.scan_state()
        if state == False:
            store = Scans(scan_name="Quick Scan on %s" % self.host,
                          nmap_xml_output=self.scan_exec.get_xml_output(),
                          date=datetime.now())
                
            return self.scan_exec.get_normal_output()
        
        return False

if __name__ == "__main__":
    Path.set_umit_conf(os.path.dirname(sys.argv[0]))
    Path.set_running_path(os.path.abspath(os.path.dirname(sys.argv[0])))
    b = Nmap(Path.nmap_command_path, "Agressive -v", "google.com")
    b.run()
    
# 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

"""
A module with a cool name that controls database data removal if it gets 
too old.
"""

from ConfigParser import ConfigParser, NoOptionError, NoSectionError
from umit.core.Paths import Path
from umit.db.Remove import ScanRemover

umitdb = Path.umitdb_ng
umit_conf = Path.get_umit_conf()

def get_decays():
    """
    Return decay for Inventory data and standard UMIT data.
    """
    section = "database"
    
    cfgparse = ConfigParser()
    cfgparse.read(umit_conf)
    
    decays = ()
    
    try:
        decays = (cfgparse.getint(section, "umit_decay"),
                  cfgparse.getint(section, "inventory_decay"))
示例#24
0

"""
import gtk
import cairo
import gobject

from higwidgets.higboxes import HIGHBox
from higwidgets.higscrollers import HIGScrolledWindow

from umit.preferences.widgets.IconToggleWidget import IconToggleWidget

import os.path
from umit.core.Paths import Path
# Develpment step
Path.set_umit_conf("umit")


class TabStruct:
    """ Struct of tab """
    def __init__(self):
        """ Constructor """
        self.__list = {}
        self.__first_k = None
    ### Interface - Public Functions ###
    def add_item(self, name, image=None, image_bw=None, widget=None):
        """
        @param name name of item
        @param image image selected
        @param image_bw imae black and white - unselected
        @param widget widget associated
示例#25
0
import os
import sys
import gtk
import gobject

from umit.core.I18N import _
from umit.core.Paths import Path
from umit.core.Utils import amiroot, open_url_as
from umit.core.qs.QuickScan import QuickScanControl

from umit.gui.GenericAlertDialogs import GenericAlert
from umit.gui.Help import show_help

if os.name == 'nt':
    run_path = Path.get_running_path()
    if run_path not in sys.path:
        sys.path.append(run_path)

    qs_launcher = __import__("quickscan_launcher")
    class QuickScanControl(object):
        def __getattr__(self, name):
            return lambda *args, **kwargs: quickscan_launcher.main([name], False)


class QSControl(object):
    """
    GUI for controlling QuickScan launching.
    """

    def __init__(self, daddy):
示例#26
0
# USA

"""
Controls read and write for startup options in Network Inventory.
"""

from ConfigParser import ConfigParser

from umit.core.Paths import Path

TL_SETTINGS = Path.tl_conf
TL_SECTION = "Startup"
INV_SECTION = "inventory"

configparser = ConfigParser()
configparser.read((TL_SETTINGS, Path.get_umit_conf()))

def startup_options():
    """
    Returns startup options dict.
    """
    startup = { }

    section = TL_SECTION

    for opt, value in configparser.items(section):
        startup[opt] = value

    section = INV_SECTION

    inv_opts = configparser.options(section)
示例#27
0
 def __init__(self):
     Path.set_umit_conf(os.path.dirname(sys.argv[0]))
     Path.set_running_path(os.path.abspath(os.path.dirname(sys.argv[0])))