diff --git a/SABnzbd.py b/SABnzbd.py index 747d7476a12..daac4da7b24 100755 --- a/SABnzbd.py +++ b/SABnzbd.py @@ -1324,6 +1324,18 @@ def main(): sabnzbd.WEB_COLOR2 = CheckColor(sabnzbd.cfg.web_color2(), web_dir2) sabnzbd.cfg.web_color2.set(sabnzbd.WEB_COLOR2) + # unwanted_extensions: + # clean up the list, so for example convert .EXe to exe: + templist = [] + for extension in sabnzbd.cfg.unwanted_extensions(): + extension_cleanlower = extension.lower().split('.')[-1].encode('ascii', 'ignore') # and hard-encode to pure ascii + templist.append(extension_cleanlower) + # ... and put it back into the global variable: + sabnzbd.cfg.unwanted_extensions.set(templist) + logging.debug('Unwanted extensions are %s',templist) + + + if fork and not sabnzbd.WIN32: daemonize() diff --git a/sabnzbd/assembler.py b/sabnzbd/assembler.py index 49792b4aa20..2f259219337 100644 --- a/sabnzbd/assembler.py +++ b/sabnzbd/assembler.py @@ -121,6 +121,20 @@ def run(self): nzo.fail_msg = T('Aborted, encryption detected') import sabnzbd.nzbqueue sabnzbd.nzbqueue.NzbQueue.do.end_job(nzo) + + unwanted = rar_contains_unwanted_file(nzo, filepath) + if unwanted: + logging.warning(Ta('WARNING: In "%s" unwanted extension in RAR file. Unwanted file is %s '), latin1(nzo.final_name), unwanted) + if cfg.pause_on_unwanted_extensions() == 1: + logging.debug('Unwanted extension ... pausing') + nzo.pause() + if cfg.pause_on_unwanted_extensions() == 2: + logging.debug('Unwanted extension ... aborting') + nzo.fail_msg = T('Aborted, unwanted extension detected') + import sabnzbd.nzbqueue + sabnzbd.nzbqueue.NzbQueue.do.end_job(nzo) + + nzf.completed = True else: sabnzbd.nzbqueue.NzbQueue.do.remove(nzo.nzo_id, add_to_history=False, cleanup=False) @@ -322,3 +336,27 @@ def check_encrypted_rar(nzo, filepath): logging.debug('RAR file %s cannot be inspected', filepath) return encrypted + +def rar_contains_unwanted_file(nzo, filepath): + # checks for unwanted extensions in the rar file 'filepath' + # ... unwanted extensions are defined in global variable cfg.unwanted_extensions() + # returns False if no unwanted extensions are found in the rar file + # returns name of file if unwanted extension is found in the rar file + unwanted = False + if is_rarfile(filepath): + #logging.debug('rar file to check: %s',filepath) + #logging.debug('unwanted extensions are: %s', cfg.unwanted_extensions()) + try: + zf = RarFile(filepath, all_names=True) + #logging.debug('files in rar file: %s', zf.namelist()) + for somefile in zf.namelist() : + logging.debug('file in rar file: %s', somefile) + if somefile.lower().split('.')[-1] in cfg.unwanted_extensions(): # [u'exe', u'bla'] + logging.debug('Unwanted file %s',somefile) + unwanted = somefile + zf.close() + except: + logging.debug('RAR file %s cannot be inspected.', filepath) + return unwanted + + diff --git a/sabnzbd/cfg.py b/sabnzbd/cfg.py index 9ae0f23fe04..891cf36ca06 100644 --- a/sabnzbd/cfg.py +++ b/sabnzbd/cfg.py @@ -212,6 +212,9 @@ def validate_server(value): cleanup_list = OptionList('misc', 'cleanup_list') warned_old_queue = OptionBool('misc', 'warned_old_queue', False) +unwanted_extensions = OptionList('misc', 'unwanted_extensions') +pause_on_unwanted_extensions = OptionBool('misc', 'pause_on_unwanted_extensions', True) + log_web = OptionBool('logging', 'enable_cherrypy_logging', False) log_dir = OptionDir('misc', 'log_dir', 'logs', validation=validate_notempty) log_level = OptionNumber('logging', 'log_level', 1, -1, 2) @@ -287,4 +290,4 @@ def set_root_folders(home, lcldata): def set_root_folders2(): https_cert.set_root(admin_dir.get_path()) https_key.set_root(admin_dir.get_path()) - https_chain.set_root(admin_dir.get_path()) \ No newline at end of file + https_chain.set_root(admin_dir.get_path())