1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2025-07-16 22:09:44 +02:00

Compare commits

..

22 Commits

Author SHA1 Message Date
93b6ca18ad VFS shall delete file after upload
All checks were successful
gitea-sync/antd-web-apps/pipeline/head This commit looks good
2023-01-04 21:45:43 +01:00
b10ecfc259 Fix PDF export problem
All checks were successful
gitea-sync/antd-web-apps/pipeline/head This commit looks good
2022-11-08 10:32:26 +01:00
452e3c5343 Update layout.ls
All checks were successful
gitea-sync/antd-web-apps/pipeline/head This commit looks good
2022-10-18 13:35:33 +02:00
04e7192ef8 Update cookie inform on blog
All checks were successful
gitea-sync/antd-web-apps/pipeline/head This commit looks good
2022-10-18 13:28:13 +02:00
1c19cc985c disable some modules
All checks were successful
gitea-sync/antd-web-apps/pipeline/head This commit looks good
2022-10-05 21:06:28 +02:00
1f9c93efb4 Update SystemController.lua
All checks were successful
gitea-sync/antd-web-apps/pipeline/head This commit looks good
2022-10-04 14:12:03 +02:00
0dba37d86e set PWD in child process
All checks were successful
gitea-sync/antd-web-apps/pipeline/head This commit looks good
2022-10-04 12:00:10 +02:00
a874234925 Dont set PWD in child process
All checks were successful
gitea-sync/antd-web-apps/pipeline/head This commit looks good
2022-10-04 11:54:03 +02:00
3c8aa63e9a fix: VFS prefix shall use only one /
All checks were successful
gitea-sync/antd-web-apps/pipeline/head This commit looks good
2022-10-03 19:03:09 +02:00
1d9107cc04 Move system package caches to tmp dir
All checks were successful
gitea-sync/antd-web-apps/pipeline/head This commit looks good
See issue #40
2022-10-03 19:01:28 +02:00
f737109330 Update Jenkinsfile
All checks were successful
gitea-sync/antd-web-apps/pipeline/head This commit looks good
2022-09-29 19:07:51 +02:00
59dd9276bf use remote agent instead of ssh
Some checks failed
gitea-sync/antd-web-apps/pipeline/head There was a failure building this commit
2022-09-29 19:05:05 +02:00
7081d2c337 dont use fixed ws path in build script
All checks were successful
gitea-sync/antd-web-apps/pipeline/head This commit looks good
2022-09-26 09:36:08 +02:00
85fa2a7c24 Update common.lua
Some checks failed
gitea-sync/antd-web-apps/pipeline/head There was a failure building this commit
2022-09-16 21:59:26 +02:00
395249972e add salt to sessionid hash 2022-09-02 20:09:46 +02:00
5b8acf2d87 minor fix on apigateway handling 2022-08-30 16:31:08 +02:00
4016a0abef code refactor 2022-08-23 01:20:05 +02:00
f10df26f82 refactory code 2022-08-22 23:08:35 +02:00
4d091604d1 fallback to sendfile if move file fail in upload 2022-08-22 23:04:44 +02:00
aec0ae5bb7 Merge branch 'master' of github.com:lxsang/antd-web-apps 2022-08-22 20:55:00 +02:00
b3ca999e88 set correct envar when user running Lua code 2022-08-22 20:54:48 +02:00
e775e9d7e7 Update vfs.lua 2022-08-21 16:26:57 +02:00
9 changed files with 89 additions and 44 deletions

26
Jenkinsfile vendored
View File

@ -1,13 +1,5 @@
def remote = [:]
remote.name = 'workstation'
remote.host = 'workstation'
remote.user = 'dany'
remote.identityFile = '/var/jenkins_home/.ssh/id_rsa'
remote.allowAnyHosts = true
remote.agent = false
remote.logLevel = 'INFO'
pipeline{ pipeline{
agent { node{ label'master' }} agent { node{ label'workstation' }}
options { options {
// Limit build history with buildDiscarder option: // Limit build history with buildDiscarder option:
// daysToKeepStr: history is only kept up to this many days. // daysToKeepStr: history is only kept up to this many days.
@ -28,15 +20,13 @@ pipeline{
{ {
stage('Build') { stage('Build') {
steps { steps {
sshCommand remote: remote, command: ''' sh'''
set -e cd $WORKSPACE
export WORKSPACE=$(realpath "./jenkins/workspace/antd-web-apps") [ -d build ] && rm -rf build
cd $WORKSPACE mkdir -p build/opt/www/htdocs
[ -d build ] && rm -rf build export BUILDDIR="$WORKSPACE/build/opt/www/htdocs"
mkdir -p build/opt/www/htdocs make
export BUILDDIR="$WORKSPACE/build/opt/www/htdocs" '''
make
'''
script { script {
// only useful for any master branch // only useful for any master branch
//if (env.BRANCH_NAME =~ /^master/) { //if (env.BRANCH_NAME =~ /^master/) {

View File

@ -152,7 +152,14 @@
</div> </div>
</div> </div>
<div id = "bottom"> <div id = "bottom">
Powered by antd server, (c) 2017 - <?=os.date("*t").year?> Dany LE Powered by antd server, (c) 2017 - <?=os.date("*t").year?> Dany LE.
<?lua
if not HEADER.mobile then
?>
This site does not use cookie, but some third-party contents (e.g. Youtube, Twitter) may do.
<?lua
end
?>
</div> </div>
</body> </body>
</html> </html>

View File

@ -57,9 +57,7 @@ function IndexController:pdf(...)
print(cmd) print(cmd)
local r = os.execute(cmd) local r = os.execute(cmd)
if r then if r then
local mime = std.mimeOf(tmp_file) std.sendFile(tmp_file)
std.header(mime)
std.f(tmp_file)
return false return false
else else
return self:error("Sorry.Problem generate PDF file") return self:error("Sorry.Problem generate PDF file")

View File

@ -109,20 +109,55 @@ function SystemController:apigateway(...)
end end
local exec_with_user_priv = function(data) local exec_with_user_priv = function(data)
local uid = ulib.uid(SESSION.user) local uid = ulib.uid(SESSION.user)
-- disable unused modules
package.loaded["silk.Router"] = nil
package.loaded["silk.BaseController"] = nil
package.loaded["silk.DBHelper"] = nil
package.loaded["silk.Template"] = nil
package.loaded["silk.api"] = nil
package.loaded["silk.Logger"] = nil
package.loaded["silk.BaseModel"] = nil
package.loaded["silk.BaseObject"] = nil
package.loaded["os.controllers.SystemController"] = nil
-- user only allowed to load module in the following paths
package.path = __api__.apiroot.."/?.lua;"..WWW_ROOT .. '/libs/?.lua'
if not ulib.setgid(uid.gid) or not ulib.setuid(uid.id) then if not ulib.setgid(uid.gid) or not ulib.setuid(uid.id) then
echo("Cannot set permission to execute the code") echo("Cannot set permission to execute the code")
return return
end end
local r, e local r, e
e = "{'error': 'Unknow function'}" e = "{'error': 'Unknow function'}"
-- set env var
local home = ulib.home_dir(uid.id)
ulib.setenv("USER", SESSION.user, 1)
ulib.setenv("LOGNAME", SESSION.user, 1)
if home then
ulib.setenv("HOME", home, 1)
ulib.setenv("PWD", home,1)
local paths = ""
if ulib.exists(home.."/bin") then
paths = home.."/bin:"
end
if ulib.exists(home.."/.local/bin") then
paths = paths..home.."/.local/bin:"
end
local envar = ulib.getenv("PATH")
if envar then
paths = paths..envar
end
ulib.setenv("PATH", paths,1)
end
-- run the code as user
if data.code then if data.code then
r, e = load(data.code) r, e = load(data.code)
if r then if r then
local status, result = pcall(r) local status, result = pcall(r)
if (status) then if result then
echo(JSON.encode(result)) if (status) then
else echo(JSON.encode(result))
echo(result) else
echo(result)
end
end end
else else
echo(e) echo(e)
@ -148,12 +183,13 @@ function SystemController:apigateway(...)
end end
if (is_auth()) then if (is_auth()) then
local pid = ulib.fork() local pid = ulib.fork()--std.pfork(HTTP_REQUEST.id)
if (pid == -1) then if (pid == -1) then
echo("{'error':'Cannot create process'}") echo("{'error':'Cannot create process'}")
elseif pid > 0 then -- parent elseif pid > 0 then -- parent
-- wait for the child exit or websocket exit -- wait for the child exit or websocket exit
ulib.waitpid(pid, 0) ulib.waitpid(pid, 0)
--ulib.kill(pid)
print("Parent exit") print("Parent exit")
else -- child else -- child
if use_ws then if use_ws then
@ -168,7 +204,7 @@ function SystemController:apigateway(...)
std.ws.close(1012) std.ws.close(1012)
elseif header.opcode == std.ws.CLOSE then elseif header.opcode == std.ws.CLOSE then
print("Connection closed") print("Connection closed")
std.ws.close(1000) -- std.ws.close(1000)
elseif header.opcode == std.ws.TEXT then elseif header.opcode == std.ws.TEXT then
-- read the file -- read the file
local data = std.ws.read(header) local data = std.ws.read(header)
@ -177,7 +213,7 @@ function SystemController:apigateway(...)
exec_with_user_priv(data) exec_with_user_priv(data)
std.ws.close(1011) std.ws.close(1011)
else else
echo("Error: Invalid request") print("Error: Invalid request")
std.ws.close(1011) std.ws.close(1011)
end end
end end

View File

@ -43,7 +43,8 @@ function UserController:login(...)
local request = JSON.decodeString(REQUEST.json) local request = JSON.decodeString(REQUEST.json)
local r = ulib.auth(request.username,request.password) local r = ulib.auth(request.username,request.password)
if r == true then if r == true then
local cookie = {sessionid=std.sha1(request.username..request.password)} -- iotos_user = request.username local salt = utils.generate_salt(20)
local cookie = {sessionid=std.sha1(request.username..request.password..salt)} -- iotos_user = request.username
local db = sysdb(); local db = sysdb();
if db == nil then return fail("Cannot setup session") end if db == nil then return fail("Cannot setup session") end
local cond = {exp= {["="] = { sessionid = cookie.sessionid }}} local cond = {exp= {["="] = { sessionid = cookie.sessionid }}}

View File

@ -186,7 +186,7 @@ end
function VFSController:upload(...) function VFSController:upload(...)
auth_or_die("User unauthorized. Please login") auth_or_die("User unauthorized. Please login")
local vfs = require("vfs") local vfs = require("vfs")
if REQUEST then if REQUEST and REQUEST.path then
local r, m = require("vfs").upload(REQUEST.path) local r, m = require("vfs").upload(REQUEST.path)
if r then if r then
result(r) result(r)
@ -195,7 +195,7 @@ function VFSController:upload(...)
fail(m) fail(m)
end end
else else
fail("Query not found") fail("Invalid query")
end end
return false return false
end end

View File

@ -1,5 +1,5 @@
require("sqlite") require("sqlite")
local TUNNEL_KEYCHAIN = "/opt/www/tmp/channels/antunnel_keychain" local TUNNEL_KEYCHAIN = __api__.tmpdir.."/channels/antunnel_keychain"
function fail(msg) function fail(msg)
std.custom_header("Connection","close") std.custom_header("Connection","close")
std.json() std.json()

View File

@ -3,8 +3,11 @@ local vfs = require("vfs")
local uid = ulib.uid(SESSION.user) local uid = ulib.uid(SESSION.user)
packages._cache = function(y) packages._cache = function(y)
local p = vfs.ospath(y) local p = vfs.ospath(y).."/packages.cache"
local f = io.open(p.."/packages.json", "w") if y:find("^os:/") then
p = __api__.tmpdir.."/packages.cache"
end
local f = io.open(p, "w")
local has_cache = false local has_cache = false
local i = 1 local i = 1
local meta = {} local meta = {}
@ -28,7 +31,7 @@ packages._cache = function(y)
f:write(table.concat(meta, ",")) f:write(table.concat(meta, ","))
f:close() f:close()
if has_cache == false then if has_cache == false then
ulib.delete(p.."/packages.json"); ulib.delete(p);
end end
end end
end end
@ -40,7 +43,10 @@ packages.list = function(paths)
local first = true local first = true
--std.f(__ROOT__.."/system/packages.json") --std.f(__ROOT__.."/system/packages.json")
for k,v in pairs(paths) do for k,v in pairs(paths) do
local osp = vfs.ospath(v.."/packages.json") local osp = vfs.ospath(v.."/packages.cache")
if v:find("^os:/") then
osp = __api__.tmpdir.."/packages.cache"
end
if ulib.exists(osp) == false then if ulib.exists(osp) == false then
packages._cache(v) packages._cache(v)
end end
@ -116,4 +122,4 @@ packages.init = function(paths)
end end
end end
return packages return packages

View File

@ -3,16 +3,16 @@ local vfs = {}
vfs.ospath = function(path) vfs.ospath = function(path)
local user = SESSION.user local user = SESSION.user
local prefix = string.match(path, "%a+://") local prefix = string.match(path, "%a+:/")
if(prefix ~= nil) then if(prefix ~= nil) then
local suffix = string.gsub(path,prefix,"") local suffix = string.gsub(path,prefix,"")
if prefix == "home://" then if prefix == "home:/" then
return string.format(VFS_HOME,user)..'/'..suffix return string.format(VFS_HOME,user)..'/'..suffix
elseif prefix == "desktop://" then elseif prefix == "desktop:/" then
return string.format(VFS_HOME,user).."/.desktop/"..suffix return string.format(VFS_HOME,user).."/.desktop/"..suffix
elseif prefix == "shared://" then elseif prefix == "shared:/" then
return require("shared").ospath(std.trim(suffix,"/")) return require("shared").ospath(std.trim(suffix,"/"))
elseif prefix == "os://" then elseif prefix == "os:/" then
return WWW_ROOT.."/"..suffix return WWW_ROOT.."/"..suffix
else else
return nil return nil
@ -150,7 +150,14 @@ vfs.upload = function(path)
local index = 0 local index = 0
while(REQUEST["upload-"..index..".tmp"] ~= nil) do while(REQUEST["upload-"..index..".tmp"] ~= nil) do
local file = m.."/"..REQUEST["upload-"..index..".file"] local file = m.."/"..REQUEST["upload-"..index..".file"]
ulib.move(REQUEST["upload-"..index..".tmp"], file) local ret = ulib.move(REQUEST["upload-"..index..".tmp"], file)
if not ret then
ret = ulib.send_file(REQUEST["upload-"..index..".tmp"], file)
ulib.delete(REQUEST["upload-"..index..".tmp"])
end
if not ret then
return false, "Unable to copy file"
end
ulib.chown(file, uid.id, uid.gid) ulib.chown(file, uid.id, uid.gid)
index = index + 1 index = index + 1
end end