English | 简体中文
This document details the development standards and requirements for luci-app-easytier.
Must be compatible with OpenWrt 18.06 ~ 26.x, using LuCI Lua1 architecture
- Lua 5.1 standard syntax
- LuCI Lua1 API:
luci.controllerluci.model.uciluci.httpluci.sysnixio.fs
- Standard libraries:
io,os,string,table,math
- Lua2-specific syntax
- New LuCI JS API
- Any libraries requiring additional dependencies
- ES5 syntax
vardeclarationsfunctionkeywordXMLHttpRequest- Native DOM manipulation
- Native event handling
// Forbidden ES6+ syntax
let x = 1; // ❌
const y = 2; // ❌
var z = () => {}; // ❌ Arrow functions
fetch('/api'); // ❌
async/await // ❌
import/export // ❌
Template literals `${x}` // ❌
Destructuring // ❌
class syntax // ❌
// Forbidden frameworks
Vue/React/Angular // ❌
jQuery // ❌
Any build tools // ❌var xhr = new XMLHttpRequest();
xhr.open('GET', '/api/status', true);
xhr.onload = function() {
if (xhr.status === 200) {
var data = JSON.parse(xhr.responseText);
document.getElementById('status').textContent = data.status;
}
};
xhr.send();User Request → Lua Controller → Render HTM Template → Return HTML
↓
Inject initial data into page
↓
JavaScript enhances interaction
↓
AJAX calls Lua API
↓
Update partial DOM
controller/easytier.lua
├── index() # Route registration
├── act_status() # Status API
├── upload_binary() # Upload API
└── ...
view/easytier/status.htm
├── Lua template code (<%...%>)
├── HTML structure
├── CSS styles (<style>)
└── JavaScript (<script>)
local i18n = require "luci.i18n"
local translate = i18n.translate
-- Translate text
local text = translate("Hello World")<!-- Short syntax -->
<h1><%:Hello World%></h1>
<!-- Full syntax -->
<p><%=translate("Welcome to EasyTier")%></p>// Method 1: Lua injects translation
var msg = '<%=translate("Upload successful")%>';
alert(msg);
// Method 2: API returns translation
xhr.onload = function() {
var response = JSON.parse(xhr.responseText);
alert(response.message); // Already translated by backend
};# po/zh_Hans/easytier.po
msgid "Hello World"
msgstr "你好世界"
msgid "Upload successful"
msgstr "上传成功"-- controller/easytier.lua
function index()
entry({"admin", "vpn", "easytier"}, firstchild(), _("EasyTier"), 46).dependent = true
entry({"admin", "vpn", "easytier", "status"}, cbi("easytier_status"), _("Status"), 1).leaf = true
entry({"admin", "vpn", "easytier", "api_status"}, call("act_status")).leaf = true
endfunction act_status()
local uci = require "luci.model.uci".cursor()
luci.http.prepare_content("application/json")
luci.http.write_json({
success = true,
running = luci.sys.call("pgrep easytier-core >/dev/null") == 0,
version = uci:get_first("easytier", "easytier", "version")
})
endfunction updateStatus() {
var xhr = new XMLHttpRequest();
xhr.open('GET', '/cgi-bin/luci/admin/vpn/easytier/api_status', true);
xhr.onload = function() {
if (xhr.status === 200) {
var data = JSON.parse(xhr.responseText);
if (data.success) {
document.getElementById('status').textContent =
data.running ? 'Running' : 'Stopped';
}
}
};
xhr.send();
}local uci = require "luci.model.uci".cursor()
-- Read single value
local enabled = uci:get("easytier", "@easytier[0]", "enabled")
-- Read first section
local network_name = uci:get_first("easytier", "easytier", "network_name")
-- Read list
local peers = uci:get("easytier", "@easytier[0]", "peers") or {}-- Set value
uci:set("easytier", "@easytier[0]", "enabled", "1")
uci:set("easytier", "@easytier[0]", "network_name", "mynet")
-- Set list
uci:delete("easytier", "@easytier[0]", "peers")
for _, peer in ipairs(peers) do
uci:set_list("easytier", "@easytier[0]", "peers", peer)
end
-- Commit changes
uci:commit("easytier")function get_log()
local log_file = "/tmp/easytier.log"
local log = ""
if luci.sys.call("[ -f '" .. log_file .. "' ]") == 0 then
-- Remove ANSI color codes
log = luci.sys.exec("sed 's/\\x1b\\[[0-9;]*m//g' " .. log_file)
end
luci.http.write(log)
endfunction loadLog() {
var xhr = new XMLHttpRequest();
xhr.open('GET', '/cgi-bin/luci/admin/vpn/easytier/get_log', true);
xhr.onload = function() {
if (xhr.status === 200) {
var lines = xhr.responseText.split('\n');
var html = '';
for (var i = 0; i < lines.length; i++) {
var line = lines[i];
var level = 'info';
if (line.indexOf('ERROR') !== -1) level = 'error';
else if (line.indexOf('WARN') !== -1) level = 'warn';
else if (line.indexOf('DEBUG') !== -1) level = 'debug';
html += '<div class="log-line log-' + level + '">' +
escapeHtml(line) + '</div>';
}
document.getElementById('log_content').innerHTML = html;
}
};
xhr.send();
}
function escapeHtml(text) {
var div = document.createElement('div');
div.appendChild(document.createTextNode(text));
return div.innerHTML;
}/* Desktop */
.container {
max-width: 1200px;
margin: 0 auto;
}
/* Mobile */
@media (max-width: 768px) {
.container {
padding: 10px;
}
.grid {
grid-template-columns: 1fr;
}
}:root {
--bg-color: #ffffff;
--text-color: #333333;
--border-color: #e0e0e0;
}
@media (prefers-color-scheme: dark) {
:root {
--bg-color: #1e1e1e;
--text-color: #e0e0e0;
--border-color: #3e3e3e;
}
}
.card {
background: var(--bg-color);
color: var(--text-color);
border: 1px solid var(--border-color);
}Must be tested on the following environments:
- ✅ OpenWrt 18.06 (Lua1)
- ✅ OpenWrt 22.03 (Lua1/Lua2)
- ✅ OpenWrt SNAPSHOT (Lua2)
- ✅ Chrome/Edge (modern browsers)
- ✅ Firefox
- ✅ Safari (iOS)
- ✅ Mobile browsers
- Configuration save and load
- Service start and stop
- File upload
- Log display
- Status updates
- Internationalization switching
A: The browser environment in OpenWrt 18.06 doesn't support ES6; ES5 syntax must be used.
A: Cannot be compatible with older versions of OpenWrt, and JS frameworks are not suitable for low-spec routers.
A: These frameworks require build tools and have large file sizes, unsuitable for embedded environments.
A: Use XMLHttpRequest + setInterval polling, or WebSocket (requires additional support).
A: Use browser developer tools, check Console and Network tabs.
Before submitting, please confirm:
- No ES6+ syntax used
- No frontend frameworks used
- All text is internationalized
- APIs return JSON format
- Error handling is complete
- Code has appropriate comments
- Tested on OpenWrt 18.06
- Mobile display is normal
- Dark theme display is normal