Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- currentUser=nil
- function os.pullEvent()
- local event, p1, p2, p3, p4, p5 = os.pullEventRaw()
- if event == "terminate" and termDisabled then
- end
- return event, p1, p2, p3, p4, p5
- end
- if not fs.exists("accountDatabase") then
- shell.run("pastebin","get","kERnnPN8","accountDatabase")
- end
- os.loadAPI("accountDatabase")
- defaultPrograms={["UpdateOS"]="vFjP50hm", ["MediaPl."]="7MfZH0jH", ["FileMgr"]="zyAKNJwB", ["LuaInt"]="RBMbTH66", ["LuaIDE"]="6WpGXY09", ["LeNet"]="EQgHhsAA"}
- function drawLogin()
- termDisabled=true
- username={}
- pass={}
- term.setTextColor(2)
- loginDrawn=true
- term.setBackgroundColor(8)
- term.clear()
- screenX,screenY=term.getSize()
- term.setCursorPos(screenX/2-10,screenY/2-5)
- term.setBackgroundColor(128)
- term.write("Login to Aperture OS")
- term.setBackgroundColor(256)
- for i=1,7 do
- term.setCursorPos(screenX/2-10,(screenY/2-5)+i)
- term.write(" ")
- end
- term.setBackgroundColor(1)
- term.setCursorPos(screenX/2-2,(screenY/2-2))
- term.write(" ")
- term.setCursorPos(screenX/2-2,(screenY/2+0))
- term.write(" ")
- term.setBackgroundColor(256)
- term.setCursorPos(screenX/2-7,(screenY/2-2))
- term.write("User")
- term.setCursorPos(screenX/2-7,(screenY/2+0))
- term.write("Pass")
- term.setCursorPos(screenX/2+4,screenY/2+2)
- term.setBackgroundColor(128)
- term.write("Login")
- term.setBackgroundColor(1)
- term.setTextColor(32768)
- term.setCursorPos(screenX/2-2,(screenY/2-2))
- term.setCursorBlink(true)
- end
- function loginEvents()
- repeat
- event,v1,v2,v3,v4,v5=os.pullEvent()
- if event=="char" then
- loginType(v1)
- elseif event=="mouse_click" then
- screenX,screenY=term.getSize()
- button=v1
- x=v2
- y=v3
- if button==1 then
- if x>=screenX/2-3 and x< screenX/2+6 and y==math.floor(screenY/2-2) then
- term.setCursorPos(screenX/2-2+#username,(screenY/2-2))
- elseif x>=screenX/2-3 and x< screenX/2+6 and y==math.floor(screenY/2+0) then
- term.setCursorPos(screenX/2-2+#pass,(screenY/2+0))
- elseif x>=screenX/2+4 and x<screenX/2+9 and y==math.floor(screenY/2+2) then
- serialiseLogin()
- end
- end
- elseif event=="key" then
- key=v1
- if key==14 then
- loginBackspace()
- elseif key==15 then
- loginTab()
- end
- end
- until currentUser~=nil
- end
- function serialiseLogin()
- userString=""
- passString=""
- for id,letter in ipairs(username) do
- userString=userString..letter
- end
- for id,letter in ipairs(pass) do
- passString=passString..letter
- end
- loggedIn=attemptLogin(userString,passString)
- if not loggedIn then
- oldX,oldY=term.getCursorPos()
- term.setCursorBlink(false)
- term.setCursorPos(screenX/2-9,screenY/2+5)
- term.setTextColor(16384)
- term.setBackgroundColor(32768)
- term.write("Incorrect Password!")
- sleep(1)
- term.setBackgroundColor(8)
- term.setCursorPos(screenX/2-9,screenY/2+5)
- term.write(" ")
- term.setCursorPos(oldX,oldY)
- term.setTextColor(32768)
- term.setCursorBlink(true)
- end
- end
- function attemptLogin(user,pass)
- password=accountDatabase.getData(user)
- if password==nil then
- passLength=string.len(pass)
- if passLength<8 then
- for i=1,8-passLength do
- pass=pass.." "
- end
- end
- accountDatabase.setData(user,pass)
- fs.makeDir("users/"..user)
- for id,paste in pairs(defaultPrograms) do
- if fs.exists(id)==false then
- term.setCursorPos(1000,1)
- shell.run("pastebin","get",paste,id)
- end
- fs.copy(id,"users/"..user.."/"..id)
- end
- login(user)
- return true
- else
- password=string.gsub(password," ","")
- password=string.gsub(password,"\n","")
- if password==pass then
- login(user)
- return true
- else
- return false
- end
- end
- end
- function login(user)
- currentUser=user
- term.setCursorBlink(false)
- loginDrawn=false
- currentDirectory="users/"..currentUser
- for id,paste in pairs(defaultPrograms) do
- if fs.exists(id)==false then
- term.setCursorPos(1000,1)
- shell.run("pastebin","get",paste,id)
- end
- if not fs.exists("users/"..user.."/"..id) then
- fs.copy(id,"users/"..user.."/"..id)
- end
- end
- drawDesktop()
- desktopEvents()
- end
- function loginType(char)
- x,y=term.getCursorPos()
- screenX,screenY=term.getSize()
- if y==math.floor(screenY/2+0) and #pass<=8 then
- writeChar="*"
- pass[#pass+1]=char
- elseif #username<8 then
- writeChar=char
- username[#username+1]=char
- end
- term.setBackgroundColor(1)
- term.write(writeChar)
- end
- function loginTab()
- x,y=term.getCursorPos()
- screenX,screenY=term.getSize()
- if y==screenY/2+0 then
- term.setCursorPos(screenX/2-2,(screenY/2-2))
- else
- term.setCursorPos(screenX/2-2,(screenY/2+0))
- end
- end
- function loginBackspace()
- x,y=term.getCursorPos()
- screenX,screenY=term.getSize()
- x,y=term.getCursorPos()
- if x>=screenX/2-2 then
- if y==screenY/2+4 then
- usernameOld=username
- username={}
- for id,letter in ipairs(usernameOld) do
- if id~=#usernameOld then
- username[#username+1]=letter
- end
- end
- else
- passOld=pass
- pass={}
- for id,letter in ipairs(passOld) do
- if id~=#passOld then
- pass[#pass+1]=letter
- end
- end
- end
- term.setBackgroundColor(1)
- x,y=term.getCursorPos()
- term.setCursorPos(x-1,y)
- term.write(" ")
- term.setCursorPos(x-1,y)
- end
- end
- function drawDesktop()
- if currentUser==nil then
- loginEvents()
- else
- screenX,screenY=term.getSize()
- term.setBackgroundColor(256) --Taskbar on top of the screen
- touchScreenTable={}
- term.clear()
- term.setCursorPos(1,1)
- term.setBackgroundColor(128)
- for i=1,screenX do
- term.setCursorPos(i,1)
- term.write(" ")
- --term.setCursorPos(i,2)
- --term.write(" ")
- end
- term.setCursorPos(1,1)
- term.setTextColor(1)
- term.setBackgroundColor(32)
- term.write("Aperture OS")
- touchScreenTable["menu"]={1,1,10,0,false,mainMenuFunction}
- term.setBackgroundColor(128)
- term.setCursorPos(screenX-10,1)
- term.write(currentUser)
- term.setBackgroundColor(256) --Programs section
- programsList=fs.list(currentDirectory) --Get the programs
- programs={}
- for id,program in ipairs(programsList) do
- programs[#programs+1]=program
- end
- term.setCursorPos(screenX-(screenX+10),5)
- programsTable={}
- screenX,screenY=term.getSize()
- pStart=screenX*0.75
- pWidth=screenX*0.6
- pTextLength=(pWidth-2)/3
- term.setBackgroundColor(128)
- if currentDirectory~="users/"..currentUser then --Get directory and draw back button
- term.setBackgroundColor(128)
- term.setCursorPos(screenX-20,screenY*0.9)
- term.setTextColor(16384)
- term.write("Home directory")
- touchScreenTable["goToHome"]={screenX-20,screenY*0.9,screenX-6,5,false,backToMainDirectory}
- else
- touchScreenTable["goToHome"]=nil
- end
- for id,data in ipairs(programs) do
- if fs.isDir("users/"..currentUser.."/"..data) then --Draw programs
- term.setTextColor(16)
- shellRunner=false
- else
- term.setTextColor(32)
- shellRunner=true
- end
- rowID=math.ceil(id/3)
- collumnID=id-rowID*3
- programsTable[data]={pStart+((collumnID)*pTextLength+((collumnID)*1)),screenY*0.3+rowID*2,pStart+((collumnID)*pTextLength+((collumnID)*1))+pTextLength,1,shellRunner}
- term.setCursorPos(pStart+((collumnID)*pTextLength+((collumnID)*1)),screenY*0.3+rowID*2)
- if string.len(data)<pTextLength then
- for i=1,pTextLength-string.len(data) do
- data=data.." "
- end
- end
- term.write(string.sub(data,1,pTextLength))
- end
- term.setTextColor(1)
- term.setBackgroundColor(256)
- for id,data in pairs(programsTable) do
- touchScreenTable[id]=data
- end
- term.setBackgroundColor(256)
- term.setTextColor(1)
- term.setCursorPos(1,2)
- end
- end
- function relogin()
- currentUser=nil drawLogin() loginEvents()
- end
- function doDaShell()
- drawShell()
- inputShell()
- end
- function editFileFunction(id)
- shell.run("edit",currentDirectory.."/"..id)
- touchScreenTable={}
- fileManager()
- end
- function editFile()
- programsList=fs.list(currentDirectory) --Get the programs
- programs={}
- for id,program in ipairs(programsList) do
- programs[#programs+1]=program
- end
- term.setCursorPos(screenX-(screenX+10),5)
- programsTable={}
- screenX,screenY=term.getSize()
- pStart=screenX*0.75
- pWidth=screenX*0.6
- pTextLength=(pWidth-2)/3
- term.setBackgroundColor(2)
- for id,data in ipairs(programs) do
- if fs.isDir("users/"..currentUser.."/"..data) then --Draw programs
- term.setTextColor(256)
- shellRunner=false
- else
- term.setTextColor(1)
- shellRunner=true
- end
- rowID=math.ceil(id/3)
- collumnID=id-rowID*3
- programsTable[data]={pStart+((collumnID)*pTextLength+((collumnID)*1)),screenY*0.3+rowID*2,pStart+((collumnID)*pTextLength+((collumnID)*1))+pTextLength,1,false,editFileFunction}
- term.setCursorPos(pStart+((collumnID)*pTextLength+((collumnID)*1)),screenY*0.3+rowID*2)
- if string.len(data)<pTextLength then
- for i=1,pTextLength-string.len(data) do
- data=data.." "
- end
- end
- term.write(string.sub(data,1,pTextLength))
- end
- term.setTextColor(1)
- term.setBackgroundColor(256)
- for id,data in pairs(programsTable) do
- touchScreenTable[id]=data
- end
- term.setBackgroundColor(256)
- term.setTextColor(1)
- term.setCursorPos(1,2)
- end
- function drawFrompastebin()
- touchScreenTable={}
- screenX,screenY=term.getSize()
- term.setTextColor(1)
- for i=1,5 do
- term.setCursorPos(screenX/2-5,i+screenY/2)
- term.setBackgroundColor(128)
- term.write(" ")
- end
- term.setCursorPos(screenX/2-4,1+screenY/2)
- term.write("Link ")
- term.setCursorPos(screenX/2-4,2+screenY/2)
- term.setBackgroundColor(1)
- term.write(" ")
- term.setCursorPos(screenX/2-4,3+screenY/2)
- term.setBackgroundColor(128)
- term.write("fileName")
- term.setCursorPos(screenX/2-4,4+screenY/2)
- term.setBackgroundColor(1)
- term.write(" ")
- term.setCursorPos(screenX/2-4,4+screenY/2)
- term.setBackgroundColor(1)
- term.setTextColor(32768)
- term.setCursorPos(screenX/2-4,2+screenY/2)
- link=read()
- term.setCursorPos(screenX/2-4,4+screenY/2)
- fileName=read()
- term.setCursorPos(screenX/2-10,screenY/2)
- term.setBackgroundColor(256)
- shell.run("pastebin","get",link,currentDirectory.."/"..fileName)
- fileManager()
- end
- function drawNewFile()
- touchScreenTable={}
- screenX,screenY=term.getSize()
- term.setTextColor(1)
- for i=1,5 do
- term.setCursorPos(screenX/2-5,i+screenY/2)
- term.setBackgroundColor(128)
- term.write(" ")
- end
- term.setCursorPos(screenX/2-4,2+screenY/2)
- term.setBackgroundColor(128)
- term.write("fileName")
- term.setCursorPos(screenX/2-4,3+screenY/2)
- term.setBackgroundColor(1)
- term.write(" ")
- term.setBackgroundColor(1)
- term.setTextColor(32768)
- term.setCursorPos(screenX/2-4,3+screenY/2)
- fileName=read()
- term.setCursorPos(screenX/2-20,screenY/2)
- term.setBackgroundColor(128)
- editFileFunction(fileName)
- fileManager()
- end
- function newFile()
- touchScreenTable={}
- screenX,screenY=term.getSize()
- term.setTextColor(1)
- for i=1,5 do
- term.setCursorPos(screenX/2-5,i+screenY/2)
- term.setBackgroundColor(128)
- term.write(" ")
- end
- term.setCursorPos(screenX/2-4,2+screenY/2)
- term.setBackgroundColor(8)
- term.write("Create ")
- term.setCursorPos(screenX/2-4,4+screenY/2)
- term.write("Pastebin")
- touchScreenTable['createNewFile']={screenX/2-4,2+screenY/2+2,screenX/2+4,1,false,drawFrompastebin}
- touchScreenTable['fileFromPastebin']={screenX/2-4,2+screenY/2,screenX/2+4,1,false,drawNewFile}
- end
- function deleteFile(fileName)
- fs.delete(currentDirectory.."/"..fileName)
- touchScreenTable={}
- fileManager()
- end
- function delFile()
- programsList=fs.list(currentDirectory) --Get the programs
- programs={}
- for id,program in ipairs(programsList) do
- programs[#programs+1]=program
- end
- term.setCursorPos(screenX-(screenX+10),5)
- programsTable={}
- screenX,screenY=term.getSize()
- pStart=screenX*0.75
- pWidth=screenX*0.6
- pTextLength=(pWidth-2)/3
- term.setBackgroundColor(16384)
- for id,data in ipairs(programs) do
- if fs.isDir("users/"..currentUser.."/"..data) then --Draw programs
- term.setTextColor(256)
- shellRunner=false
- else
- term.setTextColor(1)
- shellRunner=true
- end
- rowID=math.ceil(id/3)
- collumnID=id-rowID*3
- programsTable[data]={pStart+((collumnID)*pTextLength+((collumnID)*1)),screenY*0.3+rowID*2,pStart+((collumnID)*pTextLength+((collumnID)*1))+pTextLength,1,false,deleteFile}
- term.setCursorPos(pStart+((collumnID)*pTextLength+((collumnID)*1)),screenY*0.3+rowID*2)
- if string.len(data)<pTextLength then
- for i=1,pTextLength-string.len(data) do
- data=data.." "
- end
- end
- term.write(string.sub(data,1,pTextLength))
- end
- term.setTextColor(1)
- term.setBackgroundColor(256)
- for id,data in pairs(programsTable) do
- touchScreenTable[id]=data
- end
- term.setBackgroundColor(256)
- term.setTextColor(1)
- term.setCursorPos(1,2)
- end
- function backFile()
- touchScreenTable={}
- drawDesktop()
- end
- function fileManager()
- touchScreenTable={}
- term.setTextColor(1)
- term.setBackgroundColor(256)
- term.clear()
- term.setBackgroundColor(2)
- for i=1,3 do
- term.setCursorPos(3,i+1)
- term.write(" ")
- if i==2 then
- term.setCursorPos(3,i+1)
- term.write(" edit ")
- end
- end
- term.setBackgroundColor(32)
- for i=1,3 do
- term.setCursorPos(3,i+5)
- term.write(" ")
- if i==2 then
- term.setCursorPos(3,i+5)
- term.write(" new ")
- end
- end
- term.setBackgroundColor(16384)
- for i=1,3 do
- term.setCursorPos(3,i+9)
- term.write(" ")
- if i==2 then
- term.setCursorPos(3,i+9)
- term.write(" delete ")
- end
- end
- term.setBackgroundColor(128)
- for i=1,3 do
- term.setCursorPos(3,i+13)
- term.write(" ")
- if i==2 then
- term.setCursorPos(3,i+13)
- term.write(" back ")
- end
- end
- touchScreenTable["edit"]={2,2,11,3,false,editFile}
- touchScreenTable["new"]={2,6,11,3,false,newFile}
- touchScreenTable["del"]={2,10,11,3,false,delFile}
- touchScreenTable["back"]={2,14,11,3,false,backFile}
- --drawDesktop()
- end
- mainMenuItems={
- ["Shut down"]={['c']=16384,['f']=os.shutdown},
- ["Reboot"]={['c']=32,['f']=os.reboot},
- ["Log off"]={['c']=2,['f']=relogin},
- ["BASH Shell"]={['c']=8,['f']=doDaShell},
- ["Programs"]={['c']=8192,['f']=fileManager},
- }
- function mainMenuFunction()
- if mainmenuShown==nil then
- mainmenuShown=false
- end
- if mainmenuShown==true then
- touchScreenTable={}
- drawDesktop()
- else
- term.setBackgroundColor(128)
- for i=1,6 do
- term.setCursorPos(1,i+1)
- term.write(" ")
- end
- term.setBackgroundColor(128)
- i=2
- for name,data in pairs(mainMenuItems) do
- term.setCursorPos(1,i)
- term.setTextColor(data['c'])
- nameLength=string.len(name)
- if nameLength<9 then
- for g=1,9-nameLength do
- name=name.." "
- end
- end
- term.write(name)
- if data['f']==nil then
- touchScreenTable[name]={1,i,9,0,true}
- else
- touchScreenTable[name]={1,i,9,0,false,data['f']}
- end
- i=i+1
- end
- end
- mainmenuShown=not mainmenuShown
- end
- function backToMainDirectory()
- currentDirectory="users/"..currentUser
- print("Main Directory")
- drawDesktop()
- end
- function desktopEvents()
- while true do
- event,v1,v2,v3,v4,v5=os.pullEvent()
- if event=="mouse_click" then
- button=v1
- x=v2
- y=v3
- for id,data in pairs(touchScreenTable) do
- if button==1 and x>=math.floor(data[1]) and x<=math.floor(data[3]) and y>=math.floor(data[2]) and y<=math.floor(data[2]+data[4]) then
- if data[5] then
- termDisabled=false
- shell.run(currentDirectory.."/"..id)
- drawDesktop()
- termDisabled=true
- elseif fs.isDir(currentDirectory.."/"..id) then
- currentDirectory="users/"..currentUser.."/"..id
- drawDesktop()
- termDisabled=true
- else
- termDisabled=false
- data[6](id)
- termDisabled=true
- end
- end
- end
- elseif event=="char" then
- elseif event=="key" then
- end
- end
- end
- --NanoShell
- function drawShell()
- term.setBackgroundColor(128)
- for i=2,19 do
- term.setCursorPos(1,i)
- if i==2 then
- term.write(" BASH Shell ")
- else
- term.write(" ")
- end
- end
- term.setBackgroundColor(32768)
- for i=3,18 do
- term.setCursorPos(2,i)
- term.write(" ")
- end
- term.setCursorPos(2,3)
- term.setTextColor(1)
- end
- function inputShell()
- term.setCursorPos(2,3)
- term.setTextColor(1)
- repeat
- command=read()
- x,y=term.getCursorPos()
- if string.find(command,"edit")~=nil then
- command=string.gsub(command,"edit ","edit "..currentDirectory.."/")
- term.write(command)
- elseif string.find(command,"list")~=nil then
- command=string.gsub(command,"list","list "..currentDirectory)
- elseif string.find(command,"lua")~=nil then
- command=nil
- print("Access Denied")
- end
- if string.find(command,"edit")~=nil then
- shell.run(command)
- term.setCursorPos(2,y+1)
- drawDesktop()
- drawShell()
- elseif string.find(command,"list")~=nil then
- programs=fs.list(currentDirectory)
- ox,oy=term.getCursorPos()
- term.setCursorPos(2,oy)
- for id,program in pairs(programs) do
- term.write(program.." ")
- end
- term.setCursorPos(2,oy+1)
- elseif command~=nil and command~="stop" and fs.exists(currentDirectory.."/"..command) then
- returned=shell.run(currentDirectory.."/"..command)
- term.setCursorPos(2,y+1)
- else
- if y>=17 then
- drawShell()
- term.setCursorPos(2,3)
- else
- term.setCursorPos(2,y)
- term.write("No such program")
- term.setCursorPos(2,y+1)
- end
- end
- until command=="stop"
- drawDesktop()
- end
- function startOS()
- user = Utente
- pass = proprietario
- drawDesktop()
- end
- startOS()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement