level0.py 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-"
  3. """
  4. NOINIW 2051 - by psy (epsylon@riseup.net)
  5. """
  6. import time
  7. import pygame
  8. import pygameMenu
  9. import data.menu
  10. import os
  11. import random
  12. from data.levels.level0.level0_1 import level0_shell as level0_1
  13. translations_level0_intro = "data/translations/level0.txt"
  14. NETWORK_DOMAIN = "X/UNd.NeT" # name for level [0-10] layer network
  15. NETWORK_MACHINE_NUMBER = None
  16. COLOR_RED = (255 ,0 , 0)
  17. COLOR_WHITE = (255, 255, 255)
  18. COLOR_BLACK = (0, 0, 0)
  19. COLOR_GRAY = (50, 50, 50)
  20. COLOR_GREEN = (0, 160, 0)
  21. COLOR_BLUE = (0, 0, 228)
  22. COLOR_YELLOW = (255, 255, 0)
  23. COLOR_ORANGE = (242, 91, 37)
  24. pygame.font.init()
  25. font_type = "data/fonts/Vera.ttf"
  26. font_type_bold = "data/fonts/VeraBold.ttf"
  27. font_size = 18
  28. font_banner_size = 16
  29. fontObj = pygame.font.Font(font_type, font_size) # create font object for menu
  30. fontBANNERObj = pygame.font.Font(font_type, font_banner_size) # create font BANNER object
  31. profile_username_path = "data/profile/username.txt"
  32. PROFILE_PATH = "data/profile"
  33. DEFAULT_USER_NAME = "ANONYMOUS"
  34. def load_level0_translations(set_language):
  35. if set_language == "0": # English
  36. language_translation = "ENGLISH"
  37. else: # Spanish
  38. language_translation = "SPANISH"
  39. f = open(translations_level0_intro, "r")
  40. translations = f.readlines()
  41. f.close()
  42. for lost in translations:
  43. lost = lost.replace("\n", "")
  44. if language_translation in str(lost):
  45. if "SERVICE" in lost:
  46. TRANS_SERVICE = str(lost.split(":")[1])
  47. if "USERNAME" in lost:
  48. TRANS_USERNAME = str(lost.split(":")[1])
  49. if "PASSWORD" in lost:
  50. TRANS_PASSWORD = str(lost.split(":")[1])
  51. if "TRY" in lost:
  52. TRANS_ACCESS = str(lost.split(":")[1])
  53. if "LOGINGUESTGRANTED" in lost:
  54. GUEST_ACCESS_GRANTED = str(lost.split(":")[1])
  55. if "LOGINDENIED" in lost:
  56. DENIED_ACCESS = str(lost.split(":")[1])
  57. return TRANS_SERVICE, TRANS_USERNAME, TRANS_PASSWORD, TRANS_ACCESS, GUEST_ACCESS_GRANTED, DENIED_ACCESS
  58. def extract_username():
  59. if os.path.exists(profile_username_path) == True:
  60. f = open(profile_username_path, "r")
  61. USERNAME = str(f.read().replace("\n",""))
  62. f.close()
  63. else: # create default profile
  64. if not os.path.exists(PROFILE_PATH): # create new profile folder
  65. os.mkdir(PROFILE_PATH)
  66. f = open(profile_username_path, "w")
  67. f.write(DEFAULT_USER_NAME) # default username
  68. f.close()
  69. USERNAME = DEFAULT_USER_NAME
  70. return USERNAME
  71. def extract_web_banner_text():
  72. WEB_BANNER_TEXT = "PUBLIC [WEBSITE] for [OPEN-PROXY] MAC: ["+str(NETWORK_MACHINE_NUMBER)+"]" # default web banner for OPEN-PROXY
  73. return WEB_BANNER_TEXT
  74. def extract_ssh_banner_text():
  75. SSH_BANNER_TEXT = "SSH-ProxyVPN-32.1 (by ChaOsCL4n) for [OPEN-PROXY] MAC: ["+str(NETWORK_MACHINE_NUMBER)+"]" # default SSH banner for OPEN-PROXY
  76. return SSH_BANNER_TEXT
  77. def update_menu_service(value, enabled):
  78. banner_rect = pygame.draw.rect(login_surface,COLOR_BLACK,(WINDOW[0]/10-105,WINDOW[1]/5+120,WINDOW[0]+100,WINDOW[1])) # machine BANNER back box
  79. if enabled == "WEB":
  80. WEB_BANNER_TEXT = extract_web_banner_text()
  81. banner_surface = fontBANNERObj.render(WEB_BANNER_TEXT, True, COLOR_BLUE)
  82. banner_rect.center = (WINDOW[0]-500, WINDOW[1]-200)
  83. login_surface.blit(banner_surface, banner_rect)
  84. if login_menu.get_widget("user_name") and login_menu.get_widget("user_password"):
  85. login(login_surface, COLOR_WHITE, COLOR_BLACK, COLOR_BLUE, COLOR_GRAY, COLOR_YELLOW, COLOR_ORANGE, WINDOW, LANGUAGE)
  86. elif enabled == "SSH":
  87. SSH_BANNER_TEXT = extract_ssh_banner_text()
  88. banner_surface = fontBANNERObj.render(SSH_BANNER_TEXT, True, COLOR_BLUE)
  89. banner_rect.center = (WINDOW[0]-500, WINDOW[1]-200)
  90. login_surface.blit(banner_surface, banner_rect)
  91. if not login_menu.get_widget("user_name") and not login_menu.get_widget("user_password"):
  92. TRANS_SERVICE, TRANS_USERNAME, TRANS_PASSWORD, TRANS_ACCESS, GUEST_ACCESS_GRANTED, DENIED_ACCESS = load_level0_translations(LANGUAGE)
  93. USERNAME = extract_username()
  94. login_menu.add_text_input("* "+str(TRANS_USERNAME)+": ",
  95. default='',
  96. maxchar=12,
  97. textinput_id='user_name',
  98. input_underline='')
  99. login_menu.add_text_input("* "+str(TRANS_PASSWORD)+": ",
  100. default='',
  101. maxchar=12,
  102. password=True,
  103. textinput_id='user_password',
  104. input_underline='')
  105. def try_login():
  106. data = login_menu.get_input_data()
  107. if str(data['user_name']) == str(NETWORK_MACHINE_NUMBER): # guest access
  108. msg = str(GUEST_ACCESS_GRANTED) # -guest(whatever-pass) granted- on this level
  109. ACCESS_LEVEL = "guest"
  110. else: # rest is denied
  111. msg = str(DENIED_ACCESS)
  112. ACCESS_LEVEL = False
  113. show_login_msg(msg, login_surface, COLOR_WHITE, COLOR_BLACK, COLOR_BLUE, COLOR_GRAY, COLOR_YELLOW, COLOR_ORANGE, WINDOW, LANGUAGE, ACCESS_LEVEL, NETWORK_MACHINE_NUMBER)
  114. login_menu.add_option("-> "+str(TRANS_ACCESS)+" <-", try_login)
  115. def show_login_msg(msg, surface, COLOR_WHITE, COLOR_BLACK, COLOR_BLUE, COLOR_GRAY, COLOR_YELLOW, COLOR_ORANGE, WINDOW_SIZE, set_language, ACCESS_LEVEL, NETWORK_MACHINE_NUMBER):
  116. if ACCESS_LEVEL == "guest": # granted!
  117. login_return_text = fontObj.render('[ '+str(msg)+'! ]', True, COLOR_GREEN) # create login GREEN back msg
  118. else: # denied!
  119. login_return_text = fontObj.render('[ '+str(msg)+'! ]', True, COLOR_RED) # create login RED back msg
  120. login_surface.blit(login_return_text, dest=(WINDOW_SIZE[0]/2-100, WINDOW_SIZE[1]/4+42)) # load msg into surface
  121. while True:
  122. pygame.display.flip()
  123. if ACCESS_LEVEL == "guest": # GO FOR NEXT LEVEL: 0-1
  124. time.sleep(3) # wait for shell
  125. start_level0_1(surface, WINDOW_SIZE, set_language, ACCESS_LEVEL, NETWORK_MACHINE_NUMBER, COLOR_WHITE, COLOR_BLACK, COLOR_BLUE, COLOR_GRAY, COLOR_YELLOW, COLOR_ORANGE, COLOR_GREEN)
  126. else: # back to 'login' menu
  127. time.sleep(5) # wait until re-login
  128. pygame.draw.rect(surface,COLOR_BLACK,(WINDOW_SIZE[1]/10-75,WINDOW_SIZE[1]/2-154,WINDOW_SIZE[0],30)) # used to hide login returned msg
  129. login(surface, COLOR_WHITE, COLOR_BLACK, COLOR_BLUE, COLOR_GRAY, COLOR_YELLOW, COLOR_ORANGE, WINDOW_SIZE, set_language)
  130. def login(surface, COLOR_WHITE, COLOR_BLACK, COLOR_BLUE, COLOR_GRAY, COLOR_YELLOW, COLOR_ORANGE, WINDOW_SIZE, set_language):
  131. global login_menu
  132. global login_surface
  133. global LANGUAGE
  134. global WINDOW
  135. global NETWORK_MACHINE_NUMBER
  136. WINDOW = WINDOW_SIZE
  137. LANGUAGE = set_language
  138. login_surface = surface
  139. pygame.draw.rect(surface,COLOR_BLACK,(WINDOW_SIZE[1]/10-75,WINDOW_SIZE[1]/2-154,WINDOW_SIZE[0],30)) # used to hide login returned msg
  140. TRANS_SERVICE, TRANS_USERNAME, TRANS_PASSWORD, TRANS_ACCESS, GUEST_ACCESS_GRANTED, DENIED_ACCESS = load_level0_translations(set_language)
  141. USERNAME = extract_username()
  142. if not NETWORK_MACHINE_NUMBER:
  143. NETWORK_MACHINE_NUMBER = random.randrange(1111, 9999) # generate random proxy number (between proxy reserved directions)
  144. login_menu = pygameMenu.Menu(surface, # level 0: "login" menu
  145. bgfun=data.menu.level0_login_background,
  146. color_selected=COLOR_YELLOW,
  147. font=font_type,
  148. font_color=COLOR_WHITE,
  149. font_size=18,
  150. font_size_title=35,
  151. menu_alpha=100,
  152. menu_color=COLOR_BLACK,
  153. menu_height=220,
  154. menu_width=int(WINDOW_SIZE[0]),
  155. onclose=data.menu.main, # back to main menu
  156. option_shadow=False,
  157. title="["+str(NETWORK_DOMAIN)+"]>[MAC:"+str(NETWORK_MACHINE_NUMBER)+"]>",
  158. menu_color_title=COLOR_GREEN,
  159. widget_alignment=pygameMenu.locals.ALIGN_LEFT,
  160. window_height=220,
  161. window_width=int(WINDOW_SIZE[0])
  162. )
  163. login_menu.add_selector('* '+str(TRANS_SERVICE),
  164. [('SSH', 'SSH'),
  165. ('WEB', 'WEB')],
  166. selector_id='service',
  167. onchange=update_menu_service,
  168. default=1)
  169. if login_menu.get_widget("user_name"):
  170. login_menu.get_widget("user_name").clear()
  171. if login_menu.get_widget("user_password"):
  172. login_menu.get_widget("user_password").clear()
  173. while True:
  174. login_menu.mainloop()
  175. def start_level0_1(surface, WINDOW_SIZE, set_language, ACCESS_LEVEL, NETWORK_MACHINE_NUMBER, COLOR_WHITE, COLOR_BLACK, COLOR_BLUE, COLOR_GRAY, COLOR_YELLOW, COLOR_ORANGE, COLOR_GREEN):
  176. time.sleep(5)
  177. level0_1(surface, WINDOW_SIZE, set_language, ACCESS_LEVEL, NETWORK_MACHINE_NUMBER, COLOR_WHITE, COLOR_BLACK, COLOR_BLUE, COLOR_GRAY, COLOR_YELLOW, COLOR_ORANGE, COLOR_GREEN)