From fda6ee31d3b5bca83c2b0a105a89943a5a16e95c Mon Sep 17 00:00:00 2001 From: Dirk Rettschlag Date: Wed, 1 Mar 2017 20:45:09 +0100 Subject: [PATCH 1/4] Add Basic Auth for SABnzbd I am running SABnzb behind a reverse proxy with basic auth enabled. This will make nzb-monkey work with this setup. --- src/nzbmonkey.py | 12 ++++++++++-- src/nzbmonkeyspec.py | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/nzbmonkey.py b/src/nzbmonkey.py index f0d62f2..4a21bb8 100644 --- a/src/nzbmonkey.py +++ b/src/nzbmonkey.py @@ -1055,7 +1055,7 @@ def sec_to_time(seconds, days_only=False, ): # region NZB Targets -def push_nzb_sabnzbd(host, port, ssl, api_key, category, paused, sabnzbd_name, nzb_content, +def push_nzb_sabnzbd(host, port, ssl, api_key, basicauth_username, basicauth_password, category, paused, sabnzbd_name, nzb_content, start_message='Pushing to SABNZBD', debug=False): """Push a NZB to SABnzbd @@ -1063,6 +1063,8 @@ def push_nzb_sabnzbd(host, port, ssl, api_key, category, paused, sabnzbd_name, n :param str port: SABnzbd Port :param bool ssl: Use https :param str api_key: NZB Api Key + :param str basicauth_username: Username for Basic Auth + :param str basicauth_password: Password for Basic Auth :param str category: SABnzbd Category :param str paused: Add the nzb paused :param str sabnzbd_name: Name of the SABnzbd job. To send also the RAR password add {{password}} to the job name @@ -1091,7 +1093,11 @@ def push_nzb_sabnzbd(host, port, ssl, api_key, category, paused, sabnzbd_name, n nzb_data = {'nzbfile': (nzbname, io.BytesIO(nzb_content.encode('utf8')))} try: - res = requests.post(req_url, data=post_data, files=nzb_data, verify=False, timeout=REQUESTS_TIMEOUT) + if (basicauth_username and basicauth_password): + auth = requests.auth.HTTPBasicAuth(basicauth_username, basicauth_password) + res = requests.post(req_url, data=post_data, files=nzb_data, verify=False, timeout=REQUESTS_TIMEOUT, auth=auth) + else: + res = requests.post(req_url, data=post_data, files=nzb_data, verify=False, timeout=REQUESTS_TIMEOUT) except requests.exceptions.RequestException as e: print(Col.FAIL + 'FAILED: {}'.format(e) + Col.OFF) return 1 @@ -1468,6 +1474,8 @@ def main(): exe_target_cfg.get('port', '8080'), exe_target_cfg.as_bool('ssl'), exe_target_cfg.get('nzbkey', ''), + exe_target_cfg.get('basicauth_username', ''), + exe_target_cfg.get('basicauth_password', ''), category_args if category_args else exe_target_cfg.get('category', ''), exe_target_cfg.as_bool('addpaused'), nzbsrc['tag'] if nzbsrc['pass'] is None else '%s{{%s}}' % ( diff --git a/src/nzbmonkeyspec.py b/src/nzbmonkeyspec.py index 8a55422..fbbde1f 100644 --- a/src/nzbmonkeyspec.py +++ b/src/nzbmonkeyspec.py @@ -36,6 +36,10 @@ def getSpec(): ssl = boolean(default = False) # NZB Key nzbkey = string(default = '') +# Basic Auth Username +basicauth_username = string(default = '') +# Basic Auth Password +basicauth_password = string(default = '') # Category category = string(default = '') # Add the nzb paused to the queue From de4e3676a9315fbace338a323bb80b3f1e48ee3f Mon Sep 17 00:00:00 2001 From: nzblnk Date: Mon, 1 May 2017 00:44:22 +0200 Subject: [PATCH 2/4] Fixes a problem with SABNzbd. --- src/nzbmonkey.py | 2 ++ src/version.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/nzbmonkey.py b/src/nzbmonkey.py index 66ac68f..b791f11 100644 --- a/src/nzbmonkey.py +++ b/src/nzbmonkey.py @@ -1479,6 +1479,8 @@ def main(): exe_target_cfg.as_bool('ssl'), exe_target_cfg.get('nzbkey', ''), exe_target_cfg.get('basepath', 'sabnzbd'), + exe_target_cfg.get('basicauth_username', ''), + exe_target_cfg.get('basicauth_password', ''), category_args if category_args else exe_target_cfg.get('category', ''), exe_target_cfg.as_bool('addpaused'), nzbsrc['tag'] if nzbsrc['pass'] is None else '%s{{%s}}' % ( diff --git a/src/version.py b/src/version.py index 348d0ab..8d55c97 100644 --- a/src/version.py +++ b/src/version.py @@ -2,6 +2,9 @@ """ History +v0.1.12 ++ Bugfix SABNzbd + v0.1.11 + Basepath added (thx ralle12345) + Sanitized searchstring (thx plintogo) From decef5aac5225dcee7801fdf27b45bfa1c5db818 Mon Sep 17 00:00:00 2001 From: nzblnk Date: Mon, 1 May 2017 00:45:10 +0200 Subject: [PATCH 3/4] Versionbump --- src/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.py b/src/version.py index 8d55c97..199f305 100644 --- a/src/version.py +++ b/src/version.py @@ -54,5 +54,5 @@ """ -__version__ = '0.1.11' +__version__ = '0.1.12' __requires__ = ['pyperclip', 'requests', 'configobj', 'colorama', 'cryptography'] From de0920922fb7a4ed4143ddf9d3669675d06f5371 Mon Sep 17 00:00:00 2001 From: nzblnk Date: Sat, 20 May 2017 17:10:44 +0200 Subject: [PATCH 4/4] Timeout increased --- src/nzbmonkey.py | 14 +++++++------- src/version.py | 7 +++++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/nzbmonkey.py b/src/nzbmonkey.py index b791f11..3271570 100644 --- a/src/nzbmonkey.py +++ b/src/nzbmonkey.py @@ -5,22 +5,22 @@ NZB-Monkey """ +import argparse import base64 +import io +import operator import os import re -import io import sys import webbrowser -import argparse -import operator import xml.etree.ElementTree as ET from enum import Enum -from os.path import basename, splitext, isfile, join, expandvars -from time import sleep, time, localtime, strftime -from urllib.parse import urlparse, parse_qs, quote from glob import glob +from os.path import basename, splitext, isfile, join, expandvars from pathlib import Path +from time import sleep, time, localtime, strftime from unicodedata import normalize +from urllib.parse import urlparse, parse_qs, quote from nzblnkconfig import check_missing_modules @@ -1099,7 +1099,7 @@ def push_nzb_sabnzbd(host, port, ssl, api_key, basepath, basicauth_username, bas if basicauth_username and basicauth_password: auth = (basicauth_username, basicauth_password) - res = requests.post(req_url, data=post_data, files=nzb_data, verify=False, timeout=REQUESTS_TIMEOUT, auth=auth) + res = requests.post(req_url, data=post_data, files=nzb_data, verify=False, timeout=REQUESTS_TIMEOUT * 2, auth=auth) except requests.exceptions.RequestException as e: print(Col.FAIL + 'FAILED: {}'.format(e) + Col.OFF) return 1 diff --git a/src/version.py b/src/version.py index 199f305..e32ad55 100644 --- a/src/version.py +++ b/src/version.py @@ -2,13 +2,16 @@ """ History +v0.1.13 ++ Timeout doubled für SABNzbd + v0.1.12 + Bugfix SABNzbd v0.1.11 + Basepath added (thx ralle12345) + Sanitized searchstring (thx plintogo) -+ Basic auth for SABNzbD (thx MarcLandis) ++ Basic auth for SABNzbd (thx MarcLandis) v0.1.10 + requests 2.13.0 (incl openssl) @@ -54,5 +57,5 @@ """ -__version__ = '0.1.12' +__version__ = '0.1.13' __requires__ = ['pyperclip', 'requests', 'configobj', 'colorama', 'cryptography']