Ejemplo n.º 1
0
 def synchronize(self, device, raw_config):
     device_name = 'SEP' + format_mac(device[u'mac'], separator='', uppercase=True).encode('ascii')
     sync_service = synchronize.get_sync_service()
     if sync_service is None or sync_service.TYPE != 'AsteriskAMI':
         return defer.fail(Exception('Incompatible sync service: %s' % sync_service))
     else:
         return threads.deferToThread(sync_service.sccp_reset, device_name)
Ejemplo n.º 2
0
    def _dev_specific_filename(self, dev):
        # Return the device specific filename (not pathname) of device
        fmted_mac = format_mac(dev[u'mac'], separator='')

        if dev.get('model', '').startswith('ATA'):
            fmted_mac = 'ATA%s.cnf' % fmted_mac.upper()

        return fmted_mac + '.xml'
Ejemplo n.º 3
0
    def _add_xx_vars(self, device, raw_config):
        raw_config[u'XX_mac_addr'] = format_mac(device[u'mac'], separator='', uppercase=True)

        cur_datetime = datetime.datetime.now()
        raw_config[u'XX_version_date'] = cur_datetime.strftime('%d%m%y%H%M')

        if u'dns_enabled' in raw_config:
            ip = raw_config[u'dns_ip']
            ip_str = '0x' + ''.join(['%x' % int(p) for p in ip.split('.')])
            raw_config[u'XX_dns_ip_hex'] = ip_str

        self._add_timezone_code(raw_config)
Ejemplo n.º 4
0
 def _dev_specific_filename(self, device):
     # Return the device specific filename (not pathname) of device
     fmted_mac = format_mac(device[u'mac'], separator='', uppercase=True)
     return 'SEP%s.cnf.xml' % fmted_mac
Ejemplo n.º 5
0
 def _dev_specific_filename(self, device):
     # Return the device specific filename (not pathname) of device
     fmted_mac = format_mac(device[u'mac'], separator='')
     return fmted_mac + '.cfg'
Ejemplo n.º 6
0
 def _dev_specific_filename(self, device):
     # Return the device specific filename (not pathname) of device
     fmted_mac = format_mac(device[u'mac'], separator='', uppercase=True)
     return 'SIP%s.cfg' % fmted_mac
Ejemplo n.º 7
0
 def _device_cert_or_key_filename(self, device, suffix):
     # Return the cert or key file filename for a device
     fmted_mac = format_mac(device[u'mac'], separator='', uppercase=True)
     return fmted_mac + suffix
Ejemplo n.º 8
0
 def _dev_specific_filename(self, device):
     fmted_mac = format_mac(device[u'mac'], separator='')
     return fmted_mac + '.cfg'
Ejemplo n.º 9
0
    def configure(self, device, raw_config):
        self._check_config(raw_config)
        self._check_device(device)
        self._check_lines_password(raw_config)
        self._add_timezone(raw_config)
        self._add_locale(raw_config)
        self._add_fkeys(raw_config)
        filename = self._dev_specific_filename(device)
        tpl = self._tpl_helper.get_dev_template('GXP2000', device)

        path = os.path.join(self._tftpboot_dir, filename)
        rawdata = self._tpl_helper.render(tpl, raw_config, self._ENCODING)

        # Convert to binary
        config = ''
        for line in rawdata.splitlines():
            cleanedLine = line.strip()
            if cleanedLine:  # is not empty
                items = [x.strip() for x in cleanedLine.split('=')]
                if len(items) == 2:  # Only interested in pairs (name=value)
                    config += items[0] + '=' + urllib.quote(items[1]) + '&'

        fmted_mac = format_mac(device[u'mac'], separator='', uppercase=False)
        short_mac = fmted_mac[2:6]
        config = config + 'gnkey=' + short_mac
        # Convert to ascii
        config = str(config)

        # Convert mac to binary
        b_mac = binascii.unhexlify(fmted_mac)

        # Make sure length is even bytewise
        if len(config) % 2 != 0:
            config += '\x00'

        # Make sure length is even wordwise
        if len(config) % 4 != 0:
            config += "\x00\x00"

        config_length = 8 + (len(config) / 2)

        b_length = struct.pack('>L', config_length)

        b_crlf = '\x0D\x0A\x0D\x0A'
        b_string = b_length
        b_string += b_mac
        b_string += b_crlf
        b_string += config

        # check sum ...
        csv = 0
        for i in range(0, len(b_string), 2):
            chunk = b_string[i:i + 2]
            x = struct.unpack('>H', chunk)[0]
            csv += x
        csv = 0x10000 - csv
        csv &= 0xFFFF
        b_checksum = struct.pack('>H', csv)

        b_config = b_length + b_checksum + b_mac + b_crlf + config

        # Write config file
        with open(path, 'w') as content_file:
            content_file.write(b_config)
Ejemplo n.º 10
0
 def _dev_specific_filenames(self, device):
     # Return a tuple (htm filename, xml filename)
     fmted_mac = format_mac(device[u'mac'], separator='', uppercase=True)
     return 'snom%s-%s.htm' % (device[u'model'], fmted_mac), fmted_mac + '.xml'
Ejemplo n.º 11
0
 def _device_cert_or_key_filename(self, device, suffix):
     # Return the cert or key file filename for a device
     fmted_mac = format_mac(device[u'mac'], separator='', uppercase=True)
     return fmted_mac + suffix
Ejemplo n.º 12
0
 def _dev_specific_filename(self, device):
     # Return the device specific filename (not pathname) of device
     fmted_mac = format_mac(device[u'mac'], separator='', uppercase=True)
     return '%s_%s.txt' % (self._FILENAME_PREFIX, fmted_mac)
Ejemplo n.º 13
0
 def _dev_specific_filename(self, device):
     return u'config.{}.xml'.format(format_mac(device[u'mac'],
                                               separator=''))
Ejemplo n.º 14
0
 def _dev_specific_filename(self, device):
     fmted_mac = format_mac(device[u'mac'], separator='')
     return fmted_mac + '.cfg'
Ejemplo n.º 15
0
 def _dev_specific_filenames(self, device):
     # Return a tuple (htm filename, xml filename)
     fmted_mac = format_mac(device[u"mac"], separator="", uppercase=True)
     return "snom%s-%s.htm" % (device[u"model"], fmted_mac), fmted_mac + ".xml"
Ejemplo n.º 16
0
 def _dev_specific_filename(self, device):
     # Return the device specific filename (not pathname) of device
     fmted_mac = format_mac(device[u'mac'], separator='', uppercase=False)
     return 'cfg' + fmted_mac + '.xml'
Ejemplo n.º 17
0
 def _format_mac(self, device):
      return format_mac(device[u'mac'], separator='', uppercase=False)
Ejemplo n.º 18
0
 def _dev_specific_filename(self, device):
     # Return the device specific filename (not pathname) of device
     fmted_mac = format_mac(device[u'mac'], separator='', uppercase=False)
     return 'cfg' + fmted_mac + '.xml'
Ejemplo n.º 19
0
 def _dev_specific_filename(self, device):
     # Return the device specific filename (not pathname) of device
     fmted_mac = format_mac(device[u'mac'], separator='_', uppercase=False)
     return 'ipst_config_%s.cfg' % fmted_mac
Ejemplo n.º 20
0
 def _dev_specific_filename(self, device):
     # Return the device specific filename (not pathname) of device
     fmted_mac = format_mac(device[u'mac'], separator='', uppercase=False)
     return 'sipconfig-%s.txt' % fmted_mac
Ejemplo n.º 21
0
 def _dev_specific_filename(self, device):
     # Return the device specific filename (not pathname) of device
     fmted_mac = format_mac(device[u"mac"], separator="", uppercase=True)
     return "SEP%s.cnf.xml" % fmted_mac
Ejemplo n.º 22
0
 def _format_mac(self, device):
      return format_mac(device[u'mac'], separator='', uppercase=False)
Ejemplo n.º 23
0
 def _dev_specific_filename(self, device):
     # Return the device specific filename (not pathname) of device
     fmted_mac = format_mac(device[u'mac'], separator='')
     return fmted_mac + '.cfg'
Ejemplo n.º 24
0
 def _dev_specific_filenames(self, device):
     # Return a tuple (htm filename, xml filename)
     fmted_mac = format_mac(device[u'mac'], separator='', uppercase=True)
     return 'snom%s-%s.htm' % (device[u'model'],
                               fmted_mac), fmted_mac + '.xml'