diff --git a/modules/installed/first_boot.py b/modules/installed/first_boot.py index ff3a27e63..24c422246 100644 --- a/modules/installed/first_boot.py +++ b/modules/installed/first_boot.py @@ -7,6 +7,7 @@ from forms import Form import util as u from withsqlite.withsqlite import sqlite_db import cfg +import config class FirstBoot(PagePlugin): def __init__(self, *args, **kwargs): @@ -18,18 +19,13 @@ class FirstBoot(PagePlugin): return self.state0(*args, **kwargs) ## TODO: flesh out these tests values - def valid_box_name_p(self, name): - name = name.strip() - if re.search("\W", name): - return False - return True def valid_box_key_p(self, key): return True def generate_box_key(self): return "fake key" @cherrypy.expose - def state0(self, message="", box_name="", box_key="", submitted=False): + def state0(self, message="", hostname="", box_key="", submitted=False): """ In this state, we do time config over HTTP, name the box and server key selection. @@ -49,15 +45,13 @@ class FirstBoot(PagePlugin): ## Must resist the sick temptation to write an LDAP interface to the sqlite file with sqlite_db(cfg.store_file, table="thisbox", autocommit=True) as db: db['about'] = "This table is for information about this FreedomBox" - if box_name: - if self.valid_box_name_p(box_name): - db['box_name'] = box_name + if hostname: + if '' == config.valid_hostname(hostname): + config.set_hostname(hostname) else: - message += _("Invalid box name.") - elif 'box_name' in db and db['box_name']: - box_name = db['box_name'] - #TODO: set /etc/hostname to box name via ex machina - + message += _("Invalid box name: %s") % config.valid_hostname(hostname) + else: + hostname = config.get_hostname() if box_key: if self.valid_box_key_p(box_key): db['box_key'] = box_key @@ -70,7 +64,7 @@ class FirstBoot(PagePlugin): db['box_key'] = box_key - if box_name and box_key and self.valid_box_name_p(box_name) and self.valid_box_key_p(box_key): + if hostname and box_key and '' == config.valid_hostname(hostname) and self.valid_box_key_p(box_key): ## Update state to 1 and head there with sqlite_db(cfg.store_file, table="firstboot", autocommit=True) as db: db['state']=1 @@ -81,11 +75,9 @@ class FirstBoot(PagePlugin): action="/firstboot", name="whats_my_name", message=message) - if not box_name: - box_name = cfg.box_name form.html("

For convenience, your FreedomBox needs a name. It should be something short that doesn't contain spaces or punctuation. 'Willard' would be a good name. 'Freestyle McFreedomBox!!!' would not.

") - form.text_input('Name your FreedomBox', id="box_name", value=box_name) - form.html("

%(box_name)s uses cryptographic keys so it can prove its identity when talking to you. %(box_name)s can make a key for itself, but if one already exists (from a prior FreedomBox, for example), you can paste it below. This key should not be the same as your key because you are not your FreedomBox!

" % {'box_name':cfg.box_name}) + form.text_input('Name your FreedomBox', id="hostname", value=hostname) + form.html("

%(hostname)s uses cryptographic keys so it can prove its identity when talking to you. %(hostname)s can make a key for itself, but if one already exists (from a prior FreedomBox, for example), you can paste it below. This key should not be the same as your key because you are not your FreedomBox!

" % {'hostname':cfg.box_name}) form.text_box("If you want, paste your box's key here.", id="box_key", value=box_key) form.hidden(name="submitted", value="True") form.submit("Box it up!") diff --git a/modules/installed/system/config.py b/modules/installed/system/config.py index b671fcc12..e51c6d8c8 100644 --- a/modules/installed/system/config.py +++ b/modules/installed/system/config.py @@ -40,6 +40,9 @@ def valid_hostname(name): return message +def get_hostname(): + return gethostname() + def set_hostname(hostname): "Sets machine hostname to hostname" cfg.log.info("Writing '%s' to /etc/hostname with exmachina" % hostname) @@ -53,7 +56,7 @@ def set_hostname(hostname): if platform.linux_distribution()[0]=="Ubuntu" : cfg.exmachina.service.start("hostname") else: - cfg.exmachina.initd.restart("hostname.sh") # is hostname.sh debian-only? + cfg.exmachina.initd.start("hostname.sh") # is hostname.sh debian-only? except OSError, e: raise cherrypy.HTTPError(500, "Hostname restart failed: %s" % e)