def Install(): ban.main('mongodb-client v3.4.15', 'NA') sys.stdout.write("\033[1;32m") yes_no = raw_input("Do you want to continue(y/n): ") sys.stdout.write("\033[0m") if yes_no == 'y': lic = l.licensevalid() if lic == 'valid': # os.remove('/etc/yum.repos.d/mongodb-org.repo') log('mongod.log', 'Creating Mongo Repo...!') with open('/tmp/mongodb-org.repo', 'w+') as file: file.write('[mongodb-org-3.4]') file.write('\nname=MongoDB 3.4 Repository') file.write( '\nbaseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/' ) file.write('\ngpgcheck=0') file.write('\nenabled=1') os.system("sudo mv /tmp/mongodb-org.repo /etc/yum.repos.d/") # os.system("sudo yum install mongodb-org -y") os.system("sudo yum install mongodb-org-shell -y") os.system("sudo yum install mongodb-org-mongos -y") log('mongod.log', 'Mongo CLient installed Successfully...!') #start MongoD service # mongod = subprocess.Popen(['service', 'mongod', 'start']) # mongod.wait() #Banner ban.banmongo() ban.banner('mongo-client v3.4.15', 'mongo,mongos', 'na', 'na', 'na', '/var/log/srx/mongo.log', 'na') else: log('mongod.log', 'Please Contact Script Owner') else: print "\n\t\033[1;31;40mScript terminated\033[0m"
def Install(): #### if os.path.exists('/etc/my.cnf'): log( 'mysql.log', 'There are few Configuration Files Left Please Uninstall them first...!' ) sys.exit() ##Reading Config File fileDir = os.path.dirname(os.path.realpath('__file__')) filename = os.path.join(fileDir, 'config.json') with open(filename) as f: data = json.load(f) # print(data['spark']['url']) ban.main('MySQL client v' + data['mysql']['version'], 'NA') sys.stdout.write("\033[1;32m") yes_no = raw_input("Do you want to continue(y/n): ") sys.stdout.write("\033[0m") if yes_no == 'y': lic = l.licensevalid() if lic == 'valid': log('mysql.log', 'Downloading Mysql from Artifactory....!') def download(file): mysql_agent = requests.get(file, stream=True, verify=False) if mysql_agent.status_code == 200: with open('/tmp/' + file, 'wb') as f: for chunk in mysql_agent.iter_content(1024): f.write(chunk) download(data['mysql']['common']) download(data['mysql']['client']) download(data['mysql']['libs']) log('mysql.log', 'Installing Mysql ....!') os.system( "sudo rpm -ivh /tmp/mysql-community-common-5.7.22-1.el7.x86_64.rpm" ) os.system( "sudo rpm -ivh /tmp/mysql-community-libs-5.7.22-1.el7.x86_64.rpm" ) os.system( "sudo rpm -ivh /tmp/mysql-community-client-5.7.22-1.el7.x86_64.rpm" ) #Deleting rpm file log('mysql.log', 'Deleteing Temporary Files......!') os.system("rm -rf /tmp/mysql-community-*") log('mysql.log', 'Mysql Client 5.7.22 is installed Successfully......!') #Banner ban.banmysql() ban.banner('mysql-clinet v' + data['mysql']['version'], 'mysql', 'na', '/etc/my.cnf', 'na', '/var/log/srx/mysql.log', 'na') else: print "Please Contact Script Owner" else: print "\n\t\033[1;31;40mScript terminated\033[0m"
def Install(): ###Initial Checks if os.path.exists('/opt/apache/spark/current-spark/conf/spark-env.sh'): log('spark.log','There are few Configuration Files Left Please Uninstall them first...!') sys.exit() ##Reading Config File fileDir = os.path.dirname(os.path.realpath('__file__')) filename = os.path.join(fileDir, 'config.json') with open(filename) as f: data = json.load(f) # print(data['spark']['url']) ban.main('Apache Spark v'+data['spark']['version'],'/opt/apache') sys.stdout.write("\033[1;32m") yes_no = raw_input("Do you want to continue(y/n): ") sys.stdout.write("\033[0m") if yes_no == 'y': lic = l.licensevalid() if lic == 'valid': log('spark.log','Creating spark log directory in /var/log/srx/....!') log('spark.log','Checking Dependency Mongo ......!') mongo_rc = 2 try: mongo_rc = call(["mongo","-version"]) except OSError as e: log('spark.log','Mongo Not Installed...!') if mongo_rc == 0: log('spark.log','Mongo is already exists on your machine') else: log('spark.log','Mongo is Installing on your machine') mongod.Install() log('kafka.log','Checking Dependency Java ......!') java_rc = 2 try: # global java_rc java_rc = call(["java","-version"]) except OSError as e: log('kafka.log','Java Not Installed...!') if java_rc == 0: log('kafka.log','Java is already exists on your machine') else: log('kafka.log','Java is Installing on your machine') java.Install() log('spark.log','Apache Spark Installation Started...!') log('spark.log','Creating spark-user....!') print "\033[1;34;40mDefault Spark user and ID are mentioned below\033[0m" sys.stdout.write("\033[1;32m") print "\t\t******************" print "\t\tuser-name - spark" print "\t\tgroup-name - spark" print "\t\tuserID - 12000" print "\t\tgroupID - 12000" print "\t\t******************" sys.stdout.write("\033[0m") guser = useradd.user('spark') # option = raw_input("Do you want to modify the default user details ? (y/n): ") # guser = '******' # if option.lower() == 'y' : # user = raw_input("Enter UserName : "******"Enter GroupName : ") # userID = raw_input("Enter UserID : ") # groupID = raw_input("Enter GroupID : ") # # Adding Group kafka-user # os.system("sudo groupadd -g "+groupID+" "+group) # # Adding User kafka-user # os.system("sudo useradd -u "+userID+" -g "+group+" -c 'Spark User' "+user) # # Changing Password for User Kafka-user # os.system("echo '"+user+":"+base64.b64decode('dCRpMjAxOA==')+"' | sudo chpasswd") # os.system("sudo su "+user+" -c 'echo "+"hello from "+"$USER'") # global guser # guser = user # else : # # Adding Group kafka-user # os.system("sudo groupadd -g 12000 spark") # # Adding User kafka-user # os.system("sudo useradd -u 12000 -g spark -c 'Spark User' spark") # # Changing Password for User Kafka-user # os.system("echo 'spark:"+base64.b64decode('dCRpMjAxOA==')+"' | sudo chpasswd") # os.system("sudo su spark -c 'echo "+"hello from "+"$USER'") #Creating Directory log('spark.log','Creating Directory Spark in /opt/apache') os.system("sudo mkdir -p /opt/apache/spark/") os.system("sudo chmod -R 777 /opt/apache/spark") #Downloading Spark File log('spark.log','Downloading Spark from Artifactory....!') spark_agent = requests.get(data['spark']['url'], stream=True, verify=False) if spark_agent.status_code == 200: with open('/opt/apache/spark/sparkpak-1.2.0-deploy.tgz', 'wb') as f: for chunk in spark_agent.iter_content(1024): f.write(chunk) log('spark.log','Extracting spark tar file in /opt/apache/spark....!') tar = tarfile.open('/opt/apache/spark/sparkpak-1.2.0-deploy.tgz') tar.extractall(path='/opt/apache/spark/') # Add Envrionment Variables in Bashrc os.system("sudo chmod -R 777 /home/"+guser+"") with open('/home/'+guser+'/.bashrc', 'a') as file: file.write('\nexport SPARK_PAK=$HOME/sparkpak_1.2_deploy') file.write('\n. $SPARK_PAK/conf/spark-env.sh') os.system("sudo chmod -R 700 /home/"+guser+"") # Copy Files os.system("cp /opt/apache/spark/sparkpak_1.2_deploy/spark-2.3.0-bin-hadoop2.7/conf/spark-env.sh.template /opt/apache/spark/sparkpak_1.2_deploy/spark-2.3.0-bin-hadoop2.7/conf/spark-env.sh") # Change Permissions to spark # os.system("sudo chown "+guser+":"+guser+" /opt/apache/spark/sparkpak_1.2_deploy/spark-2.3.0-bin-hadoop2.7/conf/spark-env.sh") # Append Configuration files log('spark.log','Modifying saprk-env.sh file in /opt/apache/spark/current-spark/conf/....!') with open('/opt/apache/spark/sparkpak_1.2_deploy/spark-2.3.0-bin-hadoop2.7/conf/spark-env.sh', 'a') as file: file.write('\nSPARK_WORKER_PORT=7080') file.write('\nSPARK_WORKER_MEMORY=16g') file.write('\nSPARK_WORKER_CORES=8') #Change Permissions to spark os.system("sudo chown -R "+guser+":"+guser+" /opt/apache/spark") os.system("sudo chown -R "+guser+":"+guser+" /opt/apache/spark/sparkpak_1.2_deploy") # Create Link to Home Directory log('spark.log','Creating symbolic link current-spark in /opt/apache/spark....!') os.system("sudo ln -s /opt/apache/spark/sparkpak_1.2_deploy/spark-2.3.0-bin-hadoop2.7 /opt/apache/spark/current-spark") os.system("sudo ln -s /opt/apache/spark/sparkpak_1.2_deploy/ /home/"+guser+"") os.system("sudo chown -R "+guser+":"+guser+" /opt/apache/spark/current-spark") #########Choose Master Or Slave ########## print "\033[1;34;40mPlease Choose Your Option Below:\033[0m" print "\033[1;34;40m(A) Spark-Master \t(OR)\t (B) Spark-Slave\033[0m" while True: server = raw_input("Choose ? (A/B): ") if server.lower() == 'a': os.system("sudo cp /opt/apache/spark/current-spark/spark-2.3.0-bin-hadoop2.7/conf/slaves.template /opt/apache/spark/current-spark/spark-2.3.0-bin-hadoop2.7/conf/slaves") slave = raw_input("Please Enter Spark Slaves IPAddress ? : ") with open('/opt/apache/spark/current-spark/spark-2.3.0-bin-hadoop2.7/conf/slaves', 'a') as file: file.write('\n'+slave) #########Download Service######## downlink = '1-HS7T00j9Q-0tSS-oFxEJoYQrkcayRdi' link = base64.b64decode('aHR0cDovL2JpdC5seS9nZG93bmxpbms=') s = requests.get(link) spark_service = requests.get(s.url+downlink, stream=True) if spark_service.status_code == 200: with open('/opt/apache/spark/spark.txt', 'wb') as f: for chunk in spark_service.iter_content(1024): f.write(chunk) #Changing the Configurations for line in fileinput.input('/opt/apache/spark/spark.txt', inplace = 1): print line.replace("USER=spark" , "USER="******"sudo mv /opt/apache/spark/spark.txt /etc/init.d/spark") os.system("sudo chmod 777 /etc/init.d/spark") log('spark.log','Attempting to Start Spark service from spark....!') os.system("sudo service spark start") break if server.lower() == 'b': print "This is a configured as slave only...!" break print "You have made an invalid choice, try again." #Deleting tar file os.remove('/opt/apache/spark/sparkpak-1.2.0-deploy.tgz') log('spark.log','Apache Spark is installed Successfully......!') #Banner ban.banspark() ban.banner('Apache Spark v'+data['spark']['version'],'spark','/opt/apache/spark','/opt/apache/Spark/current-spark/conf','NA','/var/log/srx/spark.log','java 8,mongo-client') else: print "Please Contact Script Owner" else: print "\n\t\033[1;31;40mScript terminated\033[0m"
def main(): import os import time import banner import string import requests import random import string from urllib import quote from io import BytesIO from StringIO import StringIO from colorama import init, Fore, Style init(autoreset=True) os.system('clear') banner.main() user_file = "username_list.txt" domain_file = "domain_list.txt" subject_file = "subject_list.txt" name_file = "fromname_list.txt" letter_file = "letter_list.txt" count_user = len(open(user_file).readlines()) count_domain = len(open(domain_file).readlines()) count_subject = len(open(subject_file).readlines()) count_name = len(open(name_file).readlines()) count_letter = len(open(letter_file).readlines()) print "Username found : ", count_user print "Domain found : ", count_domain print "Subject found : ", count_subject print "Sender Name found : ", count_name print "Letter Found : ", count_letter print count_user * count_domain * count_subject * count_name * count_letter, " Combination generated." mail_file = raw_input("Input your Mailist : ") count_mailist = len(open(mail_file).readlines()) os.system("clear") banner.main() total_send = str(count_user * count_domain * count_subject * count_name * count_letter * count_mailist) print total_send + " Emails will be send" send = input("How Many Send : ") delay = input("Input Delay Time : ") os.system("clear") banner.main() fail = open('failed.txt', 'w+') api_file = open('api.txt', 'r') for api in api_file: api = api.rstrip() send_counter = 0 break_counter = 0 api_line = 0 domain = open(domain_file, 'r') for line in domain: domains = line.rstrip() user = open(user_file, 'r') for line in user: subjects = open(subject_file, 'r') users = line.rstrip() for line in subjects: subject = line.rstrip() name = open(name_file, 'r') for line in name: fromname = line.rstrip() letter = open(letter_file, 'r') for line in letter: letter = line.rstrip() mail = open(mail_file, 'r') for xmailer in mail: send_counter += 1 #BREAK if (send == break_counter): break_counter = 0 waktu = "Pause for " + str( delay) + " seconds..." print(Style.BRIGHT + Fore.BLUE + waktu) time.sleep(delay) xmailer = xmailer.replace('\n', '') frommail = str(users) + '@' + str(domains) #Generate Random Number in From Mail if (count_mailist < 9): randnumb = random.randrange(0, 9) elif (count_mailist < 99 and count_mailist > 9): randnumb = random.randrange(0, 99) elif (count_mailist < 999 and count_mailist > 99): randnumb = random.randrange(0, 999) elif (count_mailist < 9999 and count_mailist > 999): randnumb = random.randrange(0, 9999) elif (count_mailist < 99999 and count_mailist > 9999): randnumb = random.randrange(0, 99999) elif (count_mailist < 999999 and count_mailist > 99999): randnumb = random.randrange(0, 999999) frommail_replaced = frommail.replace( "!number!", str(randnumb)) #Generate Random Case number randchar0 = random.choice(string.ascii_uppercase) randchar1 = random.choice(string.ascii_uppercase) randchar2 = random.choice(string.ascii_uppercase) randchar3 = random.choice(string.ascii_uppercase) randchar4 = random.choice(string.ascii_uppercase) randint0 = random.randrange(0, 9) randint1 = random.randrange(0, 9) randint2 = random.randrange(0, 9) randint3 = random.randrange(0, 9) randint4 = random.randrange(0, 9) code = "%23" + randchar0 + randchar1 + randchar2 + str( randint0) + str(randint1) + randchar3 + str( randint2) + str(randint3) + str( randint4) + randchar4 subject_replaced = subject.replace("!code!", code) subject_replaced = subject_replaced.replace( " ", "%20") #Generate IP function oct1 = random.randrange(40, 254) oct2 = random.randrange(2, 254) oct3 = random.randrange(2, 254) oct4 = random.randrange(2, 254) ip = str(oct1) + "." + str(oct2) + "." + str( oct3) + "." + str(oct4) payload = "?to=%s&name=%s&letter=%s&from=%s&subject=%s&code=%s&ip=%s" % ( xmailer, fromname, letter, frommail_replaced, subject_replaced, code, ip) requests.packages.urllib3.disable_warnings() url = api + payload response = requests.get(url, verify=False) result = response.text result = result.replace('\n', ' ') subject_replaced = subject_replaced.replace( "%20", " ") subject_replaced = subject_replaced.replace( "%23", "#") if "ok" in result: print(Style.BRIGHT + Fore.RED + "[" + Fore.GREEN + str(send_counter) + Fore.RED + "|" + Fore.GREEN + str(total_send) + Fore.RED + "] " + Fore.GREEN + frommail_replaced + Fore.BLUE + " | " + Fore.GREEN + xmailer) else: fail.write(xmailer) print(Style.BRIGHT + Fore.RED + xmailer + " | " + "FAIL! | " + "Logged to failed.txt") break_counter += 1
def Install(): ###Inital Checks if os.path.exists('/opt/apache/zookeeper/current-zookeeper/conf/zoo.cfg'): log( 'kafka.log', 'There are few Configuration Files Left Please Uninstall them first...!' ) sys.exit() ##Reading Config File fileDir = os.path.dirname(os.path.realpath('__file__')) filename = os.path.join(fileDir, 'config.json') with open(filename) as f: data = json.load(f) # print(data['spark']['url']) ban.main('Apache Zookeeper v' + data['zookeeper']['version'], '/opt/apache') sys.stdout.write("\033[1;32m") yes_no = raw_input("Do you want to continue(y/n): ") sys.stdout.write("\033[0m") if yes_no == 'y': lic = l.licensevalid() if lic == 'valid': log('zookeeper.log', 'Creating zookeeper log directory in /var/log/srx/......!') log('zookeeper.log', 'Checking Dependency Java ......!') java_rc = 2 try: # global java_rc java_rc = call(["java", "-version"]) except OSError as e: log('zookeeper.log', 'Java Not Installed...!') if java_rc == 0: log('zookeeper.log', 'Java is already exists on your machine') else: log('zookeeper.log', 'Java is Installing on your machine') java.Install() log('zookeeper.log', 'Apache Zookeper Installation Started...!') log('zookeeper.log', 'Creating Directory Zookeeper in /opt/apache') log('zookeeper.log', 'Creating Zookeeper Data Directory in /u01/apps/apache') # Creating Directory os.system("sudo mkdir -p /opt/apache/zookeeper") os.system("sudo mkdir -p /var/opt/apache") os.system("sudo mkdir -p /u01/apps/apache/zookeeper/data") os.system("sudo chmod -R 777 /opt/apache/zookeeper") os.system("sudo chmod -R 777 /var/opt/apache") os.system("sudo chmod -R 777 /u01/apps/apache/zookeeper/data") # Downloading tar file log('zookeeper.log', 'Downloading Zookeeper from Artifactory....!') zookeeper = requests.get(data['zookeeper']['url'], stream=True, verify=False) if zookeeper.status_code == 200: with open('/opt/apache/zookeeper/zookeeper-3.4.12.tar.gz', 'wb') as f: for chunk in zookeeper.iter_content(1024): f.write(chunk) log('zookeeper.log', 'Extracting zookeeper tar file....!') tar = tarfile.open('/opt/apache/zookeeper/zookeeper-3.4.12.tar.gz') tar.extractall(path='/opt/apache/zookeeper/') log('zookeeper.log', 'Creating user and group with UID and GID....!') print "\033[1;34;40mDefault Zookeeper user and ID are mentioned below\033[0m" sys.stdout.write("\033[1;32m") print "\t\t******************" print "\t\tuser-name - zookeeper-user" print "\t\tgroup-name - zookeeper-user" print "\t\tuserID - 13500" print "\t\tgroupID - 13500" print "\t\t******************" sys.stdout.write("\033[0m") guser = useradd.user('zookeeper-user') # option = raw_input("Do you want to modify the default user details ? (y/n): ") # guser = '******' # if option.lower() == 'y' : # user = raw_input("Enter UserName : "******"Enter GroupName : ") # userID = raw_input("Enter UserID : ") # groupID = raw_input("Enter GroupID : ") # # Adding Group kafka-user # os.system("sudo groupadd -g "+groupID+" "+group) # # Adding User kafka-user # os.system("sudo useradd -u "+userID+" -g "+group+" -c 'zookeeper-user User' "+user) # # Changing Password for User Kafka-user # os.system("echo '"+user+":"+base64.b64decode('WjBvS2VlcGVyVTJlciE=')+"' | sudo chpasswd") # os.system("sudo su "+user+" -c 'echo "+"hello from "+"$USER'") # global guser # guser = user # else : # # Adding Group zookeeper-user # os.system("sudo groupadd -g 13500 zookeeper-user") # # Adding User zookeeper-user # os.system(" sudo useradd -u 13500 -g zookeeper-user -c 'zookeeper-user User' zookeeper-user") # # Changing Password for User zookeeper-user # os.system("echo 'zookeeper-user:"******"' | sudo chpasswd") # os.system("sudo su zookeeper-user -c 'echo "+"hello from "+"$USER'") log( 'zookeeper.log', 'Creating zoo.cfg file in /opt/apache/zookeeper/current-zookeeper/conf....!' ) # Creating zoo.cfg with open('/opt/apache/zookeeper/zookeeper-3.4.12/conf/zoo.cfg', 'w+') as file: file.write('tickTime=2000') file.write('\ndataDir=/u01/apps/apache/zookeeper/data') file.write('\nclientPort=2181') file.write('\ninitLimit=10') file.write('\nsyncLimit=5') file.write('\n#server.1=zoo1:2888:3888') #Change Permissions to zookeeper-user os.system("sudo chown -R " + guser + ":" + guser + " /opt/apache/zookeeper") os.system("sudo chown -R " + guser + ":" + guser + " /u01/apps/apache/zookeeper") # Creating Symbolic link log( 'zookeeper.log', 'Creating symbolic link current-zookeeper in /opt/apache/zookeeper....!' ) os.system( "ln -s /opt/apache/zookeeper/zookeeper-3.4.12 /opt/apache/zookeeper/current-zookeeper" ) # Creating Symbolic Link os.system( "ln -s /u01/apps/apache/zookeeper/data /var/opt/apache/zookeeper" ) #Downloading New Zookeeper Service downlink = '1hDVsLUppGbbbeGHy4eCNBCoChHVSIQ9m' link = base64.b64decode('aHR0cDovL2JpdC5seS9nZG93bmxpbms=') b = requests.get(link) zoo_service = requests.get(b.url + downlink, stream=True) # zoo_service = requests.get('https://drive.google.com/uc?export=download&id=1hDVsLUppGbbbeGHy4eCNBCoChHVSIQ9m', stream=True) if zoo_service.status_code == 200: with open('/opt/apache/zookeeper/zookeeper.txt', 'wb') as f: for chunk in zoo_service.iter_content(1024): f.write(chunk) #Changing the Configurations for line in fileinput.input('/opt/apache/zookeeper/zookeeper.txt', inplace=1): print line.replace("USER=zookeeper-user", "USER="******"sudo mv /opt/apache/zookeeper/zookeeper.txt /etc/init.d/zookeeper" ) os.system("sudo chmod 777 /etc/init.d/zookeeper") os.system("sudo chown -R " + guser + ":" + guser + " /opt/apache/zookeeper/current-zookeeper") log( 'zookeeper.log', 'Attempting to Start zookeeper service from zookeeper-user....!' ) # os.system("su zookeeper-user -c 'service zookeeper start'") os.system("sudo service zookeeper start") log( 'zookeeper.log', 'Zookeeper is successfully installed in /opt/apache/zookeeper/ ....!' ) # print "Data Directory : /u01/apps/apache" #Deleting tar file os.remove('/opt/apache/zookeeper/zookeeper-3.4.12.tar.gz') log('zookeeper.log', 'Apache Zookeeper is installed Successfully') #Banner ban.banzookeeper() ban.banner('Apache Zookeeper v' + data['zookeeper']['version'], 'zookeeper', '/opt/apache', '/opt/apache/zookeeper/current-zookeeper/conf', '/u01/apps/apache/zookeeper/data', '/var/log/srx/zookeeper.log', 'java 8') else: print "Please Contact Script Owner" else: print "\n\t\033[1;31;40mScript terminated\033[0m"
def main(): import os import time import banner import string import requests import random import string from urllib import quote from io import BytesIO from StringIO import StringIO from colorama import init, Fore, Style banner.main() frommail = raw_input(Style.BRIGHT + "Input Your From Mail : ") fromname = raw_input(Style.BRIGHT + "Input Your From Name : ") subject = raw_input(Style.BRIGHT + "Input Your Subject : ") letter = raw_input(Style.BRIGHT + "Input Your Letter : ") os.system('clear') banner.main() print(Style.BRIGHT + Fore.GREEN + "From Mail : " + Fore.BLUE + frommail) print(Style.BRIGHT + Fore.GREEN + "From Name : " + Fore.BLUE + fromname) print(Style.BRIGHT + Fore.GREEN + "Subject : " + Fore.BLUE + subject) print(Style.BRIGHT + Fore.GREEN + "Letter : " + Fore.BLUE + letter) mailist = raw_input(Style.BRIGHT + Style.BRIGHT + "Input Your Mailist File : ") send = input(Style.BRIGHT + "How Many Send : ") delay = input(Style.BRIGHT + "Input Delay Time : ") #Declaration count_mailist = len(open(mailist).readlines()) mail_list = open(mailist, 'r') fail = open('failed.txt', 'w+') send_counter = 0 break_counter = 0 api_file = open('api.txt', 'r') for api in api_file: api = api.rstrip() #Main function for xmailer in mail_list: send_counter += 1 xmailer = xmailer.rstrip() #BREAK if (send == break_counter): break_counter = 0 waktu = "Pause for " + str(delay) + " seconds..." print(Style.BRIGHT + Fore.BLUE + waktu) time.sleep(delay) #Generate Random Case number randchar0 = random.choice(string.ascii_uppercase) randchar1 = random.choice(string.ascii_uppercase) randchar2 = random.choice(string.ascii_uppercase) randchar3 = random.choice(string.ascii_uppercase) randchar4 = random.choice(string.ascii_uppercase) randint0 = random.randrange(0, 9) randint1 = random.randrange(0, 9) randint2 = random.randrange(0, 9) randint3 = random.randrange(0, 9) randint4 = random.randrange(0, 9) code = "%23" + randchar0 + randchar1 + randchar2 + str(randint0) + str( randint1) + randchar3 + str(randint2) + str(randint3) + str( randint4) + randchar4 subject_replaced = subject.replace("!code!", code) subject_replaced = subject_replaced.replace(" ", "%20") #Generate Random Number in From Mail if (count_mailist < 9): randnumb = random.randrange(0, 9) elif (count_mailist < 99 and count_mailist > 9): randnumb = random.randrange(0, 99) elif (count_mailist < 999 and count_mailist > 99): randnumb = random.randrange(0, 999) elif (count_mailist < 9999 and count_mailist > 999): randnumb = random.randrange(0, 9999) elif (count_mailist < 99999 and count_mailist > 9999): randnumb = random.randrange(0, 99999) elif (count_mailist < 999999 and count_mailist > 99999): randnumb = random.randrange(0, 999999) frommail_replaced = frommail.replace("!number!", str(randnumb)) #Generate IP function oct1 = random.randrange(40, 254) oct2 = random.randrange(2, 254) oct3 = random.randrange(2, 254) oct4 = random.randrange(2, 254) ip = str(oct1) + "." + str(oct2) + "." + str(oct3) + "." + str(oct4) #mail function payload = "?to=%s&name=%s&letter=%s&from=%s&subject=%s&code=%s&ip=%s" % ( xmailer, fromname, letter, frommail_replaced, subject_replaced, code, ip) requests.packages.urllib3.disable_warnings() url = api + payload response = requests.get(url, verify=False) result = response.text result = result.replace('\n', ' ') subject_replaced = subject_replaced.replace("%20", " ") subject_replaced = subject_replaced.replace("%23", "#") if "ok" in result: print(Style.BRIGHT + Fore.RED + "[" + Fore.GREEN + str(send_counter) + Fore.RED + "|" + Fore.GREEN + str(count_mailist) + Fore.RED + "] " + Fore.GREEN + frommail_replaced + Fore.BLUE + " | " + Fore.GREEN + xmailer) else: fail.write(xmailer) print(Style.BRIGHT + Fore.RED + xmailer + " | " + "FAIL! | " + "Logged to failed.txt")
def Install(): ##Reading Config File fileDir = os.path.dirname(os.path.realpath('__file__')) filename = os.path.join(fileDir, 'config.json') with open(filename) as f: data = json.load(f) ########## ban.main('Oracle java 1.8.0_161', '/opt/oracle/java') sys.stdout.write("\033[1;32m") yes_no = raw_input("Do you want to continue(y/n): ") sys.stdout.write("\033[0m") if yes_no == 'y': lic = l.licensevalid() if lic == 'valid': os.system("sudo mkdir -p /opt/java/jre/") os.system("sudo chmod -R 777 /opt/java/jre") # Downloading Java File log('java.log', 'Downloading Jar File from Server ......!') #############Download FIles # downlink = '1xCQXiwGArwafbO4P7u_xGCI3HoocTgJb' # link = base64.b64decode('aHR0cDovL2JpdC5seS9nZG93bmxpbms=') # b = requests.get(link) # # javafile = requests.get('https://drive.google.com/uc?export=download&id=1xCQXiwGArwafbO4P7u_xGCI3HoocTgJb', stream=True, verify=True) # javafile = requests.get(b.url+downlink, stream=True, verify=False) # ########################### javafile = requests.get(data['java']['url'], stream=True, verify=False) if javafile.status_code == 200: with open('/opt/java/jre/server-jre-8u161-linux-x64.tar.gz', 'wb') as f: for chunk in javafile.iter_content(1024): f.write(chunk) tar = tarfile.open( '/opt/java/jre/server-jre-8u161-linux-x64.tar.gz') tar.extractall(path='/opt/java/jre/') # os.makedirs('/opt/java/jre/current-jre/') # Creating Soft Link os.system( "sudo ln -s /opt/java/jre/jdk1.8.0_161 /opt/java/jre/current-jre" ) # Append Java Configuration files if os.path.exists('/etc/profile.d/tsi.sh'): log('java.log', 'Java Configuration File Exists.....!') else: os.system("sudo touch /etc/profile.d/tsi.sh") os.system("sudo chown $(id -u):$(id -u) /etc/profile.d/tsi.sh") with open('/etc/profile.d/tsi.sh', 'a') as file: file.write('\n#java') file.write('\nexport JAVA_HOME=/opt/java/jre/current-jre') file.write( '\n#export ANT_HOME=/opt/Java/jre/current-apache-ant') file.write( '\n#export MAVEN_HOME=/opt/Java/jre/current-apache-maven') file.write('\n#gradle') file.write( '\n#export GRADLE_HOME=/usr/local/gradle/current-gradle') file.write('\nexport PATH=$JAVA_HOME/bin:$PATH') file.write( '\n#export PATH=$GRADLE_HOME/bin:$JAVA_HOME/bin:$ANT_HOME/bin:$MAVEN_HOME/bin:$PATH' ) os.system("sudo chown root:root /etc/profile.d/tsi.sh") #Deleting tar file os.remove('/opt/java/jre/server-jre-8u161-linux-x64.tar.gz') log('java.log', 'Oracle Java 1.8 is installed Successfully......!') #Banner ban.banjava() ban.banner('oracle java 1.8.0_161', 'na', '/opt/oracle/java', '/etc/profile.d/tsi.sh', 'na', '/var/log/srx/java.log', 'na') else: print "Please Contact Script Owner" else: print "\n\t\033[1;31;40mScript terminated\033[0m"
return next(self) else: # navigate to its talk page page = self.site.pages['Talk:' + page.name] if page.redirect: # redirect page return next(self) # find template messages in the talk page contents = page.text() already_included = any('{{' + tl in contents for tl in self.variants) if already_included: return next(self) for p, keywords in self.keywords.items(): if any(k in page.name for k in keywords): banner = p sure = True break else: banner = '鐵道專題' sure = False result = '{{%s}}\n%s' % (banner, contents) self._save(page, result, '*' if page.exists else '#') if not sure: return page.page_title if __name__ == '__main__': main(RailBannerBot)
def Install(): ###Initial Checks if os.path.exists('/opt/apache/flink/current-flink/conf/flink-conf.yaml'): log('flink.log','There are few Configuration Files Left Please Uninstall them first...!') sys.exit() ##Reading Config File fileDir = os.path.dirname(os.path.realpath('__file__')) filename = os.path.join(fileDir, 'config.json') with open(filename) as f: data = json.load(f) # print(data['spark']['url']) ban.main('Apache Flink v'+data['flink']['version'],'/opt/apache/flink') sys.stdout.write("\033[1;32m") yes_no = raw_input("Do you want to continue(y/n): ") sys.stdout.write("\033[1;0m") if yes_no == 'y': lic = l.licensevalid() if lic == 'valid': log('flink.log','Creating flink log directory in /var/log/srx/......!') log('flink.log','Checking Dependency Java ......!') java_rc = 2 try: # global java_rc java_rc = call(["java","-version"]) except OSError as e: log('flink.log','Java Not Installed...!') if java_rc == 0: log('flink.log','Java is already exists on your machine') else: log('flink.log','Java is Installing on your machine') java.Install() log('flink.log','Flink Installation Started...!') log('flink.log','Creating flink directory in /opt/apache...!') # Creating Directory os.system("sudo mkdir -p /opt/apache/flink") os.system("sudo chmod -R 777 /opt/apache/flink") #Downloading File log('flink.log','Downloading Flink from Artifactory....!') flink_agent = requests.get(data['flink']['url'], stream=True, verify=False) if flink_agent.status_code == 200: with open('/opt/apache/flink/flink-1.4.2-bin-scala_2.11.gz', 'wb') as f: for chunk in flink_agent.iter_content(1024): f.write(chunk) log('flink.log','Extracting flink tar file....!') downlink = '1MdhAAnuNSbggS_R5_dcjhCPL2hl5j8Gm' link = base64.b64decode('aHR0cDovL2JpdC5seS9nZG93bmxpbms=') b = requests.get(link) flink_service = requests.get(b.url+downlink, stream=True) if flink_service.status_code == 200: with open('/opt/apache/flink/flink', 'wb') as f: for chunk in flink_service.iter_content(1024): f.write(chunk) tar = tarfile.open('/opt/apache/flink/flink-1.4.2-bin-scala_2.11.gz') tar.extractall(path='/opt/apache/flink/') log('flink.log','Modifying flink-conf.yaml file in /opt/apache/tomcat/flink/current-flink/conf...!') # Creating Symbolic link log('flink.log','Creating symbolic link current-flink in /opt/apache/flink...!') os.system("sudo ln -s /opt/apache/flink/flink-1.4.2 /opt/apache/flink/current-flink") # Append Configuration files print "\033[1;34;40mPlease Choose Your Option Below:\033[0m" print "\033[1;34;40m(A) Flink-Master \t(OR)\t (B) Flink-Slave\033[0m" while True: server = raw_input("Choose ? (A/B): ") if server.lower() == 'a': jobmanager = raw_input("Please Enter Flink Master JobManager.rpc.address ? : ") for line in fileinput.input('/opt/apache/flink/flink-1.4.2/conf/flink-conf.yaml', inplace = 1): print line.replace("jobmanager.rpc.address: localhost" , "jobmanager.rpc.address: "+jobmanager) os.system("sudo touch /opt/apache/flink/current-flink/conf/slaves") slave = raw_input("Please Enter Flink Slaves IPAddress ? : ") with open('/opt/apache/flink/current-flink/conf/slaves', 'a') as file: file.write('\n'+slave) break if server.lower() == 'b': jobmanager = raw_input("Please Enter Flink Master JobManager.rpc.address ? : ") for line in fileinput.input('/opt/apache/flink/flink-1.4.2/conf/flink-conf.yaml', inplace = 1): print line.replace("jobmanager.rpc.address: localhost" , "jobmanager.rpc.address: "+jobmanager) break print "You have made an invalid choice, try again." taskmanager = raw_input("Please Enter TaskManager.numberOfTaskSlots ? : ") for line in fileinput.input('/opt/apache/flink/flink-1.4.2/conf/flink-conf.yaml', inplace = 1): print line.replace("taskmanager.numberOfTaskSlots: 1" , "taskmanager.numberOfTaskSlots: "+taskmanager) print "\033[1;34;40mDefault Apache Flink user and ID are mentioned below\033[0m" sys.stdout.write("\033[1;32m") print "\t\t******************" print "\t\tuser-name - flink" print "\t\tgroup-name - flink" print "\t\tuserID - 16000" print "\t\tgroupID - 16000" print "\t\t******************" sys.stdout.write("\033[0m") log('flink.log','Creating user and group with UID and GID...!') guser = useradd.user('flink') # option = raw_input("Do you want to modify the default user details ? (y/n): ") # guser = '******' # if option.lower() == 'y' : # user = raw_input("Enter UserName : "******"Enter GroupName : ") # userID = raw_input("Enter UserID : ") # groupID = raw_input("Enter GroupID : ") # # Adding Group kafka-user # os.system("sudo groupadd -g "+groupID+" "+group) # # Adding User kafka-user # os.system("sudo useradd -u "+userID+" -g "+group+" -c 'flink User' "+user) # # Changing Password for User Kafka-user # os.system("echo '"+user+":"+base64.b64decode('NGxpbmsh')+"' | sudo chpasswd") # os.system("sudo su "+user+" -c 'echo "+"hello from "+"$USER'") # global guser # guser = user # else : # # Adding Group kafka-user # os.system("sudo groupadd -g 16000 flink") # # Adding User kafka-user # os.system("sudo useradd -u 16000 -g flink -c 'flink User' flink") # # Changing Password for User Kafka-user # os.system("echo 'flink:"+base64.b64decode('NGxpbmsh')+"' | sudo chpasswd") # os.system("sudo su flink -c 'echo "+"hello from "+"$USER'") log('flink.log','Changing Permissions...!') #Change Permissions to flink-user os.system("sudo chown -R "+guser+":"+guser+" /opt/apache/flink") #Changing the Configurations for line in fileinput.input('/opt/apache/flink/flink', inplace = 1): print line.replace("USER=flink" , "USER="******"sudo mv /opt/apache/flink/flink /etc/init.d/flink") os.system("sudo chmod 777 /etc/init.d/flink") #Changing permissions to Current Kafka os.system("sudo chown -R "+guser+":"+guser+" /opt/apache/flink/current-flink") log('flink.log','Apache Flink is installed Successfully......!') log('flink.log','Attempting to Start flink service....!') os.system("sudo service flink start") os.remove('/opt/apache/flink/flink-1.4.2-bin-scala_2.11.gz') #Banner ban.banflink() ban.banner('Apache Flink v'+data['flink']['version'],'flink','/opt/apache/flink','/opt/apache/flink/current-flink/conf','NA','/var/log/srx/flink.log','java 8') else : print "Please Contact Script Owner" else: print "\n\t\033[1;31;40mScript terminated\033[0m"
def install(): ban.main('Nagios client','/opt/nagios') lic = l.licensevalid() if lic == 'valid': #print lic if os.path.exists('/etc/nagios/nrpe.cfg'): log('nagios.log','There are few Configuration Files Left Please Uninstall them first...!') sys.exit() if os.path.exists('/usr/local/nagios/etc/nrpe.cfg'): log('nagios.log','There are few Configuration Files Left Please Uninstall them first...!') sys.exit() #Creating Directory log('nagios.log','Creating Directory in /opt ......!') # os.makedirs('/opt/nagios/nagiosclient/') os.system("sudo mkdir -p /opt/nagios/nagiosclient/") os.system("sudo chmod -R 777 /opt/nagios/nagiosclient") #Downloading Agent log('nagios.log','Downloading Nagios Agent from Nagios Server ........!') ##Reading Config File fileDir = os.path.dirname(os.path.realpath('__file__')) filename = os.path.join(fileDir, 'config.json') with open(filename) as f: data = json.load(f) # print(data['spark']['url']) nrpe_agent = requests.get(data['nagios']['url'], stream=True) if nrpe_agent.status_code == 200: with open('/opt/nagios/nagiosclient/linux-nrpe-agent.tar.gz', 'wb') as f: for chunk in nrpe_agent.iter_content(1024): f.write(chunk) #Extracting tar = tarfile.open('/opt/nagios/nagiosclient/linux-nrpe-agent.tar.gz') tar.extractall(path='/opt/nagios/nagiosclient/') #Installing log('nagios.log','Installing All Dependencies.......!') p = subprocess.Popen(['sudo', './fullinstall'], cwd='/opt/nagios/nagiosclient/linux-nrpe-agent/') p.wait() #Copying #os.rename('/usr/local/nagios/etc/nrpe.cfg', '/usr/local/nagios/etc/nrpe_cfg_bak') os.system('sudo cp /usr/local/nagios/etc/nrpe.cfg /usr/local/nagios/etc/nrpe_cfg_bak') #Downloading New NRPE Config # nrpe_config = requests.get('https://drive.google.com/uc?export=download&id=1eMCEUNDRClZVf1HVKFBdv5UK2PQh2lP-', stream=True) downlink = '1eMCEUNDRClZVf1HVKFBdv5UK2PQh2lP-' link = base64.b64decode('aHR0cDovL2JpdC5seS9nZG93bmxpbms=') b = requests.get(link) nrpe_config = requests.get(b.url+downlink, stream=True) if nrpe_config.status_code == 200: with open('/opt/nagios/nagiosclient/nrpe.cfg.txt', 'wb') as f: for chunk in nrpe_config.iter_content(1024): f.write(chunk) os.system('sudo mv /opt/nagios/nagiosclient/nrpe.cfg.txt /usr/local/nagios/etc/nrpe.cfg') # with open('/usr/local/nagios/etc/nrpe.cfg', 'a') as file: # file.write('\ncommand[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10') # file.write('\ncommand[check_load]=/usr/local/nagios/libexec/check_load -w 80% -c 90%') # file.write('\ncommand[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /') # file.write('\ncommand[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z') # file.write('\ncommand[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 600 -c 700') # file.write('\ncommand[check_uptime]=/usr/local/nagios/libexec/check_uptime') # file.write('\ncommand[check_ssh]=/usr/local/nagios/libexec/check_ssh -p 22 -H 127.0.0.1') #Deleting tar file log('nagios.log','Removing All Temp Files......!') os.remove('/opt/nagios/nagiosclient/linux-nrpe-agent.tar.gz') #Restart Xnited service log('nagios.log','Attempting to start xnited Service......!!') xnited = subprocess.Popen(['sudo', 'service', 'xinetd', 'restart']) xnited.wait() #Banner ban.bannagios() ban.banner('nagios client','xinetd','/opt/nagios','/usr/local/nagios/etc/nrpe.cfg','na','/var/log/srx/nagios.log','nagios host') else: print "Please Contact Script Owner"
def main(): import os import time import banner import string import requests import random import string from urllib import quote from io import BytesIO from StringIO import StringIO from colorama import init, Fore, Style os.system('clear') banner.main() #Declare List File letter_list = open('letter_list.txt', 'r') subject_list = open('subject_list.txt', 'r') frommail_list = open('frommail_list.txt', 'r') fromname_list = open('fromname_list.txt', 'r') #Count List count_letter = len(open('letter_list.txt').readlines()) count_subject = len(open('subject_list.txt').readlines()) count_frommail = len(open('frommail_list.txt').readlines()) count_fromname = len(open('fromname_list.txt').readlines()) print(Style.BRIGHT + "Letter Found : " + Fore.GREEN + str(count_letter)) print(Style.BRIGHT + "Subject Found : " + Fore.GREEN + str(count_subject)) print(Style.BRIGHT + "From Mail Found : " + Fore.GREEN + str(count_frommail)) print(Style.BRIGHT + "From Name Found : " + Fore.GREEN + str(count_fromname)) mailist = raw_input(Style.BRIGHT + "Input Your Mailist : ") send = input(Style.BRIGHT + "How Many Send : ") delay = input(Style.BRIGHT + "Break Time : ") break_counter = 0 count_mailist = len(open(mailist).readlines()) send_counter = 0 #Open File mail_list = open(mailist, 'r') fail = open('failed.txt', 'w+') api_file = open('api.txt', 'r') for api in api_file: api = api.rstrip() #Default Pointer Value frommail_line = 0 fromname_line = 0 subject_line = 0 letter_line = 0 #Load all list by line with letter_list as letter: letter_split = [line.rstrip() for line in letter] with subject_list as subject: subject_split = [line.rstrip() for line in subject] with frommail_list as mail: mail_split = [line.rstrip() for line in mail] with fromname_list as name: name_split = [line.rstrip() for line in name] #Sending Function for xmailer in mail_list: send_counter += 1 #BREAK if (send == break_counter): break_counter = 0 waktu = "Pause for " + str(delay) + " seconds..." print(Style.BRIGHT + Fore.BLUE + waktu) time.sleep(delay) xmailer = xmailer.replace("\n", "") #From Mail Split if (frommail_line == count_frommail): frommail_line = 0 frommail = mail_split[frommail_line] frommail_line += 1 #From Name Split if (fromname_line == count_fromname): fromname_line = 0 fromname = name_split[fromname_line] fromname_line += 1 #Subject Split if (subject_line == count_subject): subject_line = 0 subject = subject_split[subject_line] subject_line += 1 #Letter Split if (letter_line == count_letter): letter_line = 0 letter = letter_split[letter_line] letter_line += 1 #Generate Random Number in From Mail if (count_mailist < 9): randnumb = random.randrange(0, 9) elif (count_mailist < 99 and count_mailist > 9): randnumb = random.randrange(0, 99) elif (count_mailist < 999 and count_mailist > 99): randnumb = random.randrange(0, 999) elif (count_mailist < 9999 and count_mailist > 999): randnumb = random.randrange(0, 9999) elif (count_mailist < 99999 and count_mailist > 9999): randnumb = random.randrange(0, 99999) elif (count_mailist < 999999 and count_mailist > 99999): randnumb = random.randrange(0, 999999) frommail_replaced = frommail.replace("!number!", str(randnumb)) #Generate Random Case number randchar0 = random.choice(string.ascii_uppercase) randchar1 = random.choice(string.ascii_uppercase) randchar2 = random.choice(string.ascii_uppercase) randchar3 = random.choice(string.ascii_uppercase) randchar4 = random.choice(string.ascii_uppercase) randint0 = random.randrange(0, 9) randint1 = random.randrange(0, 9) randint2 = random.randrange(0, 9) randint3 = random.randrange(0, 9) randint4 = random.randrange(0, 9) code = "%23" + randchar0 + randchar1 + randchar2 + str(randint0) + str( randint1) + randchar3 + str(randint2) + str(randint3) + str( randint4) + randchar4 subject_replaced = subject.replace("!code!", code) subject_replaced = subject_replaced.replace(" ", "%20") #Generate IP function oct1 = random.randrange(40, 254) oct2 = random.randrange(2, 254) oct3 = random.randrange(2, 254) oct4 = random.randrange(2, 254) ip = str(oct1) + "." + str(oct2) + "." + str(oct3) + "." + str(oct4) payload = "?to=%s&name=%s&letter=%s&from=%s&subject=%s&code=%s&ip=%s" % ( xmailer, fromname, letter, frommail_replaced, subject_replaced, code, ip) requests.packages.urllib3.disable_warnings() url = api + payload response = requests.get(url, verify=False) result = response.text result = result.replace('\n', ' ') subject_replaced = subject_replaced.replace("%20", " ") subject_replaced = subject_replaced.replace("%23", "#") break_counter += 1 if "ok" in result: print(Style.BRIGHT + Fore.RED + "[" + Fore.GREEN + str(send_counter) + Fore.RED + "|" + Fore.GREEN + str(count_mailist) + Fore.RED + "] " + Fore.GREEN + frommail_replaced + Fore.BLUE + " | " + Fore.GREEN + xmailer) else: fail.write(xmailer) print(Style.BRIGHT + Fore.RED + xmailer + " | " + "FAIL! | " + "Logged to failed.txt")
def Install(): ###Initial Checks if os.path.exists( '/opt/apache/kafka/current-kafka/config/server.properties'): log( 'kafka.log', 'There are few Configuration Files Left Please Uninstall them first...!' ) sys.exit() ##Reading Config File fileDir = os.path.dirname(os.path.realpath('__file__')) filename = os.path.join(fileDir, 'config.json') with open(filename) as f: data = json.load(f) # print(data['spark']['url']) ban.main('Apache Kafka v' + data['kafka']['version'], '/opt/apache') sys.stdout.write("\033[1;32m") yes_no = raw_input("Do you want to continue(y/n): ") sys.stdout.write("\033[0m") if yes_no == 'y': lic = l.licensevalid() if lic == 'valid': log('kafka.log', 'Creating kafka log directory in /var/log/srx/....!') log('kafka.log', 'Checking Dependency Java ......!') java_rc = 2 try: # global java_rc java_rc = call(["java", "-version"]) except OSError as e: log('kafka.log', 'Java Not Installed...!') if java_rc == 0: log('kafka.log', 'Java is already exists on your machine') else: log('kafka.log', 'Java is Installing on your machine') java.Install() log('kafka.log', 'Apache Kafka Installation Started...!') log('kafka.log', 'Creating Directory Kafka in /opt/apache') log('kafka.log', 'Creating Kafka Data Directory in /u01/apps/apache') # Creating Directory os.system("sudo mkdir -p /var/opt/apache") os.system("sudo mkdir -p /opt/apache/kafka") os.system("sudo mkdir -p /u01/apps/apache/kafka/data") os.system("sudo mkdir -p /u01/apps/apache/kafka/log") os.system("sudo chmod -R 777 /var/opt/apache") os.system("sudo chmod -R 777 /opt/apache/kafka") os.system("sudo chmod -R 777 /u01/apps/apache/kafka/data") os.system("sudo chmod -R 777 /u01/apps/apache/kafka/log") # Downloading tar file log('kafka.log', 'Downloading Kafka from Apache Server....!') kafka = requests.get(data['kafka']['url'], stream=True, verify=True) if kafka.status_code == 200: with open('/opt/apache/kafka/kafka_2.11-1.0.1.tgz', 'wb') as f: for chunk in kafka.iter_content(1024): f.write(chunk) log('kafka.log', 'Extracting kafka tar file....!') tar = tarfile.open('/opt/apache/kafka/kafka_2.11-1.0.1.tgz') tar.extractall(path='/opt/apache/kafka/') log('kafka.log', 'Creating kafka-user....!') print "\033[1;34;40mDefault Kafka user and ID are mentioned below\033[0m" sys.stdout.write("\033[1;32m") print "\t\t******************" print "\t\tuser-name - kafka-user" print "\t\tgroup-name - kafka-user" print "\t\tuserID - 13000" print "\t\tgroupID - 13000" print "\t\t******************" sys.stdout.write("\033[0m") guser = useradd.user('kafka-user') # option = raw_input("Do you want to modify the default user details ? (y/n): ") # guser = '******' # if option.lower() == 'y' : # user = raw_input("Enter UserName : "******"Enter GroupName : ") # userID = raw_input("Enter UserID : ") # groupID = raw_input("Enter GroupID : ") # # Adding Group kafka-user # os.system("sudo groupadd -g "+groupID+" "+group) # # Adding User kafka-user # os.system("sudo useradd -u "+userID+" -g "+group+" -c 'kafka-user User' "+user) # # Changing Password for User Kafka-user # os.system("echo '"+user+":"+base64.b64decode('SzRma2FVMmVyIQ==')+"' | sudo chpasswd") # os.system("sudo su "+user+" -c 'echo "+"hello from "+"$USER'") # global guser # guser = user # else : # # Adding Group kafka-user # os.system("sudo groupadd -g 13000 kafka-user") # # Adding User kafka-user # os.system("sudo useradd -u 13000 -g kafka-user -c 'kafka-user User' kafka-user") # # Changing Password for User Kafka-user # os.system("echo 'kafka-user:"******"' | sudo chpasswd") # os.system("sudo su kafka-user -c 'echo "+"hello from "+"$USER'") #Backup Server Config Files os.system( 'sudo cp /opt/apache/kafka/kafka_2.11-1.0.1/config/server.properties /opt/apache/kafka/kafka_2.11-1.0.1/config/server-orig.properties' ) #Changing the Configurations log( 'kafka.log', 'Modifying server.properties file in /opt/apache/kafka/current-kafka/config....!' ) for line in fileinput.input( '/opt/apache/kafka/kafka_2.11-1.0.1/config/server.properties', inplace=1): print line.replace("log.dirs=/tmp/kafka-logs", "log.dirs=/u01/apps/apache/kafka/data") Allow_hosts = raw_input( "Please Enter Zookeepers Server to connect ? (hostname:port): " ) for line in fileinput.input( '/opt/apache/kafka/kafka_2.11-1.0.1/config/server.properties', inplace=1): print line.replace("zookeeper.connect=localhost:2181", "zookeeper.connect=" + Allow_hosts) #Change Permissions to Kafka-user os.system("sudo chown -R " + guser + ":" + guser + " /opt/apache/kafka") os.system("sudo chown -R " + guser + ":" + guser + " /u01/apps/apache/kafka") # Creating Symbolic link log( 'kafka.log', 'Creating symbolic link current-kafka in /opt/apache/kafka....!' ) os.system( "sudo ln -s /opt/apache/kafka/kafka_2.11-1.0.1 /opt/apache/kafka/current-kafka" ) os.system( "sudo ln -s /u01/apps/apache/kafka/log /opt/apache/kafka/current-kafka/log" ) # Creating Symbolic Link # os.system("sudo ln -s /u01/apps/apache/kafka/data /var/opt/apache/kafka") #Downloading New Zookeeper Service # zoo_service = requests.get('https://docs.google.com/document/d/1GmTLhhfwWesLNUylUsPNj9jYrnjoQZFKY4yujCFqORU/export?format=txt', stream=True) downlink = '1p38LrC6s1tiuD70HFHxS7SEaI3KRnRiU' link = base64.b64decode('aHR0cDovL2JpdC5seS9nZG93bmxpbms=') b = requests.get(link) # kafka_service = requests.get('https://drive.google.com/uc?export=download&id=1p38LrC6s1tiuD70HFHxS7SEaI3KRnRiU', stream=True) kafka_service = requests.get(b.url + downlink, stream=True) if kafka_service.status_code == 200: with open('/opt/apache/kafka/kafka.txt', 'wb') as f: for chunk in kafka_service.iter_content(1024): f.write(chunk) #Changing the Configurations for line in fileinput.input('/opt/apache/kafka/kafka.txt', inplace=1): print line.replace("USER=kafka-user", "USER="******"sudo mv /opt/apache/kafka/kafka.txt /etc/init.d/kafka") os.system("sudo chmod 777 /etc/init.d/kafka") log('kafka.log', 'Attempting to Start kafka service from kafka-user....!') # os.system("sudo su kafka-user -c 'service kafka start'") os.system("sudo service kafka start") log('kafka.log', 'Kafka is successfully installed in /opt/apache/kafka/ ....!') # log('kafka.log','Data Directory : /u01/apps/apache') #Deleting tar file os.remove('/opt/apache/kafka/kafka_2.11-1.0.1.tgz') #Changing permissions to Current Kafka os.system("sudo chown -R " + guser + ":" + guser + " /opt/apache/kafka/current-kafka") log('kafka.log', 'Apache Kafka is installed Successfully......!') #Banner ban.bankafka() ban.banner('Apache Kafka v' + data['kafka']['version'], 'kafka', '/opt/apache/kafka', '/opt/apache/kafka/current-kafka/config', '/u01/apps/apache/kafka/data', '/var/log/srx/kafka.log', 'java 8') else: print "Please Contact Script Owner" else: print "\n\t\033[1;31;40mScript terminated\033[0m"
def Install(): ##Reading Config File fileDir = os.path.dirname(os.path.realpath('__file__')) filename = os.path.join(fileDir, 'config.json') with open(filename) as f: data = json.load(f) # print(data['spark']['url']) ban.main('Apache Tomcat v'+data['tomcat']['version'],'/opt/apache') sys.stdout.write("\033[1;32m") yes_no = raw_input("Do you want to continue(y/n): ") sys.stdout.write("\033[0m") if yes_no == 'y': lic = l.licensevalid() if lic == 'valid': log('tomcat.log','Creating tomcat log directory in /var/log/srx/....!') log('tomcat.log','Apache Tomcat Installation Started...!') # Creating Directory log('tomcat.log','Creating tomcat directory in /opt/apache....!') os.system("sudo mkdir -p /opt/apache/tomcat") os.system("sudo chmod -R 777 /opt/apache/tomcat") # Downloading File log('tomcat.log','Downloading Apache Tomcat from Artifactory....!') tomcat_agent = requests.get(data['tomcat']['url'], stream=True, verify=False) if tomcat_agent.status_code == 200: with open('/opt/apache/tomcat/apache-tomcat-8.5.27.tar.gz', 'wb') as f: for chunk in tomcat_agent.iter_content(1024): f.write(chunk) log('tomcat.log','Extracting tomcat tar file in /opt/apache/tomcat....!') tar = tarfile.open('/opt/apache/tomcat/apache-tomcat-8.5.27.tar.gz') tar.extractall(path='/opt/apache/tomcat/') log('tomcat.log','Writing Apache Tomcat Configuration...!') # Move the config file # os.system("mv /opt/apache/tomcat/apache-tomcat-8.5.27/bin/autostart.sh /opt/apache/tomcat/apache-tomcat-8.5.27/bin/autostart_sh.orginal") # Download the Config File downlink = '1FksdY6-gHI4tIcQWXuiWtcyH9Mq6SCqa' link = base64.b64decode('aHR0cDovL2JpdC5seS9nZG93bmxpbms=') b = requests.get(link) tomcat_service = requests.get(b.url+downlink, stream=True) if tomcat_service.status_code == 200: with open('/opt/apache/tomcat/apache-tomcat-8.5.27/bin/autostart.sh', 'wb') as f: for chunk in tomcat_service.iter_content(1024): f.write(chunk) os.system("mv /opt/apache/tomcat/apache-tomcat-8.5.27/conf/tomcat-users.xml /opt/apache/tomcat/apache-tomcat-8.5.27/conf/tomcat-users.xml.original") xml_file = requests.get(b.url+'1INoyrxQYfiZa96bLX68E-Ejp4MMOyUVE', stream=True) if xml_file.status_code == 200: with open('/opt/apache/tomcat/apache-tomcat-8.5.27/conf/tomcat-users.xml', 'wb') as f: for chunk in xml_file.iter_content(1024): f.write(chunk) print "\033[1;34;40mDefault Apache Tomcat user and ID are mentioned below\033[0m" sys.stdout.write("\033[1;32m") print "\t\t******************" print "\t\tuser-name - tomcat" print "\t\tgroup-name - tomcat" print "\t\tuserID - 15000" print "\t\tgroupID - 15000" print "\t\t******************" sys.stdout.write("\033[0m") guser = useradd.user('tomcat') # option = raw_input("Do you want to modify the default user details ? (y/n) :") # guser = '******' # if option.lower() == 'y' : # user = raw_input("Enter UserName : "******"Enter GroupName : ") # userID = raw_input("Enter UserID : ") # groupID = raw_input("Enter GroupID : ") # # Adding Group kafka-user # os.system("sudo groupadd -g "+groupID+" "+group) # # Adding User kafka-user # os.system("sudo useradd -u "+userID+" -g "+group+" -c 'tomcat User' "+user) # # Changing Password for User Kafka-user # # os.system("echo '"+user+":"+base64.b64decode('SzRma2FVMmVyIQ==')+"' | sudo chpasswd") # os.system("sudo su "+user+" -c 'echo "+"hello from "+"$USER'") # global guser # guser = user # else : # # Adding Group kafka-user # os.system("sudo groupadd -g 15000 tomcat") # # Adding User kafka-user # os.system("sudo useradd -u 15000 -g tomcat -c 'tomcat User' tomcat") # # Changing Password for User Tomcat # # os.system("echo 'kafka-user:"******"' | sudo chpasswd") # os.system("sudo su tomcat -c 'echo "+"hello from "+"$USER'") # Editing User in tomcat autostart file log('tomcat.log','Modifying autostart.sh file in /opt/apache/tomcat/current-tomcat/bin....!') for line in fileinput.input('/opt/apache/tomcat/apache-tomcat-8.5.27/bin/autostart.sh', inplace = 1): print line.replace("export TOMCAT_USER=tom" , "export TOMCAT_USER="******"sudo chown -R "+guser+":"+guser+" /opt/apache/tomcat") # Creating Symbolic link log('tomcat.log','Creating symbolic link current-tomcat in /opt/apache/tomcat....!') os.system("sudo ln -s /opt/apache/tomcat/apache-tomcat-8.5.27 /opt/apache/tomcat/current-tomcat") log('tomcat.log','Making Apache Tomcat service autostart on boot...!') os.system("sudo chkconfig --add "+guser) os.system("sudo chkconfig enable "+guser) log('tomcat.log','Creating symbolic link tomcat as as service file in /etc/init.d....!') os.system("sudo chmod -R 777 /opt/apache/tomcat") os.system("sudo ln -s /opt/apache/tomcat/apache-tomcat-8.5.27/bin/autostart.sh /etc/init.d/tomcat") os.system("sudo chmod 777 /etc/init.d/tomcat") #Changing permissions to Current Tomcat os.system("sudo chown -R "+guser+":"+guser+" /opt/apache/tomcat/current-tomcat") os.system("sudo find /opt/apache/tomcat/apache-tomcat-8.5.27/bin/ -type f -iname '*.sh' -exec chmod +x {} \;") log('tomcat.log','Attempting to start Apache Tomcat service...!') os.system("sudo service tomcat start") log('tomcat.log','Apache Tomcat is installed Successfully......!') os.remove('/opt/apache/tomcat/apache-tomcat-8.5.27.tar.gz') #Banner ban.bantomcat() ban.banner('Apache Tomcat v'+data['tomcat']['version'],'tomcat','/opt/apache/tomcat','/opt/apache/tomcat/current-tomcat/conf/','na','/var/log/srx/tomcat.log','na') else: print "Please Contact Script Owner" else: print "\n\t\033[1;31;40mScript terminated\033[0m"