%# Spectra - A Modern Responsive LuCI Theme A clean, responsive web interface for OpenWRT LuCI luci-theme-spectra Copyright 2024 Thaolga Features: - Modern responsive design - Mobile-first approach - Enhanced user experience - Customizable appearance Based on: - luci-theme-bootstrap (Apache License 2.0) - luci-theme-argon (Apache License 2.0) - Bootstrap & MUI design principles For bug reports, feature requests and contributions: https://github.com/Thaolga/openwrt-nekobox Licensed under the Apache License, Version 2.0 -%> <%+themes/spectra/out_header_login%> <% local util = require "luci.util" local fs = require "nixio.fs" local nutil = require "nixio.util" local sys = require "luci.sys" -- Fetch Local Background Media local function glob(...) local iter, code, msg = fs.glob(...) if iter then return nutil.consume(iter) else return nil, code, msg end end local imageTypes = " jpg jpeg png gif webp " local videoTypes = " mp4 webm mkv " local allTypes = imageTypes .. videoTypes local function fetchMedia(path, themeDir) local backgroundTable = {} local backgroundCount = 0 for i, f in ipairs(glob(path)) do attr = fs.stat(f) if attr then local ext = fs.basename(f):match(".+%.(%w+)$") if ext ~= nil then ext = ext:lower() end if ext ~= nil and string.match(allTypes, " "..ext.." ") ~= nil then local bg = {} bg.type = ext bg.url = themeDir .. fs.basename(f) table.insert(backgroundTable, bg) backgroundCount = backgroundCount + 1 end end end return backgroundTable, backgroundCount end local function selectBackground(themeDir) local bgUrl = media .. "/img/bg1.jpg" local backgroundType = "Image" local mimeType = "" local mediaTable, mediaCount = fetchMedia("/www" .. themeDir .. "*", themeDir) if mediaCount > 0 then local videoFiles = {} for _, mediaFile in ipairs(mediaTable) do if string.match(videoTypes, " "..mediaFile.type.." ") ~= nil then table.insert(videoFiles, mediaFile) end end if #videoFiles > 0 then local selectedVideo = videoFiles[math.random(1, #videoFiles)] bgUrl = selectedVideo.url backgroundType = "Video" mimeType = "video/" .. selectedVideo.type else local imageFiles = {} for _, mediaFile in ipairs(mediaTable) do if string.match(imageTypes, " "..mediaFile.type.." ") ~= nil then table.insert(imageFiles, mediaFile) end end if #imageFiles > 0 then local selectedImage = imageFiles[math.random(1, #imageFiles)] bgUrl = selectedImage.url backgroundType = "Image" end end end return bgUrl, backgroundType, mimeType end local boardinfo = util.ubus("system", "board") local themeDir = "/luci-static/spectra/bgm/" local bgUrl, backgroundType, mimeType = selectBackground(themeDir) %>