6 var callInitList, callInitAction, callLocaltime, callTimezone, CBILocalTime;
8 callInitList = rpc.declare({
12 expect: { result: {} },
13 filter: function(res) {
15 return +res[k].enabled;
20 callInitAction = rpc.declare({
23 params: [ 'name', 'action' ],
24 expect: { result: false }
27 callLocaltime = rpc.declare({
30 expect: { localtime: 0 }
33 callTimezone = rpc.declare({
36 expect: { result: {} }
39 CBILocalTime = form.DummyValue.extend({
40 renderWidget: function(section_id, option_id, cfgvalue) {
42 E('span', { 'id': 'localtime' },
43 new Date(cfgvalue * 1000).toLocaleString()),
46 'class': 'cbi-button cbi-button-apply',
49 this.classList.add('spinning');
51 callLocaltime(Math.floor(Date.now() / 1000)).then(L.bind(function() {
52 this.classList.remove('spinning');
53 this.disabled = false;
56 }, _('Sync with browser')),
58 this.ntpd_support ? E('button', {
59 'class': 'cbi-button cbi-button-apply',
62 this.classList.add('spinning');
64 callInitAction('sysntpd', 'restart').then(L.bind(function() {
65 this.classList.remove('spinning');
66 this.disabled = false;
69 }, _('Sync with NTP-Server')) : ''
74 return L.view.extend({
77 callInitList('sysntpd'),
86 render: function(rpc_replies) {
87 var ntpd_support = rpc_replies[0],
88 zram_support = rpc_replies[1],
89 timezones = rpc_replies[2],
90 localtime = rpc_replies[3],
91 ntp_setup, ntp_enabled, m, s, o;
93 m = new form.Map('system',
95 _('Here you can configure the basic aspects of your device like its hostname or the timezone.'));
100 s = m.section(form.TypedSection, 'system', _('System Properties'));
104 s.tab('general', _('General Settings'));
105 s.tab('logging', _('Logging'));
106 s.tab('timesync', _('Time Synchronization'));
107 s.tab('language', _('Language and Style'));
113 o = s.taboption('general', CBILocalTime, '_systime', _('Local Time'));
114 o.cfgvalue = function() { return localtime };
115 o.ntpd_support = ntpd_support;
117 o = s.taboption('general', form.Value, 'hostname', _('Hostname'));
118 o.datatype = 'hostname';
120 o = s.taboption('general', form.ListValue, 'zonename', _('Timezone'));
123 var zones = Object.keys(timezones || {}).sort();
124 for (var i = 0; i < zones.length; i++)
127 o.write = function(section_id, formvalue) {
128 var tz = timezones[formvalue] ? timezones[formvalue].tzstring : null;
129 uci.set('system', section_id, 'zonename', formvalue);
130 uci.set('system', section_id, 'timezone', tz);
137 o = s.taboption('logging', form.Value, 'log_size', _('System log buffer size'), "kiB")
140 o.datatype = 'uinteger'
142 o = s.taboption('logging', form.Value, 'log_ip', _('External system log server'))
144 o.placeholder = '0.0.0.0'
145 o.datatype = 'ip4addr'
147 o = s.taboption('logging', form.Value, 'log_port', _('External system log server port'))
152 o = s.taboption('logging', form.ListValue, 'log_proto', _('External system log server protocol'))
153 o.value('udp', 'UDP')
154 o.value('tcp', 'TCP')
156 o = s.taboption('logging', form.Value, 'log_file', _('Write system log to file'))
158 o.placeholder = '/tmp/system.log'
160 o = s.taboption('logging', form.ListValue, 'conloglevel', _('Log output level'))
161 o.value(8, _('Debug'))
162 o.value(7, _('Info'))
163 o.value(6, _('Notice'))
164 o.value(5, _('Warning'))
165 o.value(4, _('Error'))
166 o.value(3, _('Critical'))
167 o.value(2, _('Alert'))
168 o.value(1, _('Emergency'))
170 o = s.taboption('logging', form.ListValue, 'cronloglevel', _('Cron Log Level'))
172 o.value(5, _('Debug'))
173 o.value(8, _('Normal'))
174 o.value(9, _('Warning'))
180 if (zram_support != null) {
181 s.tab('zram', _('ZRam Settings'));
183 o = s.taboption('zram', form.Value, 'zram_size_mb', _('ZRam Size'), _('Size of the ZRam device in megabytes'));
186 o.datatype = 'uinteger';
188 o = s.taboption('zram', form.ListValue, 'zram_comp_algo', _('ZRam Compression Algorithm'));
190 o.placeholder = 'lzo';
191 o.value('lzo', 'lzo');
192 o.value('lz4', 'lz4');
193 o.value('deflate', 'deflate');
195 o = s.taboption('zram', form.Value, 'zram_comp_streams', _('ZRam Compression Streams'), _('Number of parallel threads used for compression'));
198 o.datatype = 'uinteger';
205 o = s.taboption('language', form.ListValue, '_lang', _('Language'))
206 o.uciconfig = 'luci';
207 o.ucisection = 'main';
208 o.ucioption = 'lang';
211 var k = Object.keys(uci.get('luci', 'languages') || {}).sort();
212 for (var i = 0; i < k.length; i++)
213 if (k[i].charAt(0) != '.')
214 o.value(k[i], uci.get('luci', 'languages', k[i]));
216 o = s.taboption('language', form.ListValue, '_mediaurlbase', _('Design'))
217 o.uciconfig = 'luci';
218 o.ucisection = 'main';
219 o.ucioption = 'mediaurlbase';
221 var k = Object.keys(uci.get('luci', 'themes') || {}).sort();
222 for (var i = 0; i < k.length; i++)
223 if (k[i].charAt(0) != '.')
224 o.value(uci.get('luci', 'themes', k[i]), k[i]);
230 if (ntpd_support != null) {
231 var default_servers = [
232 '0.openwrt.pool.ntp.org', '1.openwrt.pool.ntp.org',
233 '2.openwrt.pool.ntp.org', '3.openwrt.pool.ntp.org'
236 o = s.taboption('timesync', form.Flag, 'enabled', _('Enable NTP client'));
238 o.ucisection = 'ntp';
239 o.default = o.disabled;
240 o.write = function(section_id, value) {
241 ntpd_support = +value;
243 if (ntpd_support && !uci.get('system', 'ntp')) {
244 uci.add('system', 'timeserver', 'ntp');
245 uci.set('system', 'ntp', 'server', default_servers);
249 uci.set('system', 'ntp', 'enabled', 0);
251 uci.unset('system', 'ntp', 'enabled');
253 return callInitAction('sysntpd', 'enable');
255 o.load = function(section_id) {
256 return (ntpd_support == 1 &&
257 uci.get('system', 'ntp') != null &&
258 uci.get('system', 'ntp', 'enabled') != 0) ? '1' : '0';
261 o = s.taboption('timesync', form.Flag, 'enable_server', _('Provide NTP server'));
262 o.ucisection = 'ntp';
263 o.depends('enabled', '1');
265 o = s.taboption('timesync', form.DynamicList, 'server', _('NTP server candidates'));
266 o.datatype = 'host(0)';
267 o.ucisection = 'ntp';
268 o.depends('enabled', '1');
269 o.remove = function() {}; // retain server list even if disabled
270 o.load = function(section_id) {
271 return uci.get('system', 'ntp')
272 ? uci.get('system', 'ntp', 'server')
277 return m.render().then(function(mapEl) {
278 L.Poll.add(function() {
279 return callLocaltime().then(function(t) {
280 mapEl.querySelector('#localtime').innerHTML = new Date(t * 1000).toLocaleString();