9 var callInitList, callInitAction, callTimezone,
10 callGetLocaltime, callSetLocaltime, CBILocalTime;
12 callInitList = rpc.declare({
14 method: 'getInitList',
17 filter: function(res) {
19 return +res[k].enabled;
24 callInitAction = rpc.declare({
26 method: 'setInitAction',
27 params: [ 'name', 'action' ],
28 expect: { result: false }
31 callGetLocaltime = rpc.declare({
33 method: 'getLocaltime',
37 callSetLocaltime = rpc.declare({
39 method: 'setLocaltime',
40 params: [ 'localtime' ],
44 callTimezone = rpc.declare({
46 method: 'getTimezones',
50 CBILocalTime = form.DummyValue.extend({
51 renderWidget: function(section_id, option_id, cfgvalue) {
57 'value': new Date(cfgvalue * 1000).toLocaleString()
60 E('span', { 'class': 'control-group' }, [
62 'class': 'cbi-button cbi-button-apply',
63 'click': ui.createHandlerFn(this, function() {
64 return callSetLocaltime(Math.floor(Date.now() / 1000));
66 'disabled': (this.readonly != null) ? this.readonly : this.map.readonly
67 }, _('Sync with browser')),
69 this.ntpd_support ? E('button', {
70 'class': 'cbi-button cbi-button-apply',
71 'click': ui.createHandlerFn(this, function() {
72 return callInitAction('sysntpd', 'restart');
74 'disabled': (this.readonly != null) ? this.readonly : this.map.readonly
75 }, _('Sync with NTP-Server')) : ''
84 callInitList('sysntpd'),
92 render: function(rpc_replies) {
93 var ntpd_enabled = rpc_replies[0],
94 timezones = rpc_replies[1],
95 localtime = rpc_replies[2],
98 m = new form.Map('system',
100 _('Here you can configure the basic aspects of your device like its hostname or the timezone.'));
104 s = m.section(form.TypedSection, 'system', _('System Properties'));
108 s.tab('general', _('General Settings'));
109 s.tab('logging', _('Logging'));
110 s.tab('timesync', _('Time Synchronization'));
111 s.tab('language', _('Language and Style'));
117 o = s.taboption('general', CBILocalTime, '_systime', _('Local Time'));
118 o.cfgvalue = function() { return localtime };
119 o.ntpd_support = ntpd_enabled;
121 o = s.taboption('general', form.Value, 'hostname', _('Hostname'));
122 o.datatype = 'hostname';
124 o = s.taboption('general', form.ListValue, 'zonename', _('Timezone'));
127 var zones = Object.keys(timezones || {}).sort();
128 for (var i = 0; i < zones.length; i++)
131 o.write = function(section_id, formvalue) {
132 var tz = timezones[formvalue] ? timezones[formvalue].tzstring : null;
133 uci.set('system', section_id, 'zonename', formvalue);
134 uci.set('system', section_id, 'timezone', tz);
141 o = s.taboption('logging', form.Value, 'log_size', _('System log buffer size'), "kiB")
144 o.datatype = 'uinteger'
146 o = s.taboption('logging', form.Value, 'log_ip', _('External system log server'))
148 o.placeholder = '0.0.0.0'
151 o = s.taboption('logging', form.Value, 'log_port', _('External system log server port'))
156 o = s.taboption('logging', form.ListValue, 'log_proto', _('External system log server protocol'))
157 o.value('udp', 'UDP')
158 o.value('tcp', 'TCP')
160 o = s.taboption('logging', form.Value, 'log_file', _('Write system log to file'))
162 o.placeholder = '/tmp/system.log'
164 o = s.taboption('logging', form.ListValue, 'conloglevel', _('Log output level'))
165 o.value(8, _('Debug'))
166 o.value(7, _('Info'))
167 o.value(6, _('Notice'))
168 o.value(5, _('Warning'))
169 o.value(4, _('Error'))
170 o.value(3, _('Critical'))
171 o.value(2, _('Alert'))
172 o.value(1, _('Emergency'))
174 o = s.taboption('logging', form.ListValue, 'cronloglevel', _('Cron Log Level'))
176 o.value(5, _('Debug'))
177 o.value(8, _('Normal'))
178 o.value(9, _('Warning'))
184 if (L.hasSystemFeature('zram')) {
185 s.tab('zram', _('ZRam Settings'));
187 o = s.taboption('zram', form.Value, 'zram_size_mb', _('ZRam Size'), _('Size of the ZRam device in megabytes'));
190 o.datatype = 'uinteger';
192 o = s.taboption('zram', form.ListValue, 'zram_comp_algo', _('ZRam Compression Algorithm'));
195 o.value('lzo', 'lzo');
196 o.value('lz4', 'lz4');
197 o.value('deflate', 'deflate');
199 o = s.taboption('zram', form.Value, 'zram_comp_streams', _('ZRam Compression Streams'), _('Number of parallel threads used for compression'));
202 o.datatype = 'uinteger';
209 o = s.taboption('language', form.ListValue, '_lang', _('Language'))
210 o.uciconfig = 'luci';
211 o.ucisection = 'main';
212 o.ucioption = 'lang';
215 var k = Object.keys(uci.get('luci', 'languages') || {}).sort();
216 for (var i = 0; i < k.length; i++)
217 if (k[i].charAt(0) != '.')
218 o.value(k[i], uci.get('luci', 'languages', k[i]));
220 o = s.taboption('language', form.ListValue, '_mediaurlbase', _('Design'))
221 o.uciconfig = 'luci';
222 o.ucisection = 'main';
223 o.ucioption = 'mediaurlbase';
225 var k = Object.keys(uci.get('luci', 'themes') || {}).sort();
226 for (var i = 0; i < k.length; i++)
227 if (k[i].charAt(0) != '.')
228 o.value(uci.get('luci', 'themes', k[i]), k[i]);
234 if (L.hasSystemFeature('sysntpd')) {
235 var default_servers = [
236 '0.openwrt.pool.ntp.org', '1.openwrt.pool.ntp.org',
237 '2.openwrt.pool.ntp.org', '3.openwrt.pool.ntp.org'
240 o = s.taboption('timesync', form.Flag, 'enabled', _('Enable NTP client'));
242 o.ucisection = 'ntp';
243 o.default = o.disabled;
244 o.write = function(section_id, value) {
245 ntpd_enabled = +value;
247 if (ntpd_enabled && !uci.get('system', 'ntp')) {
248 uci.add('system', 'timeserver', 'ntp');
249 uci.set('system', 'ntp', 'server', default_servers);
253 uci.set('system', 'ntp', 'enabled', 0);
255 uci.unset('system', 'ntp', 'enabled');
257 return callInitAction('sysntpd', 'enable');
259 o.load = function(section_id) {
260 return (ntpd_enabled == 1 &&
261 uci.get('system', 'ntp') != null &&
262 uci.get('system', 'ntp', 'enabled') != 0) ? '1' : '0';
265 o = s.taboption('timesync', form.Flag, 'enable_server', _('Provide NTP server'));
266 o.ucisection = 'ntp';
267 o.depends('enabled', '1');
269 o = s.taboption('timesync', form.Flag, 'use_dhcp', _('Use DHCP advertised servers'));
270 o.ucisection = 'ntp';
271 o.default = o.enabled;
272 o.depends('enabled', '1');
274 o = s.taboption('timesync', form.DynamicList, 'server', _('NTP server candidates'));
275 o.datatype = 'host(0)';
276 o.ucisection = 'ntp';
277 o.depends('enabled', '1');
278 o.load = function(section_id) {
279 return uci.get('system', 'ntp', 'server');
283 return m.render().then(function(mapEl) {
284 poll.add(function() {
285 return callGetLocaltime().then(function(t) {
286 mapEl.querySelector('#localtime').value = new Date(t * 1000).toLocaleString();