Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local verze = "21.0628.R3"
- local anim = 0.1
- local i = 0
- local a = 1
- local ADUsersT = true
- local w, h = term.getSize()
- local RamCesta = ("/C/system/RAM/AD")
- local nastaveni={barva=colors.blue}
- local f=fs.open("/C/system/.core/colors","r")
- local cnt=f.readAll()
- local cUsr = {}
- local cComp = {}
- f.close()
- ----------------------------------------------------
- local f=fs.open("/C/system/RAM/user","r")
- user=f.readLine()
- pass=f.readLine()
- Fname=f.readLine()
- Lname=f.readLine()
- IsAdmin=f.readLine()
- f.close()
- local function Barvy()
- if fs.exists ("/C/system/Users/"..user.."/.Registry/colors") then
- local data = fs.open("/C/system/Users/"..user.."/.Registry/colors", "r")
- BarPoz = tonumber(data.readLine())
- BarTxt = tonumber(data.readLine())
- data.close()
- end
- if BarPoz == nil or BarTxt == nil then BarPoz = 2048 BarTxt = 1 end
- end
- function ukonceni ()
- fs.delete (RamCesta)
- os.exit()
- end
- function cbarva()
- lista.setTextColor(colors.black)
- lista.setBackgroundColor(colors.gray)
- end
- function bbarva()
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.lightBlue)
- end
- function defaultvalue()
- Nuser = " "
- Npass = ""
- NFname = " "
- NLname = " "
- IsAdmin = "f"
- end
- function defaultMenu()
- ADUsersT = false
- ADCompT = false
- end
- function start()
- defaultvalue()
- Barvy()
- local myWindow = window.create(term.current(),w/2-11,h/2-5,25,9)
- myWindow.setBackgroundColor(colors.blue)
- myWindow.clear()
- myWindow.setCursorPos (2, 5)
- myWindow.write"Users Active directory"
- myWindow.setCursorPos (1, 1)
- myWindow.write"Pepek@Soft"
- myWindow.setCursorPos (22, 9)
- myWindow.write"2020"
- kontrola()
- sleep(0.5)
- menu()
- end
- function plocha()
- w, h = term.getSize()
- paintutils.drawLine(1, 1, w, 1, BarPoz)
- paintutils.drawPixel (w,1, colors.red)
- term.setCursorPos (w,1)
- term.setTextColor(BarTxt)
- write "×"
- barW = window.create(term.current(),1,2,w,1)
- barW.setBackgroundColor(colors.gray)
- barW.clear()
- barW.setTextColor(colors.white)
- barW.setCursorPos(2,1)
- barW.write"Users & Computers AD >"
- pozadi = window.create(term.current(),13,3,w,h-2)
- pozadi.setBackgroundColor(colors.white)
- pozadi.setTextColor(colors.black)
- pozadi.clear()
- lista = window.create(term.current(),1,3,12,h-2)
- lista.setBackgroundColor(BarPoz)
- lista.setTextColor(BarTxt)
- lista.clear()
- lista.setCursorPos(2,3)
- lista.write"Dashboard"
- lista.setCursorPos(2,5)
- lista.write"Users"
- lista.setCursorPos(2,7)
- lista.write"Computers"
- lista.setCursorPos(2,9)
- lista.write"Policy"
- lista.setCursorPos(2,h-2)
- lista.setTextColor(colors.white)
- lista.write("Pepek@Soft")
- term.setBackgroundColor(colors.lightGray)
- end
- -----------------------------------------------------------------------------
- function kontrola()
- if not fs.exists ("/C/system/server/rules/AD/Users/") then
- fs.makeDir("/C/system/server/rules/AD/Users/")
- end
- if not fs.exists ("/C/system/server/rules/AD/Computers/") then
- fs.makeDir("/C/system/server/rules/AD/Computers/")
- end
- if not fs.exists ("/C/service/AD") and not fs.exists ("/C/service/AD.lua") then
- if not fs.exists ("/C/stopService/AD.lua") then
- shell.run("pastebin get LpbqMJuu /C/service/AD.lua")
- multishell.launch({}, "/C/service/AD.lua")
- end
- end
- if not fs.exists ("/C/system/.core/AD") then
- local f=fs.open("/C/system/.core/AD","w")
- f.writeLine(tostring(os.getComputerID()))
- f.close()
- end
- if not fs.exists ("/C/system/server/rules/AD/Users/"..user) then
- addUser(user)
- fs.copy("/C/system/Users/"..user.."/.data", "/C/system/server/rules/AD/Users/"..user.."/.data")
- if fs.exists ("/C/system/Users/"..user.."/bar.nfp") then fs.copy("/C/system/Users/"..user.."/bar.nfp", "/C/system/server/rules/AD/Users/"..user.."/bar.nfp") end
- fs.copy("/C/system/Users/"..user.."/colors", "/C/system/server/rules/AD/Users/"..user.."/colors")
- fs.copy("/C/system/Users/"..user.."/lsprogram", "/C/system/server/rules/AD/Users/"..user.."/lsprogram")
- fs.copy("/C/system/Users/"..user.."/textcol", "/C/system/server/rules/AD/Users/"..user.."/textcol")
- end
- end
- function addUser(user)
- if not fs.exists ("/C/system/server/rules/AD/Users/"..user) then
- fs.makeDir("/C/system/server/rules/AD/Users/"..user)
- end
- end
- local page = "main"
- function main()
- barW.setCursorPos(25,1)
- barW.write"Dashboard"
- pozadi.setCursorPos(2,2)
- pozadi.write"Instaled Version:"
- pozadi.setCursorPos(2,4)
- pozadi.write"Logged in user:"
- pozadi.setCursorPos(2,5)
- pozadi.write"Count of Users:"
- pozadi.setCursorPos(2,6)
- pozadi.write"Count of Comp's:"
- pozadi.setCursorPos(2,7)
- pozadi.write"This server ID:"
- pozadi.setTextColor(colors.lightGray)
- pozadi.setCursorPos(20,7)
- pozadi.write(os.getComputerID())
- pozadi.setCursorPos(20,2)
- pozadi.write(verze)
- pozadi.setCursorPos(20,4)
- pozadi.write(user)
- pozadi.setCursorPos(20,5)
- pozadi.write(#(fs.list("/C/system/server/rules/AD/Users/")))
- pozadi.setCursorPos(20,6)
- pozadi.write(#(fs.list("/C/system/server/rules/AD/Computers/")))
- pozadi.setBackgroundColor(colors.lightGray)
- pozadi.setTextColor(colors.black)
- pozadi.setCursorPos(2,10)
- pozadi.write " Start AD "
- end
- function Usr()
- barW.setCursorPos(25,1)
- barW.write"Users "
- barW.setCursorPos(w-8,1)
- barW.write"New User"
- UsrT = window.create(term.current(),14,4,w-14,h-3)
- UsrT.setBackgroundColor(colors.lightBlue)
- UsrT.setTextColor(colors.black)
- UsrT.clear()
- if fs.exists("/C/system/server/rules/AD/Users/") then
- cUsr = fs.list("/C/system/server/rules/AD/Users/")
- local a=1
- for i = 1, #cUsr do
- local name = tostring(cUsr[i])
- UsrT.setBackgroundColor(colors.lightBlue)
- UsrT.setCursorPos(2,a)
- UsrT.write(cUsr[i])
- a = a+1
- end
- end
- end
- function Comp()
- barW.setCursorPos(25,1)
- barW.write"Computers"
- barW.setCursorPos(w-8,1)
- barW.write"New PC"
- CompT = window.create(term.current(),14,4,w-14,h-3)
- CompT.setBackgroundColor(colors.lightBlue)
- CompT.setTextColor(colors.black)
- CompT.clear()
- if fs.exists("/C/system/server/rules/AD/Computers/") then
- cComp = fs.list("/C/system/server/rules/AD/Computers/")
- local a=1
- for i = 1, #cComp do
- local name = tostring(cComp[i])
- CompT.setBackgroundColor(colors.lightBlue)
- CompT.setCursorPos(2,a)
- CompT.write(cComp[i])
- a = a+1
- end
- end
- end
- function CompWin()
- local eComp = window.create(term.current(),w/2-5,h/2-4,25,9)
- eComp.setBackgroundColor(colors.white)
- eComp.clear()
- eComp.setBackgroundColor(colors.red)
- eComp.setCursorPos (25, 1)
- eComp.write"×"
- eComp.setBackgroundColor(colors.white)
- eComp.setTextColor(colors.black)
- eComp.setCursorPos (2, 1)
- eComp.write"Add Computer manually"
- eComp.setCursorPos (2, 5)
- eComp.write"Computer ID: "
- eComp.setBackgroundColor(colors.lightGray)
- eComp.setCursorPos (15, 5)
- eComp.write" "
- eComp.setCursorPos (10, 8)
- eComp.write" Apply "
- while true do
- local event, button, x, y = os.pullEvent("mouse_click")
- xy = x..","..y
- if event == "mouse_click" and x == math.ceil(w/2+18) and y == h/2-4 then
- menu()
- elseif event == "mouse_click" and x >= w/2+8 and x <= w/2+18 and y == h/2 then
- eComp.setBackgroundColor(colors.gray)
- term.setBackgroundColor(colors.gray)
- eComp.setTextColor(colors.white)
- eComp.setCursorPos (15, 5)
- eComp.write" "
- eComp.setCursorPos (16, 5)
- nID = read()
- elseif event == "mouse_click" and x >= w/2+3 and x <= w/2+10 and y == h/2+3 then
- if not fs.exists("/C/system/server/rules/AD/Computers/"..nID) then
- local a = fs.open("/C/system/server/rules/AD/Computers/"..nID, "w")
- a.close()
- end
- menu()
- end
- end
- end
- function poli()
- barW.setCursorPos(25,1)
- barW.write"User Policy Setting"
- end
- function menu()
- plocha()
- if (page == "main") then
- main ()
- elseif (page == "Usr") then
- Usr ()
- elseif (page == "Comp") then
- Comp ()
- elseif (page == "Poli") then
- poli()
- end
- while true do
- local event, button, x, y = os.pullEvent("mouse_click")
- xy = x..","..y
- if event == "mouse_click" and x >= 2 and x <= 12 and y == 5 then
- cbarva()
- lista.setCursorPos(1,3)--
- lista.write" Dashboard "
- sleep(anim)
- page = "main"
- menu()
- elseif event == "mouse_click" and x >= 2 and x <= 12 and y == 7 then
- cbarva()
- lista.setCursorPos(1,5)--
- lista.write" Users "
- sleep(anim)
- page = "Usr"
- menu()
- elseif event == "mouse_click" and x >= 2 and x <= 12 and y == 9 then
- cbarva()
- lista.setCursorPos(1,7)--
- lista.write" Computers "
- sleep(anim)
- page = "Comp"
- menu()
- elseif event == "mouse_click" and x >= 2 and x <= 12 and y == 11 then
- cbarva()
- lista.setCursorPos(1,9)--
- lista.write" Policy "
- sleep(anim)
- page = "Poli"
- menu()
- elseif event == "mouse_click" and x >= w-8 and x <= w and y == 2 then -- refresh Rules
- barW.setTextColor(colors.lightGray)
- barW.setCursorPos(w-8,1)
- if (page=="Usr") then
- barW.write"New User"
- sleep(anim)
- UserWin("")
- else
- barW.write"New PC"
- sleep(anim)
- CompWin()
- end
- elseif event == "mouse_click" and x >= 14 and x <= 23 and y == 12 and page=="main" and button == 1 then
- pozadi.setBackgroundColor(colors.gray)
- pozadi.setCursorPos(2,10)
- pozadi.write " Start AD "
- pozadi.setBackgroundColor(colors.white)
- sleep(anim)
- if fs.exists ("/C/service/AD.lua") then
- multishell.launch({}, "/C/service/AD.lua")
- pozadi.setTextColor(colors.green)
- pozadi.setCursorPos(2,11)
- pozadi.write"Started successfully"
- sleep(0.5)
- elseif fs.exists ("/C/stopService/AD.lua") then
- pozadi.setTextColor(colors.red)
- pozadi.setCursorPos(2,12)
- pozadi.write"Service unavailable!"
- pozadi.setCursorPos(2,13)
- pozadi.write("You can enable the service in")
- pozadi.setCursorPos(2,15)
- pozadi.write("\"Server Manager > Services\"")
- sleep(2)
- end
- elseif event == "mouse_click" and x >= 14 and x <= w-1 and y >= 4 and page=="Usr" and button == 1 then
- i = y-3
- if not (cUsr[i] == nil) then
- paintutils.drawLine(14, y, w-1, y, colors.lightGray)
- term.setCursorPos(15,y)
- write(cUsr[i])
- sleep(anim)
- UserWin(cUsr[i])
- end
- elseif x >= 16 and x <= w and y >= 4 and button == 2 then
- i = y-3
- if (page == "Usr") then
- if not (cUsr[i] == nil) then
- paintutils.drawLine(14, y, w-1, y, colors.lightGray)
- term.setCursorPos(15,y)
- write(cUsr[i])
- end
- elseif (page == "Comp") then
- if not (cComp[i] == nil) then
- paintutils.drawLine(14, y, w-1, y, colors.lightGray)
- term.setCursorPos(15,y)
- write(cComp[i])
- end
- end
- dialogWin = window.create(term.current(),x,y,10,3)
- dialogWin.setBackgroundColor(colors.gray)
- dialogWin.setTextColor(colors.white)
- dialogWin.clear()
- dialogWin.setCursorPos(2,1)
- dialogWin.write "Edit"
- dialogWin.setCursorPos(2,2)
- dialogWin.write "Delete"
- ENDS = false
- dialogWin.setCursorPos(2,3)
- if (page=="Usr") and not (cUsr[i] == nil) then
- if fs.exists("/C/system/server/rules/AD/Users/"..cUsr[i].."/.lock") then ENDS = true dialogWin.write "Enable" else dialogWin.write "Disable" end
- elseif (page=="Comp") and not (cComp[i] == nil) then
- end
- PosX = x
- PosY = y
- while true do
- event, button, x,y = os.pullEvent()
- if event == "mouse_click" and x >= PosX and x<= PosX+10 and y == PosY and button == 1 then
- if (cUsr[i] == nil) then menu () end
- UserWin(cUsr[i])
- elseif event == "mouse_click" and x >= PosX and x<= PosX+10 and y == PosY+1 and button == 1 then
- if (page=="Usr") and not (cUsr[i] == nil) then fs.delete ("/C/system/server/rules/AD/Users/"..cUsr[i]) elseif (page=="Comp") and not (cComp[i] == nil) then fs.delete ("/C/system/server/rules/AD/Computers/"..cComp[i]) end
- kontrola()
- menu()
- elseif event == "mouse_click" and x >= PosX and x<= PosX+10 and y == PosY+2 and ENDS == true and button == 1 then
- if fs.exists("/C/system/server/rules/AD/Users/"..cUsr[i].."/.lock") then
- fs.delete("/C/system/server/rules/AD/Users/"..cUsr[i].."/.lock", "w")
- end
- dialogWin.setBackgroundColor(colors.lightGray)
- dialogWin.setCursorPos(1,3)
- dialogWin.write " Enable "
- sleep(anim)
- menu()
- elseif event == "mouse_click" and x >= PosX and x<= PosX+10 and y == PosY+2 and ENDS == false and button == 1 then
- if not (cUsr[i] == nil) then
- if not fs.exists("/C/system/server/rules/AD/Users/"..cUsr[i].."/.lock") then
- local f = fs.open("/C/system/server/rules/AD/Users/"..cUsr[i].."/.lock", "w")
- f.close()
- end
- dialogWin.setBackgroundColor(colors.lightGray)
- dialogWin.setCursorPos(1,3)
- dialogWin.write " Disable "
- sleep(anim)
- menu()
- else
- menu()
- end
- elseif event == "mouse_click" then
- menu()
- end
- end
- end
- if x == w and y == 1 then
- ukonceni ()
- else
- menu() -------- stejne jako nazev funkce
- end
- end
- end
- function CreateWindow()
- DialWin = window.create(term.current(),w/2-11,h/2-7,25,16)
- DialWin.setBackgroundColor(colors.white)
- DialWin.setTextColor(colors.black)
- DialWin.clear()
- ww, wh = DialWin.getSize()
- DialWin.setCursorPos (1,1)
- DialWin.write ("+-----------------------+")
- DialWin.setCursorPos (1,16)
- DialWin.write ("+-----------------------+")
- local i = 2
- repeat
- DialWin.setCursorPos (1,i)
- DialWin.write ("|")
- i = i + 1
- until i == 16
- i = 2
- repeat
- DialWin.setCursorPos (ww,i)
- DialWin.write ("|")
- i = i + 1
- until i == 16
- DialWin.setTextColor(colors.white)
- DialWin.setBackgroundColor(colors.red)
- DialWin.setCursorPos (ww,1)
- DialWin.write "×"
- DialWin.setBackgroundColor(colors.gray)
- DialWin.setCursorPos (ww/2-2,wh)
- DialWin.write " Apply "
- DialWin.setBackgroundColor(colors.white)
- DialWin.setTextColor(colors.black)
- end
- function UserWin(SUser)
- defaultvalue()
- if not (SUser == "") then
- local f=fs.open("/C/system/server/rules/AD/Users/"..SUser.."/.data","r")
- user=f.readLine()
- pass=f.readLine()
- Fname=f.readLine()
- Lname=f.readLine()
- IsAdmin=f.readLine()
- f.close()
- end
- CreateWindow()
- DialWin.setCursorPos (3,2)
- DialWin.write "UserName:"
- DialWin.setCursorPos (3,5)
- DialWin.write "Password:"
- DialWin.setCursorPos (3,7)
- DialWin.write "F Name:"
- DialWin.setCursorPos (3,9)
- DialWin.write "L Name:"
- DialWin.setCursorPos (3,11)
- DialWin.write "Permissions:"
- DialWin.setBackgroundColor(colors.lightGray)
- DialWin.setCursorPos (3,3)
- DialWin.write " "
- DialWin.setCursorPos (13,5)
- DialWin.write " "
- DialWin.setCursorPos (13,7)
- DialWin.write " "
- DialWin.setCursorPos (13,9)
- DialWin.write " "
- DialWin.setCursorPos (16,11)
- DialWin.write " "
- if (SUser == "") then
- else
- DialWin.setCursorPos (4,3)
- if (Nuser == " ") then
- DialWin.write (tostring(user))
- else
- DialWin.write (tostring(Nuser))
- end
- DialWin.setCursorPos (14,5)
- DialWin.write "Password"
- if Fname == nil then Fname = "" end
- DialWin.setCursorPos (14,7)
- DialWin.write (Fname)
- if Lname == nil then Lname = "" end
- DialWin.setCursorPos (14,9)
- DialWin.write (Lname)
- if (IsAdmin == "t") then
- DialWin.setCursorPos (16,11)
- DialWin.write " Admin "
- else
- DialWin.setCursorPos (16,11)
- DialWin.write " User "
- end
- end
- while true do
- local event, button, x, y = os.pullEvent("mouse_click")
- xy = x..","..y
- if x >= 23 and x <= 27 and y == 17 and button == 1 then
- DialWin.setCursorPos (ww/2-2,wh)
- DialWin.write " Apply "
- sleep(anim)
- if (SUser == "") then
- if not fs.exists ("/C/system/server/rules/AD/Users/"..Nuser.."/.data") and not (Nuser == "") and not (Nuser == nil)then
- local f=fs.open("/C/system/server/rules/AD/Users/"..Nuser.."/.data","w")
- f.writeLine(Nuser)
- f.writeLine(Npass)
- f.writeLine(NFname)
- f.writeLine(NLname)
- f.writeLine(IsAdmin)
- f.close()
- end
- else
- local f=fs.open("/C/system/server/rules/AD/Users/"..SUser.."/.data","w")
- f.writeLine(SUser)
- if not (Npass == " ") then f.writeLine(Npass) else f.writeLine("") end
- if not (NFname == " ") then f.writeLine(NFname) else f.writeLine("") end
- if not (NLname == " ") then f.writeLine(NLname) else f.writeLine("") end
- f.writeLine(IsAdmin)
- f.close()
- end
- defaultvalue()
- menu()
- elseif x >= w/2-ww/2+3 and x <= w/2+ww/2-2 and y == 4 and button == 1 then
- bbarva()
- DialWin.setBackgroundColor(colors.lightBlue)
- DialWin.setCursorPos (3,3)
- DialWin.write " "
- DialWin.setCursorPos (4,3)
- Nuser = read()
- elseif x >= w/2-ww/2+14 and x <= w/2+ww/2-2 and y == 6 and button == 1 then
- bbarva()
- DialWin.setBackgroundColor(colors.lightBlue)
- DialWin.setCursorPos (13,5)
- DialWin.write " "
- DialWin.setCursorPos (14,5)
- Npass = read(string.char(7))
- elseif x >= w/2-ww/2+14 and x <= w/2+ww/2-2 and y == 8 and button == 1 then
- bbarva()
- DialWin.setBackgroundColor(colors.lightBlue)
- DialWin.setCursorPos (13,7)
- DialWin.write " "
- DialWin.setCursorPos (14,7)
- NFname = read()
- elseif x >= w/2-ww/2+14 and x <= w/2+ww/2-2 and y == 10 and button == 1 then
- bbarva()
- DialWin.setBackgroundColor(colors.lightBlue)
- DialWin.setCursorPos (13,9)
- DialWin.write " "
- DialWin.setCursorPos (14,9)
- NLname = read()
- elseif x >= w/2-ww/2+17 and x <= w/2+ww/2-2 and y == 12 and button == 1 then
- DialWin.setCursorPos (16,11)
- if (IsAdmin == "t") then
- IsAdmin = "f"
- DialWin.write " User "
- else
- DialWin.write " Admin "
- IsAdmin = "t"
- end
- elseif x == ww/2+w/2 and y == 2 and button == 1 then
- defaultvalue()
- menu()
- end
- end
- end
- start()
Add Comment
Please, Sign In to add comment