mirror of
https://github.com/sirpdboy/sirpdboy-package.git
synced 2025-01-07 03:17:03 +08:00
luci-app-fileassistant 增加新建文件夹和修改权限
This commit is contained in:
parent
b76160a12e
commit
72f5855bdd
@ -9,6 +9,8 @@ include $(TOPDIR)/rules.mk
|
|||||||
|
|
||||||
LUCI_TITLE:=LuCI support for Fileassistant
|
LUCI_TITLE:=LuCI support for Fileassistant
|
||||||
LUCI_PKGARCH:=all
|
LUCI_PKGARCH:=all
|
||||||
|
PKG_VERSION:=1.0-5
|
||||||
|
PKG_RELEASE:=
|
||||||
|
|
||||||
include $(TOPDIR)/feeds/luci/luci.mk
|
include $(TOPDIR)/feeds/luci/luci.mk
|
||||||
|
|
||||||
|
@ -14,12 +14,15 @@
|
|||||||
border-bottom: none;
|
border-bottom: none;
|
||||||
}
|
}
|
||||||
.fb-container .panel-container {
|
.fb-container .panel-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
padding-bottom: 1rem;
|
||||||
justify-content: space-between;
|
align-items: center;
|
||||||
padding-bottom: 1rem;
|
justify-content: space-evenly;
|
||||||
border-bottom: 1px solid #aaa;
|
border-bottom: 1px solid #aaa;
|
||||||
}
|
}
|
||||||
|
.fb-container .cbi-section-table-row {
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
.fb-container .upload-container {
|
.fb-container .upload-container {
|
||||||
display: none;
|
display: none;
|
||||||
margin: 1rem 0;
|
margin: 1rem 0;
|
||||||
@ -32,6 +35,10 @@
|
|||||||
}
|
}
|
||||||
.fb-container .parent-icon strong {
|
.fb-container .parent-icon strong {
|
||||||
margin-left: 1rem;
|
margin-left: 1rem;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
.fb-container .cbi-section-table tr .cbi-value-field {
|
||||||
|
text-align: left;
|
||||||
}
|
}
|
||||||
.fb-container td[class$="-icon"] {
|
.fb-container td[class$="-icon"] {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
@ -91,6 +91,39 @@ String.prototype.replaceAll = function(search, replacement) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function chmodPath(filename, isdir) {
|
||||||
|
var newmod = prompt('请输入新的权限位(支持八进制权限位或者a+x格式):', isdir === "1" ? "0755" : "0644");
|
||||||
|
if (newmod) {
|
||||||
|
iwxhr.get('/cgi-bin/luci/admin/system/fileassistant/chmod',
|
||||||
|
{
|
||||||
|
filepath: concatPath(currentPath, filename),
|
||||||
|
newmod: newmod
|
||||||
|
},
|
||||||
|
function (x, res) {
|
||||||
|
if (res.ec === 0) {
|
||||||
|
refresh_list(res.data, currentPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function chownPath(filename) {
|
||||||
|
var newown = prompt('请输入新的用户名(支持用户名或用户名:群组格式):', "root");
|
||||||
|
if (newown) {
|
||||||
|
iwxhr.get('/cgi-bin/luci/admin/system/fileassistant/chown',
|
||||||
|
{
|
||||||
|
filepath: concatPath(currentPath, filename),
|
||||||
|
newown: newown
|
||||||
|
},
|
||||||
|
function (x, res) {
|
||||||
|
if (res.ec === 0) {
|
||||||
|
refresh_list(res.data, currentPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
function openpath(filename, dirname) {
|
function openpath(filename, dirname) {
|
||||||
dirname = dirname || currentPath;
|
dirname = dirname || currentPath;
|
||||||
window.open('/cgi-bin/luci/admin/system/fileassistant/open?path='
|
window.open('/cgi-bin/luci/admin/system/fileassistant/open?path='
|
||||||
@ -130,6 +163,13 @@ String.prototype.replaceAll = function(search, replacement) {
|
|||||||
else if (targetElem.className.indexOf('cbi-button-edit') > -1) {
|
else if (targetElem.className.indexOf('cbi-button-edit') > -1) {
|
||||||
renamePath(targetElem.parentNode.parentNode.dataset['filename']);
|
renamePath(targetElem.parentNode.parentNode.dataset['filename']);
|
||||||
}
|
}
|
||||||
|
else if (targetElem.className.indexOf('cbi-button-chmod') > -1) {
|
||||||
|
infoElem = targetElem.parentNode.parentNode;
|
||||||
|
chmodPath(infoElem.dataset['filename'] , infoElem.dataset['isdir']);
|
||||||
|
}
|
||||||
|
else if (targetElem.className.indexOf('cbi-button-chown') > -1) {
|
||||||
|
chownPath(targetElem.parentNode.parentNode.dataset['filename']);
|
||||||
|
}
|
||||||
else if (targetElem = getFileElem(targetElem)) {
|
else if (targetElem = getFileElem(targetElem)) {
|
||||||
if (targetElem.className.indexOf('parent-icon') > -1) {
|
if (targetElem.className.indexOf('parent-icon') > -1) {
|
||||||
update_list(currentPath.replace(/\/[^/]+($|\/$)/, ''));
|
update_list(currentPath.replace(/\/[^/]+($|\/$)/, ''));
|
||||||
@ -156,7 +196,14 @@ String.prototype.replaceAll = function(search, replacement) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
function refresh_list(filenames, path) {
|
function refresh_list(filenames, path) {
|
||||||
var listHtml = '<table class="cbi-section-table"><tbody>';
|
var listHtml = '<table class="cbi-section-table"><thead><tr class="cbi-section-table-row cbi-rowstyle-2">'
|
||||||
|
+'<td class="cbi-value-field">文件</td>'
|
||||||
|
+'<td class="cbi-value-field">所有者</td>'
|
||||||
|
+'<td class="cbi-value-field">修改时间</td>'
|
||||||
|
+'<td class="cbi-value-field">大小</td>'
|
||||||
|
+'<td class="cbi-value-field">权限</td>'
|
||||||
|
+'<td class="cbi-section-table-cell">操作</td>'
|
||||||
|
+'</tr></thead><tbody>';
|
||||||
if (path !== '/') {
|
if (path !== '/') {
|
||||||
listHtml += '<tr class="cbi-section-table-row cbi-rowstyle-2"><td class="parent-icon" colspan="6"><strong>..返回上级目录</strong></td></tr>';
|
listHtml += '<tr class="cbi-section-table-row cbi-rowstyle-2"><td class="parent-icon" colspan="6"><strong>..返回上级目录</strong></td></tr>';
|
||||||
}
|
}
|
||||||
@ -190,13 +237,15 @@ String.prototype.replaceAll = function(search, replacement) {
|
|||||||
+ '<td class="cbi-value-field ' + o.icon + '">'
|
+ '<td class="cbi-value-field ' + o.icon + '">'
|
||||||
+ '<strong>' + o.displayname + '</strong>'
|
+ '<strong>' + o.displayname + '</strong>'
|
||||||
+ '</td>'
|
+ '</td>'
|
||||||
|
+ '<td class="cbi-value-field cbi-value-owner">'+o.owner+'</td>'
|
||||||
+ '<td class="cbi-value-field cbi-value-date">'+o.date+'</td>'
|
+ '<td class="cbi-value-field cbi-value-date">'+o.date+'</td>'
|
||||||
+ '<td class="cbi-value-field cbi-value-size">'+o.size+'</td>'
|
+ '<td class="cbi-value-field cbi-value-size">'+o.size+'</td>'
|
||||||
+ '<td class="cbi-value-field cbi-value-perm">'+o.perms+'</td>'
|
+ '<td class="cbi-value-field cbi-value-perm">'+o.perms+'</td>'
|
||||||
+ '<td class="cbi-section-table-cell">\
|
+ '<td class="cbi-section-table-cell">\
|
||||||
<button class="cbi-button cbi-button-edit">重命名</button>\
|
<button class="cbi-button cbi-button-edit">重命名</button>\
|
||||||
<button class="cbi-button cbi-button-remove">删除</button>'
|
<button class="cbi-button cbi-button-remove">删除</button>\
|
||||||
|
<button class="cbi-button cbi-button-apply cbi-button-chmod">改权限</button>\
|
||||||
|
<button class="cbi-button cbi-button-apply cbi-button-chown">改用户</button>'
|
||||||
+ install_btn
|
+ install_btn
|
||||||
+ '</td>'
|
+ '</td>'
|
||||||
+ '</tr>';
|
+ '</tr>';
|
||||||
@ -270,6 +319,26 @@ String.prototype.replaceAll = function(search, replacement) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
document.getElementById('mkdir-toggle').onclick = function() {
|
||||||
|
var dirname = null;
|
||||||
|
if (dirname = prompt("请输入文件夹名称:")) {
|
||||||
|
var formData = new FormData();
|
||||||
|
formData.append('path', currentPath);
|
||||||
|
formData.append('dirname', dirname);
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.open("POST", "/cgi-bin/luci/admin/system/fileassistant/mkdir", true);
|
||||||
|
xhr.onload = function() {
|
||||||
|
if (xhr.status == 200) {
|
||||||
|
var res = JSON.parse(xhr.responseText);
|
||||||
|
refresh_list(res.data, currentPath);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
alert('创建失败,请稍后再试...');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
xhr.send(formData);
|
||||||
|
}
|
||||||
|
};
|
||||||
document.addEventListener('DOMContentLoaded', function(evt) {
|
document.addEventListener('DOMContentLoaded', function(evt) {
|
||||||
var initPath = '/';
|
var initPath = '/';
|
||||||
if (/path=([/\w]+)/.test(location.search)) {
|
if (/path=([/\w]+)/.test(location.search)) {
|
||||||
|
@ -26,6 +26,14 @@ function index()
|
|||||||
page = entry({"admin", "system", "fileassistant", "install"}, call("fileassistant_install"), nil)
|
page = entry({"admin", "system", "fileassistant", "install"}, call("fileassistant_install"), nil)
|
||||||
page.leaf = true
|
page.leaf = true
|
||||||
|
|
||||||
|
page = entry({"admin", "system", "fileassistant", "mkdir"}, call("fileassistant_mkdir"), nil)
|
||||||
|
page.leaf = true
|
||||||
|
|
||||||
|
page = entry({"admin", "system", "fileassistant", "chmod"}, call("fileassistant_chmod"), nil)
|
||||||
|
page.leaf = true
|
||||||
|
|
||||||
|
page = entry({"admin", "system", "fileassistant", "chown"}, call("fileassistant_chown"), nil)
|
||||||
|
page.leaf = true
|
||||||
end
|
end
|
||||||
|
|
||||||
function list_response(path, success)
|
function list_response(path, success)
|
||||||
@ -109,15 +117,17 @@ function installIPK(filepath)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function fileassistant_upload()
|
function fileassistant_upload()
|
||||||
local filecontent = luci.http.formvalue("upload-file")
|
|
||||||
local filename = luci.http.formvalue("upload-filename")
|
|
||||||
local uploaddir = luci.http.formvalue("upload-dir")
|
|
||||||
local filepath = uploaddir..filename
|
|
||||||
|
|
||||||
local fp
|
local fp
|
||||||
luci.http.setfilehandler(
|
luci.http.setfilehandler(
|
||||||
function(meta, chunk, eof)
|
function(meta, chunk, eof)
|
||||||
if not fp and meta and meta.name == "upload-file" then
|
if not fp and meta and meta.name == "upload-file" then
|
||||||
|
local filename = luci.http.formvalue("upload-filename")
|
||||||
|
local uploaddir = luci.http.formvalue("upload-dir")
|
||||||
|
if not uploaddir or not filename then
|
||||||
|
error("uploaddir or filename is nil")
|
||||||
|
end
|
||||||
|
local filepath = uploaddir..filename
|
||||||
fp = io.open(filepath, "w")
|
fp = io.open(filepath, "w")
|
||||||
end
|
end
|
||||||
if fp and chunk then
|
if fp and chunk then
|
||||||
@ -129,7 +139,25 @@ function fileassistant_upload()
|
|||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
list_response(uploaddir, true)
|
list_response(luci.http.formvalue("upload-dir"), true)
|
||||||
|
end
|
||||||
|
function fileassistant_mkdir()
|
||||||
|
local path = luci.http.formvalue("path")
|
||||||
|
local dirname = luci.http.formvalue("dirname")
|
||||||
|
local success = os.execute('sh -c \'cd "'..path..'" && mkdir -p "'..dirname..'"\'')
|
||||||
|
list_response(path, success)
|
||||||
|
end
|
||||||
|
function fileassistant_chmod()
|
||||||
|
local path = luci.http.formvalue("filepath")
|
||||||
|
local newmod = luci.http.formvalue("newmod")
|
||||||
|
local success = os.execute('chmod '..newmod..' "'..path..'"')
|
||||||
|
list_response(nixio.fs.dirname(path), success)
|
||||||
|
end
|
||||||
|
function fileassistant_chown()
|
||||||
|
local path = luci.http.formvalue("filepath")
|
||||||
|
local newown = luci.http.formvalue("newown")
|
||||||
|
local success = os.execute('chown '..newown..' "'..path..'"')
|
||||||
|
list_response(nixio.fs.dirname(path), success)
|
||||||
end
|
end
|
||||||
|
|
||||||
function scandir(directory)
|
function scandir(directory)
|
||||||
|
@ -7,14 +7,15 @@
|
|||||||
<div class="panel-container">
|
<div class="panel-container">
|
||||||
<div class="panel-title">文件列表</div>
|
<div class="panel-title">文件列表</div>
|
||||||
<button id="upload-toggle" class="upload-toggle cbi-button cbi-button-edit">上传文件</button>
|
<button id="upload-toggle" class="upload-toggle cbi-button cbi-button-edit">上传文件</button>
|
||||||
|
<button id="mkdir-toggle" class="upload-toggle cbi-button cbi-button-edit">新建文件夹… </button>
|
||||||
</div>
|
</div>
|
||||||
<div class="upload-container" id="upload-container">
|
<div class="upload-container" id="upload-container">
|
||||||
<input id="upload-file" name="upload-file" class="upload-file" type="file">
|
<input id="upload-file" name="upload-file" class="upload-file" type="file">
|
||||||
<button type="button" class="cbi-button cbi-input-apply">执行上传</button>
|
<button type="button" class="cbi-button cbi-input-apply">点我上传</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="list-content"></div>
|
<div id="list-content"></div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<script src="/luci-static/resources/fileassistant/fb.js?v=@ver"></script>
|
<script src="/luci-static/resources/fileassistant/fb.js<%# ?v=PKG_VERSION %>"></script>
|
||||||
|
|
||||||
<%+footer%>
|
<%+footer%>
|
||||||
|
Loading…
Reference in New Issue
Block a user