From b3ca999e88fe33ee72b2f88922a920563879a8cd Mon Sep 17 00:00:00 2001 From: DanyLE Date: Mon, 22 Aug 2022 20:54:48 +0200 Subject: [PATCH] set correct envar when user running Lua code --- os/controllers/SystemController.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/os/controllers/SystemController.lua b/os/controllers/SystemController.lua index bba2250..4a75a9d 100644 --- a/os/controllers/SystemController.lua +++ b/os/controllers/SystemController.lua @@ -115,6 +115,27 @@ function SystemController:apigateway(...) end local r, e 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 r, e = load(data.code) if r then