1ed8f64d8f0d1226529cd6a8a75f0b136b915802
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
) {
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.'));
107 s
= m
.section(form
.TypedSection
, 'system', _('System Properties'));
111 s
.tab('general', _('General Settings'));
112 s
.tab('logging', _('Logging'));
113 s
.tab('timesync', _('Time Synchronization'));
114 s
.tab('language', _('Language and Style'));
120 o
= s
.taboption('general', CBILocalTime
, '_systime', _('Local Time'));
121 o
.cfgvalue = function() { return localtime
};
122 o
.ntpd_support
= ntpd_support
;
124 o
= s
.taboption('general', form
.Value
, 'hostname', _('Hostname'));
125 o
.datatype
= 'hostname';
127 o
= s
.taboption('general', form
.ListValue
, 'zonename', _('Timezone'));
130 var zones
= Object
.keys(timezones
|| {}).sort();
131 for (var i
= 0; i
< zones
.length
; i
++)
134 o
.write = function(section_id
, formvalue
) {
135 var tz
= timezones
[formvalue
] ? timezones
[formvalue
].tzstring
: null;
136 uci
.set('system', section_id
, 'zonename', formvalue
);
137 uci
.set('system', section_id
, 'timezone', tz
);
144 o
= s
.taboption('logging', form
.Value
, 'log_size', _('System log buffer size'), "kiB")
147 o
.datatype
= 'uinteger'
149 o
= s
.taboption('logging', form
.Value
, 'log_ip', _('External system log server'))
151 o
.placeholder
= '0.0.0.0'
152 o
.datatype
= 'ip4addr'
154 o
= s
.taboption('logging', form
.Value
, 'log_port', _('External system log server port'))
159 o
= s
.taboption('logging', form
.ListValue
, 'log_proto', _('External system log server protocol'))
160 o
.value('udp', 'UDP')
161 o
.value('tcp', 'TCP')
163 o
= s
.taboption('logging', form
.Value
, 'log_file', _('Write system log to file'))
165 o
.placeholder
= '/tmp/system.log'
167 o
= s
.taboption('logging', form
.ListValue
, 'conloglevel', _('Log output level'))
168 o
.value(8, _('Debug'))
169 o
.value(7, _('Info'))
170 o
.value(6, _('Notice'))
171 o
.value(5, _('Warning'))
172 o
.value(4, _('Error'))
173 o
.value(3, _('Critical'))
174 o
.value(2, _('Alert'))
175 o
.value(1, _('Emergency'))
177 o
= s
.taboption('logging', form
.ListValue
, 'cronloglevel', _('Cron Log Level'))
179 o
.value(5, _('Debug'))
180 o
.value(8, _('Normal'))
181 o
.value(9, _('Warning'))
187 if (zram_support
!= null) {
188 s
.tab('zram', _('ZRam Settings'));
190 o
= s
.taboption('zram', form
.Value
, 'zram_size_mb', _('ZRam Size'), _('Size of the ZRam device in megabytes'));
193 o
.datatype
= 'uinteger';
195 o
= s
.taboption('zram', form
.ListValue
, 'zram_comp_algo', _('ZRam Compression Algorithm'));
197 o
.placeholder
= 'lzo';
198 o
.value('lzo', 'lzo');
199 o
.value('lz4', 'lz4');
200 o
.value('deflate', 'deflate');
202 o
= s
.taboption('zram', form
.Value
, 'zram_comp_streams', _('ZRam Compression Streams'), _('Number of parallel threads used for compression'));
205 o
.datatype
= 'uinteger';
212 o
= s
.taboption('language', form
.ListValue
, '_lang', _('Language'))
213 o
.uciconfig
= 'luci';
214 o
.ucisection
= 'main';
215 o
.ucioption
= 'lang';
218 var k
= Object
.keys(uci
.get('luci', 'languages') || {}).sort();
219 for (var i
= 0; i
< k
.length
; i
++)
220 if (k
[i
].charAt(0) != '.')
221 o
.value(k
[i
], uci
.get('luci', 'languages', k
[i
]));
223 o
= s
.taboption('language', form
.ListValue
, '_mediaurlbase', _('Design'))
224 o
.uciconfig
= 'luci';
225 o
.ucisection
= 'main';
226 o
.ucioption
= 'mediaurlbase';
228 var k
= Object
.keys(uci
.get('luci', 'themes') || {}).sort();
229 for (var i
= 0; i
< k
.length
; i
++)
230 if (k
[i
].charAt(0) != '.')
231 o
.value(uci
.get('luci', 'themes', k
[i
]), k
[i
]);
237 if (ntpd_support
!= null) {
238 var default_servers
= [
239 '0.openwrt.pool.ntp.org', '1.openwrt.pool.ntp.org',
240 '2.openwrt.pool.ntp.org', '3.openwrt.pool.ntp.org'
243 o
= s
.taboption('timesync', form
.Flag
, 'enabled', _('Enable NTP client'));
245 o
.ucisection
= 'ntp';
246 o
.default = o
.disabled
;
247 o
.write = function(section_id
, value
) {
248 ntpd_support
= +value
;
250 if (ntpd_support
&& !uci
.get('system', 'ntp')) {
251 uci
.add('system', 'timeserver', 'ntp');
252 uci
.set('system', 'ntp', 'server', default_servers
);
256 uci
.set('system', 'ntp', 'enabled', 0);
258 uci
.unset('system', 'ntp', 'enabled');
260 return callInitAction('sysntpd', 'enable');
262 o
.load = function(section_id
) {
263 return (ntpd_support
== 1 &&
264 uci
.get('system', 'ntp') != null &&
265 uci
.get('system', 'ntp', 'enabled') != 0) ? '1' : '0';
268 o
= s
.taboption('timesync', form
.Flag
, 'enable_server', _('Provide NTP server'));
269 o
.ucisection
= 'ntp';
270 o
.depends('enabled', '1');
272 o
= s
.taboption('timesync', form
.DynamicList
, 'server', _('NTP server candidates'));
273 o
.datatype
= 'host(0)';
274 o
.ucisection
= 'ntp';
275 o
.depends('enabled', '1');
276 o
.remove = function() {}; // retain server list even if disabled
277 o
.load = function(section_id
) {
278 return uci
.get('system', 'ntp')
279 ? uci
.get('system', 'ntp', 'server')
284 return m
.render().then(function(mapEl
) {
285 L
.Poll
.add(function() {
286 return callGetLocaltime().then(function(t
) {
287 mapEl
.querySelector('#localtime').innerHTML
= new Date(t
* 1000).toLocaleString();