Beispiel #1
0
    def _doAuthPostIP160s(self, urlpath, postvars):
        '''Send a POST request to the IP160s phone, in the special way required.

        The IP160s firmware has a shoddy implementation for processing of POST
        requests. When processing a POST request, the firmware expects each of
        the form variables to appear in a specific position in the encoding
        string sent by the browser, rather than relying on the key/value
        structure that is implied by the encoding protocol. This firmware happens
        to work with ordinary web browsers because they, by lucky chance, send
        the variables in form order. However, if urllib is used to encode an
        ordinary dictionary of variables, there is no ordering guarantee (in
        Python 2.4) and the variables get sent out of order. The firwmare will
        then set the variables according to the received position, which results
        in a broken setup.

        An OrderedDict would be ideal for this, but for now I will manually build
        an array of 2-tuples and use that to encode the POST data.
        '''
        postdata = []
        for tuple in postvars:
            postdata.append(urllib.quote_plus(tuple[0]) + '=' + urllib.quote_plus(str(tuple[1])))
        return self._doAuthPost(urlpath, '&'.join(postdata))
Beispiel #2
0
    def _setProvisioningServer_SIPT2x(self):
        separator = 'þ'
        provvars = ('1', 'tftp://' + self._serverip, '', '********', '',
                    '********', '1', '', '00:00', '00:00', '', '********', '1',
                    '1', '5', '3', '', '1')

        # The Yealink firmware is very picky about the order of the POST
        # variables. The PAGEID variable must appear *before* CONFIG_DATA.
        # Therefore, urllib.urlencode() cannot be used as-is, because it
        # places variables in alphabetical sort.
        postvars = 'PAGEID=16&CONFIG_DATA=' + urllib.quote_plus(
            separator + separator.join(provvars))

        try:
            if not self._doAuthPost('/cgi-bin/ConfigManApp.com', postvars):
                return False
        except httplib.BadStatusLine, e:
            # Apparently a successful POST will start provisioning immediately
            logging.error(
                'Endpoint %s@%s failed to set provisioning server - %s' %
                (self._vendorname, self._ip, str(e)))
            return False
Beispiel #3
0
 def fetch(self, keyword):
     fd = pool.spawn(self._fetch_query, "%s?q=%s" %
                     (self._url, urllib.quote_plus(keyword)))
     data = fd.wait()
     self._save(data)