Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- This program are not finished ^_^
- -- I use this program for my computer only
- -- If you need you can get this program and edited to be right for you, enjoy!! ^_^
- -- If the "LuaXML" library not found then exit
- if not require("LuaXML") then print("\nLuaXML library are required\n") return end
- function main()
- local version = "5.0"
- local filepath = "./Enters.xml"
- -- If xml file not found then create one
- if not io.open(filepath, "r+") then
- -- Include the basics
- local f = xml.new("Enters")
- f:append("password")[1] = nil
- f:append("entersNo")[1] = "0"
- xml.save(f, filepath)
- end
- -- Loads the XML file into a lua variable
- local logsFile = xml.load(filepath)
- -- Loads the pass
- local pass = logsFile:find("password")[1] or ""
- -- Loads the same computer time
- local date = os.date("%x %I:%M:%S %p")
- -- Loads how many log there are
- local numOfIds = tonumber(logsFile:find("entersNo")[1])
- local Acces = false
- local isDenieded = false
- -- The last log object (LuaXML object)
- local append
- local function debgPrint(text)
- if not text then text = "" end
- io.write(text,"\n\n")
- end
- -- TODO: find another way to clear the command line
- local function clear()
- io.write("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")
- end
- local function getValue(tag, attrb, value)
- if not logsFile:find(tag) then error("Programming Error: \"tag\" not found,\nat function \"getValue\".\nPlease report this error at programmer email\nbelal2453@gmail.com", 2) end
- for i, n in pairs(logsFile) do
- if string.find(xml.str(n), "<".. tag) and string.find(xml.str(n), attrb.. "=".. "\"".. value) then
- return logsFile[i][1], n
- end
- end
- end
- local function WriteEnter(date)
- if not date then date = os.date("%x %I:%M:%S %p") end
- append = xml.append(logsFile, "log")
- append[1] = tostring(date)
- append["id"] = numOfIds + 1
- append["isConfiemed"] = "false"
- numOfIds = numOfIds + 1
- logsFile:find("entersNo")[1] = numOfIds
- xml.save(logsFile, filepath)
- end
- local function SeeifthePassIscorect()
- local inpass = io.read()
- io.write("\n")
- if inpass == pass then
- append["isConfiemed"] = "true"
- xml.save(logsFile, filepath)
- return true
- else
- return false
- end
- end
- local function ShowunConfirmedEnters()
- local denieds = {}
- for i, n in pairs(logsFile) do
- if string.find(xml.str(n), "isConfiemed=\"false\"") then
- table.insert(denieds, n["id"])
- isDenieded = true
- end
- end
- return denieds
- end
- local function welcome()
- local denieds = ShowunConfirmedEnters()
- debgPrint("Welcome, Mr. Bilal.")
- if isDenieded == true and (pass ~= "" and pass) then
- debgPrint("There are some Denieded Enters, Do you want to see Them? Y\\N")
- if io.read() == "y" then
- io.write("\n")
- for i, l in pairs(denieds) do io.write("At line number: ", l, "\n", "At date: ", getValue("log", "id", tostring(l)), "\n\n") end
- end
- end
- if pass == "" or not pass then
- io.write("There are no password sets on programe;\nPlease write your new password here: \n")
- repeat
- local retypedPass
- local oy = false
- local newPass = io.read()
- if not newPass or newPass == "" then
- io.write("Sorry, you may enter a new password\nTo work on this programe\n\n")
- io.write("Enter your new password: \n")
- else
- io.write("\nNow please retype your new password: \n")
- retypedPass = io.read()
- if (not retypedPass or retypedPass == "") or (newPass ~= retypedPass) then
- io.write("\n\nInvaild retyped password.\nSorry you may Re enter the password\n")
- elseif newPass == retypedPass then
- io.write("Your new password sets TO: \n\n".. newPass.. "\n\n")
- logsFile:find("password")[1] = tostring(newPass)
- xml.save(logsFile, filepath)
- oy = true
- end
- end
- until oy == true
- end
- end
- local commands =
- {
- ["version"] = "The version is: ".. version,
- ["confirm"] = {
- line = function(...)
- line = {}
- for i, n in pairs(...) do table.insert(line, n) end
- local denieds = ShowunConfirmedEnters()
- local fnd = false
- if #denieds <= 0 then debgPrint("There are no denieded enters.") return false end
- for i, n in pairs(logsFile) do
- for v, j in pairs(line) do
- if string.find(xml.str(n), "<log ") and string.find(xml.str(n), "id=\"".. j) then
- logsFile[i]["isConfiemed"] = "true"
- xml.save(logsFile, filepath)
- debgPrint("Line number ".. logsFile[i]["id"].. " has confirmed.")
- fnd = true
- break
- end
- end
- end
- if fnd ~= true then debgPrint("Line not found!!") return false end
- end,
- all = function()
- local denieds = ShowunConfirmedEnters()
- local count = 0
- if #denieds == 0 then debgPrint("There are no denieded enters.") return false end
- for i, n in pairs(logsFile) do
- if string.find(xml.str(n), "<log ") and string.find(xml.str(n), "isConfiemed=\"false") then
- debgPrint("Line number ".. logsFile[i]["id"].. " has confirmed.")
- logsFile[i]["isConfiemed"] = "true"
- xml.save(logsFile, filepath)
- end
- count = count + 1
- end
- debgPrint("\nAll Enters are confirmed.")
- isDenieded = false
- return true
- end,
- usage = "Syntix: Confirm [ all, line \"number of line\" ]\nUsage: This Command is to confirms Enters."
- },
- ["show"] = {
- denieded = function()
- local denieds = ShowunConfirmedEnters()
- local fnd = false
- for i, n in pairs(denieds) do if n then fnd = true end end
- if isDenieded == false or fnd == false then
- debgPrint("There are no denieded Enters!!")
- return false
- end
- for i, l in pairs(denieds) do
- io.write("At line number: ", l, "\n", "At date: ", getValue("log", "id", l), "\n\n")
- end
- end,
- all = function()
- local fnd = false
- for i, v in pairs(logsFile) do
- if string.find(xml.str(v), "<log ") then
- fnd = true
- io.write("At line number ".. v["id"].. ":\n".. v[1].. " ")
- if v["isConfiemed"] == "true" then
- io.write("Confirmed\n\n")
- else
- io.write("\n\n")
- end
- end
- end
- if fnd == false then debgPrint("There are no enters to show it.") end
- end,
- usage = "Syntix: Show [ all, denieded ]\nUsage: This command is to show the Enters"
- },
- ["delete"] = {
- line = function(...)
- local count = 1
- local fnd = false
- if not ... then debgPrint("Please enter line number to delete it.") return false end
- -- for i, n in pairs(...) do if not n or not tonumber(n) then debgPrint("Please enter line number to delete it.") return false end end
- -- for i, n in pairs(...) do if tonumber(n) > numOfIds or tonumber(n) <= 0 then debgPrint("There are no line like that.") return false end end
- for i, n in ipairs(logsFile) do
- for v, l in ipairs(...) do
- if string.find(xml.str(n), "<log ")
- and string.find(xml.str(n), "id=\"".. l.. "\"") then
- logsFile[i] = ""
- debgPrint("Line number: ".. n["id"].. " is deleted.\n")
- fnd = true
- break
- end
- end
- end
- if fnd ~= true then debgPrint("There are no line like that.") return false end
- for i, n in pairs(logsFile) do
- if string.find(xml.str(n), "<log ")
- and n["id"] ~= count then
- logsFile[i]["id"] = count
- end
- if string.find(xml.str(n), "<log ") then count = count + 1 end
- end
- numOfIds = count - 1
- logsFile:find("entersNo")[1] = count - 1
- xml.save(logsFile, filepath)
- return true
- end,
- all = function()
- debgPrint("Are you sure to delete all enters? Y\\N\n")
- local ins = io.read()
- io.write("\n")
- if ins ~= "y" and ins ~= "Y" then return false end
- for i, n in pairs(logsFile) do
- if string.find(xml.str(n), "<log") then
- logsFile[i] = ""
- end
- end
- logsFile:find("entersNo")[1] = "0"
- numOfIds = 0
- xml.save(logsFile, filepath)
- debgPrint("All enters are deleted.")
- return true
- end,
- denieded = function()
- local count = 1
- local denieds = ShowunConfirmedEnters()
- local fnd = false
- for i, n in pairs(denieds) do if n then fnd = true end end
- if fnd ~= true then debgPrint("There are no denieds enters!!") return false end
- for i, n in pairs(logsFile) do
- for y, x in pairs(denieds) do
- if string.find(xml.str(n), "<log ")
- and string.find(xml.str(n), "id=\"".. x.."\"") then
- debgPrint("Line number ".. logsFile[i]["id"].. " was deleted.")
- logsFile[i] = ""
- break
- end
- end
- end
- for i, n in pairs(logsFile) do
- if string.find(xml.str(n), "<log ")
- and n["id"] ~= count then
- logsFile[i]["id"] = count
- end
- if string.find(xml.str(n), "<log ") then count = count + 1 end
- end
- numOfIds = count - #denieds
- logsFile:find("entersNo")[1] = count - #denieds
- xml.save(logsFile, filepath)
- return true
- end,
- usage = "Syntix: Delete [ all, denieded, line \"line number\" ]\nUsage: This command is to delete Enters."
- },
- ["enter"] = function() io.write("Enter password: ") WriteEnter() SeeifthePassIscorect() end,
- ["clear"] = function() clear() end,
- -- ["backup"] = function(...) if ... == nil then backup() else backup({...}) end debgPrint("Backup Done.") end,
- --
- help =
- [[
- version Display vesion of this programs.
- Syntix: version
- confirm Confirm any denieded Enter.
- Syntix: confirm [ all, line "line number" ]
- show Display Enters.
- Syntix: show [ all, denieded ]
- delete Delete Enters.
- Syntix: delete [ all, denieded, line "line number"]
- enter reLogin with password.
- Syntix: enter (Password needed)]]
- }
- local function pCommand()
- io.write("Commander> ")
- local command = io.read()
- io.write("\n")
- local returnedCommand = nil
- local commandArray = {}
- command = tostring( command )
- for i in string.gmatch(command, "%S+") do
- table.insert(commandArray, i)
- end
- for v in pairs(commands) do
- if v == commandArray[1] then returnedCommand = commands[commandArray[1]] end
- end
- return commandArray, returnedCommand
- end
- local function dCommand()
- logsFile = xml.load(filepath)
- local commandArray, command = pCommand()
- local params = {}
- for i, n in pairs(commandArray) do
- table.insert(params, n)
- end
- table.remove(params, 1)
- table.remove(params, 1)
- -- If type of command is table then call the params
- if (type(command) == "table") then
- local found = false
- if (#commandArray <= 1) then debgPrint(command.usage or commands.help) return end
- for i in pairs(command) do
- if i == commandArray[2] then
- if type(command[commandArray[2]]) == "function" then command[commandArray[2]](params)
- elseif type(command[commandArray[2]]) == "string" or type(command[commandArray[2]]) == "number" then debgPrint(command[commandArray[2]])
- else debgPrint("Command not found!!", "\n") end
- found = true
- end
- end
- if found ~= true then debgPrint(command.usage or command.help) return end
- -- If type of command is function then call it
- elseif type(command) == "function" then
- command(commandArray[2], commandArray[3], commandArray[4], commandArray[5])
- -- If type of command is strin then debug it
- elseif type(command) == "string" or type(command) == "number" then
- debgPrint(command)
- -- and finally if the command was exit then quit
- elseif commandArray[1] == "exit" then
- return true
- -- If command not found then return false ( to commandsloop function )
- else
- return false
- end
- end
- local function commandsLoop()
- repeat
- local status = dCommand()
- if status == false then debgPrint("Command not found!!", "\n") end
- until status == true
- end
- WriteEnter(date)
- if pass == "" or not pass then
- Acces = true
- append["isConfiemed"] = "true"
- else
- Acces = SeeifthePassIscorect()
- end
- if Acces == true then
- welcome()
- commandsLoop()
- end
- end
- -- if arg and #arg >= 3 then for i, n in pairs(arg) do print(i, n) end end
- local err, messg = pcall(main)
- if not err then print(messg,"\n\n\n","Press enter key to exit\n") io.read() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement