add passwords for extraction. fix #211

This commit is contained in:
clinton-hall 2013-11-28 10:58:30 +10:30
parent 864a5a79be
commit 39f49cf757
3 changed files with 42 additions and 4 deletions

View file

@ -175,6 +175,16 @@ def migrate():
option, value = item
confignew.set(section, option, value)
section = "passwords"
original = []
try:
original = configold.items(section)
except:
pass
for item in original:
option, value = item
confignew.set(section, option, value)
section = "loggers"
original = []
try:
@ -246,6 +256,7 @@ def migrate():
os.unlink(backupname)
os.rename(configFilenameold, backupname)
if os.path.isfile(configFilenamenew):
# rename our newly edited autoProcessMedia.cfg.sample to autoProcessMedia.cfg
os.rename(configFilenamenew, configFilenameold)
return

View file

@ -149,6 +149,11 @@ delay = 120
#Set convert =1 if you want to convert any "foreign" characters to ASCII before passing to SB/CP etc. Default is disabled (0).
convert = 0
[passwords]
#Set a list of passwords to be used for extraction attempts. e.g
#password1 = password
#password2 = secret
# Logging configuration
[loggers]
keys = root

View file

@ -1,5 +1,6 @@
import os
import sys
import ConfigParser
sys.path.insert(0, os.path.join(os.path.dirname(sys.argv[0]),'autoProcess/'))
import logging
from subprocess import call, Popen, PIPE
@ -122,6 +123,27 @@ def extract(filePath, outputDestination):
if res >= 0: # for windows chp returns process id if successful or -1*Error code. Linux returns 0 for successful.
Logger.info("EXTRACTOR: Extraction was successful for %s to %s", filePath, outputDestination)
else:
Logger.info("EXTRACTOR: Attempting to extract with passwords")
pass_success = int(0)
passwords = ConfigParser.ConfigParser()
passwordsfile = os.path.join(os.path.dirname(sys.argv[0]), 'autoProcessMedia.cfg')
passwords.read(passwordsfile)
passwordslist = passwords.items('passwords')
for item in passwordslist:
option, password = item
cmd2 = cmd
#append password here.
passcmd = "-p" + password
cmd2.append(passcmd)
p = Popen(cmd2) # should extract files fine.
res = p.wait()
if res >= 0: # for windows chp returns process id if successful or -1*Error code. Linux returns 0 for successful.
Logger.info("EXTRACTOR: Extraction was successful for %s to %s", filePath, outputDestination)
pass_success = int(1)
break
else:
continue
if pass_success == int(0):
Logger.error("EXTRACTOR: Extraction failed for %s. 7zip result was %s", filePath, res)
except:
Logger.exception("EXTRACTOR: Extraction failed for %s. Could not call command %s", filePath, cmd)