shell.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-"
  3. """
  4. NOINIW 2051 - by psy (epsylon@riseup.net)
  5. """
  6. import time
  7. from data.levels.level0.level0_2 import login as level0_2
  8. VERSION = "y-shell v0.1 'NoWb1e sh3ll' (23042020)"
  9. def getPWD(current_position): # pwd
  10. current_path = current_position
  11. if not current_path.startswith("/"):
  12. current_path = "/"+current_path
  13. return current_path
  14. def changePWD(mac_root, current_position, files_tree, direc): # cd+dir
  15. current_path = None
  16. for k in files_tree.keys():
  17. if direc in k:
  18. current_path = direc
  19. else:
  20. if direc == mac_root:
  21. current_path = mac_root
  22. if not current_path:
  23. current_path = current_position
  24. if not current_path.startswith("/"):
  25. current_path = "/"+current_path
  26. return current_path
  27. def getList(mac_root, current_position, files_tree): # ls/dir
  28. for k,v in files_tree.items():
  29. if len(current_position) > 2 and current_position in k: # not /
  30. listed_files = v
  31. else:
  32. if current_position == mac_root:
  33. listed_files = files_tree.keys()
  34. return listed_files
  35. def getId(ACCESS_LEVEL): # id/whois
  36. user_id = ACCESS_LEVEL
  37. return user_id
  38. def getHostName(NETWORK_MACHINE_NUMBER): # hostname
  39. hostname = NETWORK_MACHINE_NUMBER
  40. return hostname
  41. def getUname(mac_uname): # uname
  42. uname = mac_uname
  43. return uname
  44. def getCdUP(mac_root, current_position): # cd_up
  45. current_path = mac_root
  46. return current_path
  47. def getCAT(CURRENT_LANGUAGE, level, current_position, files_tree, file_target): # cat
  48. file_text = None
  49. final_text = []
  50. final_file_text = []
  51. for k,v in files_tree.items():
  52. if current_position in str(k):
  53. for f in v:
  54. if file_target == str(f).replace(" ",""):
  55. if str(f.replace(" ","")) == "FAQ.pdf": # level_0: fake FAQ.pdf file
  56. f = "FAQ.txt"
  57. CURRENT_LANGUAGE = -1
  58. if str(f.replace(" ","")) == "last_connections.log": # level_0: last connection logs
  59. f = "last_connections.txt"
  60. CURRENT_LANGUAGE = -1
  61. m = open("data/levels/level"+str(level)+"/data/"+str(f.replace(" ","")), "r")
  62. file_text = m.readlines()
  63. for line in file_text:
  64. if CURRENT_LANGUAGE == "0": # ENGLISH
  65. if line.startswith("ENGLISH"):
  66. final_text.append(str(line.split(":")[1]))
  67. elif CURRENT_LANGUAGE == "1": # SPANISH
  68. if line.startswith("SPANISH"):
  69. final_text.append(str(line.split(":")[1]))
  70. else: # NOT TRANSLATION REQUIRED (CURRENT_LANGUAGE= -1)
  71. final_text.append(str(line))
  72. m.close()
  73. if file_text == None:
  74. file_text = 'y-shell: file not found: "'+str(file_target)+'"'
  75. final_file_text.append(str(file_text))
  76. else:
  77. for text in final_text:
  78. final_file_text.append(str(text).replace("\n", ""))
  79. return final_file_text
  80. def installProgram(current_position, files_tree, file_target): # install program
  81. file_text = None
  82. for k,v in files_tree.items():
  83. if current_position in str(k):
  84. for f in v:
  85. if file_target == str(f).replace(" ","") and file_target.endswith(".app"):
  86. file_text = "y-shell: program '"+str(file_target)+"' has been installed!"
  87. if not file_text:
  88. file_text = "y-shell: program '"+str(file_target)+"' not valid!"
  89. return file_text
  90. def connectMac(current_position, macs_tree, file_target, surface, WINDOW_SIZE, CURRENT_LANGUAGE): # connect to machine
  91. file_text = None
  92. for v in macs_tree:
  93. if file_target == str(v).replace("\n",""):
  94. file_text = "y-shell: connecting to: '"+str(file_target)+"' ..."
  95. time.sleep(3) # wait for login
  96. NETWORK_MACHINE_NUMBER = file_target
  97. level0_2(surface, WINDOW_SIZE, CURRENT_LANGUAGE, NETWORK_MACHINE_NUMBER) # go for level 2
  98. if not file_text:
  99. file_text = "y-shell: connection to: '"+str(file_target)+"' failed!"
  100. return file_text