Translated uname.php and uptime.php to Lua.
This commit is contained in:
parent
73607f0d51
commit
1713577e62
4 changed files with 51 additions and 2 deletions
27
uname/uname.lua
Normal file
27
uname/uname.lua
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
---
|
||||
permalink: /cgi/uname/index.lua
|
||||
---
|
||||
|
||||
-- Function to execute shell commands
|
||||
local function shell_exec(command)
|
||||
local handle = io.popen(command)
|
||||
local result = handle:read("*a")
|
||||
handle:close()
|
||||
return result
|
||||
end
|
||||
|
||||
-- Execute shell command
|
||||
local uname = shell_exec('uname -mrs')
|
||||
|
||||
-- Find position of the first occurrence of a substring in a string
|
||||
local pos = string.find(uname, '-', 1, true)
|
||||
|
||||
-- Extract substring
|
||||
local res = string.sub(uname, 1, pos - 1)
|
||||
|
||||
-- Output the HTTP header
|
||||
io.write("Content-Type: text/plain; charset=utf-8\r\n\r\n")
|
||||
|
||||
-- Output the result
|
||||
io.write(res)
|
||||
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
permalink: /cgi/uname/
|
||||
permalink: /cgi/uname/obsolete.php
|
||||
---
|
||||
|
||||
<?php
|
||||
|
|
|
|||
22
uptime/uptime.lua
Normal file
22
uptime/uptime.lua
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
permalink: /cgi/uptime/index.lua
|
||||
---
|
||||
|
||||
-- Function to execute shell commands
|
||||
local function shell_exec(command)
|
||||
local handle = io.popen(command)
|
||||
local result = handle:read("*a")
|
||||
handle:close()
|
||||
return result
|
||||
end
|
||||
|
||||
-- Execute shell commands
|
||||
local uptime = shell_exec('uptime')
|
||||
local version = shell_exec('uptime -V')
|
||||
|
||||
-- Output the HTTP header
|
||||
io.write("Content-Type: text/plain; charset=utf-8\r\n\r\n")
|
||||
|
||||
-- Output the result
|
||||
io.write('Server ' .. version:sub(1, -2) .. ': ' .. uptime)
|
||||
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
permalink: /cgi/uptime/
|
||||
permalink: /cgi/uptime/obsolete.php
|
||||
---
|
||||
|
||||
<?php
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue