mirror of
https://github.com/coolsnowwolf/lede.git
synced 2025-04-19 14:13:30 +00:00
luci-app-kodexplorer: add kode owncloud
This commit is contained in:
parent
44e62959ac
commit
9950979660
18
package/lean/luci-app-kodexplorer/Makefile
Normal file
18
package/lean/luci-app-kodexplorer/Makefile
Normal file
@ -0,0 +1,18 @@
|
||||
# Copyright (C) 2018 Lienol
|
||||
#
|
||||
# This is free software, licensed under the Apache License, Version 2.0 .
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
LUCI_TITLE:=LuCI support for KodExplorer
|
||||
LUCI_DEPENDS:=+nginx +zoneinfo-asia +php7 +php7-fpm +php7-mod-curl +php7-mod-gd +php7-mod-iconv +php7-mod-json +php7-mod-mbstring +php7-mod-opcache +php7-mod-session +php7-mod-zip
|
||||
LUCI_PKGARCH:=all
|
||||
PKG_VERSION:=1.0
|
||||
PKG_RELEASE:=2-20181208
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
||||
|
||||
|
@ -0,0 +1,48 @@
|
||||
module("luci.controller.kodexplorer", package.seeall)
|
||||
|
||||
local http = require "luci.http"
|
||||
local api = require "luci.model.cbi.kodexplorer.api"
|
||||
|
||||
function index()
|
||||
if not nixio.fs.access("/etc/config/kodexplorer") then
|
||||
return
|
||||
end
|
||||
|
||||
entry({"admin","nas","kodexplorer"},cbi("kodexplorer/settings"),_("KodExplorer"),3).dependent=true
|
||||
|
||||
entry({"admin","nas","kodexplorer","check"},call("action_check")).leaf=true
|
||||
entry({"admin","nas","kodexplorer","download"},call("action_download")).leaf=true
|
||||
entry({"admin","nas","kodexplorer","status"},call("act_status")).leaf=true
|
||||
end
|
||||
|
||||
local function http_write_json(content)
|
||||
http.prepare_content("application/json")
|
||||
http.write_json(content or { code = 1 })
|
||||
end
|
||||
|
||||
function act_status()
|
||||
local nginx="nginx"
|
||||
local php_fpm="php-fpm"
|
||||
local e={}
|
||||
e.nginx_status=luci.sys.call("ps | grep -v grep | grep '"..nginx.."' >/dev/null")==0
|
||||
e.php_status=luci.sys.call("ps | grep -v grep | grep '"..php_fpm.."' >/dev/null")==0
|
||||
http_write_json(e)
|
||||
end
|
||||
|
||||
function action_check()
|
||||
local json = api.to_check()
|
||||
http_write_json(json)
|
||||
end
|
||||
|
||||
function action_download()
|
||||
local json = nil
|
||||
local task = http.formvalue("task")
|
||||
if task == "extract" then
|
||||
json = api.to_extract(http.formvalue("file"))
|
||||
elseif task == "move" then
|
||||
json = api.to_move(http.formvalue("file"))
|
||||
else
|
||||
json = api.to_download(http.formvalue("url"))
|
||||
end
|
||||
http_write_json(json)
|
||||
end
|
@ -0,0 +1,220 @@
|
||||
-- Copyright 2018 Lienol <lienol@qq.com>
|
||||
-- Licensed to the public under the Apache License 2.0.
|
||||
|
||||
local fs = require "nixio.fs"
|
||||
local sys = require "luci.sys"
|
||||
local uci = require "luci.model.uci".cursor()
|
||||
local util = require "luci.util"
|
||||
local i18n = require "luci.i18n"
|
||||
|
||||
module("luci.model.cbi.kodexplorer.api", package.seeall)
|
||||
|
||||
local api_url = "https://api.github.com/repos/kalcaddle/KodExplorer/releases/latest"
|
||||
local download_url = "https://github.com/kalcaddle/KodExplorer/archive/"
|
||||
|
||||
local wget = "/usr/bin/wget"
|
||||
local wget_args = { "--no-check-certificate", "--quiet", "--timeout=10", "--tries=2" }
|
||||
local curl = "/usr/bin/curl"
|
||||
local command_timeout = 40
|
||||
|
||||
local function _unpack(t, i)
|
||||
i = i or 1
|
||||
if t[i] ~= nil then
|
||||
return t[i], _unpack(t, i + 1)
|
||||
end
|
||||
end
|
||||
|
||||
local function exec(cmd, args, writer, timeout)
|
||||
local os = require "os"
|
||||
local nixio = require "nixio"
|
||||
|
||||
local fdi, fdo = nixio.pipe()
|
||||
local pid = nixio.fork()
|
||||
|
||||
if pid > 0 then
|
||||
fdo:close()
|
||||
|
||||
if writer or timeout then
|
||||
local starttime = os.time()
|
||||
while true do
|
||||
if timeout and os.difftime(os.time(), starttime) >= timeout then
|
||||
nixio.kill(pid, nixio.const.SIGTERM)
|
||||
return 1
|
||||
end
|
||||
|
||||
if writer then
|
||||
local buffer = fdi:read(2048)
|
||||
if buffer and #buffer > 0 then
|
||||
writer(buffer)
|
||||
end
|
||||
end
|
||||
|
||||
local wpid, stat, code = nixio.waitpid(pid, "nohang")
|
||||
|
||||
if wpid and stat == "exited" then
|
||||
return code
|
||||
end
|
||||
|
||||
if not writer and timeout then
|
||||
nixio.nanosleep(1)
|
||||
end
|
||||
end
|
||||
else
|
||||
local wpid, stat, code = nixio.waitpid(pid)
|
||||
return wpid and stat == "exited" and code
|
||||
end
|
||||
elseif pid == 0 then
|
||||
nixio.dup(fdo, nixio.stdout)
|
||||
fdi:close()
|
||||
fdo:close()
|
||||
nixio.exece(cmd, args, nil)
|
||||
nixio.stdout:close()
|
||||
os.exit(1)
|
||||
end
|
||||
end
|
||||
|
||||
local function compare_versions(ver1, comp, ver2)
|
||||
local table = table
|
||||
|
||||
local av1 = util.split(ver1, "[%.%-]", nil, true)
|
||||
local av2 = util.split(ver2, "[%.%-]", nil, true)
|
||||
|
||||
local max = table.getn(av1)
|
||||
local n2 = table.getn(av2)
|
||||
if (max < n2) then
|
||||
max = n2
|
||||
end
|
||||
|
||||
for i = 1, max, 1 do
|
||||
local s1 = av1[i] or ""
|
||||
local s2 = av2[i] or ""
|
||||
|
||||
if comp == "~=" and (s1 ~= s2) then return true end
|
||||
if (comp == "<" or comp == "<=") and (s1 < s2) then return true end
|
||||
if (comp == ">" or comp == ">=") and (s1 > s2) then return true end
|
||||
if (s1 ~= s2) then return false end
|
||||
end
|
||||
|
||||
return not (comp == "<" or comp == ">")
|
||||
end
|
||||
|
||||
local function get_api_json(url)
|
||||
local jsonc = require "luci.jsonc"
|
||||
|
||||
local output = { }
|
||||
--exec(wget, { "-O-", url, _unpack(wget_args) },
|
||||
-- function(chunk) output[#output + 1] = chunk end)
|
||||
--local json_content = util.trim(table.concat(output))
|
||||
|
||||
local json_content = luci.sys.exec(curl.." -sL "..url)
|
||||
|
||||
if json_content == "" then
|
||||
return { }
|
||||
end
|
||||
|
||||
return jsonc.parse(json_content) or { }
|
||||
end
|
||||
|
||||
function get_config_option(option, default)
|
||||
return uci:get("kcptun", "general", option) or default
|
||||
end
|
||||
|
||||
function to_check()
|
||||
local json = get_api_json(api_url)
|
||||
if json.tag_name == nil then
|
||||
return {
|
||||
code = 1,
|
||||
error = i18n.translate("Get remote version info failed.")
|
||||
}
|
||||
end
|
||||
local remote_version = json.tag_name
|
||||
local html_url = json.html_url
|
||||
download_url = download_url..json.tag_name..".tar.gz"
|
||||
if not download_url then
|
||||
return {
|
||||
code = 1,
|
||||
version = remote_version,
|
||||
html_url = html_url,
|
||||
error = i18n.translate("New version found, but failed to get new version download url.")
|
||||
}
|
||||
end
|
||||
return {
|
||||
code = 0,
|
||||
version = remote_version,
|
||||
url = {
|
||||
html = html_url,
|
||||
download = download_url
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
function to_download(url)
|
||||
if not url or url == "" then
|
||||
return {
|
||||
code = 1,
|
||||
error = i18n.translate("Download url is required.")
|
||||
}
|
||||
end
|
||||
|
||||
sys.call("/bin/rm -f /tmp/kodexplorer_download.*")
|
||||
|
||||
local tmp_file = util.trim(util.exec("mktemp -u -t kodexplorer_download.XXXXXX"))
|
||||
|
||||
local result = exec(wget, {
|
||||
"-O", tmp_file, url, _unpack(wget_args) }, nil, command_timeout) == 0
|
||||
|
||||
if not result then
|
||||
exec("/bin/rm", { "-f", tmp_file })
|
||||
return {
|
||||
code = 1,
|
||||
error = i18n.translatef("File download failed or timed out: %s", url)
|
||||
}
|
||||
end
|
||||
|
||||
return {
|
||||
code = 0,
|
||||
file = tmp_file
|
||||
}
|
||||
end
|
||||
|
||||
function to_extract(file)
|
||||
if not file or file == "" or not fs.access(file) then
|
||||
return {
|
||||
code = 1,
|
||||
error = i18n.translate("File path required.")
|
||||
}
|
||||
end
|
||||
|
||||
sys.call("/bin/rm -rf /tmp/kodexplorer_extract.*")
|
||||
local tmp_dir = util.trim(util.exec("mktemp -d -t kodexplorer_extract.XXXXXX"))
|
||||
|
||||
local output = { }
|
||||
exec("/bin/tar", { "-C", tmp_dir, "-zxvf", file },
|
||||
function(chunk) output[#output + 1] = chunk end)
|
||||
|
||||
local files = util.split(table.concat(output))
|
||||
|
||||
exec("/bin/rm", { "-f", file })
|
||||
|
||||
return {
|
||||
code = 0,
|
||||
file = tmp_dir
|
||||
}
|
||||
end
|
||||
|
||||
function to_move(file)
|
||||
if not file or file == "" or not fs.access(file) then
|
||||
sys.call("/bin/rm -rf /tmp/kodexplorer_extract.*")
|
||||
return {
|
||||
code = 1,
|
||||
error = i18n.translate("Client file is required.")
|
||||
}
|
||||
end
|
||||
|
||||
local client_file = get_config_option("storage_directory", "/mnt/sda1/kodexplorer")
|
||||
sys.call("mkdir -p "..client_file)
|
||||
sys.call("cp -R "..file.."/KodExplorer*/* "..client_file)
|
||||
sys.call("/bin/rm -rf /tmp/kodexplorer_extract.*")
|
||||
|
||||
return { code = 0 }
|
||||
end
|
@ -0,0 +1,43 @@
|
||||
m = Map("kodexplorer",translate("KodExplorer"),translate("KodExplorer是一款快捷高效的私有云和在线文档管理系统,为个人网站、企业私有云部署、网络存储、在线文档管理、在线办公等提供安全可控,简便易用、可高度定制的私有云产品。采用windows风格界面、操作习惯,无需适应即可快速上手,支持几百种常用文件格式的在线预览,可扩展易定制。"))
|
||||
m:append(Template("kodexplorer/status"))
|
||||
|
||||
s = m:section(TypedSection,"global",translate("Global Setting"))
|
||||
s.anonymous = true
|
||||
s.addremove = false
|
||||
|
||||
o = s:option(Flag,"enable",translate("Enable"))
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Value, "port", translate("Nginx监听端口"))
|
||||
o.datatype="port"
|
||||
o.default=81
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Value, "memory_limit", translate("内存最大使用"), translate("如果你的设备内存较大的话,可以适当增加。"))
|
||||
o.default="8M"
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Value, "post_max_size", translate("POST最大容量"), translate("该值不能大于 内存最大使用"))
|
||||
o.default="12M"
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Value, "upload_max_filesize", translate("上传文件最大使用内存"), translate("该值不能大于 POST最大容量"))
|
||||
o.default="12M"
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Value, "storage_device_path", translate("存储设备路径"), translate("建议插入U盘或硬盘,然后输入路径。例如:/mnt/sda1/"))
|
||||
o.default="/mnt/sda1/"
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Value, "project_directory", translate("项目存放目录"), translate("建议插入U盘或硬盘,然后输入路径。例如:/mnt/sda1/kodexplorer"))
|
||||
o.default="/mnt/sda1/kodexplorer"
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Button, "_download", translate("手动下载"),
|
||||
translate("请确保具有足够的空间。<br /><font style='color:red'>第一次运行务必填好设备路径和存放路径,然后保存应用。再手动下载,否则无法使用!</font>"))
|
||||
o.template = "kodexplorer/download"
|
||||
o.inputstyle = "apply"
|
||||
o.btnclick = "downloadClick(this);"
|
||||
o.id="download_btn"
|
||||
|
||||
return m
|
@ -0,0 +1,174 @@
|
||||
<%#
|
||||
Copyright 2018 <lienol@qq.com>
|
||||
Licensed to the public under the Apache License 2.0.
|
||||
-%>
|
||||
|
||||
<%
|
||||
local dsp = require "luci.dispatcher"
|
||||
-%>
|
||||
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
var msgInfo;
|
||||
|
||||
var tokenStr = '<%=token%>';
|
||||
var clickToDownloadText = '<%:点击下载%>';
|
||||
var inProgressText = '<%:正在下载...%>';
|
||||
var downloadInProgressNotice = '<%:正在下载,你确认要关闭吗?%>';
|
||||
var downloadSuccessText = '<%:下载成功.%>';
|
||||
var unexpectedErrorText = '<%:意外错误.%>';
|
||||
|
||||
function addPageNotice() {
|
||||
window.onbeforeunload = function(e) {
|
||||
e.returnValue = downloadInProgressNotice;
|
||||
return downloadInProgressNotice;
|
||||
};
|
||||
}
|
||||
|
||||
function removePageNotice() {
|
||||
window.onbeforeunload = undefined;
|
||||
}
|
||||
|
||||
function onUpdateSuccess(btn) {
|
||||
alert(downloadSuccessText);
|
||||
|
||||
if (btn) {
|
||||
btn.value = downloadSuccessText;
|
||||
btn.placeholder = downloadSuccessText;
|
||||
btn.disabled = true;
|
||||
}
|
||||
|
||||
window.setTimeout(function () {
|
||||
window.location.reload();
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function onRequestError(btn, errorMessage) {
|
||||
btn.disabled = false;
|
||||
btn.value = btn.placeholder;
|
||||
|
||||
if (errorMessage) {
|
||||
alert(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
function doAjaxGet(url, data, onResult) {
|
||||
new XHR().get(url, data, function(_, json) {
|
||||
var resultJson = json || {
|
||||
'code': 1,
|
||||
'error': unexpectedErrorText
|
||||
};
|
||||
|
||||
if (typeof onResult === 'function') {
|
||||
onResult(resultJson);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function downloadClick(btn) {
|
||||
if (msgInfo === undefined) {
|
||||
checkUpdate(btn);
|
||||
} else {
|
||||
doDownload(btn);
|
||||
}
|
||||
}
|
||||
|
||||
function checkUpdate(btn) {
|
||||
btn.disabled = true;
|
||||
btn.value = inProgressText;
|
||||
|
||||
addPageNotice();
|
||||
|
||||
var ckeckDetailElm = document.getElementById(btn.id + '-detail');
|
||||
|
||||
doAjaxGet('<%=dsp.build_url("admin/nas/kodexplorer/check")%>/', {
|
||||
token: tokenStr
|
||||
}, function (json) {
|
||||
removePageNotice();
|
||||
if (json.code) {
|
||||
eval('Info = undefined');
|
||||
onRequestError(btn, json.error);
|
||||
} else {
|
||||
eval('Info = json');
|
||||
btn.disabled = false;
|
||||
btn.value = clickToDownloadText;
|
||||
btn.placeholder = clickToDownloadText;
|
||||
}
|
||||
|
||||
if (ckeckDetailElm) {
|
||||
var urlNode = '';
|
||||
if (json.version) {
|
||||
urlNode = '<em style="color:red;">最新版本号:' + json.version + '</em>';
|
||||
if (json.url && json.url.html) {
|
||||
urlNode = '<a href="' + json.url.html + '" target="_blank">' + urlNode + '</a>';
|
||||
}
|
||||
}
|
||||
ckeckDetailElm.innerHTML = urlNode;
|
||||
}
|
||||
msgInfo = json;
|
||||
});
|
||||
}
|
||||
|
||||
function doDownload(btn) {
|
||||
btn.disabled = true;
|
||||
btn.value = '<%:下载中...%>';
|
||||
|
||||
addPageNotice();
|
||||
|
||||
var UpdateUrl = '<%=dsp.build_url("admin/nas/kodexplorer/download")%>';
|
||||
// Download file
|
||||
doAjaxGet(UpdateUrl, {
|
||||
token: tokenStr,
|
||||
url: msgInfo ? msgInfo.url.download : ''
|
||||
}, function (json) {
|
||||
if (json.code) {
|
||||
removePageNotice();
|
||||
onRequestError(btn, json.error);
|
||||
} else {
|
||||
btn.value = '<%:解压中...%>';
|
||||
|
||||
// Extract file
|
||||
doAjaxGet(UpdateUrl, {
|
||||
token: tokenStr,
|
||||
task: 'extract',
|
||||
file: json.file
|
||||
}, function (json) {
|
||||
if (json.code) {
|
||||
removePageNotice();
|
||||
onRequestError(btn, json.error);
|
||||
} else {
|
||||
btn.value = '<%:移动中...%>';
|
||||
|
||||
// Move file to target dir
|
||||
doAjaxGet(UpdateUrl, {
|
||||
token: tokenStr,
|
||||
task: 'move',
|
||||
file: json.file
|
||||
}, function (json) {
|
||||
removePageNotice();
|
||||
if (json.code) {
|
||||
onRequestError(btn, json.error);
|
||||
} else {
|
||||
onUpdateSuccess(btn);
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
//]]></script>
|
||||
|
||||
<%+cbi/valueheader%>
|
||||
<% if self:cfgvalue(section) ~= false then %>
|
||||
<input class="cbi-button cbi-input-<%=self.inputstyle or "button" %>" type="button"<%=
|
||||
attr("name", cbid) ..
|
||||
attr("id", self.id or cbid) ..
|
||||
attr("value", self.inputtitle or self.title) ..
|
||||
ifattr(self.btnclick, "onclick", self.btnclick) ..
|
||||
ifattr(self.placeholder, "placeholder")
|
||||
%> />
|
||||
<span id="<%=self.id or cbid%>-detail"></span>
|
||||
<% else %>
|
||||
-
|
||||
<% end %>
|
||||
<%+cbi/valuefooter%>
|
@ -0,0 +1,36 @@
|
||||
<%#
|
||||
Copyright 2018 Lienol
|
||||
Licensed to the public under the Apache License 2.0.
|
||||
-%>
|
||||
|
||||
<%
|
||||
local dsp = require "luci.dispatcher"
|
||||
-%>
|
||||
|
||||
<fieldset class="cbi-section">
|
||||
<legend><%:Running Status%></legend>
|
||||
<fieldset class="cbi-section">
|
||||
<div class="cbi-value">
|
||||
<label class="cbi-value-title">Nginx <%:Status%></label>
|
||||
<div class="cbi-value-field" id="_nginx_status"><%:Collecting data...%></div>
|
||||
</div>
|
||||
<div class="cbi-value">
|
||||
<label class="cbi-value-title">PHP <%:Status%></label>
|
||||
<div class="cbi-value-field" id="_php_status"><%:Collecting data...%></div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</fieldset>
|
||||
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
var nginx_status = document.getElementById('_nginx_status');
|
||||
var php_status = document.getElementById('_php_status');
|
||||
XHR.poll(3,'<%=dsp.build_url("admin/nas/kodexplorer/status")%>', null,
|
||||
function(x, json) {
|
||||
if (x && x.status == 200) {
|
||||
if (nginx_status)
|
||||
nginx_status.innerHTML = json.nginx_status ? '<font color=green><%:RUNNING%> ✓</font>' : '<font color=red><%:NOT RUNNING%> X</font>';
|
||||
if (php_status)
|
||||
php_status.innerHTML = json.php_status ? '<font color=green><%:RUNNING%> ✓</font>' : '<font color=red><%:NOT RUNNING%> X</font>';
|
||||
}
|
||||
});
|
||||
//]]></script>
|
@ -0,0 +1,2 @@
|
||||
msgid "KodExplorer"
|
||||
msgstr "可道云"
|
@ -0,0 +1,10 @@
|
||||
|
||||
config global
|
||||
option port '81'
|
||||
option memory_limit '8M'
|
||||
option post_max_size '12M'
|
||||
option upload_max_filesize '12M'
|
||||
option storage_device_path '/mnt/sda1/'
|
||||
option project_directory '/mnt/sda1/kodexplorer'
|
||||
option enable '0'
|
||||
|
169
package/lean/luci-app-kodexplorer/root/etc/init.d/kodexplorer
Normal file
169
package/lean/luci-app-kodexplorer/root/etc/init.d/kodexplorer
Normal file
@ -0,0 +1,169 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2018 Lienol <admin@lienol.cn>
|
||||
|
||||
START=99
|
||||
|
||||
CONFIG="kodexplorer"
|
||||
|
||||
TEMP_PATH="/var/etc/kodexplorer"
|
||||
NGINX_CONFIG="$TEMP_PATH/nginx.conf"
|
||||
PHP_FPM_CONFIG="$TEMP_PATH/php-fpm.conf"
|
||||
PHP_CONFIG="/etc/php.ini"
|
||||
PHP_BACKUP_CONFIG="/etc/php.ini.backup"
|
||||
|
||||
config_t_get() {
|
||||
local index=0
|
||||
[ -n "$4" ] && index=$4
|
||||
local ret=$(uci get $CONFIG.@$1[$index].$2 2>/dev/null)
|
||||
echo ${ret:=$3}
|
||||
}
|
||||
|
||||
gen_nginx_config() {
|
||||
port=$(config_t_get global port)
|
||||
project_directory=$(config_t_get global project_directory)
|
||||
cat <<-EOF >$NGINX_CONFIG
|
||||
user root root;
|
||||
worker_processes 1;
|
||||
pid /var/run/nginx_kodexplorer.pid;
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
http {
|
||||
include /etc/nginx/mime.types;
|
||||
sendfile on;
|
||||
keepalive_timeout 65;
|
||||
server {
|
||||
listen $port;
|
||||
server_name localhost;
|
||||
location / {
|
||||
root $project_directory;
|
||||
index index.html index.htm index.php;
|
||||
}
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
location = /50x.html {
|
||||
root html;
|
||||
}
|
||||
location ~ \.php$ {
|
||||
root $project_directory;
|
||||
try_files \$uri = 404; # PHP 文件不存在返回404
|
||||
fastcgi_pass unix:/var/run/php7-fpm.sock; # 通过 Unix 套接字执行 PHP
|
||||
fastcgi_index index.php;
|
||||
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name; # 修复 Nginx fastcgi 漏洞
|
||||
include /etc/nginx/fastcgi_params;
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
}
|
||||
|
||||
gen_php_config() {
|
||||
storage_device_path=$(config_t_get global storage_device_path)
|
||||
memory_limit=$(config_t_get global memory_limit)
|
||||
post_max_size=$(config_t_get global post_max_size)
|
||||
upload_max_filesize=$(config_t_get global upload_max_filesize)
|
||||
cp $PHP_CONFIG $PHP_BACKUP_CONFIG
|
||||
cat <<-EOF >$PHP_CONFIG
|
||||
[PHP]
|
||||
zend.ze1_compatibility_mode = Off
|
||||
engine = On
|
||||
precision = 12
|
||||
y2k_compliance = On
|
||||
output_buffering = Off
|
||||
zlib.output_compression = Off
|
||||
implicit_flush = Off
|
||||
unserialize_callback_func =
|
||||
serialize_precision = 100
|
||||
|
||||
open_basedir = $storage_device_path:/tmp/:/proc/
|
||||
disable_functions =
|
||||
disable_classes =
|
||||
expose_php = On
|
||||
max_execution_time = 30
|
||||
max_input_time = 60
|
||||
memory_limit = $memory_limit
|
||||
error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT
|
||||
|
||||
display_errors = On
|
||||
display_startup_errors = Off
|
||||
log_errors = Off
|
||||
log_errors_max_len = 1024
|
||||
ignore_repeated_errors = Off
|
||||
ignore_repeated_source = Off
|
||||
report_memleaks = On
|
||||
track_errors = Off
|
||||
|
||||
variables_order = "EGPCS"
|
||||
request_order = "GP"
|
||||
register_globals = Off
|
||||
register_long_arrays = Off
|
||||
register_argc_argv = On
|
||||
auto_globals_jit = On
|
||||
post_max_size = $post_max_size
|
||||
magic_quotes_runtime = Off
|
||||
magic_quotes_sybase = Off
|
||||
auto_prepend_file =
|
||||
auto_append_file =
|
||||
default_mimetype = "text/html"
|
||||
|
||||
;doc_root = "/www"
|
||||
user_dir =
|
||||
extension_dir = "/usr/lib/php"
|
||||
enable_dl = On
|
||||
cgi.fix_pathinfo=1
|
||||
|
||||
file_uploads = On
|
||||
upload_tmp_dir = "/tmp"
|
||||
upload_max_filesize = $upload_max_filesize
|
||||
max_file_uploads = 20
|
||||
|
||||
allow_url_fopen = On
|
||||
allow_url_include = Off
|
||||
default_socket_timeout = 60
|
||||
EOF
|
||||
cat <<-EOF >$PHP_FPM_CONFIG
|
||||
[global]
|
||||
pid = /var/run/kodexplorer_php7-fpm.pid
|
||||
error_log = /var/log/kodexplorer_php7-fpm.log
|
||||
[www]
|
||||
user = root
|
||||
listen = /var/run/php7-fpm.sock
|
||||
listen.mode = 0666
|
||||
listen.allowed_clients = 127.0.0.1
|
||||
pm = dynamic
|
||||
pm.max_children = 5
|
||||
pm.start_servers = 2
|
||||
pm.min_spare_servers = 1
|
||||
pm.max_spare_servers = 3
|
||||
chdir = /
|
||||
EOF
|
||||
}
|
||||
|
||||
start() {
|
||||
ENABLED=$(config_t_get global enable 0)
|
||||
[ "$ENABLED" = "0" ] && return 0
|
||||
mkdir -p $TEMP_PATH /var/log/nginx /var/lib/nginx
|
||||
gen_nginx_config
|
||||
gen_php_config
|
||||
/usr/bin/php-fpm -R -y $PHP_FPM_CONFIG -g "/var/run/php7-fpm.pid"
|
||||
/usr/sbin/nginx -c $NGINX_CONFIG
|
||||
}
|
||||
|
||||
stop() {
|
||||
kill -9 `cat /var/run/nginx_kodexplorer.pid` >/dev/null 2>&1 &
|
||||
killall -9 php-fpm nginx >/dev/null 2>&1 &
|
||||
rm -f /var/run/nginx_kodexplorer.pid
|
||||
rm -f /var/run/kodexplorer_php7-fpm.pid
|
||||
rm -f /var/log/kodexplorer_php7-fpm.log
|
||||
rm -f /var/run/php7-fpm.sock
|
||||
[ -f "$PHP_BACKUP_CONFIG" -a -f "$PHP_CONFIG" ] && {
|
||||
rm -f $PHP_CONFIG
|
||||
cp $PHP_BACKUP_CONFIG $PHP_CONFIG
|
||||
rm -f $PHP_BACKUP_CONFIG
|
||||
}
|
||||
}
|
||||
|
||||
restart() {
|
||||
stop
|
||||
sleep 1
|
||||
start
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete ucitrack.@kodexplorer[-1]
|
||||
add ucitrack kodexplorer
|
||||
set ucitrack.@kodexplorer[-1].init=kodexplorer
|
||||
commit ucitrack
|
||||
EOF
|
||||
|
||||
/etc/init.d/php7-fpm disable && /etc/init.d/php7-fpm stop
|
||||
/etc/init.d/nginx disable && /etc/init.d/nginx stop
|
||||
rm -f /tmp/luci-indexcache
|
||||
exit 0
|
Loading…
Reference in New Issue
Block a user