summaryrefslogtreecommitdiffstats
path: root/examples/scripts/debugging/linux/backtrace
diff options
context:
space:
mode:
Diffstat (limited to 'examples/scripts/debugging/linux/backtrace')
0 files changed, 0 insertions, 0 deletions
'>85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
#
# vnc.py: VNC related installer functionality
#
# Copyright 2004,2007 Red Hat, Inc.
#
# Jeremy Katz <katzj@redhat.com>
#
# This software may be freely redistributed under the terms of the GNU
# general public license.
#
# 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., 675 Mass Ave, Cambridge, MA 02139, USA.
#

import os, sys, string
import time
from snack import *
from constants_text import *
from rhpl.translate import _, N_
import network
import isys
import product
import iutil
import socket

import logging
log = logging.getLogger("anaconda")

# return -1 to use text mode, None for no vncpass, or vncpass otherwise
def askVncWindow():
    if not os.access('/usr/bin/Xvnc', os.X_OK):
        return -1

    if not network.hasActiveNetDev():
        return -1

    screen = SnackScreen()
    vncpass = None
    vncconnect = 0

    STEP_MESSAGE = 0
    STEP_PASS = 1
    STEP_DONE = 3
    step = 0
    while step < STEP_DONE:
        if step == STEP_MESSAGE:
            button = ButtonChoiceWindow(screen, _("Unable to Start X"),
                                        _("X was unable to start on your "
                                          "machine.  Would you like to "
                                          "start VNC to connect to "
                                          "this computer from another "
                                          "computer and perform a "
                                          "graphical install or continue "
                                          "with a text mode install?"),
                                        buttons = [ _("Use text mode"),
                                                    _("Start VNC") ])

	    if button == string.lower (_("Use text mode")):
                screen.finish()
                return -1
            else:
                step = STEP_PASS
                continue

        if step == STEP_PASS:
            grid = GridFormHelp(screen, _("VNC Configuration"),
                                "vnc", 1, 10)

            bb = ButtonBar(screen, (TEXT_OK_BUTTON,
                                    (_("No password"), "nopass"),
                                    TEXT_BACK_BUTTON))

            text = _("A password will prevent unauthorized listeners "
                     "connecting and monitoring your installation progress.  "
                     "Please enter a password to be used for the installation")
            grid.add(TextboxReflowed(40, text), 0, 0, (0, 0, 0, 1))

            entry1 = Entry (16, password = 1)
            entry2 = Entry (16, password = 1)
            passgrid = Grid (2, 2)
            passgrid.setField (Label (_("Password:")), 0, 0, (0, 0, 1, 0), anchorLeft = 1)
            passgrid.setField (Label (_("Password (confirm):")), 0, 1, (0, 0, 1, 0), anchorLeft = 1)
            passgrid.setField (entry1, 1, 0)
            passgrid.setField (entry2, 1, 1)
            grid.add (passgrid, 0, 1, (0, 0, 0, 1))

            grid.add(bb, 0, 8, (0, 1, 1, 0), growx = 1)

            while 1:
                res = grid.run()
                rc = bb.buttonPressed(res)

                if rc == TEXT_BACK_CHECK:
                    screen.popWindow()
                    step = STEP_MESSAGE
                    break
                elif rc == "nopass":
                    screen.finish()
                    return None
                else:
                    pw = entry1.value()
                    cf = entry2.value()
                    if pw != cf:
                        ButtonChoiceWindow(screen, _("Password Mismatch"),
                                           _("The passwords you entered were "
                                             "different. Please try again."),
                                           buttons = [ TEXT_OK_BUTTON ],
                                           width = 50)
                    elif len(pw) < 6:
                        ButtonChoiceWindow(screen, _("Password Length"),
                                           _("The password must be at least "
                                             "six characters long."),
                                           buttons = [ TEXT_OK_BUTTON ],
                                           width = 50)
                    else:
                        screen.finish()
                        return pw

                    entry1.set("")
                    entry2.set("")
                    continue
                continue

    screen.finish()
    return -1

def getVNCPassword():
    # see if there is a vnc password file
    try:
        pfile = open("/tmp/vncpassword.dat", "r")
        vncpassword=pfile.readline().strip()
        pfile.close()
        os.unlink("/tmp/vncpassword.dat")
    except:
        vncpassword=""
        pass

    # check length of vnc password
    if vncpassword != "" and len(vncpassword) < 6:
        screen = SnackScreen()
        ButtonChoiceWindow(screen, _('VNC Password Error'),
                           _('You need to specify a vnc password of at least 6 characters long.\n\n'
    		     'Press <return> to reboot your system.\n'),
    		   buttons = (_("OK"),))
        screen.finish()
        sys.exit(0)

    return vncpassword

# startup vnc X server
def startVNCServer(vncpassword="", root='/', vncconnecthost="",
		   vncconnectport="", vncStartedCB=None):

    stdoutLog = logging.getLogger("anaconda.stdout")

    def set_vnc_password(root, passwd, passwd_file):
	(pid, fd) = os.forkpty()

	if not pid:
	    os.execv(root + "/usr/bin/vncpasswd", [root + "/usr/bin/vncpasswd", passwd_file])
	    sys.exit(1)

	# read password prompt
	os.read(fd, 1000)

	# write password
	os.write(fd, passwd + "\n")

	# read challenge again, and newline
	os.read(fd, 1000)
	os.read(fd, 1000)

	# write password again
	os.write(fd, passwd + "\n")

	# read remaining output
	os.read(fd, 1000)

	# wait for status
	try:
	    (pid, status) = os.waitpid(pid, 0)
	except OSError, (errno, msg):
	    print __name__, "waitpid:", msg

	return status

    stdoutLog.info(_("Starting VNC..."))

    # figure out host info
    connxinfo = None
    srvname = None
    ip = None

    # try to load /tmp/netinfo and see if we can sniff out network info
    netinfo = network.Network()

    # Look for the first configured interface and use its IP address for
    # the computer to connect to.
    dev = netinfo.getFirstDeviceName()

    try:
        ip = isys.getIPAddress(dev)
        log.info("ip of %s is %s" % (dev, ip))

        if ip == "127.0.0.1" or ip == "::1":
            ip = None
    except Exception, e:
        log.warning("Got an exception trying to get the ip addr "
                    "of %s: %s" % (dev, e))

    # If we have a real hostname that resolves against configured DNS
    # servers, use that for the name to connect to.
    if netinfo.hostname != "localhost.localdomain":
        if netinfo.lookupHostname() is not None:
            srvname = netinfo.hostname
        elif ip is None:
            # If we get here and there's no valid IP address, just use the
            # hostname and hope for the best (better than displaying nothing)
            srvname = netinfo.hostname

    if srvname is not None:
        connxinfo = "%s:1" % srvname

    if ip is not None:
        try:
            tmp = socket.inet_pton(socket.AF_INET6, ip)
            family = socket.AF_INET6
        except socket.error:
            family = socket.AF_INET

        if family == socket.AF_INET6:
            ipstr = "[%s]" % ip
        else:
            ipstr = ip

        if connxinfo is None:
            connxinfo = "%s:1" % ipstr
        else:
            connxinfo += " (%s)" % ipstr

    # figure out product info
    if srvname is not None:
	desktopname = _("%s %s installation on host %s") % (product.productName, product.productVersion, srvname)
    else:
	desktopname = _("%s %s installation") % (product.productName, product.productVersion)

    vncpid = os.fork()

    if not vncpid:
	args = [ root + "/usr/bin/Xvnc", ":1", "-nevershared",
		 "-depth", "16", "-geometry", "800x600", "-br",
		 "IdleTimeout=0", "-auth", "/dev/null", "-once",
		 "DisconnectClients=false", "desktop=%s" % (desktopname,)]

	# set passwd if necessary