def grep_system_packages(self,package_name): comm = subprocess.Popen([self.system_query_command() + " " + str(package_name)], shell=True, stdout=subprocess.PIPE) if comm is not None: logger.log("INFO", "Package " + str(comm.stdout.read()).strip() + " was found.") else: logger.log("ERROR", "Package " + str(comm.stdout.read()).strip() + " was not found.")
def main(self): try: for item in self.sys_dependencies[version.system_package_manager()]: self.grep_system_packages(item) except DistutilsExecError as distutilsExecError: logger.log("ERROR", "Exception DistutilsExecError: " + str(distutilsExecError)) except Exception as exception: logger.log("ERROR", "Exception exception: " + str(exception))
def modify_conf_files(self, username): logger.log('INFO', 'Modifying config files.') subprocess.Popen([ "find src/system/* -type f -iname *.conf -exec sed -i 's/username/" + username + "/g' {} \;" ], shell=True, stdout=subprocess.PIPE)
def clear_auto_login(clear, user): if len(sys.argv) > 2 and clear: logger.log("ERROR", "Too many arguments for clear given. Exiting now.") sys.exit(1) if clear and user_present(user): remove_from_group(user) sys.exit(1) elif clear and not user_present(user): sys.exit(1)
def grep_system_packages(self, package_name): comm = subprocess.Popen( [self.system_query_command() + " " + str(package_name)], shell=True, stdout=subprocess.PIPE) if comm is not None: logger.log( "INFO", "Package " + str(comm.stdout.read()).strip() + " was found.") else: logger.log( "ERROR", "Package " + str(comm.stdout.read()).strip() + " was not found.")
def pip_package_check(self): packages = [ 'opencv-python', 'python-crontab' ] for package in packages: pip_query = subprocess.Popen(["pip show \'"+str(package)+"\' 2> /dev/null"], shell=True, stdout=subprocess.PIPE) if '' not in pip_query.stdout.readlines(): logger.log("INFO", "Package " + str(package) + " was found.") else: logger.log("ERROR", "Package " + str(package) + " was not found.")
def cron_tab(self): #Count need to be 1 in order to write to the crontab #Basically, checking for grep being None or not None will # not work in this case and we need to check for 2 occurances. count=0 command="/bin/bash /home/root/.ssh/is_imagecapture_running.sh" cron = CronTab(user='******') job = cron.new(command=command) job.minute.every(1) install = re.search('install', str(sys.argv[1]), re.M | re.I) for item in cron: grep = re.search(r'\/is_imagecapture_running.sh', str(item)) if grep is not None: count+=1 if count < 2 and install is not None: logger.log("INFO", "Installing crontab.") cron.write()
def cron_tab(self): #Count need to be 1 in order to write to the crontab #Basically, checking for grep being None or not None will # not work in this case and we need to check for 2 occurances. count = 0 command = "/bin/bash /home/root/.ssh/is_sshm_running.sh" cron = CronTab(user='******') job = cron.new(command=command) job.minute.every(1) install = re.search('install', str(sys.argv[1]), re.M | re.I) for item in cron: grep = re.search(r'\/is_sshm_running.sh', str(item)) if grep is not None: count += 1 if count < 2 and install is not None: logger.log("INFO", "Installing crontab.") cron.write() print("Please nesure that the crontab was actually installed!") print( "To do so please run(without quotes) => 'sudo contab -l -u root'" )
def pip_install_package(self,package): logger.log("INFO", "Installing opencv-python via pip") os.system("su " + str(user.name()) + " -c 'pip install --user " + str(package) + "'")
def modify_conf_files(self,username): logger.log('INFO', 'Modifying config files.') subprocess.Popen(["find src/system/* -type f -iname *.conf -exec sed -i 's/username/" + username + "/g' {} \;"], shell=True, stdout=subprocess.PIPE)
def main(self): try: for item in self.sys_dependencies[version.system_package_manager()]: self.grep_system_packages(item) except DistutilsExecError as distutilsExecError: logger.log("ERROR", "Exception DistutilsExecError: " + str(distutilsExecError))
def auto_login(auto_login, user): if auto_login: logger.log("INFO", "Automatically logging you in now.") add_to_roup(user)
if count < 2 and install is not None: logger.log("INFO", "Installing crontab.") cron.write() print("Please nesure that the crontab was actually installed!") print( "To do so please run(without quotes) => 'sudo contab -l -u root'" ) if __name__ == '__main__': prepareBuild = PrepareBuild() argument = re.match(r'(install|check|build|sdist)\b', str(sys.argv[1])) if argument is None: logger.log("ERROR", "Option is not supported.") sys.exit(0) '''elif argument.group() == 'check': logger.log("INFO","Grepping System Packages") Check().main() sys.exit(0)''' logger.log('INFO', 'Entering setup in setup.py') setup( name='sshmonitor', version='0.0.7', url='https://github.com/amboxer21/SSHMonitorPy', license='GPL-3.0', author='Anthony Guevara', author_email='*****@*****.**',
count+=1 if count < 2 and install is not None: logger.log("INFO", "Installing crontab.") cron.write() def pip_install_package(self,package): logger.log("INFO", "Installing opencv-python via pip") os.system("su " + str(user.name()) + " -c 'pip install --user " + str(package) + "'") if __name__ == '__main__': prepareBuild = PrepareBuild() argument = re.match(r'(install|check|build|sdist)\b', str(sys.argv[1])) if argument is None: logger.log("ERROR","Option is not supported.") sys.exit(0) elif argument.group() == 'check': check = Check() logger.log("INFO","Grepping System Packages") check.main() logger.log("INFO","Grepping PIP Packages") check.pip_package_check() sys.exit(0) username = str(user.name()) pam = str(gdm.pam_d()[0]) pkgm = str(version.system_package_manager()) conf_path = 'src/system/autologin/conf' conf_name = [conf_path+'/slim.conf',conf_path+'/mdm.conf',conf_path+'/gdm.conf']
count+=1 if count < 2 and install is not None: logger.log("INFO", "Installing crontab.") cron.write() def pip_install_package(self,package): logger.log("INFO", "Installing opencv-python via pip") os.system("su " + str(user.name()) + " -c 'pip install --user " + str(package) + "'") if __name__ == '__main__': prepareBuild = PrepareBuild() argument = re.match(r'(install|check|build|sdist)\b', str(sys.argv[1])) if argument is None: logger.log("ERROR","Option is not supported.") sys.exit(0) elif argument.group() == 'check': logger.log("INFO","Grepping System Packages") Check().main() sys.exit(0) username = str(user.name()) pam = str(gdm.pam_d()[0]) pkgm = str(version.system_package_manager()) conf_path = 'src/system/autologin/conf' conf_name = [conf_path+'/slim.conf',conf_path+'/mdm.conf',conf_path+'/gdm.conf'] prepareBuild.modify_conf_files(username)