-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.html
More file actions
172 lines (160 loc) · 6.11 KB
/
Copy pathindex.html
File metadata and controls
172 lines (160 loc) · 6.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>MoCI - Live Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background: #000;
}
.demo-banner {
position: fixed;
top: 0;
left: 0;
right: 0;
background: rgba(255, 165, 0, 0.1);
border-bottom: 1px solid rgba(255, 165, 0, 0.3);
padding: 8px 16px;
text-align: center;
color: #ffa500;
font-size: 14px;
z-index: 10000;
backdrop-filter: blur(10px);
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
#demo-frame {
border: none;
width: 100%;
height: calc(100vh - 36px);
display: block;
margin-top: 36px;
}
</style>
</head>
<body>
<div class="demo-banner">Live Demo Mode - All data is simulated</div>
<iframe id="demo-frame" src="moci/index.html"></iframe>
<script type="module">
const frame = document.getElementById('demo-frame');
frame.addEventListener('load', () => {
const win = frame.contentWindow;
const doc = frame.contentDocument;
const mockData = {
systemInfo: { uptime: 476040, memory: { total: 536870912, free: 411041792 } },
boardInfo: { hostname: 'OpenWrt-Demo' },
interfaces: [
{
interface: 'lan',
proto: 'static',
up: true,
device: 'br-lan',
'ipv4-address': [{ address: '192.168.1.1' }]
},
{
interface: 'wan',
proto: 'dhcp',
up: true,
device: 'eth1',
'ipv4-address': [{ address: '203.0.113.42' }],
route: [{ target: '0.0.0.0', nexthop: '203.0.113.1' }]
}
],
dhcpLeases: {
dhcp_leases: [
{ ipaddr: '192.168.1.100', macaddr: '00:11:22:33:44:55', hostname: 'laptop' },
{ ipaddr: '192.168.1.101', macaddr: '00:11:22:33:44:66', hostname: 'phone' },
{ ipaddr: '192.168.1.102', macaddr: '00:11:22:33:44:77', hostname: 'tablet' }
]
},
packages:
'Package: base-files\nVersion: 1467-r23630\n\nPackage: busybox\nVersion: 1.35.0-4\n\nPackage: dnsmasq\nVersion: 2.86-15\n\nPackage: firewall4\nVersion: 2023-02-17\n\nPackage: kmod-ath9k\nVersion: 5.15.137\n',
cpuStat: 'cpu 12345 0 6789 123456 1234 0 567 0 0 0\n',
netDev: 'Inter-| Receive | Transmit\n face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed\neth0: 1048576000 1024000 0 0 0 0 0 0 524288000 512000 0 0 0 0 0 0\nlo: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n',
arpTable:
'IP address HW type Flags HW address Mask Device\n192.168.1.100 0x1 0x2 00:11:22:33:44:55 * br-lan\n192.168.1.101 0x1 0x2 00:11:22:33:44:66 * br-lan\n192.168.1.102 0x1 0x2 00:11:22:33:44:77 * br-lan\n',
syslog: `Jan 25 12:34:56 OpenWrt daemon.info dnsmasq[1234]: started, version 2.86
Jan 25 12:35:12 OpenWrt daemon.info dnsmasq-dhcp[1234]: DHCP, IP range 192.168.1.100 -- 192.168.1.200
Jan 25 12:36:45 OpenWrt kern.info kernel: [12345.678] ath9k: Atheros AR9344 rev 2
Jan 25 12:37:22 OpenWrt daemon.notice netifd: Interface 'wan' is now up`
};
const originalFetch = win.fetch.bind(win);
win.fetch = async (url, options) => {
if (url === '/ubus' && options?.method === 'POST') {
const body = JSON.parse(options.body);
const [, object, method, params] = body.params;
await new Promise(resolve => setTimeout(resolve, 100));
let result = [1, null];
if (object === 'session' && method === 'login') {
result = [0, { ubus_rpc_session: 'demo-session-' + Date.now() }];
} else if (object === 'session' && method === 'access') {
result = [0, {}];
} else if (object === 'system' && method === 'info') {
result = [0, mockData.systemInfo];
} else if (object === 'system' && method === 'board') {
result = [0, mockData.boardInfo];
} else if (object === 'network.interface' && method === 'dump') {
result = [0, { interface: mockData.interfaces }];
} else if (object === 'luci-rpc' && method === 'getDHCPLeases') {
result = [0, mockData.dhcpLeases];
} else if (object === 'file' && method === 'read') {
if (params.path === '/proc/stat') {
result = [0, { data: mockData.cpuStat }];
} else if (params.path === '/proc/net/dev') {
result = [0, { data: mockData.netDev }];
} else if (params.path === '/proc/net/arp') {
result = [0, { data: mockData.arpTable }];
} else if (params.path === '/usr/lib/opkg/status') {
result = [0, { data: mockData.packages }];
}
} else if (object === 'file' && method === 'exec') {
if (params.command === '/usr/libexec/syslog-wrapper' && Array.isArray(params.params)) {
result = [0, { stdout: mockData.syslog }];
}
} else if (object === 'uci' && method === 'get') {
if (params.config === 'moci' && params.section === 'features') {
result = [
0,
{
values: {
dashboard: '1',
network: '1',
system: '1',
wireless: '1',
firewall: '1',
dhcp: '1',
dns: '1',
wireguard: '1',
qos: '1',
ddns: '1',
diagnostics: '1',
backup: '1',
packages: '1',
services: '1',
ssh_keys: '1',
storage: '1',
leds: '1',
firmware: '1'
}
}
];
}
}
return {
ok: true,
json: async () => ({ jsonrpc: '2.0', id: body.id, result })
};
}
return originalFetch(url, options);
};
const savedCredsKey = Object.keys(win.localStorage).find(k => k.includes('saved_credentials'));
if (savedCredsKey) {
win.localStorage.removeItem(savedCredsKey);
}
});
</script>
</body>
</html>