Index: modules/univention/admin/syntax.py =================================================================== --- modules/univention/admin/syntax.py (Revision 30181) +++ modules/univention/admin/syntax.py (Arbeitskopie) @@ -1081,14 +1081,37 @@ choices = ( ( 'ethernet', _( 'Ethernet' ) ), ( 'fddi', _( 'FDDI' ) ), ( 'token-ring', _( 'Token-Ring' ) ) ) class MAC_Address( simple ): - regex = re.compile( '^([0-9a-fA-F]{1,2}[:-]){5}[0-9a-fA-F]{1,2}$' ) - error_message = _( 'This is not a valid MAC address. It must have 6 two digit hexadecimal numbers separated by \"-\" or \":\"' ) + regexFormats = { + 'linuxFormat' : '^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$', # linux format + 'windowsFormat' :'^([0-9a-fA-F]{2}-){5}[0-9a-fA-F]{2}$', # windows format + 'rawFormat' : '^[0-9a-fA-F]{12}$', # raw format + 'ciscoFormat' : '^([0-9a-fA-F]{4}.){2}[0-9a-fA-F]{4}$', # cisco format + } + regexLinuxFormat = re.compile( regexFormats['linuxFormat'] ) + regexWindowsFormat = re.compile( regexFormats['windowsFormat'] ) + regexRawFormat = re.compile( regexFormats['rawFormat'] ) + regexCiscoFormat = re.compile( regexFormats['ciscoFormat'] ) + error_message = _( 'That is not a valid MAC address.' ) size = 'TwoThirds' @classmethod def parse( self, text ): - simple.parse( text ) - return text.replace( '-', ':' ).lower() + if self.regexLinuxFormat.match(text) is not None: + return text.lower() + elif self.regexWindowsFormat.match(text) is not None: + return text.replace('-', ':').lower() + elif self.regexRawFormat.match(text) is not None: + temp = [] + for i in range(0, len(text)-1, 2): + temp.append(text[i:i+2]) + return ':'.join(temp).lower() + elif self.regexCiscoFormat.match(text) is not None: + temp = [] + for i in range(0, len(text.translate(None, '.'))-1, 2): + temp.append(text.translate(None, '.')[i:i+2]) + return ':'.join(temp).lower() + else: + raise univention.admin.uexceptions.valueError( self.error_message ) class DHCP_HardwareAddress( complex ): subsyntaxes = ( ( _( 'Type' ), NetworkType ), ( _( 'Address' ), MAC_Address ) )