[ UP ] cgi
[archserver.git] / cgi / system / hostname.lua
blobda8076810e2c54ea64db6bcd50e3ea098802c0b8
1 #!/usr/bin/lua
3 dofile "libutil.lua"
6 local qp = ui_getqp()
8 if os.getenv("todo") then
9 -- if qp.todo then
10 oh = string.gsub(myexec("hostname"), "\n", "")
11 nh = qp.hostname
12 for k,v in pairs(qp) do print(k.."="..v) end
13 if nh == "" then message_err("主机名不能为空") return end
15 -- FIXME Cann't do with chinese encoding
16 myexec("sudo hostname "..nh)
17 print("oh="..oh.." nh="..nh)
18 local t = myread("/etc/hosts")
19 t=string.gsub(t, "(\t*%s*)"..oh.."\n", "%1"..nh.."\n")
20 t=string.gsub(t, "(\t*%s*)"..oh.."%.", "%1"..nh.."%.")
21 mywrite("/etc/hosts", t)
22 file_gsub("/etc/rc.conf", "\nHOSTNAME=(.-)\n", "\nHOSTNAME=\""..nh.."\"\n")
25 else
26 print([[<h3>设置主机名</h3>
27 <form action="system_hostname.cgi">
28 <div class="table_input_body">
29 <table cellspacing="2" cellpadding="8" border="0" width="80%">
30 ]])
31 print("<tr><td class=color_table_heading >当前主机名</td><td class=color_table_row1 >"..myexec("hostname").."</td></tr>")
32 print([[<tr><td class=color_table_heading>新主机名</td><td class=color_table_row2><input type=text name=hostname></td></tr>]])
33 print("</table></div>")
34 print([[<input type=hidden name="todo" value=todo>]])
35 print([[<input type=submit value="提交">]])
36 print("</form>")
37 end