Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f7d826f

Browse files
committed
first case where partial output is retrievable via RESTful API - issue #297
1 parent 2f69a94 commit f7d826f

2 files changed

Lines changed: 34 additions & 5 deletions

File tree

lib/core/enums.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,34 @@ class CONTENT_TYPE:
271271
OS_CMD = 23
272272
REG_READ = 24
273273

274+
PART_RUN_CONTENT_TYPES = {
275+
"checkDbms": CONTENT_TYPE.TECHNIQUES,
276+
"getFingerprint": CONTENT_TYPE.DBMS_FINGERPRINT,
277+
"getBanner": CONTENT_TYPE.BANNER,
278+
"getCurrentUser": CONTENT_TYPE.CURRENT_USER,
279+
"getCurrentDb": CONTENT_TYPE.CURRENT_DB,
280+
"getHostname": CONTENT_TYPE.HOSTNAME,
281+
"isDba": CONTENT_TYPE.IS_DBA,
282+
"getUsers": CONTENT_TYPE.USERS,
283+
"getPasswordHashes": CONTENT_TYPE.PASSWORDS,
284+
"getPrivileges": CONTENT_TYPE.PRIVILEGES,
285+
"getRoles": CONTENT_TYPE.ROLES,
286+
"getDbs": CONTENT_TYPE.DBS,
287+
"getTables": CONTENT_TYPE.TABLES,
288+
"getColumns": CONTENT_TYPE.COLUMNS,
289+
"getSchema": CONTENT_TYPE.SCHEMA,
290+
"getCount": CONTENT_TYPE.COUNT,
291+
"dumpTable": CONTENT_TYPE.DUMP_TABLE,
292+
"search": CONTENT_TYPE.SEARCH,
293+
"sqlQuery": CONTENT_TYPE.SQL_QUERY,
294+
"tableExists": CONTENT_TYPE.COMMON_TABLES,
295+
"columnExists": CONTENT_TYPE.COMMON_COLUMNS,
296+
"readFile": CONTENT_TYPE.FILE_READ,
297+
"writeFile": CONTENT_TYPE.FILE_WRITE,
298+
"osCmd": CONTENT_TYPE.OS_CMD,
299+
"regRead": CONTENT_TYPE.REG_READ
300+
}
301+
274302
class CONTENT_STATUS:
275303
IN_PROGRESS = 0
276304
COMPLETE = 1

lib/utils/api.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from lib.core.datatype import AttribDict
2828
from lib.core.defaults import _defaults
2929
from lib.core.enums import CONTENT_STATUS
30+
from lib.core.enums import PART_RUN_CONTENT_TYPES
3031
from lib.core.log import LOGGER_HANDLER
3132
from lib.core.optiondict import optDict
3233
from lib.core.subprocessng import Popen
@@ -176,16 +177,16 @@ def __init__(self, taskid, messagetype="stdout"):
176177
def write(self, value, status=CONTENT_STATUS.IN_PROGRESS, content_type=None):
177178
if self.messagetype == "stdout":
178179
if content_type is None:
179-
content_type = 99
180+
if kb.partRun is not None:
181+
content_type = PART_RUN_CONTENT_TYPES.get(kb.partRun)
182+
else:
183+
# Ignore all non-relevant messages
184+
return
180185

181186
output = conf.database_cursor.execute("SELECT id, value FROM data WHERE taskid = ? AND status = ? AND content_type = ? LIMIT 0,1",
182187
(self.taskid, status, content_type))
183188

184189
if status == CONTENT_STATUS.IN_PROGRESS:
185-
# Ignore all non-relevant messages
186-
if kb.partRun is None:
187-
return
188-
189190
if len(output) == 0:
190191
conf.database_cursor.execute("INSERT INTO data VALUES(NULL, ?, ?, ?, ?)",
191192
(self.taskid, status, content_type, jsonize(value)))

0 commit comments

Comments
 (0)