Skip to content

Commit

Permalink
modified: SABnzbd.py
Browse files Browse the repository at this point in the history
	modified:   sabnzbd/assembler.py
	modified:   sabnzbd/cfg.py
  • Loading branch information
SanderJ committed Apr 4, 2014
1 parent 80fccd9 commit 99d4565
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
12 changes: 12 additions & 0 deletions SABnzbd.py
Expand Up @@ -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()

Expand Down
38 changes: 38 additions & 0 deletions sabnzbd/assembler.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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


5 changes: 4 additions & 1 deletion sabnzbd/cfg.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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())
https_chain.set_root(admin_dir.get_path())

0 comments on commit 99d4565

Please sign in to comment.