Skip to content

Commit

Permalink
升级1.8版本
Browse files Browse the repository at this point in the history
增加Mwan3,DDNS和加入文件管理功能。
  • Loading branch information
sirpdboy authored Nov 9, 2020
1 parent 8ab275d commit c554568
Show file tree
Hide file tree
Showing 12 changed files with 646 additions and 33 deletions.
35 changes: 30 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,36 @@
#

include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/package.mk

LUCI_TITLE:=LuCI Support for advanced
LUCI_DEPENDS:=
PKG_VERSION:=1.4
PKG_NAME:=luci-app-advanced
PKG_VERSION:=1.8
PKG_RELEASE:=3
define Package/$(PKG_NAME)
SECTION:=luci
CATEGORY:=LuCI
SUBMENU:=3. Applications
DEPENDS:=
TITLE:=LuCI Support for advanced and filebrowser
PKGARCH:=all
endef

include $(TOPDIR)/feeds/luci/luci.mk
define Build/Compile
endef

# call BuildPackage - OpenWrt buildroot signature
define Package/$(PKG_NAME)/install
$(INSTALL_DIR) $(1)/usr/lib/lua/luci
$(CP) ./luasrc/* $(1)/usr/lib/lua/luci

$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_CONF) ./root/etc/config/advanced $(1)/etc/config/

$(INSTALL_DIR) $(1)/www
cp -pR ./htdocs/* $(1)/www/

$(INSTALL_DIR) $(1)/etc/uci-defaults
$(INSTALL_BIN) ./root/etc/uci-defaults/* $(1)/etc/uci-defaults/

endef

$(eval $(call BuildPackage,$(PKG_NAME)))
68 changes: 68 additions & 0 deletions htdocs/luci-static/resources/fb/fb.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
.fb-container {
margin-top: 1rem;
}
.fb-container .cbi-button {
height: 2rem;
}
.fb-container .cbi-input-text {
margin-bottom: 1rem;
width: 100%;
}
.fb-container .panel-title {
padding-bottom: 0;
width: 50%;
border-bottom: none;
}
.fb-container .panel-container {
display: flex;
align-items: center;
justify-content: space-between;
padding-bottom: 1rem;
border-bottom: 1px solid #eee;
}
.fb-container .upload-container {
display: none;
margin: 1rem 0;
}
.fb-container .upload-file {
margin-right: 2rem;
}
.fb-container .cbi-value-field {
text-align: left;
}
.fb-container .parent-icon strong {
margin-left: 1rem;
}
.fb-container td[class$="-icon"] {
cursor: pointer;
}
.fb-container .file-icon, .fb-container .folder-icon, .fb-container .link-icon {
position: relative;
}
.fb-container .file-icon:before, .fb-container .folder-icon:before, .fb-container .link-icon:before {
display: inline-block;
width: 1.5rem;
height: 1.5rem;
content: '';
background-size: contain;
margin: 0 0.5rem 0 1rem;
vertical-align: middle;
}
.fb-container .file-icon:before {
background-image: url(file-icon.png);
}
.fb-container .folder-icon:before {
background-image: url(folder-icon.png);
}
.fb-container .link-icon:before {
background-image: url(link-icon.png);
}
@media screen and (max-width: 480px) {
.fb-container .upload-file {
width: 14.6rem;
}
.fb-container .cbi-value-owner,
.fb-container .cbi-value-perm {
display: none;
}
}
234 changes: 234 additions & 0 deletions htdocs/luci-static/resources/fb/fb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
(function () {
var iwxhr = new XHR();
var listElem = document.getElementById("list-content");
listElem.onclick = handleClick;
var currentPath;
var pathElem = document.getElementById("current-path");
pathElem.onblur = function () {
update_list(this.value.trim());
};
pathElem.onkeyup = function (evt) {
if (evt.keyCode == 13) {
this.blur();
}
};
function removePath(filename, isdir) {
var c = confirm('确认删除 ' + filename + ' ?');
if (c) {
iwxhr.get('/cgi-bin/luci/admin/system/filebrowser_delete',
{
path: concatPath(currentPath, filename),
isdir: isdir
},
function (x, res) {
if (res.ec === 0) {
refresh_list(res.data, currentPath);
}
});
}
}
function renamePath(filename) {
var newname = prompt('输入新名字:', filename);
if (newname) {
newname = newname.trim();
if (newname != filename) {
var newpath = concatPath(currentPath, newname);
iwxhr.get('/cgi-bin/luci/admin/system/filebrowser_rename',
{
filepath: concatPath(currentPath, filename),
newpath: newpath
},
function (x, res) {
if (res.ec === 0) {
refresh_list(res.data, currentPath);
}
}
);
}
}
}

function openpath(filename, dirname) {
dirname = dirname || currentPath;
window.open('/cgi-bin/luci/admin/system/filebrowser_open?path='
+ encodeURIComponent(dirname) + '&filename='
+ encodeURIComponent(filename));
}

function getFileElem(elem) {
if (elem.className.indexOf('-icon') > -1) {
return elem;
}
else if (elem.parentNode.className.indexOf('-icon') > -1) {
return elem.parentNode;
}
}

function concatPath(path, filename) {
if (path === '/') {
return path + filename;
}
else {
return path.replace(/\/$/, '') + '/' + filename;
}
}

function handleClick(evt) {
var targetElem = evt.target;
var infoElem;
if (targetElem.className.indexOf('cbi-button-remove') > -1) {
infoElem = targetElem.parentNode.parentNode;
removePath(infoElem.dataset['filename'] , infoElem.dataset['isdir'])
}
else if (targetElem.className.indexOf('cbi-button-edit') > -1) {
renamePath(targetElem.parentNode.parentNode.dataset['filename']);
}
else if (targetElem = getFileElem(targetElem)) {
if (targetElem.className.indexOf('parent-icon') > -1) {
update_list(currentPath.replace(/\/[^/]+($|\/$)/, ''));
}
else if (targetElem.className.indexOf('file-icon') > -1) {
openpath(targetElem.parentNode.dataset['filename']);
}
else if (targetElem.className.indexOf('link-icon') > -1) {
infoElem = targetElem.parentNode;
var filepath = infoElem.dataset['linktarget'];
if (filepath) {
if (infoElem.dataset['isdir'] === "1") {
update_list(filepath);
}
else {
var lastSlash = filepath.lastIndexOf('/');
openpath(filepath.substring(lastSlash + 1), filepath.substring(0, lastSlash));
}
}
}
else if (targetElem.className.indexOf('folder-icon') > -1) {
update_list(concatPath(currentPath, targetElem.parentNode.dataset['filename']))
}
}
}
function refresh_list(filenames, path) {
var listHtml = '<table class="cbi-section-table"><tbody>';
if (path !== '/') {
listHtml += '<tr><td class="parent-icon" colspan="6"><strong>..</strong></td></tr>';
}
if (filenames) {
for (var i = 0; i < filenames.length; i++) {
var line = filenames[i];
if (line) {
var f = line.match(/(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+([\S\s]+)/);
var isLink = f[1][0] === 'z' || f[1][0] === 'l' || f[1][0] === 'x';
var o = {
displayname: f[9],
filename: isLink ? f[9].split(' -> ')[0] : f[9],
perms: f[1],
date: f[7] + ' ' + f[6] + ' ' + f[8],
size: f[5],
owner: f[3],
icon: (f[1][0] === 'd') ? "folder-icon" : (isLink ? "link-icon" : "file-icon")
};
listHtml += '<tr class="cbi-section-table-row cbi-rowstyle-' + (1 + i%2)
+ '" data-filename="' + o.filename + '" data-isdir="' + Number(f[1][0] === 'd' || f[1][0] === 'z') + '"'
+ ((f[1][0] === 'z' || f[1][0] === 'l') ? (' data-linktarget="' + f[9].split(' -> ')[1]) : '')
+ '">'
+ '<td class="cbi-value-field ' + o.icon + '">'
+ '<strong>' + o.displayname + '</strong>'
+ '</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-size">'+o.size+'</td>'
+ '<td class="cbi-value-field cbi-value-perm">'+o.perms+'</td>'
+ '<td class="cbi-section-table-cell"><button class="cbi-button cbi-button-edit">重命名</button>\
<button class="cbi-button cbi-button-remove">删除</button></td>'
+ '</tr>';
}
}
}
listHtml += "</table>";
listElem.innerHTML = listHtml;
}
function update_list(path, opt) {
opt = opt || {};
path = concatPath(path, '');
if (currentPath != path) {
iwxhr.get('/cgi-bin/luci/admin/system/filebrowser_list',
{path: path},
function (x, res) {
if (res.ec === 0) {
refresh_list(res.data, path);
}
else {
refresh_list([], path);
}
}
);
if (!opt.popState) {
history.pushState({path: path}, null, '?path=' + path);
}
currentPath = path;
pathElem.value = currentPath;
}
};

var uploadToggle = document.getElementById('upload-toggle');
var uploadContainer = document.getElementById('upload-container');
var isUploadHide = true;
uploadToggle.onclick = function() {
if (isUploadHide) {
uploadContainer.style.display = 'inline-flex';
}
else {
uploadContainer.style.display = 'none';
}
isUploadHide = !isUploadHide;
};
var uploadBtn = uploadContainer.getElementsByClassName('cbi-input-apply')[0];
uploadBtn.onclick = function (evt) {
var uploadinput = document.getElementById('upload-file');
var fullPath = uploadinput.value;
if (!fullPath) {
evt.preventDefault();
}
else {
var formData = new FormData();
var startIndex = (fullPath.indexOf('\\') >= 0 ? fullPath.lastIndexOf('\\') : fullPath.lastIndexOf('/'));
formData.append('upload-filename', fullPath.substring(startIndex + 1));
formData.append('upload-dir', concatPath(currentPath, ''));
formData.append('upload-file', uploadinput.files[0]);
var xhr = new XMLHttpRequest();
xhr.open("POST", "/cgi-bin/luci/admin/system/filebrowser_upload", true);
xhr.onload = function() {
if (xhr.status == 200) {
var res = JSON.parse(xhr.responseText);
refresh_list(res.data, currentPath);
uploadinput.value = '';
}
else {
alert('上传失败');
}
};
xhr.send(formData);
}
};

document.addEventListener('DOMContentLoaded', function(evt) {
var initPath = '/';
if (/path=([/\w]+)/.test(location.search)) {
initPath = RegExp.$1;
}
update_list(initPath, {popState: true});
});
window.addEventListener('popstate', function (evt) {
var path = '/';
if (evt.state && evt.state.path) {
path = evt.state.path;
}
update_list(path, {popState: true});
});

})();
Binary file added htdocs/luci-static/resources/fb/file-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added htdocs/luci-static/resources/fb/folder-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added htdocs/luci-static/resources/fb/link-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions luasrc/controller/advanced.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module("luci.controller.advanced",package.seeall)
function index()
if not nixio.fs.access("/etc/config/advanced")then
return
end
local e
e=entry({"admin","system","advanced"},cbi("advanced"),_("高级设置"),60)
e.dependent=true
Expand Down
Loading

0 comments on commit c554568

Please sign in to comment.