[ UP ] update cgi, lvm and raid can work. add set time and shutdown function to syste...
[archserver.git] / cgi / system / time.lua
blob09776e5d496bc727c1c02dd2f23aa305edf6d420
1 #!/usr/bin/lua
3 dofile "libutil.lua"
5 function display()
6 local time = os.date("*t", os.time())
7 print([[
8 <h3 >设置系统时间</h3>
9 <div align="center">
10 <form action="system_time.cgi" method="post">
11 <input type="hidden" name="todo" value="newdatetime" />
12 <table cellpadding="8" cellspacing="2" border="0">
13 <tr>
14 <td class="color_table_heading" align="right"><strong>日期:</strong></td>
15 <td class="color_table_row1">
16 <select name="day">
17 ]])
18 for day=0,31 do
19 d = string.format("%02d", day)
20 if day==tonumber(time.day) then
21 print([[<option value="]]..d..[[" selected="selected">]]..d..[[</option>]])
22 else
23 print([[<option value="]]..d..[[">]]..d..[[</option>]])
24 end
25 end
26 print([[
27 </select>
28 <select name="month">
29 ]])
31 for month=1,12 do
32 m = string.format("%02d", month)
33 if month==tonumber(time.month) then
34 print([[<option value="]]..m..[[" selected="selected">]]..m..[[</option>]])
35 else
36 print([[<option value="]]..m..[[">]]..m..[[</option>]])
37 end
38 end
39 print([[</select><select name="year">]])
40 for year=2008,2050 do
41 if year==tonumber(time.year) then
42 print([[<option value="]]..year..[[" selected="selected">]]..year..[[</option>]])
43 else
44 print([[<option value="]]..year..[[">]]..year..[[</option>]])
45 end
46 end
47 if tonumber(time.year) < 2008 then
48 print([[<option value="]]..time.year..[["selected="selected">]]..time.year..[[</option>]])
49 end
51 print([[
52 </select>
53 </td>
54 </tr>
55 <tr>
56 <td class="color_table_heading" align="right"><strong> 时间:</strong></td>
57 <td class="color_table_row2">
58 <select name="hour">
59 ]])
60 for hour=0,23 do
61 local h = string.format("%02d", hour)
62 if hour==tonumber(time.hour) then
63 print([[<option value="]]..h..[[" selected="selected">]]..h..[[</option>]])
64 else
65 print([[<option value="]]..h..[[">]]..h..[[</option>]])
66 end
67 end
68 print([[
69 </select>
70 <strong>:</strong>
71 <select name="minute">
72 ]])
73 for min=0,59 do
74 local m = string.format("%02d", min)
75 if min==tonumber(time.min) then
76 print([[<option value="]]..m..[[" selected="selected">]]..m..[[</option>]])
77 else
78 print([[<option value="]]..m..[[">]]..m..[[</option>]])
79 end
80 end
81 print([[
82 </select>
83 </td>
84 </tr>
85 <tr>
86 <td colspan="2" align="center"><input type="submit" name="actionnewdatetime" value="设置时间日期" /></td>
87 </tr>
88 </table>
89 </form>
90 </div>
91 ]])
92 end
94 function settime(t)
95 local time = t.month..t.day..t.hour..t.minute..t.year
96 local err,ret
97 err,ret = myexec("sudo date "..time)
98 if ret ~= 0 then ui_message_err(err) return nil end
99 print("设置时间 ... <font color=green><strong>成功</strong></font>")
101 local qp = ui_getqp()
102 if not qp.todo then
103 display()
104 else
105 settime(qp)