sys.luadoc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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 the current arp-table entries as two-dimensional table.
  90. @class function
  91. @name net.arptable
  92. @return Table of table containing the current arp entries.
  93. -- The following fields are defined for arp entry objects:
  94. -- { "IP address", "HW address", "HW type", "Flags", "Mask", "Device" }
  95. ]]
  96. ---[[
  97. Returns a two-dimensional table of mac address hints.
  98. @class function
  99. @name net.mac_hints
  100. @return Table of table containing known hosts from various sources.
  101. Each entry contains the values in the following order:
  102. [ "mac", "name" ]
  103. ]]
  104. ---[[
  105. Returns a two-dimensional table of IPv4 address hints.
  106. @class function
  107. @name net.ipv4_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 IPv6 address hints.
  114. @class function
  115. @name net.ipv6_hints
  116. @return Table of table containing known hosts from various sources.
  117. Each entry contains the values in the following order:
  118. [ "ip", "name" ]
  119. ]]
  120. ---[[
  121. Returns a two-dimensional table of host hints.
  122. @class function
  123. @name net.host_hints
  124. @return Table of table containing known hosts from various sources,
  125. indexed by mac address. Each subtable contains at least one
  126. of the fields "name", "ipv4" or "ipv6".
  127. ]]
  128. ---[[
  129. Returns conntrack information
  130. @class function
  131. @name net.conntrack
  132. @return Table with the currently tracked IP connections
  133. ]]
  134. ---[[
  135. Determine the names of available network interfaces.
  136. @class function
  137. @name net.devices
  138. @return Table containing all current interface names
  139. ]]
  140. ---[[
  141. Return information about available network interfaces.
  142. @class function
  143. @name net.deviceinfo
  144. @return Table containing all current interface names and their information
  145. ]]
  146. ---[[
  147. Returns the current kernel routing table entries.
  148. @class function
  149. @name net.routes
  150. @return Table of tables with properties of the corresponding routes.
  151. -- The following fields are defined for route entry tables:
  152. -- { "dest", "gateway", "metric", "refcount", "usecount", "irtt",
  153. -- "flags", "device" }
  154. ]]
  155. ---[[
  156. Returns the current ipv6 kernel routing table entries.
  157. @class function
  158. @name net.routes6
  159. @return Table of tables with properties of the corresponding routes.
  160. -- The following fields are defined for route entry tables:
  161. -- { "source", "dest", "nexthop", "metric", "refcount", "usecount",
  162. -- "flags", "device" }
  163. ]]
  164. ---[[
  165. Tests whether the given host responds to ping probes.
  166. @class function
  167. @name net.pingtest
  168. @param host String containing a hostname or IPv4 address
  169. @return Number containing 0 on success and >= 1 on error
  170. ]]
  171. ---[[
  172. LuCI system utilities / process related functions.
  173. @class module
  174. @name luci.sys.process
  175. ]]
  176. ---[[
  177. Get the current process id.
  178. @class function
  179. @name process.info
  180. @return Number containing the current pid
  181. ]]
  182. ---[[
  183. Retrieve information about currently running processes.
  184. @class function
  185. @name process.list
  186. @return Table containing process information
  187. ]]
  188. ---[[
  189. Set the gid of a process identified by given pid.
  190. @class function
  191. @name process.setgroup
  192. @param gid Number containing the Unix group id
  193. @return Boolean indicating successful operation
  194. @return String containing the error message if failed
  195. @return Number containing the error code if failed
  196. ]]
  197. ---[[
  198. Set the uid of a process identified by given pid.
  199. @class function
  200. @name process.setuser
  201. @param uid Number containing the Unix user id
  202. @return Boolean indicating successful operation
  203. @return String containing the error message if failed
  204. @return Number containing the error code if failed
  205. ]]
  206. ---[[
  207. Send a signal to a process identified by given pid.
  208. @class function
  209. @name process.signal
  210. @param pid Number containing the process id
  211. @param sig Signal to send (default: 15 [SIGTERM])
  212. @return Boolean indicating successful operation
  213. @return Number containing the error code if failed
  214. ]]
  215. ---[[
  216. Execute a process, optionally capturing stdio.
  217. Executes the process specified by the given argv vector, e.g.
  218. `{ "/bin/sh", "-c", "echo 1" }` and waits for it to terminate unless a true
  219. value has been passed for the "nowait" parameter.
  220. When a function value is passed for the stdout or stderr arguments, the passed
  221. function is repeatedly called for each chunk read from the corresponding stdio
  222. stream. The read data is passed as string containing at most 4096 bytes at a
  223. time.
  224. When a true, non-function value is passed for the stdout or stderr arguments,
  225. the data of the corresponding stdio stream is read into an internal string
  226. buffer and returned as "stdout" or "stderr" field respectively in the result
  227. table.
  228. When a true value is passed to the nowait parameter, the function does not
  229. await process termination but returns as soon as all captured stdio streams
  230. have been closed or - if no streams are captured - immediately after launching
  231. the process.
  232. @class function
  233. @name process.exec
  234. @param commend Table containing the argv vector to execute
  235. @param stdout Callback function or boolean to indicate capturing (optional)
  236. @param stderr Callback function or boolean to indicate capturing (optional)
  237. @param nowait Don't wait for process termination when true (optional)
  238. @return Table containing at least the fields "code" which holds the exit
  239. status of the invoked process or "-1" on error and "pid", which
  240. contains the process id assigned to the spawned process. When
  241. stdout and/or stderr capturing has been requested, it additionally
  242. contains "stdout" and "stderr" fields respectively, holding the
  243. captured stdio data as string.
  244. ]]
  245. ---[[
  246. LuCI system utilities / user related functions.
  247. @class module
  248. @name luci.sys.user
  249. ]]
  250. ---[[
  251. Retrieve user information for given uid.
  252. @class function
  253. @name getuser
  254. @param uid Number containing the Unix user id
  255. @return Table containing the following fields:
  256. -- { "uid", "gid", "name", "passwd", "dir", "shell", "gecos" }
  257. ]]
  258. ---[[
  259. Retrieve the current user password hash.
  260. @class function
  261. @name user.getpasswd
  262. @param username String containing the username to retrieve the password for
  263. @return String containing the hash or nil if no password is set.
  264. @return Password database entry
  265. ]]
  266. ---[[
  267. Test whether given string matches the password of a given system user.
  268. @class function
  269. @name user.checkpasswd
  270. @param username String containing the Unix user name
  271. @param pass String containing the password to compare
  272. @return Boolean indicating whether the passwords are equal
  273. ]]
  274. ---[[
  275. Change the password of given user.
  276. @class function
  277. @name user.setpasswd
  278. @param username String containing the Unix user name
  279. @param password String containing the password to compare
  280. @return Number containing 0 on success and >= 1 on error
  281. ]]
  282. ---[[
  283. LuCI system utilities / wifi related functions.
  284. @class module
  285. @name luci.sys.wifi
  286. ]]
  287. ---[[
  288. Get wireless information for given interface.
  289. @class function
  290. @name wifi.getiwinfo
  291. @param ifname String containing the interface name
  292. @return A wrapped iwinfo object instance
  293. ]]
  294. ---[[
  295. LuCI system utilities / init related functions.
  296. @class module
  297. @name luci.sys.init
  298. ]]
  299. ---[[
  300. Get the names of all installed init scripts
  301. @class function
  302. @name init.names
  303. @return Table containing the names of all inistalled init scripts
  304. ]]
  305. ---[[
  306. Get the index of he given init script
  307. @class function
  308. @name init.index
  309. @param name Name of the init script
  310. @return Numeric index value
  311. ]]
  312. ---[[
  313. Test whether the given init script is enabled
  314. @class function
  315. @name init.enabled
  316. @param name Name of the init script
  317. @return Boolean indicating whether init is enabled
  318. ]]
  319. ---[[
  320. Enable the given init script
  321. @class function
  322. @name init.enable
  323. @param name Name of the init script
  324. @return Boolean indicating success
  325. ]]
  326. ---[[
  327. Disable the given init script
  328. @class function
  329. @name init.disable
  330. @param name Name of the init script
  331. @return Boolean indicating success
  332. ]]
  333. ---[[
  334. Start the given init script
  335. @class function
  336. @name init.start
  337. @param name Name of the init script
  338. @return Boolean indicating success
  339. ]]
  340. ---[[
  341. Stop the given init script
  342. @class function
  343. @name init.stop
  344. @param name Name of the init script
  345. @return Boolean indicating success
  346. ]]