Permalink
Browse files

Add option to supply new device name when changing MAC address

  • Loading branch information...
ibot3 committed Oct 11, 2018
1 parent a258111 commit 0ab4f9e14f7915f24eef6a9c996f47353df5dce3
Showing with 15 additions and 4 deletions.
  1. +2 −1 sipa/blueprints/usersuite.py
  2. +6 −0 sipa/forms.py
  3. +2 −2 sipa/model/pycroft/api.py
  4. +5 −1 sipa/model/pycroft/user.py
@@ -281,10 +281,11 @@ def change_mac():
if form.validate_on_submit():
password = form.password.data
mac = form.mac.data
host_name = form.host_name.data

try:
with current_user.tmp_authentication(password):
current_user.mac = mac
current_user.change_mac_address(mac, host_name)
except PasswordInvalid:
flash(gettext("Passwort war inkorrekt!"), "error")
except MacAlreadyExists:
@@ -178,6 +178,12 @@ class ChangeMACForm(FlaskForm):
validators=[DataRequired("MAC-Adresse nicht angegeben!"),
MacAddress("MAC ist nicht in gültigem Format!"),
require_unicast_mac])
host_name = StringField(label=lazy_gettext("Neuer Gerätename (Optional)"),
validators=[Regexp(regex="^[a-zA-Z0-9 ]+", message=u"Gerätename ist ungültig"),
Optional()],
description="TL-WR841N, MacBook, FritzBox, PC, Laptop, o.Ä.")


class ActivateNetworkAccessForm(FlaskForm):
password = PasswordField(
label=lazy_gettext("Passwort"),
@@ -34,9 +34,9 @@ def change_cache_usage(self, user_id, use_cache):
return self.post('user/{}/change-cache-usage'.format(user_id),
data={'use_cache': use_cache})

def change_mac(self, user_id, password, interface_id, new_mac):
def change_mac(self, user_id, password, interface_id, new_mac, host_name):
return self.post('user/{}/change-mac/{}'.format(user_id, interface_id),
data={'password': password, 'mac': new_mac})
data={'password': password, 'mac': new_mac, 'host_name': host_name})

def activate_network_access(self, user_id, password, mac, birthdate, host_name):
return self.post('user/{}/activate-network-access'.format(user_id),
@@ -140,11 +140,15 @@ def activate_network_access(self, password, mac, birthdate, host_name):

@mac.setter
def mac(self, new_mac):
pass

def change_mac_address(self, new_mac, host_name):
# if this has been reached despite `tmp_readonly`, this is a bug.
assert len(self._interfaces) == 1

status, result = api.change_mac(self._id, self._tmp_password,
self._interfaces[0]['id'], new_mac)
self._interfaces[0]['id'], new_mac,
host_name)

if status == 401:
raise PasswordInvalid

0 comments on commit 0ab4f9e

Please sign in to comment.