mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2024-11-29 04:53:48 +03:00
First style-less prototype for an HTML dump output (Issue #254)
This commit is contained in:
parent
e2d8b53e97
commit
b6ea337937
|
@ -11,6 +11,8 @@ import os
|
||||||
import StringIO
|
import StringIO
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
from xml.dom.minidom import getDOMImplementation
|
||||||
|
|
||||||
from lib.core.common import Backend
|
from lib.core.common import Backend
|
||||||
from lib.core.common import dataToDumpFile
|
from lib.core.common import dataToDumpFile
|
||||||
from lib.core.common import dataToStdout
|
from lib.core.common import dataToStdout
|
||||||
|
@ -322,6 +324,10 @@ class Dump:
|
||||||
def dbTableValues(self, tableValues):
|
def dbTableValues(self, tableValues):
|
||||||
replication = None
|
replication = None
|
||||||
rtable = None
|
rtable = None
|
||||||
|
documentNode = None
|
||||||
|
tableNode = None
|
||||||
|
rowNode = None
|
||||||
|
dumpFP = None
|
||||||
|
|
||||||
if tableValues is None:
|
if tableValues is None:
|
||||||
return
|
return
|
||||||
|
@ -333,13 +339,13 @@ class Dump:
|
||||||
|
|
||||||
if conf.dumpFormat == DUMP_FORMAT.SQLITE:
|
if conf.dumpFormat == DUMP_FORMAT.SQLITE:
|
||||||
replication = Replication("%s%s%s.sqlite3" % (conf.dumpPath, os.sep, unsafeSQLIdentificatorNaming(db)))
|
replication = Replication("%s%s%s.sqlite3" % (conf.dumpPath, os.sep, unsafeSQLIdentificatorNaming(db)))
|
||||||
elif conf.dumpFormat == DUMP_FORMAT.CSV:
|
elif conf.dumpFormat in (DUMP_FORMAT.CSV, DUMP_FORMAT.HTML):
|
||||||
dumpDbPath = "%s%s%s" % (conf.dumpPath, os.sep, unsafeSQLIdentificatorNaming(db))
|
dumpDbPath = "%s%s%s" % (conf.dumpPath, os.sep, unsafeSQLIdentificatorNaming(db))
|
||||||
|
|
||||||
if not os.path.isdir(dumpDbPath):
|
if not os.path.isdir(dumpDbPath):
|
||||||
os.makedirs(dumpDbPath, 0755)
|
os.makedirs(dumpDbPath, 0755)
|
||||||
|
|
||||||
dumpFileName = "%s%s%s.csv" % (dumpDbPath, os.sep, unsafeSQLIdentificatorNaming(table))
|
dumpFileName = "%s%s%s.%s" % (dumpDbPath, os.sep, unsafeSQLIdentificatorNaming(table), conf.dumpFormat.lower())
|
||||||
dumpFP = openFile(dumpFileName, "wb")
|
dumpFP = openFile(dumpFileName, "wb")
|
||||||
|
|
||||||
count = int(tableValues["__infos__"]["count"])
|
count = int(tableValues["__infos__"]["count"])
|
||||||
|
@ -391,6 +397,9 @@ class Dump:
|
||||||
cols.append((column, colType if colType else Replication.TEXT))
|
cols.append((column, colType if colType else Replication.TEXT))
|
||||||
|
|
||||||
rtable = replication.createTable(table, cols)
|
rtable = replication.createTable(table, cols)
|
||||||
|
elif conf.dumpFormat == DUMP_FORMAT.HTML:
|
||||||
|
documentNode = getDOMImplementation().createDocument(None, "table", None)
|
||||||
|
tableNode = documentNode.documentElement
|
||||||
|
|
||||||
if count == 1:
|
if count == 1:
|
||||||
self._write("[1 entry]")
|
self._write("[1 entry]")
|
||||||
|
@ -399,6 +408,10 @@ class Dump:
|
||||||
|
|
||||||
self._write(separator)
|
self._write(separator)
|
||||||
|
|
||||||
|
if conf.dumpFormat == DUMP_FORMAT.HTML:
|
||||||
|
rowNode = documentNode.createElement("tr")
|
||||||
|
tableNode.appendChild(rowNode)
|
||||||
|
|
||||||
for column in columns:
|
for column in columns:
|
||||||
if column != "__infos__":
|
if column != "__infos__":
|
||||||
info = tableValues[column]
|
info = tableValues[column]
|
||||||
|
@ -412,6 +425,10 @@ class Dump:
|
||||||
dataToDumpFile(dumpFP, "%s" % safeCSValue(column))
|
dataToDumpFile(dumpFP, "%s" % safeCSValue(column))
|
||||||
else:
|
else:
|
||||||
dataToDumpFile(dumpFP, "%s%s" % (safeCSValue(column), conf.csvDel))
|
dataToDumpFile(dumpFP, "%s%s" % (safeCSValue(column), conf.csvDel))
|
||||||
|
elif conf.dumpFormat == DUMP_FORMAT.HTML:
|
||||||
|
entryNode = documentNode.createElement("td")
|
||||||
|
rowNode.appendChild(entryNode)
|
||||||
|
entryNode.appendChild(documentNode.createTextNode(column))
|
||||||
|
|
||||||
field += 1
|
field += 1
|
||||||
|
|
||||||
|
@ -434,6 +451,10 @@ class Dump:
|
||||||
field = 1
|
field = 1
|
||||||
values = []
|
values = []
|
||||||
|
|
||||||
|
if conf.dumpFormat == DUMP_FORMAT.HTML:
|
||||||
|
rowNode = documentNode.createElement("tr")
|
||||||
|
tableNode.appendChild(rowNode)
|
||||||
|
|
||||||
for column in columns:
|
for column in columns:
|
||||||
if column != "__infos__":
|
if column != "__infos__":
|
||||||
info = tableValues[column]
|
info = tableValues[column]
|
||||||
|
@ -457,6 +478,10 @@ class Dump:
|
||||||
dataToDumpFile(dumpFP, "%s" % safeCSValue(value))
|
dataToDumpFile(dumpFP, "%s" % safeCSValue(value))
|
||||||
else:
|
else:
|
||||||
dataToDumpFile(dumpFP, "%s%s" % (safeCSValue(value), conf.csvDel))
|
dataToDumpFile(dumpFP, "%s%s" % (safeCSValue(value), conf.csvDel))
|
||||||
|
elif conf.dumpFormat == DUMP_FORMAT.HTML:
|
||||||
|
entryNode = documentNode.createElement("td")
|
||||||
|
rowNode.appendChild(entryNode)
|
||||||
|
entryNode.appendChild(documentNode.createTextNode(value))
|
||||||
|
|
||||||
field += 1
|
field += 1
|
||||||
|
|
||||||
|
@ -476,10 +501,13 @@ class Dump:
|
||||||
rtable.endTransaction()
|
rtable.endTransaction()
|
||||||
logger.info("table '%s.%s' dumped to sqlite3 database '%s'" % (db, table, replication.dbpath))
|
logger.info("table '%s.%s' dumped to sqlite3 database '%s'" % (db, table, replication.dbpath))
|
||||||
|
|
||||||
elif conf.dumpFormat == DUMP_FORMAT.CSV:
|
elif conf.dumpFormat in (DUMP_FORMAT.CSV, DUMP_FORMAT.HTML):
|
||||||
|
if conf.dumpFormat == DUMP_FORMAT.HTML:
|
||||||
|
dataToDumpFile(dumpFP, tableNode.toxml())
|
||||||
|
else:
|
||||||
dataToDumpFile(dumpFP, "\n")
|
dataToDumpFile(dumpFP, "\n")
|
||||||
dumpFP.close()
|
dumpFP.close()
|
||||||
logger.info("table '%s.%s' dumped to CSV file '%s'" % (db, table, dumpFileName))
|
logger.info("table '%s.%s' dumped to %s file '%s'" % (db, table, conf.dumpFormat, dumpFileName))
|
||||||
|
|
||||||
def dbColumns(self, dbColumnsDict, colConsider, dbs):
|
def dbColumns(self, dbColumnsDict, colConsider, dbs):
|
||||||
for column in dbColumnsDict.keys():
|
for column in dbColumnsDict.keys():
|
||||||
|
|
Loading…
Reference in New Issue
Block a user