Skip to content

Commit 30d464c

Browse files
committed
add new tools, add new status checks, move from tabs to sidebar
1 parent 77029d8 commit 30d464c

File tree

1 file changed

+52
-6
lines changed

1 file changed

+52
-6
lines changed

ctools.py

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
from suspend_sync import suspend_filer_sync
1111
from unsuspend_sync import unsuspend_filer_sync
1212
from reset_password import reset_filer_password
13+
from cloudfs import ask,create_folders,usage
14+
from smb_audit import convert_size, extract_epoch, convert_time, show_ftr_details, summarize_audit, parse_audit, search_audit, smb_audit
15+
from pandas.api.types import CategoricalDtype
16+
import re
1317

1418

1519
def set_logging(p_level=logging.INFO, log_file="info-log.txt"):
@@ -29,7 +33,7 @@ def set_logging(p_level=logging.INFO, log_file="info-log.txt"):
2933
logging.StreamHandler()])
3034

3135

32-
@Gooey(advanced=True, navigation='TABBED', program_name="CTools", use_cmd_args=True,
36+
@Gooey(advanced=True, navigation='SIDEBAR', program_name="CTools", use_cmd_args=True,
3337
default_size=(800, 750),
3438
menu=[{
3539
'name': 'File',
@@ -70,6 +74,8 @@ def main():
7074
'suspend_sync': suspend_filer_sync,
7175
'unsuspend_sync': unsuspend_filer_sync,
7276
'reset_password': reset_filer_password,
77+
'cloudfs': create_folders,
78+
'smb_audit': smb_audit,
7379
}
7480
parser = GooeyParser(description='Manage CTERA Edge Filers')
7581
parser.add_argument('--ignore-gooey', help='Run in CLI mode')
@@ -147,21 +153,56 @@ def main():
147153
reset_password_parser.add_argument('user_name', help='User Name')
148154
reset_password_parser.add_argument('filer_password', widget='PasswordField', help=new_pw_help_text)
149155

156+
# cloudfs sub parser
157+
cloudfs_help = "Create zones, folder groups, cloud folders"
158+
cloudfs_parser = subs.add_parser('cloudfs', parents=[portal_parent_parser], help=cloudfs_help)
159+
cloudfs_parser.add_argument('csv_file', widget='FileChooser', help='csv file')
160+
161+
# SMB Audit subparsers
162+
smb_audit_help_text = "Parse, summarize, and search Samba audit logs from CTEA devices."
163+
smb_audit_parser = subs.add_parser('smb_audit', help=smb_audit_help_text)
164+
smb_audit_parser.add_argument('-f', '--function', action='store', dest='function', widget='Dropdown', choices=['Parse', 'Summarize', 'Search'], required=True, default='Parse', type=str, help='Source log directory contianing ONLY audit log files (Format: share/folder1/folder2/folderN')
165+
smb_audit_parser.add_argument('-sd', '--source-directory', action='store', dest='source_directory', widget='DirChooser', type=str, help='Source log directory contianing ONLY audit log files (Format: share/folder1/folder2/folderN')
166+
smb_audit_parser.add_argument('-of', '--output-file', action='store', dest='output_file', type=str, help='Label for output files')
167+
#smb_audit_parser.add_argument('-c', '--csv', action='store_true', dest='make_csv', default=False, help='Output a CSV file in addition to other options')
168+
smb_audit_parser.add_argument('-if', '--input-file', action='store', dest='ftr_file', type=str, widget="FileChooser", help='Name of the input file(Format: customer_location.ftr)')
169+
smb_audit_parser.add_argument('-ti', '--time-interval', action='store', dest='time_interval', type=str, widget="Dropdown", choices=['5min', '10min', '15min', '20min', '30min', '60min'], required=True, default='30min', help='Time interval used for summary computations')
170+
smb_audit_parser.add_argument('-ss', '--search-string', action='store', dest='search_string', type=str, help='String to search for in the specified field.')
171+
smb_audit_parser.add_argument('-sf', '--search-field', action='store', dest='search_field', type=str, widget="Dropdown", choices=['path', 'share', 'user'], default='path', help='Field to be searched from the audit logs: path, user, result, share.')
172+
smb_audit_parser.add_argument('--debug', action='store_true', dest='is_debug', default=False, help='Enables debug output of arguments')
173+
smb_audit_parser.add_argument('-v', '--verbose', help='Add verbose logging', action='store_true')
174+
175+
#Create dictionary of Samba operation types
176+
smb_operations = ["op=ACEChanged", "op=ACLAdded", "op=ACLDeleted", "op=AclDenied", "op=chown",
177+
"op=create", "op=createDenied", "op=delete", "op=deleteDenied", "op=move",
178+
"op=open", "op=OpenDenied", "op=setattrib", "op=setdacl", "op=write"]
179+
smb_operation_type = CategoricalDtype(categories=smb_operations)
180+
smb_ops_group = smb_audit_parser.add_argument_group('Show SMB Operations')
181+
for op in smb_operations:
182+
op_string = re.sub('op=', '', op)
183+
op_command = "--" + op_string
184+
smb_ops_group.add_argument(op_command, action='store_false', default=True, widget='CheckBox', help=op_string )
185+
186+
150187
# Parse arguments and run commands of chosen task
151188
args = parser.parse_args()
152189
if args.verbose:
153190
set_logging(logging.DEBUG, 'debug-log.txt')
154191
else:
155192
set_logging()
193+
194+
156195
# Uncomment to log the arguments. Will reveal a GUI password in plain text.
157196
# logging.debug(args)
158197
logging.info('Starting ctools')
159198
# For CLI, if required password arg is a ?, prompt for password
160-
if args.password == '?':
161-
args.password = getpass(prompt='Password: ')
162-
# Create a global_admin object and login.
199+
if args.task != 'smb_audit':
200+
if args.password == '?':
201+
args.password = getpass(prompt='Password: ')
202+
# Create a global_admin object and login.
163203
# In the future, if we add device login tasks, we'll need to change this.
164-
global_admin = global_admin_login(args.address, args.username, args.password, args.ignore_cert)
204+
if args.task != 'smb_audit': #added this since smb_audit does not require portal login
205+
global_admin = global_admin_login(args.address, args.username, args.password, args.ignore_cert)
165206
# Set the chosen task.
166207
selected_task = FUNCTION_MAP[args.task]
167208
# Run selected task with required sub arguments.
@@ -181,9 +222,14 @@ def main():
181222
selected_task(global_admin, args.device_name, args.tenant_name)
182223
elif args.task == 'reset_password':
183224
selected_task(global_admin, args.device_name, args.tenant_name, args.user_name, args.filer_password)
225+
elif args.task == 'cloudfs':
226+
selected_task(global_admin, args.csv_file)
227+
elif args.task == 'smb_audit':
228+
selected_task(args)
184229
else:
185230
logging.error('No task found or selected.')
186-
global_admin.logout()
231+
if args.task != 'smb_audit': #added this since smb_audit does not require portal login
232+
global_admin.logout()
187233
logging.info('Exiting ctools')
188234

189235

0 commit comments

Comments
 (0)