Browse Source

Warning when we refuse connection to unlisted hostname

tags/2.3.3Beta1
Safihre 7 years ago
parent
commit
3fd9e85236
  1. 12
      po/main/SABnzbd.pot
  2. 32
      sabnzbd/interface.py

12
po/main/SABnzbd.pot

@ -12,7 +12,7 @@ msgstr ""
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=ASCII\n" "Content-Type: text/plain; charset=ASCII\n"
"Content-Transfer-Encoding: 7bit\n" "Content-Transfer-Encoding: 7bit\n"
"POT-Creation-Date: 2018-03-12 16:33+W. Europe Standard Time\n" "POT-Creation-Date: 2018-03-15 09:00+W. Europe Standard Time\n"
"Generated-By: pygettext.py 1.5\n" "Generated-By: pygettext.py 1.5\n"
@ -105,7 +105,7 @@ msgid "Error"
msgstr "" msgstr ""
#: SABnzbd.py # sabnzbd/interface.py # sabnzbd/interface.py #: SABnzbd.py # sabnzbd/interface.py # sabnzbd/interface.py
#: sabnzbd/osxmenu.py # sabnzbd/wizard.py #: sabnzbd/interface.py # sabnzbd/osxmenu.py
msgid "SABnzbd shutdown finished" msgid "SABnzbd shutdown finished"
msgstr "" msgstr ""
@ -584,6 +584,10 @@ msgid "Server address \"%s:%s\" is not valid."
msgstr "" msgstr ""
#: sabnzbd/interface.py #: sabnzbd/interface.py
msgid "Refused connection with hostname \"%s\" from:"
msgstr ""
#: sabnzbd/interface.py
msgid "User logged in to the web interface" msgid "User logged in to the web interface"
msgstr "" msgstr ""
@ -591,7 +595,7 @@ msgstr ""
msgid "User logged in" msgid "User logged in"
msgstr "" msgstr ""
#: sabnzbd/interface.py [Warning message] #: sabnzbd/interface.py
msgid "Missing Session key" msgid "Missing Session key"
msgstr "" msgstr ""
@ -599,7 +603,7 @@ msgstr ""
msgid "Error: Session Key Required" msgid "Error: Session Key Required"
msgstr "" msgstr ""
#: sabnzbd/interface.py [Warning message] # sabnzbd/interface.py #: sabnzbd/interface.py # sabnzbd/interface.py
msgid "Error: Session Key Incorrect" msgid "Error: Session Key Incorrect"
msgstr "" msgstr ""

32
sabnzbd/interface.py

@ -177,7 +177,7 @@ def check_hostname():
return True return True
# Ohoh, bad # Ohoh, bad
logging.debug('Refused connection from %s with hostname %s', cherrypy.request.remote.ip, host) log_warning_and_ip(T('Refused connection with hostname "%s" from:') % host)
return False return False
@ -315,10 +315,10 @@ def check_session(kwargs):
key = kwargs.get('apikey') key = kwargs.get('apikey')
msg = None msg = None
if not key: if not key:
logging.warning(T('Missing Session key')) log_warning_and_ip(T('Missing Session key'))
msg = T('Error: Session Key Required') msg = T('Error: Session Key Required')
elif key != cfg.api_key(): elif key != cfg.api_key():
logging.warning(T('Error: Session Key Incorrect')) log_warning_and_ip(T('Error: Session Key Incorrect'))
msg = T('Error: Session Key Incorrect') msg = T('Error: Session Key Incorrect')
return msg return msg
@ -327,15 +327,6 @@ def check_apikey(kwargs, nokey=False):
""" Check api key or nzbkey """ Check api key or nzbkey
Return None when OK, otherwise an error message Return None when OK, otherwise an error message
""" """
def log_warning(txt):
# Was it proxy forwarded?
xff = cherrypy.request.headers.get('X-Forwarded-For')
if xff:
txt = '%s %s (X-Forwarded-For: %s)>%s' % (txt, cherrypy.request.remote.ip, xff, cherrypy.request.headers.get('User-Agent', '??'))
else:
txt = '%s %s>%s' % (txt, cherrypy.request.remote.ip, cherrypy.request.headers.get('User-Agent', '??'))
logging.warning('%s', txt)
output = kwargs.get('output') output = kwargs.get('output')
mode = kwargs.get('mode', '') mode = kwargs.get('mode', '')
name = kwargs.get('name', '') name = kwargs.get('name', '')
@ -356,14 +347,14 @@ def check_apikey(kwargs, nokey=False):
key = kwargs.get('session') key = kwargs.get('session')
if not key: if not key:
if cfg.api_warnings(): if cfg.api_warnings():
log_warning(T('API Key missing, please enter the api key from Config->General into your 3rd party program:')) log_warning_and_ip(T('API Key missing, please enter the api key from Config->General into your 3rd party program:'))
return report(output, 'API Key Required') return report(output, 'API Key Required')
elif req_access == 1 and key == cfg.nzb_key(): elif req_access == 1 and key == cfg.nzb_key():
return None return None
elif key == cfg.api_key(): elif key == cfg.api_key():
return None return None
else: else:
log_warning(T('API Key incorrect, Use the api key from Config->General in your 3rd party program:')) log_warning_and_ip(T('API Key incorrect, Use the api key from Config->General in your 3rd party program:'))
return report(output, 'API Key Incorrect') return report(output, 'API Key Incorrect')
# No active APIKEY, check web credentials instead # No active APIKEY, check web credentials instead
@ -372,11 +363,22 @@ def check_apikey(kwargs, nokey=False):
pass pass
else: else:
if cfg.api_warnings(): if cfg.api_warnings():
log_warning(T('Authentication missing, please enter username/password from Config->General into your 3rd party program:')) log_warning_and_ip(T('Authentication missing, please enter username/password from Config->General into your 3rd party program:'))
return report(output, 'Missing authentication') return report(output, 'Missing authentication')
return None return None
def log_warning_and_ip(txt):
""" Include the IP and the Proxy-IP for warnings """
# Was it proxy forwarded?
xff = cherrypy.request.headers.get('X-Forwarded-For')
if xff:
txt = '%s %s (X-Forwarded-For: %s)>%s' % (txt, cherrypy.request.remote.ip, xff, cherrypy.request.headers.get('User-Agent', '??'))
else:
txt = '%s %s>%s' % (txt, cherrypy.request.remote.ip, cherrypy.request.headers.get('User-Agent', '??'))
logging.warning('%s', txt)
############################################################################## ##############################################################################
class MainPage(object): class MainPage(object):

Loading…
Cancel
Save