def rootDirectoryListing(image_name, image_partition): #print("Files: Rendering Template with files for partition: ", #image_name, image_partition) image_index = bcawGetImageIndex(str(image_name), False) dm = bcaw() image_path = image_dir+'/'+image_name file_list_root, fs = dm.bcawGenFileList(image_path, image_index, int(image_partition), '/') return file_list_root
def root_directory_list(image_name, image_partition): #print("Files: Rendering Template with files for partition: ", #image_name, image_partition) image_index = bcawGetImageIndex(str(image_name), False) dm = bcaw() image_path = image_dir+'/'+image_name file_list_root, fs = dm.bcawGenFileList(image_path, image_index, int(image_partition), '/') return render_template('fl_part_temp_ext.html', image_name=str(image_name), partition_num=image_partition, file_list=file_list_root)
def dbBrowseImages(): global image_dir image_index = 0 # Since image_list is declared globally, empty it before populating global image_list del image_list[:] for img in os.listdir(image_dir): if img.endswith(".E01") or img.endswith(".AFF"): #print "\n IMAGE: ", img global image_list image_list.append(img) # FIXME: Partition info will be added to the metadata info # Till then the following three lines are not necessary. dm = bcaw_utils.bcaw() image_path = image_dir+'/'+img dm.num_partitions = dm.bcawGetNumPartsForImage(image_path, image_index) xmlfile = dm.dbGetImageInfoXml(image_path) if (xmlfile == None): #print("No XML file generated for image info. Returning") return #print("XML File {} generated for image {}".format(xmlfile, img)) # Read the XML file and populate the record for this image dbrec = bcawGetXmlInfo(xmlfile) ## print("D: Adding dbrec session to the DB: ", dbrec) dbrec['image_name'] = img # Populate the db: # Add the created record/session to the DB bcawDbSessionAdd(dbrec) image_index +=1 else: continue db.session.commit()
def listImages(): global image_dir image_index = 0 # Since image_list is declared globally, empty it before populating global image_list del image_list[:] global image_db del image_db [:] # Create the DB. FIXME: This needs to be called from runserver.py # before calling run. That seems to have some issues. So calling from # here for now. Need to fix it. session = bcaw_db.bcawdb() for img in os.listdir(image_dir): if img.endswith(".E01") or img.endswith(".AFF"): #print img global image_list image_list.append(img) dm = bcaw() image_path = image_dir+'/'+img dm.num_partitions = dm.bcawGetPartInfoForImage(image_path, image_index) idb = bcaw_db.DimacImages.query.filter_by(image_name=img).first() image_db.append(idb) ## print("D: IDB: image_index:{}, image_name:{}, acq_date:{}, md5: {}".format(image_index, idb.image_name, idb.acq_date, idb.md5)) image_index +=1 else: continue # Render the template for main page. #print 'D: Image_list: ', image_list global num_images num_images = len(image_list) return image_list
def fileInformation(image_name, image_partition, path): #print("Files: Rendering Template for subdirectory or contents of a file: ", #image_name, image_partition, path) image_index = bcawGetImageIndex(str(image_name), False) image_path = image_dir+'/'+image_name file_name_list = path.split('/') file_name = file_name_list[len(file_name_list)-1] #print "D: File_path after manipulation = ", path # To verify that the file_name exsits, we need the directory where # the file sits. That is if tje file name is $Extend/$RmData, we have # to look for the file $RmData under the directory $Extend. So we # will call the TSK API fs.open_dir with the parent directory # ($Extend in this example) temp_list = path.split("/") temp_list = file_name_list[0:(len(temp_list)-1)] parent_dir = '/'.join(temp_list) #print("D: Invoking TSK API to get files under parent_dir: ", parent_dir) # Generate File_list for the parent directory to see if the dm = bcaw() file_list, fs = dm.bcawGenFileList(image_path, image_index, int(image_partition), parent_dir) # Look for file_name in file_list for item in file_list: ## print("D: item-name={} file_name={} ".format(item['name'], file_name)) if item['name'] == file_name: #print("D : File {} Found in the list: ".format(file_name)) break else: print("D: File_clicked: File {} not found in file_list".format(file_name)) #continue if item['isdir'] == True: # We will send the file_list under this directory to the template. # So calling once again the TSK API ipen_dir, with the current # directory, this time. file_list, fs = dm.bcawGenFileList(image_path, image_index, int(image_partition), path) # Generate the URL to communicate to the template: with app.test_request_context(): url = api.url_for('api.fileInfo', image_name=str(image_name), partition=image_partition, path=path ) #print (">> Rendering template with URL: ", url) return file_list else: #print("Downloading File: ", item['name']) # It is an ordinary file f = fs.open_meta(inode=item['inode']) # Read data and store it in a string offset = 0 size = f.info.meta.size BUFF_SIZE = 1024 * 1024 total_data = "" while offset < size: available_to_read = min(BUFF_SIZE, size - offset) data = f.read_random(offset, available_to_read) if not data: #print("Done with reading") break offset += len(data) total_data = total_data+data #print "Length OF TOTAL DATA: ", len(total_data) mime = MimeTypes() mime_type, a = mime.guess_type(file_name) generator = (cell for row in total_data for cell in row) return Response(stream_with_context(generator), mimetype=mime_type, headers={"Content-Disposition": "attachment;filename=" + urllib.quote(file_name) }) #"attachment;filename=" + file_name }) '''
break offset += len(data) total_data = total_data+data #print "Length OF TOTAL DATA: ", len(total_data) mime = MimeTypes() mime_type, a = mime.guess_type(file_name) generator = (cell for row in total_data for cell in row) return Response(stream_with_context(generator), mimetype=mime_type, headers={"Content-Disposition": "attachment;filename=" + urllib.quote(file_name) }) #"attachment;filename=" + file_name }) ''' return render_template('fl_filecat_temp_ext.html', image_name=str(image_name), partition_num=image_partition, file_name=file_name, contents=str(data)) #contents = data.decode("utf-8")) ''' # FIXME: This is never called (since we run runserver.py) # Remove once confirmed to be deleted if __name__ == "__main__": dm = bcaw() bcaw_db.bcawdb() app.run()
def dbBuildTableForImage(img, bld_imgdb = False, bld_dfxmldb = False): """ This routine builds/adds the DFXML table entry to the DB for the specified image. This is needed where a user selects an individual image in the image matrix and opts to add or delete corresponding table. """ table_added = 0 if bld_imgdb and bld_dfxmldb: # table_name set to dfxmlinfo - if it exists, bcaw_images has to be there. table_name = "bcaw_dfxmlinfo" else: if bld_imgdb: table_name = "bcaw_images" elif bld_dfxmldb: table_name = "bcaw_dfxmlinfo" else: # if bld_imgdb == False and bld_dfxmldb == False: return(-1, "No DB Specified") if not img.endswith(".E01") or img.endswith(".AFF"): logging.debug('>> Not building Table: Wrong image type: %s', img) # print ">> Not building Table: Wrong image type: ", img return(-1, "Wrong Image Type") # No need to create table if it already exists if dbu_does_table_exist_for_img(img, table_name): logging.debug('>> Table already exists for image %s', img) # print ">> Table already exists for image " , img return(-2, "Table entry exists for the image") else: logging.debug('>> Table for image %s does not exist', img) # print ">> Table for image {} does not exist: ".format(img) db_login.create_all() table_added += 1 if bld_imgdb: # update the image_matrix logging.debug('D: dbBuildTableForImage: Updating the matrix for img_db_exists') # print "D: dbBuildTableForImage: Updating the matrix for img_db_exists " # By setting image to None, it sets the flags for all images. We don't # do individual flag setting for imgdb. image_browse.bcawSetFlagInMatrix('img_db_exists', bld_imgdb, None) if bld_dfxmldb: logging.debug('D: dbBuildTableForImage: Updating the matrix for dfxml_db_exists') # print "D: dbBuildTableForImage: Updating the matrix for dfxml_db_exists " image_browse.bcawSetFlagInMatrix('dfxml_db_exists', bld_dfxmldb, img) # FIXME: Partition info will be added to the metadata info # Till then the following three lines are not necessary. image_index = image_browse.bcawGetImageIndex(str(img), False) dm = bcaw_utils.bcaw() image_path = image_dir+'/'+img dm.num_partitions = dm.bcawGetNumPartsForImage(image_path, image_index) xmlfile = dm.dbGetImageInfoXml(image_path) if (xmlfile == None): logging.debug('No XML file generated for image info. Returning') # print("No XML file generated for image info. Returning") return (-1, "No Image XML File generated") logging.debug('XML File %s generated for image', xmlfile) # print("XML File {} generated for image {}".format(xmlfile, img)) dfxmlfile = dm.dbGetInfoFromDfxml(image_path) if (dfxmlfile == None): logging.debug('>> No DFXML file generated for image info. Returning') # print(">> No DFXML file generated for image info. Returning") return (-1, "No DFXML generated") logging.debug('>> DFXML File %s generated for image', dfxmlfile) # print(">> DFXML File {} generated for image {}".format(dfxmlfile, img)) # Read the XML file and populate the record for this image if bld_imgdb: dbrec = bcawGetXmlInfo(xmlfile) # FIXME: Retained temporarily. Probably not needed. ##dbu_create_table_if_doesntexist("bcaw_images") dbrec['image_name'] = img dbrec['indexed'] = 0 # Just initialize to something # Populate the db: # Add the created record/session to the DB bcawDbSessionAdd(dbrec) ## print("D: Adding dbrec session to the DB: ", dbrec) if bld_dfxmldb: d_dbrec = bcawGetDfxmlInfo(dfxmlfile, img) if table_added > 0: return(0, "New tables added to the DB") else: retstr = "Table entries exist for the image " + img return(0, retstr)
def dbBrowseImages(): """ This routine is called at initialization, soon after the tables are created. It goes through the disk images in image_dir and builds the db tables for both image_db and dfxml_db, if they don't already exist. """ global image_dir image_index = 0 # Since image_list is declared globally, empty it before populating global image_list del image_list[:] for img in os.listdir(image_dir): if img.endswith(".E01") or img.endswith(".AFF"): # print "\n Image: ", img ## global image_list image_list.append(img) # Check if table entry already exists for this image: if dbu_does_table_exist_for_img(img, 'bcaw_images'): logging.debug('>> Table already exists for Image %s', img) # print ">> Table already exists for Image ", img continue logging.debug('D: dbBrowseImages: Table does not exist for image. Proceeding.') # print "D: dbBrowseImages: Table doesnot exist for img {}. Proceeding.".format(img) # FIXME: Partition info will be added to the metadata info # Till then the following three lines are not necessary. dm = bcaw_utils.bcaw() image_path = image_dir+'/'+img dm.num_partitions = dm.bcawGetNumPartsForImage(image_path, image_index) xmlfile = dm.dbGetImageInfoXml(image_path) if (xmlfile == None): logging.debug('No XML file generated for image info. Returning') # print("No XML file generated for image info. Returning") # FIXME: This was a return stmt, but it should move on to # the next image. So replaced it with continue. Need to test # some relevant scenarios to confirm this is what we want. continue logging.debug('XML file %s generated', xmlfile) logging.debug('for image %s', img) # print("XML File {} generated for image {}".format(xmlfile, img)) dfxmlfile = dm.dbGetInfoFromDfxml(image_path) if (dfxmlfile == None): logging.debug('No DFXML file generated for image info. Returning') # print("No DFXML file generated for image info. Returning") continue logging.debug('DFXML File %s generated for image', dfxmlfile) # print("DFXML File {} generated for image {}".format(dfxmlfile, img)) # Read the XML file and populate the record for this image dbrec = bcawGetXmlInfo(xmlfile) ## print("D: Adding dbrec session to the DB: ", dbrec) dbrec['image_name'] = img dbrec['indexed'] = 0 # Populate the db: FIXME: See if we need to check if it already exists, # or the check for image DB above will suffice as the existance of the # image_db is prerequisite for the dfxml db. # Add the created record/session to the DB ## print "[D2]:dbBrowseImages: Adding session to imgdb - bcawDbSessionAdd " bcawDbSessionAdd(dbrec) image_index +=1 else: continue #db.session.commit() logging.debug('D: Image_list %s', image_list)