2
0

sys.luadoc 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. ---[[
  2. LuCI Linux and POSIX system utilities.
  3. ]]
  4. module "luci.sys"
  5. ---[[
  6. Execute a given shell command and return the error code
  7. @class function
  8. @name call
  9. @param ... Command to call
  10. @return Error code of the command
  11. ]]
  12. ---[[
  13. Execute a given shell command and capture its standard output
  14. @class function
  15. @name exec
  16. @param command Command to call
  17. @return String containing the return the output of the command
  18. ]]
  19. ---[[
  20. Retrieve information about currently mounted file systems.
  21. @class function
  22. @name mounts
  23. @return Table containing mount information
  24. ]]
  25. ---[[
  26. Retrieve environment variables. If no variable is given then a table
  27. containing the whole environment is returned otherwise this function returns
  28. the corresponding string value for the given name or nil if no such variable
  29. exists.
  30. @class function
  31. @name getenv
  32. @param var Name of the environment variable to retrieve (optional)
  33. @return String containing the value of the specified variable
  34. @return Table containing all variables if no variable name is given
  35. ]]
  36. ---[[
  37. Get or set the current hostname.
  38. @class function
  39. @name hostname
  40. @param String containing a new hostname to set (optional)
  41. @return String containing the system hostname
  42. ]]
  43. ---[[
  44. Returns the contents of a documented referred by an URL.
  45. @class function
  46. @name httpget
  47. @param url The URL to retrieve
  48. @param stream Return a stream instead of a buffer
  49. @param target Directly write to target file name
  50. @return String containing the contents of given the URL
  51. ]]
  52. ---[[
  53. Initiate a system reboot.
  54. @class function
  55. @name reboot
  56. @return Return value of os.execute()
  57. ]]
  58. ---[[
  59. Retrieves the output of the "logread" command.
  60. @class function
  61. @name syslog
  62. @return String containing the current log buffer
  63. ]]
  64. ---[[
  65. Retrieves the output of the "dmesg" command.
  66. @class function
  67. @name dmesg
  68. @return String containing the current log buffer
  69. ]]
  70. ---[[
  71. Generates a random id with specified length.
  72. @class function
  73. @name uniqueid
  74. @param bytes Number of bytes for the unique id
  75. @return String containing hex encoded id
  76. ]]
  77. ---[[
  78. Returns the current system uptime stats.
  79. @class function
  80. @name uptime
  81. @return String containing total uptime in seconds
  82. ]]
  83. ---[[
  84. LuCI system utilities / network related functions.
  85. @class module
  86. @name luci.sys.net
  87. ]]
  88. ---[[
  89. Returns a two-dimensional table of mac address hints.
  90. @class function
  91. @name net.mac_hints
  92. @return Table of table containing known hosts from various sources.
  93. Each entry contains the values in the following order:
  94. [ "mac", "name" ]
  95. ]]
  96. ---[[
  97. Returns a two-dimensional table of IPv4 address hints.
  98. @class function
  99. @name net.ipv4_hints
  100. @return Table of table containing known hosts from various sources.
  101. Each entry contains the values in the following order:
  102. [ "ip", "name" ]
  103. ]]
  104. ---[[
  105. Returns a two-dimensional table of IPv6 address hints.
  106. @class function
  107. @name net.ipv6_hints
  108. @return Table of table containing known hosts from various sources.
  109. Each entry contains the values in the following order:
  110. [ "ip", "name" ]
  111. ]]
  112. ---[[
  113. Returns a two-dimensional table of host hints.
  114. @class function
  115. @name net.host_hints
  116. @return Table of table containing known hosts from various sources,
  117. indexed by mac address. Each subtable contains at least one
  118. of the fields "name", "ipv4" or "ipv6".
  119. ]]
  120. ---[[
  121. Returns conntrack information
  122. @class function
  123. @name net.conntrack
  124. @return Table with the currently tracked IP connections
  125. ]]
  126. ---[[
  127. Determine the names of available network interfaces.
  128. @class function
  129. @name net.devices
  130. @return Table containing all current interface names
  131. ]]
  132. ---[[
  133. LuCI system utilities / process related functions.
  134. @class module
  135. @name luci.sys.process
  136. ]]
  137. ---[[
  138. Get the current process id.
  139. @class function
  140. @name process.info
  141. @return Number containing the current pid
  142. ]]
  143. ---[[
  144. Retrieve information about currently running processes.
  145. @class function
  146. @name process.list
  147. @return Table containing process information
  148. ]]
  149. ---[[
  150. Set the gid of a process identified by given pid.
  151. @class function
  152. @name process.setgroup
  153. @param gid Number containing the Unix group id
  154. @return Boolean indicating successful operation
  155. @return String containing the error message if failed
  156. @return Number containing the error code if failed
  157. ]]
  158. ---[[
  159. Set the uid of a process identified by given pid.
  160. @class function
  161. @name process.setuser
  162. @param uid Number containing the Unix user id
  163. @return Boolean indicating successful operation
  164. @return String containing the error message if failed
  165. @return Number containing the error code if failed
  166. ]]
  167. ---[[
  168. Send a signal to a process identified by given pid.
  169. @class function
  170. @name process.signal
  171. @param pid Number containing the process id
  172. @param sig Signal to send (default: 15 [SIGTERM])
  173. @return Boolean indicating successful operation
  174. @return Number containing the error code if failed
  175. ]]
  176. ---[[
  177. Execute a process, optionally capturing stdio.
  178. Executes the process specified by the given argv vector, e.g.
  179. `{ "/bin/sh", "-c", "echo 1" }` and waits for it to terminate unless a true
  180. value has been passed for the "nowait" parameter.
  181. When a function value is passed for the stdout or stderr arguments, the passed
  182. function is repeatedly called for each chunk read from the corresponding stdio
  183. stream. The read data is passed as string containing at most 4096 bytes at a
  184. time.
  185. When a true, non-function value is passed for the stdout or stderr arguments,
  186. the data of the corresponding stdio stream is read into an internal string
  187. buffer and returned as "stdout" or "stderr" field respectively in the result
  188. table.
  189. When a true value is passed to the nowait parameter, the function does not
  190. await process termination but returns as soon as all captured stdio streams
  191. have been closed or - if no streams are captured - immediately after launching
  192. the process.
  193. @class function
  194. @name process.exec
  195. @param commend Table containing the argv vector to execute
  196. @param stdout Callback function or boolean to indicate capturing (optional)
  197. @param stderr Callback function or boolean to indicate capturing (optional)
  198. @param nowait Don't wait for process termination when true (optional)
  199. @return Table containing at least the fields "code" which holds the exit
  200. status of the invoked process or "-1" on error and "pid", which
  201. contains the process id assigned to the spawned process. When
  202. stdout and/or stderr capturing has been requested, it additionally
  203. contains "stdout" and "stderr" fields respectively, holding the
  204. captured stdio data as string.
  205. ]]
  206. ---[[
  207. LuCI system utilities / user related functions.
  208. @class module
  209. @name luci.sys.user
  210. ]]
  211. ---[[
  212. Retrieve user information for given uid.
  213. @class function
  214. @name getuser
  215. @param uid Number containing the Unix user id
  216. @return Table containing the following fields:
  217. -- { "uid", "gid", "name", "passwd", "dir", "shell", "gecos" }
  218. ]]
  219. ---[[
  220. Retrieve the current user password hash.
  221. @class function
  222. @name user.getpasswd
  223. @param username String containing the username to retrieve the password for
  224. @return String containing the hash or nil if no password is set.
  225. @return Password database entry
  226. ]]
  227. ---[[
  228. Test whether given string matches the password of a given system user.
  229. @class function
  230. @name user.checkpasswd
  231. @param username String containing the Unix user name
  232. @param pass String containing the password to compare
  233. @return Boolean indicating whether the passwords are equal
  234. ]]
  235. ---[[
  236. Change the password of given user.
  237. @class function
  238. @name user.setpasswd
  239. @param username String containing the Unix user name
  240. @param password String containing the password to compare
  241. @return Number containing 0 on success and >= 1 on error
  242. ]]
  243. ---[[
  244. LuCI system utilities / wifi related functions.
  245. @class module
  246. @name luci.sys.wifi
  247. ]]
  248. ---[[
  249. Get wireless information for given interface.
  250. @class function
  251. @name wifi.getiwinfo
  252. @param ifname String containing the interface name
  253. @return A wrapped iwinfo object instance
  254. ]]
  255. ---[[
  256. LuCI system utilities / init related functions.
  257. @class module
  258. @name luci.sys.init
  259. ]]
  260. ---[[
  261. Get the names of all installed init scripts
  262. @class function
  263. @name init.names
  264. @return Table containing the names of all inistalled init scripts
  265. ]]
  266. ---[[
  267. Get the index of he given init script
  268. @class function
  269. @name init.index
  270. @param name Name of the init script
  271. @return Numeric index value
  272. ]]
  273. ---[[
  274. Test whether the given init script is enabled
  275. @class function
  276. @name init.enabled
  277. @param name Name of the init script
  278. @return Boolean indicating whether init is enabled
  279. ]]
  280. ---[[
  281. Enable the given init script
  282. @class function
  283. @name init.enable
  284. @param name Name of the init script
  285. @return Boolean indicating success
  286. ]]
  287. ---[[
  288. Disable the given init script
  289. @class function
  290. @name init.disable
  291. @param name Name of the init script
  292. @return Boolean indicating success
  293. ]]
  294. ---[[
  295. Start the given init script
  296. @class function
  297. @name init.start
  298. @param name Name of the init script
  299. @return Boolean indicating success
  300. ]]
  301. ---[[
  302. Stop the given init script
  303. @class function
  304. @name init.stop
  305. @param name Name of the init script
  306. @return Boolean indicating success
  307. ]]