5 function filteruser (all
, rm
)
7 for a
in string.gmatch(all
, "(%S+)") do
9 for r
in string.gmatch(rm
, "(%S+)") do
10 if a
== r
then find
= true end
12 if not find
then left
= left
.." "..a
end
17 function display(share
,path
,comment
,readlist
, writelist
)
18 local smbuser
, alluser
= get_samba_user(), ""
19 for u
in pairs(smbuser
) do alluser
= alluser
.." "..u
end
21 alluser
= filteruser(alluser
, readlist
.." "..writelist
),
24 <form method="post" name="myform" action="shares_edit_share.cgi">
26 <table cellspacing="1" cellpadding="2" border="0" width="40%">
27 <tr><td class="color_table_heading" align="right">共享名称</td>
28 <td class="color_table_row1">
29 <input type="text" name="share" id="_share">
31 <tr><td class="color_table_heading" align="right">共享目录</td>
32 <td class="color_table_row2">
33 <input type="text" name="path" id="_path">
35 <tr><td class="color_table_heading" align="right">
37 <td class="color_table_row1">
38 <input type="text" name="comment" id="_comment">
44 <script language="JavaScript">
46 document.myform.share.value="]]..share
..[[";
47 document.myform.path.value="]]..path
..[[";
48 document.myform.comment.value="]]..comment
..[[";
53 ui_message_info([[<strong>用户和组访问此共享的权限: </strong>选定一项或多项然后点击添加或移除(按住shift或ctrl可以多选),或双击进行添加和移除。</p>]])
56 <table border="0" width="50%">
59 <strong>所有用户和组</strong>
60 <select style="width:100%;" multiple name="list1" size="10" ondblclick="moveOption(document.myform.list1, document.myform.list2)"> ]])
62 for auser
in string.gmatch(alluser
, "(%S+)") do
63 print([[<option value="]]..auser
..[[">]]..auser
..[[</option>]])
69 <td width="5%" align="center">
70 <input type="button" value="添加" onclick="moveOption(document.myform.list1, document.myform.list2)"><br><br>
71 <input type="button" value="全选" onclick="moveAllOption(document.myform.list1, document.myform.list2)"><br><br>
72 <input type="button" value="删除" onclick="moveOption(document.myform.list2, document.myform.list1)"><br><br>
73 <input type="button" value="全删" onclick="moveAllOption(document.myform.list2, document.myform.list1)">
76 <strong>只读用户和组</strong>
77 <select style="width:100%;" multiple name="list2" size="10" ondblclick="moveOption(document.myform.list2, document.myform.list3)"> ]])
79 for ruser
in string.gmatch(readlist
, "(%S+)") do
80 print([[<option value="]]..ruser
..[[">]]..ruser
..[[</option>]])
86 <td width="5%" align="center">
87 <input type="button" value="添加" onclick="moveOption(document.myform.list2, document.myform.list3)"><br><br>
88 <input type="button" value="全选" onclick="moveAllOption(document.myform.list2, document.myform.list3)"><br><br>
89 <input type="button" value="删除" onclick="moveOption(document.myform.list3, document.myform.list2)"><br><br>
90 <input type="button" value="全删" onclick="moveAllOption(document.myform.list3, document.myform.list2)">
93 <strong>读写用户和组</strong>
94 <select style="width:100%;" multiple name="list3" size="10" ondblclick="moveOption(document.myform.list3, document.myform.list2)"> ]])
96 for wuser
in string.gmatch(writelist
, "(%S+)") do
97 print([[<option value="]]..wuser
..[[">]]..wuser
..[[</option>]])
107 <input type=hidden name="readlist" id="readlist">
108 <input type=hidden name="writelist" id="writelist">
109 <input type=hidden name=todo value="create_share">
110 <input type="submit" value="提交设置">
113 <script language="JavaScript">
116 document.getElementById('readlist').readOnly= true;
117 document.getElementById('writelist').readOnly= true;
118 document.myform.readlist.value=getvalue(document.myform.list2);
119 document.myform.writelist.value=getvalue(document.myform.list3);
121 function moveOption(e1, e2){
122 var e3 = document.myform.list3;
124 for(var i = 0; i < e1.options.length; i++){
125 if(e1.options[i].selected){
126 var e = e1.options[i];
128 e2.options.add(new Option(e.text, e.value));
133 document.myform.readlist.value=getvalue(document.myform.list2);
134 document.myform.writelist.value=getvalue(document.myform.list3);
139 function getvalue(geto){
141 for(var i = 0; i < geto.options.length; i++){
142 allvalue += geto.options[i].value + ",";
147 function moveAllOption(e1, e2){
148 var e3 = document.myform.list3;
150 for(var i = 0;i < e1.options.length; i++){
151 var e = e1.options[i];
152 e2.options.add(new Option(e.text, e.value));
158 document.myform.readlist.value=getvalue(document.myform.list2);
159 document.myform.writelist.value=getvalue(document.myform.list3);
169 --<strong>只读用户和组:</strong><textarea cols="65" rows="2" name="readlist" id="readlist" value="" /> </textarea><br>
170 --<strong>读写用户和组:</strong><textarea cols="65" rows="2" name="writelist" id="writelist" value="" /> </textarea><br>
172 -----------------------------------
174 -----------------------------------
179 local share
= qp
.share
or ""
180 local path
= qp
.path
or ""
181 local comment
= qp
.comment
or ""
182 local readlist
, writelist
= "", ""
185 if qp
.todo
=="create_share" then
188 if qp
.share
=="" or qp
.path
== "" then ui_message_err("共享名称和共享目录不能为空.") return end
190 if string.sub(path
,1,6) ~= "/home/" then path
="/home/"..qp
.path
end
191 err
,ret
= myexec("sudo mkdir -p "..path
.." && sudo chmod 777 "..path
)
192 smbshare
.set(qp
.share
,path
,qp
.readlist
,qp
.writelist
,qp
.comment
)
193 print("共享设置 ... <font color=green><strong>成功</strong></font>")
195 elseif qp
.todo
== "edit_create" then
196 sh_list
= smbshare
.get()
197 if sh_list
[qp
.share
] then
198 ui_message_err("共享 <strong>\""..qp
.share
.."\" </strong>已存在")
202 elseif qp
.todo
== "edit_update" then
203 sh_list
= smbshare
.get()
204 if not sh_list
[qp
.share
] then
205 ui_message_err("共享 <strong>\""..qp
.share
.."\" </strong>不存在")
209 if (sh_list
[qp
.share
].readlist
) then
210 readlist
= string.gsub(sh_list
[qp
.share
].readlist
, ",", " ")
213 if (sh_list
[qp
.share
].writelist
) then
214 writelist
= string.gsub(sh_list
[qp
.share
].writelist
, ",", " ")
218 display(share
,path
,comment
,readlist
,writelist
)