diff --git a/example-app/mimes.json b/example-app/mimes.json deleted file mode 100644 index 8efc9a6..0000000 --- a/example-app/mimes.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "viz": { - "mime": "text/vnd.graphviz", - "binary": false - }, - "py": { - "mime": "text/x-python", - "binary": false - }, - "coffee":{ - "mime": "text/vnd.coffeescript", - "binary": false - }, - "apj": { - "mime": "text/antos-project", - "binary": false - } -} \ No newline at end of file diff --git a/example-app/os/apigateway.lua b/example-app/os/apigateway.lua deleted file mode 100644 index fd173ef..0000000 --- a/example-app/os/apigateway.lua +++ /dev/null @@ -1,97 +0,0 @@ -local use_ws = false -if REQUEST.query and REQUEST.query.ws == "1" then - -- override the global echo command - echo = std.ws.swrite - use_ws = true -else - std.json() -end -local exec_with_user_priv = function(data) - local uid = unix.uid(SESSION.iotos_user) - if not unix.setgid(uid.gid) or not unix.setuid(uid.id) then - echo("Cannot set permission to execute the code") - return - end - local r,e - e = "{'error': 'Unknow function'}" - if data.code then - r,e = load(data.code) - if r then - local status,result = pcall(r) - if(status) then - echo(JSON.encode(result)) - else - echo(result) - end - else - echo(e) - end - elseif data.path then - r,e = loadfile(data.path) - if r then - local status,result = pcall(r, data.parameters) - if(status) then - echo(JSON.encode(result)) - else - echo(result) - end - else - echo(e) - end - else - echo(e) - end -end - -if(is_auth()) then - local pid = unix.fork() - if(pid == -1) then - echo("{'error':'Cannot create process'}") - elseif pid > 0 then -- parent - -- wait for the child exit - unix.waitpid(pid) - print("Parent exit") - else -- child - if use_ws then - if std.ws.enable() then - -- read header - local header = std.ws.header() - if header then - if header.mask == 0 then - print("Data is not masked") - std.ws.close(1012) - elseif header.opcode == std.ws.CLOSE then - print("Connection closed") - std.ws.close(1000) - elseif header.opcode == std.ws.TEXT then - -- read the file - local data = std.ws.read(header) - if data then - data = (JSON.decodeString(data)) - exec_with_user_priv(data) - std.ws.close(1011) - else - echo("Error: Invalid request") - std.ws.close(1011) - end - end - else - std.ws.close(1011) - end - else - print("Web socket is not available.") - end - else - if REQUEST.query.json then - data = JSON.decodeString(REQUEST.query.json) - std.json() - exec_with_user_priv(data) - else - fail("Unkown request") - end - end - print("Child exit") - end -else - echo('{"error":"User unauthorized. Please login"}') -end \ No newline at end of file diff --git a/example-app/os/db/delete.lua b/example-app/os/db/delete.lua deleted file mode 100644 index 276bae6..0000000 --- a/example-app/os/db/delete.lua +++ /dev/null @@ -1,29 +0,0 @@ -auth_or_die("User unauthorized. Please login") -local rq = (JSON.decodeString(REQUEST.query.json)) -if(rq ~= nil and rq.table ~= nil) then - local model = require("db.model").get(SESSION.iotos_user, rq.table, nil) - local ret - if model == nil then - fail("Cannot get table metadata:"..rq.table) - else - if(rq.id == nil ) then - if(rq.cond) then - ret = model:delete(rq.cond) - model:close() - else - model:close() - return fail("Unknow element to delete") - end - else - ret = model:deleteByID(rq.id) - model:close() - end - if ret then - result(ret) - else - fail("Querry error or database is locked") - end - end -else - fail("Unknown database request") -end \ No newline at end of file diff --git a/example-app/os/db/get.lua b/example-app/os/db/get.lua deleted file mode 100644 index fbb83de..0000000 --- a/example-app/os/db/get.lua +++ /dev/null @@ -1,19 +0,0 @@ -auth_or_die("User unauthorized. Please login") -local rq = (JSON.decodeString(REQUEST.query.json)) -if(rq ~= nil and rq.table ~= nil) then - local model = require("db.model").get(SESSION.iotos_user, rq.table, nil) - local ret - if model == nil then - fail("Cannot get table metadata:"..rq.table) - else - if(rq.id == nil ) then - ret = model:getAll() - else - ret = model:get(rq.id) - end - model:close() - result(ret) - end -else - fail("Unknown database request") -end \ No newline at end of file diff --git a/example-app/os/db/model.lua b/example-app/os/db/model.lua deleted file mode 100644 index 8dcad32..0000000 --- a/example-app/os/db/model.lua +++ /dev/null @@ -1,20 +0,0 @@ -local model = {} - -model.get = function(name, tbl, data) - local db = DBModel:new{db = name, name=tbl} - db:open() - if db:available() then return db end - if data == nil then return nil end - local meta = {} - --print(JSON.encode(data)) - for k,v in pairs(data) do - if type(v) == "number" then - meta[k] = "NUMERIC" - else - meta[k] = "TEXT" - end - end - db:createTable(meta) - return db -end -return model \ No newline at end of file diff --git a/example-app/os/db/save.lua b/example-app/os/db/save.lua deleted file mode 100644 index a57b356..0000000 --- a/example-app/os/db/save.lua +++ /dev/null @@ -1,24 +0,0 @@ -auth_or_die("User unauthorized. Please login") -local rq = (JSON.decodeString(REQUEST.query.json)) -if(rq ~= nil and rq.table ~= nil) then - local model = require("db.model").get(SESSION.iotos_user,rq.table, rq.data) - local ret - if model == nil then - fail("Cannot get table metadata:"..rq.table) - else - if(rq.data.id ~= nil ) then - rq.data.id = tonumber(rq.data.id) - ret = model:update(rq.data) - else - ret = model:insert(rq.data) - end - model:close() - if ret == true then - result(ret) - else - fail("Cannot modify/update table "..rq.table) - end - end -else - fail("Unknown database request") -end \ No newline at end of file diff --git a/example-app/os/db/select.lua b/example-app/os/db/select.lua deleted file mode 100644 index 8441bd8..0000000 --- a/example-app/os/db/select.lua +++ /dev/null @@ -1,20 +0,0 @@ -auth_or_die("User unauthorized. Please login") -local rq = (JSON.decodeString(REQUEST.query.json)) -if(rq ~= nil and rq.table ~= nil) then - local model = require("db.model").get(SESSION.iotos_user,rq.table, nil) - local ret - if model == nil then - fail("Cannot get table metadata:"..rq.table) - else - if(rq.cond == nil ) then - model:close() - return fail("Unknow condition") - else - ret = model:find(rq.cond) - end - model:close() - result(ret) - end -else - fail("Unknown database request") -end \ No newline at end of file diff --git a/example-app/os/fs/delete.lua b/example-app/os/fs/delete.lua deleted file mode 100644 index 64638de..0000000 --- a/example-app/os/fs/delete.lua +++ /dev/null @@ -1,15 +0,0 @@ -auth_or_die("User unauthorized. Please login") - -local vfs = require("fs.vfs") -local rq = (JSON.decodeString(REQUEST.query.json)) - -if rq ~= nil then - local r,e = vfs.delete(rq.path) - if r then - result(r) - else - fail(e) - end -else - fail("Uknown request") -end \ No newline at end of file diff --git a/example-app/os/fs/exists.lua b/example-app/os/fs/exists.lua deleted file mode 100644 index 522f8b3..0000000 --- a/example-app/os/fs/exists.lua +++ /dev/null @@ -1,10 +0,0 @@ -auth_or_die("User unauthorized. Please login") - -local vfs = require("fs.vfs") -local rq = (JSON.decodeString(REQUEST.query.json)) - -if rq ~= nil then - result(vfs.exists(rq.path)) -else - fail("Uknown request") -end diff --git a/example-app/os/fs/fileinfo.lua b/example-app/os/fs/fileinfo.lua deleted file mode 100644 index 9ddc6cf..0000000 --- a/example-app/os/fs/fileinfo.lua +++ /dev/null @@ -1,8 +0,0 @@ -auth_or_die("User unauthorized. Please login") -local vfspath = (JSON.decodeString(REQUEST.query.json)).path -local r,m = require("fs.vfs").fileinfo(vfspath) -if r then - result(m) -else - fail(m) -end diff --git a/example-app/os/fs/fsconf.lua.tpl b/example-app/os/fs/fsconf.lua.tpl deleted file mode 100644 index d3a53a3..0000000 --- a/example-app/os/fs/fsconf.lua.tpl +++ /dev/null @@ -1,6 +0,0 @@ - -local conf = { - home="/Users/%s/tmp/", - shared="/Users/%s/tmp/Public/" -} -return conf \ No newline at end of file diff --git a/example-app/os/fs/fsh.lua b/example-app/os/fs/fsh.lua deleted file mode 100644 index 1fc0998..0000000 --- a/example-app/os/fs/fsh.lua +++ /dev/null @@ -1,14 +0,0 @@ -local handler - -handler = function(str) - local func = str:match("^%a+/") - if func == "get/" then - require("fs.get")(str:gsub(func,"")) - elseif func == "shared/" then - require("fs.shared").get(str:gsub(func,"")) - else - fail("Action is not supported: "..func) - end -end - -return handler diff --git a/example-app/os/fs/get.lua b/example-app/os/fs/get.lua deleted file mode 100644 index c4acad8..0000000 --- a/example-app/os/fs/get.lua +++ /dev/null @@ -1,40 +0,0 @@ -local get -get = function(uri) - vfsfile = utils.decodeURI(uri) - auth_or_die("User unauthorized. Please login") - local r,m = require("fs.vfs").checkperm(vfsfile,'read') - if r then - local mime = std.mimeOf(m) - if mime == "audio/mpeg" then - local finfo = unix.file_stat(m) - local len = tostring(math.floor(finfo.size)) - local len1 = tostring(math.floor(finfo.size-1)) - std.status(200, "OK") - std.custom_header("Pragma","public") - std.custom_header("Expires","0") - std.custom_header("Content-Type",mime) - std.custom_header("Content-Length",len) - std.custom_header("Content-Disposition","inline; filename="..std.basename(m)) - std.custom_header("Content-Range:","bytes 0-"..len1.."/"..len) - std.custom_header("Accept-Ranges","bytes") - std.custom_header("X-Pad", "avoid browser bug") - std.custom_header("Content-Transfer-Encoding", "binary") - std.custom_header("Cache-Control","no-cache, no-store") - std.custom_header("Connection", "Keep-Alive") - std.custom_header("Etag","a404b-c3f-47c3a14937c80") - std.header_flush() - else - std.header(mime) - end - - if std.is_bin(m) then - std.fb(m) - else - std.f(m) - end - else - fail(m) - end -end - -return get; diff --git a/example-app/os/fs/mkdir.lua b/example-app/os/fs/mkdir.lua deleted file mode 100644 index 5ce7334..0000000 --- a/example-app/os/fs/mkdir.lua +++ /dev/null @@ -1,11 +0,0 @@ -auth_or_die("User unauthorized. Please login") - -local rq = (JSON.decodeString(REQUEST.query.json)) - -if rq ~= nil then - local r,m = require("fs.vfs").mkdir(rq.path) - if r then result(r) else fail(m) end -else - fail("Uknown request") -end - diff --git a/example-app/os/fs/move.lua b/example-app/os/fs/move.lua deleted file mode 100644 index d2ba6ac..0000000 --- a/example-app/os/fs/move.lua +++ /dev/null @@ -1,13 +0,0 @@ -auth_or_die("User unauthorized. Please login") - -local rq = (JSON.decodeString(REQUEST.query.json)) - -if rq ~= nil then - local r,m = require("fs.vfs").move(rq.src,rq.dest) - if r then result(r) else fail(m) end -else - fail("Uknown request") -end - - - diff --git a/example-app/os/fs/publish.lua b/example-app/os/fs/publish.lua deleted file mode 100644 index 3006605..0000000 --- a/example-app/os/fs/publish.lua +++ /dev/null @@ -1,36 +0,0 @@ -auth_or_die("User unauthorized. Please login") - -local rq = (JSON.decodeString(REQUEST.query.json)) - -if rq ~= nil then - local p = nil - if rq.publish then - p = require("fs.vfs").ospath(rq.path) - else - p = require("fs.shared").ospath(rq.path) - end - local user = SESSION.iotos_user - local uid = unix.uid(user) - local st = unix.file_stat(p) - if uid.id ~= st.uid then die("Only the owner can share or unshare this file") end - local entry = { sid = std.sha1(p), user = SESSION.iotos_user, path = p, uid = uid.id } - local db = require("db.model").get("sysdb", "shared", entry) - if db == nil then die("Cannot get system database") end - local cond = nil - if rq.publish then - cond = { exp = { ["="] = { path = p } } } - local data = db:find(cond) - if data == nil or data[0] == nil then - -- insert entry - db:insert(entry) - end - else - cond = { ["="] = { sid = rq.path } } - db:delete(cond) - end - db:close() - result(entry.sid) - -else - fail("Uknown request") -end \ No newline at end of file diff --git a/example-app/os/fs/scandir.lua b/example-app/os/fs/scandir.lua deleted file mode 100644 index 65947b4..0000000 --- a/example-app/os/fs/scandir.lua +++ /dev/null @@ -1,10 +0,0 @@ -auth_or_die("User unauthorized. Please login") -local vfspath = (JSON.decodeString(REQUEST.query.json)).path -local r = require("fs.vfs").readDir(vfspath) -if r == nil then - fail("Resource not found") -else - --print(JSON.encode(readDir(ospath, vfspath))) - result(r) -end - diff --git a/example-app/os/fs/shared.lua b/example-app/os/fs/shared.lua deleted file mode 100644 index d184abb..0000000 --- a/example-app/os/fs/shared.lua +++ /dev/null @@ -1,52 +0,0 @@ -local shared = {} -shared.get = function(sharedid) - if sharedid == "all" then - -- get all shared files - local db = require("db.model").get("sysdb", "shared", nil) - if db == nil then die("Cannot get shared database") end - local data = db:getAll() - if data == nil then die("No file found") end - local i = 1 - local ret = {} - for k,v in pairs(data) do - if(unix.exists(v.path)) then - local r = unix.file_stat(v.path) - if(r.error == nil) then - r.path = "shared://"..v.sid - r.filename = std.basename(v.path) - if r.mime == "application/octet-stream" then - r.mime = std.extra_mime(r.filename) - end - ret[i] = r - i = i+1 - end - else - local cond = { ["="] = { sid = v.sid } } - db:delete(cond) - end - end - db:close() - --std.json() - result(ret) - else - - local p = shared.ospath(sharedid) - std.header(std.mimeOf(p)) - if std.is_bin(p) then - std.fb(p) - else - std.f(p) - end - end -end - -shared.ospath = function(sharedid) - local db = require("db.model").get("sysdb", "shared", nil) - if db == nil then die("Cannot get shared database") end - local cond = { exp = { ["="] = { sid = sharedid } } } - local data = db:find(cond) - db:close() - if data == nil or data[1] == nil then die("Cannot get shared file with: "..sharedid) end - return data[1].path -end -return shared; diff --git a/example-app/os/fs/upload.lua b/example-app/os/fs/upload.lua deleted file mode 100644 index 8f07c4d..0000000 --- a/example-app/os/fs/upload.lua +++ /dev/null @@ -1,8 +0,0 @@ -auth_or_die("User unauthorized. Please login") -local vfs = require("fs.vfs") -if REQUEST.query then - local r,m = require("fs.vfs").upload(REQUEST.query.path) - if r then result(r) else fail(m) end -else - fail("Query not found") -end diff --git a/example-app/os/fs/vfs.lua b/example-app/os/fs/vfs.lua deleted file mode 100644 index c9ccbe0..0000000 --- a/example-app/os/fs/vfs.lua +++ /dev/null @@ -1,203 +0,0 @@ -local vfs = {} - -vfs.ospath = function(path) - local user = SESSION.iotos_user - local conf = require("fs.fsconf") - local prefix = string.match(path, "%a+://") - if(prefix ~= nil) then - local suffix = string.gsub(path,prefix,"") - if prefix == "home://" then - return string.format(conf.home,user)..'/'..suffix - elseif prefix == "desktop://" then - return string.format(conf.home,user).."/.desktop/"..suffix - elseif prefix == "shared://" then - return require("fs.shared").ospath(std.trim(suffix,"/")) - elseif prefix == "os://" then - return OSROOT.."/"..suffix - else - return nil - end - else - return nil; - end -end - - -vfs.delete = function(path) - local r,m = vfs.checkperm(path,"write") - if r then - if unix.delete(m) then - -- change permission - return true,nil - else - return false,"Cant not delete the file" - end - else - return r,m - end -end - -vfs.exists = function(path) - local osfile = vfs.ospath(path) - return unix.exists(osfile) -end - -vfs.fileinfo = function(vfspath) - local ospath = vfs.ospath(vfspath) - if ospath then - if(unix.exists(ospath) == false) then return false,"File not found" end - local r = unix.file_stat(ospath) - if(r.error ~= nil) then return false,r.error end - r.path = vfspath - r.name = std.basename(vfspath) - if r.mime == "application/octet-stream" then - r.mime = std.extra_mime(r.name) - end - return true,r - else - return false,"Resource not found" - end -end - -vfs.mkdir = function(path) - local file = std.basename(path) - local folder = string.gsub(path, utils.escape_pattern(file),"") - local r,m = vfs.checkperm(folder,"write") - - if r then - local osfile = m.."/"..file - local uid = unix.uid(SESSION.iotos_user) - unix.mkdir(osfile) - -- change permission - unix.chown(osfile, uid.id, uid.gid) - return true,nil - else - return r,m - end -end - -vfs.move = function(src,dest) - local file = std.basename(dest) - local folder = string.gsub(dest, utils.escape_pattern(file),"") - - local sp,sm = vfs.checkperm(src,"write") - if sp then - local dp,dm = vfs.checkperm(folder,"write") - if dp then - unix.move(sm,dm.."/"..file) - -- change permission - return true,nil - else - return dp,dm - end - else - return sp,sm - end -end - -vfs.write = function(path,data) - local file = std.basename(path) - local folder = string.gsub(path, utils.escape_pattern(file),"") - - local r,m = vfs.checkperm(folder,"write") - if r then - local osfile = m.."/"..file - local uid = unix.uid(SESSION.iotos_user) - -- - if data ~= "" then - local header = string.match(data, "^data%:%w+%/%w+;base64,") - if header ~= nil then - local b64data = string.gsub(data, header,"") - local barr = std.b64decode(b64data) - if std.isBinary(osfile) then - bytes.write(barr,osfile) - else - local f = io.open(osfile, "w") - f:write(bytes.__tostring(barr)) - f:close() - end - end - else - bytes.write(bytes.new(0),osfile) - end - --f:close() - -- change permission - unix.chown(osfile, uid.id, uid.gid) - return true,nil - else - return r,m - end -end - -vfs.upload = function(path) - local r,m = vfs.checkperm(path,"write") - if(r) then - local uid = unix.uid(SESSION.iotos_user) - local file = m.."/"..REQUEST.query["upload.file"] - unix.move(REQUEST.query["upload.tmp"], file) - unix.chown(file, uid.id, uid.gid) - return true, nil - else - return r,m - end -end - -vfs.checkperm = function(path, right) - local osfile = vfs.ospath(path) - local perm = vfs.perm(osfile) - print(osfile) - -- check if user own the file - if perm ~= nil then - if perm[right] == true then - print("Permission granted") - return true,osfile - else - print("Permission denie") - return false,"You dont have "..right.." permission on this file" - end - else - return false,"User is unrecognized" - end -end - -vfs.perm = function(file) - local user = SESSION.iotos_user - local uid = unix.uid(user) - local st = unix.file_stat(file) - -- check if user own the file - if uid ~= nil and st ~= nil and st.perm ~= nil then - --print(JSON.encode({uid, st})) - if(uid.id == st.uid) then -- the user owned the file - print("file belong to user") - return st.perm.owner - elseif uid.groups and uid.groups[st.gid] then - print("User belong to this group") - return st.perm.group - else - print("User belong to other") - return st.perm.other - end - else - return nil - end -end - -vfs.readDir = function(vfspath) - if(string.sub(vfspath,-1) == "/") then - prefix = string.sub(vfspath,1,-2) - else - prefix = vfspath - end - local ospath = vfs.ospath(vfspath,SESSION.iotos_user) - local r = unix.read_dir(ospath, prefix) - if(r.error ~= nil) then return nil end - -- add extra mime type - for k,v in pairs(r) do - if v.mime == "application/octet-stream" then - v.mime = std.extra_mime(v.filename) - end - end - return r -end - -return vfs diff --git a/example-app/os/fs/write.lua b/example-app/os/fs/write.lua deleted file mode 100644 index 76046f5..0000000 --- a/example-app/os/fs/write.lua +++ /dev/null @@ -1,13 +0,0 @@ - -auth_or_die("User unauthorized. Please login") -local rq = (JSON.decodeString(REQUEST.query.json)) - -if rq ~= nil then - local r,m = require("fs.vfs").write(rq.path, rq.data) - sqlite.dbclose() - if r then result(r) else fail(m) end -else - fail("Uknown request") -end - - diff --git a/example-app/os/index.lua b/example-app/os/index.lua deleted file mode 100644 index 25c7a8b..0000000 --- a/example-app/os/index.lua +++ /dev/null @@ -1 +0,0 @@ -result({r = "Welcome to antOS" }) \ No newline at end of file diff --git a/example-app/os/router.lua b/example-app/os/router.lua deleted file mode 100644 index 496ffc9..0000000 --- a/example-app/os/router.lua +++ /dev/null @@ -1,10 +0,0 @@ -local handle = function(p) - local hstr = p:match("^%a+/") - if hstr == "fs/" then - --print("require module") - require("fs.fsh")(p:gsub(hstr,"",1)) - else - fail("Resource not found for request "..p) - end -end -return handle \ No newline at end of file diff --git a/example-app/os/system/application.lua b/example-app/os/system/application.lua deleted file mode 100644 index 9da7ced..0000000 --- a/example-app/os/system/application.lua +++ /dev/null @@ -1,24 +0,0 @@ -auth_or_die("User unauthorized. Please login") -local rq = nil -if REQUEST.query.json ~= nil then - rq = (JSON.decodeString(REQUEST.query.json)) -else - rq = REQUEST.query -end - -if rq.path ~= nil then - local pkg = require("fs.vfs").ospath(rq.path) - if pkg == nil then - pkg = OSROOT..'/packages/'..rq.path - --die("unkown request path:"..rq.path) - end - pkg = pkg.."/api.lua" - if unix.exists(pkg) then - dofile(pkg).exec(rq.method,rq.arguments) - else - fail("Uknown application handler: "..pkg) - end -else - fail("Uknown request") -end - diff --git a/example-app/os/system/auth.lua b/example-app/os/system/auth.lua deleted file mode 100644 index 5b2dc60..0000000 --- a/example-app/os/system/auth.lua +++ /dev/null @@ -1,3 +0,0 @@ -auth_or_die("User unauthorized. Please login") -local user = require("system.uman").userinfo(SESSION.iotos_user) -result(user) diff --git a/example-app/os/system/curl.lua b/example-app/os/system/curl.lua deleted file mode 100644 index e08ef85..0000000 --- a/example-app/os/system/curl.lua +++ /dev/null @@ -1,17 +0,0 @@ -auth_or_die("User unauthorized. Please login") -local rq = (JSON.decodeString(REQUEST.query.json)) - -if rq ~= nil then - local r,m = require("web").get(rq.url) - if r then - if r.binary then - result({body="data:"..r.contentType..";base64,"..r.data}) - else - result({body=r.data}) - end - else - fail(m) - end -else - fail("Uknown request") -end \ No newline at end of file diff --git a/example-app/os/system/login.lua b/example-app/os/system/login.lua deleted file mode 100644 index de9c40f..0000000 --- a/example-app/os/system/login.lua +++ /dev/null @@ -1,39 +0,0 @@ -if REQUEST.query.json ~= nil then - local request = JSON.decodeString(REQUEST.query.json) - local r = unix.auth(request.username,request.password) - if r == true then - local cookie = {sessionid=std.sha1(request.username..request.password)} -- iotos_user = request.username - local db = sysdb(); - if db == nil then return fail("Cannot setup session") end - local cond = {exp= {["="] = { sessionid = cookie.sessionid }}} - local data = db:find(cond) - --print(data) - if data == nil or data[1] == nil then - --print("insert new data") - data = {sessionid = cookie.sessionid, username=request.username, stamp=os.time(os.date("!*t"))} - else - data = data[1] - --print("Update old data") - data.stamp = os.time(os.date("!*t")) - end - if data.id == nil then - db:insert(data) - else - db:update(data) - end - db:close() - std.cjson(cookie) - SESSION.iotos_user = request.username - local user = { - result = require("system.uman").userinfo(request.username), - error = false - } - std.t(JSON.encode(user)) - else - fail("Invalid login") - end -else - fail("Invalid request") -end - - diff --git a/example-app/os/system/logout.lua b/example-app/os/system/logout.lua deleted file mode 100644 index cf68cbd..0000000 --- a/example-app/os/system/logout.lua +++ /dev/null @@ -1,17 +0,0 @@ -if SESSION.sessionid ~= nil and SESSION.sessionid ~= '0' then - local cookie = {sessionid='0'} - local db = sysdb() - if db ~= nil then - --local data = db:find("sessionid ='"..SESSION.sessionid.."'") - --if data and data[0] ~= nil then - -- db:delete(data[0].id) - --end - local cond = {["="] = { sessionid = SESSION.sessionid }} - db:delete(cond) - db:close() - end - std.cjson(cookie) -else - std.json() -end -std.t(JSON.encode({error=false,result=true})) \ No newline at end of file diff --git a/example-app/os/system/packages.json b/example-app/os/system/packages.json deleted file mode 100644 index 9c3aab0..0000000 --- a/example-app/os/system/packages.json +++ /dev/null @@ -1,21 +0,0 @@ -[ - { - "className": "NotePad", - "name": "Source editor", - "description": "Advance text editor", - "category": "development", - "author": "xsang.le@gmail.com", - "version": "0.1", - "download": "http://192.168.1.49:9191/repo/AceEditor.zip" - }, - { - "className": "DummyApp", - "name": "Antos features", - "description": "Antos features show case", - "category": "utilities", - "author": "xsang.le@gmail.com", - "version": "1.0", - "download": "https://os.localhost:9195/repo/DummyApp.zip" - } - ] - \ No newline at end of file diff --git a/example-app/os/system/packages.json.tpl b/example-app/os/system/packages.json.tpl deleted file mode 100644 index 3f28bd3..0000000 --- a/example-app/os/system/packages.json.tpl +++ /dev/null @@ -1,588 +0,0 @@ -"default/About": { - "className": "ApplicationAbout", - "name": "About OS.js", - "description": "About OS.js", - "names": { - "bg_BG": " За OS.js", - "de_DE": "Über OS.js", - "fr_FR": "À propos d'OS.js", - "it_IT": "Informazioni su OS.js", - "ko_KR": "OS.js에 대하여", - "nl_NL": "Over OS.js", - "no_NO": "Om OS.js", - "pl_PL": "o OS.js", - "ru_RU": "Об OS.js", - "sk_SK": "o OS.js", - "tr_TR": "hakkında OS.js", - "vi_VN": "Thông tin về OS.js" - }, - "descriptions": { - "bg_BG": "За OS.js", - "de_DE": "Über OS.js", - "fr_FR": "À propos d'OS.js", - "it_IT": "Informazioni su OS.js", - "ko_KR": "OS.js에 대하여", - "nl_NL": "Over OS.js", - "no_NO": "Om OS.js", - "pl_PL": "o OS.js", - "ru_RU": "Об OS.js", - "sk_SK": "o OS.js", - "tr_TR": "hakkında OS.js", - "vi_VN": "Thông tin về OS.js" - }, - "singular": true, - "category": "system", - "icon": "apps/help-browser.png", - "preload": [{ - "type": "javascript", - "src": "combined.js" - }, { - "type": "stylesheet", - "src": "combined.css" - }, { - "src": "scheme.html", - "type": "scheme" - }], - "type": "application", - "path": "default/About", - "build": {}, - "repo": "default" -}, -"default/AceEditor": { - "className": "ApplicationAceEditor", - "name": "Source Editor", - "icon": "apps/accessories-text-editor.png", - "category": "development", - "mime": [ - "^text", - "inode\\/x\\-empty", - "application\\/x\\-empty", - "application\\/x\\-python", - "application\\/x\\-php", - "application\\/javascript" - ], - "build": { - "copy": [ - "metadata.json", - "scheme.html", - "main.css", - "main.js", - "vendor/ace" - ] - }, - "preload": [{ - "type": "javascript", - "src": "combined.js" - }, { - "type": "stylesheet", - "src": "combined.css" - }, { - "src": "scheme.html", - "type": "scheme" - }], - "type": "application", - "path": "default/AceEditor", - "repo": "default" -}, -"default/Archiver": { - "className": "ApplicationArchiver", - "name": "Archiver", - "mime": [ - "application/zip" - ], - "icon": "apps/system-software-install.png", - "category": "utilities", - "compability": [ - "file", - "blob" - ], - "preload": [{ - "type": "javascript", - "src": "combined.js" - }, { - "type": "stylesheet", - "src": "combined.css" - }, { - "src": "scheme.html", - "type": "scheme" - }], - "type": "application", - "path": "default/Archiver", - "build": {}, - "repo": "default" -}, -"default/Calculator": { - "className": "ApplicationCalculator", - "name": "Calculator", - "names": { - "bg_Bg": "Клакулатор", - "fr_FR": "Calculatrice", - "it_IT": "Calcolatrice", - "ko_KR": "계산기", - "nl_NL": "Rekenmachine", - "no_NO": "Kalkulator", - "pl_PL": "Kalkulator", - "ru_RU": "Калькулятор", - "sk_SK": "Kalkulačka", - "tr_TR": "Hesap Makinesi", - "vi_VN": "Máy tính" - }, - "icon": "apps/calc.png", - "category": "office", - "preload": [{ - "type": "javascript", - "src": "combined.js" - }, { - "type": "stylesheet", - "src": "combined.css" - }, { - "src": "scheme.html", - "type": "scheme" - }], - "type": "application", - "path": "default/Calculator", - "build": {}, - "repo": "default" -}, -"default/CoreWM": { - "className": "CoreWM", - "name": "OS.js Window Manager", - "names": { - "bg_BG": "Мениджър на прозорци на OS.js", - "de_DE": "OS.js Fenster-Manager", - "es_ES": "OS.js Window Manager", - "fr_FR": "Gestionnaire de fenêtre OS.js", - "it_IT": "OS.js Gestore Finestre", - "ko_KR": "OS.js 윈도우 관리자", - "nl_NL": "OS.js venster beheer", - "no_NO": "OS.js Vinduhåndterer", - "pl_PL": "Menedżer Okien OS.js", - "ru_RU": "OS.js Оконный менеджер", - "sk_SK": "Správca Okien OS.js", - "tr_TR": "OS.js Pencere Yöneticisi", - "vi_VN": "Quản lí cửa sổ OS.js" - }, - "singular": true, - "type": "windowmanager", - "icon": "apps/gnome-window-manager.png", - "splash": false, - "preload": [{ - "src": "scheme.html", - "type": "scheme" - }, { - "type": "javascript", - "src": "combined.js" - }, { - "type": "stylesheet", - "src": "combined.css" - }], - "panelItems": { - "AppMenu": { - "Name": "AppMenu", - "Description": "Application Menu", - "Icon": "actions/stock_about.png", - "HasOptions": false - }, - "Buttons": { - "Name": "Buttons", - "Description": "Button Bar", - "Icon": "actions/stock_about.png" - }, - "Clock": { - "Name": "Clock", - "Description": "View the time", - "Icon": "status/appointment-soon.png", - "HasOptions": true - }, - "NotificationArea": { - "Name": "NotificationArea", - "Description": "View notifications", - "Icon": "apps/gnome-panel-notification-area.png" - }, - "Search": { - "Name": "Search", - "Description": "Perform searches", - "Icon": "actions/find.png", - "HasOptions": true - }, - "Weather": { - "Name": "Weather", - "Description": "Weather notification", - "Icon": "status/weather-few-clouds.png" - }, - "WindowList": { - "Name": "Window List", - "Description": "Toggle between open windows", - "Icon": "apps/xfwm4.png" - } - }, - "path": "default/CoreWM", - "build": {}, - "repo": "default" -}, -"default/FileManager": { - "className": "ApplicationFileManager", - "name": "File Manager", - "description": "The default file manager", - "names": { - "bg_BG": "Файлов мениджър", - "de_DE": "Dateimanager", - "fr_FR": "Explorateur de fichier", - "it_IT": "Gestore File", - "nl_NL": "bestands beheer", - "no_NO": "Fil-håndtering", - "pl_PL": "Menedżer Plików", - "ko_KR": "파일 탐색기", - "sk_SK": "Správca súborov", - "ru_RU": "Файловый менеджер", - "tr_TR": "Dosya Yöneticisi", - "vi_VN": "Quản lí file" - }, - "descriptions": { - "bg_BG": "Стандартния файлов мениджър", - "de_DE": "Standardmäßiger Dateimanager", - "fr_FR": "Gestionnaire de fichier par défaut", - "it_IT": "Il gestore file predefinito", - "nl_NL": "Standaard bestands beheerder", - "no_NO": "Standard Fil-håndtering program", - "pl_PL": "Domyślny Menedżer Plików", - "ko_KR": "기본 파일 관리자", - "sk_SK": "Štandardný správca súborov", - "ru_RU": "Стандартный файловый менеджер", - "tr_TR": "Varsayılan dosya yöneticisi", - "vi_VN": "Trình quản lí file mặc định" - }, - "category": "utilities", - "icon": "apps/file-manager.png", - "preload": [{ - "type": "javascript", - "src": "combined.js" - }, { - "type": "stylesheet", - "src": "combined.css" - }, { - "src": "scheme.html", - "type": "scheme" - }], - "type": "application", - "path": "default/FileManager", - "build": {}, - "repo": "default" -}, -"default/MarkOn": { - "className": "ApplicationMarkOn", - "name": "MarkOn", - "mime": [ - "^text", - "inode\\/x\\-empty", - "application\\/x\\-empty" - ], - "category": "office", - "icon": "apps/libreoffice34-writer.png", - "preload": [{ - "type": "javascript", - "src": "combined.js" - }, { - "type": "stylesheet", - "src": "combined.css" - }, { - "src": "scheme.html", - "type": "scheme" - }], - "type": "application", - "path": "default/MarkOn", - "build": {}, - "repo": "default" -}, -"default/PDFjs": { - "className": "ApplicationPDFjs", - "name": "PDF Viewer", - "description": "PDF Viewer", - "mime": [ - "application/pdf" - ], - "category": "office", - "icon": "mimetypes/gnome-mime-application-pdf.png", - "build": { - "copy": [ - "metadata.json", - "scheme.html", - "main.css", - "main.js", - "vendor/pdf.js" - ] - }, - "preload": [{ - "type": "javascript", - "src": "combined.js" - }, { - "type": "stylesheet", - "src": "combined.css" - }, { - "src": "scheme.html", - "type": "scheme" - }], - "type": "application", - "path": "default/PDFjs", - "repo": "default" -}, -"default/Preview": { - "className": "ApplicationPreview", - "name": "Preview", - "description": "Preview image files", - "names": { - "bg_BG": "Преглед на изображения", - "de_DE": "Vorschau", - "fr_FR": "Visionneuse", - "it_IT": "Anteprima Immagini", - "ko_KR": "미리보기", - "nl_NL": "Foto viewer", - "no_NO": "Forhåndsviser", - "pl_PL": "Podgląd", - "ru_RU": "Просмотрщик", - "sk_SK": "Prehliadač obrázkov", - "tr_TR": "Önizle", - "vi_VN": "Trình xem ảnh" - }, - "descriptions": { - "bg_BG": "Преглед на изображения", - "de_DE": "Bildervorschau", - "fr_FR": "Visionneuse de photos", - "it_IT": "Anteprima Immagini", - "ko_KR": "이미지 파일을 미리 봅니다", - "nl_NL": "Foto viewer", - "no_NO": "Forhåndsvisning av bilde-filer", - "pl_PL": "Podgląd zdjęć", - "ru_RU": "Просмотрщик изображений", - "sk_SK": "Prehliadač obrázkov", - "tr_TR": "resim dosyalarını önizle", - "vi_VN": "Trình xem ảnh" - }, - "mime": [ - "^image", - "^video" - ], - "category": "multimedia", - "icon": "mimetypes/image.png", - "preload": [{ - "type": "javascript", - "src": "combined.js" - }, { - "type": "stylesheet", - "src": "combined.css" - }, { - "src": "scheme.html", - "type": "scheme" - }], - "type": "application", - "path": "default/Preview", - "build": {}, - "repo": "default" -}, -"default/ProcessViewer": { - "className": "ApplicationProcessViewer", - "name": "Process Viewer", - "description": "View running processes", - "names": { - "bg_BG": "Процеси", - "de_DE": "Prozess-Manager", - "fr_FR": "Gestionnaire de processus", - "it_IT": "Gestore Attività", - "ko_KR": "프로세스 관리자", - "nl_NL": "Proces manager", - "no_NO": "Prosess oversikt", - "pl_PL": "Procesy", - "ru_RU": "Менеджер процессов", - "sk_SK": "Správca procesov", - "tr_TR": "İşlemleri Görüntüle", - "vi_VN": "Xem tiến trình" - }, - "descriptions": { - "bg_BG": "Преглед на процеси", - "de_DE": "Laufende Prozesse verwalten", - "fr_FR": "Visualiser les processus en cours", - "it_IT": "Mostri processi attivi", - "ko_KR": "실행 중인 프로세스를 관리합니다", - "nl_NL": "Bekijk de lopende processen", - "no_NO": "Se oversikt over kjørende prosesser", - "pl_PL": "Zobacz działające procesy", - "ru_RU": "Менеджер запущенных процессов", - "sk_SK": "Spravovanie bežiacich procesov", - "tr_TR": "çalışan işlemleri görüntüle", - "vi_VN": "Xem các tiến trình đang chạy" - }, - "singular": true, - "category": "system", - "icon": "apps/gnome-monitor.png", - "preload": [{ - "type": "javascript", - "src": "combined.js" - }, { - "type": "stylesheet", - "src": "combined.css" - }, { - "src": "scheme.html", - "type": "scheme" - }], - "type": "application", - "path": "default/ProcessViewer", - "build": {}, - "repo": "default" -}, -"default/Settings": { - "className": "ApplicationSettings", - "preloadParallel": true, - "name": "Settings", - "mime": null, - "icon": "categories/applications-system.png", - "category": "system", - "singular": true, - "names": { - "bg_BG": "Настройки", - "de_DE": "Einstellungen", - "es_ES": "Settings", - "fr_FR": "Paramètres", - "it_IT": "Settaggi", - "ko_KR": "환경설정", - "nl_NL": "Instellingen", - "no_NO": "Instillinger", - "pl_PL": "Ustawienia", - "ru_RU": "Настройки", - "sk_SK": "Nastavenia", - "tr_TR": "Ayarlar", - "vi_VN": "Cài đặt" - }, - "descriptions": { - "bg_BG": "Настройки", - "de_DE": "Einstellungen", - "es_ES": "Settings", - "fr_FR": "Paramètres", - "it_IT": "Settaggi", - "ko_KR": "환경설정", - "nl_NL": "Instellingen", - "no_NO": "Instillinger", - "pl_PL": "Ustawienia", - "ru_RU": "Настройки", - "sk_SK": "Nastavenia", - "tr_TR": "Program Ayarlarını düzenle", - "vi_VN": "Cài đặt" - }, - "preload": [{ - "type": "javascript", - "src": "combined.js" - }, { - "type": "stylesheet", - "src": "combined.css" - }, { - "src": "scheme.html", - "type": "scheme" - }], - "type": "application", - "path": "default/Settings", - "build": {}, - "repo": "default" -}, -"default/Textpad": { - "className": "ApplicationTextpad", - "name": "Textpad", - "description": "Simple text editor", - "names": { - "bg_BG": "Текстов редактор", - "de_DE": "Texteditor", - "fr_FR": "Éditeur de texte", - "it_IT": "Editor Testi", - "ko_KR": "텍스트패드", - "nl_NL": "Notities", - "no_NO": "Tekstblokk", - "pl_PL": "Notatnik", - "ru_RU": "Редактор текста", - "sk_SK": "Poznámkový blok", - "tr_TR": "Basit Bir Metin Düzenleyicisi", - "vi_VN": "Trình sửa văn bản" - }, - "descriptions": { - "bg_BG": "Стандартен текстов редактор", - "de_DE": "Einfacher Texteditor", - "fr_FR": "Éditeur de texte simple", - "it_IT": "Semplice editor di testi", - "ko_KR": "간단한 텍스트 편집기", - "nl_NL": "Eenvoudige Tekstverwerker", - "no_NO": "Simpel tekst redigering", - "pl_PL": "Prosty edytor tekstu", - "ru_RU": "Простой текстовый редактор", - "sk_SK": "Jednoduchý textový editor", - "tr_TR": "Basit Bir Metin Düzenleyicisi", - "vi_VN": "Trình sửa văn bản đơn giản" - }, - "mime": [ - "^text", - "inode\\/x\\-empty", - "application\\/x\\-empty", - "application\\/x\\-lua", - "application\\/x\\-python", - "application\\/javascript", - "application\\/json" - ], - "category": "utilities", - "icon": "apps/accessories-text-editor.png", - "preload": [{ - "type": "javascript", - "src": "combined.js" - }, { - "type": "stylesheet", - "src": "combined.css" - }, { - "src": "scheme.html", - "type": "scheme" - }], - "type": "application", - "path": "default/Textpad", - "build": {}, - "repo": "default" -}, -"default/wTerm": { - "className": "ApplicationwTerm", - "name": "wTerm", - "mime": null, - "icon": "apps/terminal.png", - "category": "system", - "preload": [{ - "type": "stylesheet", - "src": "combined.css" - }, { - "type": "javascript", - "src": "combined.js" - }, { - "src": "scheme.html", - "type": "scheme" - }], - "type": "application", - "path": "default/wTerm", - "build": {}, - "repo": "default" -}, -"default/LuaPlayground": { - "className": "ApplicationLuaPlayground", - "name": "Lua Playground", - "mime": null, - "icon": "categories/preferences-other.png", - "category": "development", - "preload": [ - { - "type": "javascript", - "src": "combined.js" - }, - { - "type": "stylesheet", - "src": "combined.css" - }, - { - "src": "scheme.html", - "type": "scheme" - } - ], - "type": "application", - "path": "default/LuaPlayground", - "build": {}, - "repo": "default" -} \ No newline at end of file diff --git a/example-app/os/system/packages.lua b/example-app/os/system/packages.lua deleted file mode 100644 index 34734b1..0000000 --- a/example-app/os/system/packages.lua +++ /dev/null @@ -1,140 +0,0 @@ -auth_or_die("User unauthorized. Please login") - -local packages={} -local vfs = require("fs.vfs") -local uid = unix.uid(SESSION.iotos_user) - -packages._cache = function(y) - local p = vfs.ospath(y) - local f = io.open(p.."/packages.json", "w") - local has_cache = false - local i = 1 - local meta = {} - if f then - local files = vfs.readDir(y) - for k,v in pairs(files) do - if v.type == "dir" then - local f1 = io.open(vfs.ospath(v.path.."/package.json")) - if f1 then - - local name = std.basename(v.path) - local mt = JSON.decodeString(f1:read("*all")) - mt.path = v.path - meta[i] ='"'..name..'":'..JSON.encode(mt) - i = i+1 - f1:close() - has_cache = true; - end - end - end - f:write(table.concat(meta, ",")) - f:close() - if has_cache == false then - unix.delete(p.."/packages.json"); - end - end -end - --- we will change this later -packages.list = function(paths) - std.json() - std.t("{\"result\" : { ") - local first = true - --std.f(__ROOT__.."/system/packages.json") - for k,v in pairs(paths) do - local osp = vfs.ospath(v.."/packages.json") - if unix.exists(osp) == false then - packages._cache(v) - end - if unix.exists(osp) then - if first == false then - std.t(",") - else - first = false - end - std.f(osp) - end - end - std.t("}, \"error\":false}") -end - --- generate the packages caches -packages.cache = function(args) - -- perform a packages caches - for x,y in pairs(args.paths) do - packages._cache(y) - end - result(true) -end --- install a function from zip file -packages.install = function(args) - local path = vfs.ospath(args.dest) - local zip = vfs.ospath(args.zip) - if(unix.exists(path) == false) then - -- create directory if not exist - unix.mkdir(path) - -- change permission - unix.chown(path, uid.id, uid.gid) - end - -- extract the zip file to it - if(unix.unzip(zip, path)) then - -- read metadata - local meta = JSON.decodeFile(path.."/metadata.json") - meta.path = args.dest - meta.scope = "user" - local f=io.open(path.."/package.json","w") - if f then - f:write(JSON.encode(meta)) - f:close() - end - result(true) - else - fail("Problem extracting zip file") - end - -end --- uninstall the package -packages.uninstall = function(path) - local osf = vfs.ospath(path) - if(osf and unix.exists(osf) ) then - --remove it - unix.delete(osf) - result(true) - else - fail("Cannot find package") - end -end --- set user packages environment -packages.init = function(paths) - if(paths) then - for k,v in pairs(paths) do - local p = vfs.ospath(v) - if p and (unix.exists(p) == false) then - unix.mkdir(p) - -- change permission - unix.chown(p, uid.id, uid.gid) - end - end - end -end - --- main() - -local rq = (JSON.decodeString(REQUEST.query.json)) -packages.init(rq.args.paths) -if rq ~= nil then - -- check user command here - if(rq.command == "install") then - packages.install(rq.args) - elseif rq.command == "cache" then - packages.cache(rq.args) - elseif rq.command == "list" then - packages.list(rq.args.paths) - elseif rq.command == "uninstall" then - packages.uninstall(rq.args.path) - else - fail("Uknown packages command") - end -else - fail("Uknown request") -end diff --git a/example-app/os/system/settings.lua b/example-app/os/system/settings.lua deleted file mode 100644 index 151c5de..0000000 --- a/example-app/os/system/settings.lua +++ /dev/null @@ -1,19 +0,0 @@ -auth_or_die("User unauthorized. Please login") -local user = SESSION.iotos_user -if user then - local ospath = require('fs.vfs').ospath("home:///",user) - if REQUEST.query and REQUEST.query.json then - local f = io.open(ospath.."/"..".settings.json", "w") - if f then - f:write(REQUEST.query.json) - f:close() - result(true) - else - fail("Cannot save setting") - end - else - fail("No setting founds") - end -else - fail("User not found") -end diff --git a/example-app/os/system/uman.lua b/example-app/os/system/uman.lua deleted file mode 100644 index 12f5115..0000000 --- a/example-app/os/system/uman.lua +++ /dev/null @@ -1,27 +0,0 @@ -local uman={} - -uman.userinfo = function(user) - local info = {} - local uid = unix.uid(user) - if uid then - -- read the setting - -- use the decodeFile function of JSON instead - local file = require('fs.vfs').ospath("home:///").."/.settings.json" - local st = JSON.decodeFile(file) - if(st) then - info = st - end - info.user = { - username = user, - id = uid.id, - name = user, - groups = uid.groups - } - --print(JSON.encode(info)) - return info - else - return {} - end -end - -return uman \ No newline at end of file diff --git a/example-app/os/system/users.lua b/example-app/os/system/users.lua deleted file mode 100644 index 541438d..0000000 --- a/example-app/os/system/users.lua +++ /dev/null @@ -1,23 +0,0 @@ -auth_or_die("User unauthorized. Please login") -local rq = (JSON.decodeString(REQUEST.query.json)) -if rq then - if rq.command == "list" then - users = {} - local uid = unix.uid(SESSION.iotos_user) - if uid then - users[0] = { - username = SESSION.iotos_user, - id = uid.id, - name = SESSION.iotos_user, - groups = {"admin"} - } - result(users) - else - fail("Problem when retreive users") - end - else - fail("command "..rq.command.." is not supported yet") - end -else - fail("Unknow request") -end diff --git a/example-app/os/test.ls b/example-app/os/test.ls deleted file mode 100644 index 1e9cddf..0000000 --- a/example-app/os/test.ls +++ /dev/null @@ -1,28 +0,0 @@ - - - -
-This is a paragraph.
-