Advertisement
pepeknamornik

Server Manager P7

Mar 19th, 2020 (edited)
837
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.86 KB | None | 0 0
  1. local verze = "22.0222.R1"
  2. local anim = 0.1
  3. local RamCesta = ("/C/system/RAM/SM")
  4. local w, h = term.getSize()
  5. local nRul = {}
  6. local pRul = {}
  7. local iRul = {}
  8. local bRul = {}
  9. ----------------------------------------------------
  10. local f=fs.open("/C/system/RAM/user","r")
  11. user=f.readLine()
  12. pass=f.readLine()
  13. Fname=f.readLine()
  14. Lname=f.readLine()
  15. f.close()
  16.  
  17. local function Barvy()
  18.     if fs.exists ("/C/system/Users/"..user.."/.Registry/colors") then
  19.     local data = fs.open("/C/system/Users/"..user.."/.Registry/colors", "r")
  20.     BarPoz = tonumber(data.readLine())
  21.     BarTxt = tonumber(data.readLine())
  22.     data.close()
  23.     end
  24.     if BarPoz == nil or BarTxt == nil then BarPoz = 2048 BarTxt = 1 end
  25. end
  26.  
  27. function ukonceni ()
  28.     fs.delete (RamCesta)
  29.     os.exit()
  30. end
  31.  
  32. function cbarva()
  33. lista.setTextColor(colors.black)
  34. lista.setBackgroundColor(colors.gray)
  35. end
  36.  
  37. function defaultvalue()
  38. end
  39.  
  40. function start()
  41. defaultvalue()
  42. Barvy()
  43. local myWindow = window.create(term.current(),w/2-11,h/2-5,25,9)
  44. myWindow.setBackgroundColor(colors.lightBlue)
  45. myWindow.clear()
  46. myWindow.setCursorPos (7, 5)
  47. myWindow.write"Server Manager"
  48. myWindow.setCursorPos (1, 1)
  49. myWindow.write"Pepek@Soft"
  50. myWindow.setCursorPos (22, 9)
  51. myWindow.write"2020"
  52. sleep(1)
  53. menu()
  54. end
  55.  
  56. function plocha()
  57. w, h = term.getSize()
  58. paintutils.drawLine(1, 1, w, 1, BarPoz)
  59. paintutils.drawPixel (w,1, colors.red)
  60. term.setCursorPos (w,1)
  61. term.setTextColor(BarTxt)
  62. write "×"
  63. barW = window.create(term.current(),1,2,w,1)
  64. barW.setBackgroundColor(colors.gray)
  65. barW.clear()
  66. barW.setTextColor(colors.white)
  67. barW.setCursorPos(2,1)
  68. barW.write"Server Manager >"
  69. pozadi = window.create(term.current(),13,3,w,h-2)
  70. pozadi.setBackgroundColor(colors.white)
  71. pozadi.setTextColor(colors.black)
  72. pozadi.clear()
  73. lista = window.create(term.current(),1,3,12,h-2)
  74. lista.setBackgroundColor(BarPoz)
  75. lista.setTextColor(BarTxt)
  76. lista.clear()
  77. lista.setCursorPos(2,3)
  78. lista.write"Dashboard"
  79. lista.setCursorPos(2,5)
  80. lista.write"Rules"
  81. lista.setCursorPos(2,7)
  82. lista.write"Services"
  83. lista.setCursorPos(2,h-2)
  84. lista.setTextColor(colors.white)
  85. lista.write("Pepek@Soft")
  86. term.setBackgroundColor(colors.lightGray)
  87. end
  88. -----------------------------------------------------------------------------
  89. local page = "Fdb"
  90.  
  91. function Fdb()
  92. barW.setCursorPos(19,1)
  93. barW.write"Dashboard"
  94. pozadi.setCursorPos(2,2)
  95. pozadi.write"Instaled Version:"
  96. pozadi.setCursorPos(2,4)
  97. pozadi.write"BootLoader:"
  98. pozadi.setCursorPos(2,5)
  99. pozadi.write"Explorer:"
  100. pozadi.setCursorPos(2,6)
  101. pozadi.write"Server manager:"
  102. pozadi.setCursorPos(2,8)
  103. pozadi.write"Logged in user:"
  104. pozadi.setCursorPos(2,9)
  105. pozadi.write"Instaled rules:"
  106. pozadi.setCursorPos(2,10)
  107. pozadi.write"Active services:"
  108. pozadi.setCursorPos(2,11)
  109. pozadi.write"Computer ID:"
  110. pozadi.setCursorPos(2,12)
  111. pozadi.write"Computer name:"
  112. pozadi.setCursorPos(2,13)
  113. pozadi.write"Primary modem:"
  114.  
  115. pozadi.setTextColor(colors.lightGray)
  116.     if fs.exists("/C/system/RAM/versions.tmp") then
  117.         local x = fs.open("/C/system/RAM/versions.tmp","r")
  118.         pozadi.setCursorPos(19,4)
  119.         pozadi.write(x.readLine())
  120.         pozadi.setCursorPos(19,5)
  121.         pozadi.write(x.readLine())
  122.         x.close()
  123.     end
  124.         pozadi.setCursorPos(19,6)
  125.         pozadi.write(verze)
  126.         pozadi.setCursorPos(19,8)
  127.         pozadi.write(user)
  128.         if fs.exists("/C/system/server/rules/") then cRul = fs.list("/C/system/server/rules/") cRul = #cRul else cRul = 0 end
  129.         pozadi.setCursorPos(19,9)
  130.         pozadi.write(cRul)
  131.         if fs.exists("/C/service/") then cRul = fs.list("/C/service/") cRul = #cRul else cRul = 0 end
  132.         pozadi.setCursorPos(19,10)
  133.         pozadi.write(cRul)
  134.         pozadi.setCursorPos(19,11)
  135.         pozadi.write(os.getComputerID())
  136.         pozadi.setCursorPos(19,12)
  137.         if not (os.getComputerLabel() == nil) then pozadi.write(os.getComputerLabel())end
  138.         if fs.exists("/C/system/.core/defmodem") then
  139.         local x = fs.open("/C/system/.core/defmodem","r")
  140.         pozadi.setCursorPos(19,13)
  141.         pozadi.write(x.readLine())
  142.         x.close()
  143.         end
  144.        
  145. end
  146. ---------------------------------------------------------------------------------------------------
  147. local function downloading(kod, cestaP)
  148.     local WinDown = window.create(term.current(),15,8,w-15,5)
  149.     WinDown.setBackgroundColor(colors.lightGray)
  150.     WinDown.clear()
  151.     WinDown.setTextColor(colors.black)
  152.     WinDown.setCursorPos(2,1)
  153.     WinDown.write "Downloading files..."
  154.     term.setCursorPos(16,-5)
  155.     term.setBackgroundColor(colors.lightGray)
  156.     shell.run("/stahni get "..kod.." /C/system/server/rules/"..cestaP..".lua")
  157. end
  158.  
  159. function preInRul()
  160. term.setCursorPos(13,3)
  161. shell.run("pastebin get JWk3Qhi2 /stahni")
  162. end
  163.  
  164. function instalRul(ins)
  165.     plocha()
  166.     barW.setCursorPos(19,1)
  167.     barW.write"Rules > Install"
  168.     pozadi.setCursorPos(2,2)
  169.     pozadi.write"The selected role is installed"
  170.     preInRul()
  171.     downloading(pRul[ins], iRul[ins])
  172.     local sh = fs.open("/C/system/Users/"..user.."/Desktop/Rules/"..iRul[ins]..".src","w")
  173.     sh.writeLine("shell.run(\"/C/system/server/rules/"..iRul[ins]..".lua\")")
  174.     sh.close()
  175.     sleep(1)
  176. end
  177.  
  178. function Rul()
  179.     barW.setCursorPos(19,1)
  180.     barW.write"Rules"
  181.     barW.setCursorPos(w-7,1)
  182.     barW.write"Refresh"
  183.     pozadi.setCursorPos(2,2)
  184.     pozadi.write"List of available roles"
  185.     RulT = window.create(term.current(),14,6,w-14,h-6)
  186.     RulT.setBackgroundColor(colors.lightBlue)
  187.     RulT.setTextColor(colors.black)
  188.     RulT.clear()
  189.     if fs.exists(RamCesta.."/rules.cat") then
  190.     local rul = fs.open(RamCesta.."/rules.cat","r")
  191.         local a = 1
  192.         for i = 1, 7 do
  193.         nRul[i] = rul.readLine()
  194.         pRul[i] = rul.readLine()
  195.         iRul[i] = rul.readLine()
  196.         RulT.setCursorPos(2,a)
  197.         RulT.setBackgroundColor(colors.lightBlue)
  198.         if not (nRul[i] == nil) then
  199.             RulT.write(nRul[i])
  200.             RulT.setCursorPos(w-22,a) RulT.setBackgroundColor(colors.lightGray)
  201.             if not fs.exists("/C/system/server/rules/"..iRul[i]..".lua") then bRul[i] = "Install" else bRul[i] = "Manager" end
  202.             RulT.write(" "..bRul[i].." ")
  203.             a= a+2
  204.             end
  205.         end
  206.         rul.close()
  207.     else
  208.         term.setCursorPos(13,-5)
  209.         shell.run("pastebin get zdcN43an "..RamCesta.."/rules.cat")
  210.         menu()
  211.     end
  212. end
  213. ---------------------------------------------------------------------------------------------------
  214. local sPage = "allo"
  215. local aService = {}
  216. local pService = {}
  217.  
  218. function Ser()
  219.     barW.setCursorPos(19,1)
  220.     barW.write"Services"
  221.     barW.setCursorPos(w-7,1)
  222.     barW.write"Refresh"
  223.     if (sPage == "allo") then pozadi.setBackgroundColor(colors.lightBlue) else pozadi.setBackgroundColor(colors.lightGray) end
  224.     pozadi.setCursorPos(2,3)
  225.     pozadi.write" Allowed "
  226.     if (sPage == "proh") then pozadi.setBackgroundColor(colors.lightBlue) else pozadi.setBackgroundColor(colors.lightGray) end
  227.     pozadi.setCursorPos(11,3)
  228.     pozadi.write" Prohibited "
  229.     SerT = window.create(term.current(),14,6,w-14,h-6)
  230.     SerT.setBackgroundColor(colors.lightBlue)
  231.     SerT.setTextColor(colors.black)
  232.     SerT.clear()
  233.    
  234.     if (sPage == "allo") then
  235.         if fs.exists("/C/service/") then
  236.         cSer = fs.list("/C/service/")
  237.         local a=1
  238.             for i = 1, #cSer do
  239.                 local name = tostring(cSer[i])
  240.                 SerT.setBackgroundColor(colors.lightBlue)
  241.                 SerT.setCursorPos(2,a)
  242.                 SerT.write(cSer[i])
  243.                 SerT.setBackgroundColor(colors.lightGray)
  244.                 SerT.setCursorPos(w-25,a)
  245.                 SerT.write(" Proh ")
  246.                 SerT.setCursorPos(w-18,a)
  247.                 SerT.write(" Run ")
  248.                 a = a+2        
  249.             end
  250.         end
  251.     elseif (sPage == "proh") then
  252.         if fs.exists("/C/stopService/") then
  253.         cSer = fs.list("/C/stopService/")
  254.         local a=1
  255.             for i = 1, #cSer do
  256.                 local name = tostring(cSer[i])
  257.                 SerT.setBackgroundColor(colors.lightBlue)
  258.                 SerT.setCursorPos(2,a)
  259.                 SerT.write(cSer[i])
  260.                 SerT.setBackgroundColor(colors.lightGray)
  261.                 SerT.setCursorPos(w-18,a)
  262.                 SerT.write(" Run ")
  263.                 SerT.setCursorPos(w-25,a)
  264.                 SerT.write(" Allo ")
  265.                 a = a+2        
  266.             end
  267.         end
  268.     end
  269. end
  270. ---------------------------------------------------------------------------------------------------
  271. function sel(y)
  272.     inst = 0
  273.     if (y==6) then
  274.         inst = 1
  275.     elseif (y==8) then
  276.         inst = 2
  277.     elseif (y==10) then
  278.         inst = 3
  279.     elseif (y==12) then
  280.         inst = 4
  281.     elseif (y==14) then
  282.         inst = 5
  283.     elseif (y==16) then
  284.         inst = 6
  285.     elseif (y==18) then
  286.         inst = 7
  287.     end
  288. end
  289.  
  290. function menu()
  291.     plocha()
  292.     if (page == "Fdb") then
  293.         Fdb ()
  294.     elseif (page == "Rul") then
  295.         Rul ()
  296.     elseif (page == "Ser") then
  297.         Ser ()
  298.     end
  299.  
  300.     while true do
  301.         local event, button, x, y = os.pullEvent("mouse_click")
  302.         xy = x..","..y
  303.        
  304.         if event == "mouse_click" and x >= 2 and x <= 12 and y == 5 then
  305.         cbarva()
  306.         lista.setCursorPos(1,3)--
  307.         lista.write" Dashboard  "
  308.         sleep(anim)
  309.         page = "Fdb"
  310.         menu()
  311.         elseif event == "mouse_click" and x >= 2 and x <= 12 and y == 7 then
  312.         cbarva()
  313.         lista.setCursorPos(1,5)--
  314.         lista.write" Rules      "
  315.         sleep(anim)
  316.         page = "Rul"
  317.         menu()
  318.         elseif event == "mouse_click" and x >= 2 and x <= 12 and y == 9 then
  319.         cbarva()
  320.         lista.setCursorPos(1,7)--
  321.         lista.write" Services   "
  322.         sleep(anim)
  323.         page = "Ser"
  324.         menu()
  325.         elseif event == "mouse_click" and x >= w-37 and x <= w-29 and y == 5 then -- povolene sluzby
  326.         sPage = "allo"
  327.         menu()
  328.         elseif event == "mouse_click" and x >= w-28 and x <= w-17 and y == 5 then -- zakazane sluzby
  329.         sPage = "proh"
  330.         menu()
  331.         elseif event == "mouse_click" and x >= w-12 and x <= w-7 and (page == "Ser") then -- zakazat/povolit sluzby
  332.         sel(y)
  333.         term.setBackgroundColor(colors.gray)
  334.         if (sPage == "allo") then
  335.         fs.move("C/service/"..cSer[inst], "C/stopService/"..cSer[inst])
  336.         term.setCursorPos(w-12,y)
  337.         term.write(" Proh ")
  338.         else
  339.         fs.move("C/stopService/"..cSer[inst], "C/service/"..cSer[inst])
  340.         term.setCursorPos(w-12,y)
  341.         term.write(" Allo ")
  342.         end
  343.         sleep(anim)
  344.         menu()
  345.         elseif event == "mouse_click" and x >= w-5 and x <= w-1 and y > 2 and (page == "Ser") then -- spustit sluzby
  346.         sel(y)
  347.         term.setCursorPos(w-5,y) term.setBackgroundColor(colors.gray)
  348.         if not (sPage == "allo") then
  349.         fs.move("C/stopService/"..cSer[inst], "C/service/"..cSer[inst])
  350.         end
  351.         term.write(" Run ")
  352.         sleep(anim)
  353.         multishell.launch({}, "C/service/"..cSer[inst])
  354.         menu()
  355.         elseif event == "mouse_click" and x >= w-7 and x <= w and y == 2 then   -- refresh Rules
  356.             barW.setTextColor(colors.lightGray)
  357.             barW.setCursorPos(w-7,1)
  358.             barW.write"Refresh"
  359.             sleep(anim)
  360.         if (page == "Rul") then
  361.             term.setCursorPos(13,3)
  362.             barW.setTextColor(colors.black)
  363.             if fs.exists(RamCesta.."/rules.cat") then fs.delete(RamCesta.."/rules.cat") end
  364.             shell.run("pastebin get zdcN43an "..RamCesta.."/rules.cat")
  365.         end
  366.             menu()
  367.         elseif event == "mouse_click" and x >= w-9 and x <= w-1 and (page == "Rul") then -- install/manage rules
  368.             sel(y)
  369.             term.setCursorPos(w-9,y) term.setBackgroundColor(colors.gray)
  370.             if not fs.exists("/C/system/server/rules/"..iRul[inst]..".lua") then term.write(" Install ") sleep(anim) instalRul(inst) else term.write(" Manager ") shell.run("/C/system/server/rules/"..iRul[inst])end
  371.         end
  372.        
  373.        
  374.         if x == w and y == 1 then
  375.             ukonceni ()
  376.         else
  377.             menu() -------- stejne jako nazev funkce
  378.         end
  379.     end
  380. end
  381.  
  382. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement