4c53474ffe
- Add custom rules editor to LUCI web interface - Support 32 rule types (DOMAIN, IP-CIDR, GEOSITE, etc.) - Rule CRUD, sorting, batch import, templates - netflow-rules script for mihomo config injection - Standalone IPK repackaging support
52 lines
2.4 KiB
Python
52 lines
2.4 KiB
Python
"""Build LuCI template version from working file."""
|
|
with open(r'E:\AI Project\WangAgent\_tmp_extract\router_live.htm', 'r', encoding='utf-8') as f:
|
|
c = f.read()
|
|
|
|
# Remove standalone HTML wrapper (everything before <style> and after </script>)
|
|
# Current file structure: <!DOCTYPE html>\n<html...><head...><style>...</style>...<script>...</script></body></html>
|
|
# LuCI template needs: <%+header%>\n<style>...</style>\n...\n<script>...</script>\n<%+footer%>
|
|
|
|
# Find the actual content
|
|
style_start = c.find('<style>')
|
|
script_end = c.find('</script>') + 9
|
|
|
|
# Remove the outer HTML wrapper
|
|
content = c[style_start:script_end]
|
|
|
|
# Add LuCI template tags
|
|
content = '<%+header%>\n' + content + '\n<%+footer%>'
|
|
|
|
# Replace API URLs
|
|
old_api = "var apiUrl = '<%=luci.dispatcher.build_url(\"admin\", \"services\", \"netflow\", \"api\")%>';"
|
|
new_api = "var apiUrl = '/cgi-bin/luci/admin/services/netflow/api';"
|
|
if old_api not in content:
|
|
# It was already hardcoded, update to LuCI format
|
|
content = content.replace(
|
|
"var apiUrl = '/cgi-bin/luci/admin/services/netflow/api';",
|
|
"var apiUrl = '<%=luci.dispatcher.build_url(\"admin\", \"services\", \"netflow\", \"api\")%>';"
|
|
)
|
|
|
|
old_upload = "xhr.open('POST', '<%=luci.dispatcher.build_url(\"admin\",\"services\",\"netflow\",\"upload_core\")%>', true);"
|
|
new_upload = "xhr.open('POST', '/cgi-bin/luci/admin/services/netflow/upload_core', true);"
|
|
# The upload URL is usually hardcoded now, let's use LuCI format instead
|
|
content = content.replace(new_upload, old_upload)
|
|
|
|
# Clean up old tab navigation remnants
|
|
import re
|
|
content = re.sub(r'/\* Tab Navigation \*/\s*\nfunction nfSwitchTab\(btn\)\{.*?\n\}', '', content, flags=re.DOTALL)
|
|
content = re.sub(r'\s*<!-- Tab Navigation -->\s*\n\s*<div id="nf-tab-bar">.*?</div>\s*\n', '', content, flags=re.DOTALL)
|
|
content = re.sub(r'\s*<!-- Tab content wrappers -->\s*\n\s*(<div class="nf-tab-full-card".*?</div>\s*\n)+', '', content, flags=re.DOTALL)
|
|
|
|
# Ensure LF
|
|
content = content.replace('\r\n', '\n').replace('\r', '\n')
|
|
|
|
out = r'E:\AI Project\WangAgent\_tmp_extract\router_main_lf.htm'
|
|
with open(out, 'w', encoding='utf-8', newline='') as f:
|
|
f.write(content)
|
|
|
|
print(f'Template: {len(content)} bytes, LF: {chr(13)+chr(10) not in content[:300]}')
|
|
print(f'Has <%+header%>: {"<%+header%>" in content}')
|
|
print(f'Has <%+footer%>: {"<%+footer%>" in content}')
|
|
print(f'Has standalone DOCTYPE: {"<!DOCTYPE" in content}')
|
|
print(f'nf-ipv6-proxy-toggle: {content.count("nf-ipv6-proxy-toggle")}')
|