-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmdparse.py
More file actions
69 lines (54 loc) · 1.59 KB
/
cmdparse.py
File metadata and controls
69 lines (54 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
#---------------------
# Talwar v 0.2
# Command Parse
#---------------------
#Imports
import re
#Internal Imports
from db_config import default_db
#Vairables
default_options=['each','switch']
def start_parsecmd(uinput):
module_table=default_db('modules')
cmd=uinput.split('.')
valid=module_table.find_one(mod_name=cmd[0])
if valid:
try:
input_options = re.findall("'([^']*)'", str(valid['inputs']))
output_options = re.findall("'([^']*)'", str(valid['outputs']))
options = list(set(input_options + output_options))
if cmd[1] in options:
print '[#]Valid'
else:
if cmd[1] == 'help':
print '[#]Module Name:'+valid['mod_name']
print '[#]Inputs('+str(valid['inputsint'])+'):'+valid['inputs']
print '[#]Outputs('+str(valid['outputsint'])+'):'+valid['outputs']
else:
print '[!]No Valid Options'
except:
print '[#]Module Name:'+valid['mod_name']
print '[#]Inputs('+str(valid['inputsint'])+'):'+valid['inputs']
print '[#]Outputs('+str(valid['outputsint'])+'):'+valid['outputs']
else:
print '[!]Invlaid Command'
#Validate token from the scan script
def validate_token(token):
module_table=default_db('modules')
cmd=token.split('.')
valid=module_table.find_one(mod_name=cmd[0])
if valid:
try:
input_options = re.findall("'([^']*)'", str(valid['inputs']))
output_options = re.findall("'([^']*)'", str(valid['outputs']))
options = list(set(input_options + output_options))
if cmd[1] not in options:
return 0
if cmd[2] not in default_options:
return 0
return 1
except:
return 0
else:
return 0