Translated using Weblate (Japanese)
[oweals/luci.git] / modules / luci-mod-system / htdocs / luci-static / resources / view / system / system.js
1 'use strict';
2 'require view';
3 'require poll';
4 'require ui';
5 'require uci';
6 'require rpc';
7 'require form';
8
9 var callInitList, callInitAction, callTimezone,
10     callGetLocaltime, callSetLocaltime, CBILocalTime;
11
12 callInitList = rpc.declare({
13         object: 'luci',
14         method: 'getInitList',
15         params: [ 'name' ],
16         expect: { '': {} },
17         filter: function(res) {
18                 for (var k in res)
19                         return +res[k].enabled;
20                 return null;
21         }
22 });
23
24 callInitAction = rpc.declare({
25         object: 'luci',
26         method: 'setInitAction',
27         params: [ 'name', 'action' ],
28         expect: { result: false }
29 });
30
31 callGetLocaltime = rpc.declare({
32         object: 'luci',
33         method: 'getLocaltime',
34         expect: { result: 0 }
35 });
36
37 callSetLocaltime = rpc.declare({
38         object: 'luci',
39         method: 'setLocaltime',
40         params: [ 'localtime' ],
41         expect: { result: 0 }
42 });
43
44 callTimezone = rpc.declare({
45         object: 'luci',
46         method: 'getTimezones',
47         expect: { '': {} }
48 });
49
50 CBILocalTime = form.DummyValue.extend({
51         renderWidget: function(section_id, option_id, cfgvalue) {
52                 return E([], [
53                         E('input', {
54                                 'id': 'localtime',
55                                 'type': 'text',
56                                 'readonly': true,
57                                 'value': new Date(cfgvalue * 1000).toLocaleString()
58                         }),
59                         E('br'),
60                         E('span', { 'class': 'control-group' }, [
61                                 E('button', {
62                                         'class': 'cbi-button cbi-button-apply',
63                                         'click': ui.createHandlerFn(this, function() {
64                                                 return callSetLocaltime(Math.floor(Date.now() / 1000));
65                                         }),
66                                         'disabled': (this.readonly != null) ? this.readonly : this.map.readonly
67                                 }, _('Sync with browser')),
68                                 ' ',
69                                 this.ntpd_support ? E('button', {
70                                         'class': 'cbi-button cbi-button-apply',
71                                         'click': ui.createHandlerFn(this, function() {
72                                                 return callInitAction('sysntpd', 'restart');
73                                         }),
74                                         'disabled': (this.readonly != null) ? this.readonly : this.map.readonly
75                                 }, _('Sync with NTP-Server')) : ''
76                         ])
77                 ]);
78         },
79 });
80
81 return view.extend({
82         load: function() {
83                 return Promise.all([
84                         callInitList('sysntpd'),
85                         callTimezone(),
86                         callGetLocaltime(),
87                         uci.load('luci'),
88                         uci.load('system')
89                 ]);
90         },
91
92         render: function(rpc_replies) {
93                 var ntpd_enabled = rpc_replies[0],
94                     timezones = rpc_replies[1],
95                     localtime = rpc_replies[2],
96                     m, s, o;
97
98                 m = new form.Map('system',
99                         _('System'),
100                         _('Here you can configure the basic aspects of your device like its hostname or the timezone.'));
101
102                 m.chain('luci');
103
104                 s = m.section(form.TypedSection, 'system', _('System Properties'));
105                 s.anonymous = true;
106                 s.addremove = false;
107
108                 s.tab('general', _('General Settings'));
109                 s.tab('logging', _('Logging'));
110                 s.tab('timesync', _('Time Synchronization'));
111                 s.tab('language', _('Language and Style'));
112
113                 /*
114                  * System Properties
115                  */
116
117                 o = s.taboption('general', CBILocalTime, '_systime', _('Local Time'));
118                 o.cfgvalue = function() { return localtime };
119                 o.ntpd_support = ntpd_enabled;
120
121                 o = s.taboption('general', form.Value, 'hostname', _('Hostname'));
122                 o.datatype = 'hostname';
123
124                 o = s.taboption('general', form.ListValue, 'zonename', _('Timezone'));
125                 o.value('UTC');
126
127                 var zones = Object.keys(timezones || {}).sort();
128                 for (var i = 0; i < zones.length; i++)
129                         o.value(zones[i]);
130
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);
135                 };
136
137                 /*
138                  * Logging
139                  */
140
141                 o = s.taboption('logging', form.Value, 'log_size', _('System log buffer size'), "kiB")
142                 o.optional    = true
143                 o.placeholder = 16
144                 o.datatype    = 'uinteger'
145
146                 o = s.taboption('logging', form.Value, 'log_ip', _('External system log server'))
147                 o.optional    = true
148                 o.placeholder = '0.0.0.0'
149                 o.datatype    = 'host'
150
151                 o = s.taboption('logging', form.Value, 'log_port', _('External system log server port'))
152                 o.optional    = true
153                 o.placeholder = 514
154                 o.datatype    = 'port'
155
156                 o = s.taboption('logging', form.ListValue, 'log_proto', _('External system log server protocol'))
157                 o.value('udp', 'UDP')
158                 o.value('tcp', 'TCP')
159
160                 o = s.taboption('logging', form.Value, 'log_file', _('Write system log to file'))
161                 o.optional    = true
162                 o.placeholder = '/tmp/system.log'
163
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'))
173
174                 o = s.taboption('logging', form.ListValue, 'cronloglevel', _('Cron Log Level'))
175                 o.default = 8
176                 o.value(5, _('Debug'))
177                 o.value(8, _('Normal'))
178                 o.value(9, _('Warning'))
179
180                 /*
181                  * Zram Properties
182                  */
183
184                 if (L.hasSystemFeature('zram')) {
185                         s.tab('zram', _('ZRam Settings'));
186
187                         o = s.taboption('zram', form.Value, 'zram_size_mb', _('ZRam Size'), _('Size of the ZRam device in megabytes'));
188                         o.optional    = true;
189                         o.placeholder = 16;
190                         o.datatype    = 'uinteger';
191
192                         o = s.taboption('zram', form.ListValue, 'zram_comp_algo', _('ZRam Compression Algorithm'));
193                         o.optional    = true;
194                         o.default     = 'lzo';
195                         o.value('lzo', 'lzo');
196                         o.value('lz4', 'lz4');
197                         o.value('deflate', 'deflate');
198
199                         o = s.taboption('zram', form.Value, 'zram_comp_streams', _('ZRam Compression Streams'), _('Number of parallel threads used for compression'));
200                         o.optional    = true;
201                         o.placeholder = 1;
202                         o.datatype    = 'uinteger';
203                 }
204
205                 /*
206                  * Language & Style
207                  */
208
209                 o = s.taboption('language', form.ListValue, '_lang', _('Language'))
210                 o.uciconfig = 'luci';
211                 o.ucisection = 'main';
212                 o.ucioption = 'lang';
213                 o.value('auto');
214
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]));
219
220                 o = s.taboption('language', form.ListValue, '_mediaurlbase', _('Design'))
221                 o.uciconfig = 'luci';
222                 o.ucisection = 'main';
223                 o.ucioption = 'mediaurlbase';
224
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]);
229
230                 /*
231                  * NTP
232                  */
233
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'
238                         ];
239
240                         o = s.taboption('timesync', form.Flag, 'enabled', _('Enable NTP client'));
241                         o.rmempty = false;
242                         o.ucisection = 'ntp';
243                         o.default = o.disabled;
244                         o.write = function(section_id, value) {
245                                 ntpd_enabled = +value;
246
247                                 if (ntpd_enabled && !uci.get('system', 'ntp')) {
248                                         uci.add('system', 'timeserver', 'ntp');
249                                         uci.set('system', 'ntp', 'server', default_servers);
250                                 }
251
252                                 if (!ntpd_enabled)
253                                         uci.set('system', 'ntp', 'enabled', 0);
254                                 else
255                                         uci.unset('system', 'ntp', 'enabled');
256
257                                 return callInitAction('sysntpd', 'enable');
258                         };
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';
263                         };
264
265                         o = s.taboption('timesync', form.Flag, 'enable_server', _('Provide NTP server'));
266                         o.ucisection = 'ntp';
267                         o.depends('enabled', '1');
268
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');
273
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');
280                         };
281                 }
282
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();
287                                 });
288                         });
289
290                         return mapEl;
291                 });
292         }
293 });