6 var callInitList, callInitAction, callTimezone,
7 callGetLocaltime, callSetLocaltime, CBILocalTime;
9 callInitList = rpc.declare({
13 expect: { result: {} },
14 filter: function(res) {
16 return +res[k].enabled;
21 callInitAction = rpc.declare({
24 params: [ 'name', 'action' ],
25 expect: { result: false }
28 callGetLocaltime = rpc.declare({
30 method: 'getLocaltime',
31 expect: { localtime: 0 }
34 callSetLocaltime = rpc.declare({
36 method: 'setLocaltime',
37 params: [ 'localtime' ],
38 expect: { localtime: 0 }
41 callTimezone = rpc.declare({
44 expect: { result: {} }
47 CBILocalTime = form.DummyValue.extend({
48 renderWidget: function(section_id, option_id, cfgvalue) {
50 E('span', { 'id': 'localtime' },
51 new Date(cfgvalue * 1000).toLocaleString()),
54 'class': 'cbi-button cbi-button-apply',
57 this.classList.add('spinning');
59 callSetLocaltime(Math.floor(Date.now() / 1000)).then(L.bind(function() {
60 this.classList.remove('spinning');
61 this.disabled = false;
64 }, _('Sync with browser')),
66 this.ntpd_support ? E('button', {
67 'class': 'cbi-button cbi-button-apply',
70 this.classList.add('spinning');
72 callInitAction('sysntpd', 'restart').then(L.bind(function() {
73 this.classList.remove('spinning');
74 this.disabled = false;
77 }, _('Sync with NTP-Server')) : ''
82 return L.view.extend({
85 callInitList('sysntpd'),
94 render: function(rpc_replies) {
95 var ntpd_support = rpc_replies[0],
96 zram_support = rpc_replies[1],
97 timezones = rpc_replies[2],
98 localtime = rpc_replies[3],
99 ntp_setup, ntp_enabled, m, s, o;
101 m = new form.Map('system',
103 _('Here you can configure the basic aspects of your device like its hostname or the timezone.'));
108 s = m.section(form.TypedSection, 'system', _('System Properties'));
112 s.tab('general', _('General Settings'));
113 s.tab('logging', _('Logging'));
114 s.tab('timesync', _('Time Synchronization'));
115 s.tab('language', _('Language and Style'));
121 o = s.taboption('general', CBILocalTime, '_systime', _('Local Time'));
122 o.cfgvalue = function() { return localtime };
123 o.ntpd_support = ntpd_support;
125 o = s.taboption('general', form.Value, 'hostname', _('Hostname'));
126 o.datatype = 'hostname';
128 o = s.taboption('general', form.ListValue, 'zonename', _('Timezone'));
131 var zones = Object.keys(timezones || {}).sort();
132 for (var i = 0; i < zones.length; i++)
135 o.write = function(section_id, formvalue) {
136 var tz = timezones[formvalue] ? timezones[formvalue].tzstring : null;
137 uci.set('system', section_id, 'zonename', formvalue);
138 uci.set('system', section_id, 'timezone', tz);
145 o = s.taboption('logging', form.Value, 'log_size', _('System log buffer size'), "kiB")
148 o.datatype = 'uinteger'
150 o = s.taboption('logging', form.Value, 'log_ip', _('External system log server'))
152 o.placeholder = '0.0.0.0'
153 o.datatype = 'ip4addr'
155 o = s.taboption('logging', form.Value, 'log_port', _('External system log server port'))
160 o = s.taboption('logging', form.ListValue, 'log_proto', _('External system log server protocol'))
161 o.value('udp', 'UDP')
162 o.value('tcp', 'TCP')
164 o = s.taboption('logging', form.Value, 'log_file', _('Write system log to file'))
166 o.placeholder = '/tmp/system.log'
168 o = s.taboption('logging', form.ListValue, 'conloglevel', _('Log output level'))
169 o.value(8, _('Debug'))
170 o.value(7, _('Info'))
171 o.value(6, _('Notice'))
172 o.value(5, _('Warning'))
173 o.value(4, _('Error'))
174 o.value(3, _('Critical'))
175 o.value(2, _('Alert'))
176 o.value(1, _('Emergency'))
178 o = s.taboption('logging', form.ListValue, 'cronloglevel', _('Cron Log Level'))
180 o.value(5, _('Debug'))
181 o.value(8, _('Normal'))
182 o.value(9, _('Warning'))
188 if (zram_support != null) {
189 s.tab('zram', _('ZRam Settings'));
191 o = s.taboption('zram', form.Value, 'zram_size_mb', _('ZRam Size'), _('Size of the ZRam device in megabytes'));
194 o.datatype = 'uinteger';
196 o = s.taboption('zram', form.ListValue, 'zram_comp_algo', _('ZRam Compression Algorithm'));
198 o.placeholder = 'lzo';
199 o.value('lzo', 'lzo');
200 o.value('lz4', 'lz4');
201 o.value('deflate', 'deflate');
203 o = s.taboption('zram', form.Value, 'zram_comp_streams', _('ZRam Compression Streams'), _('Number of parallel threads used for compression'));
206 o.datatype = 'uinteger';
213 o = s.taboption('language', form.ListValue, '_lang', _('Language'))
214 o.uciconfig = 'luci';
215 o.ucisection = 'main';
216 o.ucioption = 'lang';
219 var k = Object.keys(uci.get('luci', 'languages') || {}).sort();
220 for (var i = 0; i < k.length; i++)
221 if (k[i].charAt(0) != '.')
222 o.value(k[i], uci.get('luci', 'languages', k[i]));
224 o = s.taboption('language', form.ListValue, '_mediaurlbase', _('Design'))
225 o.uciconfig = 'luci';
226 o.ucisection = 'main';
227 o.ucioption = 'mediaurlbase';
229 var k = Object.keys(uci.get('luci', 'themes') || {}).sort();
230 for (var i = 0; i < k.length; i++)
231 if (k[i].charAt(0) != '.')
232 o.value(uci.get('luci', 'themes', k[i]), k[i]);
238 if (ntpd_support != null) {
239 var default_servers = [
240 '0.openwrt.pool.ntp.org', '1.openwrt.pool.ntp.org',
241 '2.openwrt.pool.ntp.org', '3.openwrt.pool.ntp.org'
244 o = s.taboption('timesync', form.Flag, 'enabled', _('Enable NTP client'));
246 o.ucisection = 'ntp';
247 o.default = o.disabled;
248 o.write = function(section_id, value) {
249 ntpd_support = +value;
251 if (ntpd_support && !uci.get('system', 'ntp')) {
252 uci.add('system', 'timeserver', 'ntp');
253 uci.set('system', 'ntp', 'server', default_servers);
257 uci.set('system', 'ntp', 'enabled', 0);
259 uci.unset('system', 'ntp', 'enabled');
261 return callInitAction('sysntpd', 'enable');
263 o.load = function(section_id) {
264 return (ntpd_support == 1 &&
265 uci.get('system', 'ntp') != null &&
266 uci.get('system', 'ntp', 'enabled') != 0) ? '1' : '0';
269 o = s.taboption('timesync', form.Flag, 'enable_server', _('Provide NTP server'));
270 o.ucisection = 'ntp';
271 o.depends('enabled', '1');
273 o = s.taboption('timesync', form.DynamicList, 'server', _('NTP server candidates'));
274 o.datatype = 'host(0)';
275 o.ucisection = 'ntp';
276 o.depends('enabled', '1');
277 o.remove = function() {}; // retain server list even if disabled
278 o.load = function(section_id) {
279 return uci.get('system', 'ntp')
280 ? uci.get('system', 'ntp', 'server')
285 return m.render().then(function(mapEl) {
286 L.Poll.add(function() {
287 return callGetLocaltime().then(function(t) {
288 mapEl.querySelector('#localtime').innerHTML = new Date(t * 1000).toLocaleString();