Skip to content

Instantly share code, notes, and snippets.

@operator-DD3
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save operator-DD3/89016f7d52c58a8b05d9 to your computer and use it in GitHub Desktop.
Save operator-DD3/89016f7d52c58a8b05d9 to your computer and use it in GitHub Desktop.
[Lua] XSA Database v1.0
-- XSA DATABASE (XSADB)
-- Copyright 2015
-- XOUT SECURITY AGENCY (XSA)
function wrap(str, limit, indent, indent1) indent = indent or "" indent1 = indent1 or indent limit = limit or 72 local here = 1-#indent1 return indent1..str:gsub("(%s+)()(%S+)()", function(sp, st, word, fi) if fi-here > limit then here = st - #indent return "\n"..indent..word end end) end
function uuid()
my_uuid = ""
t = {[0] = '0', [1] = '1', [2] = '2', [3] = '3', [4] = '4', [5] = '5', [6] = '6', [7] = '7', [8] = '8', [9] = '9', [10] = 'a', [11] = 'b', [12] = 'c', [13] = 'd', [14] = 'e', [15] = 'f'}
for i = 1, 32 do
if i == 9 then
my_uuid=my_uuid.."-"
elseif i == 13 then
my_uuid = my_uuid..'-'
elseif i == 17 then
my_uuid = my_uuid..'-'
elseif i == 21 then
my_uuid = my_uuid..'-'
end
my_uuid = my_uuid .. t[math.random(16)-1]
end
return (my_uuid)
end
db = {["XSA"] = "\27[3m\27[31mXOUT SECURITY AGENCY - Official Document\27[0m "}
filename = ""
version = "3.0.0823\27[0m"
print("\27[32mX.S.A. DataBase Client: \27[0m" .. version)
while #filename == 0 do
io.write("Database: ")
filename=io.read()
end
xsadb = {}
xsadb.set = function(s) table.insert(db, s) end
print("\27[32mXSADB Status:\27[0m Opening Database.")
fp, err = io.open( filename, "r" )
if fp ~= nil then
while true do
line = fp:read("*line*")
if line == nil then break end
xsadb.set(line)
end
fp:close()
end
xsadb.showAll = function() print("\n\27[32m\27[1mKey", "Value")
print("--- -----\27[0m")
for k,v in pairs(db) do
print("\27[32m\27[1m"..k.."\27[0m",wrap(v,72,"\t",""),"\n")
end
print("\27[32m\27[1m--- -----\27[0m")
end
xsadb.search = function()
io.write("Search: ")
query = io.read()
print()
print("\27[32m-------- Search Results --------")
found = 0
print("\27[1mKey", "Value")
print("--- -----\27[0m")
for k,v in pairs(db) do
if string.find(string.lower(v),string.lower(query)) then
found = found + 1
--print(k,v,"\n")
print("\27[32m" .. k .. "\27[0m",string.gsub(wrap(v,72,"\t",""),query,"\27[4m\27[1m\27[34m" .. query .. "\27[0m"),"\n")
end
end
print()
print("\27[1m\27[32mQuery:\27[0m " .. query)
print("\27[1m\27[32mSearch Found:\27[0m " .. found .. "\27[0m")
print("\27[32m---------- End Search ----------\27[0m")
end
xsadb.delete = function()
io.write("Key ID: ")
local temp = io.read()
if tonumber(temp) then
local n = tonumber(temp)
db[n] = nil
else
print("\27[31mKey ID MUST be a Number.\27[0m")
end
end
-- MAIN PROGRAM LOOP
print("\27[32mXSADB Console:\27[0m READY")
io.write("\n#! ")
kmnd = io.read()
while kmnd ~= "exit" do
if kmnd == "set" then
io.write("Value: ")
xsadb.set(io.read())
elseif kmnd == "search" then
xsadb.search()
elseif kmnd == "show" then
xsadb.showAll()
elseif kmnd == "delete" then
xsadb.delete()
-- elseif kmnd == "sort" then
-- table.sort(db)
elseif kmnd == "help" then
print("\nXSADB: Help System")
print("-------------------")
print("show - List all database")
print("set - Set into database")
print("delete - Delete from database")
print("search - Search for value (case insensitive)")
-- print("sort - Sort the database")
print("help - Show this screen")
print("version - Display XSADB Version")
print("exit - Exit the application")
elseif kmnd == "version" then
print("\27[32mXSADB Version:\27[0m " .. version)
else
print("\27[31mUnknown Command\27[0m")
end
io.write("\n#! ")
kmnd = io.read()
end
print("\27[32m\nXSADB Status:\27[0m Saving Database.")
os.remove(filename)
fp = io.open(filename, "w")
if fp ~= nil then
for k,v in ipairs(db) do
fp:write(v .. "\n")
end
fp:close()
end
print("\27[32mXSADB Status: \27[0m Save Complete.\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment