[ UP ] cgi
[archserver.git] / cgi / system / time.lua
blob9f967d7c02eedd7a9a0acf48380be8ff2c02655a
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="year">
17 ]])
19 for year=2008,2050 do
20 if year==tonumber(time.year) then
21 print([[<option value="]]..year..[[" selected="selected">]]..year..[[</option>]])
22 else
23 print([[<option value="]]..year..[[">]]..year..[[</option>]])
24 end
25 end
26 if tonumber(time.year) < 2008 then
27 print([[<option value="]]..time.year..[["selected="selected">]]..time.year..[[</option>]])
28 end
29 print([[
30 </select>
31 <select name="month">
32 ]])
34 for month=1,12 do
35 m = string.format("%02d", month)
36 if month==tonumber(time.month) then
37 print([[<option value="]]..m..[[" selected="selected">]]..m..[[</option>]])
38 else
39 print([[<option value="]]..m..[[">]]..m..[[</option>]])
40 end
41 end
42 print([[</select><select name="day">]])
44 for day=0,31 do
45 d = string.format("%02d", day)
46 if day==tonumber(time.day) then
47 print([[<option value="]]..d..[[" selected="selected">]]..d..[[</option>]])
48 else
49 print([[<option value="]]..d..[[">]]..d..[[</option>]])
50 end
51 end
53 print([[
54 </select>
55 </td>
56 </tr>
57 <tr>
58 <td class="color_table_heading" align="right"><strong> 时间:</strong></td>
59 <td class="color_table_row2">
60 <select name="hour">
61 ]])
62 for hour=0,23 do
63 local h = string.format("%02d", hour)
64 if hour==tonumber(time.hour) then
65 print([[<option value="]]..h..[[" selected="selected">]]..h..[[</option>]])
66 else
67 print([[<option value="]]..h..[[">]]..h..[[</option>]])
68 end
69 end
70 print([[
71 </select>
72 <strong>:</strong>
73 <select name="minute">
74 ]])
75 for min=0,59 do
76 local m = string.format("%02d", min)
77 if min==tonumber(time.min) then
78 print([[<option value="]]..m..[[" selected="selected">]]..m..[[</option>]])
79 else
80 print([[<option value="]]..m..[[">]]..m..[[</option>]])
81 end
82 end
83 print([[
84 </select>
85 </td>
86 </tr>
87 <tr>
88 <td colspan="2" align="center"><input type="submit" name="actionnewdatetime" value="设置时间日期" /></td>
89 </tr>
90 </table>
91 </form>
92 </div>
93 ]])
94 end
96 function settime(t)
97 local time = t.month..t.day..t.hour..t.minute..t.year
98 local err,ret
99 err,ret = myexec("sudo date "..time)
100 if ret ~= 0 then ui_message_err(err) return nil end
101 print("设置时间 ... <font color=green><strong>成功</strong></font>")
103 local qp = ui_getqp()
104 if not qp.todo then
105 display()
106 else
107 settime(qp)