def render_installation_model(self, ctx, data): root = livecddb.get_livecd_database_root() if root.hasS(ns_ui.installLargeDisk) and root.getS( ns_ui.installLargeDisk, rdf.Boolean): return 'Install with separate /boot and root partitions' else: return 'Install with single root partition'
def submitted_select_target(self, ctx, form, data): print 'submitted_select_target' # XXX: target selection error messages as constants? fda = formalutils.FormDataAccessor(form, [], ctx) target = None recovery = False large_install = False try: target = form.data['selecttarget.target'] print 'selected target: %s' % target medium = mediahelper.get_media().get_medium_by_device_name(target) if medium.get_size() < constants.DISK_SIZE_MINIMUM: fda.add_error('selecttarget.target', 'Minimum target medium size is 2 GB') if medium.is_write_protected(): fda.add_error('selecttarget.target', 'Target medium is write-protected') if form.data.has_key('selecttarget.recovery'): recovery = form.data['selecttarget.recovery'] if medium.get_size() >= constants.DISK_SIZE_MINIMUM_FOR_LARGE_INSTALL: large_install = True except: fda.add_error('selecttarget.target', 'Target medium cannot be selected') fda.finalize_validation() root = livecddb.get_livecd_database_root() root.setS(ns_ui.targetDevice, rdf.String, target) root.setS(ns_ui.attemptRecovery, rdf.Boolean, recovery) root.removeNodes(ns_ui.previousConfigurationRdfXml) root.removeNodes(ns_ui.previousInstalledVersion) # Recovery check here if recovery: print 'attempting recovery from %s' % target try: prev_cfg, prev_version = installhelpers.recover_existing_configuration(target) if prev_cfg is not None: root.setS(ns_ui.previousConfigurationRdfXml, rdf.String, prev_cfg.encode('hex')) if prev_version is not None: root.setS(ns_ui.previousInstalledVersion, rdf.String, prev_version) else: pass else: raise Exception('did not find recovery data') except: print 'recovery failed' # Select installation model based on target size root.setS(ns_ui.installLargeDisk, rdf.Boolean, large_install) print livecddb.dump_livecd_database() request = inevow.IRequest(ctx) request.redirect(request.URLPath().sibling('installconfirm.html')) return ''
def form_select_target(self, ctx): form = formal.Form() g = formalutils.CollapsibleGroup('selecttarget', label='Installation Targets') g.setCollapsed(False) targets = [] for m in self._get_disks(): errors = [] if m.get_size() < constants.DISK_SIZE_MINIMUM: errors.append('device too small') if m.is_write_protected(): errors.append('write-protected') if errors: errorstr = ' [' + (', '.join(errors)) + ']' else: errorstr = '' devname = m.get_device() devstring = '%s %s (%s) %s' % (m.get_size_pretty(), m.get_human_readable_description(), m.get_device(), errorstr) targets.append((devname, devstring)) def _target_cmp(x, y): x_dev, x_info = x y_dev, y_info = y return unicode.__cmp__(unicode(x_dev), unicode(y_dev)) targets.sort(cmp=_target_cmp) # XXX: we can't currently disable individual radiobuttons in Formal. # We thus leave them enabled, and check for device size below. This # is unfortunate, but better than not showing small devices at all lbl = 'Target device' g.add(formal.Field('target', formal.String(required=True), formal.widgetFactory(formal.RadioChoice, options=targets), label=lbl)) g.add(formal.Field('recovery', formal.Boolean(required=False), label='Attempt recovery')) sg = formalutils.SubmitFieldGroup('buttons') sg.add(formalutils.SubmitField('selecttarget', formal.String(), label='Next')) sg.add(formalutils.SubmitField('rescan', formal.String(), label='Rescan')) sg.add(formalutils.SubmitField('cancel', formal.String(), label='Cancel')) g.add(sg) form.add(g) form.addAction(self.submitted_select_target, name='selecttarget', label='Next', validate=False) form.addAction(self.submitted_rescan, name='rescan', label='Rescan', validate=False) form.addAction(self.submitted_cancel_installation, name='cancel', label='Cancel', validate=False) # set previous selection if exists as default value cfg = livecddb.get_livecd_database_root() if cfg.hasS(ns_ui.targetDevice): form.data['selecttarget.target'] = cfg.getS(ns_ui.targetDevice, rdf.String) if cfg.hasS(ns_ui.attemptRecovery): form.data['selecttarget.recovery'] = cfg.getS(ns_ui.attemptRecovery, rdf.Boolean) return form
def render_reset_state(self, ctx, data): # reset selected device for installer/formatter # don't nuke whole database, because we want to remember install failed -case root = livecddb.get_livecd_database_root() root.removeNodes(ns_ui.targetDevice) root.removeNodes(ns_ui.attemptRecovery) root.removeNodes(ns_ui.previousConfigurationRdfXml) root.removeNodes(ns_ui.previousInstalledVersion) root.removeNodes(ns_ui.installLargeDisk) return ''
def render_recovery(self, ctx, data): root = livecddb.get_livecd_database_root() if root.hasS(ns_ui.attemptRecovery) and root.getS(ns_ui.attemptRecovery, rdf.Boolean): if root.hasS(ns_ui.previousConfigurationRdfXml): ver_str = 'unknown' if root.hasS(ns_ui.previousInstalledVersion): ver_str = root.getS(ns_ui.previousInstalledVersion, rdf.String) return 'Previous installation found (version %s), attempting recovery of previous configuration' % ver_str else: return 'No previous installation found, cannot recover previous configuration' else: return 'Recovery of previous configuration not attempted (overwrite any existing data)'
def submitted_select_target(self, ctx, form, data): print 'submitted_select_target' fda = formalutils.FormDataAccessor(form, [], ctx) try: target = form.data['selecttarget.target'] print 'selected target: %s' % target medium = mediahelper.get_media().get_medium_by_device_name(target) if medium.is_write_protected(): fda.add_error('selecttarget.target', 'Target medium is write-protected') except: fda.add_error('selecttarget.target', 'Target medium cannot be selected') fda.finalize_validation() livecddb.get_livecd_database_root().setS(ns_ui.targetDevice, rdf.String, target) print livecddb.dump_livecd_database() request = inevow.IRequest(ctx) request.redirect(request.URLPath().sibling('formatconfirm.html')) return ''
def render_recovery(self, ctx, data): root = livecddb.get_livecd_database_root() if root.hasS(ns_ui.attemptRecovery) and root.getS( ns_ui.attemptRecovery, rdf.Boolean): if root.hasS(ns_ui.previousConfigurationRdfXml): ver_str = 'unknown' if root.hasS(ns_ui.previousInstalledVersion): ver_str = root.getS(ns_ui.previousInstalledVersion, rdf.String) return 'Previous installation found (version %s), attempting recovery of previous configuration' % ver_str else: return 'No previous installation found, cannot recover previous configuration' else: return 'Recovery of previous configuration not attempted (overwrite any existing data)'
def form_select_target(self, ctx): form = formal.Form() g = formalutils.CollapsibleGroup('selecttarget', label='Select Target Device') g.setCollapsed(False) targets = [] for m in self._get_disks(): errors = [] if m.is_write_protected(): errors.append('write-protected') if errors: errorstr = ' [' + (', '.join(errors)) + ']' else: errorstr = '' devname = m.get_device() devstring = '%s %s (%s) %s' % (m.get_size_pretty(), m.get_human_readable_description(), m.get_device(), errorstr) targets.append((devname, devstring)) def _target_cmp(x, y): x_dev, x_info = x y_dev, y_info = y return unicode.__cmp__(unicode(x_dev), unicode(y_dev)) targets.sort(cmp=_target_cmp) lbl = 'Target device' g.add(formal.Field('target', formal.String(required=True), formal.widgetFactory(formal.RadioChoice, options=targets), label=lbl)) sg = formalutils.SubmitFieldGroup('buttons') sg.add(formalutils.SubmitField('selecttarget', formal.String(), label='Next')) sg.add(formalutils.SubmitField('rescan', formal.String(), label='Rescan')) sg.add(formalutils.SubmitField('cancel', formal.String(), label='Cancel')) g.add(sg) form.add(g) form.addAction(self.submitted_select_target, name='selecttarget', label='Continue', validate=False) form.addAction(self.submitted_rescan, name='rescan', label='Rescan targets', validate=False) form.addAction(self.submitted_cancel_formatting, name='cancel', label='Cancel formatting', validate=False) # set previous selection if exists as default value cfg = livecddb.get_livecd_database_root() if cfg.hasS(ns_ui.targetDevice): form.data['selecttarget.target'] = cfg.getS(ns_ui.targetDevice, rdf.String) return form
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 render_targetmedium(self, ctx, data): return livecddb.get_livecd_database_root().getS(ns_ui.targetDevice, rdf.String)
def render_bustype(self, ctx, data): target = livecddb.get_livecd_database_root().getS(ns_ui.targetDevice, rdf.String) medium = mediahelper.get_media().get_medium_by_device_name(target) return medium.get_human_readable_bus_type()
def render_sizebytes(self, ctx, data): target = livecddb.get_livecd_database_root().getS(ns_ui.targetDevice, rdf.String) medium = mediahelper.get_media().get_medium_by_device_name(target) return medium.get_size()
def render_reset_state(self, ctx, data): # reset selected device for installer/formatter # don't nuke whole database, because we want to remember install failed -case root = livecddb.get_livecd_database_root() root.removeNodes(ns_ui.targetDevice) return ''
def render_installation_model(self, ctx, data): root = livecddb.get_livecd_database_root() if root.hasS(ns_ui.installLargeDisk) and root.getS(ns_ui.installLargeDisk, rdf.Boolean): return 'Install with separate /boot and root partitions' else: return 'Install with single root partition'
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 ''
def form_select_target(self, ctx): form = formal.Form() g = formalutils.CollapsibleGroup('selecttarget', label='Installation Targets') g.setCollapsed(False) targets = [] for m in self._get_disks(): errors = [] if m.get_size() < constants.DISK_SIZE_MINIMUM: errors.append('device too small') if m.is_write_protected(): errors.append('write-protected') if errors: errorstr = ' [' + (', '.join(errors)) + ']' else: errorstr = '' devname = m.get_device() devstring = '%s %s (%s) %s' % (m.get_size_pretty(), m.get_human_readable_description(), m.get_device(), errorstr) targets.append((devname, devstring)) def _target_cmp(x, y): x_dev, x_info = x y_dev, y_info = y return unicode.__cmp__(unicode(x_dev), unicode(y_dev)) targets.sort(cmp=_target_cmp) # XXX: we can't currently disable individual radiobuttons in Formal. # We thus leave them enabled, and check for device size below. This # is unfortunate, but better than not showing small devices at all lbl = 'Target device' g.add( formal.Field('target', formal.String(required=True), formal.widgetFactory(formal.RadioChoice, options=targets), label=lbl)) g.add( formal.Field('recovery', formal.Boolean(required=False), label='Attempt recovery')) sg = formalutils.SubmitFieldGroup('buttons') sg.add( formalutils.SubmitField('selecttarget', formal.String(), label='Next')) sg.add( formalutils.SubmitField('rescan', formal.String(), label='Rescan')) sg.add( formalutils.SubmitField('cancel', formal.String(), label='Cancel')) g.add(sg) form.add(g) form.addAction(self.submitted_select_target, name='selecttarget', label='Next', validate=False) form.addAction(self.submitted_rescan, name='rescan', label='Rescan', validate=False) form.addAction(self.submitted_cancel_installation, name='cancel', label='Cancel', validate=False) # set previous selection if exists as default value cfg = livecddb.get_livecd_database_root() if cfg.hasS(ns_ui.targetDevice): form.data['selecttarget.target'] = cfg.getS( ns_ui.targetDevice, rdf.String) if cfg.hasS(ns_ui.attemptRecovery): form.data['selecttarget.recovery'] = cfg.getS( ns_ui.attemptRecovery, rdf.Boolean) return form
def submitted_rescan(self, ctx, form, data): # clear previous selection if exists cfg = livecddb.get_livecd_database_root() if cfg.hasS(ns_ui.targetDevice): cfg.removeNodes(ns_ui.targetDevice)
def submitted_select_target(self, ctx, form, data): print 'submitted_select_target' # XXX: target selection error messages as constants? fda = formalutils.FormDataAccessor(form, [], ctx) target = None recovery = False large_install = False try: target = form.data['selecttarget.target'] print 'selected target: %s' % target medium = mediahelper.get_media().get_medium_by_device_name(target) if medium.get_size() < constants.DISK_SIZE_MINIMUM: fda.add_error('selecttarget.target', 'Minimum target medium size is 2 GB') if medium.is_write_protected(): fda.add_error('selecttarget.target', 'Target medium is write-protected') if form.data.has_key('selecttarget.recovery'): recovery = form.data['selecttarget.recovery'] if medium.get_size( ) >= constants.DISK_SIZE_MINIMUM_FOR_LARGE_INSTALL: large_install = True except: fda.add_error('selecttarget.target', 'Target medium cannot be selected') fda.finalize_validation() root = livecddb.get_livecd_database_root() root.setS(ns_ui.targetDevice, rdf.String, target) root.setS(ns_ui.attemptRecovery, rdf.Boolean, recovery) root.removeNodes(ns_ui.previousConfigurationRdfXml) root.removeNodes(ns_ui.previousInstalledVersion) # Recovery check here if recovery: print 'attempting recovery from %s' % target try: prev_cfg, prev_version = installhelpers.recover_existing_configuration( target) if prev_cfg is not None: root.setS(ns_ui.previousConfigurationRdfXml, rdf.String, prev_cfg.encode('hex')) if prev_version is not None: root.setS(ns_ui.previousInstalledVersion, rdf.String, prev_version) else: pass else: raise Exception('did not find recovery data') except: print 'recovery failed' # Select installation model based on target size root.setS(ns_ui.installLargeDisk, rdf.Boolean, large_install) print livecddb.dump_livecd_database() request = inevow.IRequest(ctx) request.redirect(request.URLPath().sibling('installconfirm.html')) return ''
def render_check_no_earlier_install_run(self, ctx, data): if livecddb.get_livecd_database_root().hasS( ns_ui.installHasBeenStarted): return '' return ctx
def render_targetmedium(self, ctx, data): return livecddb.get_livecd_database_root().getS( ns_ui.targetDevice, rdf.String)
def render_check_no_earlier_install_run(self, ctx, data): if livecddb.get_livecd_database_root().hasS(ns_ui.installHasBeenStarted): return '' return ctx