Пример #1
0
    def __generateProfileName(hardwareList):
        hostname = None
        ipaddr = ip6addr = None
        profileName = None
        for hw in hardwareList:
            if hw["class"] == "NETINFO":
                hostname = hw.get("hostname")
                ipaddr = hw.get("ipaddr")
                ip6addr = hw.get("ipaddr6")

        if hostname:
            profileName = idn_pune_to_unicode(hostname)
        elif ipaddr:
            profileName = ipaddr
        elif ip6addr:
            profileName = ip6addr

        if not profileName:
            print _(
                "A profilename was not specified, "
                "and hostname and IP address could not be determined "
                "to use as a profilename, please specify one."
            )
            sys.exit(-1)

        return profileName
Пример #2
0
    def auth_system(self):
        if CFG.DISABLE_ISS:
            raise rhnFault(2005, _('ISS is disabled on this satellite.'))

        if not rhnSQL.fetchone_dict("select 1 from rhnISSSlave where slave = :hostname and enabled = 'Y'",
            hostname = idn_pune_to_unicode(self.remote_hostname)):
            raise rhnFault(2004,
              _('Server "%s" is not enabled for ISS.')
                % self.remote_hostname)
        return self.remote_hostname
Пример #3
0
    def auth_system(self, req):
        if CFG.DISABLE_ISS:
            raise rhnFault(2005, _('ISS is disabled on this satellite.'))

        remote_hostname = req.get_remote_host(apache.REMOTE_DOUBLE_REV)
        row = rhnSQL.fetchone_dict("""
        select id, allow_all_orgs
          from rhnISSSlave
         where slave = :hostname
           and enabled = 'Y'
        """, hostname = idn_pune_to_unicode(remote_hostname))
        if not row:
            raise rhnFault(2004,
              _('Server "%s" is not enabled for ISS.')
                % remote_hostname)
        iss_slave_condition = "select id from web_customer"
        if not(row['allow_all_orgs'] == 'Y'):
            iss_slave_condition = "select rhnISSSlaveOrgs.org_id from rhnISSSlaveOrgs where slave_id = %d" % row['id']
        return iss_slave_condition
Пример #4
0
def __check_headers(h):
    if type(h) != type({}) or not hasattr(h, "has_key"):
        # does not look like a dictionary
        h = {}
    if not h.has_key("Subject"):
        h["Subject"] = "%s System Mail From %s" % (PRODUCT_NAME,
                                                   idn_pune_to_unicode(os.uname()[1]))
    if not h.has_key("To"):
        to = CFG.TRACEBACK_MAIL
    else:
        to = h["To"]
    if not ("Content-Type" in h):
        h["Content-Type"] = "text/plain; charset=utf-8"
    if type(to) in [type([]), type(())]:
        toaddrs = to
        to = ', '.join(to)
    else:
        toaddrs = to.split(',')
    h["To"] = to
    return [h, toaddrs]
Пример #5
0
def generateProfileName(hardwareList):
    hostname = None
    ipaddr = None
    profileName = None
    for hw in hardwareList:
        if hw['class'] == 'NETINFO':
            hostname = hw.get('hostname')
            ipaddr = hw.get('ipaddr')

    if hostname:
        profileName = idn_pune_to_unicode(hostname)
    else:
        if ipaddr:
            profileName = ipaddr

    if not profileName:
        print _("A profilename was not specified, "\
                "and hostname and IP address could not be determined "\
                "to use as a profilename, please specify one.")
        sys.exit(-1)

    return profileName
Пример #6
0
    def auth_system(self, req):
        if CFG.DISABLE_ISS:
            raise rhnFault(2005, _('ISS is disabled on this satellite.'))

        remote_hostname = req.get_remote_host(apache.REMOTE_DOUBLE_REV)
        row = rhnSQL.fetchone_dict(
            """
        select id, allow_all_orgs
          from rhnISSSlave
         where slave = :hostname
           and enabled = 'Y'
        """,
            hostname=idn_pune_to_unicode(remote_hostname))
        if not row:
            raise rhnFault(
                2004,
                _('Server "%s" is not enabled for ISS.') % remote_hostname)
        iss_slave_condition = "select id from web_customer"
        if not (row['allow_all_orgs'] == 'Y'):
            iss_slave_condition = "select rhnISSSlaveOrgs.org_id from rhnISSSlaveOrgs where slave_id = %d" % row[
                'id']
        return iss_slave_condition
Пример #7
0
def generateProfileName(hardwareList):
    hostname = None
    ipaddr = None
    profileName = None
    for hw in hardwareList:
        if hw['class'] == 'NETINFO':
            hostname = hw.get('hostname')
            ipaddr = hw.get('ipaddr')

    if hostname:
        profileName = idn_pune_to_unicode(hostname)
    else:
        if ipaddr:
            profileName = ipaddr

    if not profileName:
        print _("A profilename was not specified, "\
                "and hostname and IP address could not be determined "\
                "to use as a profilename, please specify one.")
        sys.exit(-1)

    return profileName
Пример #8
0
    def __init__(self, screen, tui):
        self.screen = screen
        self.tui = tui
        size = snack._snack.size()

        #get the virtualization uuid and set it to other.
        (virt_uuid, virt_type) = rhnreg.get_virt_info()
        if not virt_uuid is None:
            self.tui.other['virt_uuid'] = virt_uuid
            self.tui.other['virt_type'] = virt_type

        # read all hardware in
        tui.hardware = hardware.Hardware()

        toplevel = snack.GridForm(screen, HARDWARE_WINDOW.encode('utf-8'), 1,
                                  7)

        text = snack.TextboxReflowed(70, HARDWARE_WINDOW_DESC1.encode('utf-8'))

        toplevel.add(text, 0, 0, anchorLeft=1)

        grid = snack.Grid(2, 2)

        label = snack.Label(_("Profile name:").encode('utf-8'))
        grid.setField(label, 0, 0, padding=(0, 0, 1, 0), anchorRight=1)

        self.profileEntry = snack.Entry(40)
        grid.setField(self.profileEntry, 1, 0, anchorLeft=1)

        toplevel.add(grid, 0, 1, anchorLeft=1)

        if tui.includeHardware:
            self.hardwareButton = snack.Checkbox(
                HARDWARE_WINDOW_CHECKBOX.encode('utf-8'), isOn=1)
        else:
            self.hardwareButton = snack.Checkbox(
                HARDWARE_WINDOW_CHECKBOX.encode('utf-8'))

        toplevel.add(self.hardwareButton,
                     0,
                     2,
                     padding=(0, 1, 0, 0),
                     anchorLeft=1)

        label = snack.Label(DESELECT.encode('utf-8'))
        toplevel.add(label, 0, 3, anchorLeft=1, padding=(0, 0, 0, 1))

        grid = snack.Grid(4, 3)
        hardware_text = ''

        hardware_text += _("Version: ") + up2dateUtils.getVersion() + "  "
        self.versionLabel = snack.Label(_("Version: ").encode('utf-8'))
        grid.setField(self.versionLabel,
                      0,
                      0,
                      padding=(0, 0, 1, 0),
                      anchorLeft=1)

        self.versionLabel2 = snack.Label(up2dateUtils.getVersion())
        grid.setField(self.versionLabel2, 1, 0, anchorLeft=1)

        hardware_text += _("CPU model: ")

        for hw in tui.hardware:
            if hw['class'] == 'CPU':
                hardware_text += hw['model'] + "\n"

        hardware_text += _("Hostname: ")

        for hw in tui.hardware:
            if hw['class'] == 'NETINFO':
                unicode_hostname = idn_pune_to_unicode(hw['hostname'])
                hardware_text += unicode_hostname + "\n"

                if tui.profileName != "":
                    self.profileEntry.set(tui.profileName)
                else:
                    self.profileEntry.set(unicode_hostname.encode('utf-8'))

        hardware_text += _("CPU speed: ")

        for hw in tui.hardware:
            if hw['class'] == 'CPU':
                hardware_text += _("%d MHz") % hw['speed'] + "  "

        hardware_text += _("IP Address: ")

        for hw in tui.hardware:
            if hw['class'] == 'NETINFO':
                if hw['ipaddr']:
                    hardware_text += hw['ipaddr'] + "  "
                elif hw['ip6addr']:
                    hardware_text += hw['ip6addr'] + "  "

        hardware_text += _("Memory: ")

        for hw in tui.hardware:
            if hw['class'] == 'MEMORY':
                hardware_text += _("%s megabytes") % hw['ram']

        tb = snack.TextboxReflowed(80, hardware_text.encode('utf-8'))
        toplevel.add(tb, 0, 4)

        self.additionalHWLabel = snack.TextboxReflowed(
            size[0] - 10, HARDWARE_WINDOW_DESC2.encode('utf-8'))

        toplevel.add(self.additionalHWLabel,
                     0,
                     5,
                     padding=(0, 1, 0, 0),
                     anchorLeft=1)

        # BUTTON BAR
        self.bb = snack.ButtonBar(screen, [(NEXT.encode('utf-8'), "next"),
                                           (BACK.encode('utf-8'), "back"),
                                           (CANCEL.encode('utf-8'), "cancel")])
        toplevel.add(self.bb, 0, 6, padding=(0, 1, 0, 0), growx=1)

        self.g = toplevel
Пример #9
0
    def __init__(self, screen, tui):
        self.name = "HardwareWindow"
        self.screen = screen
        self.tui = tui
        size = snack._snack.size()

        #get the virtualization uuid and set it to other.
        (virt_uuid, virt_type) = rhnreg.get_virt_info()
        if not virt_uuid is None:
            self.tui.other['virt_uuid'] = virt_uuid
            self.tui.other['virt_type'] = virt_type

        # read all hardware in
        tui.hardware = hardware.Hardware()

        toplevel = snack.GridForm(screen, HARDWARE_WINDOW.encode('utf-8'), 1, 7)

        text = snack.TextboxReflowed(70, HARDWARE_WINDOW_DESC1.encode('utf-8'))

        toplevel.add(text, 0, 0, anchorLeft = 1)

        grid = snack.Grid(2, 2)

        label = snack.Label(_("Profile name:").encode('utf-8'))
        grid.setField(label, 0, 0, padding = (0, 0, 1, 0), anchorRight = 1)

        self.profileEntry = snack.Entry(40)
        grid.setField(self.profileEntry, 1, 0, anchorLeft = 1)

        toplevel.add(grid, 0, 1, anchorLeft = 1)

        if tui.includeHardware:
            self.hardwareButton = snack.Checkbox(HARDWARE_WINDOW_CHECKBOX.encode('utf-8'), isOn = 1)
        else:
            self.hardwareButton = snack.Checkbox(HARDWARE_WINDOW_CHECKBOX.encode('utf-8'))

        toplevel.add(self.hardwareButton, 0, 2, padding = (0, 1, 0, 0),
                     anchorLeft = 1)

        label = snack.Label(DESELECT.encode('utf-8'))
        toplevel.add(label, 0, 3, anchorLeft = 1, padding = (0, 0, 0, 1))

        grid = snack.Grid(4, 3)
        hardware_text = ''

        hardware_text += _("Version: ") + up2dateUtils.getVersion() + "  "
        self.versionLabel = snack.Label(_("Version: ").encode('utf-8'))
        grid.setField(self.versionLabel, 0, 0, padding = (0, 0, 1, 0), anchorLeft = 1)

        self.versionLabel2 = snack.Label(up2dateUtils.getVersion())
        grid.setField(self.versionLabel2, 1, 0, anchorLeft = 1)

        hardware_text += _("CPU model: ")

        for hw in tui.hardware:
            if hw['class'] == 'CPU':
                hardware_text += hw['model'] +"\n"

        hardware_text += _("Hostname: ")

        for hw in tui.hardware:
            if hw['class'] == 'NETINFO':
                unicode_hostname = idn_pune_to_unicode(hw['hostname'])
                hardware_text += unicode_hostname + "\n"

                if tui.profileName != "":
                    self.profileEntry.set(tui.profileName)
                else:
                    self.profileEntry.set(unicode_hostname.encode('utf-8'))

        hardware_text += _("CPU speed: ")

        for hw in tui.hardware:
            if hw['class'] == 'CPU':
                hardware_text += _("%d MHz") % hw['speed'] + "  "

        hardware_text += _("IP Address: ")

        for hw in tui.hardware:
            if hw['class'] == 'NETINFO':
                if hw['ipaddr']:
                    hardware_text += hw['ipaddr'] + "  "
                elif hw['ip6addr']:
                    hardware_text += hw['ip6addr'] + "  "

        hardware_text += _("Memory: ")

        for hw in tui.hardware:
            if hw['class'] == 'MEMORY':
                hardware_text += _("%s megabytes") % hw['ram']

        tb = snack.TextboxReflowed(80, hardware_text.encode('utf-8'))
        toplevel.add(tb, 0, 4)

        self.additionalHWLabel = snack.TextboxReflowed(size[0]-10, HARDWARE_WINDOW_DESC2.encode('utf-8'))

        toplevel.add(self.additionalHWLabel, 0, 5, padding = (0, 1, 0, 0),
                     anchorLeft = 1)

        # BUTTON BAR
        self.bb = snack.ButtonBar(screen,
                                  [(NEXT.encode('utf-8'), "next"),
                                   (BACK.encode('utf-8'), "back"),
                                   (CANCEL.encode('utf-8'), "cancel")])
        toplevel.add(self.bb, 0, 6, padding = (0, 1, 0, 0),
                     growx = 1)

        self.g = toplevel
Пример #10
0
def convert_url_from_pune(url):
    """ returns url where hostname is converted from Pune encoding. Returns unicode string. """
    s = urlsplit(url)
    return unicode(
        urlunsplit((s[0], idn_pune_to_unicode(s[1]), s[2], s[3], s[4])))
Пример #11
0
def Traceback(method=None,
              req=None,
              mail=1,
              ostream=sys.stderr,
              extra=None,
              severity="notification",
              with_locals=0):
    """ Reports an traceback error and optionally sends mail about it.
        NOTE: extra = extra text information.
    """
    # pylint: disable=C0103

    global QUIET_MAIL

    if mail:
        # safeguard
        if QUIET_MAIL is None:
            QUIET_MAIL = CFG.QUIET_MAIL

        if QUIET_MAIL < 0:
            QUIET_MAIL = 0
        if QUIET_MAIL == 0:  # make sure we don't mail
            mail = 0

    e_type = sys.exc_info()[:2][0]
    t = time.ctime(time.time())
    exc = StringIO()

    unicode_hostname = idn_pune_to_unicode(hostname)
    exc.write("Exception reported from %s\nTime: %s\n" %
              (to_string(unicode_hostname), t))
    exc.write("Exception type %s\n" % to_string(e_type))
    if method:
        exc.write("Exception while handling function %s\n" % to_string(method))

    # print information about the request being served
    if req:
        print_req(req, exc)
    if extra:
        exc.write("Extra information about this error:\n%s\n" %
                  to_string(extra))

    # Print the traceback
    exc.write("\nException Handler Information\n")
    traceback.print_exc(None, exc)

    if with_locals and not mail:
        # The mail case will call print_locals by itself
        print_locals(exc)

    # we always log it somewhere
    if ostream:
        ostream.write(to_string(exc.getvalue()))
        ostream.write("\n")

    if mail:
        # print the stack frames for the mail we send out
        print_locals(exc)
        # dump the environment
        print_env(exc)
        # and send the mail
        # build the headers
        to = CFG.TRACEBACK_MAIL
        fr = to
        if isinstance(to, type([])):
            fr = to[0].strip()
            to = ', '.join([x.strip() for x in to])
        headers = {
            "Subject":
            "%s TRACEBACK from %s" % (PRODUCT_NAME, unicode_hostname),
            "From": "%s <%s>" % (hostname, fr),
            "To": to,
            "X-RHN-Traceback-Severity": severity,
            "Content-Type": 'text/plain; charset="utf-8"',
        }
        QUIET_MAIL = QUIET_MAIL - 1  # count it no matter what

        outstring = to_string(exc.getvalue())

        # 5/18/05 wregglej - 151158 Go through every string in the security list
        # and censor it out of the debug information.
        outstring = censor_string(outstring)

        rhnMail.send(headers, outstring)

    exc.close()
    return
Пример #12
0
def convert_url_from_pune(url):
    """ returns url where hostname is converted from Pune encoding. Returns unicode string. """
    s = urlsplit(url)
    return unicode(urlunsplit((s[0], idn_pune_to_unicode(s[1]), s[2], s[3], s[4])))
Пример #13
0
def Traceback(method = None, req = None, mail = 1, ostream = sys.stderr,
              extra = None, severity="notification", with_locals=0):
    """ Reports an traceback error and optionally sends mail about it.
        NOTE: extra = extra text information.
    """
    # pylint: disable=C0103

    global QUIET_MAIL

    if mail:
        # safeguard
        if QUIET_MAIL is None:
            QUIET_MAIL = CFG.QUIET_MAIL

        if QUIET_MAIL < 0:
            QUIET_MAIL = 0
        if QUIET_MAIL == 0: # make sure we don't mail
            mail = 0

    e_type = sys.exc_info()[:2][0]
    t = time.ctime(time.time())
    exc = StringIO()

    unicode_hostname = idn_pune_to_unicode(hostname)
    exc.write("Exception reported from %s\nTime: %s\n" % (to_string(unicode_hostname), t))
    exc.write("Exception type %s\n" % to_string(e_type))
    if method:
        exc.write("Exception while handling function %s\n" % to_string(method))

    # print information about the request being served
    if req:
        print_req(req, exc)
    if extra:
        exc.write("Extra information about this error:\n%s\n" % to_string(extra))

    # Print the traceback
    exc.write("\nException Handler Information\n")
    traceback.print_exc(None, exc)

    if with_locals and not mail:
        # The mail case will call print_locals by itself
        print_locals(exc)

    # we always log it somewhere
    if ostream:
        ostream.write(to_string(exc.getvalue()))
        ostream.write("\n")

    if mail:
        # print the stack frames for the mail we send out
        print_locals(exc)
        # dump the environment
        print_env(exc)
        # and send the mail
        # build the headers
        to = CFG.TRACEBACK_MAIL
        fr = to
        if isinstance(to, type([])):
            fr = to[0].strip()
            to = ', '.join([x.strip() for x in to])
        headers = {
            "Subject" : "%s TRACEBACK from %s" % (PRODUCT_NAME, unicode_hostname),
            "From"    : "%s <%s>" % (hostname, fr),
            "To"      : to,
            "X-RHN-Traceback-Severity"  : severity,
            "Content-Type" : 'text/plain; charset="utf-8"',

            }
        QUIET_MAIL = QUIET_MAIL - 1     # count it no matter what

        outstring = to_string(exc.getvalue())

        #5/18/05 wregglej - 151158 Go through every string in the security list
        # and censor it out of the debug information.
        outstring = censor_string(outstring)

        rhnMail.send(headers, outstring)

    exc.close()
    return