mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-02 15:03:56 +08:00
🐤 Sync 2026-07-30 00:01:42
This commit is contained in:
1 parent
04fb515e5a
commit
6a78b2a925
34 files changed
+472
-290
No files matched your search
@@ -32,6 +32,7 @@ validate_section() {
|
||||
'use_auth:bool:0' \
|
||||
'auth_users:list(string)' \
|
||||
'readonly_users:list(string)' \
|
||||
'autologin_user:string' \
|
||||
'global_readonly:bool:0' \
|
||||
'root_path:directory' \
|
||||
'date_format:or("d.m.o", "d-m-o", "d/m/o", "j.n.o", "j-n-o", "j/n/o", "o.m.d", "o-m-d", "o/m/d", "o.n.j", "o-n-j", "o/n/j"):d.m.o' \
|
||||
@@ -50,6 +51,7 @@ init_config() {
|
||||
s|// --- EDIT BELOW CONFIGURATION CAREFULLY ---|\<?php\n$defconf|; \
|
||||
s|// --- EDIT BELOW CAREFULLY OR DO NOT EDIT AT ALL ---|?\>|; \
|
||||
/\/\/ if User has the external config file, try to use it to override the default config above/,/^}/d; \
|
||||
/^define(/d; \
|
||||
p \
|
||||
}" "$WORKDIR/index.php" > "$1"
|
||||
|
||||
@@ -72,6 +74,7 @@ apply_config() {
|
||||
|
||||
[ -n "$defconf" ] && sed -Ei "s|^\\\$CONFIG\s*=.*|\$CONFIG = '$defconf'\;|" "$_conf"
|
||||
[ "$use_auth" -eq "1" ] && sed -Ei "s|(^\\\$use_auth =)(.+)|\1 true;|" "$_conf" || sed -Ei "s|(^\\\$use_auth =)(.+)|\1 false;|" "$_conf"
|
||||
[ -n "$autologin_user" ] && sed -Ei "s|\?>|\$luci_autologin_user = '$autologin_user';\ninclude '/usr/share/tinyfilemanager/auto-login-base-luci.php';\n\n?>|" "$_conf"
|
||||
[ "$global_readonly" -eq "1" ] && sed -Ei "s|(^\\\$global_readonly =)(.+)|\1 true;|" "$_conf" || sed -Ei "s|(^\\\$global_readonly =)(.+)|\1 false;|" "$_conf"
|
||||
sed -Ei "/^\\\$auth_users /,/\);/{/^ /d}" "$_conf" && sed -Ei "/^\\\$auth_users /a\ $auth_users" "$_conf"
|
||||
sed -Ei "/^\\\$readonly_users /,/\);/{/^ /d}" "$_conf" && sed -Ei "/^\\\$readonly_users /a\ $readonly_users" "$_conf"
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
# unpack
|
||||
tar -C /www/tinyfilemanager -xzf /www/tinyfilemanager/index.tgz
|
||||
rm -f /www/tinyfilemanager/index.tgz
|
||||
|
||||
# uhttpd
|
||||
uci -q get uhttpd.main.index_page|grep -i 'index.php' >/dev/null || uci add_list uhttpd.main.index_page='index.php'
|
||||
uci -q get uhttpd.main.interpreter|grep -i '.php=/usr/bin/php-cgi' >/dev/null || uci add_list uhttpd.main.interpreter='.php=/usr/bin/php-cgi'
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
// Validates LuCI session via ubus on every request.
|
||||
// Auto-login when accessed from LuCI menu (luci_sid passed in URL).
|
||||
// Forces logout when LuCI session expires.
|
||||
|
||||
if (!defined('FM_SESSION_ID')) define('FM_SESSION_ID', 'filemanager');
|
||||
session_name('filemanager');
|
||||
session_start();
|
||||
|
||||
function luci_validate_sid($sid) {
|
||||
if (empty($sid) || !preg_match('/^[a-f0-9]{32}$/', $sid)) return false;
|
||||
$out = shell_exec('ubus call session get \'{"ubus_rpc_session":"' . $sid . '"}\' 2>/dev/null');
|
||||
return $out && strpos($out, '"username"') !== false;
|
||||
}
|
||||
|
||||
// Step 1: luci_sid in URL → validate and auto-login
|
||||
if (!empty($_GET['luci_sid'])) {
|
||||
$sid = preg_replace('/[^a-f0-9]/', '', $_GET['luci_sid']);
|
||||
if (luci_validate_sid($sid)) {
|
||||
$_SESSION['filemanager']['logged'] = $luci_autologin_user;
|
||||
$_SESSION['filemanager']['luci_sid'] = $sid;
|
||||
session_write_close();
|
||||
header('Location: /tinyfilemanager/');
|
||||
exit;
|
||||
} else {
|
||||
unset($_SESSION['filemanager']['logged']);
|
||||
unset($_SESSION['filemanager']['luci_sid']);
|
||||
session_write_close();
|
||||
http_response_code(403);
|
||||
die('LuCI session invalid or expired.');
|
||||
}
|
||||
}
|
||||
|
||||
// Step 2: On every request, re-validate stored LuCI session
|
||||
if (!empty($_SESSION['filemanager']['logged'])) {
|
||||
$sid = $_SESSION['filemanager']['luci_sid'] ?? '';
|
||||
if (!luci_validate_sid($sid)) {
|
||||
// LuCI session expired → force logout
|
||||
unset($_SESSION['filemanager']['logged']);
|
||||
unset($_SESSION['filemanager']['luci_sid']);
|
||||
session_write_close();
|
||||
header('Location: /tinyfilemanager/');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
session_write_close();
|
||||
|
||||
?>
|
||||
Reference in new issue
Block a user