Beispiel #1
0
    def three(self, **kwargs):
        """ Accept webserver parms and show Indexer page """
        if kwargs:
            if 'access' in kwargs:
                cfg.cherryhost.set(kwargs['access'])
            cfg.enable_https.set(kwargs.get('enable_https', 0))
            cfg.autobrowser.set(kwargs.get('autobrowser', 0))
            cfg.username.set(kwargs.get('web_user', ''))
            cfg.password.set(kwargs.get('web_pass', ''))
            if not cfg.username() or not cfg.password():
                sabnzbd.interface.set_auth(cherrypy.config)
        config.save_config()

        # Create indexer page
        info = self.info.copy()
        info['num'] = '» %s' % T('Step Three')
        info['number'] = 3
        info['T'] = Ttemplate

        info['rating_enable'] = cfg.rating_enable()
        info['rating_api_key'] = cfg.rating_api_key()

        template = Template(file=os.path.join(self.__web_dir, 'three.html'),
                            searchList=[info],
                            compilerSettings=sabnzbd.interface.DIRECTIVES)
        return template.respond()
Beispiel #2
0
    def three(self, **kwargs):
        """ Accept webserver parms and show Indexer page """
        if kwargs:
            if 'access' in kwargs:
                cfg.cherryhost.set(kwargs['access'])
            cfg.enable_https.set(kwargs.get('enable_https',0))
            cfg.autobrowser.set(kwargs.get('autobrowser',0))
            cfg.username.set(kwargs.get('web_user', ''))
            cfg.password.set(kwargs.get('web_pass', ''))
            if not cfg.username() or not cfg.password():
                sabnzbd.interface.set_auth(cherrypy.config)
        config.save_config()
        
        # Create indexer page
        info = self.info.copy()
        info['num'] = '» %s' % T('Step Three')
        info['number'] = 3
        info['T'] = Ttemplate

        info['rating_enable'] = cfg.rating_enable()
        info['rating_api_key'] = cfg.rating_api_key()
        
        template = Template(file=os.path.join(self.__web_dir, 'three.html'),
                            searchList=[info], compilerSettings=sabnzbd.interface.DIRECTIVES)
        return template.respond()
Beispiel #3
0
    def _send_rating(self, indexer_id):
        logging.debug('Updating indexer rating (%s)', indexer_id)

        api_key = cfg.rating_api_key()
        rating_host = cfg.rating_host()
        rating_url = _RATING_URL
        if not api_key:
            return True

        requests = []
        _headers = {'User-agent': 'SABnzbd+/%s' % sabnzbd.version.__version__, 'Content-type': 'application/x-www-form-urlencoded'}
        rating = self._get_rating_by_indexer(indexer_id)  # Requesting info here ensures always have latest information even on retry
        if hasattr(rating, 'host') and rating.host:
            host_parsed = urlparse.urlparse(rating.host)
            rating_host = host_parsed.netloc
            # Is it an URL or just a HOST?
            if host_parsed.path and host_parsed.path != '/':
                rating_url = host_parsed.path + '?' + host_parsed.query if host_parsed.query else host_parsed.path
        if not rating_host:
            return True
        if rating.changed & Rating.CHANGED_USER_VIDEO:
            requests.append({'m': 'r', 'r': 'videoQuality', 'rn': rating.user_video})
        if rating.changed & Rating.CHANGED_USER_AUDIO:
            requests.append({'m': 'r', 'r': 'audioQuality', 'rn': rating.user_audio})
        if rating.changed & Rating.CHANGED_USER_VOTE:
            up_down = 'up' if rating.user_vote == Rating.VOTE_UP else 'down'
            requests.append({'m': 'v', 'v': up_down, 'r': 'overall'})
        if rating.changed & Rating.CHANGED_USER_FLAG:
            requests.append(self._flag_request(rating.user_flag.get('val'), rating.user_flag.get('detail'), 0))
        if rating.changed & Rating.CHANGED_AUTO_FLAG:
            requests.append(self._flag_request(rating.auto_flag.get('val'), rating.auto_flag.get('detail'), 1))

        try:
            conn = httplib.HTTPSConnection(rating_host)
            for request in filter(lambda r: r is not None, requests):
                if api_key:
                    request['apikey'] = api_key
                request['i'] = indexer_id
                conn.request('POST', rating_url, urllib.urlencode(request), headers=_headers)

                response = conn.getresponse()
                response.read()
                if response.status == httplib.UNAUTHORIZED:
                    _warn('Ratings server unauthorized user')
                    return False
                elif response.status != httplib.OK:
                    _warn('Ratings server failed to process request (%s, %s)' % (response.status, response.reason))
                    return False
            self.ratings[indexer_id].changed = self.ratings[indexer_id].changed & ~rating.changed
            _reset_warn()
            return True
        except:
            _warn('Problem accessing ratings server: %s' % rating_host)
            return False
Beispiel #4
0
    def _send_rating(self, indexer_id):
        logging.debug('Updating indexer rating (%s)', indexer_id)

        api_key = cfg.rating_api_key()
        rating_host = cfg.rating_host()
        if not api_key or not rating_host:
            return False

        requests = []
        _headers = {'User-agent' : 'SABnzbd+/%s' % sabnzbd.version.__version__, 'Content-type': 'application/x-www-form-urlencoded'}
        rating = self._get_rating_by_indexer(indexer_id) # Requesting info here ensures always have latest information even on retry
        if rating.changed & Rating.CHANGED_USER_VIDEO:
            requests.append({'m': 'r', 'r': 'videoQuality', 'rn': rating.user_video})
        if rating.changed & Rating.CHANGED_USER_AUDIO:
            requests.append({'m': 'r', 'r': 'audioQuality', 'rn': rating.user_audio})
        if rating.changed & Rating.CHANGED_USER_VOTE:
            up_down = 'up' if rating.user_vote == Rating.VOTE_UP else 'down'
            requests.append({'m': 'v', 'v': up_down, 'r': 'overall'})
        if rating.changed & Rating.CHANGED_USER_FLAG:
            requests.append(self._flag_request(rating.user_flag.get('val'), rating.user_flag.get('detail'), 0))
        if rating.changed & Rating.CHANGED_AUTO_FLAG:
            requests.append(self._flag_request(rating.auto_flag.get('val'), rating.auto_flag.get('detail'), 1))

        try:
            conn = httplib.HTTPSConnection(rating_host)
            for request in filter(lambda r: r is not None, requests):
                request['apikey'] = api_key
                request['i'] =  indexer_id
                conn.request('POST', RATING_URL, urllib.urlencode(request), headers = _headers)

                response = conn.getresponse()
                response.read()
                if response.status == httplib.UNAUTHORIZED:
                    _warn('Ratings server unauthorized user')
                    return False
                elif response.status != httplib.OK:
                    _warn('Ratings server failed to process request (%s, %s)' % (response.status, response.reason))
                    return False

            self.ratings[indexer_id].changed = self.ratings[indexer_id].changed & ~rating.changed
            _reset_warn()
            return True
        except:
            _warn('Problem accessing ratings server: %s' % rating_host)
            return False
Beispiel #5
0
    def _send_rating(self, indexer_id):
        logging.debug("Updating indexer rating (%s)", indexer_id)

        api_key = cfg.rating_api_key()
        rating_host = cfg.rating_host()
        rating_url = _RATING_URL

        requests = []
        _headers = {
            "User-agent": "SABnzbd/%s" % sabnzbd.__version__,
            "Content-type": "application/x-www-form-urlencoded",
        }
        rating = self._get_rating_by_indexer(
            indexer_id
        )  # Requesting info here ensures always have latest information even on retry
        if hasattr(rating, "host") and rating.host:
            host_parsed = urllib.parse.urlparse(rating.host)
            rating_host = host_parsed.netloc
            # Is it an URL or just a HOST?
            if host_parsed.path and host_parsed.path != "/":
                rating_url = host_parsed.path + "?" + host_parsed.query if host_parsed.query else host_parsed.path

        if not rating_host:
            _warn("%s: %s" % (T("Cannot send, missing required data"), T("Server address")))
            return True

        if not api_key:
            _warn(
                "%s [%s]: %s - %s"
                % (
                    T("Cannot send, missing required data"),
                    rating_host,
                    T("API Key"),
                    T("This key provides identity to indexer. Check your profile on the indexer's website."),
                )
            )
            return True

        if rating.changed & Rating.CHANGED_USER_VIDEO:
            requests.append({"m": "r", "r": "videoQuality", "rn": rating.user_video})
        if rating.changed & Rating.CHANGED_USER_AUDIO:
            requests.append({"m": "r", "r": "audioQuality", "rn": rating.user_audio})
        if rating.changed & Rating.CHANGED_USER_VOTE:
            up_down = "up" if rating.user_vote == Rating.VOTE_UP else "down"
            requests.append({"m": "v", "v": up_down, "r": "overall"})
        if rating.changed & Rating.CHANGED_USER_FLAG:
            requests.append(self._flag_request(rating.user_flag.get("val"), rating.user_flag.get("detail"), 0))
        if rating.changed & Rating.CHANGED_AUTO_FLAG:
            requests.append(self._flag_request(rating.auto_flag.get("val"), rating.auto_flag.get("detail"), 1))

        try:
            conn = http.client.HTTPSConnection(rating_host)
            for request in [r for r in requests if r is not None]:
                if api_key:
                    request["apikey"] = api_key
                request["i"] = indexer_id
                conn.request("POST", rating_url, urllib.parse.urlencode(request), headers=_headers)

                response = conn.getresponse()
                response.read()
                if response.status == http.client.UNAUTHORIZED:
                    _warn("Ratings server unauthorized user")
                    return False
                elif response.status != http.client.OK:
                    _warn("Ratings server failed to process request (%s, %s)" % (response.status, response.reason))
                    return False
            self.ratings[indexer_id].changed = self.ratings[indexer_id].changed & ~rating.changed
            _reset_warn()
            return True
        except:
            _warn("Problem accessing ratings server: %s" % rating_host)
            return False
Beispiel #6
0
    def _send_rating(self, indexer_id):
        logging.debug('Updating indexer rating (%s)', indexer_id)

        api_key = cfg.rating_api_key()
        rating_host = cfg.rating_host()
        rating_url = _RATING_URL

        requests = []
        _headers = {
            'User-agent': 'SABnzbd+/%s' % sabnzbd.version.__version__,
            'Content-type': 'application/x-www-form-urlencoded'
        }
        rating = self._get_rating_by_indexer(
            indexer_id
        )  # Requesting info here ensures always have latest information even on retry
        if hasattr(rating, 'host') and rating.host:
            host_parsed = urlparse.urlparse(rating.host)
            rating_host = host_parsed.netloc
            # Is it an URL or just a HOST?
            if host_parsed.path and host_parsed.path != '/':
                rating_url = host_parsed.path + '?' + host_parsed.query if host_parsed.query else host_parsed.path

        if not rating_host:
            _warn(
                '%s: %s' %
                (T('Cannot send, missing required data'), T('Server address')))
            return True

        if not api_key:
            _warn('%s [%s]: %s - %s' % (
                T('Cannot send, missing required data'), rating_host,
                T('API Key'),
                T('This key provides identity to indexer. Check your profile on the indexer\'s website.'
                  )))
            return True

        if rating.changed & Rating.CHANGED_USER_VIDEO:
            requests.append({
                'm': 'r',
                'r': 'videoQuality',
                'rn': rating.user_video
            })
        if rating.changed & Rating.CHANGED_USER_AUDIO:
            requests.append({
                'm': 'r',
                'r': 'audioQuality',
                'rn': rating.user_audio
            })
        if rating.changed & Rating.CHANGED_USER_VOTE:
            up_down = 'up' if rating.user_vote == Rating.VOTE_UP else 'down'
            requests.append({'m': 'v', 'v': up_down, 'r': 'overall'})
        if rating.changed & Rating.CHANGED_USER_FLAG:
            requests.append(
                self._flag_request(rating.user_flag.get('val'),
                                   rating.user_flag.get('detail'), 0))
        if rating.changed & Rating.CHANGED_AUTO_FLAG:
            requests.append(
                self._flag_request(rating.auto_flag.get('val'),
                                   rating.auto_flag.get('detail'), 1))

        try:
            conn = httplib.HTTPSConnection(rating_host)
            for request in filter(lambda r: r is not None, requests):
                if api_key:
                    request['apikey'] = api_key
                request['i'] = indexer_id
                conn.request('POST',
                             rating_url,
                             urllib.urlencode(request),
                             headers=_headers)

                response = conn.getresponse()
                response.read()
                if response.status == httplib.UNAUTHORIZED:
                    _warn('Ratings server unauthorized user')
                    return False
                elif response.status != httplib.OK:
                    _warn('Ratings server failed to process request (%s, %s)' %
                          (response.status, response.reason))
                    return False
            self.ratings[indexer_id].changed = self.ratings[
                indexer_id].changed & ~rating.changed
            _reset_warn()
            return True
        except:
            _warn('Problem accessing ratings server: %s' % rating_host)
            return False