Permalink
Browse files

Allow change of mac address in pycroft backend

  • Loading branch information...
Georgeto committed Sep 1, 2018
1 parent 1a2419b commit 7be3c419889868bfed632a433c03b542863b06a3
@@ -18,7 +18,7 @@
from sipa.mail import send_usersuite_contact_mail
from sipa.utils import password_changeable
from sipa.model.exceptions import DBQueryEmpty, LDAPConnectionError, \
PasswordInvalid, UserNotFound
PasswordInvalid, UserNotFound, MacAlreadyExists
from sipa.model.misc import PaymentDetails

logger = logging.getLogger(__name__)
@@ -287,6 +287,8 @@ def change_mac():
current_user.mac = mac
except PasswordInvalid:
flash(gettext("Passwort war inkorrekt!"), "error")
except MacAlreadyExists:
flash(gettext("MAC-Adresse ist bereits in Verwendung!"), "error")
else:
logger.info('Successfully changed MAC address',
extra={'data': {'mac': mac},
@@ -19,6 +19,10 @@ class PasswordInvalid(InvalidCredentials):
pass


class MacAlreadyExists(Exception):
pass


class DBQueryEmpty(Exception):
pass

@@ -34,6 +34,10 @@ 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):
return self.post('user/{}/change-mac/{}'.format(user_id, interface_id),
data={'password': password, 'mac': new_mac})

def get(self, url, params=None):
request_function = partial(requests.get, params=params or {})
return self._do_api_call(request_function, url)
@@ -6,7 +6,7 @@
from sipa.model.fancy_property import active_prop, connection_dependent, \
unsupported_prop
from sipa.model.misc import PaymentDetails
from sipa.model.exceptions import UserNotFound, PasswordInvalid
from sipa.model.exceptions import UserNotFound, PasswordInvalid, MacAlreadyExists
from .api import PycroftApi

from flask_login import AnonymousUserMixin
@@ -115,9 +115,21 @@ def ips(self):
@active_prop
@connection_dependent
def mac(self):
return ", ".join(i['mac'] for i in self._interfaces)
return {'value': ", ".join(i['mac'] for i in self._interfaces),
'tmp_readonly': len(self._interfaces) != 1}

# TODO: Implement changing of MAC
@mac.setter
def mac(self, new_mac):
# 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)

if status == 401:
raise PasswordInvalid
elif status == 400:
raise MacAlreadyExists

@active_prop
def mail(self):
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2018-06-17 02:20+0200\n"
"POT-Creation-Date: 2018-09-01 13:48+0200\n"
"PO-Revision-Date: 2014-08-01 19:22+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: de\n"
@@ -16,7 +16,7 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.5.3\n"
"Generated-By: Babel 2.6.0\n"

msgid "Kleinbuchstaben (a-z)"
msgstr ""
@@ -296,6 +296,9 @@ msgstr ""
msgid "E-Mail-Adresse wurde zurückgesetzt"
msgstr ""

msgid "MAC-Adresse ist bereits in Verwendung!"
msgstr ""

msgid "MAC-Adresse wurde geändert!"
msgstr ""

@@ -7,16 +7,16 @@ msgid ""
msgstr ""
"Project-Id-Version: Sipa\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2018-06-17 02:20+0200\n"
"PO-Revision-Date: 2018-06-17 02:21+0200\n"
"POT-Creation-Date: 2018-09-01 13:48+0200\n"
"PO-Revision-Date: 2018-09-01 13:48+0200\n"
"Last-Translator: Lukas Juhrich <lukasjuhrich@wh2.tu-dresden.de>\n"
"Language: en\n"
"Language-Team: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.5.3\n"
"Generated-By: Babel 2.6.0\n"
"X-Source-Language: de\n"
"X-Generator: Poedit 2.0.6\n"

@@ -303,6 +303,9 @@ msgstr "Email address has been changed"
msgid "E-Mail-Adresse wurde zurückgesetzt"
msgstr "Email address has been reset"

msgid "MAC-Adresse ist bereits in Verwendung!"
msgstr "MAC address is already in use!"

msgid "MAC-Adresse wurde geändert!"
msgstr "MAC address has been changed"

0 comments on commit 7be3c41

Please sign in to comment.