def submitted_confirm_formatting(self, ctx, form, data): debug_install = True print 'submitted_confirm_formatting' # Fire up the formatter # XXX: we should track previous instance and kill it if necessary for i in [ constants.INSTALL_STATUS_FILE, constants.INSTALL_STDOUT, constants.INSTALL_STDERR ]: if os.path.exists(i): os.unlink(i) # arguments target = livecddb.get_livecd_database_root().getS(ns_ui.targetDevice, rdf.String) cmd = constants.CMD_L2TPGW_INSTALL args = [ constants.CMD_L2TPGW_INSTALL, 'fatformat', # command target, # target device 'vpnease-%s' % passwordgen.generate_password(length=8), # hostname constants.ADMIN_USER_NAME, # admin user passwordgen.generate_password(length=8), # admin password '0' ] # large install ('1' or '0') # env env = None if debug_install: env = dict(os.environ) env['CODEBAY_LOGGER_DEBUG'] = '1' env['CODEBAY_LOGGER_STDOUT'] = '1' print 'spawning installer (format), cmd=%s, args=%s, env=%s' % (cmd, args, env) # XXX: we should track the process more carefully p = reactor.spawnProcess(InstallerProcessProtocol(), executable=cmd, args=args, env=env, usePTY=1) request = inevow.IRequest(ctx) request.redirect(request.URLPath().sibling('formatprogress.html')) request.finish() return ''
def submitted_confirm_installation(self, ctx, form, data): debug_install = True root = livecddb.get_livecd_database_root() print 'submitted_confirm_installation' # If a previous install has failed, we cannot allow install to begin. # This is because current installer may corrupt host filesystem state # in case install fails (see codebay.l2tpserver.installer.install). if root.hasS(ns_ui.installHasBeenStarted): print 'earlier install run, refusing to install' # XXX: separate page? request = inevow.IRequest(ctx) request.redirect(request.URLPath().sibling('installfailed.html')) request.finish() return '' # If recovery attempted, write recovery rdf/xml to a temp file recovery_rdfxml = '/tmp/recovery-data.xml' if os.path.exists(recovery_rdfxml): os.unlink(recovery_rdfxml) if root.hasS(ns_ui.previousConfigurationRdfXml): f = None try: f = open(recovery_rdfxml, 'wb') f.write( root.getS(ns_ui.previousConfigurationRdfXml, rdf.String).decode('hex')) finally: if f is not None: f.close() f = None else: recovery_rdfxml = None # Large install large_install_param = '0' if root.hasS(ns_ui.installLargeDisk) and root.getS( ns_ui.installLargeDisk, rdf.Boolean): large_install_param = '1' # Fire up the installer # # The underlying assumption here is that prechecks are strong enough to # prevent install failures from occurring - install failures are not recoverable. # # NB: Because we're running a shell command, we need strict control of what # goes into these fields. They are not likely to be exploits as such, but # can cause interesting failures. # # As such, it would be better to run the installer through Twisted; we could # process the stdout inside the UI code and so on. However, this is enough # for now: the Twisted change can be done later if it adds any value to this. # # XXX: passwordgen is not ideal for hostname 'uid' generation, but works. # XXX: we should track previous instance and kill it if necessary for i in [ constants.INSTALL_STATUS_FILE, constants.INSTALL_STDOUT, constants.INSTALL_STDERR ]: if os.path.exists(i): os.unlink(i) # arguments target = root.getS(ns_ui.targetDevice, rdf.String) cmd = constants.CMD_L2TPGW_INSTALL args = [ constants.CMD_L2TPGW_INSTALL, 'install', # command target, # target device 'vpnease-%s' % passwordgen.generate_password(length=8), # hostname constants.ADMIN_USER_NAME, # admin user passwordgen.generate_password(length=8), # admin password large_install_param ] # large install ('1' or '0') if recovery_rdfxml is not None: args.append(recovery_rdfxml) # env env = None if debug_install: env = dict(os.environ) env['CODEBAY_LOGGER_DEBUG'] = '1' env['CODEBAY_LOGGER_STDOUT'] = '1' print 'spawning installer, cmd=%s, args=%s, env=%s' % (cmd, args, env) # XXX: we should track the process more carefully p = reactor.spawnProcess(InstallerProcessProtocol(), executable=cmd, args=args, env=env, usePTY=1) # set 'sticky' marker: second install start will be refused root.setS(ns_ui.installHasBeenStarted, rdf.Boolean, True) request = inevow.IRequest(ctx) request.redirect(request.URLPath().sibling('installcopying.html')) request.finish() return ''
def submitted_confirm_installation(self, ctx, form, data): debug_install = True root = livecddb.get_livecd_database_root() print 'submitted_confirm_installation' # If a previous install has failed, we cannot allow install to begin. # This is because current installer may corrupt host filesystem state # in case install fails (see codebay.l2tpserver.installer.install). if root.hasS(ns_ui.installHasBeenStarted): print 'earlier install run, refusing to install' # XXX: separate page? request = inevow.IRequest(ctx) request.redirect(request.URLPath().sibling('installfailed.html')) request.finish() return '' # If recovery attempted, write recovery rdf/xml to a temp file recovery_rdfxml = '/tmp/recovery-data.xml' if os.path.exists(recovery_rdfxml): os.unlink(recovery_rdfxml) if root.hasS(ns_ui.previousConfigurationRdfXml): f = None try: f = open(recovery_rdfxml, 'wb') f.write(root.getS(ns_ui.previousConfigurationRdfXml, rdf.String).decode('hex')) finally: if f is not None: f.close() f = None else: recovery_rdfxml = None # Large install large_install_param = '0' if root.hasS(ns_ui.installLargeDisk) and root.getS(ns_ui.installLargeDisk, rdf.Boolean): large_install_param = '1' # Fire up the installer # # The underlying assumption here is that prechecks are strong enough to # prevent install failures from occurring - install failures are not recoverable. # # NB: Because we're running a shell command, we need strict control of what # goes into these fields. They are not likely to be exploits as such, but # can cause interesting failures. # # As such, it would be better to run the installer through Twisted; we could # process the stdout inside the UI code and so on. However, this is enough # for now: the Twisted change can be done later if it adds any value to this. # # XXX: passwordgen is not ideal for hostname 'uid' generation, but works. # XXX: we should track previous instance and kill it if necessary for i in [ constants.INSTALL_STATUS_FILE, constants.INSTALL_STDOUT, constants.INSTALL_STDERR ]: if os.path.exists(i): os.unlink(i) # arguments target = root.getS(ns_ui.targetDevice, rdf.String) cmd = constants.CMD_L2TPGW_INSTALL args = [ constants.CMD_L2TPGW_INSTALL, 'install', # command target, # target device 'vpnease-%s' % passwordgen.generate_password(length=8), # hostname constants.ADMIN_USER_NAME, # admin user passwordgen.generate_password(length=8), # admin password large_install_param ] # large install ('1' or '0') if recovery_rdfxml is not None: args.append(recovery_rdfxml) # env env = None if debug_install: env = dict(os.environ) env['CODEBAY_LOGGER_DEBUG'] = '1' env['CODEBAY_LOGGER_STDOUT'] = '1' print 'spawning installer, cmd=%s, args=%s, env=%s' % (cmd, args, env) # XXX: we should track the process more carefully p = reactor.spawnProcess(InstallerProcessProtocol(), executable=cmd, args=args, env=env, usePTY=1) # set 'sticky' marker: second install start will be refused root.setS(ns_ui.installHasBeenStarted, rdf.Boolean, True) request = inevow.IRequest(ctx) request.redirect(request.URLPath().sibling('installcopying.html')) request.finish() return ''