Пример #1
0
    def mod_user(self):
        self.task_usermod = None
        self.task_grpmod = None
        self.task_modcmt = None
        i = snack.ListboxChoiceWindow(self.screen,
                                      self.task_type[0],
                                      "Pick a User Modification Task",
                                      [("Add Group Membership", "addgrp"),
                                       ("Remove Group Membership", "remgrp"),
                                       ("Modify Account Comment", "modcmt")],
                                      buttons=['Ok', 'Back'], width=65)
        if i[0] != 'back':
            self.task_usermod = i
            if i[1] in ['addgrp', 'remgrp']:
                self.set_user()
                grp = snack.EntryWindow(self.screen,
                                        self.task_type[0],
                                        "Provide Groups: "
                                        "(ie: group1,group2,group3)\n",
                                        ["Groups: "],
                                        buttons=['Ok', 'Back'],
                                        width=65, entryWidth=40)
                if grp[0] != 'back':
                    self.task_grpmod = grp
                    self.set_hosts()
                else:
                    self.mod_user()

            elif i[1] == 'modcmt':
                self.set_user()
                cmt = snack.EntryWindow(self.screen,
                                        self.task_type[0],
                                        "Update info for %s"
                                        % self.task_user[1][0],
                                        ["First Name",
                                         "Last Name",
                                         ("Company/Department",
                                          lugms_settings.company),
                                         ("Phone Number",
                                          lugms_settings.phone),
                                         ("Accnt Type",
                                          lugms_settings.acct_type)],
                                        buttons=['Ok', 'Back'],
                                        width=65, entryWidth=40)
                if cmt[0] != 'back':
                    self.task_modcmt = cmt
                    cstring = str()
                    for v in self.task_modcmt[1]:
                        if v.strip():
                            cstring = cstring + v + " "
                    self.user_comment = cstring.rstrip()
                    self.set_hosts()
                else:
                    self.mod_user()
        else:
            self.get_task()
Пример #2
0
    def askuserIP(self, nodename):
        #
        # ask the user for an IP address
        #
        done = 0

        while not done:
            entry = snack.Entry(15)

            rc, values = snack.EntryWindow(
                self.screen,
                _("IP Address Selection"),
                _("Enter the IP address for host %s") % (nodename),
                [(_("IP Address"), entry)],
                buttons=['Ok'])

            ipaddr = entry.value()
            try:

                nodeid = self.sql.getNodeId(ipaddr)
                if nodeid:
                    msg = "Duplicate IP '%s' Specified" % ipaddr
                    raise rocks.util.CommandError, msg
                self.setIPaddr(ipaddr)
                done = 1
            except rocks.util.CommandError:
                snack.ButtonChoiceWindow(self.screen,
                 _("Duplicate IP"),
                 _("The IP address (%s) already exists.\n\n" \
                 % (ipaddr) + "Please select another."),
                 buttons = [ _("OK") ])

        return ipaddr
Пример #3
0
 def action_create(self):
     i = snack.EntryWindow(self.screen,
                           self.task_type[0],
                           "Please enter action Information",
                           ["action_name ",
                            "group_name"],
                           buttons=['Ok', 'Back'],
                           width=65, entryWidth=40)
     if i[0] != 'back':
         self.action = i
         action_name=self.action[1][0]
         group_name=self.action[1][1]
         zabbix=zabbix_api(False,False,output=False)
         info = zabbix.action_autoreg_create(action_name,group_name)
         info_dirt=eval(info)
         snack.ButtonChoiceWindow(self.screen,
                                              "%s" % self.task_type[0],
                                              "Info:\n\n"
                                              "%s: %s"
                                              % (info_dirt["status"],info_dirt["output"]),
                                              buttons=['Ok'],
                                              width=65)
             
         self.get_task()
     else:
         self.get_task()
Пример #4
0
 def set_user(self):
     i = snack.EntryWindow(self.screen,
                           self.task_type[0],
                           "Please enter User ID",
                           ["User ID: "],
                           buttons=['Ok', 'Back'],
                           width=65, entryWidth=20)
     if i[0] != 'back':
         self.task_user = i
     else:
         self.get_task()
Пример #5
0
 def InputBox(self, title, prompt, label_value_list, entryWidth=20):
     label_entry = []
     for label, value in label_value_list:
         label_entry.append((label, value))
     buttons = self._NormalizeButtons(self.MB_OKCANCEL)
     return snack.EntryWindow(self.screen,
                              title,
                              prompt,
                              label_entry,
                              buttons=buttons,
                              entryWidth=entryWidth)
Пример #6
0
def get_nfs_dest(answers):
    text = "Please enter the server and path of your NFS share (e.g. myserver:/my/directory)"
    label = "NFS Path:"

    if 'dest-address' in answers:
        default = answers['dest-address']
    else:
        default = ""
    (button, result) = snack.EntryWindow(tui.screen,
                                         "Specify Path",
                                         text, [(label, default)],
                                         entryWidth=50,
                                         width=50,
                                         buttons=['Ok', 'Back'],
                                         help='getnfsdest')

    if button == 'back': return uicontroller.LEFT_BACKWARDS

    answers['dest-address'] = result[0]

    return uicontroller.RIGHT_FORWARDS
Пример #7
0
 def modificarConfiguracion(self):
     config = ConfigParser.RawConfigParser()
     config.read(self.archivo)
     banned_ip = config.get('Datos', 'banned_ip')
     banned_site = config.get('Datos', 'banned_site')
     banned_extension = config.get('Datos', 'banned_extension')
     exception_ip = config.get('Datos', 'exception_ip')
     exception_site = config.get('Datos', 'exception_site')
     exception_extension = config.get('Datos', 'exception_extension')
     archivo_log = config.get('Datos', 'logging')
     gw = config.get('Datos', 'default_gateway')
     (buttons, valores) = snack.EntryWindow(
         self.screen,
         self.titulo,
         self.texto, [('IP Bloqueadas', banned_ip),
                      ('IP Liberadas', exception_ip),
                      ('Dominios Bloqueados', banned_site),
                      ('Dominios Liberados', exception_site),
                      ('Extensiones Bloqueadas', banned_extension),
                      ('Extensiones Liberadas', exception_extension),
                      ('Archivo LOG', archivo_log),
                      ('Default Gateway', gw)],
         width=40,
         buttons=['Aceptar', 'Cancelar'])
     config = ConfigParser.RawConfigParser()
     config.add_section('Datos')
     config.set('Datos', 'banned_ip', valores[0])
     config.set('Datos', 'exception_ip', valores[1])
     config.set('Datos', 'banned_site', valores[2])
     config.set('Datos', 'exception_site', valores[3])
     config.set('Datos', 'banned_extension', valores[4])
     config.set('Datos', 'exception_extension', valores[5])
     config.set('Datos', 'logging', valores[6])
     config.set('Datos', 'default_gateway', valores[7])
     if (buttons == "aceptar"):
         configfile = open(self.archivo, "wb")
         config.write(configfile)
Пример #8
0
    def askuserIP(self, nodename):
        #
        # ask the user for an IP address
        #
        done = 0

        while not done:
            entry = snack.Entry(15)

            rc, values = snack.EntryWindow(
                self.screen,
                _("IP Address Selection"),
                _("Enter the IP address for host %s") % (nodename),
                [(_("IP Address"), entry)],
                buttons=['Ok'])

            ipaddr = entry.value()
            try:
                query = 'select id from networks where ' +\
                 'ip="%s"' % ipaddr
                rows = self.sql.execute(query)
                if rows:
                    raise ValueError, "Duplicate IP"

                self.setIPaddr(ipaddr)
                done = 1
            except ValueError:
                msg = _("The IP address (%s) " % ipaddr +\
                 "already exists.\n" ) +\
                 _("Please select another.")
                snack.ButtonChoiceWindow(self.screen,
                                         _("Duplicate IP"),
                                         msg,
                                         buttons=[_("OK")])

        return ipaddr
Пример #9
0
 def set_hosts(self, val=None):
     i = snack.ListboxChoiceWindow(self.screen,
                                   self.task_type[0],
                                   "Select Servers",
                                   [('Specific Servers', "hosts_ind"),
                                    ('All Linux Servers', 'hosts_all')],
                                   buttons=['Ok', 'Back'], width=65)
     if i[0] != 'back':
         self.task_hosts = i
         if i[1] == 'hosts_ind':
             if val:
                 ind = snack.EntryWindow(self.screen,
                                         self.task_type[0],
                                         "Provide Hostnames: "
                                         "(ie: server1,server2,server3)",
                                         [("Hosts: ", val)],
                                         buttons=['Ok', 'Back'],
                                         width=65, entryWidth=40)
             else:
                 ind = snack.EntryWindow(self.screen,
                                         self.task_type[0],
                                         "Provide Host Names\n"
                                         "ie: server1,server2,server3",
                                         ["Hosts: "],
                                         buttons=['Ok', 'Back'],
                                         width=65, entryWidth=40)
             if ind[0] != 'back' and len(ind[1][0].split(',')) >= 1:
                 taskhosts = str()
                 invalhosts = str()
                 hostlist = ind[1][0].split(',')
                 hostlist = list(set(hostlist))
                 hostlist.sort()
                 for host in hostlist:
                     if host in validhosts:
                         taskhosts = taskhosts + (host + ',')
                     else:
                         invalhosts = invalhosts + (host + ',')
                 taskhosts = taskhosts.rstrip(",")
                 invalhosts = invalhosts.rstrip(",")
                 if taskhosts == '':
                     snack.ButtonChoiceWindow(self.screen,
                                              self.task_type[0],
                                              "No Valid Hostnames Provided",
                                              buttons=['Ok'], width=65)
                     self.set_hosts()
                 elif len(invalhosts) > 1:
                     snack.ButtonChoiceWindow(self.screen,
                                              self.task_type[0],
                                              "Valid hostnames: %s\n"
                                              "\nInvalid hostnames: %s\n"
                                              "\nPlease re-verify hosts.."
                                              % (taskhosts, invalhosts),
                                              buttons=['Verify Hosts'],
                                              width=65)
                     self.set_hosts(taskhosts)
                 else:
                     self.task_hostsind = ind
             else:
                 self.set_hosts()
     else:
         self.get_task()
Пример #10
0
while not salida:
    screen = snack.SnackScreen()
    _salida, modo = snack.ListboxChoiceWindow(
        screen,
        "Modo de descarga",
        "Elije un modo para descargar el paquete", [
            "Descargar el RPM",
            "Descargar el contenido del RPM (RPM descomprimido)",
            "Descargar el RPM y el contenido del mismo",
            "Descargar el RPM y sus dependencias", "Descargar un grupo"
        ],
        buttons=["Ok", "Salir"])
    if _salida != "salir":
        data = snack.EntryWindow(
            screen, "Paquete a descargar", "Escribe los siguientes datos", [
                "Nombre del paquete o grupo: ",
                "Directorio donde se guardará lo descargado: "
            ])
        if data[0] == "ok":
            pack, dir = data[1]
            screen.suspend()
            if modo == 0:
                os.system("yumdownloader --disablerepo=dextrose " + pack)
                os.system("mv *.rpm " + dir)
                raw_input("Presiona enter para continuar")
                screen.resume()
            elif modo == 1:
                os.system("yumdownloader --disablerepo=dextrose " + pack)
                os.system("rpm2cpio *.rpm | cpio -ivd")
                os.system("rm *.rpm")
                os.system("mv * " + dir)
Пример #11
0
    def run_selector(self):
        """
        Compile and run the task selector.

        See: http://www.wanware.com/tsgdocs/snack.html for info on the
        python snack module.
        Also look at the code in snack.py to understand what it is doing.
        """
        wdays_short = "M  T  W  T  F  S  S  "

        extrahkeysdict = {
            '0': ' mod due:today',
            '1': ' mod due:1d',
            '2': ' mod due:2d',
            '3': ' mod due:3d',
            '4': ' mod due:4d',
            '5': ' mod due:5d',
            '6': ' mod due:6d',
            '7': ' mod due:7d',
            '8': ' mod due:1w',
            '9': ' mod due:2w',
            'd': ' done',
            'i': ' info',
            'h': ' HELP'
        }

        for key in extrahkeysdict.keys():
            snack.hotkeys[key] = ord(key)  # Add to the snack hkey library
            snack.hotkeys[ord(key)] = key
        screen = snack.SnackScreen()
        buttonlist = [("1d", "1d", "F1"), ("2d", "2d", "F2"),
                      ("3d", "3d", "F3"), ("1w", "1w", "F4"),
                      ("2w", "2w", "F5")]
        mybuttonbar = snack.ButtonBar(screen, buttonlist, 1)
        lbox = snack.Listbox(height=20,
                             width=90,
                             returnExit=1,
                             multiple=1,
                             border=1,
                             scroll=1)
        for task in self.tasks:  # Step through list of task dictionary objects
            taskline, tdate = self.compile_taskline(task)
            lbox.append(taskline, task["id"])
        grid = snack.GridForm(screen, wdays_short * self.weeks, 3, 3)
        # Note the padding option.  It is set to shift the lbox content one
        # position to the right so as to allign with the dayheader at the top
        grid.add(lbox, 0, 0, padding=(1, 0, 0, 0))
        grid.add(mybuttonbar, 0, 1, growx=1)
        grid.addHotKey('ESC')
        for key in extrahkeysdict.keys():
            grid.addHotKey(key)
        result = grid.runOnce()  # This is the key of the HotKey dict
        buttonpressed = mybuttonbar.buttonPressed(result)  # The Hotkey dict \
        # value of key in 'result'.  Returns None if no hotkey or button \
        # pressed
        selection = lbox.getSelection()  # This is a list

        # The first set of if options deals with all the exceptions while \
        # the last 'else' deals with actual task manupulations.
        if result == 'ESC':
            screen.finish()
            return (None, True)
        elif result == 'h':
            mytext = ''
            for mykey in sorted(extrahkeysdict):
                mytext = mytext + '\n' + mykey + ': ' + extrahkeysdict[mykey]
            snack.ButtonChoiceWindow(screen, 'Help', mytext, ['Ok'])
            screen.finish()
            return (None, False)
        elif result == 'i':
            basictaskstr = 'task ' + str(lbox.current()) + ' info'
            mytext = commands.getoutput(basictaskstr)
            snack.ButtonChoiceWindow(screen, 'Task information', mytext, \
                ['Ok'],width=80)
            screen.finish()
            return (None, False)
        else:
            # Get the selected or current task/s from the listbox
            if len(selection) > 0:
                # Joins the selections into comma seperated list, and suppresses
                # confirmation for this number of tasks
                # basictaskstr = 'task ' + ','.join(map(repr, lbox.getSelection())) \
                basictaskstr = 'task ' + ','.join(map(repr, selection)) \
                    + ' rc.bulk:' + str(len(selection) + 1)
            else:  # If no selections have been made use the current task
                basictaskstr = 'task ' + str(lbox.current())

            # Figure out what commands to add, if any given
            if buttonpressed:
                # TODO Change values in Buttonlist dict so that it provides the full command\
                #    so that it can be used in the same way as if any other hotkey was pressed
                basictaskstr = basictaskstr + ' mod due:' + buttonpressed
            elif result in extrahkeysdict:  # If a hotkey not linked to button.
                basictaskstr = basictaskstr + extrahkeysdict[result]
            else:  # Else type in the rest of the command.
                basictaskstr = basictaskstr + ' mod '

            result2 = snack.EntryWindow(screen, "Command details...", \
                "", [('Command to be executed:', basictaskstr)], width=50, \
                entryWidth=30, buttons=[('OK', 'OK', 'F1'), ('Cancel', 'Cancel',
                'ESC')])  # Look at the code for this function to understand this
            screen.finish()
            if result2[0] == 'Cancel':
                return (None, True)
            else:
                print '>' + result2[1][0]
                return (commands.getoutput(result2[1][0]), False)