Skip to content

Commit

Permalink
Add type param to dbexport.py
Browse files Browse the repository at this point in the history
  • Loading branch information
JrDw0 committed Jul 12, 2020
1 parent a631342 commit ccb105b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 22 deletions.
62 changes: 41 additions & 21 deletions dbexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,22 @@ def domain_to_table(table):
return table.replace('.', '_') + "_now_result"


def export(target, db=None, alive=False, limit=None, path=None, format='csv', show=False):
def export(target, type='target', db=None, alive=False, limit=None, path=None, format='csv', show=False):
"""
OneForAll export from database module
Example:
python3 dbexport.py --target name --format csv --dir= ./result.csv
python3 dbexport.py --db result.db --target name --show False
python3 dbexport.py --target table_name --tb True --show False
Note:
--alive True/False Only export alive subdomains or not (default False)
--format rst/csv/tsv/json/yaml/html/jira/xls/xlsx/dbf/latex/ods (result format)
--path Result directory (default directory is ./results)
:param str target: Table to be exported
:param str target: Table to be exported
:param str type: Type of target
:param str db: Database path to be exported (default ./results/result.sqlite3)
:param bool alive: Only export the results of alive subdomains (default False)
:param str limit: Export limit (default None)
Expand All @@ -41,25 +43,43 @@ def export(target, db=None, alive=False, limit=None, path=None, format='csv', sh
:param bool show: Displays the exported data in terminal (default False)
"""

database = Database(db)
domains = utils.get_domains(target)
datas = []
if domains:
for domain in domains:
table_name = domain_to_table(domain)
rows = database.export_data(table_name, alive, limit)
if rows is None:
continue
format = utils.check_format(format, len(rows))
if show:
print(rows.dataset)
data = rows.as_dict()
datas.extend(data)
database.close()
if datas:
utils.export_all(alive, format, path, datas)
if type == 'target':
database = Database(db)
domains = utils.get_domains(target)
datas = []
if domains:
for domain in domains:
table_name = domain_to_table(domain)
rows = database.export_data(table_name, alive, limit)
if rows is None:
continue
format = utils.check_format(format, len(rows))
path = utils.check_path(path, target, format)
if show:
print(rows.dataset)
data = rows.export(format)
utils.save_data(path, data)
logger.log('ALERT', f'The subdomain result for {table_name}: {path}')
data = rows.as_dict()
datas.extend(data)
database.close()
if len(domains) > 1:
utils.export_all(alive, format, path, datas)
elif type == 'table':
database = Database(db)
rows = database.export_data(target, alive, limit)
format = utils.check_format(format, len(rows))
path = utils.check_path(path, target, format)
if show:
print(rows.dataset)
data = rows.export(format)
database.close()
utils.save_data(path, data)
logger.log('ALERT', f'The subdomain result for {target}: {path}')
data_dict = rows.as_dict()
return data_dict


if __name__ == '__main__':
# fire.Fire(export)
export('example.com')
fire.Fire(export)
# export('example.com')
2 changes: 1 addition & 1 deletion oneforall.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def export(self, table):
:rtype: list
"""
db = Database()
data = dbexport.export(table, alive=self.alive, format=self.format)
data = dbexport.export(table, type='table', alive=self.alive, format=self.format)
db.drop_table(self.new_table)
db.rename_table(self.domain, self.new_table)
db.close()
Expand Down

0 comments on commit ccb105b

Please sign in to comment.