level0_2.py 8.6 KB

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