[ UP ] cgi
[archserver.git] / cgi / shares / manager_user.lua
blob37d90abc2e25b2a3e91ce8f30ae72028a283b8fa
1 #!/usr/bin/lua
3 dofile "libutil.lua"
5 function display()
6 local user_list = get_samba_user()
7 local options = "<option id=_select style=\"color:blue;\" value=myselect selected>------ 用户列表 ------</option>"
8 local hiddens = [[<input type=hidden id="myselect">]]
9 local style = [[style="background-image:url(icons/volume.png);"]]
11 for u in pairs(user_list) do
12 options = options..[[<option ]]..style..[[ value="]]..u..[[">]]..u..[[</option>]]
13 end
15 print([[
16 <h3>用户管理</h3>
17 <form action="shares_manager_user.cgi",method="post">
18 <table width="80%"><tr><td>
19 <select class="icon-menu" name="selTitle" size=10 id="titles" onchange="setOtherText(this)" width="100%">
21 ..options..
23 </select>
24 </td>
25 <td>
26 <div align="left">
27 <table width="90%" cellspacing="2" cellpadding="5" border="0">
28 <tr class=color_table_row1><td>
29 <strong>用户名称</strong>
30 <input type="text" id="user_name" name="user_name">
31 </td></tr>
32 <tr class=color_table_row2><td>
33 <strong>用户密码</strong>
34 <input type="password" id="passwd" name="passwd">
35 </td></tr>
36 <tr class=color_table_row1><td>
37 <strong>确认密码</strong>
38 <input type="password" id="passwd_cf" name="passwd_cf">
39 </td></tr>
40 <tr><td>
41 <input type=hidden name=todo value="">
42 <input type="submit" value="新建用户" onclick="return mysubmit(1)">
43 <input type="submit" value="更新用户" onclick="return mysubmit(2)">
44 <input type="submit" value="删除用户" onclick="return mysubmit(3)">
45 </td></tr>
46 </table>
47 </div>
48 </td></tr>
49 </table>
50 </form>
52 <script>
53 function setOtherText(obj) {
54 if (!document.layers) {
55 var user = document.getElementById("user_name");
56 var passwd = document.getElementById("passwd");
57 var passwd_cf = document.getElementById("passwd_cf");
58 user.value = obj.value;
59 if (obj.value == "myselect") {
60 user.value = "";
62 passwd.value = "";
66 function mysubmit(value) {
67 if (value == 1){
68 document.forms[0].todo.value="create_user";
69 } else if (value == 2) {
70 document.forms[0].todo.value="update_user";
71 } else if (value == 3) {
72 var ss = "您要删除用户\""+document.getElementById("user_name").value + "\"吗?";
73 if (confirm(ss)) {
74 document.forms[0].todo.value="delete_user";
75 } else {
76 return false;
79 document.forms[0].submit();
81 </script>
83 ]])
84 end
85 -------------------------
86 --CGI OUTPUT
87 -------------------------
88 qp = ui_getqp()
89 if qp.todo then
90 print("todo="..qp.todo)
91 end
92 if not qp.todo then
93 elseif qp.todo == "create_user" then
94 local user_list = get_samba_user()
96 if qp.user_name and user_list[qp.user_name] then
97 ui_message_err("用户 <strong>\""..qp.user_name.."\" </strong>已存在")
98 return
99 end
101 if qp.username=="" or qp.passwd=="" or qp.passwd_cf=="" then
102 ui_message_err("用户名和密码不能为空.")
103 return
106 if qp.passwd ~= qp.passwd_cf then
107 ui_message_err("密码和确认密码不符.")
108 return
111 local err, ret
112 err,ret = myexec("sudo useradd "..qp.user_name)
113 if ret ~= 0 then ui_message_err(err) return end
114 err,ret = myexec("(echo "..qp.passwd.."; echo "..qp.passwd..")|sudo smbpasswd -L -s -a "..qp.user_name)
115 if ret ~= 0 then ui_message_err(err) return end
117 ui_message_success("添加用户: "..qp.user_name)
119 elseif qp.todo == "update_user" then
120 local user_list = get_samba_user()
122 if not qp.user_name or not user_list[qp.user_name] then
123 ui_message_err("用户 <strong>\""..qp.user_name.."\" </strong>不存在")
124 return
127 if qp.username=="" or qp.passwd=="" or qp.passwd_cf=="" then
128 ui_message_err("用户名和密码不能为空.")
129 return
132 if qp.passwd ~= qp.passwd_cf then
133 ui_message_err("密码和确认密码不符.")
134 return
137 local err, ret
138 err,ret = myexec("(echo "..qp.passwd.."; echo "..qp.passwd..")|sudo smbpasswd -L -s -a "..qp.user_name)
139 if ret ~= 0 then ui_message_err(err) return end
140 ui_message_success("更改用户: "..qp.user_name)
142 elseif qp.todo=="delete_user" then
143 if true then print("df") return end
144 if qp.user_name == "" then
145 ui_message_err("用户名不能为空.")
146 return
150 display()