7 callInitList: rpc.declare({
11 expect: { result: {} },
12 filter: function(res) {
14 return +res[k].enabled;
19 callInitAction: rpc.declare({
22 params: [ 'name', 'action' ],
23 expect: { result: false }
26 callLocaltime: rpc.declare({
29 expect: { localtime: 0 }
32 callTimezone: rpc.declare({
35 expect: { result: {} }
38 CBILocalTime: form.DummyValue.extend({
39 renderWidget: function(section_id, option_id, cfgvalue) {
41 E('span', { 'id': 'localtime' },
42 new Date(cfgvalue * 1000).toLocaleString()),
45 'class': 'cbi-button cbi-button-apply',
46 'click': L.bind(function(ev) {
48 ev.target.classList.add('spinning');
49 ev.target.disabled = true;
50 this.callLocaltime(Math.floor(Date.now() / 1000)).then(function() {
51 ev.target.classList.remove('spinning');
52 ev.target.disabled = false;
55 }, _('Sync with browser')),
57 this.ntpd_support ? E('button', {
58 'class': 'cbi-button cbi-button-apply',
59 'click': L.bind(function(ev) {
61 ev.target.classList.add('spinning');
62 ev.target.disabled = true;
63 this.callLocaltime(Math.floor(Date.now() / 1000)).then(function() {
64 ev.target.classList.remove('spinning');
65 ev.target.disabled = false;
68 }, _('Sync with NTP-Server')) : ''
75 this.callInitList('sysntpd');
76 this.callInitList('zram');
84 render: function(rpc_replies) {
85 var ntpd_support = rpc_replies[0],
86 zram_support = rpc_replies[1],
87 timezones = rpc_replies[2],
88 localtime = rpc_replies[3],
90 ntp_setup, ntp_enabled, m, s, o;
92 m = new form.Map('system',
94 _('Here you can configure the basic aspects of your device like its hostname or the timezone.'));
99 s = m.section(form.TypedSection, 'system', _('System Properties'));
103 s.tab('general', _('General Settings'));
104 s.tab('logging', _('Logging'));
105 s.tab('timesync', _('Time Synchronization'));
106 s.tab('language', _('Language and Style'));
112 o = s.taboption('general', this.CBILocalTime, '_systime', _('Local Time'));
113 o.cfgvalue = function() { return localtime };
114 o.ntpd_support = ntpd_support;
116 o = s.taboption('general', form.Value, 'hostname', _('Hostname'));
117 o.datatype = 'hostname';
119 o = s.taboption('general', form.ListValue, 'zonename', _('Timezone'));
122 var zones = Object.keys(timezones || {}).sort();
123 for (var i = 0; i < zones.length; i++)
126 o.write = function(section_id, formvalue) {
127 var tz = timezones[formvalue] ? timezones[formvalue].tzstring : null;
128 uci.set('system', section_id, 'zonename', formvalue);
129 uci.set('system', section_id, 'timezone', tz);
136 o = s.taboption('logging', form.Value, 'log_size', _('System log buffer size'), "kiB")
139 o.datatype = 'uinteger'
141 o = s.taboption('logging', form.Value, 'log_ip', _('External system log server'))
143 o.placeholder = '0.0.0.0'
144 o.datatype = 'ip4addr'
146 o = s.taboption('logging', form.Value, 'log_port', _('External system log server port'))
151 o = s.taboption('logging', form.ListValue, 'log_proto', _('External system log server protocol'))
152 o.value('udp', 'UDP')
153 o.value('tcp', 'TCP')
155 o = s.taboption('logging', form.Value, 'log_file', _('Write system log to file'))
157 o.placeholder = '/tmp/system.log'
159 o = s.taboption('logging', form.ListValue, 'conloglevel', _('Log output level'))
160 o.value(8, _('Debug'))
161 o.value(7, _('Info'))
162 o.value(6, _('Notice'))
163 o.value(5, _('Warning'))
164 o.value(4, _('Error'))
165 o.value(3, _('Critical'))
166 o.value(2, _('Alert'))
167 o.value(1, _('Emergency'))
169 o = s.taboption('logging', form.ListValue, 'cronloglevel', _('Cron Log Level'))
171 o.value(5, _('Debug'))
172 o.value(8, _('Normal'))
173 o.value(9, _('Warning'))
179 if (zram_support != null) {
180 s.tab('zram', _('ZRam Settings'));
182 o = s.taboption('zram', form.Value, 'zram_size_mb', _('ZRam Size'), _('Size of the ZRam device in megabytes'));
185 o.datatype = 'uinteger';
187 o = s.taboption('zram', form.ListValue, 'zram_comp_algo', _('ZRam Compression Algorithm'));
189 o.placeholder = 'lzo';
190 o.value('lzo', 'lzo');
191 o.value('lz4', 'lz4');
192 o.value('deflate', 'deflate');
194 o = s.taboption('zram', form.Value, 'zram_comp_streams', _('ZRam Compression Streams'), _('Number of parallel threads used for compression'));
197 o.datatype = 'uinteger';
204 o = s.taboption('language', form.ListValue, '_lang', _('Language'))
205 o.uciconfig = 'luci';
206 o.ucisection = 'main';
207 o.ucioption = 'lang';
210 var k = Object.keys(uci.get('luci', 'languages') || {}).sort();
211 for (var i = 0; i < k.length; i++)
212 if (k[i].charAt(0) != '.')
213 o.value(k[i], uci.get('luci', 'languages', k[i]));
215 o = s.taboption('language', form.ListValue, '_mediaurlbase', _('Design'))
216 o.uciconfig = 'luci';
217 o.ucisection = 'main';
218 o.ucioption = 'mediaurlbase';
220 var k = Object.keys(uci.get('luci', 'themes') || {}).sort();
221 for (var i = 0; i < k.length; i++)
222 if (k[i].charAt(0) != '.')
223 o.value(uci.get('luci', 'themes', k[i]), k[i]);
229 if (ntpd_support != null) {
230 var default_servers = [
231 '0.openwrt.pool.ntp.org', '1.openwrt.pool.ntp.org',
232 '2.openwrt.pool.ntp.org', '3.openwrt.pool.ntp.org'
235 o = s.taboption('timesync', form.Flag, 'enabled', _('Enable NTP client'));
237 o.ucisection = 'ntp';
238 o.default = o.disabled;
239 o.write = function(section_id, value) {
240 ntpd_support = +value;
242 if (ntpd_support && !uci.get('system', 'ntp')) {
243 uci.add('system', 'timeserver', 'ntp');
244 uci.set('system', 'ntp', 'server', default_servers);
248 uci.set('system', 'ntp', 'enabled', 0);
250 uci.unset('system', 'ntp', 'enabled');
252 return view.callInitAction('sysntpd', 'enable');
254 o.load = function(section_id) {
255 return (ntpd_support == 1 &&
256 uci.get('system', 'ntp') != null &&
257 uci.get('system', 'ntp', 'enabled') != 0) ? '1' : '0';
260 o = s.taboption('timesync', form.Flag, 'enable_server', _('Provide NTP server'));
261 o.ucisection = 'ntp';
262 o.depends('enabled', '1');
264 o = s.taboption('timesync', form.DynamicList, 'server', _('NTP server candidates'));
265 o.datatype = 'host(0)';
266 o.ucisection = 'ntp';
267 o.depends('enabled', '1');
268 o.remove = function() {}; // retain server list even if disabled
269 o.load = function(section_id) {
270 return uci.get('system', 'ntp')
271 ? uci.get('system', 'ntp', 'server')
276 window.setInterval(L.bind(function() {
277 this.callLocaltime().then(function(t) {
278 var lt = document.getElementById('localtime');
279 if (lt) lt.innerHTML = new Date(t * 1000).toLocaleString();