Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- verze = "23.0402.R1"
- logs = false
- term.clear()
- term.setCursorPos(1,1)
- local idPC = os.getComputerID()
- local ADmode = false
- local IsAdmin = false
- dofile("/C/system/api/APIS.lua")
- if not fs.exists ("/C/system/.core/SMBsecure.cfg") then
- local data = fs.open("/C/system/.core/SMBsecure.cfg", "w")
- data.writeLine("C")
- data.writeLine("rom")
- data.writeLine("startup")
- data.close()
- end
- if fs.exists("/C/system/server/rules/AD/") and fs.exists("/C/service/AD.lua") then
- ADmode = true
- end
- if fs.exists("/C/system/.core/defmodem") then
- local data = fs.open ("/C/system/.core/defmodem","r")
- modemPos = data.readLine()
- data.close()
- if not modemPos then
- modemPos = "offline"
- end
- else
- modemPos = "offline"
- end
- if not (modemPos == "offline") then
- modem = peripheral.wrap(modemPos)
- modem.open(idPC)
- print("Samba server, version "..verze..", ID serveru: "..idPC)
- if ADmode then print"sluzba Active directory je aktivni" end
- else
- term.setTextColor(colors.red)
- print("Error, you must configure the modem first")
- modem.open("Error")
- end
- function logy(Zlog)
- cas = (textutils.formatTime(os.time(), true))
- local l = fs.open("/C/system/server/rules/AD/log","a")
- l.writeLine(cas..": "..Zlog)
- l.close()
- end
- function bar(styl, text)
- if (styl == "OK") then -- Uspech
- term.setTextColor(colors.green)
- elseif (styl == "FAIL") then -- Neuspesne
- term.setTextColor(colors.red)
- elseif (styl == "INFO") then -- Informativni
- term.setTextColor(colors.lightBlue)
- elseif (styl == "def") then -- defaultni
- term.setTextColor(colors.white)
- elseif (styl == "PRO") then -- Progress
- term.setTextColor(colors.yellow)
- else
- styl = "def"
- term.setTextColor(colors.white)
- end
- if not (styl == "def") then
- zprava = ("["..textutils.formatTime(os.time(), true).."] ["..styl.."] "..text)
- else
- zprava = text
- end
- if logs then
- logy(zprava)
- end
- print (zprava)
- end
- local function defaultV()
- idComp = nil
- filePath = ""
- exfile = false
- user = "guest"
- pass = ""
- end
- function findFile(filePath, inverze)
- if fs.exists (filePath) then
- if inverze then
- bar("FAIL", "Soubor "..filePath.." nalezen!")
- else
- bar("OK", "Soubor "..filePath.." nalezen!")
- end
- exfile = true
- else
- if inverze then
- bar("OK", "Soubor "..filePath.." nenalezen!")
- else
- bar("FAIL", "Soubor "..filePath.." nenalezen!")
- end
- exfile = false
- end
- if inverze then
- modem.transmit(tonumber(idComp),992,not exfile)
- else
- modem.transmit(tonumber(idComp),992,exfile)
- end
- end
- function fail() modem.transmit(tonumber(idComp),992,false) defaultV() end
- function copyFile(filePath)
- if not (fs.isDir(filePath)) then
- if exfile then
- local data = fs.open(filePath, "r")
- obsah = data.readAll()
- data.close()
- modem.transmit(tonumber(idComp),994,obsah)
- bar("OK", "Soubor byl odeslan na adresu: "..idComp)
- end
- else
- bar("FAIL", "Slozku nelze kopirovat jako soubor!")
- end
- end
- function deleteFile(filePath)
- if exfile then
- fs.delete(filePath)
- bar("OK", "Soubor byl smazan, PC: "..idComp)
- modem.transmit(tonumber(idComp),997,"Soubor byl smazan!")
- end
- end
- function struktura(filePath)
- if (filePath == nil) then
- fail()
- else
- function detekce(slv)
- if (slv == "") then return false end
- local dct = string.find(filePath.."/"..name, slv)
- if dct ~= nil then
- if dct > 0 then
- return true
- else return false
- end
- end
- end
- local function scann()
- for i=1,#BL do
- if (detekce(BL[i])) then
- return true
- end
- end
- end
- BL = {}
- local e = 0
- if fs.exists("/C/system/.core/SMBsecure.cfg") then
- local blackList = fs.open("/C/system/.core/SMBsecure.cfg", "r")
- repeat
- e = e+1
- BL[e] = blackList.readLine()
- until BL[e] == nil
- blackList.close()
- end
- logy(filePath)
- if fs.exists(filePath) then
- if fs.isDir(filePath) then
- if (fs.list(filePath)) then
- cDir = fs.list(filePath)
- local data = fs.open("/C/system/RAM/signature.tmp", "w")
- for a = 1,#cDir do
- name = tostring(cDir[a])
- if (string.sub(cDir[a],1,1) == ".") or scann() then
- bar("FAIL", "Pristup odepren!")
- else
- if fs.isDir(filePath.."/"..name) then
- data.writeLine(name.."*")
- else
- data.writeLine(name)
- end
- end
- end
- data.close()
- exfile=true copyFile("/C/system/RAM/signature.tmp")
- bar("OK", "Struktura odeslana na PC "..idComp)
- defaultV()
- end
- else
- bar("FAIL", "Neni signatura, ale soubor!")
- fail()
- end
- else
- bar("FAIL", "Slozka nenalezena!")
- fail()
- end
- end
- end
- function overit()
- if fs.exists ("/C/system/server/rules/AD/Users/"..user.."/.data") then
- bar("OK", "Uzivatel existuje!")
- local f = fs.open("/C/system/server/rules/AD/Users/"..user.."/.data", "r")
- Su=f.readLine()
- Sp=f.readLine()
- Fname=f.readLine()
- Lname=f.readLine()
- perm=f.readLine()
- if (perm == "t") then IsAdmin = true end
- f.close()
- if user == Su then
- if pass == Sp then
- bar("OK", "Uzivatel overen!")
- return true
- else
- bar("FAIL", "Spatne heslo!")
- modem.transmit(tonumber(idComp),999,"pass")
- fail()
- return false
- end
- else
- bar("FAIL", "Spatne uzivatelske jmeno!")
- modem.transmit(tonumber(idComp),999,"user")
- fail()
- return false
- end
- else
- bar("FAIL", "Pristup uzivateli odepren!")
- modem.transmit(tonumber(idComp),999,"user")
- fail()
- end
- end
- function createFile(filePath)
- if not exfile then
- create_file = fs.open(filePath,"w")
- create_file.close()
- bar("OK", "Soubor uspesne vytvoren!")
- modem.transmit(tonumber(idComp),997,"Soubor uspesne vytvoren!")
- else
- bar("FAIL", "Soubor jiz existuje!")
- modem.transmit(tonumber(idComp),997,"Soubor jiz existuje, nevytvoreno!")
- end
- end
- function createFolder(filePath)
- if not exfile then
- fs.makeDir(filePath)
- bar("OK", "Slozka uspesne vytvorena!")
- modem.transmit(tonumber(idComp),997,"Slozka uspesne vytvorena!")
- else
- bar("FAIL", "Slozka jiz existuje!")
- modem.transmit(tonumber(idComp),997,"Slozka jiz existuje, nevytvoreno!")
- end
- end
- function ulozit(filePath)
- local file = fs.open(filePath,"w")
- file.write(obsah)
- file.close()
- bar("OK", "Soubor byl ulozen, z PC: "..idComp)
- end
- function prijmout ()
- local _, side, freq, rfreq, message = os.pullEvent('modem_message')
- if (rfreq == 990) then
- bar("INFO", "Zadost o zpracovani udaju.")
- idComp = message
- bar("PRO", "Adresa zarizeni: "..idComp)
- end
- if (rfreq == 998) then
- user = message
- bar("INFO", "Jmeno uzivatele: "..user)
- end
- if (rfreq == 999) then
- pass = message
- bar("INFO", "Heslo prijato!")
- end
- if (rfreq == 991) then
- filePath = message
- bar("INFO", "Zadana cesta!")
- end
- if (rfreq == 993) then
- if overit() then
- if (message == "copy") then
- findFile(filePath)
- copyFile(filePath)
- elseif(message == "cut") then
- findFile(filePath)
- copyFile(filePath)
- deleteFile(filePath)
- elseif(message == "signature") then
- struktura(filePath)
- elseif(message == "delete") then
- findFile(filePath)
- deleteFile(filePath)
- elseif(message == "newFile") then
- findFile(filePath, true)
- createFile(filePath)
- elseif(message == "newFolder") then
- findFile(filePath, true)
- createFolder(filePath)
- elseif(message == "paste") then
- ulozit(filePath)
- end
- end
- end
- if (rfreq == 994) then
- obsah = message
- bar("INFO", "Obsah souboru prijat!")
- end
- prijmout()
- end
- defaultV()
- prijmout()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement