@@ -129,8 +129,9 @@ def get_options(self):
129129 return self .options
130130
131131 def set_output_directory (self ):
132- self .output_directory = tempfile .mkdtemp (prefix = "sqlmapoutput-" )
133- self .set_option ("oDir" , self .output_directory )
132+ if not self .output_directory or not os .path .isdir (self .output_directory ):
133+ self .output_directory = tempfile .mkdtemp (prefix = "sqlmapoutput-" )
134+ self .set_option ("oDir" , self .output_directory )
134135
135136 def clean_filesystem (self ):
136137 shutil .rmtree (self .output_directory )
@@ -180,6 +181,8 @@ def __init__(self, taskid, messagetype="stdout"):
180181
181182 def write (self , value , status = CONTENT_STATUS .IN_PROGRESS , content_type = None ):
182183 if self .messagetype == "stdout" :
184+ insert = True
185+
183186 if content_type is None :
184187 if kb .partRun is not None :
185188 content_type = PART_RUN_CONTENT_TYPES .get (kb .partRun )
@@ -189,28 +192,32 @@ def write(self, value, status=CONTENT_STATUS.IN_PROGRESS, content_type=None):
189192
190193 #print >>sys.__stdout__, "value: %s\nstatus: %d\ncontent_type: %d\nkb.partRun: %s\n--------------" % (value, status, content_type, kb.partRun)
191194
192- output = conf .database_cursor .execute ("SELECT id, value FROM data WHERE taskid = ? AND content_type = ?" ,
195+ output = conf .database_cursor .execute ("SELECT id, status, value FROM data WHERE taskid = ? AND content_type = ?" ,
193196 (self .taskid , content_type ))
194197
195198 # Delete partial output from IPC database if we have got a complete output
196- if status == CONTENT_STATUS .COMPLETE and len (output ) > 0 :
197- for index in xrange (0 , len (output )- 1 ):
198- conf .database_cursor .execute ("DELETE FROM data WHERE id = ?" , (output [index ][0 ],))
199-
199+ if status == CONTENT_STATUS .COMPLETE :
200+ if len (output ) > 0 :
201+ for index in xrange (0 , len (output )- 1 ):
202+ if output [index ][1 ] == CONTENT_STATUS .COMPLETE :
203+ insert = False
204+ else :
205+ conf .database_cursor .execute ("DELETE FROM data WHERE id = ?" , (output [index ][0 ],))
206+
207+ if insert :
208+ conf .database_cursor .execute ("INSERT INTO data VALUES(NULL, ?, ?, ?, ?)" ,
209+ (self .taskid , status , content_type , jsonize (value )))
200210 if kb .partRun :
201211 kb .partRun = None
202212
203- if status == CONTENT_STATUS .IN_PROGRESS :
213+ elif status == CONTENT_STATUS .IN_PROGRESS :
204214 if len (output ) == 0 :
205215 conf .database_cursor .execute ("INSERT INTO data VALUES(NULL, ?, ?, ?, ?)" ,
206216 (self .taskid , status , content_type , jsonize (value )))
207217 else :
208- new_value = "%s%s" % (dejsonize (output [0 ][1 ]), value )
218+ new_value = "%s%s" % (dejsonize (output [0 ][2 ]), value )
209219 conf .database_cursor .execute ("UPDATE data SET value = ? WHERE id = ?" ,
210220 (jsonize (new_value ), output [0 ][0 ]))
211- else :
212- conf .database_cursor .execute ("INSERT INTO data VALUES(NULL, ?, ?, ?, ?)" ,
213- (self .taskid , status , content_type , jsonize (value )))
214221 else :
215222 conf .database_cursor .execute ("INSERT INTO errors VALUES(NULL, ?, ?)" ,
216223 (self .taskid , str (value ) if value else "" ))
0 commit comments