module.lua 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. string.split=util.string.split
  2. string.trim=util.string.trim
  3. shell=util.shell
  4. check_command=util.check_command
  5. function get_kmodule_info(kmod)
  6. local cmd="systool -vm %s"
  7. local info={}
  8. info.info={}
  9. info.attributes={}
  10. info.params={}
  11. info.sections={}
  12. local mode=""
  13. for line in shell(cmd:format(kmod)):gmatch("[^\r\n]+") do
  14. if line:match("Attributes") then
  15. mode="attributes"
  16. elseif line:match("Parameters") then
  17. mode="params"
  18. elseif line:match("Sections") then
  19. mode="sections"
  20. elseif line:match("Module") then
  21. mode="info"
  22. end
  23. local key=line:split("=")[1]
  24. local val=line:split("=")[2]
  25. if key ~= nil and val ~= nil then
  26. print(mode,key,val)
  27. key=key:trim()
  28. val=val:trim()
  29. info[mode][key] =val
  30. end
  31. end
  32. --print(serpent.block(info))
  33. return info
  34. end
  35. function run()
  36. ret.data={}
  37. if request and request.data then
  38. req=json.decode(request.data)
  39. if req.method == "get" then
  40. if req.modul == nil then
  41. ret.data={error="module field is empty"}
  42. else
  43. ret.data[req.modul]=get_kmodule_info(req.modul)
  44. end
  45. if next(ret.data) == nil then ret={error="undefined get query"} end
  46. end
  47. else
  48. ret.api={
  49. title="Kernel Modül Bilgisi",
  50. auth=false,
  51. method={
  52. get={
  53. modul="bilgi alınacak modul",
  54. },
  55. --post={
  56. --},
  57. },
  58. }
  59. end
  60. response=json.encode(ret)
  61. end