{# Argon is a clean HTML5 theme for LuCI. It is based on luci-theme-bootstrap and MUI and Argon Template luci-theme-argon Copyright 2020 Jerryk Have a bug? Please create an issue here on GitHub! https://github.com/jerrykuku/luci-theme-argon/issues luci-theme-bootstrap: Copyright 2008 Steven Barth Copyright 2008-2016 Jo-Philipp Wich Copyright 2012 David Menting MUI: https://github.com/muicss/mui Argon Theme https://demos.creative-tim.com/argon-dashboard/index.html Licensed to the public under the Apache License 2.0 -#} {% include("themes/" + theme + "/out_header_login") %} {% import * as fs from 'fs'; import { cursor } from 'uci'; let cfg = cursor(); // Per-request pseudo-random state for selecting local backgrounds. let lcgState = (+time()) % 2147483648; function randomIndex(limit) { lcgState = (lcgState * 1103515245 + 12345) % 2147483648; return lcgState % limit; } //Fetch Local Background Media const imageTypes = " jpg jpeg png gif webp "; const videoTypes = " mp4 webm "; const allTypes = imageTypes + videoTypes; function fetchMedia(path, themeDir) { let backgroundTable = []; for (f in (fs.lsdir(path))) { let parts = split(f, '.'); let ext = lc(parts?.[length(parts) - 1]); if (ext && index(allTypes, " " + ext + " ") != -1) { let bg = {}; bg.type = ext; bg.url = themeDir + http.urlencode(f); push(backgroundTable, bg); } } return backgroundTable; } function selectBackground(themeDir) { let bgUrl = media + "/img/bg1.jpg"; let backgroundType = "Image"; let mimeType = ""; if (fs.access("/etc/config/argon")) { online_wallpaper = cfg.get_first('argon', 'global', 'online_wallpaper') ?? (cfg.get_first('argon', 'global', 'bing_background') == '1' ? 'bing' : null); if (online_wallpaper && online_wallpaper != "none") { const picurl = ubus.call("luci.argon_wallpaper", "get_url") ?? {}; if (type(picurl?.url) == 'string' && match(picurl.url, /^https:\/\/[^[:space:]"'<>]+$/)) { bgUrl = picurl.url; return {bgUrl, backgroundType, mimeType}; } } } let background = fetchMedia("/www" + themeDir, themeDir); if ( length(background) > 0 ) { let currentBg = background[randomIndex(length(background))]; bgUrl = currentBg.url; if (index(videoTypes, " " + currentBg.type + " ") != -1) { backgroundType = "Video"; mimeType = "video/" + currentBg.type; } } return {bgUrl, backgroundType, mimeType}; } const boardinfo = ubus.call("system", "board"); const hostname = striptags(boardinfo?.hostname ?? '?'); const themeDir = media + "/background/"; const bgArry = selectBackground(themeDir); %}