6 var callInitList, callInitAction, callTimezone,
7 callGetLocaltime, callSetLocaltime, CBILocalTime;
9 callInitList = rpc.declare({
11 method: 'getInitList',
14 filter: function(res) {
16 return +res[k].enabled;
21 callInitAction = rpc.declare({
23 method: 'setInitAction',
24 params: [ 'name', 'action' ],
25 expect: { result: false }
28 callGetLocaltime = rpc.declare({
30 method: 'getLocaltime',
34 callSetLocaltime = rpc.declare({
36 method: 'setLocaltime',
37 params: [ 'localtime' ],
41 callTimezone = rpc.declare({
43 method: 'getTimezones',
47 CBILocalTime = form.DummyValue.extend({
48 renderWidget: function(section_id, option_id, cfgvalue) {
55 'value': new Date(cfgvalue * 1000).toLocaleString()
60 'class': 'cbi-button cbi-button-apply',
61 'click': L.ui.createHandlerFn(this, function() {
62 return callSetLocaltime(Math.floor(Date.now() / 1000));
64 }, _('Sync with browser')),
66 this.ntpd_support ? E('button', {
67 'class': 'cbi-button cbi-button-apply',
68 'click': L.ui.createHandlerFn(this, function() {
69 return callInitAction('sysntpd', 'restart');
71 }, _('Sync with NTP-Server')) : ''
76 return L.view.extend({
79 callInitList('sysntpd'),
87 render: function(rpc_replies) {
88 var ntpd_enabled = rpc_replies[0],
89 timezones = rpc_replies[1],
90 localtime = rpc_replies[2],
93 m = new form.Map('system',
95 _('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', CBILocalTime, '_systime', _('Local Time'));
113 o.cfgvalue = function() { return localtime };
114 o.ntpd_support = ntpd_enabled;
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 (L.hasSystemFeature('zram')) {
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 (L.hasSystemFeature('sysntpd')) {
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_enabled = +value;
242 if (ntpd_enabled && !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 callInitAction('sysntpd', 'enable');
254 o.load = function(section_id) {
255 return (ntpd_enabled == 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 return m.render().then(function(mapEl) {
277 L.Poll.add(function() {
278 return callGetLocaltime().then(function(t) {
279 mapEl.querySelector('#localtime').value = new Date(t * 1000).toLocaleString();