def set_profile_active(self, profile):
     profilelist = getProfileList()
     for prof in profilelist:
         if prof.ProfileName == profile:
             prof.Active = True
             #print "profile " + prof.ProfileName + " activated\n"
         else:
             prof.Active = False
         prof.commit()
 def getProfDeviceList(self, refresh=None):
     profilelist = getProfileList(refresh)
     prof = profilelist.getActiveProfile()
     devlist = getDeviceList(refresh)
     activedevlist = []
     for devid in prof.ActiveDevices:
         for dev in devlist:
             if dev.DeviceId != devid:
                 continue
             break
         else:
             continue
         activedevlist.append(dev)  # pylint: disable-msg=W0631
     return activedevlist
    def hydrateProfiles(self, refresh=None):
        profilelist = getProfileList(refresh)

        self.no_profileentry_update = True
        omenu = self.xml.get_widget('profileOption')

        if len(profilelist) == 1:
            self.xml.get_widget('profileFrame').hide()

        if omenu:
            omenu.remove_menu()

        menu = gtk.Menu()
        history = 0
        i = 0
        for prof in profilelist:
            name = prof.ProfileName
            # change the default profile to a more understandable name
            if name == "default":
                name = DEFAULT_PROFILE_NAME
            if prof.Active == True:
                name += _(" (active)")
            menu_item = gtk.MenuItem(name)
            menu_item.show()
            menu_item.connect("activate", self.on_profileMenuItem_activated,
                              prof.ProfileName)
            menu.append(menu_item)
            if prof.ProfileName == self.get_active_profile().ProfileName:
                history = i
                if self.oldprofile == None:
                    self.oldprofile = prof.ProfileName
            i = i + 1
        if self.get_active_profile().ProfileName != self.oldprofile:
            self.xml.get_widget('interfaceClist').set_sensitive(False)
        else:
            self.xml.get_widget('interfaceClist').set_sensitive(True)
        menu.show()

        if omenu:
            omenu.set_menu(menu)
            omenu.set_history(history)

        menu.get_children()[history].activate()
        self.no_profileentry_update = False
示例#4
0
    def on_ipsecDruidFinishPage_finish(self, druid_page, druid):
        profilelist = getProfileList()
        for prof in profilelist:
            if self.ipsec.oldname and self.ipsec.oldname in prof.ActiveIPsecs:
                prof.ActiveIPsecs.remove(self.ipsec.oldname)
                prof.ActiveIPsecs.append(self.ipsec.IPsecId)

            if prof.Active == False:
                continue
            if not self.ipsec.oldname:
                prof.ActiveIPsecs.append(self.ipsec.IPsecId)
            break

        profilelist.commit()

        self.druid.hide()
        self.druid.destroy()
        gtk.main_quit()
        return False
 def get_active_profile(self):
     profilelist = getProfileList()
     return profilelist.getActiveProfile()
示例#6
0
 def saveProfiles(self):
     if not self.do_save:
         return
     profilelist = getProfileList()
     profilelist.save()
示例#7
0
def main(mcmdline):
    from netconfpkg.NCDeviceList import getDeviceList
    from netconfpkg.NCHardwareList import getHardwareList               
    from netconfpkg.NCIPsecList import getIPsecList
    from netconfpkg.NCProfileList import getProfileList
    from netconfpkg.NC_functions import log

    signal.signal (signal.SIGINT, signal.SIG_DFL)
    class BadUsage(Exception):
        pass

    #progname = os.path.basename(sys.argv[0])
    NC_functions.setVerboseLevel(2)
    NC_functions.setDebugLevel(0)

    do_activate = 0
    switch_profile = 0
    profile = None
    test = 0
    EXPORT = 1
    IMPORT = 2
    SWITCH = 3
    mode = EXPORT
    filename = None
    clear = 0
    chroot = None
    debug = None
    devlists = []

    try:
        opts = getopt.getopt(mcmdline, "asp:?r:dhvtief:co",
                                   [
                                    "activate",
                                    "profile=",
                                    "help",
                                    "devicelist",
                                    "verbose",
                                    "test",
                                    "import",
                                    "export",
                                    "clear",
                                    "root=",
                                    "file=",
                                    "debug",
                                    "hardwarelist",
                                    "ipseclist",
                                    "profilelist"])[0]
        for opt, val in opts:
            if opt == '-r' or opt == '--root':                
                chroot = val
                NC_functions.prepareRoot(chroot)
                NC_functions.updateNetworkScripts()
                continue
    except (getopt.error, BadUsage):
        pass

    try:
        opts = getopt.getopt(mcmdline, "asp:?r:dhvtief:co",
                                   [
                                    "activate",
                                    "profile=",
                                    "help",
                                    "devicelist",
                                    "verbose",
                                    "test",
                                    "import",
                                    "export",
                                    "clear",
                                    "root=",
                                    "file=",
                                    "debug",
                                    "hardwarelist",
                                    "ipseclist",
                                    "profilelist"])[0]
        for opt, val in opts:
            if opt == '-d' or opt == '--devicelist':
                devlists.append(getDeviceList())
                continue

            if opt == '-h' or opt == '--hardwarelist':
                devlists.append(getHardwareList())
                continue

            if opt == '-s' or opt == '--ipseclist':
                devlists.append(getIPsecList())
                continue

            if opt == '-o' or opt == '--profilelist':
                devlists.append(getProfileList())
                continue

            if opt == '-p' or opt == '--profile':
                mode = SWITCH
                switch_profile = 1
                profile = val
                continue

            if opt == '-f' or opt == '--file':
                filename = val
                continue

            if opt == '-r' or opt == '--root':
                # already parsed
                continue

            if opt == '-c' or opt == '--clear':
                clear = 1
                continue

            if opt == '-t' or opt == '--test':
                test = 1
                continue

            if opt == '-a' or opt == '--activate':
                mode = SWITCH
                do_activate = 1
                continue

            if opt == '-i' or opt == '--import':
                mode = IMPORT
                continue

            if opt == '-e' or opt == '--export':
                mode = EXPORT
                continue

            if opt == '-?' or opt == '--help':
                Usage()
                return(0)

            if opt == '-v' or opt == '--verbose':
                NC_functions.setVerboseLevel(NC_functions.getVerboseLevel()+1)
                continue

            if opt == '--debug':
                NC_functions.setDebugLevel(NC_functions.getDebugLevel()+1)
                debug = 1
                continue

            sys.stderr.write(_("Unknown option %s\n" % opt))
            raise BadUsage

    except (getopt.error, BadUsage):
        Usage()
        return(1)

    try:

        if not NC_functions.getDebugLevel():
            log.handler = log.syslog_handler
            log.open()
        else:
            log.handler = log.file_handler
            log.open(sys.stderr)

        if not len(devlists):
            devlists = [getDeviceList(), getHardwareList(),
                        getIPsecList(),
                        getProfileList()]

        if clear:
            for devlist in devlists:
                del devlist[0:len(devlist)]

        if mode == EXPORT:
            for devlist in devlists:
                devstr =  str(devlist)
                if len(devstr):
                    # remove the last \n
                    print devstr[:-1]
            return(0)

        elif mode == IMPORT:
            devlistsdict = {
                "HardwareList" : getHardwareList(),
                "DeviceList" : getDeviceList(),
                "IPsecList" : getIPsecList(),
                "ProfileList" : getProfileList() }

            if filename:
                mfile = open(filename, "r")
            else:
                mfile = sys.stdin

            lines = mfile.readlines()

            for line in lines:
                try:
                    line = line[:-1]
                    log.log(3, "Parsing '%s'\n" % line)
                    vals = line.split("=")
                    if len(vals) <= 1:
                        continue
                    key = vals[0]
                    value = "=".join(vals[1:])

                    vals = key.split(".")
                    if devlistsdict.has_key(vals[0]):
                        # pylint: disable-msg=W0212
                        devlistsdict[vals[0]].fromstr(vals, value)
                    else:
                        sys.stderr.write(_("Unknown List %s\n", vals[0]))
                        raise ParseError

                except Exception, e:
                    pe = ParseError(_("Error parsing line: %s") % line)
                    pe.args += e.args
                    raise pe


            for devlist in devlists:
                log.log(1, "%s" % devlist)
                devlist.save()

            return(0)

        elif test:
            return(0)
示例#8
0
                    pe.args += e.args
                    raise pe


            for devlist in devlists:
                log.log(1, "%s" % devlist)
                devlist.save()

            return(0)

        elif test:
            return(0)

        elif mode == SWITCH:
            ret = None
            profilelist = getProfileList()
            actdev = Control.NetworkDevice()
            actdev.load()
            aprof = profilelist.getActiveProfile()

            if switch_profile and aprof.ProfileName != profile:
                log.log(1, "Switching to profile %s" % profile)
                if do_activate:
                    for p in profilelist:
                        if p.ProfileName == profile:
                            aprof = p
                            break
                    for device in getDeviceList():
                        if device.DeviceId not in aprof.ActiveDevices:
                            if actdev.find(device.Device):
                                (ret, msg) = device.deactivate()