def vb_reply(message): if audit_functions.check_role( message ) == 401: # if user is authorised to use this command then move to the lines bot.send_message(message.from_user.id, "Starting backup process...") os.startfile( config.script_fd + 'mysql_backup.bat' ) # executing 'mysql_backup.bat' batch file from 'BATs' folder. time.sleep(75) # wait for 75 seconds (look at ToDo) bot.send_message(message.from_user.id, "Backup process has ended. Please check logs...") mysql_logfile = glob.glob( config.mysqlbackup_logfolder + '*.log' ) # looking for files with '.log' extention in config.mysqlbackup_logfolder folder. youngest_log = max( mysql_logfile, key=os.path.getctime ) # checking and choosing the file with maximum TIMESTAMP (i.e youngest one) youngest_log = str.replace( youngest_log, '\\', '/') # fixing full path to log file by replacing '\' by '/' file_to_send = open( youngest_log, 'rb' ) # opening file and assigning filestream to file_to_send variable bot.send_document(message.chat.id, file_to_send) # sending logfile to user # ToDo Add Successfully operation check else: bot.send_message( message.from_user.id, 'You have no permission to execute this command...' ) # if not authorised then return ' No permission to execute' message
def send_runcmd(message): if audit_functions.check_role( message ) == 401: # if user is authorised to use this command then move to the lines command = str.replace( message.text, '/runcmd ', '') # replacing '/runcmd' in input string by empty string bot.send_message( message.from_user.id, '"' + command + '" command execution started...' ) # Notification about start of execution with name of command try: subprocess.run(command) # try to start command bot.send_message(message.from_user.id, 'Successfully executed ') # execution completed except: bot.send_message( message.from_user.id, 'Error happened while execution of requested command. Please check for permissiond or typos in command' ) # execution failed due to some typo or other problem else: bot.send_message( message.from_user.id, 'You have no permission to execute this command...' ) # if not authorised then return ' No permission to execute' message
def si_reply(message): if audit_functions.check_role( message ) == 401: # if user is authorised to use this command then move to the lines bot.send_message(message.from_user.id, "Gathering information ..." ) # sending 'Gathering information ...' message RAM_BUSY = str(psutil.virtual_memory().percent ) # assigning RAM busy % to RAM BUSY variable C_DISK_BUSY = str(psutil.disk_usage( 'C:/').percent) # assigning C drive busy % to C_DISK_BUSY variable D_DISK_BUSY = str(psutil.disk_usage( 'D:/').percent) # assigning D drive busy % to D_DISK_BUSY variable CPU_BUSY = 0 for x in range(10): # iterating to... CPU_BUSY = CPU_BUSY + psutil.cpu_percent( interval=1 ) # to get information about 10 second period CPU busy % CPU_BUSY = str( round(CPU_BUSY / 10, 2) ) # dividing output from previous step to number of seconds to get average bot.send_message( message.from_user.id, 'CPU busy: ' + CPU_BUSY + ' % \nC:\ drive busy: ' + C_DISK_BUSY + ' % \nD:\ drive busy: ' + D_DISK_BUSY + ' % \nRAM busy: ' + RAM_BUSY + ' %') # outputing and sending information gathered to user. # ToDo Add Successfully operation check # ToDo What to add? Think about this. else: bot.send_message( message.from_user.id, 'You have no permission to execute this command...' ) # if not authorised then return ' No permission to execute' message
def oo_reply(message): if audit_functions.check_role(message)==401: # if user is authorised to use this command then move to the lines bot.send_message(message.from_user.id, "Stopping service...") os.startfile(config.script_fd + 'restart_oo.bat') # executing 'restart_oo.bat' batch file from 'BATs' folder. bot.send_message(message.from_user.id, "Starting service") # ToDo Add Sucsessfully operation check else: bot.send_message(message.from_user.id, 'You have no permission to execute this command...') # if not authorised then return ' No permission to execute' message