exit 1
fi
-if [[ ! "$HOSTNAME" =~ ^[a-zA-Z0-9-]{1,63}$ ]]; then
+if [[ ! "$HOSTNAME" =~ ^[a-zA-Z][a-zA-Z0-9-]{0,62}$ ]]; then
echo "Invalid hostname '$HOSTNAME'"
exit 1
fi
h3(slot="header") Hostname Set
div(slot="body")
p Hostname was successfuly set to <strong>{{hostname}}</strong>.
- p Rebooting. Please wait...
- p Redirecting in {{redirectTimeout}} seconds.
+ p Rebooting to apply changes.
+ p Redirecting to new hostname in {{redirectTimeout}} seconds.
div(slot="footer")
message(:show.sync="passwordSet")
import shutil
import tarfile
import subprocess
+import socket
import bbctrl
class HostnameHandler(bbctrl.APIHandler):
- def get(self):
- p = subprocess.Popen(['hostname'], stdout = subprocess.PIPE)
- hostname = p.communicate()[0].decode('utf-8').strip()
- self.write_json(hostname)
-
+ def get(self): self.write_json(socket.gethostname())
def put(self):
if 'hostname' in self.json:
class ConfigDownloadHandler(bbctrl.APIHandler):
def set_default_headers(self):
- filename = datetime.date.today().strftime('bbctrl-%Y%m%d.json')
+ fmt = socket.gethostname() + '-%Y%m%d.json'
+ filename = datetime.date.today().strftime(fmt)
self.set_header('Content-Type', 'application/octet-stream')
self.set_header('Content-Disposition',
'attachment; filename="%s"' % filename)